mirror of
https://github.com/wled/WLED.git
synced 2025-07-22 18:26:32 +00:00
Implemented temporary presets.
This commit is contained in:
parent
aef53a8753
commit
9c295d1884
@ -184,7 +184,9 @@ void handlePlaylist();
|
|||||||
|
|
||||||
//presets.cpp
|
//presets.cpp
|
||||||
bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE);
|
bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE);
|
||||||
|
inline bool applyTemporaryPreset() {return applyPreset(255);};
|
||||||
void savePreset(byte index, bool persist = true, const char* pname = nullptr, JsonObject saveobj = JsonObject());
|
void savePreset(byte index, bool persist = true, const char* pname = nullptr, JsonObject saveobj = JsonObject());
|
||||||
|
inline void saveTemporaryPreset() {savePreset(255, false);};
|
||||||
void deletePreset(byte index);
|
void deletePreset(byte index);
|
||||||
|
|
||||||
//set.cpp
|
//set.cpp
|
||||||
|
@ -7,8 +7,11 @@
|
|||||||
bool applyPreset(byte index, byte callMode)
|
bool applyPreset(byte index, byte callMode)
|
||||||
{
|
{
|
||||||
if (index == 0) return false;
|
if (index == 0) return false;
|
||||||
|
|
||||||
|
const char *filename = index < 255 ? "/presets.json" : "/tmp.json";
|
||||||
|
|
||||||
if (fileDoc) {
|
if (fileDoc) {
|
||||||
errorFlag = readObjectFromFileUsingId("/presets.json", index, fileDoc) ? ERR_NONE : ERR_FS_PLOAD;
|
errorFlag = readObjectFromFileUsingId(filename, index, fileDoc) ? ERR_NONE : ERR_FS_PLOAD;
|
||||||
JsonObject fdo = fileDoc->as<JsonObject>();
|
JsonObject fdo = fileDoc->as<JsonObject>();
|
||||||
if (fdo["ps"] == index) fdo.remove("ps"); //remove load request for same presets to prevent recursive crash
|
if (fdo["ps"] == index) fdo.remove("ps"); //remove load request for same presets to prevent recursive crash
|
||||||
#ifdef WLED_DEBUG_FS
|
#ifdef WLED_DEBUG_FS
|
||||||
@ -18,7 +21,7 @@ bool applyPreset(byte index, byte callMode)
|
|||||||
} else {
|
} else {
|
||||||
DEBUGFS_PRINTLN(F("Make read buf"));
|
DEBUGFS_PRINTLN(F("Make read buf"));
|
||||||
DynamicJsonDocument fDoc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument fDoc(JSON_BUFFER_SIZE);
|
||||||
errorFlag = readObjectFromFileUsingId("/presets.json", index, &fDoc) ? ERR_NONE : ERR_FS_PLOAD;
|
errorFlag = readObjectFromFileUsingId(filename, index, &fDoc) ? ERR_NONE : ERR_FS_PLOAD;
|
||||||
JsonObject fdo = fDoc.as<JsonObject>();
|
JsonObject fdo = fDoc.as<JsonObject>();
|
||||||
if (fdo["ps"] == index) fdo.remove("ps");
|
if (fdo["ps"] == index) fdo.remove("ps");
|
||||||
#ifdef WLED_DEBUG_FS
|
#ifdef WLED_DEBUG_FS
|
||||||
@ -28,19 +31,20 @@ bool applyPreset(byte index, byte callMode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!errorFlag) {
|
if (!errorFlag) {
|
||||||
currentPreset = index;
|
if (index < 255) currentPreset = index;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//persist=false is not currently honored
|
|
||||||
void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj)
|
void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj)
|
||||||
{
|
{
|
||||||
if (index == 0 || index > 250) return;
|
if (index == 0 || (index > 250 && persist) || (index<255 && !persist)) return;
|
||||||
bool docAlloc = (fileDoc != nullptr);
|
bool docAlloc = (fileDoc != nullptr);
|
||||||
JsonObject sObj = saveobj;
|
JsonObject sObj = saveobj;
|
||||||
|
|
||||||
|
const char *filename = persist ? "/presets.json" : "/tmp.json";
|
||||||
|
|
||||||
if (!docAlloc) {
|
if (!docAlloc) {
|
||||||
DEBUGFS_PRINTLN(F("Allocating saving buffer"));
|
DEBUGFS_PRINTLN(F("Allocating saving buffer"));
|
||||||
DynamicJsonDocument lDoc(JSON_BUFFER_SIZE);
|
DynamicJsonDocument lDoc(JSON_BUFFER_SIZE);
|
||||||
@ -48,9 +52,9 @@ void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj)
|
|||||||
if (pname) sObj["n"] = pname;
|
if (pname) sObj["n"] = pname;
|
||||||
DEBUGFS_PRINTLN(F("Save current state"));
|
DEBUGFS_PRINTLN(F("Save current state"));
|
||||||
serializeState(sObj, true);
|
serializeState(sObj, true);
|
||||||
currentPreset = index;
|
if (persist) currentPreset = index;
|
||||||
|
|
||||||
writeObjectToFileUsingId("/presets.json", index, &lDoc);
|
writeObjectToFileUsingId(filename, index, &lDoc);
|
||||||
} else { //from JSON API
|
} else { //from JSON API
|
||||||
DEBUGFS_PRINTLN(F("Reuse recv buffer"));
|
DEBUGFS_PRINTLN(F("Reuse recv buffer"));
|
||||||
sObj.remove(F("psave"));
|
sObj.remove(F("psave"));
|
||||||
@ -59,7 +63,7 @@ void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj)
|
|||||||
if (!sObj["o"]) {
|
if (!sObj["o"]) {
|
||||||
DEBUGFS_PRINTLN(F("Save current state"));
|
DEBUGFS_PRINTLN(F("Save current state"));
|
||||||
serializeState(sObj, true, sObj["ib"], sObj["sb"]);
|
serializeState(sObj, true, sObj["ib"], sObj["sb"]);
|
||||||
currentPreset = index;
|
if (persist) currentPreset = index;
|
||||||
}
|
}
|
||||||
sObj.remove("o");
|
sObj.remove("o");
|
||||||
sObj.remove("ib");
|
sObj.remove("ib");
|
||||||
@ -67,9 +71,9 @@ void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj)
|
|||||||
sObj.remove(F("error"));
|
sObj.remove(F("error"));
|
||||||
sObj.remove(F("time"));
|
sObj.remove(F("time"));
|
||||||
|
|
||||||
writeObjectToFileUsingId("/presets.json", index, fileDoc);
|
writeObjectToFileUsingId(filename, index, fileDoc);
|
||||||
}
|
}
|
||||||
presetsModifiedTime = toki.second(); //unix time
|
if (persist) presetsModifiedTime = toki.second(); //unix time
|
||||||
updateFSInfo();
|
updateFSInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// version code in format yymmddb (b = daily build)
|
||||||
#define VERSION 2110022
|
#define VERSION 2110041
|
||||||
|
|
||||||
//uncomment this if you have a "my_config.h" file you'd like to use
|
//uncomment this if you have a "my_config.h" file you'd like to use
|
||||||
//#define WLED_USE_MY_CONFIG
|
//#define WLED_USE_MY_CONFIG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user