@@ -543,7 +543,16 @@ void Wippersnapper_FS::createDisplayConfig() {
543543 delay (2500 ); // give FS some time to write the file
544544}
545545
546- void Wippersnapper_FS::parseDisplayConfig (displayConfig &dispCfg) {
546+ bool Wippersnapper_FS::parseDisplayConfig (displayConfig &dispCfg, bool forceRecreate) {
547+ if (forceRecreate) {
548+ if (wipperFatFs.exists (" /display_config.json" )) {
549+ wipperFatFs.remove (" /display_config.json" );
550+ }
551+ #ifdef ARDUINO_FUNHOUSE_ESP32S2
552+ createDisplayConfig ();
553+ #endif
554+ }
555+
547556 // Check if display_config.json file exists, if not, generate it
548557 if (!wipperFatFs.exists (" /display_config.json" )) {
549558 WS_DEBUG_PRINTLN (" Could not find display_config.json, generating..." );
@@ -556,13 +565,19 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) {
556565 // Attempt to open file for JSON parsing
557566 File32 file = wipperFatFs.open (" /display_config.json" , FILE_READ);
558567 if (!file) {
568+ if (!forceRecreate && parseDisplayConfig (dispCfg, true )) {
569+ return true ;
570+ }
559571 fsHalt (" FATAL ERROR: Unable to open display_config.json for parsing" );
560572 }
561573
562574 // Attempt to deserialize the file's json document
563575 JsonDocument doc;
564576 DeserializationError error = deserializeJson (doc, file);
565577 if (error) {
578+ if (!forceRecreate && parseDisplayConfig (dispCfg, true )) {
579+ return true ;
580+ }
566581 fsHalt (String (" FATAL ERROR: Unable to parse display_config.json - "
567582 " deserializeJson() failed with code" ) +
568583 error.c_str ());
@@ -571,6 +586,7 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) {
571586 file.close ();
572587 // Extract a displayConfig struct from the JSON document
573588 dispCfg = doc.as <displayConfig>();
589+ return true ;
574590}
575591#endif // ARDUINO_FUNHOUSE_ESP32S2
576592
0 commit comments