optimized

This commit is contained in:
RemiDing 2020-01-25 11:22:28 +01:00
parent 50a25aeb7c
commit cfbd1cb85d
2 changed files with 42 additions and 3 deletions

View File

@ -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) {

View File

@ -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 };