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
|
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];
|
uint16_t zcr = *(uint16_t*)um_data->u_data[11];
|
||||||
|
|
||||||
// WLED-MM/TroyHacks: Calculate the long- and short-running averages
|
// 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
|
// go into freefall - this logic stops that from triggering right
|
||||||
// after change_lockout. Better for smaller change_lockout values.
|
// after change_lockout. Better for smaller change_lockout values.
|
||||||
|
|
||||||
// SH7: this method is sub-optimal, as its interfering with the "playlist" engine
|
suspendPlaylist(); // suspend the playlist engine before changing to another preset
|
||||||
// we shoud find a better method for triggering playlist changes
|
|
||||||
applyPreset(newpreset);
|
applyPreset(newpreset);
|
||||||
|
|
||||||
#ifdef USERMOD_AUTO_PLAYLIST_DEBUG
|
#ifdef USERMOD_AUTO_PLAYLIST_DEBUG
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ void _overlayAnalogCountdown();
|
|||||||
void _overlayAnalogClock();
|
void _overlayAnalogClock();
|
||||||
|
|
||||||
//playlist.cpp
|
//playlist.cpp
|
||||||
|
void suspendPlaylist(); // WLEDMM support function for auto playlist usermod
|
||||||
void shufflePlaylist();
|
void shufflePlaylist();
|
||||||
void unloadPlaylist();
|
void unloadPlaylist();
|
||||||
int16_t loadPlaylist(JsonObject playlistObject, byte presetId = 0);
|
int16_t loadPlaylist(JsonObject playlistObject, byte presetId = 0);
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ void shufflePlaylist() {
|
|||||||
DEBUG_PRINTLN(F("Playlist shuffle."));
|
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() {
|
void unloadPlaylist() {
|
||||||
if (playlistEntries != nullptr) {
|
if (playlistEntries != nullptr) {
|
||||||
@@ -49,6 +55,7 @@ void unloadPlaylist() {
|
|||||||
}
|
}
|
||||||
currentPlaylist = playlistIndex = -1;
|
currentPlaylist = playlistIndex = -1;
|
||||||
playlistLen = playlistEntryDur = playlistOptions = 0;
|
playlistLen = playlistEntryDur = playlistOptions = 0;
|
||||||
|
playlistSuspended = false; // WLEDMM
|
||||||
DEBUG_PRINTLN(F("Playlist unloaded."));
|
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 fileDoc is not null JSON buffer is in use so just quit
|
||||||
if (currentPlaylist < 0 || playlistEntries == nullptr || fileDoc != nullptr) return;
|
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)) {
|
if (millis() - presetCycledTime > (100*playlistEntryDur)) {
|
||||||
presetCycledTime = millis();
|
presetCycledTime = millis();
|
||||||
if (bri == 0 || nightlightActive) return;
|
if (bri == 0 || nightlightActive) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user