mirror of
https://github.com/wled/WLED.git
synced 2025-04-23 22:37:18 +00:00
Better fix for #4154
This commit is contained in:
parent
a60231ba59
commit
49f044ecde
@ -454,20 +454,25 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
|
||||
handleSet(nullptr, apireq, false); // may set stateChanged
|
||||
}
|
||||
|
||||
// applying preset (2 cases: a) API call includes all preset values ("pd"), b) API only specifies preset ID ("ps"))
|
||||
// Applying preset from JSON API has 2 cases: a) "pd" AKA "preset direct" and b) "ps" AKA "preset select"
|
||||
// a) "preset direct" can only be an integer value representing preset ID. "preset direct" assumes JSON API contains the rest of preset content (i.e. from UI call)
|
||||
// "preset direct" JSON can contain "ps" API (i.e. call from UI to cycle presets) in such case stateChanged has to be false (i.e. no "win" or "seg" API)
|
||||
// b) "preset select" can be cycling ("1~5~""), random ("r" or "1~5r"), ID, etc. value allowed from JSON API. This type of call assumes no state changing content in API call
|
||||
byte presetToRestore = 0;
|
||||
// a) already applied preset content (requires "seg" or "win" but will ignore the rest)
|
||||
if (!root[F("pd")].isNull() && stateChanged) {
|
||||
// a) already applied preset content (requires "seg" or "win" but will ignore the rest)
|
||||
currentPreset = root[F("pd")] | currentPreset;
|
||||
if (root["win"].isNull()) presetCycCurr = currentPreset; // otherwise it was set in handleSet() [set.cpp]
|
||||
if (root["win"].isNull()) presetCycCurr = currentPreset; // otherwise presetCycCurr was set in handleSet() [set.cpp]
|
||||
presetToRestore = currentPreset; // stateUpdated() will clear the preset, so we need to restore it after
|
||||
DEBUG_PRINTF_P(PSTR("Preset direct: %d\n"), currentPreset);
|
||||
} else if (!root["ps"].isNull()) {
|
||||
ps = presetCycCurr;
|
||||
if (root["win"].isNull() && getVal(root["ps"], &ps, 0, 0) && ps > 0 && ps < 251 && ps != currentPreset) {
|
||||
// we have "ps" call (i.e. from button or external API call) or "pd" that includes "ps" (i.e. from UI call)
|
||||
if (root["win"].isNull() && getVal(root["ps"], &presetCycCurr, 0, 0) && presetCycCurr > 0 && presetCycCurr < 251 && presetCycCurr != currentPreset) {
|
||||
DEBUG_PRINTF_P(PSTR("Preset select: %d\n"), presetCycCurr);
|
||||
// b) preset ID only or preset that does not change state (use embedded cycling limits if they exist in getVal())
|
||||
applyPreset(ps, callMode); // async load from file system (only preset ID was specified)
|
||||
applyPreset(presetCycCurr, callMode); // async load from file system (only preset ID was specified)
|
||||
return stateResponse;
|
||||
}
|
||||
} else presetCycCurr = currentPreset; // restore presetCycCurr
|
||||
}
|
||||
|
||||
JsonObject playlist = root[F("playlist")];
|
||||
|
@ -118,7 +118,7 @@ void initPresetsFile()
|
||||
bool applyPresetFromPlaylist(byte index)
|
||||
{
|
||||
DEBUG_PRINTF_P(PSTR("Request to apply preset: %d\n"), index);
|
||||
presetToApply = presetCycCurr = index;
|
||||
presetToApply = index;
|
||||
callModeToApply = CALL_MODE_DIRECT_CHANGE;
|
||||
return true;
|
||||
}
|
||||
@ -127,7 +127,7 @@ bool applyPreset(byte index, byte callMode)
|
||||
{
|
||||
unloadPlaylist(); // applying a preset unloads the playlist (#3827)
|
||||
DEBUG_PRINTF_P(PSTR("Request to apply preset: %u\n"), index);
|
||||
presetToApply = presetCycCurr = index;
|
||||
presetToApply = index;
|
||||
callModeToApply = callMode;
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user