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)
This commit is contained in:
@@ -113,7 +113,7 @@ class AutoPlaylistUsermod : public Usermod {
|
||||
|
||||
energy /= ENERGY_SCALE; // scale down so we get 0 sometimes
|
||||
|
||||
uint8_t lfc = float(fftResult[0]) * fftDeScaler[0] / 0.85f; // might as well undo pink noise here too.
|
||||
uint16_t lfc = float(fftResult[0]) * fftDeScaler[0] / 0.85f; // might as well undo pink noise here too.
|
||||
uint16_t zcr = *(uint16_t*)um_data->u_data[11];
|
||||
|
||||
// WLED-MM/TroyHacks: Calculate the long- and short-running averages
|
||||
@@ -244,8 +244,7 @@ class AutoPlaylistUsermod : public Usermod {
|
||||
// go into freefall - this logic stops that from triggering right
|
||||
// after change_lockout. Better for smaller change_lockout values.
|
||||
|
||||
// SH7: this method is sub-optimal, as its interfering with the "playlist" engine
|
||||
// we shoud find a better method for triggering playlist changes
|
||||
suspendPlaylist(); // suspend the playlist engine before changing to another preset
|
||||
applyPreset(newpreset);
|
||||
|
||||
#ifdef USERMOD_AUTO_PLAYLIST_DEBUG
|
||||
|
||||
@@ -208,6 +208,7 @@ void _overlayAnalogCountdown();
|
||||
void _overlayAnalogClock();
|
||||
|
||||
//playlist.cpp
|
||||
void suspendPlaylist(); // WLEDMM support function for auto playlist usermod
|
||||
void shufflePlaylist();
|
||||
void unloadPlaylist();
|
||||
int16_t loadPlaylist(JsonObject playlistObject, byte presetId = 0);
|
||||
|
||||
@@ -41,6 +41,12 @@ void shufflePlaylist() {
|
||||
DEBUG_PRINTLN(F("Playlist shuffle."));
|
||||
}
|
||||
|
||||
// WLEDMM supporting function for auto_playlist usermod
|
||||
// prevents the active playlist from progressing (until it gets unloaded)
|
||||
static bool playlistSuspended = false;
|
||||
void suspendPlaylist() {
|
||||
playlistSuspended = true;
|
||||
}
|
||||
|
||||
void unloadPlaylist() {
|
||||
if (playlistEntries != nullptr) {
|
||||
@@ -49,6 +55,7 @@ void unloadPlaylist() {
|
||||
}
|
||||
currentPlaylist = playlistIndex = -1;
|
||||
playlistLen = playlistEntryDur = playlistOptions = 0;
|
||||
playlistSuspended = false; // WLEDMM
|
||||
DEBUG_PRINTLN(F("Playlist unloaded."));
|
||||
}
|
||||
|
||||
@@ -125,6 +132,11 @@ void handlePlaylist() {
|
||||
// if fileDoc is not null JSON buffer is in use so just quit
|
||||
if (currentPlaylist < 0 || playlistEntries == nullptr || fileDoc != nullptr) return;
|
||||
|
||||
if (playlistSuspended) { // WLEDMM
|
||||
if (millis() - presetCycledTime > (100*playlistEntryDur)) presetCycledTime = millis(); // keep updating timer
|
||||
return; // but don't progress to next extry, and don't shuffle
|
||||
}
|
||||
|
||||
if (millis() - presetCycledTime > (100*playlistEntryDur)) {
|
||||
presetCycledTime = millis();
|
||||
if (bri == 0 || nightlightActive) return;
|
||||
|
||||
Reference in New Issue
Block a user