rgbwifi/src/settings/system.cpp

63 lines
1.5 KiB
C++
Raw Normal View History

2020-09-19 17:24:34 +00:00
/*
* ESP8266 RGBW controller
* Copyright 2020 (c) Mark van Renswoude
*
* https://git.x2software.net/pub/RGBWifi
*/
#include "./system.h"
#include <ArduinoJson.h>
#include <FS.h>
#include "../debug.h"
#include "../global.h"
#include "../config.h"
void SystemSettings::toJson(Print &print)
{
DynamicJsonDocument jsonDocument(1024);
2020-09-19 17:24:34 +00:00
JsonObject pins = jsonDocument.createNestedObject("pins");
2020-09-19 17:24:34 +00:00
pins["ledAP"] = pinLEDAP();
pins["ledSTA"] = pinLEDSTA();
pins["apButton"] = pinAPButton();
2020-09-20 10:58:27 +00:00
jsonDocument["ledCount"] = ledCount();
serializeJson(jsonDocument, print);
2020-09-19 17:24:34 +00:00
}
bool SystemSettings::fromJson(JsonVariant &jsonDocument, bool* changed)
2020-09-19 17:24:34 +00:00
{
if (changed != nullptr)
*changed = false;
JsonObject pins = jsonDocument["pins"];
2020-09-19 17:24:34 +00:00
uint8_t jsonPinLEDAP = pins["ledAP"];
uint8_t jsonPinLEDSTA = pins["ledSTA"];
uint8_t jsonPinAPButton = pins["apButton"];
2020-09-20 10:58:27 +00:00
uint16_t jsonLEDCount = jsonDocument["ledCount"];
2020-09-19 17:24:34 +00:00
if (jsonPinLEDAP == 0) jsonPinLEDAP = pinLEDAP();
if (jsonPinLEDSTA == 0) jsonPinLEDSTA = pinLEDSTA();
if (jsonPinAPButton == 0) jsonPinAPButton = pinAPButton();
2020-09-20 10:58:27 +00:00
if (jsonLEDCount == 0) jsonLEDCount = ledCount();
2020-09-19 17:24:34 +00:00
if ((jsonPinLEDAP != pinLEDAP()) ||
(jsonPinLEDSTA != pinLEDSTA()) ||
2020-09-20 10:58:27 +00:00
(jsonPinAPButton != pinAPButton()) ||
(jsonLEDCount != ledCount()))
2020-09-19 17:24:34 +00:00
{
pinLEDAP(jsonPinLEDAP);
pinLEDSTA(jsonPinLEDSTA);
pinAPButton(jsonPinAPButton);
2020-09-20 10:58:27 +00:00
ledCount(jsonLEDCount);
2020-09-19 17:24:34 +00:00
if (changed != nullptr)
*changed = true;
}
return true;
}