Skip to content

Commit

Permalink
Non-effect preset should not unload playlist.
Browse files Browse the repository at this point in the history
  • Loading branch information
blazoncek committed Feb 2, 2022
1 parent d31271f commit 09bcf34
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);};
Expand Down
5 changes: 2 additions & 3 deletions wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 8 additions & 3 deletions wled00/presets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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."));
Expand All @@ -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);
}

Expand All @@ -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)]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09bcf34

Please sign in to comment.