Cleanup
This commit is contained in:
parent
90808ac67e
commit
b8de36b340
@ -279,7 +279,8 @@ bool deserializeState(JsonObject root)
|
||||
|
||||
JsonObject playlist = root[F("playlist")];
|
||||
if (!playlist.isNull()) {
|
||||
loadPlaylist(playlist); //return stateResponse;
|
||||
loadPlaylist(playlist);
|
||||
noNotification = true; //do not notify both for this request and the first playlist entry
|
||||
}
|
||||
|
||||
colorUpdated(noNotification ? NOTIFIER_CALL_MODE_NO_NOTIFY : NOTIFIER_CALL_MODE_DIRECT_CHANGE);
|
||||
|
@ -34,46 +34,6 @@ void shufflePlaylist() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The same thing as saving and loading playlist can be achieved using JSON API saved in a preset.
|
||||
*
|
||||
void deserializePlaylist() {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
|
||||
DEBUG_PRINTLN(F("Reading playlist from /playlist.json..."));
|
||||
|
||||
if (!readObjectFromFile("/playlist.json", nullptr, &doc)) return; //if file does not exist just exit
|
||||
|
||||
JsonObject playlist = doc[F("playlist")];
|
||||
if (!playlist.isNull()) loadPlaylist(playlist);
|
||||
}
|
||||
|
||||
|
||||
void serializePlaylist() {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE/8); // we don't need big buffer (>1k is ok)
|
||||
|
||||
DEBUG_PRINTLN(F("Writing playlist to /playlist.json..."));
|
||||
|
||||
PlaylistEntry* entries = reinterpret_cast<PlaylistEntry*>(playlistEntries);
|
||||
|
||||
JsonObject playlist = doc.createNestedObject(F("playlist"));
|
||||
JsonArray ps = playlist.createNestedArray(F("ps"));
|
||||
JsonArray dur = playlist.createNestedArray(F("dur"));
|
||||
JsonArray tr = playlist.createNestedArray(F("transition"));
|
||||
for (uint8_t i=0; i<playlistLen; i++) {
|
||||
ps.add(entries[i].preset);
|
||||
dur.add(entries[i].dur);
|
||||
tr.add(entries[i].tr);
|
||||
}
|
||||
playlist[F("repeat")] = playlistRepeat; // TODO: this one is decreasing with each loop
|
||||
playlist[F("end")] = playlistEndPreset;
|
||||
|
||||
File f = WLED_FS.open("/playlist.json", "w");
|
||||
if (f) serializeJson(doc, f);
|
||||
f.close();
|
||||
}
|
||||
*/
|
||||
|
||||
void unloadPlaylist() {
|
||||
if (playlistEntries != nullptr) {
|
||||
delete[] playlistEntries;
|
||||
@ -84,7 +44,6 @@ void unloadPlaylist() {
|
||||
}
|
||||
|
||||
void loadPlaylist(JsonObject playlistObj) {
|
||||
|
||||
unloadPlaylist();
|
||||
|
||||
JsonArray presets = playlistObj["ps"];
|
||||
@ -147,9 +106,7 @@ void handlePlaylist() {
|
||||
++playlistIndex %= playlistLen; // -1 at 1st run (limit to playlistLen)
|
||||
|
||||
if (!playlistRepeat && !playlistIndex) { //stop if repeat == 0 and restart of playlist
|
||||
currentPlaylist = -1;
|
||||
delete[] playlistEntries;
|
||||
playlistEntries = nullptr;
|
||||
unloadPlaylist();
|
||||
if (playlistEndPreset) applyPreset(playlistEndPreset);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user