Loading...
diff --git a/wled00/html_settings.h b/wled00/html_settings.h index f795d670..d376dc87 100644 --- a/wled00/html_settings.h +++ b/wled00/html_settings.h @@ -350,12 +350,13 @@ Define API macros here:15:
16:
Use 0 for the default action instead of a macro
-Boot Macro:
-Alexa On/Off Macros:
-Button Macro: Long Press:
-Countdown-Over Macro:
-Timed-Light-Over Macro:
-Time-Controlled Macros:
+Boot macro:
+Alexa On/Off macros:
+Button short press macro:
+Long press: Double press:
+Countdown-Over macro:
+Timed-Light-Over macro:
+Time-Controlled macros:
diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 51c960cf..a79fb35d 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -89,7 +89,7 @@ //version code in format yymmddb (b = daily build) -#define VERSION 1903112 +#define VERSION 1903131 char versionString[] = "0.8.4-dev"; @@ -236,7 +236,7 @@ byte macroBoot = 0; //macro loaded after startup byte macroNl = 0; //after nightlight delay over byte macroCountdown = 0; byte macroAlexaOn = 0, macroAlexaOff = 0; -byte macroButton = 0, macroLongPress = 0; +byte macroButton = 0, macroLongPress = 0, macroDoublePress = 0; //Security CONFIG @@ -278,6 +278,7 @@ byte briNlT = 0; //current nightlight brightness //brightness unsigned long lastOnTime = 0; +bool offMode = !turnOnAtBoot; byte bri = briS; byte briOld = 0; byte briT = 0; @@ -287,7 +288,7 @@ byte briLast = 127; //brightness before turned off. Us //button bool buttonPressedBefore = false; unsigned long buttonPressedTime = 0; -unsigned long buttonReleasedTime = 0; +unsigned long buttonWaitTime = 0; //notifications bool notifyDirectDefault = notifyDirect; @@ -536,8 +537,7 @@ void loop() { handleBlynk(); } yield(); - if (briT) lastOnTime = millis(); - if (millis() - lastOnTime < 600) strip.service(); + if (!offMode) strip.service(); } //DEBUG serial logging diff --git a/wled00/wled01_eeprom.ino b/wled00/wled01_eeprom.ino index ff206c38..3a821984 100644 --- a/wled00/wled01_eeprom.ino +++ b/wled00/wled01_eeprom.ino @@ -3,7 +3,7 @@ * EEPROM Map: https://github.com/Aircoookie/WLED/wiki/EEPROM-Map */ -#define EEPSIZE 3072 +#define EEPSIZE 2560 //eeprom Version code, enables default settings instead of 0 init on update #define EEPVER 10 @@ -214,6 +214,7 @@ void saveSettingsToEEPROM() EEPROM.write(2179, macroLongPress); EEPROM.write(2180, macroCountdown); EEPROM.write(2181, macroNl); + EEPROM.write(2182, macroDoublePress); EEPROM.write(2190, e131Universe & 0xFF); EEPROM.write(2191, (e131Universe >> 8) & 0xFF); @@ -423,6 +424,8 @@ void loadSettingsFromEEPROM(bool first) macroLongPress = EEPROM.read(2179); macroCountdown = EEPROM.read(2180); macroNl = EEPROM.read(2181); + macroDoublePress = EEPROM.read(2182); + if (macroDoublePress > 16) macroDoublePress = 0; } if (lastEEPROMversion > 6) diff --git a/wled00/wled02_xml.ino b/wled00/wled02_xml.ino index 2437ab70..afe6831f 100644 --- a/wled00/wled02_xml.ino +++ b/wled00/wled02_xml.ino @@ -359,6 +359,7 @@ char* getSettingsJS(byte subPage) sappend('v',"ML",macroLongPress); sappend('v',"MC",macroCountdown); sappend('v',"MN",macroNl); + sappend('v',"MD",macroDoublePress); k[2] = 0; //Time macros for (int i = 0; i<8; i++) diff --git a/wled00/wled03_set.ino b/wled00/wled03_set.ino index 639eb427..ad1c78a5 100644 --- a/wled00/wled03_set.ino +++ b/wled00/wled03_set.ino @@ -250,6 +250,7 @@ void handleSettingsSet(AsyncWebServerRequest *request, byte subPage) macroLongPress = request->arg("ML").toInt(); macroCountdown = request->arg("MC").toInt(); macroNl = request->arg("MN").toInt(); + macroDoublePress = request->arg("MD").toInt(); char k[3]; k[2] = 0; for (int i = 0; i<8; i++) diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index 05741bdf..015f4284 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -156,6 +156,16 @@ void beginStrip() if (bootPreset>0) applyPreset(bootPreset, turnOnAtBoot, true, true); colorUpdated(0); + //init relay pin + #if RLYPIN >= 0 + pinMode(RLYPIN, OUTPUT); + #if RLYMDE + digitalWrite(RLYPIN, bri); + #else + digitalWrite(RLYPIN, !bri); + #endif + #endif + //disable button if it is "pressed" unintentionally if(digitalRead(BTNPIN) == LOW) buttonEnabled = false; } diff --git a/wled00/wled06_usermod.ino b/wled00/wled06_usermod.ino index 1c75ad1d..71f6853b 100644 --- a/wled00/wled06_usermod.ino +++ b/wled00/wled06_usermod.ino @@ -1,7 +1,8 @@ /* * This file allows you to add own functionality to WLED more easily * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality - * EEPROM bytes 2944 to 3071 are reserved for your custom use case. + * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in wled01_eeprom.h) + * bytes 2400+ are currently ununsed, but might be used for future wled features */ //Use userVar0 and userVar1 (API calls &U0=,&U1=, uint16_t) diff --git a/wled00/wled09_button.ino b/wled00/wled09_button.ino index 6ade83de..a4e8da23 100644 --- a/wled00/wled09_button.ino +++ b/wled00/wled09_button.ino @@ -2,42 +2,78 @@ * Physical IO */ +void shortPressAction() +{ + if (!macroButton) + { + toggleOnOff(); + colorUpdated(2); + } else { + applyMacro(macroButton); + } +} + + void handleButton() { - if (buttonEnabled && millis() - buttonReleasedTime > 20) //debounce + if (!buttonEnabled) return; + + if (digitalRead(BTNPIN) == LOW && !buttonPressedBefore) //pressed { - if (digitalRead(BTNPIN) == LOW && !buttonPressedBefore) //pressed + buttonPressedTime = millis(); + buttonPressedBefore = true; + } + else if (digitalRead(BTNPIN) == HIGH && buttonPressedBefore) //released + { + long dur = millis() - buttonPressedTime; + if (dur < 50) {buttonPressedBefore = false; return;} //too short "press", debounce + bool doublePress = buttonWaitTime; + buttonWaitTime = 0; + + if (dur > 6000) {initAP();} + else if (dur > 600) //long press { - buttonPressedTime = millis(); - buttonPressedBefore = true; + if (macroLongPress) {applyMacro(macroLongPress);} + else _setRandomColor(false,true); } - else if (digitalRead(BTNPIN) == HIGH && buttonPressedBefore) //released - { - if (buttonReleasedTime == 0) { - buttonReleasedTime = millis(); - } else { - if (digitalRead(BTNPIN) == HIGH) - { - if (buttonReleasedTime - buttonPressedTime > 7000) {initAP();} - else if (buttonReleasedTime - buttonPressedTime > 700) - { - if (macroLongPress != 0) {applyMacro(macroLongPress);} - else _setRandomColor(false,true); - } - else { - if (macroButton == 0) - { - toggleOnOff(); - colorUpdated(2); - } else { - applyMacro(macroButton); - } - } - buttonPressedBefore = false; - } - buttonReleasedTime = 0; - } + else { //short press + if (macroDoublePress) + { + if (doublePress) applyMacro(macroDoublePress); + else buttonWaitTime = millis(); + } else shortPressAction(); } + buttonPressedBefore = false; + } + + if (buttonWaitTime && millis() - buttonWaitTime > 450 && !buttonPressedBefore) + { + buttonWaitTime = 0; + shortPressAction(); + } +} + +void handleIO() +{ + handleButton(); + + //set relay when LEDs turn on + if (strip.getBrightness()) + { + lastOnTime = millis(); + if (offMode) + { + #if RLYPIN >= 0 + digitalWrite(RLYPIN, RLYMDE); + #endif + offMode = false; + } + } else if (millis() - lastOnTime > 600) + { + #if RLYPIN >= 0 + if (!offMode) digitalWrite(RLYPIN, !RLYMDE); + #endif + offMode = true; } #if AUXPIN >= 0