@@ -529,7 +529,16 @@ void Wippersnapper_FS::createDisplayConfig() {
529
529
delay (2500 ); // give FS some time to write the file
530
530
}
531
531
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
+
533
542
// Check if display_config.json file exists, if not, generate it
534
543
if (!wipperFatFs.exists (" /display_config.json" )) {
535
544
WS_DEBUG_PRINTLN (" Could not find display_config.json, generating..." );
@@ -542,13 +551,19 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) {
542
551
// Attempt to open file for JSON parsing
543
552
File32 file = wipperFatFs.open (" /display_config.json" , FILE_READ);
544
553
if (!file) {
554
+ if (!forceRecreate && parseDisplayConfig (dispCfg, true )) {
555
+ return true ;
556
+ }
545
557
fsHalt (" FATAL ERROR: Unable to open display_config.json for parsing" );
546
558
}
547
559
548
560
// Attempt to deserialize the file's json document
549
561
JsonDocument doc;
550
562
DeserializationError error = deserializeJson (doc, file);
551
563
if (error) {
564
+ if (!forceRecreate && parseDisplayConfig (dispCfg, true )) {
565
+ return true ;
566
+ }
552
567
fsHalt (String (" FATAL ERROR: Unable to parse display_config.json - "
553
568
" deserializeJson() failed with code" ) +
554
569
error.c_str ());
@@ -557,6 +572,7 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) {
557
572
file.close ();
558
573
// Extract a displayConfig struct from the JSON document
559
574
dispCfg = doc.as <displayConfig>();
575
+ return true ;
560
576
}
561
577
#endif // ARDUINO_FUNHOUSE_ESP32S2
562
578
0 commit comments