@@ -446,7 +446,16 @@ void Wippersnapper_FS::createDisplayConfig() {
446
446
delay (2500 ); // give FS some time to write the file
447
447
}
448
448
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
+
450
459
// Check if display_config.json file exists, if not, generate it
451
460
if (!wipperFatFs.exists (" /display_config.json" )) {
452
461
WS_DEBUG_PRINTLN (" Could not find display_config.json, generating..." );
@@ -458,19 +467,26 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) {
458
467
// Attempt to open file for JSON parsing
459
468
File32 file = wipperFatFs.open (" /display_config.json" , FILE_READ);
460
469
if (!file) {
470
+ if (!forceRecreate && parseDisplayConfig (dispCfg, true )) {
471
+ return true ;
472
+ }
461
473
fsHalt (" FATAL ERROR: Unable to open display_config.json for parsing" );
462
474
}
463
475
464
476
// Attempt to deserialize the file's json document
465
477
JsonDocument doc;
466
478
DeserializationError error = deserializeJson (doc, file);
467
479
if (error) {
480
+ if (!forceRecreate && parseDisplayConfig (dispCfg, true )) {
481
+ return true ;
482
+ }
468
483
fsHalt (String (" FATAL ERROR: Unable to parse display_config.json - deserializeJson() failed with code" ) + error.c_str ());
469
484
}
470
485
// Close the file, we're done with it
471
486
file.close ();
472
487
// Extract a displayConfig struct from the JSON document
473
488
dispCfg = doc.as <displayConfig>();
489
+ return true ;
474
490
}
475
491
#endif // ARDUINO_FUNHOUSE_ESP32S2
476
492
0 commit comments