diff --git a/tasmota/tasmota_support/support_button _v3.ino b/tasmota/tasmota_support/support_button _v3.ino index e28d172e4..1fe449b77 100644 --- a/tasmota/tasmota_support/support_button _v3.ino +++ b/tasmota/tasmota_support/support_button _v3.ino @@ -26,10 +26,9 @@ \*********************************************************************************************/ #define MAX_RELAY_BUTTON1 5 // Max number of relay controlled by BUTTON1 -#ifdef ESP32 + #define TOUCH_PIN_THRESHOLD 12 // Smaller value will treated as button press #define TOUCH_HIT_THRESHOLD 3 // successful hits to filter out noise -#endif // ESP32 const uint8_t BUTTON_PROBE_INTERVAL = 10; // Time in milliseconds between button input probe const uint8_t BUTTON_FAST_PROBE_INTERVAL = 2; // Time in milliseconds between button input probe for AC detection @@ -67,9 +66,9 @@ struct BUTTON { #ifdef ESP32 struct TOUCH_BUTTON { - uint8_t pin_threshold = TOUCH_PIN_THRESHOLD; + uint32_t calibration = 0; // Bitfield + uint32_t pin_threshold = TOUCH_PIN_THRESHOLD; uint8_t hit_threshold = TOUCH_HIT_THRESHOLD; - uint32_t calibration = 0; // Bitfield } TOUCH_BUTTON; #endif // ESP32 diff --git a/tasmota/tasmota_support/support_button_v2.ino b/tasmota/tasmota_support/support_button_v2.ino index 099c77e01..19538b0ed 100644 --- a/tasmota/tasmota_support/support_button_v2.ino +++ b/tasmota/tasmota_support/support_button_v2.ino @@ -24,10 +24,9 @@ \*********************************************************************************************/ #define MAX_RELAY_BUTTON1 5 // Max number of relay controlled by BUTTON1 -#ifdef ESP32 + #define TOUCH_PIN_THRESHOLD 12 // Smaller value will treated as button press #define TOUCH_HIT_THRESHOLD 3 // successful hits to filter out noise -#endif // ESP32 const char kMultiPress[] PROGMEM = "|SINGLE|DOUBLE|TRIPLE|QUAD|PENTA|"; @@ -56,9 +55,9 @@ struct BUTTON { #ifdef ESP32 struct TOUCH_BUTTON { - uint8_t pin_threshold = TOUCH_PIN_THRESHOLD; + uint32_t calibration = 0; // Bitfield + uint32_t pin_threshold = TOUCH_PIN_THRESHOLD; uint8_t hit_threshold = TOUCH_HIT_THRESHOLD; - uint32_t calibration = 0; // Bitfield } TOUCH_BUTTON; #endif // ESP32 diff --git a/tasmota/tasmota_support/support_command.ino b/tasmota/tasmota_support/support_command.ino index e29c3ccb9..83cfa5ff5 100644 --- a/tasmota/tasmota_support/support_command.ino +++ b/tasmota/tasmota_support/support_command.ino @@ -2605,39 +2605,34 @@ void CmndCpuFrequency(void) { ResponseCmndNumber(getCpuFrequencyMhz()); } -void CmndTouchCal(void) -{ +void CmndTouchCal(void) { if (XdrvMailbox.payload >= 0) { - if (XdrvMailbox.payload < MAX_KEYS + 1) TOUCH_BUTTON.calibration = bitSet(TOUCH_BUTTON.calibration, XdrvMailbox.payload); - if (XdrvMailbox.payload == 0) TOUCH_BUTTON.calibration = 0; - if (XdrvMailbox.payload == 255) TOUCH_BUTTON.calibration = 255; // all pinss + if (XdrvMailbox.payload == 0) { + TOUCH_BUTTON.calibration = 0; + } + else if (XdrvMailbox.payload < MAX_KEYS + 1) { + TOUCH_BUTTON.calibration = bitSet(TOUCH_BUTTON.calibration, XdrvMailbox.payload); + } + else if (XdrvMailbox.payload == 255) { + TOUCH_BUTTON.calibration = 0x0FFFFFFF; // All MAX_KEYS pins + } } - Response_P(PSTR("{\"" D_CMND_TOUCH_CAL "\": %u"), TOUCH_BUTTON.calibration); - ResponseJsonEnd(); + ResponseCmndNumber(TOUCH_BUTTON.calibration); AddLog(LOG_LEVEL_INFO, PSTR("Button Touchvalue Hits,")); } -void CmndTouchThres(void) -{ - if (XdrvMailbox.payload >= 0) { - if (XdrvMailbox.payload<256){ - TOUCH_BUTTON.pin_threshold = XdrvMailbox.payload; - } +void CmndTouchThres(void) { + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32000)) { + TOUCH_BUTTON.pin_threshold = XdrvMailbox.payload; } - Response_P(PSTR("{\"" D_CMND_TOUCH_THRES "\": %u"), TOUCH_BUTTON.pin_threshold); - ResponseJsonEnd(); + ResponseCmndNumber(TOUCH_BUTTON.pin_threshold); } -void CmndTouchNum(void) -{ - if (XdrvMailbox.payload >= 0) { - if (XdrvMailbox.payload<32){ - TOUCH_BUTTON.hit_threshold = XdrvMailbox.payload; - } +void CmndTouchNum(void) { + if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32)) { + TOUCH_BUTTON.hit_threshold = XdrvMailbox.payload; } - Response_P(PSTR("{\"" D_CMND_TOUCH_NUM "\": %u"), TOUCH_BUTTON.hit_threshold); - ResponseJsonEnd(); - + ResponseCmndNumber(TOUCH_BUTTON.hit_threshold); } #endif // ESP32