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.
This commit is contained in:
Frank
2024-12-20 01:57:02 +01:00
parent dc0b6bca37
commit fd2bce521b
5 changed files with 47 additions and 18 deletions

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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_

View File

@@ -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;