diff --git a/CHANGELOG.md b/CHANGELOG.md index 03bde2e..72c41c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ### Builds after release 0.12.0 +#### Build 2104120 + +- Added switch support (button macro is switch closing action, long press macro switch opening) +- Replaced Circus effect with new Running Dual effect (Circus is Tricolor Chase with Red/White/Black) +- Fixed ledmap with multiple segments (PR #1864) + #### Build 2104030 - Fixed ESP32 crash on Drip effect with reversed segment (#1854) diff --git a/wled00/button.cpp b/wled00/button.cpp index 22e71a6..c263a66 100644 --- a/wled00/button.cpp +++ b/wled00/button.cpp @@ -4,6 +4,8 @@ * Physical IO */ +#define WLED_DEBOUNCE_THRESHOLD 50 //only consider button input of at least 50ms as valid (debouncing) + void shortPressAction() { if (!macroButton) @@ -25,10 +27,42 @@ bool isButtonPressed() } +void handleSwitch() +{ + if (buttonPressedBefore != isButtonPressed()) { + buttonPressedTime = millis(); + buttonPressedBefore = !buttonPressedBefore; + } + + if (buttonLongPressed == buttonPressedBefore) return; + + if (millis() - buttonPressedTime > WLED_DEBOUNCE_THRESHOLD) { //fire edge event only after 50ms without change (debounce) + if (buttonPressedBefore) { //LOW, falling edge, switch closed + if (macroButton) applyPreset(macroButton); + else { //turn on + if (!bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);} + } + } else { //HIGH, rising edge, switch opened + if (macroLongPress) applyPreset(macroLongPress); + else { //turn off + if (bri) {toggleOnOff(); colorUpdated(NOTIFIER_CALL_MODE_BUTTON);} + } + } + buttonLongPressed = buttonPressedBefore; //save the last "long term" switch state + } +} + + void handleButton() { - if (btnPin<0 || !buttonEnabled) return; + if (btnPin<0 || buttonType < BTN_TYPE_PUSH) return; + + if (buttonType == BTN_TYPE_SWITCH) { //button is not momentary, but switch. This is only suitable on pins whose on-boot state does not matter (NO gpio0) + handleSwitch(); return; + } + + //momentary button logic if (isButtonPressed()) //pressed { if (!buttonPressedBefore) buttonPressedTime = millis(); @@ -48,7 +82,7 @@ void handleButton() else if (!isButtonPressed() && buttonPressedBefore) //released { long dur = millis() - buttonPressedTime; - if (dur < 50) {buttonPressedBefore = false; return;} //too short "press", debounce + if (dur < WLED_DEBOUNCE_THRESHOLD) {buttonPressedBefore = false; return;} //too short "press", debounce bool doublePress = buttonWaitTime; buttonWaitTime = 0; diff --git a/wled00/cfg.cpp b/wled00/cfg.cpp index 1261140..4955eec 100644 --- a/wled00/cfg.cpp +++ b/wled00/cfg.cpp @@ -137,7 +137,7 @@ void deserializeConfig() { if (hw_led["rev"]) busses.getBus(0)->reversed = true; //set 0.11 global reversed setting for first bus JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0]; - CJSON(buttonEnabled, hw_btn_ins_0["type"]); + CJSON(buttonType, hw_btn_ins_0["type"]); int hw_btn_pin = hw_btn_ins_0[F("pin")][0]; if (pinManager.allocatePin(hw_btn_pin,false)) { btnPin = hw_btn_pin; @@ -477,7 +477,7 @@ void serializeConfig() { // button BTNPIN JsonObject hw_btn_ins_0 = hw_btn_ins.createNestedObject(); - hw_btn_ins_0["type"] = (buttonEnabled) ? BTN_TYPE_PUSH : BTN_TYPE_NONE; + hw_btn_ins_0["type"] = buttonType; JsonArray hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin"); hw_btn_ins_0_pin.add(btnPin); diff --git a/wled00/const.h b/wled00/const.h index e6d6d1f..89492a1 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -135,7 +135,7 @@ #define BTN_TYPE_RESERVED 1 #define BTN_TYPE_PUSH 2 #define BTN_TYPE_PUSH_ACT_HIGH 3 //not implemented -#define BTN_TYPE_SWITCH 4 //not implemented +#define BTN_TYPE_SWITCH 4 #define BTN_TYPE_SWITCH_ACT_HIGH 5 //not implemented //Ethernet board types diff --git a/wled00/data/settings_sync.htm b/wled00/data/settings_sync.htm index 37b56e6..c1e2819 100644 --- a/wled00/data/settings_sync.htm +++ b/wled00/data/settings_sync.htm @@ -16,7 +16,12 @@ function GetV(){var d=document;}