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>
settings
Sebastian 2023-05-31 20:12:17 +02:00 zatwierdzone przez GitHub
rodzic e3783e0236
commit 9d22a06969
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 24 dodań i 8 usunięć

Wyświetl plik

@ -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; }

Wyświetl plik

@ -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;

Wyświetl plik

@ -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);