Skip to content

Commit 989f666

Browse files
committed
Regenerate displayconfig.json if erroneous
1 parent dac7ebb commit 989f666

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Diff for: src/provisioning/tinyusb/Wippersnapper_FS.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -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

Diff for: src/provisioning/tinyusb/Wippersnapper_FS.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Wippersnapper_FS {
5959
void parseSecrets();
6060

6161
#ifdef ARDUINO_FUNHOUSE_ESP32S2
62-
void parseDisplayConfig(displayConfig &displayFile);
62+
bool parseDisplayConfig(displayConfig &displayFile, bool forceRecreate = false);
6363
void createDisplayConfig();
6464
#endif
6565
private:

0 commit comments

Comments
 (0)