Skip to content

Commit acfbe89

Browse files
committed
suspend playlist engine while auto-change is active
* adding suspendPlaylist() to playlist engine code * autoplaylist usermod calls suspendPlaylist() before switching to another preset * fix a potential overflow on `lfc` (uint8_t -> uint16_t)
1 parent 11315a8 commit acfbe89

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

usermods/usermod_v2_auto_playlist/usermod_v2_auto_playlist.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class AutoPlaylistUsermod : public Usermod {
113113

114114
energy /= ENERGY_SCALE; // scale down so we get 0 sometimes
115115

116-
uint8_t lfc = float(fftResult[0]) * fftDeScaler[0] / 0.85f; // might as well undo pink noise here too.
116+
uint16_t lfc = float(fftResult[0]) * fftDeScaler[0] / 0.85f; // might as well undo pink noise here too.
117117
uint16_t zcr = *(uint16_t*)um_data->u_data[11];
118118

119119
// WLED-MM/TroyHacks: Calculate the long- and short-running averages
@@ -244,8 +244,7 @@ class AutoPlaylistUsermod : public Usermod {
244244
// go into freefall - this logic stops that from triggering right
245245
// after change_lockout. Better for smaller change_lockout values.
246246

247-
// SH7: this method is sub-optimal, as its interfering with the "playlist" engine
248-
// we shoud find a better method for triggering playlist changes
247+
suspendPlaylist(); // suspend the playlist engine before changing to another preset
249248
applyPreset(newpreset);
250249

251250
#ifdef USERMOD_AUTO_PLAYLIST_DEBUG

wled00/fcn_declare.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ void _overlayAnalogCountdown();
208208
void _overlayAnalogClock();
209209

210210
//playlist.cpp
211+
void suspendPlaylist(); // WLEDMM support function for auto playlist usermod
211212
void shufflePlaylist();
212213
void unloadPlaylist();
213214
int16_t loadPlaylist(JsonObject playlistObject, byte presetId = 0);

wled00/playlist.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ void shufflePlaylist() {
4141
DEBUG_PRINTLN(F("Playlist shuffle."));
4242
}
4343

44+
// WLEDMM supporting function for auto_playlist usermod
45+
// prevents the active playlist from progressing (until it gets unloaded)
46+
static bool playlistSuspended = false;
47+
void suspendPlaylist() {
48+
playlistSuspended = true;
49+
}
4450

4551
void unloadPlaylist() {
4652
if (playlistEntries != nullptr) {
@@ -49,6 +55,7 @@ void unloadPlaylist() {
4955
}
5056
currentPlaylist = playlistIndex = -1;
5157
playlistLen = playlistEntryDur = playlistOptions = 0;
58+
playlistSuspended = false; // WLEDMM
5259
DEBUG_PRINTLN(F("Playlist unloaded."));
5360
}
5461

@@ -125,6 +132,11 @@ void handlePlaylist() {
125132
// if fileDoc is not null JSON buffer is in use so just quit
126133
if (currentPlaylist < 0 || playlistEntries == nullptr || fileDoc != nullptr) return;
127134

135+
if (playlistSuspended) { // WLEDMM
136+
if (millis() - presetCycledTime > (100*playlistEntryDur)) presetCycledTime = millis(); // keep updating timer
137+
return; // but don't progress to next extry, and don't shuffle
138+
}
139+
128140
if (millis() - presetCycledTime > (100*playlistEntryDur)) {
129141
presetCycledTime = millis();
130142
if (bri == 0 || nightlightActive) return;

0 commit comments

Comments
 (0)