2020-03-25 09:00:55 +01:00
|
|
|
#include "wled.h"
|
2020-03-31 02:38:08 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Infrared sensor support for generic 24/40/44 key RGB remotes
|
|
|
|
*/
|
2018-11-18 00:31:45 +01:00
|
|
|
|
2020-01-08 00:46:16 +01:00
|
|
|
#if defined(WLED_DISABLE_INFRARED)
|
2018-11-22 00:09:30 +01:00
|
|
|
void handleIR(){}
|
|
|
|
#else
|
|
|
|
|
2018-11-18 00:31:45 +01:00
|
|
|
IRrecv* irrecv;
|
|
|
|
//change pin in NpbWrapper.h
|
|
|
|
|
|
|
|
decode_results results;
|
|
|
|
|
|
|
|
unsigned long irCheckedTime = 0;
|
|
|
|
uint32_t lastValidCode = 0;
|
2020-06-04 14:24:55 +02:00
|
|
|
byte lastRepeatableAction = ACTION_NONE;
|
|
|
|
uint8_t lastRepeatableValue = 0;
|
2018-11-18 00:31:45 +01:00
|
|
|
uint16_t irTimesRepeated = 0;
|
2020-01-25 17:35:18 +01:00
|
|
|
uint8_t lastIR6ColourIdx = 0;
|
2018-11-18 00:31:45 +01:00
|
|
|
|
|
|
|
|
2021-02-13 21:50:27 +01:00
|
|
|
// brightnessSteps: a static array of brightness levels following a geometric
|
|
|
|
// progression. Can be generated from the following Python, adjusting the
|
|
|
|
// arbitrary 4.5 value to taste:
|
|
|
|
//
|
|
|
|
// def values(level):
|
|
|
|
// while level >= 5:
|
|
|
|
// yield int(level)
|
|
|
|
// level -= level / 4.5
|
|
|
|
// result = [v for v in reversed(list(values(255)))]
|
|
|
|
// print("%d values: %s" % (len(result), result))
|
|
|
|
//
|
|
|
|
// It would be hard to maintain repeatable steps if calculating this on the fly.
|
|
|
|
const byte brightnessSteps[] = {
|
|
|
|
5, 7, 9, 12, 16, 20, 26, 34, 43, 56, 72, 93, 119, 154, 198, 255
|
|
|
|
};
|
|
|
|
const size_t numBrightnessSteps = sizeof(brightnessSteps) / sizeof(uint8_t);
|
|
|
|
|
|
|
|
// increment `bri` to the next `brightnessSteps` value
|
|
|
|
void incBrightness()
|
|
|
|
{
|
|
|
|
// dumb incremental search is efficient enough for so few items
|
|
|
|
for (int index = 0; index < numBrightnessSteps; ++index)
|
|
|
|
{
|
|
|
|
if (brightnessSteps[index] > bri)
|
|
|
|
{
|
|
|
|
bri = brightnessSteps[index];
|
|
|
|
lastRepeatableAction = ACTION_BRIGHT_UP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// decrement `bri` to the next `brightnessSteps` value
|
|
|
|
void decBrightness()
|
|
|
|
{
|
|
|
|
// dumb incremental search is efficient enough for so few items
|
|
|
|
for (int index = numBrightnessSteps - 1; index >= 0; --index)
|
|
|
|
{
|
|
|
|
if (brightnessSteps[index] < bri)
|
|
|
|
{
|
|
|
|
bri = brightnessSteps[index];
|
|
|
|
lastRepeatableAction = ACTION_BRIGHT_DOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-22 00:09:30 +01:00
|
|
|
//Add what your custom IR codes should trigger here. Guide: https://github.com/Aircoookie/WLED/wiki/Infrared-Control
|
|
|
|
//IR codes themselves can be defined directly after "case" or in "ir_codes.h"
|
|
|
|
bool decodeIRCustom(uint32_t code)
|
|
|
|
{
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
//just examples, feel free to modify or remove
|
|
|
|
case IRCUSTOM_ONOFF : toggleOnOff(); break;
|
2020-11-06 22:12:48 +01:00
|
|
|
case IRCUSTOM_MACRO1 : applyPreset(1); break;
|
2018-11-22 00:09:30 +01:00
|
|
|
|
|
|
|
default: return false;
|
|
|
|
}
|
2020-02-22 16:17:32 +01:00
|
|
|
if (code != IRCUSTOM_MACRO1) colorUpdated(NOTIFIER_CALL_MODE_BUTTON); //don't update color again if we apply macro, it already does it
|
2018-11-22 00:09:30 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-04 14:24:55 +02:00
|
|
|
|
2020-03-26 09:49:35 +01:00
|
|
|
void relativeChange(byte* property, int8_t amount, byte lowerBoundary, byte higherBoundary)
|
2018-11-18 00:31:45 +01:00
|
|
|
{
|
|
|
|
int16_t new_val = (int16_t) *property + amount;
|
2020-03-02 13:31:34 +01:00
|
|
|
if (new_val > higherBoundary) new_val = higherBoundary;
|
2018-11-18 00:31:45 +01:00
|
|
|
else if (new_val < lowerBoundary) new_val = lowerBoundary;
|
2020-03-02 13:31:34 +01:00
|
|
|
*property = (byte)constrain(new_val,0.1,255.1);
|
2018-11-18 00:31:45 +01:00
|
|
|
}
|
|
|
|
|
2020-03-02 13:31:34 +01:00
|
|
|
void changeEffectSpeed(int8_t amount)
|
|
|
|
{
|
|
|
|
if (effectCurrent != 0) {
|
|
|
|
int16_t new_val = (int16_t) effectSpeed + amount;
|
|
|
|
effectSpeed = (byte)constrain(new_val,0.1,255.1);
|
|
|
|
} else { // if Effect == "solid Color", change the hue of the primary color
|
|
|
|
CRGB fastled_col;
|
|
|
|
fastled_col.red = col[0];
|
|
|
|
fastled_col.green = col[1];
|
|
|
|
fastled_col.blue = col[2];
|
|
|
|
CHSV prim_hsv = rgb2hsv_approximate(fastled_col);
|
|
|
|
int16_t new_val = (int16_t) prim_hsv.h + amount;
|
|
|
|
if (new_val > 255) new_val -= 255; // roll-over if bigger than 255
|
|
|
|
if (new_val < 0) new_val += 255; // roll-over if smaller than 0
|
|
|
|
prim_hsv.h = (byte)new_val;
|
|
|
|
hsv2rgb_rainbow(prim_hsv, fastled_col);
|
|
|
|
col[0] = fastled_col.red;
|
|
|
|
col[1] = fastled_col.green;
|
|
|
|
col[2] = fastled_col.blue;
|
|
|
|
}
|
2020-06-04 14:24:55 +02:00
|
|
|
|
|
|
|
if(amount > 0) lastRepeatableAction = ACTION_SPEED_UP;
|
|
|
|
if(amount < 0) lastRepeatableAction = ACTION_SPEED_DOWN;
|
|
|
|
lastRepeatableValue = amount;
|
2020-03-02 13:31:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void changeEffectIntensity(int8_t amount)
|
|
|
|
{
|
|
|
|
if (effectCurrent != 0) {
|
|
|
|
int16_t new_val = (int16_t) effectIntensity + amount;
|
|
|
|
effectIntensity = (byte)constrain(new_val,0.1,255.1);
|
|
|
|
} else { // if Effect == "solid Color", change the saturation of the primary color
|
|
|
|
CRGB fastled_col;
|
|
|
|
fastled_col.red = col[0];
|
|
|
|
fastled_col.green = col[1];
|
|
|
|
fastled_col.blue = col[2];
|
|
|
|
CHSV prim_hsv = rgb2hsv_approximate(fastled_col);
|
|
|
|
int16_t new_val = (int16_t) prim_hsv.s + amount;
|
|
|
|
prim_hsv.s = (byte)constrain(new_val,0.1,255.1); // constrain to 0-255
|
|
|
|
hsv2rgb_rainbow(prim_hsv, fastled_col);
|
|
|
|
col[0] = fastled_col.red;
|
|
|
|
col[1] = fastled_col.green;
|
|
|
|
col[2] = fastled_col.blue;
|
|
|
|
}
|
2020-06-04 14:24:55 +02:00
|
|
|
|
|
|
|
if(amount > 0) lastRepeatableAction = ACTION_INTENSITY_UP;
|
|
|
|
if(amount < 0) lastRepeatableAction = ACTION_INTENSITY_DOWN;
|
|
|
|
lastRepeatableValue = amount;
|
2020-03-02 13:31:34 +01:00
|
|
|
}
|
2018-11-22 00:09:30 +01:00
|
|
|
|
|
|
|
void decodeIR(uint32_t code)
|
2018-11-18 00:31:45 +01:00
|
|
|
{
|
|
|
|
if (code == 0xFFFFFFFF) //repeated code, continue brightness up/down
|
|
|
|
{
|
|
|
|
irTimesRepeated++;
|
2020-06-04 14:24:55 +02:00
|
|
|
applyRepeatActions();
|
2018-11-18 00:31:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastValidCode = 0; irTimesRepeated = 0;
|
2018-11-22 00:09:30 +01:00
|
|
|
if (decodeIRCustom(code)) return;
|
2018-11-18 00:31:45 +01:00
|
|
|
if (code > 0xFFFFFF) return; //invalid code
|
|
|
|
else if (code > 0xF70000 && code < 0xF80000) decodeIR24(code); //is in 24-key remote range
|
2020-01-08 00:46:16 +01:00
|
|
|
else if (code > 0xFF0000) {
|
|
|
|
switch (irEnabled) {
|
|
|
|
case 1: decodeIR24OLD(code); break; // white 24-key remote (old) - it sends 0xFF0000 values
|
|
|
|
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
|
2020-01-19 12:53:44 +01:00
|
|
|
case 5: decodeIR21(code); break; // white 21-key remote
|
2020-02-22 16:17:32 +01:00
|
|
|
case 6: decodeIR6(code); break; // black 6-key learning remote defaults: "CH" controls brightness,
|
2020-01-25 17:35:18 +01:00
|
|
|
// "VOL +" controls effect, "VOL -" controls colour/palette, "MUTE"
|
|
|
|
// sets bright plain white
|
2020-06-04 14:24:55 +02:00
|
|
|
case 7: decodeIR9(code); break;
|
2020-01-08 00:46:16 +01:00
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
}
|
2020-03-02 12:41:14 +01:00
|
|
|
if (nightlightActive && bri == 0) nightlightActive = false;
|
2020-02-28 16:27:18 +01:00
|
|
|
colorUpdated(NOTIFIER_CALL_MODE_BUTTON); //for notifier, IR is considered a button input
|
2018-11-18 00:31:45 +01:00
|
|
|
//code <= 0xF70000 also invalid
|
|
|
|
}
|
|
|
|
|
2020-06-04 14:24:55 +02:00
|
|
|
void applyRepeatActions(){
|
|
|
|
|
|
|
|
if (lastRepeatableAction == ACTION_BRIGHT_UP)
|
|
|
|
{
|
2021-02-13 21:50:27 +01:00
|
|
|
incBrightness(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
2020-06-04 14:24:55 +02:00
|
|
|
}
|
|
|
|
else if (lastRepeatableAction == ACTION_BRIGHT_DOWN )
|
|
|
|
{
|
2021-02-13 21:50:27 +01:00
|
|
|
decBrightness(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
2020-06-04 14:24:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lastRepeatableAction == ACTION_SPEED_UP)
|
|
|
|
{
|
|
|
|
changeEffectSpeed(lastRepeatableValue); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
|
|
|
}
|
|
|
|
else if (lastRepeatableAction == ACTION_SPEED_DOWN )
|
|
|
|
{
|
|
|
|
changeEffectSpeed(lastRepeatableValue); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastRepeatableAction == ACTION_INTENSITY_UP)
|
|
|
|
{
|
|
|
|
changeEffectIntensity(lastRepeatableValue); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
|
|
|
}
|
|
|
|
else if (lastRepeatableAction == ACTION_INTENSITY_DOWN )
|
|
|
|
{
|
|
|
|
changeEffectIntensity(lastRepeatableValue); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastValidCode == IR40_WPLUS)
|
|
|
|
{
|
|
|
|
relativeChangeWhite(10); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
|
|
|
}
|
|
|
|
else if (lastValidCode == IR40_WMINUS)
|
|
|
|
{
|
|
|
|
relativeChangeWhite(-10, 5); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
|
|
|
}
|
|
|
|
else if ((lastValidCode == IR24_ON || lastValidCode == IR40_ON) && irTimesRepeated > 7 )
|
|
|
|
{
|
|
|
|
nightlightActive = true;
|
|
|
|
nightlightStartTime = millis();
|
|
|
|
colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-22 00:09:30 +01:00
|
|
|
|
2018-11-18 00:31:45 +01:00
|
|
|
void decodeIR24(uint32_t code)
|
|
|
|
{
|
|
|
|
switch (code) {
|
2021-02-13 21:50:27 +01:00
|
|
|
case IR24_BRIGHTER : incBrightness(); break;
|
|
|
|
case IR24_DARKER : decBrightness(); break;
|
2018-11-18 00:31:45 +01:00
|
|
|
case IR24_OFF : briLast = bri; bri = 0; break;
|
|
|
|
case IR24_ON : bri = briLast; break;
|
|
|
|
case IR24_RED : colorFromUint32(COLOR_RED); break;
|
|
|
|
case IR24_REDDISH : colorFromUint32(COLOR_REDDISH); break;
|
|
|
|
case IR24_ORANGE : colorFromUint32(COLOR_ORANGE); break;
|
|
|
|
case IR24_YELLOWISH : colorFromUint32(COLOR_YELLOWISH); break;
|
|
|
|
case IR24_YELLOW : colorFromUint32(COLOR_YELLOW); break;
|
|
|
|
case IR24_GREEN : colorFromUint32(COLOR_GREEN); break;
|
|
|
|
case IR24_GREENISH : colorFromUint32(COLOR_GREENISH); break;
|
|
|
|
case IR24_TURQUOISE : colorFromUint32(COLOR_TURQUOISE); break;
|
|
|
|
case IR24_CYAN : colorFromUint32(COLOR_CYAN); break;
|
|
|
|
case IR24_AQUA : colorFromUint32(COLOR_AQUA); break;
|
|
|
|
case IR24_BLUE : colorFromUint32(COLOR_BLUE); break;
|
|
|
|
case IR24_DEEPBLUE : colorFromUint32(COLOR_DEEPBLUE); break;
|
|
|
|
case IR24_PURPLE : colorFromUint32(COLOR_PURPLE); break;
|
|
|
|
case IR24_MAGENTA : colorFromUint32(COLOR_MAGENTA); break;
|
|
|
|
case IR24_PINK : colorFromUint32(COLOR_PINK); break;
|
|
|
|
case IR24_WHITE : colorFromUint32(COLOR_WHITE); effectCurrent = 0; break;
|
|
|
|
case IR24_FLASH : if (!applyPreset(1)) effectCurrent = FX_MODE_COLORTWINKLE; break;
|
|
|
|
case IR24_STROBE : if (!applyPreset(2)) effectCurrent = FX_MODE_RAINBOW_CYCLE; break;
|
|
|
|
case IR24_FADE : if (!applyPreset(3)) effectCurrent = FX_MODE_BREATH; break;
|
|
|
|
case IR24_SMOOTH : if (!applyPreset(4)) effectCurrent = FX_MODE_RAINBOW; break;
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
lastValidCode = code;
|
|
|
|
}
|
|
|
|
|
2020-01-08 00:46:16 +01:00
|
|
|
void decodeIR24OLD(uint32_t code)
|
|
|
|
{
|
|
|
|
switch (code) {
|
2021-02-13 21:50:27 +01:00
|
|
|
case IR24_OLD_BRIGHTER : incBrightness(); break;
|
|
|
|
case IR24_OLD_DARKER : decBrightness(); break;
|
2020-01-08 00:46:16 +01:00
|
|
|
case IR24_OLD_OFF : briLast = bri; bri = 0; break;
|
|
|
|
case IR24_OLD_ON : bri = briLast; break;
|
|
|
|
case IR24_OLD_RED : colorFromUint32(COLOR_RED); break;
|
|
|
|
case IR24_OLD_REDDISH : colorFromUint32(COLOR_REDDISH); break;
|
|
|
|
case IR24_OLD_ORANGE : colorFromUint32(COLOR_ORANGE); break;
|
|
|
|
case IR24_OLD_YELLOWISH : colorFromUint32(COLOR_YELLOWISH); break;
|
|
|
|
case IR24_OLD_YELLOW : colorFromUint32(COLOR_YELLOW); break;
|
|
|
|
case IR24_OLD_GREEN : colorFromUint32(COLOR_GREEN); break;
|
|
|
|
case IR24_OLD_GREENISH : colorFromUint32(COLOR_GREENISH); break;
|
|
|
|
case IR24_OLD_TURQUOISE : colorFromUint32(COLOR_TURQUOISE); break;
|
|
|
|
case IR24_OLD_CYAN : colorFromUint32(COLOR_CYAN); break;
|
|
|
|
case IR24_OLD_AQUA : colorFromUint32(COLOR_AQUA); break;
|
|
|
|
case IR24_OLD_BLUE : colorFromUint32(COLOR_BLUE); break;
|
|
|
|
case IR24_OLD_DEEPBLUE : colorFromUint32(COLOR_DEEPBLUE); break;
|
|
|
|
case IR24_OLD_PURPLE : colorFromUint32(COLOR_PURPLE); break;
|
|
|
|
case IR24_OLD_MAGENTA : colorFromUint32(COLOR_MAGENTA); break;
|
|
|
|
case IR24_OLD_PINK : colorFromUint32(COLOR_PINK); break;
|
|
|
|
case IR24_OLD_WHITE : colorFromUint32(COLOR_WHITE); effectCurrent = 0; break;
|
2020-01-24 23:15:57 +01:00
|
|
|
case IR24_OLD_FLASH : if (!applyPreset(1)) { effectCurrent = FX_MODE_COLORTWINKLE; effectPalette = 0; } break;
|
|
|
|
case IR24_OLD_STROBE : if (!applyPreset(2)) { effectCurrent = FX_MODE_RAINBOW_CYCLE; effectPalette = 0; } break;
|
|
|
|
case IR24_OLD_FADE : if (!applyPreset(3)) { effectCurrent = FX_MODE_BREATH; effectPalette = 0; } break;
|
|
|
|
case IR24_OLD_SMOOTH : if (!applyPreset(4)) { effectCurrent = FX_MODE_RAINBOW; effectPalette = 0; } break;
|
2020-01-08 00:46:16 +01:00
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
lastValidCode = code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void decodeIR24CT(uint32_t code)
|
|
|
|
{
|
|
|
|
switch (code) {
|
2021-02-13 21:50:27 +01:00
|
|
|
case IR24_CT_BRIGHTER : incBrightness(); break;
|
|
|
|
case IR24_CT_DARKER : decBrightness(); break;
|
2020-01-08 00:46:16 +01:00
|
|
|
case IR24_CT_OFF : briLast = bri; bri = 0; break;
|
|
|
|
case IR24_CT_ON : bri = briLast; break;
|
|
|
|
case IR24_CT_RED : colorFromUint32(COLOR_RED); break;
|
|
|
|
case IR24_CT_REDDISH : colorFromUint32(COLOR_REDDISH); break;
|
|
|
|
case IR24_CT_ORANGE : colorFromUint32(COLOR_ORANGE); break;
|
|
|
|
case IR24_CT_YELLOWISH : colorFromUint32(COLOR_YELLOWISH); break;
|
|
|
|
case IR24_CT_YELLOW : colorFromUint32(COLOR_YELLOW); break;
|
|
|
|
case IR24_CT_GREEN : colorFromUint32(COLOR_GREEN); break;
|
|
|
|
case IR24_CT_GREENISH : colorFromUint32(COLOR_GREENISH); break;
|
|
|
|
case IR24_CT_TURQUOISE : colorFromUint32(COLOR_TURQUOISE); break;
|
|
|
|
case IR24_CT_CYAN : colorFromUint32(COLOR_CYAN); break;
|
|
|
|
case IR24_CT_AQUA : colorFromUint32(COLOR_AQUA); break;
|
|
|
|
case IR24_CT_BLUE : colorFromUint32(COLOR_BLUE); break;
|
|
|
|
case IR24_CT_DEEPBLUE : colorFromUint32(COLOR_DEEPBLUE); break;
|
|
|
|
case IR24_CT_PURPLE : colorFromUint32(COLOR_PURPLE); break;
|
|
|
|
case IR24_CT_MAGENTA : colorFromUint32(COLOR_MAGENTA); break;
|
|
|
|
case IR24_CT_PINK : colorFromUint32(COLOR_PINK); break;
|
2020-01-24 23:15:57 +01:00
|
|
|
case IR24_CT_COLDWHITE : colorFromUint32(COLOR2_COLDWHITE); effectCurrent = 0; break;
|
|
|
|
case IR24_CT_WARMWHITE : colorFromUint32(COLOR2_WARMWHITE); effectCurrent = 0; break;
|
|
|
|
case IR24_CT_CTPLUS : colorFromUint32(COLOR2_COLDWHITE2); effectCurrent = 0; break;
|
|
|
|
case IR24_CT_CTMINUS : colorFromUint32(COLOR2_WARMWHITE2); effectCurrent = 0; break;
|
2020-01-08 00:46:16 +01:00
|
|
|
case IR24_CT_MEMORY : {
|
|
|
|
if (col[3] > 0) col[3] = 0;
|
2020-01-24 23:15:57 +01:00
|
|
|
else colorFromUint32(COLOR2_NEUTRALWHITE); effectCurrent = 0; } break;
|
2020-01-08 00:46:16 +01:00
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
lastValidCode = code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void decodeIR40(uint32_t code)
|
|
|
|
{
|
|
|
|
switch (code) {
|
2021-02-13 21:50:27 +01:00
|
|
|
case IR40_BPLUS : incBrightness(); break;
|
|
|
|
case IR40_BMINUS : decBrightness(); break;
|
2020-01-08 00:46:16 +01:00
|
|
|
case IR40_OFF : briLast = bri; bri = 0; break;
|
|
|
|
case IR40_ON : bri = briLast; break;
|
|
|
|
case IR40_RED : colorFromUint24(COLOR_RED); break;
|
|
|
|
case IR40_REDDISH : colorFromUint24(COLOR_REDDISH); break;
|
|
|
|
case IR40_ORANGE : colorFromUint24(COLOR_ORANGE); break;
|
|
|
|
case IR40_YELLOWISH : colorFromUint24(COLOR_YELLOWISH); break;
|
|
|
|
case IR40_YELLOW : colorFromUint24(COLOR_YELLOW); break;
|
|
|
|
case IR40_GREEN : colorFromUint24(COLOR_GREEN); break;
|
|
|
|
case IR40_GREENISH : colorFromUint24(COLOR_GREENISH); break;
|
|
|
|
case IR40_TURQUOISE : colorFromUint24(COLOR_TURQUOISE); break;
|
|
|
|
case IR40_CYAN : colorFromUint24(COLOR_CYAN); break;
|
|
|
|
case IR40_AQUA : colorFromUint24(COLOR_AQUA); break;
|
|
|
|
case IR40_BLUE : colorFromUint24(COLOR_BLUE); break;
|
|
|
|
case IR40_DEEPBLUE : colorFromUint24(COLOR_DEEPBLUE); break;
|
|
|
|
case IR40_PURPLE : colorFromUint24(COLOR_PURPLE); break;
|
|
|
|
case IR40_MAGENTA : colorFromUint24(COLOR_MAGENTA); break;
|
|
|
|
case IR40_PINK : colorFromUint24(COLOR_PINK); break;
|
|
|
|
case IR40_WARMWHITE2 : {
|
|
|
|
if (useRGBW) { colorFromUint32(COLOR2_WARMWHITE2); effectCurrent = 0; }
|
|
|
|
else colorFromUint24(COLOR_WARMWHITE2); } break;
|
|
|
|
case IR40_WARMWHITE : {
|
|
|
|
if (useRGBW) { colorFromUint32(COLOR2_WARMWHITE); effectCurrent = 0; }
|
|
|
|
else colorFromUint24(COLOR_WARMWHITE); } break;
|
|
|
|
case IR40_WHITE : {
|
|
|
|
if (useRGBW) { colorFromUint32(COLOR2_NEUTRALWHITE); effectCurrent = 0; }
|
|
|
|
else colorFromUint24(COLOR_NEUTRALWHITE); } break;
|
|
|
|
case IR40_COLDWHITE : {
|
|
|
|
if (useRGBW) { colorFromUint32(COLOR2_COLDWHITE); effectCurrent = 0; }
|
|
|
|
else colorFromUint24(COLOR_COLDWHITE); } break;
|
|
|
|
case IR40_COLDWHITE2 : {
|
|
|
|
if (useRGBW) { colorFromUint32(COLOR2_COLDWHITE2); effectCurrent = 0; }
|
|
|
|
else colorFromUint24(COLOR_COLDWHITE2); } 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_W25 : bri = 63; break;
|
|
|
|
case IR40_W50 : bri = 127; break;
|
|
|
|
case IR40_W75 : bri = 191; break;
|
|
|
|
case IR40_W100 : bri = 255; break;
|
2020-03-02 13:31:34 +01:00
|
|
|
case IR40_QUICK : changeEffectSpeed( 16); break;
|
|
|
|
case IR40_SLOW : changeEffectSpeed(-16); break;
|
|
|
|
case IR40_JUMP7 : changeEffectIntensity( 16); break;
|
|
|
|
case IR40_AUTO : changeEffectIntensity(-16); break;
|
2020-01-24 23:15:57 +01:00
|
|
|
case IR40_JUMP3 : if (!applyPreset(1)) { effectCurrent = FX_MODE_STATIC; effectPalette = 0; } break;
|
|
|
|
case IR40_FADE3 : if (!applyPreset(2)) { effectCurrent = FX_MODE_BREATH; effectPalette = 0; } break;
|
|
|
|
case IR40_FADE7 : if (!applyPreset(3)) { effectCurrent = FX_MODE_FIRE_FLICKER; effectPalette = 0; } break;
|
|
|
|
case IR40_FLASH : if (!applyPreset(4)) { effectCurrent = FX_MODE_RAINBOW; effectPalette = 0; } break;
|
2020-01-08 00:46:16 +01:00
|
|
|
}
|
|
|
|
lastValidCode = code;
|
|
|
|
}
|
2018-11-22 00:09:30 +01:00
|
|
|
|
2018-11-18 00:31:45 +01:00
|
|
|
void decodeIR44(uint32_t code)
|
|
|
|
{
|
2020-01-08 00:46:16 +01:00
|
|
|
switch (code) {
|
2021-02-13 21:50:27 +01:00
|
|
|
case IR44_BPLUS : incBrightness(); break;
|
|
|
|
case IR44_BMINUS : decBrightness(); break;
|
2020-01-08 00:46:16 +01:00
|
|
|
case IR44_OFF : briLast = bri; bri = 0; break;
|
|
|
|
case IR44_ON : bri = briLast; break;
|
|
|
|
case IR44_RED : colorFromUint24(COLOR_RED); break;
|
|
|
|
case IR44_REDDISH : colorFromUint24(COLOR_REDDISH); break;
|
|
|
|
case IR44_ORANGE : colorFromUint24(COLOR_ORANGE); break;
|
|
|
|
case IR44_YELLOWISH : colorFromUint24(COLOR_YELLOWISH); break;
|
|
|
|
case IR44_YELLOW : colorFromUint24(COLOR_YELLOW); break;
|
|
|
|
case IR44_GREEN : colorFromUint24(COLOR_GREEN); break;
|
|
|
|
case IR44_GREENISH : colorFromUint24(COLOR_GREENISH); break;
|
|
|
|
case IR44_TURQUOISE : colorFromUint24(COLOR_TURQUOISE); break;
|
|
|
|
case IR44_CYAN : colorFromUint24(COLOR_CYAN); break;
|
|
|
|
case IR44_AQUA : colorFromUint24(COLOR_AQUA); break;
|
|
|
|
case IR44_BLUE : colorFromUint24(COLOR_BLUE); break;
|
|
|
|
case IR44_DEEPBLUE : colorFromUint24(COLOR_DEEPBLUE); break;
|
|
|
|
case IR44_PURPLE : colorFromUint24(COLOR_PURPLE); break;
|
|
|
|
case IR44_MAGENTA : colorFromUint24(COLOR_MAGENTA); break;
|
|
|
|
case IR44_PINK : colorFromUint24(COLOR_PINK); break;
|
|
|
|
case IR44_WHITE : {
|
|
|
|
if (useRGBW) {
|
|
|
|
if (col[3] > 0) col[3] = 0;
|
|
|
|
else { colorFromUint32(COLOR2_NEUTRALWHITE); effectCurrent = 0; }
|
|
|
|
} else colorFromUint24(COLOR_NEUTRALWHITE); } break;
|
|
|
|
case IR44_WARMWHITE2 : {
|
|
|
|
if (useRGBW) { colorFromUint32(COLOR2_WARMWHITE2); effectCurrent = 0; }
|
|
|
|
else colorFromUint24(COLOR_WARMWHITE2); } break;
|
|
|
|
case IR44_WARMWHITE : {
|
|
|
|
if (useRGBW) { colorFromUint32(COLOR2_WARMWHITE); effectCurrent = 0; }
|
|
|
|
else colorFromUint24(COLOR_WARMWHITE); } break;
|
|
|
|
case IR44_COLDWHITE : {
|
|
|
|
if (useRGBW) { colorFromUint32(COLOR2_COLDWHITE); effectCurrent = 0; }
|
|
|
|
else colorFromUint24(COLOR_COLDWHITE); } break;
|
|
|
|
case IR44_COLDWHITE2 : {
|
|
|
|
if (useRGBW) { colorFromUint32(COLOR2_COLDWHITE2); effectCurrent = 0; }
|
|
|
|
else colorFromUint24(COLOR_COLDWHITE2); } break;
|
2020-03-02 13:31:34 +01:00
|
|
|
case IR44_REDPLUS : relativeChange(&effectCurrent, 1, 0, MODE_COUNT); break;
|
2020-01-08 00:46:16 +01:00
|
|
|
case IR44_REDMINUS : relativeChange(&effectCurrent, -1, 0); break;
|
2020-03-02 13:31:34 +01:00
|
|
|
case IR44_GREENPLUS : relativeChange(&effectPalette, 1, 0, strip.getPaletteCount() -1); break;
|
2020-01-08 00:46:16 +01:00
|
|
|
case IR44_GREENMINUS : relativeChange(&effectPalette, -1, 0); break;
|
2020-03-02 13:31:34 +01:00
|
|
|
case IR44_BLUEPLUS : changeEffectIntensity( 16); break;
|
|
|
|
case IR44_BLUEMINUS : changeEffectIntensity(-16); break;
|
|
|
|
case IR44_QUICK : changeEffectSpeed( 16); break;
|
|
|
|
case IR44_SLOW : changeEffectSpeed(-16); break;
|
2020-01-24 23:15:57 +01:00
|
|
|
case IR44_DIY1 : if (!applyPreset(1)) { effectCurrent = FX_MODE_STATIC; effectPalette = 0; } break;
|
|
|
|
case IR44_DIY2 : if (!applyPreset(2)) { effectCurrent = FX_MODE_BREATH; effectPalette = 0; } break;
|
|
|
|
case IR44_DIY3 : if (!applyPreset(3)) { effectCurrent = FX_MODE_FIRE_FLICKER; effectPalette = 0; } break;
|
|
|
|
case IR44_DIY4 : if (!applyPreset(4)) { effectCurrent = FX_MODE_RAINBOW; effectPalette = 0; } break;
|
|
|
|
case IR44_DIY5 : if (!applyPreset(5)) { effectCurrent = FX_MODE_METEOR_SMOOTH; effectPalette = 0; } break;
|
|
|
|
case IR44_DIY6 : if (!applyPreset(6)) { effectCurrent = FX_MODE_RAIN; effectPalette = 0; } break;
|
2020-01-08 00:46:16 +01:00
|
|
|
case IR44_AUTO : effectCurrent = FX_MODE_STATIC; break;
|
|
|
|
case IR44_FLASH : effectCurrent = FX_MODE_PALETTE; break;
|
|
|
|
case IR44_JUMP3 : bri = 63; break;
|
|
|
|
case IR44_JUMP7 : bri = 127; break;
|
|
|
|
case IR44_FADE3 : bri = 191; break;
|
|
|
|
case IR44_FADE7 : bri = 255; break;
|
|
|
|
}
|
|
|
|
lastValidCode = code;
|
2018-11-18 00:31:45 +01:00
|
|
|
}
|
|
|
|
|
2020-01-19 12:53:44 +01:00
|
|
|
void decodeIR21(uint32_t code)
|
|
|
|
{
|
2020-03-02 13:31:34 +01:00
|
|
|
switch (code) {
|
2021-02-13 21:50:27 +01:00
|
|
|
case IR21_BRIGHTER: incBrightness(); break;
|
|
|
|
case IR21_DARKER: decBrightness(); break;
|
2020-01-19 12:53:44 +01:00
|
|
|
case IR21_OFF: briLast = bri; bri = 0; break;
|
|
|
|
case IR21_ON: bri = briLast; break;
|
|
|
|
case IR21_RED: colorFromUint32(COLOR_RED); break;
|
|
|
|
case IR21_REDDISH: colorFromUint32(COLOR_REDDISH); break;
|
|
|
|
case IR21_ORANGE: colorFromUint32(COLOR_ORANGE); break;
|
|
|
|
case IR21_YELLOWISH: colorFromUint32(COLOR_YELLOWISH); break;
|
|
|
|
case IR21_GREEN: colorFromUint32(COLOR_GREEN); break;
|
|
|
|
case IR21_GREENISH: colorFromUint32(COLOR_GREENISH); break;
|
|
|
|
case IR21_TURQUOISE: colorFromUint32(COLOR_TURQUOISE); break;
|
|
|
|
case IR21_CYAN: colorFromUint32(COLOR_CYAN); break;
|
|
|
|
case IR21_BLUE: colorFromUint32(COLOR_BLUE); break;
|
|
|
|
case IR21_DEEPBLUE: colorFromUint32(COLOR_DEEPBLUE); break;
|
|
|
|
case IR21_PURPLE: colorFromUint32(COLOR_PURPLE); break;
|
|
|
|
case IR21_PINK: colorFromUint32(COLOR_PINK); break;
|
|
|
|
case IR21_WHITE: colorFromUint32(COLOR_WHITE); effectCurrent = 0; break;
|
2020-01-24 23:15:57 +01:00
|
|
|
case IR21_FLASH: if (!applyPreset(1)) { effectCurrent = FX_MODE_COLORTWINKLE; effectPalette = 0; } break;
|
|
|
|
case IR21_STROBE: if (!applyPreset(2)) { effectCurrent = FX_MODE_RAINBOW_CYCLE; effectPalette = 0; } break;
|
|
|
|
case IR21_FADE: if (!applyPreset(3)) { effectCurrent = FX_MODE_BREATH; effectPalette = 0; } break;
|
|
|
|
case IR21_SMOOTH: if (!applyPreset(4)) { effectCurrent = FX_MODE_RAINBOW; effectPalette = 0; } break;
|
2020-01-19 12:53:44 +01:00
|
|
|
default: return;
|
2020-03-02 13:31:34 +01:00
|
|
|
}
|
|
|
|
lastValidCode = code;
|
2020-01-19 12:53:44 +01:00
|
|
|
}
|
2018-11-22 00:09:30 +01:00
|
|
|
|
2020-01-25 17:35:18 +01:00
|
|
|
void decodeIR6(uint32_t code)
|
|
|
|
{
|
2020-02-22 16:17:32 +01:00
|
|
|
switch (code) {
|
2020-06-04 14:24:55 +02:00
|
|
|
case IR6_POWER: toggleOnOff(); break;
|
2021-02-13 21:50:27 +01:00
|
|
|
case IR6_CHANNEL_UP: incBrightness(); break;
|
|
|
|
case IR6_CHANNEL_DOWN: decBrightness(); break;
|
2020-03-02 13:31:34 +01:00
|
|
|
case IR6_VOLUME_UP: relativeChange(&effectCurrent, 1, 0, MODE_COUNT); break; // next effect
|
|
|
|
case IR6_VOLUME_DOWN: // next palette
|
|
|
|
relativeChange(&effectPalette, 1, 0, strip.getPaletteCount() -1);
|
2020-02-22 16:17:32 +01:00
|
|
|
switch(lastIR6ColourIdx) {
|
2020-02-28 16:27:18 +01:00
|
|
|
case 0: colorFromUint32(COLOR_RED); break;
|
|
|
|
case 1: colorFromUint32(COLOR_REDDISH); break;
|
|
|
|
case 2: colorFromUint32(COLOR_ORANGE); break;
|
|
|
|
case 3: colorFromUint32(COLOR_YELLOWISH); break;
|
|
|
|
case 4: colorFromUint32(COLOR_GREEN); break;
|
|
|
|
case 5: colorFromUint32(COLOR_GREENISH); break;
|
|
|
|
case 6: colorFromUint32(COLOR_TURQUOISE); break;
|
|
|
|
case 7: colorFromUint32(COLOR_CYAN); break;
|
|
|
|
case 8: colorFromUint32(COLOR_BLUE); break;
|
|
|
|
case 9: colorFromUint32(COLOR_DEEPBLUE); break;
|
|
|
|
case 10:colorFromUint32(COLOR_PURPLE); break;
|
|
|
|
case 11:colorFromUint32(COLOR_PINK); break;
|
|
|
|
case 12:colorFromUint32(COLOR_WHITE); break;
|
|
|
|
default: break;
|
2020-02-22 16:17:32 +01:00
|
|
|
}
|
|
|
|
lastIR6ColourIdx++;
|
2020-03-02 13:31:34 +01:00
|
|
|
if(lastIR6ColourIdx > 12) lastIR6ColourIdx = 0; break;
|
2020-02-28 16:27:18 +01:00
|
|
|
case IR6_MUTE: effectCurrent = 0; effectPalette = 0; colorFromUint32(COLOR_WHITE); bri=255; break;
|
2020-02-22 16:17:32 +01:00
|
|
|
}
|
|
|
|
lastValidCode = code;
|
2020-01-25 17:35:18 +01:00
|
|
|
}
|
|
|
|
|
2020-06-04 14:24:55 +02:00
|
|
|
void decodeIR9(uint32_t code)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case IR9_POWER : toggleOnOff(); break;
|
|
|
|
case IR9_A : if (!applyPreset(1)) effectCurrent = FX_MODE_COLORTWINKLE; break;
|
|
|
|
case IR9_B : if (!applyPreset(2)) effectCurrent = FX_MODE_RAINBOW_CYCLE; break;
|
|
|
|
case IR9_C : if (!applyPreset(3)) effectCurrent = FX_MODE_BREATH; break;
|
2021-02-13 21:50:27 +01:00
|
|
|
case IR9_UP : incBrightness(); break;
|
|
|
|
case IR9_DOWN : decBrightness(); break;
|
2020-06-04 14:24:55 +02:00
|
|
|
//case IR9_UP : changeEffectIntensity(16); break;
|
|
|
|
//case IR9_DOWN : changeEffectIntensity(-16); break;
|
|
|
|
case IR9_LEFT : changeEffectSpeed(-16); break;
|
|
|
|
case IR9_RIGHT : changeEffectSpeed(16); break;
|
|
|
|
case IR9_SELECT : relativeChange(&effectCurrent, 1, 0, MODE_COUNT); break;
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
lastValidCode = code;
|
|
|
|
}
|
2020-01-25 17:35:18 +01:00
|
|
|
|
2018-11-18 00:31:45 +01:00
|
|
|
void initIR()
|
|
|
|
{
|
2020-01-08 00:46:16 +01:00
|
|
|
if (irEnabled > 0)
|
2018-11-18 00:31:45 +01:00
|
|
|
{
|
2020-11-29 20:47:13 +01:00
|
|
|
irrecv = new IRrecv(IRPIN);
|
2018-11-18 00:31:45 +01:00
|
|
|
irrecv->enableIRIn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-22 00:09:30 +01:00
|
|
|
|
2018-11-18 00:31:45 +01:00
|
|
|
void handleIR()
|
|
|
|
{
|
2020-01-08 00:46:16 +01:00
|
|
|
if (irEnabled > 0 && millis() - irCheckedTime > 120)
|
2018-11-18 00:31:45 +01:00
|
|
|
{
|
|
|
|
irCheckedTime = millis();
|
2020-01-08 00:46:16 +01:00
|
|
|
if (irEnabled > 0)
|
2018-11-18 00:31:45 +01:00
|
|
|
{
|
|
|
|
if (irrecv == NULL)
|
|
|
|
{
|
|
|
|
initIR(); return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (irrecv->decode(&results))
|
|
|
|
{
|
2020-01-08 00:46:16 +01:00
|
|
|
if (results.value != 0) // only print results if anything is received ( != 0 )
|
|
|
|
{
|
|
|
|
Serial.print("IR recv\r\n0x");
|
|
|
|
Serial.println((uint32_t)results.value, HEX);
|
|
|
|
Serial.println();
|
|
|
|
}
|
2018-11-22 00:09:30 +01:00
|
|
|
decodeIR(results.value);
|
2018-11-18 00:31:45 +01:00
|
|
|
irrecv->resume();
|
|
|
|
}
|
|
|
|
} else if (irrecv != NULL)
|
|
|
|
{
|
2018-11-22 00:09:30 +01:00
|
|
|
irrecv->disableIRIn();
|
2018-11-18 00:31:45 +01:00
|
|
|
delete irrecv; irrecv = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-22 00:09:30 +01:00
|
|
|
|
|
|
|
#endif
|