mirror of
https://github.com/wled/WLED.git
synced 2025-04-19 12:27:17 +00:00
Separate FS write from serializeConfig
Break the actual JSON assembly apart from the file writing code. This permits calling it in other contexts, allowing us to pull the live config data even if the filesystem is out of date.
This commit is contained in:
parent
a0d1a8cbc4
commit
e21a09cec9
@ -671,7 +671,7 @@ void deserializeConfigFromFS() {
|
||||
// call readFromConfig() with an empty object so that usermods can initialize to defaults prior to saving
|
||||
JsonObject empty = JsonObject();
|
||||
UsermodManager::readFromConfig(empty);
|
||||
serializeConfig();
|
||||
serializeConfigToFS();
|
||||
// init Ethernet (in case default type is set at compile time)
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
|
||||
initEthernet();
|
||||
@ -685,10 +685,10 @@ void deserializeConfigFromFS() {
|
||||
bool needsSave = deserializeConfig(root, true);
|
||||
releaseJSONBufferLock();
|
||||
|
||||
if (needsSave) serializeConfig(); // usermods required new parameters
|
||||
if (needsSave) serializeConfigToFS(); // usermods required new parameters
|
||||
}
|
||||
|
||||
void serializeConfig() {
|
||||
void serializeConfigToFS() {
|
||||
serializeConfigSec();
|
||||
|
||||
DEBUG_PRINTLN(F("Writing settings to /cfg.json..."));
|
||||
@ -697,6 +697,17 @@ void serializeConfig() {
|
||||
|
||||
JsonObject root = pDoc->to<JsonObject>();
|
||||
|
||||
serializeConfig(root);
|
||||
|
||||
File f = WLED_FS.open(FPSTR(s_cfg_json), "w");
|
||||
if (f) serializeJson(root, f);
|
||||
f.close();
|
||||
releaseJSONBufferLock();
|
||||
|
||||
doSerializeConfig = false;
|
||||
}
|
||||
|
||||
void serializeConfig(JsonObject root) {
|
||||
JsonArray rev = root.createNestedArray("rev");
|
||||
rev.add(1); //major settings revision
|
||||
rev.add(0); //minor settings revision
|
||||
@ -1111,13 +1122,6 @@ void serializeConfig() {
|
||||
|
||||
JsonObject usermods_settings = root.createNestedObject("um");
|
||||
UsermodManager::addToConfig(usermods_settings);
|
||||
|
||||
File f = WLED_FS.open(FPSTR(s_cfg_json), "w");
|
||||
if (f) serializeJson(root, f);
|
||||
f.close();
|
||||
releaseJSONBufferLock();
|
||||
|
||||
doSerializeConfig = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,7 +27,8 @@ void IRAM_ATTR touchButtonISR();
|
||||
bool deserializeConfig(JsonObject doc, bool fromFS = false);
|
||||
void deserializeConfigFromFS();
|
||||
bool deserializeConfigSec();
|
||||
void serializeConfig();
|
||||
void serializeConfig(JsonObject doc);
|
||||
void serializeConfigToFS();
|
||||
void serializeConfigSec();
|
||||
|
||||
template<typename DestType>
|
||||
|
@ -272,5 +272,5 @@ void parseWiFiCommand(char* rpcData) {
|
||||
improvActive = 2;
|
||||
|
||||
forceReconnect = true;
|
||||
serializeConfig();
|
||||
serializeConfigToFS();
|
||||
}
|
@ -200,7 +200,7 @@ void WLED::loop()
|
||||
loadLedmap = -1;
|
||||
}
|
||||
yield();
|
||||
if (doSerializeConfig) serializeConfig();
|
||||
if (doSerializeConfig) serializeConfigToFS();
|
||||
|
||||
yield();
|
||||
handleWs();
|
||||
|
Loading…
x
Reference in New Issue
Block a user