Skip to content

Commit

Permalink
Merge pull request #964 from kareem613/master
Browse files Browse the repository at this point in the history
adds support for 9-key remote and intensity/speed repeat actions
  • Loading branch information
Aircoookie authored Jun 5, 2020
2 parents 41da889 + 0a1bbca commit 2049e8b
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 39 deletions.
3 changes: 3 additions & 0 deletions wled00/fcn_declare.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ void onHueData(void* arg, AsyncClient* client, void *data, size_t len);

//ir.cpp
bool decodeIRCustom(uint32_t code);
void applyRepeatActions();
void relativeChange(byte* property, int8_t amount, byte lowerBoundary = 0, byte higherBoundary = 0xFF);
void changeEffectSpeed(int8_t amount);
void changeBrightness(int8_t amount);
void changeEffectIntensity(int8_t amount);
void decodeIR(uint32_t code);
void decodeIR24(uint32_t code);
Expand All @@ -68,6 +70,7 @@ void decodeIR40(uint32_t code);
void decodeIR44(uint32_t code);
void decodeIR21(uint32_t code);
void decodeIR6(uint32_t code);
void decodeIR9(uint32_t code);

void initIR();
void handleIR();
Expand Down
1 change: 1 addition & 0 deletions wled00/html_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ Infrared remote:
<option value=4>44-key RGB</option>
<option value=5>21-key RGB</option>
<option value=6>6-key black</option>
<option value=7>9-key red</option>
</select><br>
<a href=https://github.com/Aircoookie/WLED/wiki/Infrared-Control target=_blank>IR info</a>
<h3>WLED Broadcast</h3>
Expand Down
140 changes: 101 additions & 39 deletions wled00/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ decode_results results;

unsigned long irCheckedTime = 0;
uint32_t lastValidCode = 0;
byte lastRepeatableAction = ACTION_NONE;
uint8_t lastRepeatableValue = 0;
uint16_t irTimesRepeated = 0;
uint8_t lastIR6ColourIdx = 0;

Expand All @@ -36,7 +38,7 @@ bool decodeIRCustom(uint32_t code)
}


//relatively change brightness, minumum A=5

void relativeChange(byte* property, int8_t amount, byte lowerBoundary, byte higherBoundary)
{
int16_t new_val = (int16_t) *property + amount;
Expand All @@ -45,6 +47,16 @@ void relativeChange(byte* property, int8_t amount, byte lowerBoundary, byte high
*property = (byte)constrain(new_val,0.1,255.1);
}

void changeBrightness(int8_t amount)
{
int16_t new_val = bri + amount;
if (new_val < 5) new_val = 5; //minimum brightness A=5
bri = (byte)constrain(new_val,0.1,255.1);
if(amount > 0) lastRepeatableAction = ACTION_BRIGHT_UP;
if(amount < 0) lastRepeatableAction = ACTION_BRIGHT_DOWN;
lastRepeatableValue = amount;
}

void changeEffectSpeed(int8_t amount)
{
if (effectCurrent != 0) {
Expand All @@ -65,6 +77,10 @@ void changeEffectSpeed(int8_t amount)
col[1] = fastled_col.green;
col[2] = fastled_col.blue;
}

if(amount > 0) lastRepeatableAction = ACTION_SPEED_UP;
if(amount < 0) lastRepeatableAction = ACTION_SPEED_DOWN;
lastRepeatableValue = amount;
}

void changeEffectIntensity(int8_t amount)
Expand All @@ -85,39 +101,21 @@ void changeEffectIntensity(int8_t amount)
col[1] = fastled_col.green;
col[2] = fastled_col.blue;
}

if(amount > 0) lastRepeatableAction = ACTION_INTENSITY_UP;
if(amount < 0) lastRepeatableAction = ACTION_INTENSITY_DOWN;
lastRepeatableValue = amount;
}

void decodeIR(uint32_t code)
{
if (code == 0xFFFFFFFF) //repeated code, continue brightness up/down
{
irTimesRepeated++;
if (lastValidCode == IR24_BRIGHTER || lastValidCode == IR40_BPLUS )
{
relativeChange(&bri, 10); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
}
else if (lastValidCode == IR24_DARKER || lastValidCode == IR40_BMINUS )
{
relativeChange(&bri, -10, 5); 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);
}
applyRepeatActions();
return;
}
lastValidCode = 0; irTimesRepeated = 0;

if (decodeIRCustom(code)) return;
if (code > 0xFFFFFF) return; //invalid code
else if (code > 0xF70000 && code < 0xF80000) decodeIR24(code); //is in 24-key remote range
Expand All @@ -131,6 +129,7 @@ void decodeIR(uint32_t code)
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;
default: return;
}
}
Expand All @@ -139,12 +138,57 @@ void decodeIR(uint32_t code)
//code <= 0xF70000 also invalid
}

void applyRepeatActions(){

if (lastRepeatableAction == ACTION_BRIGHT_UP)
{
changeBrightness(lastRepeatableValue); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
}
else if (lastRepeatableAction == ACTION_BRIGHT_DOWN )
{
changeBrightness(lastRepeatableValue); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
}

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


void decodeIR24(uint32_t code)
{
switch (code) {
case IR24_BRIGHTER : relativeChange(&bri, 10); break;
case IR24_DARKER : relativeChange(&bri, -10, 5); break;
case IR24_BRIGHTER : changeBrightness(10); break;
case IR24_DARKER : changeBrightness(-10); break;
case IR24_OFF : briLast = bri; bri = 0; break;
case IR24_ON : bri = briLast; break;
case IR24_RED : colorFromUint32(COLOR_RED); break;
Expand Down Expand Up @@ -175,8 +219,8 @@ void decodeIR24(uint32_t code)
void decodeIR24OLD(uint32_t code)
{
switch (code) {
case IR24_OLD_BRIGHTER : relativeChange(&bri, 10); break;
case IR24_OLD_DARKER : relativeChange(&bri, -10, 5); break;
case IR24_OLD_BRIGHTER : changeBrightness(10); break;
case IR24_OLD_DARKER : changeBrightness(-10); break;
case IR24_OLD_OFF : briLast = bri; bri = 0; break;
case IR24_OLD_ON : bri = briLast; break;
case IR24_OLD_RED : colorFromUint32(COLOR_RED); break;
Expand Down Expand Up @@ -208,8 +252,8 @@ void decodeIR24OLD(uint32_t code)
void decodeIR24CT(uint32_t code)
{
switch (code) {
case IR24_CT_BRIGHTER : relativeChange(&bri, 10); break;
case IR24_CT_DARKER : relativeChange(&bri, -10, 5); break;
case IR24_CT_BRIGHTER : changeBrightness(10); break;
case IR24_CT_DARKER : changeBrightness(-10); break;
case IR24_CT_OFF : briLast = bri; bri = 0; break;
case IR24_CT_ON : bri = briLast; break;
case IR24_CT_RED : colorFromUint32(COLOR_RED); break;
Expand Down Expand Up @@ -243,8 +287,8 @@ void decodeIR24CT(uint32_t code)
void decodeIR40(uint32_t code)
{
switch (code) {
case IR40_BPLUS : relativeChange(&bri, 10); break;
case IR40_BMINUS : relativeChange(&bri, -10, 5); break;
case IR40_BPLUS : changeBrightness(10); break;
case IR40_BMINUS : changeBrightness(-10); break;
case IR40_OFF : briLast = bri; bri = 0; break;
case IR40_ON : bri = briLast; break;
case IR40_RED : colorFromUint24(COLOR_RED); break;
Expand Down Expand Up @@ -300,8 +344,8 @@ void decodeIR40(uint32_t code)
void decodeIR44(uint32_t code)
{
switch (code) {
case IR44_BPLUS : relativeChange(&bri, 10); break;
case IR44_BMINUS : relativeChange(&bri, -10, 5); break;
case IR44_BPLUS : changeBrightness(10); break;
case IR44_BMINUS : changeBrightness(-10); break;
case IR44_OFF : briLast = bri; bri = 0; break;
case IR44_ON : bri = briLast; break;
case IR44_RED : colorFromUint24(COLOR_RED); break;
Expand Down Expand Up @@ -363,8 +407,8 @@ void decodeIR44(uint32_t code)
void decodeIR21(uint32_t code)
{
switch (code) {
case IR21_BRIGHTER: relativeChange(&bri, 10); break;
case IR21_DARKER: relativeChange(&bri, -10, 5); break;
case IR21_BRIGHTER: changeBrightness(10); break;
case IR21_DARKER: changeBrightness(-10); break;
case IR21_OFF: briLast = bri; bri = 0; break;
case IR21_ON: bri = briLast; break;
case IR21_RED: colorFromUint32(COLOR_RED); break;
Expand Down Expand Up @@ -392,9 +436,9 @@ void decodeIR21(uint32_t code)
void decodeIR6(uint32_t code)
{
switch (code) {
case IR6_POWER: toggleOnOff(); break;
case IR6_CHANNEL_UP: relativeChange(&bri, 10); break;
case IR6_CHANNEL_DOWN: relativeChange(&bri, -10, 5); break;
case IR6_POWER: toggleOnOff(); break;
case IR6_CHANNEL_UP: changeBrightness(10); break;
case IR6_CHANNEL_DOWN: changeBrightness(-10); break;
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);
Expand All @@ -421,6 +465,24 @@ void decodeIR6(uint32_t code)
lastValidCode = code;
}

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;
case IR9_UP : changeBrightness(16); break;
case IR9_DOWN : changeBrightness(-16); break;
//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;
}

void initIR()
{
Expand Down
18 changes: 18 additions & 0 deletions wled00/ir_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
#define IR6_VOLUME_DOWN 0xFF2FD0
#define IR6_MUTE 0xFFAF50

#define IR9_POWER 0xFF629D
#define IR9_A 0xFF22DD
#define IR9_B 0xFF02FD
#define IR9_C 0xFFC23D
#define IR9_LEFT 0xFF30CF
#define IR9_RIGHT 0xFF7A85
#define IR9_UP 0xFF9867
#define IR9_DOWN 0xFF38C7
#define IR9_SELECT 0xFF18E7

//Infrared codes for 24-key remote from http://woodsgood.ca/projects/2015/02/13/rgb-led-strip-controllers-ir-codes/
#define IR24_BRIGHTER 0xF700FF
Expand Down Expand Up @@ -229,3 +238,12 @@
#define COLOR2_NEUTRALWHITE 0xFF000000
#define COLOR2_COLDWHITE 0xFF7F7F7F
#define COLOR2_COLDWHITE2 0xFFFFFFFF

#define ACTION_NONE 0
#define ACTION_BRIGHT_UP 1
#define ACTION_BRIGHT_DOWN 2
#define ACTION_SPEED_UP 3
#define ACTION_SPEED_DOWN 4
#define ACTION_INTENSITY_UP 5
#define ACTION_INTENSITY_DOWN 6
#define ACTION_POWER 7

0 comments on commit 2049e8b

Please sign in to comment.