Skip to content

Commit b8de36b

Browse files
committed
Cleanup
1 parent 90808ac commit b8de36b

File tree

2 files changed

+3
-45
lines changed

2 files changed

+3
-45
lines changed

wled00/json.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ bool deserializeState(JsonObject root)
279279

280280
JsonObject playlist = root[F("playlist")];
281281
if (!playlist.isNull()) {
282-
loadPlaylist(playlist); //return stateResponse;
282+
loadPlaylist(playlist);
283+
noNotification = true; //do not notify both for this request and the first playlist entry
283284
}
284285

285286
colorUpdated(noNotification ? NOTIFIER_CALL_MODE_NO_NOTIFY : NOTIFIER_CALL_MODE_DIRECT_CHANGE);

wled00/playlist.cpp

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,6 @@ void shufflePlaylist() {
3434
}
3535
}
3636

37-
/*
38-
* The same thing as saving and loading playlist can be achieved using JSON API saved in a preset.
39-
*
40-
void deserializePlaylist() {
41-
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
42-
43-
DEBUG_PRINTLN(F("Reading playlist from /playlist.json..."));
44-
45-
if (!readObjectFromFile("/playlist.json", nullptr, &doc)) return; //if file does not exist just exit
46-
47-
JsonObject playlist = doc[F("playlist")];
48-
if (!playlist.isNull()) loadPlaylist(playlist);
49-
}
50-
51-
52-
void serializePlaylist() {
53-
DynamicJsonDocument doc(JSON_BUFFER_SIZE/8); // we don't need big buffer (>1k is ok)
54-
55-
DEBUG_PRINTLN(F("Writing playlist to /playlist.json..."));
56-
57-
PlaylistEntry* entries = reinterpret_cast<PlaylistEntry*>(playlistEntries);
58-
59-
JsonObject playlist = doc.createNestedObject(F("playlist"));
60-
JsonArray ps = playlist.createNestedArray(F("ps"));
61-
JsonArray dur = playlist.createNestedArray(F("dur"));
62-
JsonArray tr = playlist.createNestedArray(F("transition"));
63-
for (uint8_t i=0; i<playlistLen; i++) {
64-
ps.add(entries[i].preset);
65-
dur.add(entries[i].dur);
66-
tr.add(entries[i].tr);
67-
}
68-
playlist[F("repeat")] = playlistRepeat; // TODO: this one is decreasing with each loop
69-
playlist[F("end")] = playlistEndPreset;
70-
71-
File f = WLED_FS.open("/playlist.json", "w");
72-
if (f) serializeJson(doc, f);
73-
f.close();
74-
}
75-
*/
76-
7737
void unloadPlaylist() {
7838
if (playlistEntries != nullptr) {
7939
delete[] playlistEntries;
@@ -84,7 +44,6 @@ void unloadPlaylist() {
8444
}
8545

8646
void loadPlaylist(JsonObject playlistObj) {
87-
8847
unloadPlaylist();
8948

9049
JsonArray presets = playlistObj["ps"];
@@ -147,9 +106,7 @@ void handlePlaylist() {
147106
++playlistIndex %= playlistLen; // -1 at 1st run (limit to playlistLen)
148107

149108
if (!playlistRepeat && !playlistIndex) { //stop if repeat == 0 and restart of playlist
150-
currentPlaylist = -1;
151-
delete[] playlistEntries;
152-
playlistEntries = nullptr;
109+
unloadPlaylist();
153110
if (playlistEndPreset) applyPreset(playlistEndPreset);
154111
return;
155112
}

0 commit comments

Comments
 (0)