Fix support of more touch pins (#16518)

This commit is contained in:
Theo Arends 2022-09-15 12:27:49 +02:00
parent 903d3174b2
commit 7e21442e96
3 changed files with 25 additions and 32 deletions

View File

@ -26,10 +26,9 @@
\*********************************************************************************************/ \*********************************************************************************************/
#define MAX_RELAY_BUTTON1 5 // Max number of relay controlled by BUTTON1 #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_PIN_THRESHOLD 12 // Smaller value will treated as button press
#define TOUCH_HIT_THRESHOLD 3 // successful hits to filter out noise #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_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 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 #ifdef ESP32
struct TOUCH_BUTTON { struct TOUCH_BUTTON {
uint8_t pin_threshold = TOUCH_PIN_THRESHOLD;
uint8_t hit_threshold = TOUCH_HIT_THRESHOLD;
uint32_t calibration = 0; // Bitfield uint32_t calibration = 0; // Bitfield
uint32_t pin_threshold = TOUCH_PIN_THRESHOLD;
uint8_t hit_threshold = TOUCH_HIT_THRESHOLD;
} TOUCH_BUTTON; } TOUCH_BUTTON;
#endif // ESP32 #endif // ESP32

View File

@ -24,10 +24,9 @@
\*********************************************************************************************/ \*********************************************************************************************/
#define MAX_RELAY_BUTTON1 5 // Max number of relay controlled by BUTTON1 #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_PIN_THRESHOLD 12 // Smaller value will treated as button press
#define TOUCH_HIT_THRESHOLD 3 // successful hits to filter out noise #define TOUCH_HIT_THRESHOLD 3 // successful hits to filter out noise
#endif // ESP32
const char kMultiPress[] PROGMEM = const char kMultiPress[] PROGMEM =
"|SINGLE|DOUBLE|TRIPLE|QUAD|PENTA|"; "|SINGLE|DOUBLE|TRIPLE|QUAD|PENTA|";
@ -56,9 +55,9 @@ struct BUTTON {
#ifdef ESP32 #ifdef ESP32
struct TOUCH_BUTTON { struct TOUCH_BUTTON {
uint8_t pin_threshold = TOUCH_PIN_THRESHOLD;
uint8_t hit_threshold = TOUCH_HIT_THRESHOLD;
uint32_t calibration = 0; // Bitfield uint32_t calibration = 0; // Bitfield
uint32_t pin_threshold = TOUCH_PIN_THRESHOLD;
uint8_t hit_threshold = TOUCH_HIT_THRESHOLD;
} TOUCH_BUTTON; } TOUCH_BUTTON;
#endif // ESP32 #endif // ESP32

View File

@ -2605,39 +2605,34 @@ void CmndCpuFrequency(void) {
ResponseCmndNumber(getCpuFrequencyMhz()); ResponseCmndNumber(getCpuFrequencyMhz());
} }
void CmndTouchCal(void) void CmndTouchCal(void) {
{
if (XdrvMailbox.payload >= 0) { if (XdrvMailbox.payload >= 0) {
if (XdrvMailbox.payload < MAX_KEYS + 1) TOUCH_BUTTON.calibration = bitSet(TOUCH_BUTTON.calibration, XdrvMailbox.payload); if (XdrvMailbox.payload == 0) {
if (XdrvMailbox.payload == 0) TOUCH_BUTTON.calibration = 0; TOUCH_BUTTON.calibration = 0;
if (XdrvMailbox.payload == 255) TOUCH_BUTTON.calibration = 255; // all pinss
} }
Response_P(PSTR("{\"" D_CMND_TOUCH_CAL "\": %u"), TOUCH_BUTTON.calibration); else if (XdrvMailbox.payload < MAX_KEYS + 1) {
ResponseJsonEnd(); TOUCH_BUTTON.calibration = bitSet(TOUCH_BUTTON.calibration, XdrvMailbox.payload);
}
else if (XdrvMailbox.payload == 255) {
TOUCH_BUTTON.calibration = 0x0FFFFFFF; // All MAX_KEYS pins
}
}
ResponseCmndNumber(TOUCH_BUTTON.calibration);
AddLog(LOG_LEVEL_INFO, PSTR("Button Touchvalue Hits,")); AddLog(LOG_LEVEL_INFO, PSTR("Button Touchvalue Hits,"));
} }
void CmndTouchThres(void) void CmndTouchThres(void) {
{ if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32000)) {
if (XdrvMailbox.payload >= 0) {
if (XdrvMailbox.payload<256){
TOUCH_BUTTON.pin_threshold = XdrvMailbox.payload; TOUCH_BUTTON.pin_threshold = XdrvMailbox.payload;
} }
} ResponseCmndNumber(TOUCH_BUTTON.pin_threshold);
Response_P(PSTR("{\"" D_CMND_TOUCH_THRES "\": %u"), TOUCH_BUTTON.pin_threshold);
ResponseJsonEnd();
} }
void CmndTouchNum(void) void CmndTouchNum(void) {
{ if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32)) {
if (XdrvMailbox.payload >= 0) {
if (XdrvMailbox.payload<32){
TOUCH_BUTTON.hit_threshold = XdrvMailbox.payload; TOUCH_BUTTON.hit_threshold = XdrvMailbox.payload;
} }
} ResponseCmndNumber(TOUCH_BUTTON.hit_threshold);
Response_P(PSTR("{\"" D_CMND_TOUCH_NUM "\": %u"), TOUCH_BUTTON.hit_threshold);
ResponseJsonEnd();
} }
#endif // ESP32 #endif // ESP32