Skip to content

Commit 505768d

Browse files
blazoncekdeece
authored andcommitted
Some fixes & implement recommendation from @Aircoookie
wled#3298 (comment)
1 parent c74db95 commit 505768d

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

wled00/bus_manager.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,11 @@ void BusDigital::show() {
205205
_milliAmpsTotal = 0;
206206
if (!_valid) return;
207207

208+
uint8_t cctWW = 0, cctCW = 0;
208209
uint8_t newBri = estimateCurrentAndLimitBri(); // will fill _milliAmpsTotal
209210
if (newBri < _bri) PolyBus::setBrightness(_busPtr, _iType, newBri); // limit brightness to stay within current limits
210211

211-
if (_data) { // use _buffering this causes ~20% FPS drop
212+
if (_data) {
212213
size_t channels = Bus::hasWhite(_type) + 3*Bus::hasRGB(_type);
213214
for (size_t i=0; i<_len; i++) {
214215
size_t offset = i*channels;
@@ -226,7 +227,8 @@ void BusDigital::show() {
226227
uint16_t pix = i;
227228
if (_reversed) pix = _len - pix -1;
228229
pix += _skip;
229-
PolyBus::setPixelColor(_busPtr, _iType, pix, c, co);
230+
if (_type == TYPE_FW1906) Bus::calculateCCT(c, cctWW, cctCW);
231+
PolyBus::setPixelColor(_busPtr, _iType, pix, c, co, (cctCW<<8) | cctWW);
230232
}
231233
#if !defined(STATUSLED) || STATUSLED>=0
232234
if (_skip) PolyBus::setPixelColor(_busPtr, _iType, 0, 0, _colorOrderMap.getPixelColorOrder(_start, _colorOrder)); // paint skipped pixels black
@@ -239,7 +241,8 @@ void BusDigital::show() {
239241
for (unsigned i = 0; i < hwLen; i++) {
240242
// use 0 as color order, actual order does not matter here as we just update the channel values as-is
241243
uint32_t c = restoreColorLossy(PolyBus::getPixelColor(_busPtr, _iType, i, 0), _bri);
242-
PolyBus::setPixelColor(_busPtr, _iType, i, c, 0); // repaint all pixels with new brightness
244+
if (_type == TYPE_FW1906) Bus::calculateCCT(c, cctWW, cctCW);
245+
PolyBus::setPixelColor(_busPtr, _iType, i, c, 0, (cctCW<<8) | cctWW); // repaint all pixels with new brightness
243246
}
244247
}
245248
}
@@ -278,10 +281,10 @@ void BusDigital::setStatusPixel(uint32_t c) {
278281

279282
void IRAM_ATTR BusDigital::setPixelColor(uint16_t pix, uint32_t c) {
280283
if (!_valid) return;
284+
uint8_t cctWW = 0, cctCW = 0;
281285
if (Bus::hasWhite(_type)) c = autoWhiteCalc(c);
282286
if (_cct >= 1900) c = colorBalanceFromKelvin(_cct, c); //color correction from CCT
283-
if (_type == TYPE_FW1906) calculateCCT(c, PolyBus::cctWW, PolyBus::cctCW); // FW1906 ignores W component in c
284-
if (_data) { // use _buffering this causes ~20% FPS drop
287+
if (_data) {
285288
size_t channels = Bus::hasWhite(_type) + 3*Bus::hasRGB(_type);
286289
size_t offset = pix*channels;
287290
if (Bus::hasRGB(_type)) {
@@ -304,14 +307,15 @@ void IRAM_ATTR BusDigital::setPixelColor(uint16_t pix, uint32_t c) {
304307
case 2: c = RGBW32(R(cOld), G(cOld), W(c) , 0); break;
305308
}
306309
}
307-
PolyBus::setPixelColor(_busPtr, _iType, pix, c, co);
310+
if (_type == TYPE_FW1906) Bus::calculateCCT(c, cctWW, cctCW);
311+
PolyBus::setPixelColor(_busPtr, _iType, pix, c, co, (cctCW<<8) | cctWW);
308312
}
309313
}
310314

311315
// returns original color if global buffering is enabled, else returns lossly restored color from bus
312316
uint32_t IRAM_ATTR BusDigital::getPixelColor(uint16_t pix) {
313317
if (!_valid) return 0;
314-
if (_data) { // use _buffering this causes ~20% FPS drop
318+
if (_data) {
315319
size_t channels = Bus::hasWhite(_type) + 3*Bus::hasRGB(_type);
316320
size_t offset = pix*channels;
317321
uint32_t c;
@@ -422,22 +426,16 @@ void BusPwm::setPixelColor(uint16_t pix, uint32_t c) {
422426
uint8_t g = G(c);
423427
uint8_t b = B(c);
424428
uint8_t w = W(c);
425-
426-
uint8_t ww, cw;
427-
428-
calculateCCT(c, ww, cw);
429429

430430
switch (_type) {
431431
case TYPE_ANALOG_1CH: //one channel (white), relies on auto white calculation
432432
_data[0] = w;
433433
break;
434434
case TYPE_ANALOG_2CH: //warm white + cold white
435-
_data[1] = cw;
436-
_data[0] = ww;
435+
Bus::calculateCCT(c, _data[0], _data[1]);
437436
break;
438437
case TYPE_ANALOG_5CH: //RGB + warm white + cold white
439-
_data[4] = cw;
440-
w = ww;
438+
Bus::calculateCCT(c, w, _data[4]);
441439
case TYPE_ANALOG_4CH: //RGBW
442440
_data[3] = w;
443441
case TYPE_ANALOG_3CH: //standard dumb RGB

wled00/bus_wrapper.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,6 @@
314314
//handles pointer type conversion for all possible bus types
315315
class PolyBus {
316316
public:
317-
// WW and CW components for chips that support them (FW1906). They have to be set before calling
318-
// PolyBus::setPixelColor(). In such case W component has no meaning in setPixelColor()
319-
// as there is no support for WW/CW API yet
320-
// if both values are 0, W component *may* be used instead (for WW & CW)
321-
static uint8_t cctWW, cctCW;
322317

323318
// initialize SPI bus speed for DotStar methods
324319
template <class T>
@@ -837,12 +832,13 @@ class PolyBus {
837832
return true;
838833
}
839834

840-
static void setPixelColor(void* busPtr, uint8_t busType, uint16_t pix, uint32_t c, uint8_t co) {
835+
static void setPixelColor(void* busPtr, uint8_t busType, uint16_t pix, uint32_t c, uint8_t co, uint16_t wwcw = 0) {
841836
uint8_t r = c >> 16;
842837
uint8_t g = c >> 8;
843838
uint8_t b = c >> 0;
844839
uint8_t w = c >> 24;
845840
RgbwColor col;
841+
uint8_t cctWW = wwcw & 0xFF, cctCW = (wwcw>>8) & 0xFF;
846842

847843
// reorder channels to selected order
848844
switch (co & 0x0F) {
@@ -1140,10 +1136,10 @@ class PolyBus {
11401136
case I_8266_U1_APA106_3: col = (static_cast<B_8266_U1_APA106_3*>(busPtr))->GetPixelColor(pix); break;
11411137
case I_8266_DM_APA106_3: col = (static_cast<B_8266_DM_APA106_3*>(busPtr))->GetPixelColor(pix); break;
11421138
case I_8266_BB_APA106_3: col = (static_cast<B_8266_BB_APA106_3*>(busPtr))->GetPixelColor(pix); break;
1143-
case I_8266_U0_FW6_5: { RgbwwColor c = (static_cast<B_8266_U0_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.WW>>8); } break;
1144-
case I_8266_U1_FW6_5: { RgbwwColor c = (static_cast<B_8266_U1_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.WW>>8); } break;
1145-
case I_8266_DM_FW6_5: { RgbwwColor c = (static_cast<B_8266_DM_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.WW>>8); } break;
1146-
case I_8266_BB_FW6_5: { RgbwwColor c = (static_cast<B_8266_BB_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.WW>>8); } break;
1139+
case I_8266_U0_FW6_5: { RgbwwColor c = (static_cast<B_8266_U0_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R,c.G,c.B,max(c.WW,c.CW)); } break; // will not return original W
1140+
case I_8266_U1_FW6_5: { RgbwwColor c = (static_cast<B_8266_U1_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R,c.G,c.B,max(c.WW,c.CW)); } break; // will not return original W
1141+
case I_8266_DM_FW6_5: { RgbwwColor c = (static_cast<B_8266_DM_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R,c.G,c.B,max(c.WW,c.CW)); } break; // will not return original W
1142+
case I_8266_BB_FW6_5: { RgbwwColor c = (static_cast<B_8266_BB_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R,c.G,c.B,max(c.WW,c.CW)); } break; // will not return original W
11471143
#endif
11481144
#ifdef ARDUINO_ARCH_ESP32
11491145
case I_32_RN_NEO_3: col = (static_cast<B_32_RN_NEO_3*>(busPtr))->GetPixelColor(pix); break;
@@ -1204,12 +1200,12 @@ class PolyBus {
12041200
case I_32_I1_APA106_3: col = (static_cast<B_32_I1_APA106_3*>(busPtr))->GetPixelColor(pix); break;
12051201
#endif
12061202
// case I_32_BB_APA106_3: col = (static_cast<B_32_BB_APA106_3*>(busPtr))->GetPixelColor(pix); break;
1207-
case I_32_RN_FW6_5: { RgbwwColor c = (static_cast<B_32_RN_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.WW>>8); } break;
1203+
case I_32_RN_FW6_5: { RgbwwColor c = (static_cast<B_32_RN_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R,c.G,c.B,max(c.WW,c.CW)); } break; // will not return original W
12081204
#ifndef WLED_NO_I2S0_PIXELBUS
1209-
case I_32_I0_FW6_5: { RgbwwColor c = (static_cast<B_32_I0_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.WW>>8); } break;
1205+
case I_32_I0_FW6_5: { RgbwwColor c = (static_cast<B_32_I0_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R,c.G,c.B,max(c.WW,c.CW)); } break; // will not return original W
12101206
#endif
12111207
#ifndef WLED_NO_I2S1_PIXELBUS
1212-
case I_32_I1_FW6_5: { RgbwwColor c = (static_cast<B_32_I1_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R>>8,c.G>>8,c.B>>8,c.WW>>8); } break;
1208+
case I_32_I1_FW6_5: { RgbwwColor c = (static_cast<B_32_I1_FW6_5*>(busPtr))->GetPixelColor(pix); col = RGBW32(c.R,c.G,c.B,max(c.WW,c.CW)); } break; // will not return original W
12131209
#endif
12141210
#endif
12151211
case I_HS_DOT_3: col = (static_cast<B_HS_DOT_3*>(busPtr))->GetPixelColor(pix); break;
@@ -1462,7 +1458,4 @@ class PolyBus {
14621458
return I_NONE;
14631459
}
14641460
};
1465-
1466-
uint8_t PolyBus::cctWW;
1467-
uint8_t PolyBus::cctCW;
14681461
#endif

0 commit comments

Comments
 (0)