21
21
So as long as the status LED is off you can safely remove the drive.
22
22
The sketch will log to internal storage in the meantime, and wait for the USB drive to be inserted again.
23
23
*/
24
-
24
+ # define ARDUINO_UNIFIED_STORAGE_DEBUG
25
25
#include " Arduino_UnifiedStorage.h"
26
- #include " Logger.h"
27
26
#include < vector>
28
27
29
28
@@ -98,10 +97,10 @@ void performUpdate() {
98
97
backingUP = true ;
99
98
unsigned lastUpdateBytes = lastUpdateFile.readAsString ().toInt (); // Read the last update size from the file
100
99
101
- printlnToSerialOrRS485 (" Last update bytes: " + String (lastUpdateBytes));
100
+ debugPrint (" Last update bytes: " + String (lastUpdateBytes));
102
101
103
102
if (lastUpdateBytes >= bytesWritten) {
104
- printlnToSerialOrRS485 (" No new data to copy. " );
103
+ debugPrint (" No new data to copy. " );
105
104
backupFile.close ();
106
105
lastUpdateFile.close ();
107
106
backingUP = false ;
@@ -110,14 +109,14 @@ void performUpdate() {
110
109
111
110
logFile.seek (lastUpdateBytes); // Move the file pointer to the last update position
112
111
unsigned long totalBytesToMove = bytesWritten - lastUpdateBytes;
113
- printlnToSerialOrRS485 (" New update bytes: " + String (totalBytesToMove));
112
+ debugPrint (" New update bytes: " + String (totalBytesToMove));
114
113
115
114
uint8_t * buffer = new uint8_t [totalBytesToMove];
116
115
117
116
size_t bytesRead = logFile.read (buffer, totalBytesToMove);
118
117
size_t bytesMoved = backupFile.write (buffer, bytesRead); // Only write the bytes that haven't been backed up yet
119
118
120
- printlnToSerialOrRS485 (" Successfully copied " + String (bytesMoved) + " new bytes. " );
119
+ debugPrint (" Successfully copied " + String (bytesMoved) + " new bytes. " );
121
120
122
121
lastUpdateFile.changeMode (FileMode::WRITE); // Open the last update file in write mode
123
122
lastUpdateFile.write (String (lastUpdateBytes + bytesMoved)); // Update the last update size
@@ -139,32 +138,32 @@ void performUpdate() {
139
138
void backupToUSB () {
140
139
if (usbAvailable && !usbIntialized){
141
140
usbStorage.begin ();
142
- printlnToSerialOrRS485 (" First drive insertion, creating folders... " );
141
+ debugPrint (" First drive insertion, creating folders... " );
143
142
Folder usbRoot = usbStorage.getRootFolder ();
144
143
String folderName = " LoggerBackup" + String (random (9999 ));
145
144
backupFolder = usbRoot.createSubfolder (folderName);
146
- printlnToSerialOrRS485 (" Successfully created backup folder: " + backupFolder.getPathAsString ());
145
+ debugPrint (" Successfully created backup folder: " + backupFolder.getPathAsString ());
147
146
usbStorage.unmount ();
148
147
usbIntialized = true ;
149
148
}
150
149
else if (usbAvailable && usbIntialized) {
151
- printlnToSerialOrRS485 (" USB Mass storage is available " );
150
+ debugPrint (" USB Mass storage is available " );
152
151
delay (100 );
153
152
if (!usbStorage.isMounted ()) {
154
153
155
- printlnToSerialOrRS485 (" Mounting USB Mass Storage " );
154
+ debugPrint (" Mounting USB Mass Storage " );
156
155
digitalWrite (USB_MOUNTED_LED, LOW);
157
156
if (usbStorage.begin ()){
158
157
performUpdate ();
159
158
}
160
159
161
160
} else if (usbStorage.isMounted ()) {
162
- printlnToSerialOrRS485 (" USB Mass storage is connected, performing update " );
161
+ debugPrint (" USB Mass storage is connected, performing update " );
163
162
performUpdate ();
164
163
165
164
}
166
165
} else {
167
- printlnToSerialOrRS485 (" USB Mass storage is not available " );
166
+ debugPrint (" USB Mass storage is not available " );
168
167
}
169
168
170
169
@@ -186,17 +185,17 @@ void setup() {
186
185
usbStorage.onDisconnect (disconnectionCallback);
187
186
188
187
pinMode (USB_MOUNTED_LED, OUTPUT);
189
- printlnToSerialOrRS485 (" Formatting internal storage... " );
188
+ debugPrint (" Formatting internal storage... " );
190
189
int formatted = internalStorage.format (FS_LITTLEFS);
191
- printlnToSerialOrRS485 (" QSPI Format status: " + String (formatted));
190
+ debugPrint (" QSPI Format status: " + String (formatted));
192
191
193
192
194
193
195
194
if (!internalStorage.begin ()) {
196
- printlnToSerialOrRS485 (" Failed to initialize internal storage " );
195
+ debugPrint (" Failed to initialize internal storage " );
197
196
return ;
198
197
} else {
199
- printlnToSerialOrRS485 (" Initialized storage " );
198
+ debugPrint (" Initialized storage " );
200
199
}
201
200
202
201
}
0 commit comments