Refactor support_switche.ino

- Add commands ``SwitchMode 13`` PushOn and ``SwitchMode 14`` PushOnInverted (#7912)
- Refactor support_switche.ino
This commit is contained in:
Theo Arends 2020-03-14 13:13:33 +01:00
parent a664278c78
commit d043ac770d
4 changed files with 50 additions and 29 deletions

View File

@ -87,6 +87,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
- Add command ``ShutterButton <parameters>`` to control shutter(s) by to-scho (#7403)
- Add commands ``SwitchMode 8`` ToggleMulti, ``SwitchMode 9`` FollowMulti and ``SwitchMode 10`` FollowMultiInverted (#7522)
- Add commands ``SwitchMode 11`` PushHoldMulti and ``SwitchMode 12`` PushHoldInverted (#7603)
- Add commands ``SwitchMode 13`` PushOn and ``SwitchMode 14`` PushOnInverted (#7912)
- Add command ``Buzzer -1`` for infinite mode and command ``Buzzer -2`` for following led mode (#7623)
- Add SerialConfig to ``Status 1``
- Add WifiPower to ``Status 5``

View File

@ -4,6 +4,7 @@
- Add HAss Discovery support for Button and Switch triggers by Federico Leoni (#7901)
- Add support for HDC1080 Temperature and Humidity sensor by Luis Teixeira (#7888)
- Add commands ``SwitchMode 13`` PushOn and ``SwitchMode 14`` PushOnInverted (#7912)
### 8.1.0.10 20200227

View File

@ -17,8 +17,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define SWITCH_V2
#ifdef SWITCH_V2
#define SWITCH_V3
#ifdef SWITCH_V3
/*********************************************************************************************\
* Switch support with input filter
*
@ -166,20 +166,20 @@ void SwitchHandler(uint8_t mode)
switchflag = ~button &1; // Follow inverted wall switch state after hold
break;
case PUSHHOLDMULTI:
if (NOT_PRESSED == button){
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
} else {
SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT
}
break;
case PUSHHOLDMULTI_INV:
if (PRESSED == button){
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
} 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
@ -188,9 +188,7 @@ void SwitchHandler(uint8_t mode)
}
}
// enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE, TOGGLEMULTI, FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, MAX_SWITCH_OPTION};
if (button != Switch.last_state[i]) {
if (button != Switch.last_state[i]) { // This implies if ((PRESSED == button) then (NOT_PRESSED == Switch.last_state[i]))
switch (Settings.switchmode[i]) {
case TOGGLE:
case PUSHBUTTON_TOGGLE:
@ -203,29 +201,35 @@ 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) && (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) && (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) && (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) && (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) && (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) && (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
}
@ -253,31 +257,46 @@ void SwitchHandler(uint8_t mode)
}
break;
case PUSHHOLDMULTI:
if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) {
if(Switch.hold_timer[i]!=0)
// 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(Switch.hold_timer[i] > loops_per_second * Settings.param[P_HOLD_TIME] / 25)
// if ((PRESSED == button) && (NOT_PRESSED == Switch.last_state[i])) {
if (PRESSED == button) {
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)
// 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(Switch.hold_timer[i] > loops_per_second * Settings.param[P_HOLD_TIME] / 25)
// if ((NOT_PRESSED == button) && (PRESSED == Switch.last_state[i])) {
if (NOT_PRESSED == button) {
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 PUSHON:
if (PRESSED == button) switchflag = POWER_ON; // Power ON with pushbutton to Gnd
if (PRESSED == button) {
switchflag = POWER_ON; // Power ON with pushbutton to Gnd
}
break;
case PUSHON_INV:
if (NOT_PRESSED == button) {
switchflag = POWER_ON; // Power ON with releasing pushbutton from Gnd
}
break;
}
Switch.last_state[i] = button;
@ -301,4 +320,4 @@ void SwitchLoop(void)
}
}
#endif // SWITCH_V2
#endif // SWITCH_V3

View File

@ -233,7 +233,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, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, MAX_SWITCH_OPTION};
FOLLOWMULTI, FOLLOWMULTI_INV, PUSHHOLDMULTI, PUSHHOLDMULTI_INV, PUSHON, PUSHON_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};
@ -317,7 +317,7 @@ enum DeviceGroupItem { DGR_ITEM_EOL, DGR_ITEM_STATUS,
DGR_ITEM_LAST_16BIT, DGR_ITEM_MAX_16BIT = 127,
DGR_ITEM_POWER, DGR_ITEM_DIMMER_RANGE,
// Add new 32-bit items before this line
DGR_ITEM_LAST_32BIT, DGR_ITEM_MAX_32BIT = 191,
DGR_ITEM_LAST_32BIT, DGR_ITEM_MAX_32BIT = 191,
// Add new string items before this line
DGR_ITEM_LAST_STRING, DGR_ITEM_MAX_STRING = 223,
DGR_ITEM_LIGHT_CHANNELS };