Skip to content

Commit 5dfa6d6

Browse files
authored
Merge branch 'MoonModules:mdev' into Strip_Level_Color_Adjust
2 parents e765531 + 6e2bd77 commit 5dfa6d6

File tree

6 files changed

+79
-25
lines changed

6 files changed

+79
-25
lines changed

wled00/FX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,7 @@ uint16_t ripple_base()
25612561
if ((v >= 0) && (v < SEGLEN)) // WLEDMM bugfix: v and w can be negative or out-of-range
25622562
SEGMENT.setPixelColor(v, color_blend(SEGMENT.getPixelColor(v), col, mag)); // TODO
25632563
int w = left + propI*2 + 3 -(v-left);
2564-
if ((v >= 0) && (v < SEGLEN)) // WLEDMM bugfix: v and w can be negative or out-of-range
2564+
if ((w >= 0) && (w < SEGLEN)) // WLEDMM bugfix: v and w can be negative or out-of-range
25652565
SEGMENT.setPixelColor(w, color_blend(SEGMENT.getPixelColor(w), col, mag)); // TODO
25662566
}
25672567
}

wled00/FX_2Dfcn.cpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,35 @@ void IRAM_ATTR_YN Segment::setPixelColorXY(int x, int y, uint32_t col) //WLEDMM:
216216
if (Segment::maxHeight==1) return; // not a matrix set-up
217217
if (x<0 || y<0 || x >= virtualWidth() || y >= virtualHeight()) return; // if pixel would fall out of virtual segment just exit
218218

219-
if (ledsrgb) ledsrgb[XY(x,y)] = col;
220-
219+
unsigned i = UINT_MAX;
220+
bool sameColor = false;
221+
if (ledsrgb) { // WLEDMM small optimization
222+
i = XY(x,y);
223+
CRGB fastled_col = CRGB(col);
224+
if (ledsrgb[i] == fastled_col) sameColor = true;
225+
else ledsrgb[i] = fastled_col;
226+
}
221227
uint8_t _bri_t = currentBri(on ? opacity : 0);
222228
if (!_bri_t && !transitional) return;
223229
if (_bri_t < 255) {
224230
col = color_fade(col, _bri_t);
225231
}
226232

233+
#if 0 // this is a dangerous optimization
234+
if ((i < UINT_MAX) && sameColor && (call > 0) && (ledsrgb[i] == CRGB(col)) && (_globalLeds == nullptr)) return; // WLEDMM looks like nothing to do (but we don't trust globalleds)
235+
#endif
236+
227237
if (reverse ) x = virtualWidth() - x - 1;
228238
if (reverse_y) y = virtualHeight() - y - 1;
229239
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
230240

241+
// WLEDMM shortcut when no grouping/spacing used
242+
bool simpleSegment = !mirror && !mirror_y && (grouping == 1) && (spacing == 0);
243+
if (simpleSegment) {
244+
strip.setPixelColorXY(start + x, startY + y, col);
245+
return;
246+
}
247+
231248
x *= groupLength(); // expand to physical pixels
232249
y *= groupLength(); // expand to physical pixels
233250
if (x >= width() || y >= height()) return; // if pixel would fall out of segment just exit
@@ -308,8 +325,10 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa, bool fast
308325
// returns RGBW values of pixel
309326
uint32_t IRAM_ATTR_YN Segment::getPixelColorXY(int x, int y) {
310327
if (x<0 || y<0 || !isActive()) return 0; // not active or out-of range
311-
int i = XY(x,y);
312-
if (ledsrgb) return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
328+
if (ledsrgb) {
329+
int i = XY(x,y);
330+
return RGBW32(ledsrgb[i].r, ledsrgb[i].g, ledsrgb[i].b, 0);
331+
}
313332
if (reverse ) x = virtualWidth() - x - 1;
314333
if (reverse_y) y = virtualHeight() - y - 1;
315334
if (transpose) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed
@@ -325,23 +344,11 @@ void Segment::blendPixelColorXY(uint16_t x, uint16_t y, uint32_t color, uint8_t
325344
}
326345

327346
// Adds the specified color with the existing pixel color perserving color balance.
328-
void Segment::addPixelColorXY(int x, int y, uint32_t color, bool fast) {
347+
void IRAM_ATTR_YN Segment::addPixelColorXY(int x, int y, uint32_t color, bool fast) {
329348
if (!isActive()) return; // not active
330349
if (x >= virtualWidth() || y >= virtualHeight() || x<0 || y<0) return; // if pixel would fall out of virtual segment just exit
331350
uint32_t col = getPixelColorXY(x,y);
332-
uint8_t r = R(col);
333-
uint8_t g = G(col);
334-
uint8_t b = B(col);
335-
uint8_t w = W(col);
336-
if (fast) {
337-
r = qadd8(r, R(color));
338-
g = qadd8(g, G(color));
339-
b = qadd8(b, B(color));
340-
w = qadd8(w, W(color));
341-
col = RGBW32(r,g,b,w);
342-
} else {
343-
col = color_add(col, color);
344-
}
351+
col = color_add(col, color, fast);
345352
setPixelColorXY(x, y, col);
346353
}
347354

wled00/FX_fcn.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,17 @@ void IRAM_ATTR_YN Segment::setPixelColor(int i, uint32_t col) //WLEDMM: IRAM_ATT
10441044
}
10451045
i += start; // starting pixel in a group
10461046

1047+
#if 0 // needs more testing
1048+
// WLEDMM shortcut when no grouping/spacing used
1049+
bool simpleSegment = !mirror && (grouping == 1) && (spacing == 0);
1050+
if (simpleSegment) {
1051+
int indexSet = i + offset; // offset/phase
1052+
if (indexSet >= stop) indexSet -= len; // wrap
1053+
strip.setPixelColor(indexSet, col);
1054+
return;
1055+
}
1056+
#endif
1057+
10471058
// set all the pixels in the group
10481059
for (int j = 0; j < grouping; j++) {
10491060
uint16_t indexSet = i + ((reverse) ? -j : j);

wled00/bus_manager.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void IRAM_ATTR BusDigital::setPixelColor(uint16_t pix, uint32_t c) {
179179
PolyBus::setPixelColor(_busPtr, _iType, pix, c, co);
180180
}
181181

182-
uint32_t BusDigital::getPixelColor(uint16_t pix) {
182+
uint32_t IRAM_ATTR_YN BusDigital::getPixelColor(uint16_t pix) {
183183
if (reversed) pix = _len - pix -1;
184184
else pix += _skip;
185185
uint8_t co = _colorOrderMap.getPixelColorOrder(pix+_start, _colorOrder);
@@ -728,6 +728,10 @@ int BusManager::add(BusConfig &bc) {
728728
} else {
729729
busses[numBusses] = new BusPwm(bc);
730730
}
731+
// WLEDMM clear cached Bus info
732+
lastBus = nullptr;
733+
laststart = 0;
734+
lastend = 0;
731735
return numBusses++;
732736
}
733737

@@ -738,6 +742,10 @@ void BusManager::removeAll() {
738742
while (!canAllShow()) yield();
739743
for (uint8_t i = 0; i < numBusses; i++) delete busses[i];
740744
numBusses = 0;
745+
// WLEDMM clear cached Bus info
746+
lastBus = nullptr;
747+
laststart = 0;
748+
lastend = 0;
741749
}
742750

743751
void BusManager::show() {
@@ -753,11 +761,24 @@ void BusManager::setStatusPixel(uint32_t c) {
753761
}
754762

755763
void IRAM_ATTR BusManager::setPixelColor(uint16_t pix, uint32_t c, int16_t cct) {
764+
if ((pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) {
765+
// WLEDMM same bus as last time - no need to search again
766+
lastBus->setPixelColor(pix - laststart, c);
767+
return;
768+
}
769+
756770
for (uint_fast8_t i = 0; i < numBusses; i++) { // WLEDMM use fast native types
757771
Bus* b = busses[i];
758772
uint_fast16_t bstart = b->getStart();
759773
if (pix < bstart || pix >= bstart + b->getLength()) continue;
760-
busses[i]->setPixelColor(pix - bstart, c);
774+
else {
775+
// WLEDMM remember last Bus we took
776+
lastBus = b;
777+
laststart = bstart;
778+
lastend = bstart + b->getLength();
779+
b->setPixelColor(pix - bstart, c);
780+
break; // WLEDMM found the right Bus -> so we can stop searching
781+
}
761782
}
762783
}
763784

@@ -776,12 +797,23 @@ void BusManager::setSegmentCCT(int16_t cct, bool allowWBCorrection) {
776797
Bus::setCCT(cct);
777798
}
778799

779-
uint32_t BusManager::getPixelColor(uint_fast16_t pix) { // WLEDMM use fast native types
800+
uint32_t IRAM_ATTR BusManager::getPixelColor(uint_fast16_t pix) { // WLEDMM use fast native types, IRAM_ATTR
801+
if ((pix >= laststart) && (pix < lastend ) && (lastBus != nullptr)) {
802+
// WLEDMM same bus as last time - no need to search again
803+
return lastBus->getPixelColor(pix - laststart);
804+
}
805+
780806
for (uint_fast8_t i = 0; i < numBusses; i++) {
781807
Bus* b = busses[i];
782808
uint_fast16_t bstart = b->getStart();
783809
if (pix < bstart || pix >= bstart + b->getLength()) continue;
784-
return b->getPixelColor(pix - bstart);
810+
else {
811+
// WLEDMM remember last Bus we took
812+
lastBus = b;
813+
laststart = bstart;
814+
lastend = bstart + b->getLength();
815+
return b->getPixelColor(pix - bstart);
816+
}
785817
}
786818
return 0;
787819
}

wled00/bus_manager.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,12 @@ class BusManager {
427427

428428
private:
429429
uint8_t numBusses = 0;
430-
Bus* busses[WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES];
430+
Bus* busses[WLED_MAX_BUSSES+WLED_MIN_VIRTUAL_BUSSES] = {nullptr}; // WLEDMM init array
431431
ColorOrderMap colorOrderMap;
432+
// WLEDMM cache last used Bus -> 20% to 30% speedup when using many LED pins
433+
Bus *lastBus = nullptr;
434+
unsigned laststart = 0;
435+
unsigned lastend = 0;
432436

433437
inline uint8_t getNumVirtualBusses() {
434438
int j = 0;

wled00/wled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// version code in format yymmddb (b = daily build)
11-
#define VERSION 2404181
11+
#define VERSION 2404201
1212

1313
// 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.
1414
#define _MoonModules_WLED_

0 commit comments

Comments
 (0)