-
Notifications
You must be signed in to change notification settings - Fork 51
Regenerate displayconfig.json if erroneous #575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -529,7 +529,16 @@ void Wippersnapper_FS::createDisplayConfig() { | |
delay(2500); // give FS some time to write the file | ||
} | ||
|
||
void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) { | ||
bool Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg, bool forceRecreate) { | ||
if (forceRecreate) { | ||
if (wipperFatFs.exists("/display_config.json")) { | ||
wipperFatFs.remove("/display_config.json"); | ||
} | ||
#ifdef ARDUINO_FUNHOUSE_ESP32S2 | ||
createDisplayConfig(); | ||
#endif | ||
} | ||
|
||
// Check if display_config.json file exists, if not, generate it | ||
if (!wipperFatFs.exists("/display_config.json")) { | ||
WS_DEBUG_PRINTLN("Could not find display_config.json, generating..."); | ||
|
@@ -542,13 +551,19 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) { | |
// Attempt to open file for JSON parsing | ||
File32 file = wipperFatFs.open("/display_config.json", FILE_READ); | ||
if (!file) { | ||
if (!forceRecreate && parseDisplayConfig(dispCfg, true)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This call to Instead, I'd like to see this segment (and the segment on L564, which has the same logic) returning |
||
return true; | ||
} | ||
fsHalt("FATAL ERROR: Unable to open display_config.json for parsing"); | ||
} | ||
|
||
// Attempt to deserialize the file's json document | ||
JsonDocument doc; | ||
DeserializationError error = deserializeJson(doc, file); | ||
if (error) { | ||
if (!forceRecreate && parseDisplayConfig(dispCfg, true)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment about L554, this is the same potential recursion issue |
||
return true; | ||
} | ||
fsHalt(String("FATAL ERROR: Unable to parse display_config.json - " | ||
"deserializeJson() failed with code") + | ||
error.c_str()); | ||
|
@@ -557,6 +572,7 @@ void Wippersnapper_FS::parseDisplayConfig(displayConfig &dispCfg) { | |
file.close(); | ||
// Extract a displayConfig struct from the JSON document | ||
dispCfg = doc.as<displayConfig>(); | ||
return true; | ||
} | ||
#endif // ARDUINO_FUNHOUSE_ESP32S2 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ class Wippersnapper_FS { | |
void parseSecrets(); | ||
|
||
#ifdef ARDUINO_FUNHOUSE_ESP32S2 | ||
void parseDisplayConfig(displayConfig &displayFile); | ||
bool parseDisplayConfig(displayConfig &displayFile, bool forceRecreate = false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not set default arg in header, set in .cpp |
||
void createDisplayConfig(); | ||
#endif | ||
private: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change
forceRecreate to
force_recreateand give it a default param here:
bool force_recreate=false`