avoid updating strip / segments while draving effects (ESP32 only)

💫 this is the way🌟
A new locking mechanism that allows to wait until strip.service() has completed.
This commit is contained in:
Frank
2023-06-01 17:41:36 +02:00
parent e99874159d
commit 0a5bfb656d
7 changed files with 100 additions and 11 deletions

View File

@@ -1423,6 +1423,7 @@ void WS2812FX::enumerateLedmaps() {
void WS2812FX::finalizeInit(void)
{
//reset segment runtimes
suspendStripService = true; // WELDMM avoid running effects on an incomplete strip
for (segment &seg : _segments) {
seg.markForReset();
seg.resetIfRequired();
@@ -1502,6 +1503,27 @@ void WS2812FX::finalizeInit(void)
loadCustomPalettes(); // (re)load all custom palettes
DEBUG_PRINTLN(F("Loading custom ledmaps"));
deserializeMap(); // (re)load default ledmap
_isServicing = false; // WLEDMM
suspendStripService = false; // WELDMM ready, run !
}
// WLEDMM wait until strip is idle (=not servicing).
// on 8266 this function does nothing, because we can only do "buisy waiting" on ESP32
#define MAX_IDLE_WAIT_MS 50 // seems to work in most cases
void WS2812FX::waitUntilIdle(void) {
#ifdef ARDUINO_ARCH_ESP32
if (isServicing()) {
unsigned long waitStarted = millis();
do {
delay(1);
yield();
} while (isServicing() && (millis() - waitStarted < MAX_IDLE_WAIT_MS));
USER_PRINTF("strip.waitUntilIdle(): strip %sidle after %d ms. (task %s)\n", isServicing()?"not ":"", int(millis() - waitStarted), pcTaskGetTaskName(NULL));
}
return;
#else
return;
#endif
}
void WS2812FX::service() {