Add ESP32 pulldown switches ``Switch_d``

Add ESP32 pulldown switches ``Switch_d`` (#10814)
This commit is contained in:
Theo Arends 2021-04-27 11:36:10 +02:00
parent 74156c9965
commit 06667d98fa
5 changed files with 21 additions and 11 deletions

View File

@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file.
## [9.4.0.2]
### Added
- Initial support for optional ``Template`` JSON fieldpair ``"CMND":"<any template related command>;<any template related command>;..."`` (#11788)
- ESP32 pulldown buttons ``Button_d`` and ``Button_id`` (#10814)
- ESP32 pulldown buttons ``Button_d`` and ``Button_id`` and switches ``Switch_d`` (#10814)
- Support for MQTT using Azure IoT Hub by Kevin Saye (#11906)
## [Released]

View File

@ -79,7 +79,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota
## Changelog v9.4.0.2
### Added
- Initial support for optional ``Template`` JSON fieldpair ``"CMND":"<any template related command>;<any template related command>;..."`` [#11788](https://github.com/arendst/Tasmota/issues/11788)
- ESP32 pulldown buttons ``Button_d`` and ``Button_id`` [#10814](https://github.com/arendst/Tasmota/issues/10814)
- ESP32 pulldown buttons ``Button_d`` and ``Button_id`` and switches ``Switch_d`` [#10814](https://github.com/arendst/Tasmota/issues/10814)
- Support for MQTT using Azure IoT Hub by Kevin Saye [#11906](https://github.com/arendst/Tasmota/issues/11906)
### Breaking Changed

View File

@ -46,6 +46,7 @@ Ticker TickerSwitch;
struct SWITCH {
uint32_t debounce = 0; // Switch debounce timer
uint32_t no_pullup_mask = 0; // Switch pull-up bitmask flags
uint32_t pulldown_mask = 0; // Switch pull-down bitmask flags
uint8_t state[MAX_SWITCHES] = { 0 };
uint8_t last_state[MAX_SWITCHES]; // Last wall switch states
uint8_t hold_timer[MAX_SWITCHES] = { 0 }; // Timer for wallswitch push button hold
@ -60,6 +61,10 @@ void SwitchPullupFlag(uint32 switch_bit) {
bitSet(Switch.no_pullup_mask, switch_bit);
}
void SwitchPulldownFlag(uint32 switch_bit) {
bitSet(Switch.pulldown_mask, switch_bit);
}
void SwitchSetVirtual(uint32_t index, uint32_t state) {
Switch.virtual_state[index] = state;
}
@ -199,7 +204,7 @@ void SwitchInit(void) {
pinMode(Pin(GPIO_SWT1, i), bitRead(Switch.no_pullup_mask, i) ? INPUT : ((16 == Pin(GPIO_SWT1, i)) ? INPUT_PULLDOWN_16 : INPUT_PULLUP));
#endif // ESP8266
#ifdef ESP32
pinMode(Pin(GPIO_SWT1, i), bitRead(Switch.no_pullup_mask, i) ? INPUT : INPUT_PULLUP);
pinMode(Pin(GPIO_SWT1, i), bitRead(Switch.pulldown_mask, i) ? INPUT_PULLDOWN : bitRead(Switch.no_pullup_mask, i) ? INPUT : INPUT_PULLUP);
#endif // ESP32
if (ac_detect) {
Switch.state[i] = 0x80 + 2 * AC_PERIOD;

View File

@ -1672,12 +1672,6 @@ void GpioInit(void)
ButtonPullupFlag(mpin - AGPIO(GPIO_KEY1_NP)); // 0 .. 3
mpin -= (AGPIO(GPIO_KEY1_NP) - AGPIO(GPIO_KEY1));
}
#ifdef ESP32
else if ((mpin >= AGPIO(GPIO_KEY1_PD)) && (mpin < (AGPIO(GPIO_KEY1_PD) + MAX_KEYS))) {
ButtonPulldownFlag(mpin - AGPIO(GPIO_KEY1_PD)); // 0 .. 3
mpin -= (AGPIO(GPIO_KEY1_PD) - AGPIO(GPIO_KEY1));
}
#endif
else if ((mpin >= AGPIO(GPIO_KEY1_INV)) && (mpin < (AGPIO(GPIO_KEY1_INV) + MAX_KEYS))) {
ButtonInvertFlag(mpin - AGPIO(GPIO_KEY1_INV)); // 0 .. 3
mpin -= (AGPIO(GPIO_KEY1_INV) - AGPIO(GPIO_KEY1));
@ -1688,6 +1682,14 @@ void GpioInit(void)
mpin -= (AGPIO(GPIO_KEY1_INV_NP) - AGPIO(GPIO_KEY1));
}
#ifdef ESP32
else if ((mpin >= AGPIO(GPIO_SWT1_PD)) && (mpin < (AGPIO(GPIO_SWT1_PD) + MAX_SWITCHES))) {
SwitchPulldownFlag(mpin - AGPIO(GPIO_SWT1_PD));
mpin -= (AGPIO(GPIO_SWT1_PD) - AGPIO(GPIO_SWT1));
}
else if ((mpin >= AGPIO(GPIO_KEY1_PD)) && (mpin < (AGPIO(GPIO_KEY1_PD) + MAX_KEYS))) {
ButtonPulldownFlag(mpin - AGPIO(GPIO_KEY1_PD)); // 0 .. 3
mpin -= (AGPIO(GPIO_KEY1_PD) - AGPIO(GPIO_KEY1));
}
else if ((mpin >= AGPIO(GPIO_KEY1_INV_PD)) && (mpin < (AGPIO(GPIO_KEY1_INV_PD) + MAX_KEYS))) {
ButtonPulldownFlag(mpin - AGPIO(GPIO_KEY1_INV_PD)); // 0 .. 3
ButtonInvertFlag(mpin - AGPIO(GPIO_KEY1_INV_PD)); // 0 .. 3

View File

@ -164,7 +164,7 @@ enum UserSelectablePins {
#endif
GPIO_INPUT,
#ifdef ESP32
GPIO_KEY1_PD, GPIO_KEY1_INV_PD,
GPIO_KEY1_PD, GPIO_KEY1_INV_PD, GPIO_SWT1_PD,
#endif
GPIO_SENSOR_END };
@ -350,7 +350,7 @@ const char kSensorNames[] PROGMEM =
#endif
D_SENSOR_INPUT "|"
#ifdef ESP32
D_SENSOR_BUTTON "_d|" D_SENSOR_BUTTON "_id|"
D_SENSOR_BUTTON "_d|" D_SENSOR_BUTTON "_id|" D_SENSOR_SWITCH "_d|"
#endif
;
@ -379,6 +379,9 @@ const uint16_t kGpioNiceList[] PROGMEM = {
#endif
AGPIO(GPIO_SWT1) + MAX_SWITCHES, // User connected external switches
AGPIO(GPIO_SWT1_NP) + MAX_SWITCHES,
#ifdef ESP32
AGPIO(GPIO_SWT1_PD) + MAX_SWITCHES,
#endif
#ifdef ROTARY_V1
AGPIO(GPIO_ROT1A) + MAX_ROTARIES, // Rotary A Pin
AGPIO(GPIO_ROT1B) + MAX_ROTARIES, // Rotary B Pin