kopia lustrzana https://github.com/Aircoookie/WLED
Progress with parsers
rodzic
8ddae6bba0
commit
d9050dd8b9
|
@ -12,14 +12,22 @@ void getStringFromJson(char* dest, const char* src, size_t len) {
|
||||||
if (src != nullptr) strlcpy(dest, src, len);
|
if (src != nullptr) strlcpy(dest, src, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deserializeSettings() {
|
void deserializeConfig() {
|
||||||
|
bool fromeep = false;
|
||||||
|
bool success = deserializeConfigSec();
|
||||||
|
if (!success) { //if file does not exist, try reading from EEPROM
|
||||||
|
loadSettingsFromEEPROM();
|
||||||
|
fromeep = true;
|
||||||
|
}
|
||||||
|
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
|
|
||||||
DEBUG_PRINTLN(F("Reading settings from /cfg.json..."));
|
DEBUG_PRINTLN(F("Reading settings from /cfg.json..."));
|
||||||
|
|
||||||
bool success = readObjectFromFile("/cfg.json", nullptr, &doc);
|
success = readObjectFromFile("/cfg.json", nullptr, &doc);
|
||||||
if (!success) { //if file does not exist, try reading from EEPROM
|
if (!success) { //if file does not exist, try reading from EEPROM
|
||||||
loadSettingsFromEEPROM();
|
if (!fromeep) deEEP();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//deserializeJson(doc, json);
|
//deserializeJson(doc, json);
|
||||||
|
@ -298,7 +306,7 @@ void deserializeSettings() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void serializeSettings() {
|
void serializeConfig() {
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
|
|
||||||
JsonArray rev = doc.createNestedArray("rev");
|
JsonArray rev = doc.createNestedArray("rev");
|
||||||
|
@ -561,7 +569,7 @@ void serializeSettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//settings in /wsec.json, not accessible via webserver, for passwords and tokens
|
//settings in /wsec.json, not accessible via webserver, for passwords and tokens
|
||||||
void deserializeSettingsSec() {
|
bool deserializeConfigSec() {
|
||||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||||
|
|
||||||
JsonObject nw_ins_0 = doc["nw"]["ins"][0];
|
JsonObject nw_ins_0 = doc["nw"]["ins"][0];
|
||||||
|
@ -570,15 +578,25 @@ void deserializeSettingsSec() {
|
||||||
JsonObject ap = doc["ap"];
|
JsonObject ap = doc["ap"];
|
||||||
getStringFromJson(apPass, ap["psk"] , 65);
|
getStringFromJson(apPass, ap["psk"] , 65);
|
||||||
|
|
||||||
//mqtt pass
|
JsonObject interfaces = doc["if"];
|
||||||
|
|
||||||
//blynk token
|
const char* apikey = interfaces["blynk"]["token"] | "Hidden";
|
||||||
|
int tdd = strnlen(apikey, 36);
|
||||||
|
if (tdd > 20 || tdd == 0)
|
||||||
|
getStringFromJson(blynkApiKey, apikey, 36);
|
||||||
|
|
||||||
//hue token
|
JsonObject if_mqtt = interfaces["mqtt"];
|
||||||
|
getStringFromJson(mqttPass, if_mqtt["psk"], 41);
|
||||||
|
|
||||||
//ota pass
|
getStringFromJson(hueApiKey, interfaces["hue"]["key"], 47);
|
||||||
|
|
||||||
|
JsonObject ota = doc["ota"];
|
||||||
|
getStringFromJson(otaPass, ota["pwd"], 33);
|
||||||
|
CJSON(otaLock, ota["lock"]);
|
||||||
|
CJSON(wifiLock, ota["lock-wifi"]);
|
||||||
|
CJSON(aOtaEnabled, ota["aota"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serializeSettingsSec() {
|
void serializeConfigSec() {
|
||||||
|
|
||||||
}
|
}
|
|
@ -25,6 +25,12 @@ bool isButtonPressed();
|
||||||
void handleButton();
|
void handleButton();
|
||||||
void handleIO();
|
void handleIO();
|
||||||
|
|
||||||
|
//cfg.cpp
|
||||||
|
void deserializeConfig();
|
||||||
|
bool deserializeConfigSec();
|
||||||
|
void serializeConfig();
|
||||||
|
void serializeConfigSec();
|
||||||
|
|
||||||
//colors.cpp
|
//colors.cpp
|
||||||
void colorFromUint32(uint32_t in, bool secondary = false);
|
void colorFromUint32(uint32_t in, bool secondary = false);
|
||||||
void colorFromUint24(uint32_t in, bool secondary = false);
|
void colorFromUint24(uint32_t in, bool secondary = false);
|
||||||
|
@ -209,6 +215,7 @@ void loadMacro(byte index, char* m);
|
||||||
void applyMacro(byte index);
|
void applyMacro(byte index);
|
||||||
void saveMacro(byte index, const String& mc, bool persist = true); //only commit on single save, not in settings
|
void saveMacro(byte index, const String& mc, bool persist = true); //only commit on single save, not in settings
|
||||||
void deEEP();
|
void deEEP();
|
||||||
|
void deEEPSettings();
|
||||||
|
|
||||||
//wled_serial.cpp
|
//wled_serial.cpp
|
||||||
void handleSerial();
|
void handleSerial();
|
||||||
|
|
|
@ -172,33 +172,33 @@ void WLED::setup()
|
||||||
DEBUG_PRINTLN(ESP.getFreeHeap());
|
DEBUG_PRINTLN(ESP.getFreeHeap());
|
||||||
registerUsermods();
|
registerUsermods();
|
||||||
|
|
||||||
strip.init(EEPROM.read(372), ledCount, EEPROM.read(2204)); // init LEDs quickly
|
//strip.init(EEPROM.read(372), ledCount, EEPROM.read(2204)); // init LEDs quickly
|
||||||
strip.setBrightness(0);
|
//strip.setBrightness(0);
|
||||||
|
|
||||||
DEBUG_PRINT(F("LEDs inited. heap usage ~"));
|
//DEBUG_PRINT(F("LEDs inited. heap usage ~"));
|
||||||
DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap());
|
//DEBUG_PRINTLN(heapPreAlloc - ESP.getFreeHeap());
|
||||||
|
|
||||||
#ifndef WLED_DISABLE_FILESYSTEM
|
|
||||||
bool fsinit = false;
|
bool fsinit = false;
|
||||||
DEBUGFS_PRINTLN(F("Mount FS"));
|
DEBUGFS_PRINTLN(F("Mount FS"));
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
fsinit = WLED_FS.begin(true);
|
fsinit = WLED_FS.begin(true);
|
||||||
#else
|
#else
|
||||||
fsinit = WLED_FS.begin();
|
fsinit = WLED_FS.begin();
|
||||||
#endif
|
|
||||||
if (!fsinit) {
|
|
||||||
DEBUGFS_PRINTLN(F("FS failed!"));
|
|
||||||
errorFlag = ERR_FS_BEGIN;
|
|
||||||
} else deEEP();
|
|
||||||
updateFSInfo();
|
|
||||||
#endif
|
#endif
|
||||||
|
if (!fsinit) {
|
||||||
|
DEBUGFS_PRINTLN(F("FS failed!"));
|
||||||
|
errorFlag = ERR_FS_BEGIN;
|
||||||
|
} else deEEP();
|
||||||
|
updateFSInfo();
|
||||||
|
deserializeConfig();
|
||||||
|
|
||||||
#if STATUSLED && STATUSLED != LEDPIN
|
#if STATUSLED && STATUSLED != LEDPIN
|
||||||
pinMode(STATUSLED, OUTPUT);
|
pinMode(STATUSLED, OUTPUT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DEBUG_PRINTLN(F("Load EEPROM"));
|
//DEBUG_PRINTLN(F("Load EEPROM"));
|
||||||
loadSettingsFromEEPROM();
|
//loadSettingsFromEEPROM();
|
||||||
beginStrip();
|
beginStrip();
|
||||||
userSetup();
|
userSetup();
|
||||||
usermods.setup();
|
usermods.setup();
|
||||||
|
@ -252,6 +252,8 @@ void WLED::setup()
|
||||||
void WLED::beginStrip()
|
void WLED::beginStrip()
|
||||||
{
|
{
|
||||||
// Initialize NeoPixel Strip and button
|
// Initialize NeoPixel Strip and button
|
||||||
|
strip.init(useRGBW, ledCount, skipFirstLed);
|
||||||
|
strip.setBrightness(0);
|
||||||
strip.setShowCallback(handleOverlayDraw);
|
strip.setShowCallback(handleOverlayDraw);
|
||||||
|
|
||||||
#ifdef BTNPIN
|
#ifdef BTNPIN
|
||||||
|
|
|
@ -790,7 +790,7 @@ void deEEP() {
|
||||||
JsonObject sObj = dDoc.to<JsonObject>();
|
JsonObject sObj = dDoc.to<JsonObject>();
|
||||||
sObj.createNestedObject("0");
|
sObj.createNestedObject("0");
|
||||||
|
|
||||||
//EEPROM.begin(EEPSIZE);
|
EEPROM.begin(EEPSIZE);
|
||||||
if (EEPROM.read(233) == 233) { //valid EEPROM save
|
if (EEPROM.read(233) == 233) { //valid EEPROM save
|
||||||
for (uint16_t index = 1; index <= 16; index++) { //copy presets to presets.json
|
for (uint16_t index = 1; index <= 16; index++) { //copy presets to presets.json
|
||||||
uint16_t i = 380 + index*20;
|
uint16_t i = 380 + index*20;
|
||||||
|
@ -861,7 +861,7 @@ void deEEP() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//EEPROM.end();
|
EEPROM.end();
|
||||||
|
|
||||||
File f = WLED_FS.open("/presets.json", "w");
|
File f = WLED_FS.open("/presets.json", "w");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
@ -871,4 +871,13 @@ void deEEP() {
|
||||||
serializeJson(dDoc, f);
|
serializeJson(dDoc, f);
|
||||||
f.close();
|
f.close();
|
||||||
DEBUG_PRINTLN(F("deEEP complete!"));
|
DEBUG_PRINTLN(F("deEEP complete!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deEEPSettings() {
|
||||||
|
DEBUG_PRINTLN(F("Restore settings from EEPROM"));
|
||||||
|
EEPROM.begin(EEPSIZE);
|
||||||
|
loadSettingsFromEEPROM();
|
||||||
|
EEPROM.end();
|
||||||
|
|
||||||
|
serializeConfig();
|
||||||
}
|
}
|
Ładowanie…
Reference in New Issue