forked from Aircoookie/WLED
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9050dd
commit 3ff23ad
Showing
13 changed files
with
155 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "wled.h" | ||
|
||
/* | ||
* Methods to handle saving and loading presets to/from the filesystem | ||
*/ | ||
|
||
bool applyPreset(byte index) | ||
{ | ||
if (fileDoc) { | ||
errorFlag = readObjectFromFileUsingId("/presets.json", index, fileDoc) ? ERR_NONE : ERR_FS_PLOAD; | ||
#ifdef WLED_DEBUG_FS | ||
serializeJson(*fileDoc, Serial); | ||
#endif | ||
deserializeState(fileDoc->as<JsonObject>()); | ||
} else { | ||
DEBUGFS_PRINTLN(F("Make read buf")); | ||
DynamicJsonDocument fDoc(JSON_BUFFER_SIZE); | ||
errorFlag = readObjectFromFileUsingId("/presets.json", index, &fDoc) ? ERR_NONE : ERR_FS_PLOAD; | ||
#ifdef WLED_DEBUG_FS | ||
serializeJson(fDoc, Serial); | ||
#endif | ||
deserializeState(fDoc.as<JsonObject>()); | ||
} | ||
|
||
if (!errorFlag) { | ||
currentPreset = index; | ||
isPreset = true; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj) | ||
{ | ||
if (index == 0) return; | ||
bool docAlloc = fileDoc; | ||
JsonObject sObj = saveobj; | ||
|
||
if (!docAlloc) { | ||
DEBUGFS_PRINTLN(F("Allocating saving buffer")); | ||
fileDoc = new DynamicJsonDocument(JSON_BUFFER_SIZE); | ||
sObj = fileDoc->to<JsonObject>(); | ||
if (pname) sObj["n"] = pname; | ||
} else { | ||
DEBUGFS_PRINTLN(F("Reuse recv buffer")); | ||
sObj.remove(F("psave")); | ||
sObj.remove(F("v")); | ||
} | ||
|
||
if (!sObj["o"]) { | ||
DEBUGFS_PRINTLN(F("Save current state")); | ||
serializeState(sObj, true, sObj["ib"], sObj["sb"]); | ||
currentPreset = index; | ||
} | ||
sObj.remove("o"); | ||
sObj.remove("ib"); | ||
sObj.remove("sb"); | ||
sObj.remove(F("error")); | ||
sObj.remove(F("time")); | ||
|
||
writeObjectToFileUsingId("/presets.json", index, fileDoc); | ||
if (!docAlloc) delete fileDoc; | ||
presetsModifiedTime = now(); //unix time | ||
updateFSInfo(); | ||
} | ||
|
||
void deletePreset(byte index) { | ||
StaticJsonDocument<24> empty; | ||
writeObjectToFileUsingId("/presets.json", index, &empty); | ||
presetsModifiedTime = now(); //unix time | ||
updateFSInfo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.