Skip to content

Commit d7ef511

Browse files
committed
Fix ArduinoJson deprecations
Swapped doc.containsKey(...) and settings.containsKey(...) in src/sp140/extra-data.ino:209-249 for the modern isNull() checks via doc["..."]/settings["..."], all guarded with null tests before use.
1 parent 20b1c44 commit d7ef511

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/sp140/extra-data.ino

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void parse_serial_commands() {
206206
return;
207207
}
208208

209-
if (doc.containsKey("command")) {
209+
if (!doc["command"].isNull()) {
210210
String command = doc["command"].as<String>();
211211

212212
if (command == "reboot") {
@@ -220,31 +220,33 @@ void parse_serial_commands() {
220220
}
221221

222222
// Handle device settings updates
223-
if (doc.containsKey("settings")) {
224-
JsonObject settings = doc["settings"];
223+
if (!doc["settings"].isNull()) {
224+
JsonObject settings = doc["settings"].as<JsonObject>();
225225

226-
if (settings.containsKey("screen_rot")) {
227-
deviceData.screen_rotation = settings["screen_rot"].as<unsigned int>();
228-
}
226+
if (!settings.isNull()) {
227+
if (!settings["screen_rot"].isNull()) {
228+
deviceData.screen_rotation = settings["screen_rot"].as<unsigned int>();
229+
}
229230

230-
if (settings.containsKey("sea_pressure")) {
231-
deviceData.sea_pressure = settings["sea_pressure"].as<float>();
232-
}
231+
if (!settings["sea_pressure"].isNull()) {
232+
deviceData.sea_pressure = settings["sea_pressure"].as<float>();
233+
}
233234

234-
if (settings.containsKey("metric_temp")) {
235-
deviceData.metric_temp = settings["metric_temp"].as<bool>();
236-
}
235+
if (!settings["metric_temp"].isNull()) {
236+
deviceData.metric_temp = settings["metric_temp"].as<bool>();
237+
}
237238

238-
if (settings.containsKey("metric_alt")) {
239-
deviceData.metric_alt = settings["metric_alt"].as<bool>();
240-
}
239+
if (!settings["metric_alt"].isNull()) {
240+
deviceData.metric_alt = settings["metric_alt"].as<bool>();
241+
}
241242

242-
if (settings.containsKey("performance_mode")) {
243-
deviceData.performance_mode = settings["performance_mode"].as<int>();
244-
}
243+
if (!settings["performance_mode"].isNull()) {
244+
deviceData.performance_mode = settings["performance_mode"].as<int>();
245+
}
245246

246-
if (settings.containsKey("theme")) {
247-
deviceData.theme = settings["theme"].as<int>();
247+
if (!settings["theme"].isNull()) {
248+
deviceData.theme = settings["theme"].as<int>();
249+
}
248250
}
249251

250252
sanitizeDeviceData();

0 commit comments

Comments
 (0)