This commit is contained in:
cschwinne 2021-03-13 22:46:08 +01:00
parent 90808ac67e
commit b8de36b340
2 changed files with 3 additions and 45 deletions

View File

@ -279,7 +279,8 @@ bool deserializeState(JsonObject root)
JsonObject playlist = root[F("playlist")]; JsonObject playlist = root[F("playlist")];
if (!playlist.isNull()) { 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); colorUpdated(noNotification ? NOTIFIER_CALL_MODE_NO_NOTIFY : NOTIFIER_CALL_MODE_DIRECT_CHANGE);

View File

@ -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() { void unloadPlaylist() {
if (playlistEntries != nullptr) { if (playlistEntries != nullptr) {
delete[] playlistEntries; delete[] playlistEntries;
@ -84,7 +44,6 @@ void unloadPlaylist() {
} }
void loadPlaylist(JsonObject playlistObj) { void loadPlaylist(JsonObject playlistObj) {
unloadPlaylist(); unloadPlaylist();
JsonArray presets = playlistObj["ps"]; JsonArray presets = playlistObj["ps"];
@ -147,9 +106,7 @@ void handlePlaylist() {
++playlistIndex %= playlistLen; // -1 at 1st run (limit to playlistLen) ++playlistIndex %= playlistLen; // -1 at 1st run (limit to playlistLen)
if (!playlistRepeat && !playlistIndex) { //stop if repeat == 0 and restart of playlist if (!playlistRepeat && !playlistIndex) { //stop if repeat == 0 and restart of playlist
currentPlaylist = -1; unloadPlaylist();
delete[] playlistEntries;
playlistEntries = nullptr;
if (playlistEndPreset) applyPreset(playlistEndPreset); if (playlistEndPreset) applyPreset(playlistEndPreset);
return; return;
} }