Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/provisioning/tinyusb/Wippersnapper_FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

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`

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...");
Expand All @@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call to parseDisplayConfig() within parseDisplayConfig() potentially causes recursion.

Instead, I'd like to see this segment (and the segment on L564, which has the same logic) returning false and whatever calls this should check the return and then attempt to call parseDisplayConfig(dispCfg, true).

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)) {
Copy link
Member

Choose a reason for hiding this comment

The 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());
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/provisioning/tinyusb/Wippersnapper_FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Wippersnapper_FS {
void parseSecrets();

#ifdef ARDUINO_FUNHOUSE_ESP32S2
void parseDisplayConfig(displayConfig &displayFile);
bool parseDisplayConfig(displayConfig &displayFile, bool forceRecreate = false);
Copy link
Member

Choose a reason for hiding this comment

The 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:
Expand Down
Loading