diff --git a/wled00/WS2812FX.cpp b/wled00/WS2812FX.cpp index e14a7c9e..31a91d6f 100644 --- a/wled00/WS2812FX.cpp +++ b/wled00/WS2812FX.cpp @@ -889,13 +889,23 @@ uint16_t WS2812FX::mode_theater_chase_rainbow(void) { /* - * Running lights effect with smooth sine transition. + * Running lights effect with smooth sine transition base. */ -uint16_t WS2812FX::mode_running_lights(void) { +uint16_t WS2812FX::running_base(bool saw) { uint8_t x_scale = SEGMENT.intensity >> 2; for(uint16_t i=0; i < SEGMENT_LENGTH; i++) { - uint8_t s = sin8(i*x_scale + (SEGMENT_RUNTIME.counter_mode_step >> 4)); + uint8_t s = 0; + uint8_t a = i*x_scale - (SEGMENT_RUNTIME.counter_mode_step >> 4); + if (saw) { + if (a < 16) + { + a = 192 + a*8; + } else { + a = map(a,16,255,64,192); + } + } + s = sin8(a); setPixelColor(SEGMENT.start + i, color_blend(SEGMENT.colors[1], color_from_palette(SEGMENT.start + i, true, PALETTE_SOLID_WRAP, 0), s)); } SEGMENT_RUNTIME.counter_mode_step += SEGMENT.speed; @@ -904,42 +914,38 @@ uint16_t WS2812FX::mode_running_lights(void) { /* - * twinkle function + * Running lights effect with smooth sine transition. */ -uint16_t WS2812FX::twinkle(uint32_t color) { +uint16_t WS2812FX::mode_running_lights(void) { + return running_base(false); +} + + +/* + * Running lights effect with sawtooth transition. + */ +uint16_t WS2812FX::mode_saw(void) { + return running_base(true); +} + + +/* + * Blink several LEDs in random colors on, reset, repeat. + * Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ + */ +uint16_t WS2812FX::mode_twinkle(void) { if(SEGMENT_RUNTIME.counter_mode_step == 0) { fill(SEGMENT.colors[1]); SEGMENT_RUNTIME.counter_mode_step = map(SEGMENT.intensity, 0, 255, 1, SEGMENT_LENGTH); // make sure, at least one LED is on } uint16_t i = SEGMENT.start + random16(SEGMENT_LENGTH); - if (color == SEGMENT.colors[0]) - { - setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); - } else { - setPixelColor(i, color); - } + setPixelColor(i, color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); SEGMENT_RUNTIME.counter_mode_step--; return 20 + (5 * (uint16_t)(255 - SEGMENT.speed)); } -/* - * Blink several LEDs on, reset, repeat. - * Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ - */ -uint16_t WS2812FX::mode_twinkle(void) { - return twinkle(SEGMENT.colors[0]); -} - -/* - * Blink several LEDs in random colors on, reset, repeat. - * Inspired by www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ - */ -uint16_t WS2812FX::mode_twinkle_random(void) { - return twinkle(color_wheel(random8())); -} - /* * fade out function diff --git a/wled00/WS2812FX.h b/wled00/WS2812FX.h index 8ca04e9a..5fb47121 100644 --- a/wled00/WS2812FX.h +++ b/wled00/WS2812FX.h @@ -103,8 +103,8 @@ #define FX_MODE_THEATER_CHASE 13 #define FX_MODE_THEATER_CHASE_RAINBOW 14 #define FX_MODE_RUNNING_LIGHTS 15 -#define FX_MODE_TWINKLE 16 -#define FX_MODE_TWINKLE_RANDOM 17 +#define FX_MODE_SAW 16 +#define FX_MODE_TWINKLE 17 #define FX_MODE_DISSOLVE 18 #define FX_MODE_DISSOLVE_RANDOM 19 #define FX_MODE_SPARKLE 20 @@ -211,8 +211,8 @@ class WS2812FX { _mode[FX_MODE_FADE] = &WS2812FX::mode_fade; _mode[FX_MODE_THEATER_CHASE] = &WS2812FX::mode_theater_chase; _mode[FX_MODE_THEATER_CHASE_RAINBOW] = &WS2812FX::mode_theater_chase_rainbow; + _mode[FX_MODE_SAW] = &WS2812FX::mode_saw; _mode[FX_MODE_TWINKLE] = &WS2812FX::mode_twinkle; - _mode[FX_MODE_TWINKLE_RANDOM] = &WS2812FX::mode_twinkle_random; _mode[FX_MODE_DISSOLVE] = &WS2812FX::mode_dissolve; _mode[FX_MODE_DISSOLVE_RANDOM] = &WS2812FX::mode_dissolve_random; _mode[FX_MODE_SPARKLE] = &WS2812FX::mode_sparkle; @@ -370,7 +370,7 @@ class WS2812FX { color_wipe(uint32_t, uint32_t, bool , bool), scan(bool), theater_chase(uint32_t, uint32_t, bool), - twinkle(uint32_t), + running_base(bool), dissolve(uint32_t), chase(uint32_t, uint32_t, uint32_t, uint8_t), gradient_base(bool), @@ -400,8 +400,8 @@ class WS2812FX { mode_rainbow(void), mode_rainbow_cycle(void), mode_running_lights(void), + mode_saw(void), mode_twinkle(void), - mode_twinkle_random(void), mode_dissolve(void), mode_dissolve_random(void), mode_sparkle(void), diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 04ce2538..576c2f80 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -78,7 +78,7 @@ //version code in format yymmddb (b = daily build) -#define VERSION 1902051 +#define VERSION 1902053 char versionString[] = "0.8.3-dev"; @@ -122,10 +122,8 @@ bool autoRGBtoRGBW = false; //if RGBW enabled, calculate White bool turnOnAtBoot = true; //turn on LEDs at power-up byte bootPreset = 0; //save preset to load after power-up -byte colS[]{255, 159, 0}; //default RGB color -byte colSecS[]{0, 0, 0}; //default RGB secondary color -byte whiteS = 0; //default White channel -byte whiteSecS = 0; //default secondary White channel +byte colS[]{255, 159, 0, 0}; //default RGB(W) color +byte colSecS[]{0, 0, 0, 0}; //default RGB(W) secondary color byte briS = 127; //default brightness byte effectDefault = 0; byte effectSpeedDefault = 75; @@ -246,16 +244,14 @@ uint16_t userVar0 = 0, userVar1 = 0; //internal global variable declarations //color -byte col[]{255, 159, 0}; //target RGB color -byte colOld[]{0, 0, 0}; //color before transition -byte colT[]{0, 0, 0}; //current color -byte colIT[]{0, 0, 0}; //color that was last sent to LEDs -byte colSec[]{0, 0, 0}; -byte colSecT[]{0, 0, 0}; -byte colSecOld[]{0, 0, 0}; -byte colSecIT[]{0, 0, 0}; -byte white = whiteS, whiteOld, whiteT, whiteIT; -byte whiteSec = whiteSecS, whiteSecOld, whiteSecT, whiteSecIT; +byte col[]{255, 159, 0, 0}; //target RGB(W) color +byte colOld[]{0, 0, 0, 0}; //color before transition +byte colT[]{0, 0, 0, 0}; //current color +byte colIT[]{0, 0, 0, 0}; //color that was last sent to LEDs +byte colSec[]{0, 0, 0, 0}; +byte colSecT[]{0, 0, 0, 0}; +byte colSecOld[]{0, 0, 0, 0}; +byte colSecIT[]{0, 0, 0, 0}; byte lastRandomIndex = 0; //used to save last random color so the new one is not the same diff --git a/wled00/wled01_eeprom.ino b/wled00/wled01_eeprom.ino index 90552bcb..c19009a8 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled01_eeprom.ino @@ -129,7 +129,7 @@ void saveSettingsToEEPROM() EEPROM.write(368, abs(arlsOffset)); EEPROM.write(369, turnOnAtBoot); EEPROM.write(370, useHSBDefault); - EEPROM.write(371, whiteS); + EEPROM.write(371, colS[3]); //white default EEPROM.write(372, useRGBW); EEPROM.write(373, effectPaletteDefault); EEPROM.write(374, strip.paletteFade); @@ -141,7 +141,7 @@ void saveSettingsToEEPROM() EEPROM.write(378, colSecS[0]); EEPROM.write(379, colSecS[1]); EEPROM.write(380, colSecS[2]); - EEPROM.write(381, whiteSecS); + EEPROM.write(381, colSecS[3]); EEPROM.write(382, strip.paletteBlend); EEPROM.write(383, strip.colorOrder); @@ -352,7 +352,7 @@ void loadSettingsFromEEPROM(bool first) if (!EEPROM.read(367)) arlsOffset = -arlsOffset; turnOnAtBoot = EEPROM.read(369); useHSBDefault = EEPROM.read(370); - whiteS = EEPROM.read(371); white = whiteS; + colS[3] = EEPROM.read(371); col[3] = colS[3]; useRGBW = EEPROM.read(372); effectPaletteDefault = EEPROM.read(373); effectPalette = effectPaletteDefault; //374 - strip.paletteFade @@ -363,10 +363,10 @@ void loadSettingsFromEEPROM(bool first) } //377 = lastEEPROMversion if (lastEEPROMversion > 1) { - colSecS[0] = EEPROM.read(378); colSec[0] = colSecS[0]; - colSecS[1] = EEPROM.read(379); colSec[1] = colSecS[1]; - colSecS[2] = EEPROM.read(380); colSec[2] = colSecS[2]; - whiteSecS = EEPROM.read(381); whiteSec = whiteSecS; + for (byte i=0; i<4; i++) + { + colSecS[i] = EEPROM.read(378+i); colSec[i] = colSecS[i]; + } } if (lastEEPROMversion > 3) { effectIntensityDefault = EEPROM.read(326); effectIntensity = effectIntensityDefault; @@ -538,14 +538,11 @@ bool applyPreset(byte index, bool loadBri = true, bool loadCol = true, bool load if (loadBri) bri = EEPROM.read(i+1); if (loadCol) { - col[0] = EEPROM.read(i+2); - col[1] = EEPROM.read(i+3); - col[2] = EEPROM.read(i+4); - white = EEPROM.read(i+5); - colSec[0] = EEPROM.read(i+6); - colSec[1] = EEPROM.read(i+7); - colSec[2] = EEPROM.read(i+8); - whiteSec = EEPROM.read(i+9); + for (byte j=0; j<4; j++) + { + col[j] = EEPROM.read(i+j+2); + colSec[j] = EEPROM.read(i+j+6); + } } if (loadFX) { @@ -564,14 +561,11 @@ void savePreset(byte index) uint16_t i = 380 + index*20;//min400 EEPROM.write(i, 1); EEPROM.write(i+1, bri); - EEPROM.write(i+2, col[0]); - EEPROM.write(i+3, col[1]); - EEPROM.write(i+4, col[2]); - EEPROM.write(i+5, white); - EEPROM.write(i+6, colSec[0]); - EEPROM.write(i+7, colSec[1]); - EEPROM.write(i+8, colSec[2]); - EEPROM.write(i+9, whiteSec); + for (uint16_t j=0; j<4; j++) + { + EEPROM.write(i+j+2, col[j]); + EEPROM.write(i+j+6, colSec[j]); + } EEPROM.write(i+10, effectCurrent); EEPROM.write(i+11, effectSpeed); diff --git a/wled00/wled02_xml.ino b/wled00/wled02_xml.ino index 712e0bf9..758e2fa7 100644 --- a/wled00/wled02_xml.ino +++ b/wled00/wled02_xml.ino @@ -45,12 +45,12 @@ void XML_response(bool isHTTP, bool includeTheme) oappendi(effectPalette); oappend(""); if (useRGBW && !autoRGBtoRGBW) { - oappendi(white); + oappendi(col[3]); } else { oappend("-1"); } oappend(""); - oappendi(whiteSec); + oappendi(colSec[3]); oappend(""); oappendi(useHSB); oappend(""); @@ -216,11 +216,11 @@ void getSettingsJS(byte subPage) sappend('c',"EW",useRGBW); sappend('i',"CO",strip.colorOrder); sappend('c',"AW",autoRGBtoRGBW); - sappend('v',"CW",whiteS); + sappend('v',"CW",colS[3]); sappend('v',"SR",colSecS[0]); sappend('v',"SG",colSecS[1]); sappend('v',"SB",colSecS[2]); - sappend('v',"SW",whiteSecS); + sappend('v',"SW",colSecS[3]); sappend('c',"BO",turnOnAtBoot); sappend('v',"BP",bootPreset); sappend('v',"FX",effectDefault); diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index 23956390..33fcb4b7 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -67,14 +67,11 @@ void handleSettingsSet(byte subPage) //ignore settings and save current brightness, colors and fx as default if (server.hasArg("IS")) { - colS[0] = col[0]; - colS[1] = col[1]; - colS[2] = col[2]; - colSecS[0] = colSec[0]; - colSecS[1] = colSec[1]; - colSecS[2] = colSec[2]; - whiteS = white; - whiteSecS = whiteSec; + for (byte i=0; i<4; i++) + { + colS[i] = col[i]; + colSecS[i] = colSec[i]; + } briS = bri; effectDefault = effectCurrent; effectSpeedDefault = effectSpeed; @@ -87,8 +84,8 @@ void handleSettingsSet(byte subPage) colSecS[0] = server.arg("SR").toInt(); colSecS[1] = server.arg("SG").toInt(); colSecS[2] = server.arg("SB").toInt(); - whiteS = server.arg("CW").toInt(); - whiteSecS = server.arg("SW").toInt(); + colS[3] = server.arg("CW").toInt(); + colSecS[3] = server.arg("SW").toInt(); briS = server.arg("CA").toInt(); effectDefault = server.arg("FX").toInt(); effectSpeedDefault = server.arg("SX").toInt(); @@ -386,7 +383,7 @@ bool handleSet(String req) //set white value pos = req.indexOf("&W="); if (pos > 0) { - white = getNumVal(&req, pos); + col[3] = getNumVal(&req, pos); } //set 2nd red value @@ -407,24 +404,24 @@ bool handleSet(String req) //set 2nd white value pos = req.indexOf("W2="); if (pos > 0) { - whiteSec = getNumVal(&req, pos); + colSec[3] = getNumVal(&req, pos); } //set color from HEX or 32bit DEC pos = req.indexOf("CL="); if (pos > 0) { - colorFromDecOrHexString(col, &white, (char*)req.substring(pos + 3).c_str()); + colorFromDecOrHexString(col, (char*)req.substring(pos + 3).c_str()); } pos = req.indexOf("C2="); if (pos > 0) { - colorFromDecOrHexString(colSec, &whiteSec, (char*)req.substring(pos + 3).c_str()); + colorFromDecOrHexString(colSec, (char*)req.substring(pos + 3).c_str()); } //set 2nd to white pos = req.indexOf("SW"); if (pos > 0) { if(useRGBW) { - whiteSec = 255; + colSec[3] = 255; colSec[0] = 0; colSec[1] = 0; colSec[2] = 0; @@ -438,7 +435,7 @@ bool handleSet(String req) //set 2nd to black pos = req.indexOf("SB"); if (pos > 0) { - whiteSec = 0; + colSec[3] = 0; colSec[0] = 0; colSec[1] = 0; colSec[2] = 0; @@ -455,21 +452,18 @@ bool handleSet(String req) colSec[0] = col[0]; colSec[1] = col[1]; colSec[2] = col[2]; - whiteSec = white; + colSec[3] = col[3]; } //swap 2nd & 1st pos = req.indexOf("SC"); if (pos > 0) { - byte _temp[4]; - for (int i = 0; i<3; i++) + byte temp; + for (uint8_t i=0; i<4; i++) { - _temp[i] = col[i]; + temp = col[i]; col[i] = colSec[i]; - colSec[i] = _temp[i]; + colSec[i] = temp; } - _temp[3] = white; - white = whiteSec; - whiteSec = _temp[3]; } //set current effect index diff --git a/wled00/wled07_notify.ino b/wled00/wled07_notify.ino index 6befaae5..3150cebd 100644 --- a/wled00/wled07_notify.ino +++ b/wled00/wled07_notify.ino @@ -33,12 +33,12 @@ void notify(byte callMode, bool followUp=false) udpOut[7] = nightlightDelayMins; udpOut[8] = effectCurrent; udpOut[9] = effectSpeed; - udpOut[10] = white; + udpOut[10] = col[3]; udpOut[11] = 5; //compatibilityVersionByte: 0: old 1: supports white 2: supports secondary color 3: supports FX intensity, 24 byte packet 4: supports transitionDelay 5: sup palette udpOut[12] = colSec[0]; udpOut[13] = colSec[1]; udpOut[14] = colSec[2]; - udpOut[15] = whiteSec; + udpOut[15] = colSec[3]; udpOut[16] = effectIntensity; udpOut[17] = (transitionDelay >> 0) & 0xFF; udpOut[18] = (transitionDelay >> 8) & 0xFF; @@ -168,13 +168,13 @@ void handleNotifications() col[2] = udpIn[5]; if (udpIn[11] > 0) //check if sending modules white val is inteded { - white = udpIn[10]; + col[3] = udpIn[10]; if (udpIn[11] > 1) { colSec[0] = udpIn[12]; colSec[1] = udpIn[13]; colSec[2] = udpIn[14]; - whiteSec = udpIn[15]; + colSec[3] = udpIn[15]; } } } diff --git a/wled00/wled08_led.ino b/wled00/wled08_led.ino index 5e9d7aee..3de46df6 100644 --- a/wled00/wled08_led.ino +++ b/wled00/wled08_led.ino @@ -34,51 +34,46 @@ void setAllLeds() { { colSecT[i] = colSec[i]; } - whiteSecT = whiteSec; + colSecT[3] = colSec[3]; } if (useRGBW && autoRGBtoRGBW) { - colorRGBtoRGBW(colT,&whiteT); - colorRGBtoRGBW(colSecT,&whiteSecT); + colorRGBtoRGBW(colT); + colorRGBtoRGBW(colSecT); } if (useGammaCorrectionRGB) { - strip.setColor(gamma8[colT[0]], gamma8[colT[1]], gamma8[colT[2]], gamma8[whiteT]); - strip.setSecondaryColor(gamma8[colSecT[0]], gamma8[colSecT[1]], gamma8[colSecT[2]], gamma8[whiteSecT]); + strip.setColor(gamma8[colT[0]], gamma8[colT[1]], gamma8[colT[2]], gamma8[colT[3]]); + strip.setSecondaryColor(gamma8[colSecT[0]], gamma8[colSecT[1]], gamma8[colSecT[2]], gamma8[colSecT[3]]); } else { - strip.setColor(colT[0], colT[1], colT[2], whiteT); - strip.setSecondaryColor(colSecT[0], colSecT[1], colSecT[2], whiteSecT); + strip.setColor(colT[0], colT[1], colT[2], colT[3]); + strip.setSecondaryColor(colSecT[0], colSecT[1], colSecT[2], colSecT[3]); } } void setLedsStandard() { - for (byte i = 0; i<3; i++) + for (byte i=0; i<4; i++) { colOld[i] = col[i]; colT[i] = col[i]; colSecOld[i] = colSec[i]; colSecT[i] = colSec[i]; } - whiteOld = white; briOld = bri; - whiteSecOld = whiteSec; - whiteT = white; briT = bri; - whiteSecT = whiteSec; setAllLeds(); } bool colorChanged() { - for (int i = 0; i < 3; i++) + for (byte i=0; i<4; i++) { if (col[i] != colIT[i]) return true; if (colSec[i] != colSecIT[i]) return true; } - if (white != whiteIT || whiteSec != whiteSecIT) return true; if (bri != briIT) return true; return false; } @@ -104,14 +99,11 @@ void colorUpdated(int callMode) nightlightDelayMs -= (millis() - nightlightStartTime); nightlightStartTime = millis(); } - colIT[0] = col[0]; - colIT[1] = col[1]; - colIT[2] = col[2]; - colSecIT[0] = colSec[0]; - colSecIT[1] = colSec[1]; - colSecIT[2] = colSec[2]; - whiteIT = white; - whiteSecIT = whiteSec; + for (byte i=0; i<4; i++) + { + colIT[i] = col[i]; + colSecIT[i] = colSec[i]; + } briIT = bri; if (bri > 0) briLast = bri; @@ -125,14 +117,11 @@ void colorUpdated(int callMode) if (transitionActive) { - colOld[0] = colT[0]; - colOld[1] = colT[1]; - colOld[2] = colT[2]; - whiteOld = whiteT; - colSecOld[0] = colSecT[0]; - colSecOld[1] = colSecT[1]; - colSecOld[2] = colSecT[2]; - whiteSecOld = whiteSecT; + for (byte i=0; i<4; i++) + { + colOld[i] = colT[i]; + colSecOld[i] = colSecT[i]; + } briOld = briT; tperLast = 0; } @@ -189,13 +178,11 @@ void handleTransitions() } if (tper - tperLast < 0.004) return; tperLast = tper; - for (byte i = 0; i<3; i++) + for (byte i=0; i<4; i++) { colT[i] = colOld[i]+((col[i] - colOld[i])*tper); colSecT[i] = colSecOld[i]+((colSec[i] - colSecOld[i])*tper); } - whiteT = whiteOld +((white - whiteOld )*tper); - whiteSecT = whiteSecOld +((whiteSec - whiteSecOld )*tper); briT = briOld +((bri - briOld )*tper); setAllLeds(); diff --git a/wled00/wled11_ol.ino b/wled00/wled11_ol.ino index f0b8bb84..6cf060c3 100644 --- a/wled00/wled11_ol.ino +++ b/wled00/wled11_ol.ino @@ -22,7 +22,7 @@ void _nixieDisplay(int num[], uint16_t dur[], uint16_t pausedur[], byte cnt) strip.setRange(overlayMin, overlayMax, 0); if (num[nixieClockI] >= 0 && !nixiePause) { - strip.setIndividual(num[nixieClockI],((uint32_t)white << 24)| ((uint32_t)colT[0] << 16) | ((uint32_t)colT[1] << 8) | colT[2]); + strip.setIndividual(num[nixieClockI],((uint32_t)colT[3] << 24)| ((uint32_t)colT[0] << 16) | ((uint32_t)colT[1] << 8) | colT[2]); strip.unlock(num[nixieClockI]); } if (!nixiePause) @@ -310,11 +310,11 @@ void _overlayAnalogCountdown() byte pixelCnt = perc*overlaySize; if (analogClock12pixel + pixelCnt > overlayMax) { - strip.setRange(analogClock12pixel, overlayMax, ((uint32_t)whiteSec << 24)| ((uint32_t)colSec[0] << 16) | ((uint32_t)colSec[1] << 8) | colSec[2]); - strip.setRange(overlayMin, overlayMin +pixelCnt -(1+ overlayMax -analogClock12pixel), ((uint32_t)whiteSec << 24)| ((uint32_t)colSec[0] << 16) | ((uint32_t)colSec[1] << 8) | colSec[2]); + strip.setRange(analogClock12pixel, overlayMax, ((uint32_t)colSec[3] << 24)| ((uint32_t)colSec[0] << 16) | ((uint32_t)colSec[1] << 8) | colSec[2]); + strip.setRange(overlayMin, overlayMin +pixelCnt -(1+ overlayMax -analogClock12pixel), ((uint32_t)colSec[3] << 24)| ((uint32_t)colSec[0] << 16) | ((uint32_t)colSec[1] << 8) | colSec[2]); } else { - strip.setRange(analogClock12pixel, analogClock12pixel + pixelCnt, ((uint32_t)whiteSec << 24)| ((uint32_t)colSec[0] << 16) | ((uint32_t)colSec[1] << 8) | colSec[2]); + strip.setRange(analogClock12pixel, analogClock12pixel + pixelCnt, ((uint32_t)colSec[3] << 24)| ((uint32_t)colSec[0] << 16) | ((uint32_t)colSec[1] << 8) | colSec[2]); } } overlayRefreshMs = 998; diff --git a/wled00/wled12_alexa.ino b/wled00/wled12_alexa.ino index f9ccb6a5..4f249680 100644 --- a/wled00/wled12_alexa.ino +++ b/wled00/wled12_alexa.ino @@ -68,7 +68,7 @@ void onAlexaChange(byte b, uint32_t color) col[0] = ((color >> 16) & 0xFF); col[1] = ((color >> 8) & 0xFF); col[2] = (color & 0xFF); - if (useRGBW) colorRGBtoRGBW(col,&white); + if (useRGBW) colorRGBtoRGBW(col); colorUpdated(10); } } diff --git a/wled00/wled14_colors.ino b/wled00/wled14_colors.ino index 5dbf378b..2562ac3f 100644 --- a/wled00/wled14_colors.ino +++ b/wled00/wled14_colors.ino @@ -4,7 +4,7 @@ void colorFromUint32(uint32_t in) { - white = in >> 24 & 0xFF; + col[3] = in >> 24 & 0xFF; col[0] = in >> 16 & 0xFF; col[1] = in >> 8 & 0xFF; col[2] = in & 0xFF; @@ -118,7 +118,7 @@ void colorRGBtoXY(byte* rgb, float* xy) //rgb to coordinates (https://www.develo } #endif -void colorFromDecOrHexString(byte* rgb, byte* wht, char* in) +void colorFromDecOrHexString(byte* rgb, char* in) { if (in[0] == 0) return; char first = in[0]; @@ -132,7 +132,7 @@ void colorFromDecOrHexString(byte* rgb, byte* wht, char* in) c = strtoul(in, NULL, 10); } - *wht = (c >> 24) & 0xFF; + rgb[3] = (c >> 24) & 0xFF; rgb[0] = (c >> 16) & 0xFF; rgb[1] = (c >> 8) & 0xFF; rgb[2] = c & 0xFF; @@ -150,11 +150,11 @@ float maxf (float v, float w) return v; } -void colorRGBtoRGBW(byte* rgb, byte* wht) //rgb to rgbw (http://codewelt.com/rgbw) +void colorRGBtoRGBW(byte* rgb) //rgb to rgbw (http://codewelt.com/rgbw) { float low = minf(rgb[0],minf(rgb[1],rgb[2])); float high = maxf(rgb[0],maxf(rgb[1],rgb[2])); if (high < 0.1f) return; float sat = 255.0f * ((high - low) / high); - *wht = (byte)((255.0f - sat) / 255.0f * (rgb[0] + rgb[1] + rgb[2]) / 3); + rgb[3] = (byte)((255.0f - sat) / 255.0f * (rgb[0] + rgb[1] + rgb[2]) / 3); } diff --git a/wled00/wled17_mqtt.ino b/wled00/wled17_mqtt.ino index 1a1fd8ee..d8ac1f4c 100644 --- a/wled00/wled17_mqtt.ino +++ b/wled00/wled17_mqtt.ino @@ -25,7 +25,7 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length) { if (strstr(topic, "/col")) { - colorFromDecOrHexString(col, &white, (char*)payload); + colorFromDecOrHexString(col, (char*)payload); colorUpdated(1); } else if (strstr(topic, "/api")) { @@ -53,7 +53,7 @@ void publishMQTT() strcat(subuf, "/g"); mqtt->publish(subuf, s); - sprintf(s, "#%X", white*16777216 + col[0]*65536 + col[1]*256 + col[2]); + sprintf(s, "#%X", col[3]*16777216 + col[0]*65536 + col[1]*256 + col[2]); strcpy(subuf, mqttDeviceTopic); strcat(subuf, "/c"); mqtt->publish(subuf, s);