Merge pull request #7603 from RemiDing/development

New switchmodes to control a dimmer with one switch
This commit is contained in:
Theo Arends 2020-02-06 14:14:12 +01:00 committed by GitHub
commit 702821b4e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 5 deletions

View File

@ -154,6 +154,22 @@ void SwitchHandler(uint8_t mode)
case FOLLOWMULTI_INV: case FOLLOWMULTI_INV:
switchflag = ~button &1; // Follow inverted wall switch state after hold switchflag = ~button &1; // Follow inverted wall switch state after hold
break; break;
case PUSHHOLDMULTI:
if (NOT_PRESSED == button){
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 25;
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
}
else
SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT
break;
case PUSHHOLDMULTI_INV:
if (PRESSED == button){
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 25;
SendKey(KEY_SWITCH, i +1, POWER_INCREMENT); // Execute command via MQTT
}
else
SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT
break;
default: default:
SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT
break; break;
@ -161,7 +177,7 @@ void SwitchHandler(uint8_t mode)
} }
} }
// 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};
if (button != Switch.last_state[i]) { if (button != Switch.last_state[i]) {
switch (Settings.switchmode[i]) { switch (Settings.switchmode[i]) {
@ -213,8 +229,31 @@ void SwitchHandler(uint8_t mode)
Switch.hold_timer[i] = loops_per_second / 2; // 0.5 second multi press window Switch.hold_timer[i] = loops_per_second / 2; // 0.5 second multi press window
} }
break; break;
case PUSHHOLDMULTI:
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;
case PUSHHOLDMULTI_INV:
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;
} }
Switch.last_state[i] = button; Switch.last_state[i] = button;
} }
if (switchflag <= POWER_TOGGLE) { if (switchflag <= POWER_TOGGLE) {

View File

@ -232,7 +232,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 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}; enum LedStateOptions {LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT, MAX_LED_OPTION};
@ -243,7 +243,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, 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_OFF_NO_STATE = 8, POWER_ON_NO_STATE, POWER_TOGGLE_NO_STATE,
POWER_SHOW_STATE = 16 }; POWER_SHOW_STATE = 16 };
enum SendKeyPowerOptions { POWER_HOLD = 3, CLEAR_RETAIN = 9 }; enum SendKeyPowerOptions { POWER_HOLD = 3, POWER_INCREMENT = 4, POWER_INV = 5, POWER_CLEAR = 6, CLEAR_RETAIN = 9 };
enum SendKeyOptions { KEY_BUTTON, KEY_SWITCH }; 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 }; enum PowerOnStateOptions { POWER_ALL_OFF, POWER_ALL_ON, POWER_ALL_SAVED_TOGGLE, POWER_ALL_SAVED, POWER_ALL_ALWAYS_ON, POWER_ALL_OFF_PULSETIME_ON };

View File

@ -578,7 +578,7 @@ void RulesEvery50ms(void)
#else #else
if (pin[GPIO_SWT1 +i] < 99) { if (pin[GPIO_SWT1 +i] < 99) {
#endif // USE_TM1638 #endif // USE_TM1638
bool swm = ((FOLLOW_INV == Settings.switchmode[i]) || (PUSHBUTTON_INV == Settings.switchmode[i]) || (PUSHBUTTONHOLD_INV == Settings.switchmode[i]) || (FOLLOWMULTI_INV == Settings.switchmode[i])); bool swm = ((FOLLOW_INV == Settings.switchmode[i]) || (PUSHBUTTON_INV == Settings.switchmode[i]) || (PUSHBUTTONHOLD_INV == Settings.switchmode[i]) || (FOLLOWMULTI_INV == Settings.switchmode[i]) || (PUSHHOLDMULTI_INV == Settings.switchmode[i]));
snprintf_P(json_event, sizeof(json_event), PSTR("{\"" D_JSON_SWITCH "%d\":{\"Boot\":%d}}"), i +1, (swm ^ SwitchLastState(i))); snprintf_P(json_event, sizeof(json_event), PSTR("{\"" D_JSON_SWITCH "%d\":{\"Boot\":%d}}"), i +1, (swm ^ SwitchLastState(i)));
RulesProcessEvent(json_event); RulesProcessEvent(json_event);
} }