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 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 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 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) - 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 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 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 ### 8.1.0.5 20200126

View File

@ -48,21 +48,32 @@ void SwitchPullupFlag(uint16 switch_bit)
bitSet(Switch.no_pullup_mask, switch_bit); bitSet(Switch.no_pullup_mask, switch_bit);
} }
uint8_t SwitchLastState(uint8_t index) void SwitchSetVirtual(uint32_t index, uint8_t state)
{
return Switch.last_state[index];
}
void SwitchSetVirtual(uint8_t index, uint8_t state)
{ {
Switch.virtual_state[index] = state; Switch.virtual_state[index] = state;
} }
uint8_t SwitchGetVirtual(uint8_t index) uint8_t SwitchGetVirtual(uint32_t index)
{ {
return Switch.virtual_state[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) void SwitchProbe(void)

View File

@ -664,8 +664,7 @@ bool MqttShowSensor(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])); ResponseAppend_P(PSTR(",\"" D_JSON_SWITCH "%d\":\"%s\""), i +1, GetStateText(SwitchState(i)));
ResponseAppend_P(PSTR(",\"" D_JSON_SWITCH "%d\":\"%s\""), i +1, GetStateText(swm ^ SwitchLastState(i)));
} }
} }
XsnsCall(FUNC_JSON_APPEND); 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 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}; 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 #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]) || (PUSHHOLDMULTI_INV == Settings.switchmode[i])); snprintf_P(json_event, sizeof(json_event), PSTR("{\"" D_JSON_SWITCH "%d\":{\"Boot\":%d}}"), i +1, (SwitchState(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);
} }
} }

View File

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