2323*/
2424
2525#include " Arduino_UnifiedStorage.h"
26+ #include " Logger.h"
2627#include < vector>
2728
2829
@@ -46,18 +47,15 @@ unsigned long lastLog = 0;
4647unsigned long lastMove = 0 ;
4748unsigned long lastBackup = 0 ;
4849
49-
5050volatile bool usbAvailable = false ;
5151bool backingUP = false ;
5252
5353void connectionCallback (){
54- printToSerialOrRS485 (" CONNECTION CALLBACK RAISED !!!" );
5554 usbAvailable = true ;
5655 usbStorage.removeOnConnectCallback ();
5756}
5857
5958void disconnectionCallback (){
60- printToSerialOrRS485 (" DISCONNECTION CALLBACK RAISED !!!" );
6159 usbAvailable = false ;
6260 usbStorage.onConnect (connectionCallback);
6361
@@ -76,7 +74,7 @@ void runPeriodically(void (*method)(), unsigned long interval, unsigned long* va
7674void logDataToRAM () {
7775 int timeStamp = millis ();
7876 int sensorReading = analogRead (A0);
79- String line = String (timeStamp) + " ," + String (random (9999 )) + " \n " ;
77+ String line = String (timeStamp) + " ," + String (random (9999 ));
8078 sensorDataBuffer.push_back (line);
8179}
8280
@@ -100,10 +98,10 @@ void performUpdate() {
10098 backingUP = true ;
10199 unsigned lastUpdateBytes = lastUpdateFile.readAsString ().toInt (); // Read the last update size from the file
102100
103- printToSerialOrRS485 (" Last update bytes: " + String (lastUpdateBytes) + " \n " );
101+ printlnToSerialOrRS485 (" Last update bytes: " + String (lastUpdateBytes));
104102
105103 if (lastUpdateBytes >= bytesWritten) {
106- printToSerialOrRS485 (" No new data to copy. \n " );
104+ printlnToSerialOrRS485 (" No new data to copy. " );
107105 backupFile.close ();
108106 lastUpdateFile.close ();
109107 backingUP = false ;
@@ -112,14 +110,14 @@ void performUpdate() {
112110
113111 logFile.seek (lastUpdateBytes); // Move the file pointer to the last update position
114112 unsigned long totalBytesToMove = bytesWritten - lastUpdateBytes;
115- printToSerialOrRS485 (" New update bytes: " + String (totalBytesToMove) + " \n " );
113+ printlnToSerialOrRS485 (" New update bytes: " + String (totalBytesToMove));
116114
117115 uint8_t * buffer = new uint8_t [totalBytesToMove];
118116
119117 size_t bytesRead = logFile.read (buffer, totalBytesToMove);
120118 size_t bytesMoved = backupFile.write (buffer, bytesRead); // Only write the bytes that haven't been backed up yet
121119
122- printToSerialOrRS485 (" Successfully copied " + String (bytesMoved) + " new bytes. \n " );
120+ printlnToSerialOrRS485 (" Successfully copied " + String (bytesMoved) + " new bytes. " );
123121
124122 lastUpdateFile.changeMode (FileMode::WRITE); // Open the last update file in write mode
125123 lastUpdateFile.write (String (lastUpdateBytes + bytesMoved)); // Update the last update size
@@ -141,32 +139,32 @@ void performUpdate() {
141139void backupToUSB () {
142140 if (usbAvailable && !usbIntialized){
143141 usbStorage.begin ();
144- printToSerialOrRS485 (" First drive insertion, creating folders... \n " );
142+ printlnToSerialOrRS485 (" First drive insertion, creating folders... " );
145143 Folder usbRoot = usbStorage.getRootFolder ();
146144 String folderName = " LoggerBackup" + String (random (9999 ));
147145 backupFolder = usbRoot.createSubfolder (folderName);
148- printToSerialOrRS485 (" Succesfully created backup folder: " + backupFolder.getPathAsString () + " \n " );
146+ printlnToSerialOrRS485 (" Succesfully created backup folder: " + backupFolder.getPathAsString ());
149147 usbStorage.unmount ();
150148 usbIntialized = true ;
151149 }
152150 else if (usbAvailable && usbIntialized) {
153- printToSerialOrRS485 (" USB Mass storage is available \n " );
151+ printlnToSerialOrRS485 (" USB Mass storage is available " );
154152 delay (100 );
155153 if (!usbStorage.isMounted ()) {
156154
157- printToSerialOrRS485 (" Mounting USB Mass Storage \n " );
155+ printlnToSerialOrRS485 (" Mounting USB Mass Storage " );
158156 digitalWrite (USB_MOUNTED_LED, LOW);
159157 if (usbStorage.begin ()){
160158 performUpdate ();
161159 }
162160
163161 } else if (usbStorage.isMounted ()) {
164- printToSerialOrRS485 (" USB Mass storage is connected, performing update \n " );
162+ printlnToSerialOrRS485 (" USB Mass storage is connected, performing update " );
165163 performUpdate ();
166164
167165 }
168166 } else {
169- printToSerialOrRS485 (" USB Mass storage is not available \n " );
167+ printlnToSerialOrRS485 (" USB Mass storage is not available " );
170168 }
171169
172170
@@ -188,17 +186,17 @@ void setup() {
188186 usbStorage.onDisconnect (disconnectionCallback);
189187
190188 pinMode (USB_MOUNTED_LED, OUTPUT);
191- printToSerialOrRS485 (" Formatting internal storage... \n " );
189+ printlnToSerialOrRS485 (" Formatting internal storage... " );
192190 int formatted = internalStorage.format (FS_LITTLEFS);
193- printToSerialOrRS485 (" QSPI Format status: " + String (formatted) + " \n " );
191+ printlnToSerialOrRS485 (" QSPI Format status: " + String (formatted));
194192
195193
196194
197195 if (!internalStorage.begin ()) {
198- printToSerialOrRS485 (" Failed to initialize internal storage \n " );
196+ printlnToSerialOrRS485 (" Failed to initialize internal storage " );
199197 return ;
200198 } else {
201- printToSerialOrRS485 (" Initialized storage \n " );
199+ printlnToSerialOrRS485 (" Initialized storage " );
202200 }
203201
204202}
0 commit comments