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
#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

View File

@ -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

View File

@ -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