From 9d22a0696926dbe880eda4ea28194688ae97c78d Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 31 May 2023 20:12:17 +0200 Subject: [PATCH] Changes for allowing Alexa to change light color to White when auto-calculating from RGB (#3211) * Changes for allowing Alexa to change light color to White when auto-calculating from RGB * Update alexa.cpp Indention * Do not rely on global auto white override (gets white mode from segment light capabilities) * alexa.cpp: Removed unnecessary whitespaces --------- Co-authored-by: Aircoookie <21045690+Aircoookie@users.noreply.github.com> --- wled00/FX.h | 1 + wled00/FX_fcn.cpp | 8 ++++++++ wled00/alexa.cpp | 23 +++++++++++++++-------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index 40fb0d48f..19b1fc4ac 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -772,6 +772,7 @@ class WS2812FX { // 96 bytes getActiveSegmentsNum(void), getFirstSelectedSegId(void), getLastActiveSegmentId(void), + getActiveSegsLightCapabilities(bool selectedOnly = false), setPixelSegment(uint8_t n); inline uint8_t getBrightness(void) { return _brightness; } diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index fe26e0290..c60ea5f23 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -1330,6 +1330,14 @@ void WS2812FX::setBrightness(uint8_t b, bool direct) { } } +uint8_t WS2812FX::getActiveSegsLightCapabilities(bool selectedOnly) { + uint8_t totalLC = 0; + for (segment &seg : _segments) { + if (seg.isActive() && (!selectedOnly || seg.isSelected())) totalLC |= seg.getLightCapabilities(); + } + return totalLC; +} + uint8_t WS2812FX::getFirstSelectedSegId(void) { size_t i = 0; diff --git a/wled00/alexa.cpp b/wled00/alexa.cpp index c122402a4..179a522c0 100644 --- a/wled00/alexa.cpp +++ b/wled00/alexa.cpp @@ -101,20 +101,27 @@ void onAlexaChange(EspalexaDevice* dev) { byte rgbw[4]; uint16_t ct = dev->getCt(); - if (!ct) return; - uint16_t k = 1000000 / ct; //mireds to kelvin - - if (strip.hasCCTBus()) { - strip.setCCT(k); - rgbw[0]= 0; rgbw[1]= 0; rgbw[2]= 0; rgbw[3]= 255; - } else if (strip.hasWhiteChannel()) { + if (!ct) return; + uint16_t k = 1000000 / ct; //mireds to kelvin + + if (strip.hasCCTBus()) { + bool hasManualWhite = strip.getActiveSegsLightCapabilities(true) & SEG_CAPABILITY_W; + + strip.setCCT(k); + if (hasManualWhite) { + rgbw[0] = 0; rgbw[1] = 0; rgbw[2] = 0; rgbw[3] = 255; + } else { + rgbw[0] = 255; rgbw[1] = 255; rgbw[2] = 255; rgbw[3] = 0; + dev->setValue(255); + } + } else if (strip.hasWhiteChannel()) { switch (ct) { //these values empirically look good on RGBW case 199: rgbw[0]=255; rgbw[1]=255; rgbw[2]=255; rgbw[3]=255; break; case 234: rgbw[0]=127; rgbw[1]=127; rgbw[2]=127; rgbw[3]=255; break; case 284: rgbw[0]= 0; rgbw[1]= 0; rgbw[2]= 0; rgbw[3]=255; break; case 350: rgbw[0]=130; rgbw[1]= 90; rgbw[2]= 0; rgbw[3]=255; break; case 383: rgbw[0]=255; rgbw[1]=153; rgbw[2]= 0; rgbw[3]=255; break; - default : colorKtoRGB(k, rgbw); + default : colorKtoRGB(k, rgbw); } } else { colorKtoRGB(k, rgbw);