Skip to content

Commit 9ddb120

Browse files
committed
Use defined default + rem 2nd check of brightness
1 parent 53ca349 commit 9ddb120

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/provisioning/littlefs/WipperSnapper_LittleFS.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,11 @@ void WipperSnapper_LittleFS::parseSecrets() {
138138
"credentials!\n");
139139
}
140140

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

150147
// Close the file
151148
secretsFile.close();

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void Wippersnapper_FS::createSecretsFile() {
325325
strcpy(secretsConfig.aio_key, "YOUR_IO_KEY_HERE");
326326
strcpy(secretsConfig.network.ssid, "YOUR_WIFI_SSID_HERE");
327327
strcpy(secretsConfig.network.pass, "YOUR_WIFI_PASS_HERE");
328-
secretsConfig.status_pixel_brightness = 0.2;
328+
secretsConfig.status_pixel_brightness = STATUS_PIXEL_BRIGHTNESS_DEFAULT;
329329

330330
// Serialize the struct to a JSON document
331331
JsonDocument doc;
@@ -452,13 +452,11 @@ void Wippersnapper_FS::parseSecrets() {
452452
"credentials!");
453453
}
454454

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

463461
// Close secrets.json file
464462
secretsFile.close();

0 commit comments

Comments
 (0)