Add switch modes 11 and 12

Add switch modes 11 (PUSHHOLDMULTI) and 12 (PUSHHOLDMULTI_INV) (#7603)
This commit is contained in:
Theo Arends 2020-02-06 14:53:35 +01:00
parent d52ed6f2bf
commit d779a2b9b4
7 changed files with 34 additions and 22 deletions

View File

@ -92,3 +92,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
- Add rule trigger on one level deeper using syntax with two ``#`` like ``on zigbeereceived#vibration_sensor#aqaracubeside=0 do ...``
- Add support for sensor DS18x20 on Shelly 1 and Shelly 1PM using Shelly Add-On adapter (#7469)
- Add support for sensor DHT family on Shelly 1 and Shelly 1PM using Shelly Add-On adapter (#7469)
- Add switch modes 11 (PUSHHOLDMULTI) and 12 (PUSHHOLDMULTI_INV) (#7603)

View File

@ -5,6 +5,7 @@
- Fix Hass sensor discovery part 1/4 by Federico Leoni (#7582, #7548)
- Add support for sensor DS18x20 on Shelly 1 and Shelly 1PM using Shelly Add-On adapter (#7469)
- Add support for sensor DHT family on Shelly 1 and Shelly 1PM using Shelly Add-On adapter (#7469)
- Add switch modes 11 (PUSHHOLDMULTI) and 12 (PUSHHOLDMULTI_INV) (#7603)
### 8.1.0.5 20200126

View File

@ -48,21 +48,32 @@ void SwitchPullupFlag(uint16 switch_bit)
bitSet(Switch.no_pullup_mask, switch_bit);
}
uint8_t SwitchLastState(uint8_t index)
{
return Switch.last_state[index];
}
void SwitchSetVirtual(uint8_t index, uint8_t state)
void SwitchSetVirtual(uint32_t index, uint8_t state)
{
Switch.virtual_state[index] = state;
}
uint8_t SwitchGetVirtual(uint8_t index)
uint8_t SwitchGetVirtual(uint32_t index)
{
return Switch.virtual_state[index];
}
uint8_t SwitchLastState(uint32_t index)
{
return Switch.last_state[index];
}
bool SwitchState(uint32_t index)
{
uint32_t switchmode = Settings.switchmode[index];
return ((FOLLOW_INV == switchmode) ||
(PUSHBUTTON_INV == switchmode) ||
(PUSHBUTTONHOLD_INV == switchmode) ||
(FOLLOWMULTI_INV == switchmode) ||
(PUSHHOLDMULTI_INV == switchmode)
) ^ Switch.last_state[index];
}
/*********************************************************************************************/
void SwitchProbe(void)
@ -161,15 +172,15 @@ void SwitchHandler(uint8_t mode)
}
else
SendKey(KEY_SWITCH, i +1, POWER_CLEAR); // Execute command via MQTT
break;
case PUSHHOLDMULTI_INV:
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;
break;
default:
SendKey(KEY_SWITCH, i +1, POWER_HOLD); // Execute command via MQTT
break;
@ -233,24 +244,24 @@ void SwitchHandler(uint8_t mode)
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;
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;
}
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
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;
Switch.hold_timer[i] = loops_per_second * Settings.param[P_HOLD_TIME] / 10;
}
break;
}

View File

@ -664,8 +664,7 @@ bool MqttShowSensor(void)
#else
if (pin[GPIO_SWT1 +i] < 99) {
#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]));
ResponseAppend_P(PSTR(",\"" D_JSON_SWITCH "%d\":\"%s\""), i +1, GetStateText(swm ^ SwitchLastState(i)));
ResponseAppend_P(PSTR(",\"" D_JSON_SWITCH "%d\":\"%s\""), i +1, GetStateText(SwitchState(i)));
}
}
XsnsCall(FUNC_JSON_APPEND);

View File

@ -232,7 +232,8 @@ 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, 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};

View File

@ -578,8 +578,7 @@ void RulesEvery50ms(void)
#else
if (pin[GPIO_SWT1 +i] < 99) {
#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]) || (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, (SwitchState(i)));
RulesProcessEvent(json_event);
}
}

View File

@ -1588,7 +1588,7 @@ chknext:
if (!strncmp(vname,"sw[",3)) {
// tasmota switch state
GetNumericResult(vname+3,OPER_EQU,&fvar,0);
fvar=SwitchLastState((uint8_t)fvar);
fvar=SwitchLastState((uint32_t)fvar);
// skip ] bracket
len++;
goto exit;