@@ -446,7 +446,16 @@ void Wippersnapper_FS::createDisplayConfig() {
446446 delay (2500 ); // give FS some time to write the file
447447}
448448
449- void Wippersnapper_FS::parseDisplayConfig (displayConfig &dispCfg) {
449+ bool Wippersnapper_FS::parseDisplayConfig (displayConfig &dispCfg, bool forceRecreate) {
450+ if (forceRecreate) {
451+ if (wipperFatFs.exists (" /display_config.json" )) {
452+ wipperFatFs.remove (" /display_config.json" );
453+ }
454+ #ifdef ARDUINO_FUNHOUSE_ESP32S2
455+ createDisplayConfig ();
456+ #endif
457+ }
458+
450459 // Check if display_config.json file exists, if not, generate it
451460 if (!wipperFatFs.exists (" /display_config.json" )) {
452461 WS_DEBUG_PRINTLN (" Could not find display_config.json, generating..." );
@@ -458,19 +467,26 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) {
458467 // Attempt to open file for JSON parsing
459468 File32 file = wipperFatFs.open (" /display_config.json" , FILE_READ);
460469 if (!file) {
470+ if (!forceRecreate && parseDisplayConfig (dispCfg, true )) {
471+ return true ;
472+ }
461473 fsHalt (" FATAL ERROR: Unable to open display_config.json for parsing" );
462474 }
463475
464476 // Attempt to deserialize the file's json document
465477 JsonDocument doc;
466478 DeserializationError error = deserializeJson (doc, file);
467479 if (error) {
480+ if (!forceRecreate && parseDisplayConfig (dispCfg, true )) {
481+ return true ;
482+ }
468483 fsHalt (String (" FATAL ERROR: Unable to parse display_config.json - deserializeJson() failed with code" ) + error.c_str ());
469484 }
470485 // Close the file, we're done with it
471486 file.close ();
472487 // Extract a displayConfig struct from the JSON document
473488 dispCfg = doc.as <displayConfig>();
489+ return true ;
474490}
475491#endif // ARDUINO_FUNHOUSE_ESP32S2
476492
0 commit comments