waitUntilIdle() improvements

* protect deserializeMap()
* better handling of recursion in deserializeSegment() and deserializeState
* don't use yield() on esp32
This commit is contained in:
Frank
2023-06-01 21:28:46 +02:00
parent 0a5bfb656d
commit 333f5ac2a1
3 changed files with 46 additions and 8 deletions

View File

@@ -72,6 +72,15 @@
#error "Max segments must be at least max number of busses!"
#endif
// WLEDMM experimental . this is a "C style" wrapper for strip.waitUntilIdle()
// This workaround is just needed for the segment class, that does't know about "strip"
void strip_wait_until_idle(String whoCalledMe) {
if (strip.isServicing() && (strncmp(pcTaskGetTaskName(NULL), "loopTask", 8) != 0)) { // if we are in looptask (arduino loop), its safe to proceed without waiting
USER_PRINTLN(whoCalledMe + String(": strip is still drawing effects, waiting ..."));
strip.waitUntilIdle();
}
}
///////////////////////////////////////////////////////////////////////////////
// Segment class implementation
@@ -1515,8 +1524,8 @@ void WS2812FX::waitUntilIdle(void) {
if (isServicing()) {
unsigned long waitStarted = millis();
do {
delay(1);
yield();
delay(1); // Suspending for 1 tick or more gives other tasks a chance to run.
//yield(); // seems to be a no-op on esp32
} 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));
}
@@ -2154,6 +2163,12 @@ bool WS2812FX::deserializeMap(uint8_t n) {
if (!requestJSONBufferLock(7)) return false;
// WLEDMM: before changing maps, make sure our strip is _not_ servicing effects in parallel
if (strip.isServicing()) {
USER_PRINTLN(F("deserializeMap(): strip is still drawing effects, waiting ..."));
strip.waitUntilIdle();
}
//WLEDMM: change upstream code: do not load complete ledmaps in json as this blows up memory, use file read instead
//read the file
File f;