diff --git a/CHANGELOG.md b/CHANGELOG.md index 336c85abe..b41715cea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. - Command ``Subscribe2 ...`` to subscribe to a MQTT topic without appended "/#" (#12858) - Support for Hydreon RG-15 Solid State Rain sensor (#12974) - Support for IKEA VINDRIKTNING particle concentration sensor (#12976) +- Commands ``SwitchMode 17`` PushHoldMultiDelay and ``SwitchMode 18`` PushHoldMultiDelayInverted adding delayed single press event (#12973) ### Changed - Shelly EM template needs to use GPIO ADE7953_IRQ_2 @@ -1037,7 +1038,7 @@ All notable changes to this project will be documented in this file. ## [8.1.0.6] - 20200205 ### Added - Support for sensors DS18x20 and DHT family on Shelly 1 and Shelly 1PM using Shelly Add-On adapter (#7469) -- Commands ``SwitchMode 11`` PushHoldMulti and ``SwitchMode 12`` PushHoldInverted (#7603) +- Commands ``SwitchMode 11`` PushHoldMulti and ``SwitchMode 12`` PushHoldMultiInverted (#7603) - Command ``Buzzer -1`` for infinite mode and command ``Buzzer -2`` for following led mode (#7623) - Support for MI-BLE sensors using HM-10 Bluetooth 4.0 module by Christian Staars (#7683) - BootCount Reset Time as BCResetTime to ``Status 1`` diff --git a/RELEASENOTES.md b/RELEASENOTES.md index f87825dd6..19bace10e 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -104,6 +104,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo - Command ``SetOption127 1`` to force Wi-Fi in no-sleep mode even if ``Sleep 0`` is not enabled - Command ``SetOption128 0|1`` web referer check disabling HTTP API commands if set to 0. Default set to 1 for backward compatibility [#12828](https://github.com/arendst/Tasmota/issues/12828) - Command ``SetSensor1..127 0|1`` to globally disable individual sensor driver +- Commands ``SwitchMode 17`` PushHoldMultiDelay and ``SwitchMode 18`` PushHoldMultiDelayInverted adding delayed single press event [#12973](https://github.com/arendst/Tasmota/issues/12973) - Neopool commands ``NPPHRes``, ``NPCLRes`` and ``NPIonRes`` [#12813](https://github.com/arendst/Tasmota/issues/12813) - Support for second DNS server - Support for (Yeelight) Mi Desk Pro using binary tasmota32solo1.bin diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index 68400e5a9..4b1688c72 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -237,17 +237,32 @@ void SwitchHandler(uint32_t mode) { uint32_t mqtt_action = POWER_NONE; uint32_t switchmode = Settings->switchmode[i]; - if (Switch.hold_timer[i] & (((switchmode == PUSHHOLDMULTI) | (switchmode == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK)) { + bool push_hold_multi_delay = ((PUSHHOLDMULTIDELAY == switchmode) || (PUSHHOLDMULTIDELAY_INV == switchmode)); + if (push_hold_multi_delay) { + switchmode -= (PUSHHOLDMULTIDELAY - PUSHHOLDMULTI); + } + bool push_hold_multi = ((PUSHHOLDMULTI == switchmode) || (PUSHHOLDMULTI_INV == switchmode)); + + if (Switch.hold_timer[i] & ((push_hold_multi) ? SM_TIMER_MASK : SM_NO_TIMER_MASK)) { Switch.hold_timer[i]--; if ((Switch.hold_timer[i] & SM_TIMER_MASK) == loops_per_second * Settings->param[P_HOLD_TIME] / 25) { - if ((switchmode == PUSHHOLDMULTI) & (NOT_PRESSED == Switch.last_state[i])) { - SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT + bool do_sendkey = false; + switch (switchmode) { + case PUSHHOLDMULTI: + do_sendkey = (NOT_PRESSED == Switch.last_state[i]); + break; + case PUSHHOLDMULTI_INV: + do_sendkey = (PRESSED == Switch.last_state[i]); + break; } - if ((switchmode == PUSHHOLDMULTI_INV) & (PRESSED == Switch.last_state[i])) { + if (do_sendkey) { SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT + } else if (push_hold_multi_delay && ((Switch.hold_timer[i] & ~SM_TIMER_MASK) == SM_FIRST_PRESS)) { + switchflag = POWER_TOGGLE; // Toggle with pushbutton + Switch.hold_timer[i] = 0; } } - if (0 == (Switch.hold_timer[i] & (((switchmode == PUSHHOLDMULTI) | (switchmode == PUSHHOLDMULTI_INV)) ? SM_TIMER_MASK: SM_NO_TIMER_MASK))) { + if (0 == (Switch.hold_timer[i] & ((push_hold_multi) ? SM_TIMER_MASK: SM_NO_TIMER_MASK))) { switch (switchmode) { case TOGGLEMULTI: switchflag = POWER_TOGGLE; // Toggle after hold @@ -274,7 +289,6 @@ void SwitchHandler(uint32_t mode) { Switch.hold_timer[i] = loops_per_second * Settings->param[P_HOLD_TIME] / 25; SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT mqtt_action = POWER_INCREMENT; - } else { Switch.hold_timer[i]= 0; SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT @@ -349,9 +363,11 @@ void SwitchHandler(uint32_t mode) { } } else { if ((Switch.hold_timer[i] & SM_TIMER_MASK) > loops_per_second * Settings->param[P_HOLD_TIME] / 25) { - if((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) { + if ((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) { Switch.hold_timer[i]= SM_FIRST_PRESS; - switchflag = POWER_TOGGLE; // Toggle with pushbutton + if (!push_hold_multi_delay) { + switchflag = POWER_TOGGLE; // Toggle with pushbutton + } } else{ SendKey(KEY_SWITCH, i +1, POWER_100); // Execute command via MQTT @@ -375,9 +391,11 @@ void SwitchHandler(uint32_t mode) { } } else { if ((Switch.hold_timer[i] & SM_TIMER_MASK)> loops_per_second * Settings->param[P_HOLD_TIME] / 25) { - if((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) { + if ((Switch.hold_timer[i] & ~SM_TIMER_MASK) != SM_SECOND_PRESS) { Switch.hold_timer[i]= SM_FIRST_PRESS; - switchflag = POWER_TOGGLE; // Toggle with pushbutton + if (!push_hold_multi_delay) { + switchflag = POWER_TOGGLE; // Toggle with pushbutton + } } else{ SendKey(KEY_SWITCH, i +1, POWER_100); // Execute command via MQTT diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 5a475cc9d..19f485329 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -280,7 +280,8 @@ enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_D enum WifiConfigOptions {WIFI_RESTART, EX_WIFI_SMARTCONFIG, WIFI_MANAGER, EX_WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL, WIFI_MANAGER_RESET_ONLY, MAX_WIFI_OPTION}; enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, TOGGLEMULTI, - FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, PUSHON_INV, PUSH_IGNORE, MAX_SWITCH_OPTION}; + FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, PUSHON_INV, PUSH_IGNORE, PUSHNOTUSED, PUSHHOLDMULTIDELAY, + PUSHHOLDMULTIDELAY_INV, MAX_SWITCH_OPTION}; enum LedStateOptions {LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT, MAX_LED_OPTION};