2121 So as long as the status LED is off you can safely remove the drive.
2222 The sketch will log to internal storage in the meantime, and wait for the USB drive to be inserted again.
2323*/
24-
24+ # define ARDUINO_UNIFIED_STORAGE_DEBUG
2525#include " Arduino_UnifiedStorage.h"
26- #include " Logger.h"
2726#include < vector>
2827
2928
@@ -98,10 +97,10 @@ void performUpdate() {
9897 backingUP = true ;
9998 unsigned lastUpdateBytes = lastUpdateFile.readAsString ().toInt (); // Read the last update size from the file
10099
101- printlnToSerialOrRS485 (" Last update bytes: " + String (lastUpdateBytes));
100+ debugPrint (" Last update bytes: " + String (lastUpdateBytes));
102101
103102 if (lastUpdateBytes >= bytesWritten) {
104- printlnToSerialOrRS485 (" No new data to copy. " );
103+ debugPrint (" No new data to copy. " );
105104 backupFile.close ();
106105 lastUpdateFile.close ();
107106 backingUP = false ;
@@ -110,14 +109,14 @@ void performUpdate() {
110109
111110 logFile.seek (lastUpdateBytes); // Move the file pointer to the last update position
112111 unsigned long totalBytesToMove = bytesWritten - lastUpdateBytes;
113- printlnToSerialOrRS485 (" New update bytes: " + String (totalBytesToMove));
112+ debugPrint (" New update bytes: " + String (totalBytesToMove));
114113
115114 uint8_t * buffer = new uint8_t [totalBytesToMove];
116115
117116 size_t bytesRead = logFile.read (buffer, totalBytesToMove);
118117 size_t bytesMoved = backupFile.write (buffer, bytesRead); // Only write the bytes that haven't been backed up yet
119118
120- printlnToSerialOrRS485 (" Successfully copied " + String (bytesMoved) + " new bytes. " );
119+ debugPrint (" Successfully copied " + String (bytesMoved) + " new bytes. " );
121120
122121 lastUpdateFile.changeMode (FileMode::WRITE); // Open the last update file in write mode
123122 lastUpdateFile.write (String (lastUpdateBytes + bytesMoved)); // Update the last update size
@@ -139,32 +138,32 @@ void performUpdate() {
139138void backupToUSB () {
140139 if (usbAvailable && !usbIntialized){
141140 usbStorage.begin ();
142- printlnToSerialOrRS485 (" First drive insertion, creating folders... " );
141+ debugPrint (" First drive insertion, creating folders... " );
143142 Folder usbRoot = usbStorage.getRootFolder ();
144143 String folderName = " LoggerBackup" + String (random (9999 ));
145144 backupFolder = usbRoot.createSubfolder (folderName);
146- printlnToSerialOrRS485 (" Successfully created backup folder: " + backupFolder.getPathAsString ());
145+ debugPrint (" Successfully created backup folder: " + backupFolder.getPathAsString ());
147146 usbStorage.unmount ();
148147 usbIntialized = true ;
149148 }
150149 else if (usbAvailable && usbIntialized) {
151- printlnToSerialOrRS485 (" USB Mass storage is available " );
150+ debugPrint (" USB Mass storage is available " );
152151 delay (100 );
153152 if (!usbStorage.isMounted ()) {
154153
155- printlnToSerialOrRS485 (" Mounting USB Mass Storage " );
154+ debugPrint (" Mounting USB Mass Storage " );
156155 digitalWrite (USB_MOUNTED_LED, LOW);
157156 if (usbStorage.begin ()){
158157 performUpdate ();
159158 }
160159
161160 } else if (usbStorage.isMounted ()) {
162- printlnToSerialOrRS485 (" USB Mass storage is connected, performing update " );
161+ debugPrint (" USB Mass storage is connected, performing update " );
163162 performUpdate ();
164163
165164 }
166165 } else {
167- printlnToSerialOrRS485 (" USB Mass storage is not available " );
166+ debugPrint (" USB Mass storage is not available " );
168167 }
169168
170169
@@ -186,17 +185,17 @@ void setup() {
186185 usbStorage.onDisconnect (disconnectionCallback);
187186
188187 pinMode (USB_MOUNTED_LED, OUTPUT);
189- printlnToSerialOrRS485 (" Formatting internal storage... " );
188+ debugPrint (" Formatting internal storage... " );
190189 int formatted = internalStorage.format (FS_LITTLEFS);
191- printlnToSerialOrRS485 (" QSPI Format status: " + String (formatted));
190+ debugPrint (" QSPI Format status: " + String (formatted));
192191
193192
194193
195194 if (!internalStorage.begin ()) {
196- printlnToSerialOrRS485 (" Failed to initialize internal storage " );
195+ debugPrint (" Failed to initialize internal storage " );
197196 return ;
198197 } else {
199- printlnToSerialOrRS485 (" Initialized storage " );
198+ debugPrint (" Initialized storage " );
200199 }
201200
202201}
0 commit comments