Non-effect preset should not unload playlist.

This commit is contained in:
Blaz Kristan 2022-02-02 20:53:16 +01:00
parent d31271fee3
commit 09bcf34050
4 changed files with 12 additions and 8 deletions

View File

@ -195,7 +195,7 @@ void handlePlaylist();
//presets.cpp
void handlePresets();
bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE);
bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE, bool fromJson = false);
inline bool applyTemporaryPreset() {return applyPreset(255);};
void savePreset(byte index, bool persist = true, const char* pname = nullptr, JsonObject saveobj = JsonObject());
inline void saveTemporaryPreset() {savePreset(255, false);};

View File

@ -163,7 +163,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
if (getVal(elem["fx"], &fx, 1, strip.getModeCount())) { //load effect ('r' random, '~' inc/dec, 1-255 exact value)
if (!presetId && currentPlaylist>=0) unloadPlaylist();
strip.setMode(id, fx);
if (!presetId && seg.mode != fxPrev) effectChanged = true; //send UDP
if (!presetId && fx != fxPrev) effectChanged = true; //send UDP
}
byte prevSpd = seg.speed;
byte prevInt = seg.intensity;
@ -357,9 +357,8 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
ps = presetCycCurr;
if (getVal(root["ps"], &ps, presetCycMin, presetCycMax)) { //load preset (clears state request!)
if (!presetId) unloadPlaylist(); //stop playlist if preset changed manually
if (ps >= presetCycMin && ps <= presetCycMax) presetCycCurr = ps;
applyPreset(ps, callMode);
applyPreset(ps, callMode, true);
return stateResponse;
}

View File

@ -10,11 +10,13 @@ static char *tmpRAMbuffer = nullptr;
static volatile byte presetToApply = 0;
static volatile byte callModeToApply = 0;
static volatile bool checkPlaylist = false;
bool applyPreset(byte index, byte callMode)
bool applyPreset(byte index, byte callMode, bool fromJson)
{
presetToApply = index;
callModeToApply = callMode;
checkPlaylist = fromJson;
return true;
}
@ -23,7 +25,7 @@ void handlePresets()
if (presetToApply == 0 || fileDoc) return; //JSON buffer allocated (apply preset in next cycle) or no preset waiting
JsonObject fdo;
const char *filename = presetToApply < 255 ? "/presets.json" : "/tmp.json";
const char *filename = presetToApply < 255 ? PSTR("/presets.json") : PSTR("/tmp.json");
// allocate buffer
DEBUG_PRINTLN(F("Apply preset JSON buffer requested."));
@ -48,6 +50,8 @@ void handlePresets()
handleSet(nullptr, apireq, false);
} else {
fdo.remove("ps"); //remove load request for presets to prevent recursive crash
// if we applyPreset from JSON and preset contains "seg" we must unload playlist
if (checkPlaylist && !fdo["seg"].isNull()) unloadPlaylist();
deserializeState(fdo, CALL_MODE_NO_NOTIFY, presetToApply);
}
@ -68,6 +72,7 @@ void handlePresets()
presetToApply = 0; //clear request for preset
callModeToApply = 0;
checkPlaylist = false;
}
//called from handleSet(PS=) [network callback (fileDoc==nullptr), IR (irrational), deserializeState, UDP] and deserializeState() [network callback (filedoc!=nullptr)]
@ -78,7 +83,7 @@ void savePreset(byte index, bool persist, const char* pname, JsonObject saveobj)
JsonObject sObj = saveobj;
bool bufferAllocated = false;
const char *filename = persist ? "/presets.json" : "/tmp.json";
const char *filename = persist ? PSTR("/presets.json") : PSTR("/tmp.json");
if (!fileDoc) {
// called from handleSet() HTTP API

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2201311
#define VERSION 2202021
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG