diff --git a/src/provisioning/tinyusb/Wippersnapper_FS.cpp b/src/provisioning/tinyusb/Wippersnapper_FS.cpp index 1aefeea14..02aa7e4fe 100644 --- a/src/provisioning/tinyusb/Wippersnapper_FS.cpp +++ b/src/provisioning/tinyusb/Wippersnapper_FS.cpp @@ -446,7 +446,16 @@ void Wippersnapper_FS::createDisplayConfig() { delay(2500); // give FS some time to write the file } -void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) { +bool Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg, bool forceRecreate) { + if (forceRecreate) { + if (wipperFatFs.exists("/display_config.json")) { + wipperFatFs.remove("/display_config.json"); + } +#ifdef ARDUINO_FUNHOUSE_ESP32S2 + createDisplayConfig(); +#endif + } + // Check if display_config.json file exists, if not, generate it if (!wipperFatFs.exists("/display_config.json")) { WS_DEBUG_PRINTLN("Could not find display_config.json, generating..."); @@ -458,6 +467,9 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) { // Attempt to open file for JSON parsing File32 file = wipperFatFs.open("/display_config.json", FILE_READ); if (!file) { + if (!forceRecreate && parseDisplayConfig(dispCfg, true)) { + return true; + } fsHalt("FATAL ERROR: Unable to open display_config.json for parsing"); } @@ -465,12 +477,16 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) { JsonDocument doc; DeserializationError error = deserializeJson(doc, file); if (error) { + if (!forceRecreate && parseDisplayConfig(dispCfg, true)) { + return true; + } fsHalt(String("FATAL ERROR: Unable to parse display_config.json - deserializeJson() failed with code") + error.c_str()); } // Close the file, we're done with it file.close(); // Extract a displayConfig struct from the JSON document dispCfg = doc.as(); + return true; } #endif // ARDUINO_FUNHOUSE_ESP32S2 diff --git a/src/provisioning/tinyusb/Wippersnapper_FS.h b/src/provisioning/tinyusb/Wippersnapper_FS.h index 22fe7df27..25e2475df 100644 --- a/src/provisioning/tinyusb/Wippersnapper_FS.h +++ b/src/provisioning/tinyusb/Wippersnapper_FS.h @@ -59,7 +59,7 @@ class Wippersnapper_FS { void parseSecrets(); #ifdef ARDUINO_FUNHOUSE_ESP32S2 - void parseDisplayConfig(displayConfig &displayFile); + bool parseDisplayConfig(displayConfig &displayFile, bool forceRecreate = false); void createDisplayConfig(); #endif private: