From cd234673ea86b532eb6691358d08517ac4c66871 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Thu, 22 Nov 2018 00:09:30 +0100 Subject: [PATCH] Fixed nightlight issues Added custom infrared method --- wled00/ir_codes.h | 8 ++++++- wled00/wled00.ino | 2 +- wled00/wled03_set.ino | 12 +++-------- wled00/wled08_led.ino | 17 ++++++++++++++- wled00/wled09_button.ino | 9 +------- wled00/wled17_mqtt.ino | 2 +- wled00/wled19_ir.ino | 46 +++++++++++++++++++++++++++++++++------- 7 files changed, 67 insertions(+), 29 deletions(-) diff --git a/wled00/ir_codes.h b/wled00/ir_codes.h index 0f07c226..e9043bd9 100644 --- a/wled00/ir_codes.h +++ b/wled00/ir_codes.h @@ -1,4 +1,10 @@ -//Infrared codes from http://woodsgood.ca/projects/2015/02/13/rgb-led-strip-controllers-ir-codes/ +//Infrared codes + +//Add your custom codes here +#define IRCUSTOM_ONOFF 0xA55AEA15 //Pioneer RC-975R "+FAV" button (example) +#define IRCUSTOM_MACRO1 0xFFFFFFFF //placeholder, will never be checked for + +//Infrared codes for 24-key remote from http://woodsgood.ca/projects/2015/02/13/rgb-led-strip-controllers-ir-codes/ #define IR24_BRIGHTER 0xF700FF #define IR24_DARKER 0xF7807F #define IR24_OFF 0xF740BF diff --git a/wled00/wled00.ino b/wled00/wled00.ino index b116de09..649fbcce 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -74,7 +74,7 @@ //version code in format yymmddb (b = daily build) -#define VERSION 1811201 +#define VERSION 1811221 char versionString[] = "0.8.2-dev"; diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index 6875942f..0c24fa20 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -109,7 +109,7 @@ void handleSettingsSet(byte subPage) nightlightTargetBri = server.arg("TB").toInt(); t = server.arg("TL").toInt(); - if (t > 0) nightlightDelayMins = t; + if (t > 0) nightlightDelayMinsDefault = t; nightlightFade = server.hasArg("TW"); t = server.arg("PB").toInt(); @@ -144,6 +144,7 @@ void handleSettingsSet(byte subPage) if (subPage == 4) { buttonEnabled = server.hasArg("BT"); + irEnabled = server.hasArg("IR"); int t = server.arg("UP").toInt(); if (t > 0) udpPort = t; receiveNotificationBrightness = server.hasArg("RB"); @@ -633,14 +634,7 @@ bool handleSet(String req) { case 0: if (bri != 0){briLast = bri; bri = 0;} break; //off case 1: bri = briLast; break; //on - default: if (bri == 0) //toggle - { - bri = briLast; - } else - { - briLast = bri; - bri = 0; - } + default: toggleOnOff(); //toggle } } diff --git a/wled00/wled08_led.ino b/wled00/wled08_led.ino index de1d3a1f..d7ebfb49 100644 --- a/wled00/wled08_led.ino +++ b/wled00/wled08_led.ino @@ -2,6 +2,18 @@ * LED methods */ +void toggleOnOff() +{ + if (bri == 0) + { + bri = briLast; + } else + { + briLast = bri; + bri = 0; + } +} + void setAllLeds() { if (!realtimeActive || !arlsForceMaxBri) { @@ -73,6 +85,10 @@ void colorUpdated(int callMode) //call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (NN)6: fx changed 7: hue 8: preset cycle 9: blynk if (!colorChanged()) { + if (nightlightActive && !nightlightActiveOld && callMode != 3 && callMode != 5) + { + notify(4); return; + } if (callMode == 2) notify(2); else if (callMode == 6) notify(6); return; //no change @@ -188,7 +204,6 @@ void handleNightlight() if (!nightlightActiveOld) //init { nightlightStartTime = millis(); - notify(4); nightlightDelayMs = (int)(nightlightDelayMins*60000); nightlightActiveOld = true; briNlT = bri; diff --git a/wled00/wled09_button.ino b/wled00/wled09_button.ino index 0c6e3a27..83904927 100644 --- a/wled00/wled09_button.ino +++ b/wled00/wled09_button.ino @@ -25,14 +25,7 @@ void handleButton() else { if (macroButton == 0) { - if (bri == 0) - { - bri = briLast; - } else - { - briLast = bri; - bri = 0; - } + toggleOnOff(); colorUpdated(2); } else { applyMacro(macroButton); diff --git a/wled00/wled17_mqtt.ino b/wled00/wled17_mqtt.ino index c98833f7..1a1fd8ee 100644 --- a/wled00/wled17_mqtt.ino +++ b/wled00/wled17_mqtt.ino @@ -5,7 +5,7 @@ void parseMQTTBriPayload(char* payload) { if (strcmp(payload, "ON") == 0) {bri = briLast; colorUpdated(1);} - else if (strcmp(payload, "T" ) == 0) {handleSet("win&T=2");} + else if (strcmp(payload, "T" ) == 0) {toggleOnOff(); colorUpdated(1);} else { uint8_t in = strtoul(payload, NULL, 10); if (in == 0 && bri > 0) briLast = bri; diff --git a/wled00/wled19_ir.ino b/wled00/wled19_ir.ino index a1e2f727..f59dd63a 100644 --- a/wled00/wled19_ir.ino +++ b/wled00/wled19_ir.ino @@ -2,6 +2,10 @@ * Infrared sensor support for generic 24 key RGB remote */ +#if defined(WLED_DISABLE_INFRARED) || defined(ARDUINO_ARCH_ESP32) +void handleIR(){} +#else + IRrecv* irrecv; //change pin in NpbWrapper.h @@ -12,6 +16,23 @@ uint32_t lastValidCode = 0; uint16_t irTimesRepeated = 0; +//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; + case IRCUSTOM_MACRO1 : applyMacro(1); break; + + default: return false; + } + if (code != IRCUSTOM_MACRO1) colorUpdated(2); //don't update color again if we apply macro, it already does it + return true; +} + + //relatively change brightness, minumum A=5 void relativeChange(byte* property, int8_t amount, byte lowerBoundary =0) { @@ -21,34 +42,38 @@ void relativeChange(byte* property, int8_t amount, byte lowerBoundary =0) *property = new_val; } -void decodeIr(uint32_t code) + +void decodeIR(uint32_t code) { if (code == 0xFFFFFFFF) //repeated code, continue brightness up/down { irTimesRepeated++; if (lastValidCode == IR24_BRIGHTER) { - relativeChange(&bri, 10); return; + relativeChange(&bri, 10); colorUpdated(2); } else if (lastValidCode == IR24_DARKER) { - relativeChange(&bri, -10, 5); return; + relativeChange(&bri, -10, 5); colorUpdated(2); } else if (lastValidCode == IR24_ON && irTimesRepeated > 7) { nightlightActive = true; nightlightStartTime = millis(); + colorUpdated(2); } return; } lastValidCode = 0; irTimesRepeated = 0; - + + if (decodeIRCustom(code)) return; if (code > 0xFFFFFF) return; //invalid code else if (code > 0xFF0000) decodeIR44(code); //is in 44-key remote range else if (code > 0xF70000 && code < 0xF80000) decodeIR24(code); //is in 24-key remote range //code <= 0xF70000 also invalid } + void decodeIR24(uint32_t code) { switch (code) { @@ -82,11 +107,13 @@ void decodeIR24(uint32_t code) colorUpdated(2); //for notifier, IR is considered a button input } + void decodeIR44(uint32_t code) { //not implemented for now } + void initIR() { if (irEnabled) @@ -94,9 +121,9 @@ void initIR() irrecv = new IRrecv(IR_PIN); irrecv->enableIRIn(); } - //irrecv.disableIRIn(); } + void handleIR() { if (irEnabled && millis() - irCheckedTime > 120) @@ -111,16 +138,19 @@ void handleIR() if (irrecv->decode(&results)) { - DEBUG_PRINTLN("IR recv"); - #ifdef DEBUG + DEBUG_PRINT("IR recv\r\n0x"); + #ifdef WLED_DEBUG Serial.println((uint32_t)results.value, HEX); #endif - decodeIr(results.value); + decodeIR(results.value); irrecv->resume(); } } else if (irrecv != NULL) { + irrecv->disableIRIn(); delete irrecv; irrecv = NULL; } } } + +#endif