From cfbd1cb85d870085276d7592a69c0e238de2237a Mon Sep 17 00:00:00 2001 From: RemiDing Date: Sat, 25 Jan 2020 11:22:28 +0100 Subject: [PATCH] optimized --- tasmota/support_switch.ino | 41 +++++++++++++++++++++++++++++++++++++- tasmota/tasmota.h | 4 ++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index 9cc3c336f..6df39c5d7 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -154,6 +154,22 @@ void SwitchHandler(uint8_t mode) case FOLLOWMULTI_INV: switchflag = ~button &1; // Follow inverted wall switch state after hold break; + case PUSHHOLDMULTI: + if (PRESSED == button){ + Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 25; + SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT + } + else + SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT + break; + case PUSHHOLDMULTI_INV: + if (NOT_PRESSED == button){ + Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 25; + SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT + } + else + SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT + break; default: SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT break; @@ -213,8 +229,31 @@ void SwitchHandler(uint8_t mode) Switch.hold_timer[i] = loops_per_second / 2; // 0.5 second multi press window } break; + case PUSHHOLDMULTI: + if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) { + if(Switch.hold_timer[i]!=0) + SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT + Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; + } + if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) { + if(Switch.hold_timer[i] > loops_per_second * Settings.param[P_HOLD_TIME] / 25) + switchflag = POWER_TOGGLE; // Toggle with pushbutton + Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; + } + break; + case PUSHHOLDMULTI_INV: + if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) { + if(Switch.hold_timer[i]!=0) + SendKey(KEY_SWITCH, i +1, POWER_INV); // Execute command via MQTT + Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; + } + if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) { + if(Switch.hold_timer[i] > loops_per_second * Settings.param[P_HOLD_TIME] / 25) + switchflag = POWER_TOGGLE; // Toggle with pushbutton + Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; + } + break; } - Switch.last_state[i] = button; } if (switchflag <= POWER_TOGGLE) { diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index b4b944d80..d12bb22ef 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -231,7 +231,7 @@ 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, MAX_SWITCH_OPTION}; +enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, TOGGLEMULTI, FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_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}; @@ -242,7 +242,7 @@ enum TopicOptions { CMND, STAT, TELE, nu1, RESULT_OR_CMND, RESULT_OR_STAT, RESUL enum ExecuteCommandPowerOptions { POWER_OFF, POWER_ON, POWER_TOGGLE, POWER_BLINK, POWER_BLINK_STOP, POWER_OFF_NO_STATE = 8, POWER_ON_NO_STATE, POWER_TOGGLE_NO_STATE, POWER_SHOW_STATE = 16 }; -enum SendKeyPowerOptions { POWER_HOLD = 3, CLEAR_RETAIN = 9 }; +enum SendKeyPowerOptions { POWER_HOLD = 3, POWER_INV = 4, POWER_CLEAR = 5, CLEAR_RETAIN = 9 }; enum SendKeyOptions { KEY_BUTTON, KEY_SWITCH }; enum PowerOnStateOptions { POWER_ALL_OFF, POWER_ALL_ON, POWER_ALL_SAVED_TOGGLE, POWER_ALL_SAVED, POWER_ALL_ALWAYS_ON, POWER_ALL_OFF_PULSETIME_ON };