@@ -66,7 +66,10 @@ void scanForFirmware()
66
66
tempFile.getName (fname, sizeof (fname));
67
67
68
68
if (strcmp (forceFirmwareFileName, fname) == 0 )
69
+ {
70
+ Serial.println (F (" Forced firmware detected. Loading..." ));
69
71
updateFromSD ((char *)forceFirmwareFileName);
72
+ }
70
73
71
74
// Check for 'sfe_rtk' and 'bin' extension
72
75
if (strcmp (BIN_EXT, &fname[strlen (fname) - strlen (BIN_EXT)]) == 0 )
@@ -109,8 +112,10 @@ void updateFromSD(char *firmwareFileName)
109
112
}
110
113
111
114
Serial.print (F (" Moving file to OTA section" ));
115
+ Serial.print (F (" Bytes to write: " ));
116
+ Serial.print (updateSize);
112
117
113
- const int pageSize = 512 ;
118
+ const int pageSize = 512 * 4 ;
114
119
byte dataArray[pageSize];
115
120
int bytesWritten = 0 ;
116
121
@@ -122,15 +127,19 @@ void updateFromSD(char *firmwareFileName)
122
127
// Bulk write from the SD file to the EEPROM
123
128
while (firmwareFile.available ())
124
129
{
130
+ digitalWrite (baseStatusLED, !digitalRead (baseStatusLED)); // Toggle LED to indcate activity
131
+
125
132
int bytesToWrite = pageSize; // Max number of bytes to read
126
133
if (firmwareFile.available () < bytesToWrite) bytesToWrite = firmwareFile.available (); // Trim this read size as needed
127
134
128
135
firmwareFile.read (dataArray, bytesToWrite); // Read the next set of bytes from file into our temp array
136
+ delay (10 ); // Give RTOS time
129
137
130
138
if (Update.write (dataArray, bytesToWrite) != bytesToWrite)
131
139
Serial.println (F (" Write failed" ));
132
140
else
133
141
bytesWritten += bytesToWrite;
142
+ delay (10 ); // Give RTOS time
134
143
135
144
// Indicate progress
136
145
if (bytesWritten > barWidth * portionSize)
@@ -151,6 +160,24 @@ void updateFromSD(char *firmwareFileName)
151
160
if (Update.isFinished ())
152
161
{
153
162
Serial.println (F (" Firmware updated successfully. Rebooting. Good bye!" ));
163
+
164
+ // If forced firmware is detected, do a full reset of config as well
165
+ if (strcmp (forceFirmwareFileName, firmwareFileName) == 0 )
166
+ {
167
+ Serial.println (F (" Removing firmware file" ));
168
+
169
+ // Remove forced firmware file to prevent endless loading
170
+ firmwareFile.close ();
171
+ sd.remove (firmwareFileName);
172
+
173
+ eepromErase ();
174
+
175
+ if (sd.exists (settingsFileName))
176
+ sd.remove (settingsFileName);
177
+
178
+ myGPS.factoryReset (); // Reset everything: baud rate, I2C address, update rate, everything.
179
+ }
180
+
154
181
delay (1000 );
155
182
ESP.restart ();
156
183
}
0 commit comments