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