Skip to content

Commit 9b52d98

Browse files
committed
Change createBootFile to only if needed
1 parent 270344d commit 9b52d98

File tree

1 file changed

+36
-28
lines changed

1 file changed

+36
-28
lines changed

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -269,44 +269,52 @@ void Wippersnapper_FS::eraseBootFile() {
269269
bool Wippersnapper_FS::createBootFile() {
270270
bool is_success = false;
271271
char sMAC[18] = {0};
272+
String newContent;
272273

273-
File32 bootFile = wipperFatFs.open("/wipper_boot_out.txt", FILE_WRITE);
274-
if (bootFile) {
275-
bootFile.println("Adafruit.io WipperSnapper");
276-
277-
bootFile.print("Firmware Version: ");
278-
bootFile.println(WS_VERSION);
279-
280-
bootFile.print("Board ID: ");
281-
bootFile.println(BOARD_ID);
282-
283-
sprintf(sMAC, "%02X:%02X:%02X:%02X:%02X:%02X", WS._macAddr[0],
284-
WS._macAddr[1], WS._macAddr[2], WS._macAddr[3], WS._macAddr[4],
285-
WS._macAddr[5]);
286-
bootFile.print("MAC Address: ");
287-
bootFile.println(sMAC);
274+
// Generate new content
275+
newContent += "Adafruit.io WipperSnapper\n";
276+
newContent += "Firmware Version: " + String(WS_VERSION) + "\n";
277+
newContent += "Board ID: " + String(BOARD_ID) + "\n";
278+
sprintf(sMAC, "%02X:%02X:%02X:%02X:%02X:%02X", WS._macAddr[0],
279+
WS._macAddr[1], WS._macAddr[2], WS._macAddr[3], WS._macAddr[4],
280+
WS._macAddr[5]);
281+
newContent += "MAC Address: " + String(sMAC) + "\n";
288282

289283
#if PRINT_DEPENDENCIES
290-
bootFile.println("Build dependencies:");
291-
bootFile.println(project_dependencies);
284+
newContent += ("Build dependencies:\n");
285+
newContent += (project_dependencies);
286+
newContent += ("\n");
292287
#endif
293288

294-
// Print ESP-specific info to boot file
295-
#ifdef ARDUINO_ARCH_ESP32
296-
// Get version of ESP-IDF
297-
bootFile.print("ESP-IDF Version: ");
298-
bootFile.println(ESP.getSdkVersion());
299-
// Get version of this core
300-
bootFile.print("ESP32 Core Version: ");
301-
bootFile.println(ESP.getCoreVersion());
302-
#endif
289+
#ifdef ARDUINO_ARCH_ESP32
290+
newContent += "ESP-IDF Version: " + String(ESP.getSdkVersion()) + "\n";
291+
newContent += "ESP32 Core Version: " + String(ESP.getCoreVersion()) + "\n";
292+
#endif
293+
294+
// Check if the file exists and read its content
295+
File32 bootFile = wipperFatFs.open("/wipper_boot_out.txt", FILE_READ);
296+
if (bootFile) {
297+
String existingContent;
298+
while (bootFile.available()) {
299+
existingContent += char(bootFile.read());
300+
}
301+
bootFile.close();
302+
303+
// Compare existing content with new content
304+
if (existingContent == newContent) {
305+
return true; // No need to overwrite
306+
}
307+
}
303308

309+
// Overwrite the file with new content
310+
bootFile = wipperFatFs.open("/wipper_boot_out.txt", FILE_WRITE);
311+
if (bootFile) {
312+
bootFile.print(newContent);
304313
bootFile.flush();
305314
bootFile.close();
306315
is_success = true;
307-
} else {
308-
bootFile.close();
309316
}
317+
310318
return is_success;
311319
}
312320

0 commit comments

Comments
 (0)