Fixed nightlight issues

Added custom infrared method
This commit is contained in:
cschwinne 2018-11-22 00:09:30 +01:00
parent 54d7a81f16
commit cd234673ea
7 changed files with 67 additions and 29 deletions

View File

@ -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_BRIGHTER 0xF700FF
#define IR24_DARKER 0xF7807F #define IR24_DARKER 0xF7807F
#define IR24_OFF 0xF740BF #define IR24_OFF 0xF740BF

View File

@ -74,7 +74,7 @@
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 1811201 #define VERSION 1811221
char versionString[] = "0.8.2-dev"; char versionString[] = "0.8.2-dev";

View File

@ -109,7 +109,7 @@ void handleSettingsSet(byte subPage)
nightlightTargetBri = server.arg("TB").toInt(); nightlightTargetBri = server.arg("TB").toInt();
t = server.arg("TL").toInt(); t = server.arg("TL").toInt();
if (t > 0) nightlightDelayMins = t; if (t > 0) nightlightDelayMinsDefault = t;
nightlightFade = server.hasArg("TW"); nightlightFade = server.hasArg("TW");
t = server.arg("PB").toInt(); t = server.arg("PB").toInt();
@ -144,6 +144,7 @@ void handleSettingsSet(byte subPage)
if (subPage == 4) if (subPage == 4)
{ {
buttonEnabled = server.hasArg("BT"); buttonEnabled = server.hasArg("BT");
irEnabled = server.hasArg("IR");
int t = server.arg("UP").toInt(); int t = server.arg("UP").toInt();
if (t > 0) udpPort = t; if (t > 0) udpPort = t;
receiveNotificationBrightness = server.hasArg("RB"); receiveNotificationBrightness = server.hasArg("RB");
@ -633,14 +634,7 @@ bool handleSet(String req)
{ {
case 0: if (bri != 0){briLast = bri; bri = 0;} break; //off case 0: if (bri != 0){briLast = bri; bri = 0;} break; //off
case 1: bri = briLast; break; //on case 1: bri = briLast; break; //on
default: if (bri == 0) //toggle default: toggleOnOff(); //toggle
{
bri = briLast;
} else
{
briLast = bri;
bri = 0;
}
} }
} }

View File

@ -2,6 +2,18 @@
* LED methods * LED methods
*/ */
void toggleOnOff()
{
if (bri == 0)
{
bri = briLast;
} else
{
briLast = bri;
bri = 0;
}
}
void setAllLeds() { void setAllLeds() {
if (!realtimeActive || !arlsForceMaxBri) 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 //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 (!colorChanged())
{ {
if (nightlightActive && !nightlightActiveOld && callMode != 3 && callMode != 5)
{
notify(4); return;
}
if (callMode == 2) notify(2); if (callMode == 2) notify(2);
else if (callMode == 6) notify(6); else if (callMode == 6) notify(6);
return; //no change return; //no change
@ -188,7 +204,6 @@ void handleNightlight()
if (!nightlightActiveOld) //init if (!nightlightActiveOld) //init
{ {
nightlightStartTime = millis(); nightlightStartTime = millis();
notify(4);
nightlightDelayMs = (int)(nightlightDelayMins*60000); nightlightDelayMs = (int)(nightlightDelayMins*60000);
nightlightActiveOld = true; nightlightActiveOld = true;
briNlT = bri; briNlT = bri;

View File

@ -25,14 +25,7 @@ void handleButton()
else { else {
if (macroButton == 0) if (macroButton == 0)
{ {
if (bri == 0) toggleOnOff();
{
bri = briLast;
} else
{
briLast = bri;
bri = 0;
}
colorUpdated(2); colorUpdated(2);
} else { } else {
applyMacro(macroButton); applyMacro(macroButton);

View File

@ -5,7 +5,7 @@
void parseMQTTBriPayload(char* payload) void parseMQTTBriPayload(char* payload)
{ {
if (strcmp(payload, "ON") == 0) {bri = briLast; colorUpdated(1);} 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 { else {
uint8_t in = strtoul(payload, NULL, 10); uint8_t in = strtoul(payload, NULL, 10);
if (in == 0 && bri > 0) briLast = bri; if (in == 0 && bri > 0) briLast = bri;

View File

@ -2,6 +2,10 @@
* Infrared sensor support for generic 24 key RGB remote * Infrared sensor support for generic 24 key RGB remote
*/ */
#if defined(WLED_DISABLE_INFRARED) || defined(ARDUINO_ARCH_ESP32)
void handleIR(){}
#else
IRrecv* irrecv; IRrecv* irrecv;
//change pin in NpbWrapper.h //change pin in NpbWrapper.h
@ -12,6 +16,23 @@ uint32_t lastValidCode = 0;
uint16_t irTimesRepeated = 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 //relatively change brightness, minumum A=5
void relativeChange(byte* property, int8_t amount, byte lowerBoundary =0) 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; *property = new_val;
} }
void decodeIr(uint32_t code)
void decodeIR(uint32_t code)
{ {
if (code == 0xFFFFFFFF) //repeated code, continue brightness up/down if (code == 0xFFFFFFFF) //repeated code, continue brightness up/down
{ {
irTimesRepeated++; irTimesRepeated++;
if (lastValidCode == IR24_BRIGHTER) if (lastValidCode == IR24_BRIGHTER)
{ {
relativeChange(&bri, 10); return; relativeChange(&bri, 10); colorUpdated(2);
} }
else if (lastValidCode == IR24_DARKER) else if (lastValidCode == IR24_DARKER)
{ {
relativeChange(&bri, -10, 5); return; relativeChange(&bri, -10, 5); colorUpdated(2);
} }
else if (lastValidCode == IR24_ON && irTimesRepeated > 7) else if (lastValidCode == IR24_ON && irTimesRepeated > 7)
{ {
nightlightActive = true; nightlightActive = true;
nightlightStartTime = millis(); nightlightStartTime = millis();
colorUpdated(2);
} }
return; return;
} }
lastValidCode = 0; irTimesRepeated = 0; lastValidCode = 0; irTimesRepeated = 0;
if (decodeIRCustom(code)) return;
if (code > 0xFFFFFF) return; //invalid code if (code > 0xFFFFFF) return; //invalid code
else if (code > 0xFF0000) decodeIR44(code); //is in 44-key remote range 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 else if (code > 0xF70000 && code < 0xF80000) decodeIR24(code); //is in 24-key remote range
//code <= 0xF70000 also invalid //code <= 0xF70000 also invalid
} }
void decodeIR24(uint32_t code) void decodeIR24(uint32_t code)
{ {
switch (code) { switch (code) {
@ -82,11 +107,13 @@ void decodeIR24(uint32_t code)
colorUpdated(2); //for notifier, IR is considered a button input colorUpdated(2); //for notifier, IR is considered a button input
} }
void decodeIR44(uint32_t code) void decodeIR44(uint32_t code)
{ {
//not implemented for now //not implemented for now
} }
void initIR() void initIR()
{ {
if (irEnabled) if (irEnabled)
@ -94,9 +121,9 @@ void initIR()
irrecv = new IRrecv(IR_PIN); irrecv = new IRrecv(IR_PIN);
irrecv->enableIRIn(); irrecv->enableIRIn();
} }
//irrecv.disableIRIn();
} }
void handleIR() void handleIR()
{ {
if (irEnabled && millis() - irCheckedTime > 120) if (irEnabled && millis() - irCheckedTime > 120)
@ -111,16 +138,19 @@ void handleIR()
if (irrecv->decode(&results)) if (irrecv->decode(&results))
{ {
DEBUG_PRINTLN("IR recv"); DEBUG_PRINT("IR recv\r\n0x");
#ifdef DEBUG #ifdef WLED_DEBUG
Serial.println((uint32_t)results.value, HEX); Serial.println((uint32_t)results.value, HEX);
#endif #endif
decodeIr(results.value); decodeIR(results.value);
irrecv->resume(); irrecv->resume();
} }
} else if (irrecv != NULL) } else if (irrecv != NULL)
{ {
irrecv->disableIRIn();
delete irrecv; irrecv = NULL; delete irrecv; irrecv = NULL;
} }
} }
} }
#endif