Refactored isRgbw to hasWhiteChannel()

This commit is contained in:
cschwinne 2022-02-04 13:28:00 +01:00
parent 04d5932252
commit 97f8eea302
9 changed files with 36 additions and 32 deletions

View File

@ -660,8 +660,6 @@ class WS2812FX {
deserializeMap(uint8_t n=0); deserializeMap(uint8_t n=0);
bool bool
isRgbw = false,
isOffRefreshRequred = false, //periodic refresh is required for the strip to remain off.
gammaCorrectBri = false, gammaCorrectBri = false,
gammaCorrectCol = true, gammaCorrectCol = true,
applyToAllSelected = true, applyToAllSelected = true,
@ -864,6 +862,8 @@ class WS2812FX {
uint16_t _cumulativeFps = 2; uint16_t _cumulativeFps = 2;
bool bool
_isOffRefreshRequired = false, //periodic refresh is required for the strip to remain off.
_hasWhiteChannel = false,
_triggered; _triggered;
mode_ptr _mode[MODE_COUNT]; // SRAM footprint: 4 bytes per element mode_ptr _mode[MODE_COUNT]; // SRAM footprint: 4 bytes per element
@ -925,6 +925,10 @@ class WS2812FX {
uint16_t uint16_t
realPixelIndex(uint16_t i), realPixelIndex(uint16_t i),
transitionProgress(uint8_t tNr); transitionProgress(uint8_t tNr);
public:
inline bool hasWhiteChannel(void) {return _hasWhiteChannel;}
inline bool isOffRefreshRequired(void) {return _isOffRefreshRequired;}
}; };
//10 names per line //10 names per line

View File

@ -68,7 +68,7 @@
void WS2812FX::finalizeInit(void) void WS2812FX::finalizeInit(void)
{ {
RESET_RUNTIME; RESET_RUNTIME;
isRgbw = isOffRefreshRequred = false; _hasWhiteChannel = _isOffRefreshRequired = false;
//if busses failed to load, add default (fresh install, FS issue, ...) //if busses failed to load, add default (fresh install, FS issue, ...)
if (busses.getNumBusses() == 0) { if (busses.getNumBusses() == 0) {
@ -93,9 +93,9 @@ void WS2812FX::finalizeInit(void)
if (bus == nullptr) continue; if (bus == nullptr) continue;
if (bus->getStart() + bus->getLength() > MAX_LEDS) break; if (bus->getStart() + bus->getLength() > MAX_LEDS) break;
//RGBW mode is enabled if at least one of the strips is RGBW //RGBW mode is enabled if at least one of the strips is RGBW
isRgbw |= bus->isRgbw(); _hasWhiteChannel |= bus->isRgbw();
//refresh is required to remain off if at least one of the strips requires the refresh. //refresh is required to remain off if at least one of the strips requires the refresh.
isOffRefreshRequred |= bus->isOffRefreshRequired(); _isOffRefreshRequired |= bus->isOffRefreshRequired();
uint16_t busEnd = bus->getStart() + bus->getLength(); uint16_t busEnd = bus->getStart() + bus->getLength();
if (busEnd > _length) _length = busEnd; if (busEnd > _length) _length = busEnd;
#ifdef ESP8266 #ifdef ESP8266

View File

@ -83,7 +83,7 @@ void onAlexaChange(EspalexaDevice* dev)
seg.setCCT(k, segid); seg.setCCT(k, segid);
if (seg.cct != cctPrev) effectChanged = true; //send UDP if (seg.cct != cctPrev) effectChanged = true; //send UDP
col[0]= 0; col[1]= 0; col[2]= 0; col[3]= 255; col[0]= 0; col[1]= 0; col[2]= 0; col[3]= 255;
} else if (strip.isRgbw) { } else if (strip.hasWhiteChannel()) {
switch (ct) { //these values empirically look good on RGBW switch (ct) { //these values empirically look good on RGBW
case 199: col[0]=255; col[1]=255; col[2]=255; col[3]=255; break; case 199: col[0]=255; col[1]=255; col[2]=255; col[3]=255; break;
case 234: col[0]=127; col[1]=127; col[2]=127; col[3]=255; break; case 234: col[0]=127; col[1]=127; col[2]=127; col[3]=255; break;

View File

@ -302,7 +302,7 @@ void handleIO()
// turn off built-in LED if strip is turned off // turn off built-in LED if strip is turned off
// this will break digital bus so will need to be reinitialised on On // this will break digital bus so will need to be reinitialised on On
PinOwner ledPinOwner = pinManager.getPinOwner(LED_BUILTIN); PinOwner ledPinOwner = pinManager.getPinOwner(LED_BUILTIN);
if (!strip.isOffRefreshRequred && (ledPinOwner == PinOwner::None || ledPinOwner == PinOwner::BusDigital)) { if (!strip.isOffRefreshRequired() && (ledPinOwner == PinOwner::None || ledPinOwner == PinOwner::BusDigital)) {
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
} }

View File

@ -363,20 +363,20 @@ void decodeIR40(uint32_t code)
case IR40_MAGENTA : colorFromUint24(COLOR_MAGENTA); break; case IR40_MAGENTA : colorFromUint24(COLOR_MAGENTA); break;
case IR40_PINK : colorFromUint24(COLOR_PINK); break; case IR40_PINK : colorFromUint24(COLOR_PINK); break;
case IR40_WARMWHITE2 : { case IR40_WARMWHITE2 : {
if (strip.isRgbw) { colorFromUint32(COLOR2_WARMWHITE2); effectCurrent = 0; } if (strip.hasWhiteChannel()) {colorFromUint32(COLOR2_WARMWHITE2); effectCurrent = 0; }
else colorFromUint24(COLOR_WARMWHITE2); } break; else colorFromUint24(COLOR_WARMWHITE2); } break;
case IR40_WARMWHITE : { case IR40_WARMWHITE : {
if (strip.isRgbw) { colorFromUint32(COLOR2_WARMWHITE); effectCurrent = 0; } if (strip.hasWhiteChannel()) {colorFromUint32(COLOR2_WARMWHITE); effectCurrent = 0; }
else colorFromUint24(COLOR_WARMWHITE); } break; else colorFromUint24(COLOR_WARMWHITE); } break;
case IR40_WHITE : { case IR40_WHITE : {
if (strip.isRgbw) { colorFromUint32(COLOR2_NEUTRALWHITE); effectCurrent = 0; } if (strip.hasWhiteChannel()) {colorFromUint32(COLOR2_NEUTRALWHITE); effectCurrent = 0; }
else colorFromUint24(COLOR_NEUTRALWHITE); } break; else colorFromUint24(COLOR_NEUTRALWHITE); } break;
case IR40_COLDWHITE : { case IR40_COLDWHITE : {
if (strip.isRgbw) { colorFromUint32(COLOR2_COLDWHITE); effectCurrent = 0; } if (strip.hasWhiteChannel()) {colorFromUint32(COLOR2_COLDWHITE); effectCurrent = 0; }
else colorFromUint24(COLOR_COLDWHITE); } break; else colorFromUint24(COLOR_COLDWHITE); } break;
case IR40_COLDWHITE2 : { case IR40_COLDWHITE2 : {
if (strip.isRgbw) { colorFromUint32(COLOR2_COLDWHITE2); effectCurrent = 0; } if (strip.hasWhiteChannel()) {colorFromUint32(COLOR2_COLDWHITE2); effectCurrent = 0; }
else colorFromUint24(COLOR_COLDWHITE2); } break; else colorFromUint24(COLOR_COLDWHITE2); } break;
case IR40_WPLUS : relativeChangeWhite(10); break; case IR40_WPLUS : relativeChangeWhite(10); break;
case IR40_WMINUS : relativeChangeWhite(-10, 5); break; case IR40_WMINUS : relativeChangeWhite(-10, 5); break;
case IR40_WOFF : whiteLast = col[3]; col[3] = 0; break; case IR40_WOFF : whiteLast = col[3]; col[3] = 0; break;
@ -420,22 +420,22 @@ void decodeIR44(uint32_t code)
case IR44_MAGENTA : colorFromUint24(COLOR_MAGENTA); break; case IR44_MAGENTA : colorFromUint24(COLOR_MAGENTA); break;
case IR44_PINK : colorFromUint24(COLOR_PINK); break; case IR44_PINK : colorFromUint24(COLOR_PINK); break;
case IR44_WHITE : { case IR44_WHITE : {
if (strip.isRgbw) { if (strip.hasWhiteChannel()) {
if (col[3] > 0) col[3] = 0; if (col[3] > 0) col[3] = 0;
else { colorFromUint32(COLOR2_NEUTRALWHITE); effectCurrent = 0; } else { colorFromUint32(COLOR2_NEUTRALWHITE); effectCurrent = 0; }
} else colorFromUint24(COLOR_NEUTRALWHITE); } break; } else colorFromUint24(COLOR_NEUTRALWHITE); } break;
case IR44_WARMWHITE2 : { case IR44_WARMWHITE2 : {
if (strip.isRgbw) { colorFromUint32(COLOR2_WARMWHITE2); effectCurrent = 0; } if (strip.hasWhiteChannel()) {colorFromUint32(COLOR2_WARMWHITE2); effectCurrent = 0; }
else colorFromUint24(COLOR_WARMWHITE2); } break; else colorFromUint24(COLOR_WARMWHITE2); } break;
case IR44_WARMWHITE : { case IR44_WARMWHITE : {
if (strip.isRgbw) { colorFromUint32(COLOR2_WARMWHITE); effectCurrent = 0; } if (strip.hasWhiteChannel()) {colorFromUint32(COLOR2_WARMWHITE); effectCurrent = 0; }
else colorFromUint24(COLOR_WARMWHITE); } break; else colorFromUint24(COLOR_WARMWHITE); } break;
case IR44_COLDWHITE : { case IR44_COLDWHITE : {
if (strip.isRgbw) { colorFromUint32(COLOR2_COLDWHITE); effectCurrent = 0; } if (strip.hasWhiteChannel()) {colorFromUint32(COLOR2_COLDWHITE); effectCurrent = 0; }
else colorFromUint24(COLOR_COLDWHITE); } break; else colorFromUint24(COLOR_COLDWHITE); } break;
case IR44_COLDWHITE2 : { case IR44_COLDWHITE2 : {
if (strip.isRgbw) { colorFromUint32(COLOR2_COLDWHITE2); effectCurrent = 0; } if (strip.hasWhiteChannel()) {colorFromUint32(COLOR2_COLDWHITE2); effectCurrent = 0; }
else colorFromUint24(COLOR_COLDWHITE2); } break; else colorFromUint24(COLOR_COLDWHITE2); } break;
case IR44_REDPLUS : relativeChange(&effectCurrent, 1, 0, MODE_COUNT); break; case IR44_REDPLUS : relativeChange(&effectCurrent, 1, 0, MODE_COUNT); break;
case IR44_REDMINUS : relativeChange(&effectCurrent, -1, 0); break; case IR44_REDMINUS : relativeChange(&effectCurrent, -1, 0); break;
case IR44_GREENPLUS : relativeChange(&effectPalette, 1, 0, strip.getPaletteCount() -1); break; case IR44_GREENPLUS : relativeChange(&effectPalette, 1, 0, strip.getPaletteCount() -1); break;

View File

@ -418,7 +418,7 @@ void serializeSegment(JsonObject& root, WS2812FX::Segment& seg, byte id, bool fo
// to conserve RAM we will serialize the col array manually // to conserve RAM we will serialize the col array manually
// this will reduce RAM footprint from ~300 bytes to 84 bytes per segment // this will reduce RAM footprint from ~300 bytes to 84 bytes per segment
char colstr[70]; colstr[0] = '['; colstr[1] = '\0'; //max len 68 (5 chan, all 255) char colstr[70]; colstr[0] = '['; colstr[1] = '\0'; //max len 68 (5 chan, all 255)
const char *format = strip.isRgbw ? PSTR("[%u,%u,%u,%u]") : PSTR("[%u,%u,%u]"); const char *format = strip.hasWhiteChannel() ? PSTR("[%u,%u,%u,%u]") : PSTR("[%u,%u,%u]");
for (uint8_t i = 0; i < 3; i++) for (uint8_t i = 0; i < 3; i++)
{ {
byte segcol[4]; byte* c = segcol; byte segcol[4]; byte* c = segcol;
@ -524,13 +524,13 @@ void serializeInfo(JsonObject root)
JsonObject leds = root.createNestedObject("leds"); JsonObject leds = root.createNestedObject("leds");
leds[F("count")] = strip.getLengthTotal(); leds[F("count")] = strip.getLengthTotal();
leds[F("rgbw")] = strip.isRgbw; leds[F("rgbw")] = strip.hasWhiteChannel();
leds[F("wv")] = false; leds[F("wv")] = false;
leds["cct"] = correctWB || strip.hasCCTBus(); leds["cct"] = correctWB || strip.hasCCTBus();
switch (Bus::getAutoWhiteMode()) { switch (Bus::getAutoWhiteMode()) {
case RGBW_MODE_MANUAL_ONLY: case RGBW_MODE_MANUAL_ONLY:
case RGBW_MODE_DUAL: case RGBW_MODE_DUAL:
if (strip.isRgbw) leds[F("wv")] = true; if (strip.hasWhiteChannel()) leds[F("wv")] = true;
break; break;
} }

View File

@ -177,7 +177,7 @@ void WLED::loop()
yield(); yield();
if (!offMode || strip.isOffRefreshRequred) if (!offMode || strip.isOffRefreshRequired())
strip.service(); strip.service();
#ifdef ESP8266 #ifdef ESP8266
else if (!noWifiSleep) else if (!noWifiSleep)

View File

@ -414,7 +414,7 @@ void deEEP() {
JsonArray colarr = segObj.createNestedArray("col"); JsonArray colarr = segObj.createNestedArray("col");
byte numChannels = (strip.isRgbw)? 4:3; byte numChannels = (strip.hasWhiteChannel())? 4:3;
for (uint8_t k = 0; k < 3; k++) //k=0 primary (i+2) k=1 secondary (i+6) k=2 tertiary color (i+12) for (uint8_t k = 0; k < 3; k++) //k=0 primary (i+2) k=1 secondary (i+6) k=2 tertiary color (i+12)
{ {

View File

@ -52,7 +52,7 @@ void XML_response(AsyncWebServerRequest *request, char* dest)
oappend(SET_F("</ix><fp>")); oappend(SET_F("</ix><fp>"));
oappendi(effectPalette); oappendi(effectPalette);
oappend(SET_F("</fp><wv>")); oappend(SET_F("</fp><wv>"));
if (strip.isRgbw) { if (strip.hasWhiteChannel()) {
oappendi(col[3]); oappendi(col[3]);
} else { } else {
oappend("-1"); oappend("-1");