Skip to content

Commit

Permalink
fix for outputs not working any more when receiving DDP or art-net pi…
Browse files Browse the repository at this point in the history
…xels

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.
  • Loading branch information
softhack007 committed Dec 20, 2024
1 parent dc0b6bc commit fd2bce5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 18 deletions.
38 changes: 23 additions & 15 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,7 @@ int BusManager::add(BusConfig &bc) {
lastBus = nullptr;
laststart = 0;
lastend = 0;
slowMode = false;
return numBusses++;
}

Expand All @@ -1279,6 +1280,7 @@ void BusManager::removeAll() {
lastBus = nullptr;
laststart = 0;
lastend = 0;
slowMode = false;
}

void __attribute__((hot)) BusManager::show() {
Expand All @@ -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;
Expand All @@ -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
}
Expand All @@ -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);
}
Expand All @@ -1345,18 +1349,20 @@ 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);
}
}
return 0;
}

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);
}
Expand All @@ -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);
}
}
Expand Down
9 changes: 9 additions & 0 deletions wled00/bus_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions wled00/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -199,6 +210,7 @@ void exitRealtime() {
} else {
strip.show(); // possible fix for #3589
}
busses.invalidateCache(false); // WLEDMM
updateInterfaces(CALL_MODE_WS_SEND);
}

Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
4 changes: 2 additions & 2 deletions wled00/wled00.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fd2bce5

Please sign in to comment.