From fd2bce521b34b1b74853031dcd81d281b7dc167d Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Fri, 20 Dec 2024 01:57:02 +0100 Subject: [PATCH] fix for outputs not working any more when receiving DDP or art-net pixels This disables bus caching (and related speedups) while receiving realtime UDP pixels. Its still totally unclear to me what happens, and why disabling the cache solves problems. --- wled00/bus_manager.cpp | 38 +++++++++++++++++++++++--------------- wled00/bus_manager.h | 9 +++++++++ wled00/udp.cpp | 12 ++++++++++++ wled00/wled.h | 2 +- wled00/wled00.ino | 4 ++-- 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index 2c87c498e8..19c0c17479 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -1261,6 +1261,7 @@ int BusManager::add(BusConfig &bc) { lastBus = nullptr; laststart = 0; lastend = 0; + slowMode = false; return numBusses++; } @@ -1279,6 +1280,7 @@ void BusManager::removeAll() { lastBus = nullptr; laststart = 0; lastend = 0; + slowMode = false; } void __attribute__((hot)) BusManager::show() { @@ -1298,7 +1300,7 @@ void BusManager::setStatusPixel(uint32_t c) { } void IRAM_ATTR __attribute__((hot)) BusManager::setPixelColor(uint16_t pix, uint32_t c, int16_t cct) { - if ((pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) { + if ( !slowMode && (pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) { // WLEDMM same bus as last time - no need to search again lastBus->setPixelColor(pix - laststart, c); return; @@ -1309,10 +1311,12 @@ void IRAM_ATTR __attribute__((hot)) BusManager::setPixelColor(uint16_t pix, uint uint_fast16_t bstart = b->getStart(); if (pix < bstart || pix >= bstart + b->getLength()) continue; else { - // WLEDMM remember last Bus we took - lastBus = b; - laststart = bstart; - lastend = bstart + b->getLength(); + if (!slowMode) { + // WLEDMM remember last Bus we took + lastBus = b; + laststart = bstart; + lastend = bstart + b->getLength(); + } b->setPixelColor(pix - bstart, c); break; // WLEDMM found the right Bus -> so we can stop searching } @@ -1335,7 +1339,7 @@ void __attribute__((cold)) BusManager::setSegmentCCT(int16_t cct, bool allowWBCo } uint32_t IRAM_ATTR __attribute__((hot)) BusManager::getPixelColor(uint_fast16_t pix) { // WLEDMM use fast native types, IRAM_ATTR - if ((pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) { + if ( !slowMode && (pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) { // WLEDMM same bus as last time - no need to search again return lastBus->getPixelColor(pix - laststart); } @@ -1345,10 +1349,12 @@ uint32_t IRAM_ATTR __attribute__((hot)) BusManager::getPixelColor(uint_fast16_t uint_fast16_t bstart = b->getStart(); if (pix < bstart || pix >= bstart + b->getLength()) continue; else { - // WLEDMM remember last Bus we took - lastBus = b; - laststart = bstart; - lastend = bstart + b->getLength(); + if (!slowMode) { + // WLEDMM remember last Bus we took + lastBus = b; + laststart = bstart; + lastend = bstart + b->getLength(); + } return b->getPixelColor(pix - bstart); } } @@ -1356,7 +1362,7 @@ uint32_t IRAM_ATTR __attribute__((hot)) BusManager::getPixelColor(uint_fast16_t } uint32_t IRAM_ATTR __attribute__((hot)) BusManager::getPixelColorRestored(uint_fast16_t pix) { // WLEDMM uses bus::getPixelColorRestored() - if ((pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) { + if ( !slowMode && (pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) { // WLEDMM same bus as last time - no need to search again return lastBus->getPixelColorRestored(pix - laststart); } @@ -1366,10 +1372,12 @@ uint32_t IRAM_ATTR __attribute__((hot)) BusManager::getPixelColorRestored(uint_ uint_fast16_t bstart = b->getStart(); if (pix < bstart || pix >= bstart + b->getLength()) continue; else { - // WLEDMM remember last Bus we took - lastBus = b; - laststart = bstart; - lastend = bstart + b->getLength(); + if (!slowMode) { + // WLEDMM remember last Bus we took + lastBus = b; + laststart = bstart; + lastend = bstart + b->getLength(); + } return b->getPixelColorRestored(pix - bstart); } } diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index 69f3aa2d74..04062215bf 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -459,6 +459,14 @@ class BusManager { void show(); + void invalidateCache(bool isRTMode) { + // WLEDMM clear cached Bus info + lastBus = nullptr; + laststart = 0; + lastend = 0; + slowMode = isRTMode; + } + void setStatusPixel(uint32_t c); void setPixelColor(uint16_t pix, uint32_t c, int16_t cct=-1); @@ -497,6 +505,7 @@ class BusManager { Bus *lastBus = nullptr; unsigned laststart = 0; unsigned lastend = 0; + bool slowMode = false; // WLEDMM not sure why we need this. But its necessary. inline uint8_t getNumVirtualBusses() const { int j = 0; diff --git a/wled00/udp.cpp b/wled00/udp.cpp index 6dd01a3bdf..bec3c0e204 100644 --- a/wled00/udp.cpp +++ b/wled00/udp.cpp @@ -153,11 +153,22 @@ void notify(byte callMode, bool followUp) void realtimeLock(uint32_t timeoutMs, byte md) { if (!realtimeMode && !realtimeOverride) { + // this code runs once when we enter realtime mode + // WLEDMM begin - we need to init segment caches before putting any pixels + if (strip.isServicing()) { + USER_PRINTLN(F("realtimeLock() enter RTM: strip is still drawing effects.")); + strip.waitUntilIdle(); + } + strip.service(); // WLEDMM make sure that all segments are properly initialized + busses.invalidateCache(true); + // WLEDMM end + uint16_t stop, start; if (useMainSegmentOnly) { Segment& mainseg = strip.getMainSegment(); start = mainseg.start; stop = mainseg.stop; + mainseg.map1D2D = M12_Pixels; // WLEDMM no mapping mainseg.freeze = true; } else { start = 0; @@ -199,6 +210,7 @@ void exitRealtime() { } else { strip.show(); // possible fix for #3589 } + busses.invalidateCache(false); // WLEDMM updateInterfaces(CALL_MODE_WS_SEND); } diff --git a/wled00/wled.h b/wled00/wled.h index ab19f1b09e..ab6d3d2ff8 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -7,7 +7,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2412190 +#define VERSION 2412200 // WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED. #define _MoonModules_WLED_ diff --git a/wled00/wled00.ino b/wled00/wled00.ino index ce1721fdfa..83d3f95919 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -87,8 +87,8 @@ void loop() { USER_PRINTF("%lu lps\t", lps); USER_PRINTF("%u fps\t", strip.getFps()); //USER_PRINTF("%lu lps without show\t\t", lps2); - USER_PRINTF("frametime %d\t", int(strip.getFrameTime())); - USER_PRINTF("targetFPS %d\n", int(strip.getTargetFps())); + USER_PRINTF("target frametime %dms\t", int(strip.getFrameTime())); + USER_PRINTF("target FPS %d\n", int(strip.getTargetFps())); } lastMillis = millis(); loopCounter = 0;