Skip to content

Commit

Permalink
Use defined default + rem 2nd check of brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Dec 19, 2024
1 parent 53ca349 commit 9ddb120
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
13 changes: 5 additions & 8 deletions src/provisioning/littlefs/WipperSnapper_LittleFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,11 @@ void WipperSnapper_LittleFS::parseSecrets() {
"credentials!\n");
}

if (doc["status_pixel_brightness"]) {
// check it casts to float and support user specifying 0.0f which is
// default, by using the |operator instead of .as
// https://arduinojson.org/v7/api/jsonvariant/or/
if ((doc["status_pixel_brightness"] | -1.0f) != -1.0f) {
WS.status_pixel_brightness = doc["status_pixel_brightness"].as<float>();
}
}
// specify type of value for json key, by using the |operator to include
// a typed default value equivalent of with .as<float> w/ default value
// https://arduinojson.org/v7/api/jsonvariant/or/
WS._config.status_pixel_brightness =
doc["status_pixel_brightness"] | (float)STATUS_PIXEL_BRIGHTNESS_DEFAULT;

// Close the file
secretsFile.close();
Expand Down
14 changes: 6 additions & 8 deletions src/provisioning/tinyusb/Wippersnapper_FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void Wippersnapper_FS::createSecretsFile() {
strcpy(secretsConfig.aio_key, "YOUR_IO_KEY_HERE");
strcpy(secretsConfig.network.ssid, "YOUR_WIFI_SSID_HERE");
strcpy(secretsConfig.network.pass, "YOUR_WIFI_PASS_HERE");
secretsConfig.status_pixel_brightness = 0.2;
secretsConfig.status_pixel_brightness = STATUS_PIXEL_BRIGHTNESS_DEFAULT;

// Serialize the struct to a JSON document
JsonDocument doc;
Expand Down Expand Up @@ -452,13 +452,11 @@ void Wippersnapper_FS::parseSecrets() {
"credentials!");
}

if (doc["status_pixel_brightness"]){
// check it casts to float and support user specifying 0.0f which is default,
// by using the |operator instead of .as https://arduinojson.org/v7/api/jsonvariant/or/
if ((doc["status_pixel_brightness"] | -1.0f) != -1.0f) {
WS.status_pixel_brightness = doc["status_pixel_brightness"].as<float>();
}
}
// specify type of value for json key, by using the |operator to include
// a typed default value equivalent of with .as<float> w/ default value
// https://arduinojson.org/v7/api/jsonvariant/or/
WS._config.status_pixel_brightness =
doc["status_pixel_brightness"] | (float)STATUS_PIXEL_BRIGHTNESS_DEFAULT;

// Close secrets.json file
secretsFile.close();
Expand Down

0 comments on commit 9ddb120

Please sign in to comment.