Add more functionality to ``Switchmode`` 11 and 12 (#8450)

Add more functionality to ``Switchmode`` 11 and 12 (#8450)
This commit is contained in:
Theo Arends 2020-05-19 15:52:10 +02:00
parent d61345e79f
commit cd7f719563
5 changed files with 24 additions and 33 deletions

View File

@ -55,3 +55,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
### Version 8.3.1.1
- Add command ``Rule0`` to change global rule parameters
- Add more functionality to ``Switchmode`` 11 and 12 (#8450)

View File

@ -3,6 +3,7 @@
### 8.3.1.1 20200518
- Add command ``Rule0`` to change global rule parameters
- Add more functionality to ``Switchmode`` 11 and 12 (#8450)
## Released

View File

@ -154,8 +154,15 @@ void SwitchHandler(uint8_t mode)
if (Switch.hold_timer[i]) {
Switch.hold_timer[i]--;
if (Switch.hold_timer[i] == loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
if ((Settings.switchmode[i] == PUSHHOLDMULTI) & (NOT_PRESSED == Switch.last_state[i])) {
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
}
if ((Settings.switchmode[i] == PUSHHOLDMULTI_INV) & (PRESSED == Switch.last_state[i])) {
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
}
}
if (0 == Switch.hold_timer[i]) {
switch (Settings.switchmode[i]) {
case TOGGLEMULTI:
switchflag = POWER_TOGGLE; // Toggle after hold
@ -202,51 +209,33 @@ void SwitchHandler(uint8_t mode)
switchflag = ~button &1; // Follow inverted wall switch state
break;
case PUSHBUTTON:
// if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) {
if (PRESSED == button) {
switchflag = POWER_TOGGLE; // Toggle with pushbutton to Gnd
}
break;
case PUSHBUTTON_INV:
// if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) {
if (NOT_PRESSED == button) {
switchflag = POWER_TOGGLE; // Toggle with releasing pushbutton from Gnd
}
break;
case PUSHBUTTONHOLD:
// if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) {
if (PRESSED == button) {
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; // Start timer on button press
}
// if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i]) && (Switch.hold_timer[i])) {
if ((NOT_PRESSED == button) && (Switch.hold_timer[i])) {
Switch.hold_timer[i] = 0; // Button released and hold timer not expired : stop timer...
switchflag = POWER_TOGGLE; // ...and Toggle
}
break;
case PUSHBUTTONHOLD_INV:
// if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) {
if (NOT_PRESSED == button) {
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; // Start timer on button press...
}
// if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i]) && (Switch.hold_timer[i])) {
if ((PRESSED == button) && (Switch.hold_timer[i])) {
Switch.hold_timer[i] = 0; // Button released and hold timer not expired : stop timer.
switchflag = POWER_TOGGLE; // ...and Toggle
}
break;
/*
// Reverted Fix switchmode 6 according to issue 7778 (#7831)
case PUSHBUTTONHOLD_INV:
if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) {
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10; // Start timer on button press...
switchflag = POWER_TOGGLE; // ...and Toggle
}
if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) {
Switch.hold_timer[i] = 0; // Button released : stop timer.
}
break;
*/
case TOGGLEMULTI:
case FOLLOWMULTI:
case FOLLOWMULTI_INV:
@ -258,36 +247,32 @@ void SwitchHandler(uint8_t mode)
}
break;
case PUSHHOLDMULTI:
// if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) {
if (NOT_PRESSED == button) {
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 (PRESSED == button) {
} else {
if (Switch.hold_timer[i] > loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
switchflag = POWER_TOGGLE; // Toggle with pushbutton
} else {
SendKey(KEY_SWITCH, i +1, POWER_RELEASE); // Execute command via MQTT
}
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10;
}
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10;
break;
case PUSHHOLDMULTI_INV:
// if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) {
if (PRESSED == button) {
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 (NOT_PRESSED == button) {
} else {
if (Switch.hold_timer[i] > loops_per_second * Settings.param[P_HOLD_TIME] / 25) {
switchflag = POWER_TOGGLE; // Toggle with pushbutton
} else {
SendKey(KEY_SWITCH, i +1, POWER_RELEASE); // Execute command via MQTT
}
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10;
}
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10;
break;
case PUSHON:
if (PRESSED == button) {

View File

@ -423,6 +423,10 @@ bool SendKey(uint32_t key, uint32_t device, uint32_t state)
// state 1 = POWER_ON = on
// state 2 = POWER_TOGGLE = toggle
// state 3 = POWER_HOLD = hold
// state 4 = POWER_INCREMENT = button still pressed
// state 5 = POWER_INV = button released
// state 6 = POWER_CLEAR = button released
// state 7 = POWER_RELEASE = button released
// state 9 = CLEAR_RETAIN = clear retain flag
char stopic[TOPSZ];
@ -1232,7 +1236,7 @@ void SerialInput(void)
}
else if ((serial_in_byte_counter == INPUT_BUFFER_SIZE)
#ifdef ESP8266
|| Serial.hasOverrun() // Default ESP8266 Serial buffer size is 256. Tasmota increases to INPUT_BUFFER_SIZE
|| Serial.hasOverrun()
#endif
) {
serial_buffer_overrun = true;

View File

@ -232,7 +232,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, POWER_INCREMENT = 4, POWER_INV = 5, POWER_CLEAR = 6, CLEAR_RETAIN = 9 };
enum SendKeyPowerOptions { POWER_HOLD = 3, POWER_INCREMENT = 4, POWER_INV = 5, POWER_CLEAR = 6, POWER_RELEASE = 7, CLEAR_RETAIN = 9 };
enum SendKeyOptions { KEY_BUTTON, KEY_SWITCH };
enum SendKeyMultiClick { SINGLE = 10, DOUBLE = 11, TRIPLE = 12, QUAD = 13, PENTA = 14};