Skip to content

Commit

Permalink
Change createBootFile to only if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Oct 11, 2024
1 parent 901e2a4 commit a5f7283
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions src/provisioning/tinyusb/Wippersnapper_FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,39 +260,46 @@ void Wippersnapper_FS::eraseBootFile() {
bool Wippersnapper_FS::createBootFile() {
bool is_success = false;
char sMAC[18] = {0};

File32 bootFile = wipperFatFs.open("/wipper_boot_out.txt", FILE_WRITE);
String newContent;

// Generate new content
newContent += "Adafruit.io WipperSnapper\n";
newContent += "Firmware Version: " + String(WS_VERSION) + "\n";
newContent += "Board ID: " + String(BOARD_ID) + "\n";
sprintf(sMAC, "%02X:%02X:%02X:%02X:%02X:%02X", WS._macAddr[0],
WS._macAddr[1], WS._macAddr[2], WS._macAddr[3], WS._macAddr[4],
WS._macAddr[5]);
newContent += "MAC Address: " + String(sMAC) + "\n";

#ifdef ARDUINO_ARCH_ESP32
newContent += "ESP-IDF Version: " + String(ESP.getSdkVersion()) + "\n";
newContent += "ESP32 Core Version: " + String(ESP.getCoreVersion()) + "\n";
#endif

// Check if the file exists and read its content
File32 bootFile = wipperFatFs.open("/wipper_boot_out.txt", FILE_READ);
if (bootFile) {
bootFile.println("Adafruit.io WipperSnapper");

bootFile.print("Firmware Version: ");
bootFile.println(WS_VERSION);

bootFile.print("Board ID: ");
bootFile.println(BOARD_ID);

sprintf(sMAC, "%02X:%02X:%02X:%02X:%02X:%02X", WS._macAddr[0],
WS._macAddr[1], WS._macAddr[2], WS._macAddr[3], WS._macAddr[4],
WS._macAddr[5]);
bootFile.print("MAC Address: ");
bootFile.println(sMAC);

// Print ESP-specific info to boot file
#ifdef ARDUINO_ARCH_ESP32
// Get version of ESP-IDF
bootFile.print("ESP-IDF Version: ");
bootFile.println(ESP.getSdkVersion());
// Get version of this core
bootFile.print("ESP32 Core Version: ");
bootFile.println(ESP.getCoreVersion());
#endif
String existingContent;
while (bootFile.available()) {
existingContent += char(bootFile.read());
}
bootFile.close();

// Compare existing content with new content
if (existingContent == newContent) {
return true; // No need to overwrite
}
}

// Overwrite the file with new content
bootFile = wipperFatFs.open("/wipper_boot_out.txt", FILE_WRITE);
if (bootFile) {
bootFile.print(newContent);
bootFile.flush();
bootFile.close();
is_success = true;
} else {
bootFile.close();
}

return is_success;
}

Expand Down

0 comments on commit a5f7283

Please sign in to comment.