Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an API parameter to allow the user to skip to the next preset in a playlist at any time #3946

Merged
merged 15 commits into from
May 3, 2024
2 changes: 1 addition & 1 deletion wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void _overlayAnalogClock();
void shufflePlaylist();
void unloadPlaylist();
int16_t loadPlaylist(JsonObject playlistObject, byte presetId = 0);
void handlePlaylist();
void handlePlaylist(bool skipNext=false);
void serializePlaylist(JsonObject obj);

//presets.cpp
Expand Down
6 changes: 5 additions & 1 deletion wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,11 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
strip.loadCustomPalettes();
}
}


if (root.containsKey(F("np")) && root[F("np")].as<bool>()) { //skip to next preset in a playlist
handlePlaylist(true);
softhack007 marked this conversation as resolved.
Show resolved Hide resolved
}

JsonObject wifi = root[F("wifi")];
if (!wifi.isNull()) {
bool apMode = getBoolVal(wifi[F("ap")], apActive);
Expand Down
4 changes: 2 additions & 2 deletions wled00/playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ int16_t loadPlaylist(JsonObject playlistObj, byte presetId) {
}


void handlePlaylist() {
void handlePlaylist(bool skipNext) {
static unsigned long presetCycledTime = 0;
if (currentPlaylist < 0 || playlistEntries == nullptr) return;

if (millis() - presetCycledTime > (100*playlistEntryDur)) {
if (millis() - presetCycledTime > (100 * playlistEntryDur) || skipNext) {
presetCycledTime = millis();
if (bri == 0 || nightlightActive) return;

Expand Down
3 changes: 3 additions & 0 deletions wled00/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,9 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
applyPreset(presetCycCurr);
}

pos = req.indexOf(F("NP")); //skips to next preset in a playlist
if (pos > 0) handlePlaylist(true);

//set brightness
updateVal(req.c_str(), "&A=", &bri);

Expand Down