@@ -529,7 +529,16 @@ void Wippersnapper_FS::createDisplayConfig() {
529529 delay (2500 ); // give FS some time to write the file
530530}
531531
532- void Wippersnapper_FS::parseDisplayConfig (displayConfig &dispCfg) {
532+ bool Wippersnapper_FS::parseDisplayConfig (displayConfig &dispCfg, bool forceRecreate) {
533+ if (forceRecreate) {
534+ if (wipperFatFs.exists (" /display_config.json" )) {
535+ wipperFatFs.remove (" /display_config.json" );
536+ }
537+ #ifdef ARDUINO_FUNHOUSE_ESP32S2
538+ createDisplayConfig ();
539+ #endif
540+ }
541+
533542 // Check if display_config.json file exists, if not, generate it
534543 if (!wipperFatFs.exists (" /display_config.json" )) {
535544 WS_DEBUG_PRINTLN (" Could not find display_config.json, generating..." );
@@ -542,13 +551,19 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) {
542551 // Attempt to open file for JSON parsing
543552 File32 file = wipperFatFs.open (" /display_config.json" , FILE_READ);
544553 if (!file) {
554+ if (!forceRecreate && parseDisplayConfig (dispCfg, true )) {
555+ return true ;
556+ }
545557 fsHalt (" FATAL ERROR: Unable to open display_config.json for parsing" );
546558 }
547559
548560 // Attempt to deserialize the file's json document
549561 JsonDocument doc;
550562 DeserializationError error = deserializeJson (doc, file);
551563 if (error) {
564+ if (!forceRecreate && parseDisplayConfig (dispCfg, true )) {
565+ return true ;
566+ }
552567 fsHalt (String (" FATAL ERROR: Unable to parse display_config.json - "
553568 " deserializeJson() failed with code" ) +
554569 error.c_str ());
@@ -557,6 +572,7 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) {
557572 file.close ();
558573 // Extract a displayConfig struct from the JSON document
559574 dispCfg = doc.as <displayConfig>();
575+ return true ;
560576}
561577#endif // ARDUINO_FUNHOUSE_ESP32S2
562578
0 commit comments