From 4d10c9de955df123c2829fc4344d8c5c77d6a5ea Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Sun, 27 Feb 2022 16:18:37 +0100 Subject: [PATCH] Removed unnecessary set call. Fixed incorrect colorUpdated call. Fixed white +/- in IR40 remote. --- wled00/colors.cpp | 10 ------ wled00/fcn_declare.h | 1 - wled00/ir.cpp | 78 +++++++++++++++++++++++++------------------- wled00/set.cpp | 1 - wled00/wled.h | 2 +- 5 files changed, 46 insertions(+), 46 deletions(-) diff --git a/wled00/colors.cpp b/wled00/colors.cpp index b63dab38e..25cce032e 100644 --- a/wled00/colors.cpp +++ b/wled00/colors.cpp @@ -10,16 +10,6 @@ void setRandomColor(byte* rgb) colorHStoRGB(lastRandomIndex*256,255,rgb); } -//relatively change white brightness, minumum A=5 -void relativeChangeWhite(int8_t amount, byte lowerBoundary) -{ - int16_t new_val = (int16_t) col[3] + amount; - if (new_val > 0xFF) new_val = 0xFF; - else if (new_val < lowerBoundary) new_val = lowerBoundary; - col[3] = new_val; - stateChanged = true; -} - void colorHStoRGB(uint16_t hue, byte sat, byte* rgb) //hue, sat to rgb { float h = ((float)hue)/65535.0; diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index c9ee0af26..26ba161c8 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -59,7 +59,6 @@ bool getJsonValue(const JsonVariant& element, DestType& destination, const Defau //colors.cpp inline uint32_t colorFromRgbw(byte* rgbw) { return uint32_t((byte(rgbw[3]) << 24) | (byte(rgbw[0]) << 16) | (byte(rgbw[1]) << 8) | (byte(rgbw[2]))); } -void relativeChangeWhite(int8_t amount, byte lowerBoundary = 0); void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb void colorKtoRGB(uint16_t kelvin, byte* rgb); void colorCTtoRGB(uint16_t mired, byte* rgb); //white spectrum to rgb diff --git a/wled00/ir.cpp b/wled00/ir.cpp index 0b4c1222b..aadd17d25 100644 --- a/wled00/ir.cpp +++ b/wled00/ir.cpp @@ -249,17 +249,27 @@ void changeColor(uint32_t c, int16_t cct=-1) stateChanged = true; } +void changeWhite(int8_t amount, int16_t cct=-1) +{ + WS2812FX::Segment& seg = irApplyToAllSelected ? strip.getFirstSelectedSeg() : strip.getMainSegment(); + byte r = R(seg.colors[0]); + byte g = G(seg.colors[0]); + byte b = B(seg.colors[0]); + byte w = relativeChange(W(seg.colors[0]), amount, 5); + changeColor(RGBW32(r, g, b, w), cct); +} + void decodeIR(uint32_t code) { - if (code == 0xFFFFFFFF) //repeated code, continue brightness up/down - { + if (code == 0xFFFFFFFF) { + //repeated code, continue brightness up/down irTimesRepeated++; applyRepeatActions(); return; } lastValidCode = 0; irTimesRepeated = 0; - //if (decodeIRCustom(code)) return; lastRepeatableAction = ACTION_NONE; + if (irEnabled == 8) { // any remote configurable with ir.json file decodeIRJson(code); stateUpdated(CALL_MODE_BUTTON); @@ -269,25 +279,22 @@ void decodeIR(uint32_t code) switch (irEnabled) { case 1: - if (code > 0xF80000) { - decodeIR24OLD(code); // white 24-key remote (old) - it sends 0xFF0000 values - } else { - decodeIR24(code); // 24-key remote - 0xF70000 to 0xF80000 - } + if (code > 0xF80000) decodeIR24OLD(code); // white 24-key remote (old) - it sends 0xFF0000 values + else decodeIR24(code); // 24-key remote - 0xF70000 to 0xF80000 break; - case 2: decodeIR24CT(code); break; // white 24-key remote with CW, WW, CT+ and CT- keys - case 3: decodeIR40(code); break; // blue 40-key remote with 25%, 50%, 75% and 100% keys - case 4: decodeIR44(code); break; // white 44-key remote with color-up/down keys and DIY1 to 6 keys - case 5: decodeIR21(code); break; // white 21-key remote - case 6: decodeIR6(code); break; // black 6-key learning remote defaults: "CH" controls brightness, - // "VOL +" controls effect, "VOL -" controls colour/palette, "MUTE" - // sets bright plain white - case 7: decodeIR9(code); break; + case 2: decodeIR24CT(code); break; // white 24-key remote with CW, WW, CT+ and CT- keys + case 3: decodeIR40(code); break; // blue 40-key remote with 25%, 50%, 75% and 100% keys + case 4: decodeIR44(code); break; // white 44-key remote with color-up/down keys and DIY1 to 6 keys + case 5: decodeIR21(code); break; // white 21-key remote + case 6: decodeIR6(code); break; // black 6-key learning remote defaults: "CH" controls brightness, + // "VOL +" controls effect, "VOL -" controls colour/palette, "MUTE" + // sets bright plain white + case 7: decodeIR9(code); break; //case 8: return; // ir.json file, handled above switch statement } if (nightlightActive && bri == 0) nightlightActive = false; - colorUpdated(CALL_MODE_BUTTON); //for notifier, IR is considered a button input + stateUpdated(CALL_MODE_BUTTON); //for notifier, IR is considered a button input } void applyRepeatActions() @@ -296,24 +303,24 @@ void applyRepeatActions() decodeIRJson(lastValidCode); return; } else switch (lastRepeatableAction) { - case ACTION_BRIGHT_UP : incBrightness(); colorUpdated(CALL_MODE_BUTTON); return; - case ACTION_BRIGHT_DOWN : decBrightness(); colorUpdated(CALL_MODE_BUTTON); return; - case ACTION_SPEED_UP : changeEffectSpeed(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); return; - case ACTION_SPEED_DOWN : changeEffectSpeed(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); return; - case ACTION_INTENSITY_UP : changeEffectIntensity(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); return; - case ACTION_INTENSITY_DOWN : changeEffectIntensity(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); return; + case ACTION_BRIGHT_UP : incBrightness(); stateUpdated(CALL_MODE_BUTTON); return; + case ACTION_BRIGHT_DOWN : decBrightness(); stateUpdated(CALL_MODE_BUTTON); return; + case ACTION_SPEED_UP : changeEffectSpeed(lastRepeatableValue); stateUpdated(CALL_MODE_BUTTON); return; + case ACTION_SPEED_DOWN : changeEffectSpeed(lastRepeatableValue); stateUpdated(CALL_MODE_BUTTON); return; + case ACTION_INTENSITY_UP : changeEffectIntensity(lastRepeatableValue); stateUpdated(CALL_MODE_BUTTON); return; + case ACTION_INTENSITY_DOWN : changeEffectIntensity(lastRepeatableValue); stateUpdated(CALL_MODE_BUTTON); return; default: break; } - if (lastValidCode == IR40_WPLUS) { - relativeChangeWhite(10); - colorUpdated(CALL_MODE_BUTTON); + if (lastValidCode == IR40_WPLUS) { + changeWhite(10); + stateUpdated(CALL_MODE_BUTTON); } else if (lastValidCode == IR40_WMINUS) { - relativeChangeWhite(-10, 5); - colorUpdated(CALL_MODE_BUTTON); + changeWhite(-10); + stateUpdated(CALL_MODE_BUTTON); } else if ((lastValidCode == IR24_ON || lastValidCode == IR40_ON) && irTimesRepeated > 7 ) { nightlightActive = true; nightlightStartTime = millis(); - colorUpdated(CALL_MODE_BUTTON); + stateUpdated(CALL_MODE_BUTTON); } } @@ -415,6 +422,11 @@ void decodeIR24CT(uint32_t code) void decodeIR40(uint32_t code) { + WS2812FX::Segment& seg = irApplyToAllSelected ? strip.getFirstSelectedSeg() : strip.getMainSegment(); + byte r = R(seg.colors[0]); + byte g = G(seg.colors[0]); + byte b = B(seg.colors[0]); + byte w = W(seg.colors[0]); switch (code) { case IR40_BPLUS : incBrightness(); break; case IR40_BMINUS : decBrightness(); break; @@ -440,10 +452,10 @@ void decodeIR40(uint32_t code) case IR40_WHITE : changeColor(COLOR_NEUTRALWHITE, 127); changeEffect(FX_MODE_STATIC); break; case IR40_COLDWHITE : changeColor(COLOR_COLDWHITE, 191); changeEffect(FX_MODE_STATIC); break; case IR40_COLDWHITE2 : changeColor(COLOR_COLDWHITE2, 255); changeEffect(FX_MODE_STATIC); break; - case IR40_WPLUS : relativeChangeWhite(10); break; - case IR40_WMINUS : relativeChangeWhite(-10, 5); break; - case IR40_WOFF : whiteLast = col[3]; col[3] = 0; break; - case IR40_WON : col[3] = whiteLast; break; + case IR40_WPLUS : changeWhite(10); break; + case IR40_WMINUS : changeWhite(-10); break; + case IR40_WOFF : if (w) whiteLast = w; changeColor(RGBW32(r, g, b, 0)); break; + case IR40_WON : changeColor(RGBW32(r, g, b, whiteLast)); break; case IR40_W25 : bri = 63; break; case IR40_W50 : bri = 127; break; case IR40_W75 : bri = 191; break; diff --git a/wled00/set.cpp b/wled00/set.cpp index 7f0bca033..7ff7f74c9 100644 --- a/wled00/set.cpp +++ b/wled00/set.cpp @@ -776,7 +776,6 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply) if (intensityChanged) seg.intensity = intensityIn; if (paletteChanged) seg.palette = paletteIn; } - setValuesFromFirstSelectedSeg(); // will fill col[] and cloSec[] as well as effectCurrent, ... //set advanced overlay pos = req.indexOf(F("OL=")); diff --git a/wled00/wled.h b/wled00/wled.h index 559730f94..560449117 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2202241 +#define VERSION 2202271 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG