mirror of https://github.com/arendst/Tasmota.git
Add support for inverted buttons
* Add core version conditional compile options to provided PWM files (#4917) * Add support for inverted buttons and inverted buttons without pullup (#4914)
This commit is contained in:
parent
d1c6cfb6f9
commit
dc75b473cf
|
@ -2,6 +2,8 @@
|
|||
* Remove command SetOption14 as it has been superseded by command Interlock
|
||||
* Remove command SetOption63 as it has been superseded by command Interlock
|
||||
* Add command Interlock 0 / 1 / 1,2 3,4 .. to control interlock ON/OFF and add up to 8 relays in 1 to 4 interlock groups (#5014)
|
||||
* Add core version conditional compile options to provided PWM files (#4917)
|
||||
* Add support for inverted buttons and inverted buttons without pullup (#4914)
|
||||
*
|
||||
* 6.4.1.10 20190121
|
||||
* Fix Hass discovery of MHZ19(B) sensors (#4992)
|
||||
|
|
|
@ -2279,9 +2279,18 @@ void GpioInit(void)
|
|||
mpin -= (GPIO_SWT1_NP - GPIO_SWT1);
|
||||
}
|
||||
else if ((mpin >= GPIO_KEY1_NP) && (mpin < (GPIO_KEY1_NP + MAX_KEYS))) {
|
||||
ButtonPullupFlag(mpin - GPIO_KEY1_NP);
|
||||
ButtonPullupFlag(mpin - GPIO_KEY1_NP); // 0 .. 3
|
||||
mpin -= (GPIO_KEY1_NP - GPIO_KEY1);
|
||||
}
|
||||
else if ((mpin >= GPIO_KEY1_INV) && (mpin < (GPIO_KEY1_INV + MAX_KEYS))) {
|
||||
ButtonInvertFlag(mpin - GPIO_KEY1_INV); // 0 .. 3
|
||||
mpin -= (GPIO_KEY1_INV - GPIO_KEY1);
|
||||
}
|
||||
else if ((mpin >= GPIO_KEY1_INV_NP) && (mpin < (GPIO_KEY1_INV_NP + MAX_KEYS))) {
|
||||
ButtonPullupFlag(mpin - GPIO_KEY1_INV_NP); // 0 .. 3
|
||||
ButtonInvertFlag(mpin - GPIO_KEY1_INV_NP); // 0 .. 3
|
||||
mpin -= (GPIO_KEY1_INV_NP - GPIO_KEY1);
|
||||
}
|
||||
else if ((mpin >= GPIO_REL1_INV) && (mpin < (GPIO_REL1_INV + MAX_RELAYS))) {
|
||||
bitSet(rel_inverted, mpin - GPIO_REL1_INV);
|
||||
mpin -= (GPIO_REL1_INV - GPIO_REL1);
|
||||
|
|
|
@ -146,6 +146,14 @@ enum UserSelectablePins {
|
|||
GPIO_MAX31855CS, // MAX31855 Serial interface
|
||||
GPIO_MAX31855CLK, // MAX31855 Serial interface
|
||||
GPIO_MAX31855DO, // MAX31855 Serial interface
|
||||
GPIO_KEY1_INV, // Inverted buttons
|
||||
GPIO_KEY2_INV,
|
||||
GPIO_KEY3_INV,
|
||||
GPIO_KEY4_INV,
|
||||
GPIO_KEY1_INV_NP, // Inverted buttons without pull-up
|
||||
GPIO_KEY2_INV_NP,
|
||||
GPIO_KEY3_INV_NP,
|
||||
GPIO_KEY4_INV_NP,
|
||||
GPIO_SENSOR_END };
|
||||
|
||||
// Programmer selectable GPIO functionality offset by user selectable GPIOs
|
||||
|
@ -209,7 +217,10 @@ const char kSensorNames[] PROGMEM =
|
|||
D_SENSOR_SSPI_MISO "|" D_SENSOR_SSPI_MOSI "|" D_SENSOR_SSPI_SCLK "|" D_SENSOR_SSPI_CS "|" D_SENSOR_SSPI_DC "|"
|
||||
D_SENSOR_RF_SENSOR "|"
|
||||
D_SENSOR_AZ_TX "|" D_SENSOR_AZ_RX "|"
|
||||
D_SENSOR_MAX31855_CS "|" D_SENSOR_MAX31855_CLK "|" D_SENSOR_MAX31855_DO;
|
||||
D_SENSOR_MAX31855_CS "|" D_SENSOR_MAX31855_CLK "|" D_SENSOR_MAX31855_DO "|"
|
||||
D_SENSOR_BUTTON "1i|" D_SENSOR_BUTTON "2i|" D_SENSOR_BUTTON "3i|" D_SENSOR_BUTTON "4i|"
|
||||
D_SENSOR_BUTTON "1in|" D_SENSOR_BUTTON "2in|" D_SENSOR_BUTTON "3in|" D_SENSOR_BUTTON "4in"
|
||||
;
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
|
@ -331,12 +342,20 @@ const uint8_t kGpioNiceList[] PROGMEM = {
|
|||
GPIO_NONE, // Not used
|
||||
GPIO_KEY1, // Buttons
|
||||
GPIO_KEY1_NP,
|
||||
GPIO_KEY1_INV,
|
||||
GPIO_KEY1_INV_NP,
|
||||
GPIO_KEY2,
|
||||
GPIO_KEY2_NP,
|
||||
GPIO_KEY2_INV,
|
||||
GPIO_KEY2_INV_NP,
|
||||
GPIO_KEY3,
|
||||
GPIO_KEY3_NP,
|
||||
GPIO_KEY3_INV,
|
||||
GPIO_KEY3_INV_NP,
|
||||
GPIO_KEY4,
|
||||
GPIO_KEY4_NP,
|
||||
GPIO_KEY4_INV,
|
||||
GPIO_KEY4_INV_NP,
|
||||
GPIO_SWT1, // User connected external switches
|
||||
GPIO_SWT1_NP,
|
||||
GPIO_SWT2,
|
||||
|
@ -1780,6 +1799,27 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {
|
|||
/*
|
||||
Optionals
|
||||
|
||||
{ "ESP RGBWWC", // esp rgbww controller https://github.com/pljakobs/esp_rgbww_controller/tree/v2.3
|
||||
GPIO_KEY1, // GPIO00 Button
|
||||
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
|
||||
0, // GPIO02
|
||||
GPIO_USER, // GPIO03 Serial TXD and Optional sensor
|
||||
GPIO_PWM5, // GPIO04 LED Warm White
|
||||
GPIO_PWM4, // GPIO05 LED Cold White
|
||||
// GPIO06 (SD_CLK Flash)
|
||||
// GPIO07 (SD_DATA0 Flash QIO/DIO/DOUT)
|
||||
// GPIO08 (SD_DATA1 Flash QIO/DIO/DOUT)
|
||||
0, // GPIO09 (SD_DATA2 Flash QIO or ESP8285)
|
||||
0, // GPIO10 (SD_DATA3 Flash QIO or ESP8285)
|
||||
// GPIO11 (SD_CMD Flash)
|
||||
GPIO_PWM2, // GPIO12 LED Green
|
||||
GPIO_PWM1, // GPIO13 LED Red
|
||||
GPIO_PWM3, // GPIO14 LED Blue
|
||||
0, // GPIO15
|
||||
GPIO_KEY2, // GPIO16 Button
|
||||
0
|
||||
}
|
||||
|
||||
{ "N0DY Relay", // N0DY Wifi Dual Relay (ESP-07)
|
||||
// https://www.n0dy.com/product/web-controlled-dual-relay/
|
||||
// https://www.amazon.com/dp/B072MKV8ZM
|
||||
|
|
|
@ -32,8 +32,9 @@ uint8_t multiwindow[MAX_KEYS] = { 0 }; // Max time between button presses t
|
|||
uint8_t multipress[MAX_KEYS] = { 0 }; // Number of button presses within multiwindow
|
||||
|
||||
uint8_t dual_hex_code = 0; // Sonoff dual input flag
|
||||
uint8_t key_no_pullup = 0;
|
||||
uint8_t buttons_found = 0;
|
||||
uint8_t key_no_pullup = 0; // key no pullup flag (1 = no pullup)
|
||||
uint8_t key_inverted = 0; // Key inverted flag (1 = inverted)
|
||||
uint8_t buttons_found = 0; // Number of buttons found flag
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
|
@ -42,6 +43,11 @@ void ButtonPullupFlag(uint8 button_bit)
|
|||
bitSet(key_no_pullup, button_bit);
|
||||
}
|
||||
|
||||
void ButtonInvertFlag(uint8 button_bit)
|
||||
{
|
||||
bitSet(key_inverted, button_bit);
|
||||
}
|
||||
|
||||
void ButtonInit(void)
|
||||
{
|
||||
if (my_module_flag.pullup) {
|
||||
|
@ -115,7 +121,7 @@ void ButtonHandler(void)
|
|||
} else {
|
||||
if (pin[GPIO_KEY1 +button_index] < 99) {
|
||||
button_present = 1;
|
||||
button = digitalRead(pin[GPIO_KEY1 +button_index]);
|
||||
button = (digitalRead(pin[GPIO_KEY1 +button_index]) != key_inverted);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue