Skip to content

Commit b7a915a

Browse files
committed
Regenerate displayconfig.json if erroneous
1 parent b75aae3 commit b7a915a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/provisioning/tinyusb/Wippersnapper_FS.cpp

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

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)