From 06667d98face3a532f40756ece0e9e33919824e9 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 27 Apr 2021 11:36:10 +0200 Subject: [PATCH] Add ESP32 pulldown switches ``Switch_d`` Add ESP32 pulldown switches ``Switch_d`` (#10814) --- CHANGELOG.md | 2 +- RELEASENOTES.md | 2 +- tasmota/support_switch.ino | 7 ++++++- tasmota/support_tasmota.ino | 14 ++++++++------ tasmota/tasmota_template.h | 7 +++++-- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40eefa499..dda462284 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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":";;..."`` (#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] diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 5904545a6..ab9114bf0 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -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":";;..."`` [#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 diff --git a/tasmota/support_switch.ino b/tasmota/support_switch.ino index 91f233bb7..646c2bf9c 100644 --- a/tasmota/support_switch.ino +++ b/tasmota/support_switch.ino @@ -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; diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 7dcc83f59..9f52d2747 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -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 diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index 060722c58..f53975e5d 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -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