From de803d32071ebbb26403cc8a5b438ad5b1e4026a Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Mon, 18 Nov 2024 21:57:28 +0100 Subject: [PATCH 01/16] Update _P097_Esp32Touch.ino - added extra routine for esp32 s2 and s3 - added option to wake up the esp for supported devices (tested with s3) - added second value "state" for easier handling - failed epically to add a long press event because I am just a simple person, but left the remains for someone else to pick up And as always, please don't stone me. me and c++ are not going to be friends in this life anymore. :) If you agree to the changes i will update the documentatzion accordingly --- src/_P097_Esp32Touch.ino | 102 +++++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 25 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index f482a76049..9d49401d9e 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -23,23 +23,23 @@ # define PLUGIN_097 -# define PLUGIN_ID_097 97 -# define PLUGIN_NAME_097 "Touch (ESP32) - internal" -# define PLUGIN_VALUENAME1_097 "Touch" - - -# ifdef ESP32 - # define P097_MAX_ADC_VALUE 4095 -# endif // ifdef ESP32 -# ifdef ESP8266 - # define P097_MAX_ADC_VALUE 1023 -# endif // ifdef ESP8266 - - -# define P097_SEND_TOUCH_EVENT PCONFIG(0) -# define P097_SEND_RELEASE_EVENT PCONFIG(1) -# define P097_SEND_DURATION_EVENT PCONFIG(2) -# define P097_TOUCH_THRESHOLD PCONFIG(3) +# define PLUGIN_ID_097 97 +# define PLUGIN_NAME_097 "Touch (ESP32) - internal" +# define PLUGIN_VALUENAME1_097 "Touch" +# define PLUGIN_VALUENAME2_097 "State" +# define P097_MAX_ADC_VALUE 4095 +# define P097_MAX_LONGPRESS_VALUE 10000 + + +# define P097_SEND_TOUCH_EVENT PCONFIG(0) +# define P097_SEND_RELEASE_EVENT PCONFIG(1) +# define P097_SEND_DURATION_EVENT PCONFIG(2) +# define P097_TOUCH_THRESHOLD PCONFIG(3) +//# define P097_SEND_LONG_PRESS_EVENT PCONFIG(4) +//# define P097_LONG_PRESS_TIME PCONFIG(5) +#if defined(ESP32S2) || defined(ESP32S3) +# define P097_Sleep_WakeUp PCONFIG(6) +#endif // Share this bitmap among all instances of this plugin DRAM_ATTR uint32_t p097_pinTouched = 0; @@ -61,12 +61,13 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) Device[deviceCount].PullUpOption = false; Device[deviceCount].InverseLogicOption = false; Device[deviceCount].FormulaOption = true; - Device[deviceCount].ValueCount = 1; + Device[deviceCount].ValueCount = 2; Device[deviceCount].SendDataOption = true; Device[deviceCount].DecimalsOnly = false; Device[deviceCount].TimerOption = false; Device[deviceCount].TimerOptional = true; Device[deviceCount].GlobalSyncOption = true; + Device[deviceCount].OutputDataType = Output_Data_type_t::All; break; } @@ -77,16 +78,25 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) } case PLUGIN_GET_DEVICEVALUENAMES: - { + { strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_097)); + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_097)); + ExtraTaskSettings.TaskDeviceValueDecimals[1] = 0; + ExtraTaskSettings.TaskDeviceValueDecimals[2] = 0; break; } case PLUGIN_SET_DEFAULTS: { P097_SEND_TOUCH_EVENT = 1; - P097_SEND_DURATION_EVENT = 1; + P097_SEND_RELEASE_EVENT = 1; + P097_SEND_DURATION_EVENT = 0; + //P097_LONG_PRESS_TIME = 1000; + #if defined(ESP32S2) || defined(ESP32S3) + P097_TOUCH_THRESHOLD = 1500; + #else P097_TOUCH_THRESHOLD = 20; + #endif break; } @@ -99,8 +109,14 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) addFormCheckBox(F("Send Touch Event"), F("sendtouch"), P097_SEND_TOUCH_EVENT); addFormCheckBox(F("Send Release Event"), F("sendrelease"), P097_SEND_RELEASE_EVENT); + //addFormCheckBox(F("Send Long Press Event"), F("sendlongpress"), P097_SEND_LONG_PRESS_EVENT); + //addFormNumericBox(F("Long Press Time"), F("longpress"), P097_LONG_PRESS_TIME, 0, P097_MAX_LONGPRESS_VALUE); addFormCheckBox(F("Send Duration Event"), F("sendduration"), P097_SEND_DURATION_EVENT); addFormNumericBox(F("Touch Threshold"), F("threshold"), P097_TOUCH_THRESHOLD, 0, P097_MAX_ADC_VALUE); + #if defined(ESP32S2) || defined(ESP32S3) + addFormCheckBox(F("Wake Up from sleep"), F("sleepwakeup"), P097_Sleep_WakeUp); + addFormNote(F("Wake up from sleep is only supported on one touch pin!")); + #endif // Show current value addRowLabel(F("Current Pressure")); @@ -114,9 +130,13 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) { P097_SEND_TOUCH_EVENT = isFormItemChecked(F("sendtouch")); P097_SEND_RELEASE_EVENT = isFormItemChecked(F("sendrelease")); + //P097_SEND_LONG_PRESS_EVENT = isFormItemChecked(F("sendlongpress")); + //P097_LONG_PRESS_TIME = getFormItemInt(F("longpress")); P097_SEND_DURATION_EVENT = isFormItemChecked(F("sendduration")); P097_TOUCH_THRESHOLD = getFormItemInt(F("threshold")); - + #if defined(ESP32S2) || defined(ESP32S3) + P097_Sleep_WakeUp = isFormItemChecked(F("sleepwakeup")); + #endif success = true; break; } @@ -124,6 +144,11 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_INIT: { P097_setEventParams(CONFIG_PIN1, P097_TOUCH_THRESHOLD); + #if defined(ESP32S2) || defined(ESP32S3) + if (P097_Sleep_WakeUp) { + touchSleepWakeUpEnable(CONFIG_PIN1, P097_TOUCH_THRESHOLD); + } + #endif success = true; break; } @@ -139,6 +164,28 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) const bool touched = bitRead(p097_pinTouched, t); const bool touched_prev = bitRead(p097_pinTouchedPrev, t); + #if defined(ESP32S2) || defined(ESP32S3) + if (touched) { + bitClear(p097_pinTouched, t); + UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); + if (touchInterruptGetLastStatus(CONFIG_PIN1)) { + Scheduler.schedule_task_device_timer(event->TaskIndex, millis()); + UserVar.setFloat(event->TaskIndex, 1, 1); + } else { + if (P097_SEND_RELEASE_EVENT) { + Scheduler.schedule_task_device_timer(event->TaskIndex, millis()); + UserVar.setFloat(event->TaskIndex, 1, 0); + } + + if (P097_SEND_DURATION_EVENT) { + eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t])); + } + + p097_timestamp[t] = 0; + } + } + + #else if (touched) { bitClear(p097_pinTouched, t); } @@ -150,25 +197,30 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) if (touched) { if (P097_SEND_TOUCH_EVENT) { // schedule a read to update output values and send to controllers + UserVar.setFloat(event->TaskIndex, 1, 1); Scheduler.schedule_task_device_timer(event->TaskIndex, millis()); + } bitSet(p097_pinTouchedPrev, t); - } else { + } else { + // Touch released if (P097_SEND_RELEASE_EVENT) { // schedule a read to update output values and send to controllers + UserVar.setFloat(event->TaskIndex, 1, 0); Scheduler.schedule_task_device_timer(event->TaskIndex, millis()); + } if (P097_SEND_DURATION_EVENT) { - if (Settings.UseRules) { eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t])); - } } + bitClear(p097_pinTouchedPrev, t); p097_timestamp[t] = 0; } } - } + #endif + } } success = true; break; From 2f29a76e26608a75c257b1325170a1f8d7e9a4b7 Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:34:40 +0100 Subject: [PATCH 02/16] Update _P097_Esp32Touch.ino - added and tested wakeup on ep32 classic --- src/_P097_Esp32Touch.ino | 57 ++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index 9d49401d9e..7047fa6500 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -35,11 +35,9 @@ # define P097_SEND_RELEASE_EVENT PCONFIG(1) # define P097_SEND_DURATION_EVENT PCONFIG(2) # define P097_TOUCH_THRESHOLD PCONFIG(3) -//# define P097_SEND_LONG_PRESS_EVENT PCONFIG(4) -//# define P097_LONG_PRESS_TIME PCONFIG(5) -#if defined(ESP32S2) || defined(ESP32S3) -# define P097_Sleep_WakeUp PCONFIG(6) -#endif +//# define P097_SEND_LONG_PRESS_EVENT PCONFIG(5) +//# define P097_LONG_PRESS_TIME PCONFIG(6) +# define P097_SLEEP_WAKEUP PCONFIG(4) // Share this bitmap among all instances of this plugin DRAM_ATTR uint32_t p097_pinTouched = 0; @@ -81,8 +79,8 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) { strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_097)); strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_097)); + ExtraTaskSettings.TaskDeviceValueDecimals[0] = 0; ExtraTaskSettings.TaskDeviceValueDecimals[1] = 0; - ExtraTaskSettings.TaskDeviceValueDecimals[2] = 0; break; } @@ -113,8 +111,8 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) //addFormNumericBox(F("Long Press Time"), F("longpress"), P097_LONG_PRESS_TIME, 0, P097_MAX_LONGPRESS_VALUE); addFormCheckBox(F("Send Duration Event"), F("sendduration"), P097_SEND_DURATION_EVENT); addFormNumericBox(F("Touch Threshold"), F("threshold"), P097_TOUCH_THRESHOLD, 0, P097_MAX_ADC_VALUE); + addFormCheckBox(F("Wake Up from sleep"), F("sleepwakeup"), P097_SLEEP_WAKEUP); #if defined(ESP32S2) || defined(ESP32S3) - addFormCheckBox(F("Wake Up from sleep"), F("sleepwakeup"), P097_Sleep_WakeUp); addFormNote(F("Wake up from sleep is only supported on one touch pin!")); #endif @@ -134,9 +132,7 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) //P097_LONG_PRESS_TIME = getFormItemInt(F("longpress")); P097_SEND_DURATION_EVENT = isFormItemChecked(F("sendduration")); P097_TOUCH_THRESHOLD = getFormItemInt(F("threshold")); - #if defined(ESP32S2) || defined(ESP32S3) - P097_Sleep_WakeUp = isFormItemChecked(F("sleepwakeup")); - #endif + P097_SLEEP_WAKEUP = isFormItemChecked(F("sleepwakeup")); success = true; break; } @@ -144,11 +140,9 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_INIT: { P097_setEventParams(CONFIG_PIN1, P097_TOUCH_THRESHOLD); - #if defined(ESP32S2) || defined(ESP32S3) - if (P097_Sleep_WakeUp) { + if (P097_SLEEP_WAKEUP) { touchSleepWakeUpEnable(CONFIG_PIN1, P097_TOUCH_THRESHOLD); } - #endif success = true; break; } @@ -168,17 +162,27 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) if (touched) { bitClear(p097_pinTouched, t); UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); + if (touchInterruptGetLastStatus(CONFIG_PIN1)) { - Scheduler.schedule_task_device_timer(event->TaskIndex, millis()); UserVar.setFloat(event->TaskIndex, 1, 1); - } else { - if (P097_SEND_RELEASE_EVENT) { - Scheduler.schedule_task_device_timer(event->TaskIndex, millis()); + eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 1); + + if (P097_SEND_TOUCH_EVENT) { + eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0)); + } + + } else { UserVar.setFloat(event->TaskIndex, 1, 0); + eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 0); + + if (P097_SEND_RELEASE_EVENT) { + eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0)); } if (P097_SEND_DURATION_EVENT) { + if (Settings.UseRules) { eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t])); + } } p097_timestamp[t] = 0; @@ -195,24 +199,27 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); if (touched) { + UserVar.setFloat(event->TaskIndex, 1, 1); + eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 1); + if (P097_SEND_TOUCH_EVENT) { - // schedule a read to update output values and send to controllers - UserVar.setFloat(event->TaskIndex, 1, 1); - Scheduler.schedule_task_device_timer(event->TaskIndex, millis()); - + eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0)); } + bitSet(p097_pinTouchedPrev, t); } else { // Touch released + UserVar.setFloat(event->TaskIndex, 1, 0); + eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 0); + if (P097_SEND_RELEASE_EVENT) { - // schedule a read to update output values and send to controllers - UserVar.setFloat(event->TaskIndex, 1, 0); - Scheduler.schedule_task_device_timer(event->TaskIndex, millis()); - + eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0)); } if (P097_SEND_DURATION_EVENT) { + if (Settings.UseRules) { eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t])); + } } bitClear(p097_pinTouchedPrev, t); From 5deca7f7207b1c947cdca733fb671002f0c98d11 Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:42:08 +0100 Subject: [PATCH 03/16] Update _P097_Esp32Touch.ino get the actual valuename --- src/_P097_Esp32Touch.ino | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index 7047fa6500..bc836406c5 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -156,7 +156,9 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) if (getADC_gpio_info(CONFIG_PIN1, adc, ch, t)) { const bool touched = bitRead(p097_pinTouched, t); + #ifdef ESP32_CLASSIC const bool touched_prev = bitRead(p097_pinTouchedPrev, t); + #endif #if defined(ESP32S2) || defined(ESP32S3) if (touched) { @@ -165,18 +167,18 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) if (touchInterruptGetLastStatus(CONFIG_PIN1)) { UserVar.setFloat(event->TaskIndex, 1, 1); - eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 1); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 1); if (P097_SEND_TOUCH_EVENT) { - eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0)); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); } } else { UserVar.setFloat(event->TaskIndex, 1, 0); - eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 0); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1), 0); if (P097_SEND_RELEASE_EVENT) { - eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0)); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); } if (P097_SEND_DURATION_EVENT) { @@ -200,20 +202,20 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) if (touched) { UserVar.setFloat(event->TaskIndex, 1, 1); - eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 1); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 1); if (P097_SEND_TOUCH_EVENT) { - eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0)); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); } bitSet(p097_pinTouchedPrev, t); } else { // Touch released UserVar.setFloat(event->TaskIndex, 1, 0); - eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME2_097), 0); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); if (P097_SEND_RELEASE_EVENT) { - eventQueue.add(event->TaskIndex, F(PLUGIN_VALUENAME1_097), UserVar.getFloat(event->TaskIndex, 0)); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); } if (P097_SEND_DURATION_EVENT) { From 0ac220098007ba0c60ca679495bd15603755483a Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Tue, 19 Nov 2024 12:15:09 +0100 Subject: [PATCH 04/16] Update _P097_Esp32Touch.ino --- src/_P097_Esp32Touch.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index bc836406c5..0e83f92ea8 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -175,7 +175,7 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) } else { UserVar.setFloat(event->TaskIndex, 1, 0); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1), 0); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); if (P097_SEND_RELEASE_EVENT) { eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); From a14b3222aecf3a1807902127b5db30f82aa33ffb Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Sat, 23 Nov 2024 22:42:12 +0100 Subject: [PATCH 05/16] Update _P097_Esp32Touch.ino - added "toggle state" option (since I am not able to add a long press :) ) --- src/_P097_Esp32Touch.ino | 245 ++++++++++++++++++++++----------------- 1 file changed, 136 insertions(+), 109 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index 0e83f92ea8..ee3f3f56de 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -6,43 +6,44 @@ // ####################################################################################################### -#if defined(ESP32) && !defined(ESP32C2) && !defined(ESP32C3) && !defined(ESP32C6) - -#ifdef ESP32_CLASSIC - # define HAS_T0_INPUT 1 - # define HAS_T10_TO_T14 0 - # define LAST_TOUCH_INPUT_INDEX 10 -#endif -#if defined(ESP32S2) || defined(ESP32S3) - # define HAS_T0_INPUT 0 - # define HAS_T10_TO_T14 1 - # define LAST_TOUCH_INPUT_INDEX 15 - -#endif - - - -# define PLUGIN_097 -# define PLUGIN_ID_097 97 -# define PLUGIN_NAME_097 "Touch (ESP32) - internal" -# define PLUGIN_VALUENAME1_097 "Touch" -# define PLUGIN_VALUENAME2_097 "State" -# define P097_MAX_ADC_VALUE 4095 -# define P097_MAX_LONGPRESS_VALUE 10000 - - -# define P097_SEND_TOUCH_EVENT PCONFIG(0) -# define P097_SEND_RELEASE_EVENT PCONFIG(1) -# define P097_SEND_DURATION_EVENT PCONFIG(2) -# define P097_TOUCH_THRESHOLD PCONFIG(3) -//# define P097_SEND_LONG_PRESS_EVENT PCONFIG(5) -//# define P097_LONG_PRESS_TIME PCONFIG(6) -# define P097_SLEEP_WAKEUP PCONFIG(4) +# if defined(ESP32) && !defined(ESP32C2) && !defined(ESP32C3) && !defined(ESP32C6) + +# ifdef ESP32_CLASSIC + # define HAS_T0_INPUT 1 + # define HAS_T10_TO_T14 0 + # define LAST_TOUCH_INPUT_INDEX 10 +# endif // ifdef ESP32_CLASSIC +# if defined(ESP32S2) || defined(ESP32S3) + # define HAS_T0_INPUT 0 + # define HAS_T10_TO_T14 1 + # define LAST_TOUCH_INPUT_INDEX 15 + +# endif // if defined(ESP32S2) || defined(ESP32S3) + + +# define PLUGIN_097 +# define PLUGIN_ID_097 97 +# define PLUGIN_NAME_097 "Touch (ESP32) - internal" +# define PLUGIN_VALUENAME1_097 "Touch" +# define PLUGIN_VALUENAME2_097 "State" +# define P097_MAX_ADC_VALUE 4095 +# define P097_MAX_LONGPRESS_VALUE 10000 + + +# define P097_SEND_TOUCH_EVENT PCONFIG(0) +# define P097_SEND_RELEASE_EVENT PCONFIG(1) +# define P097_SEND_DURATION_EVENT PCONFIG(2) +# define P097_TOUCH_THRESHOLD PCONFIG(3) +# define P097_TYPE_TOGGLE PCONFIG(4) +# define P097_SLEEP_WAKEUP PCONFIG(5) + +// # define P097_SEND_LONG_PRESS_EVENT PCONFIG(6) +// # define P097_LONG_PRESS_TIME PCONFIG(7) // Share this bitmap among all instances of this plugin -DRAM_ATTR uint32_t p097_pinTouched = 0; -DRAM_ATTR uint32_t p097_pinTouchedPrev = 0; -DRAM_ATTR uint32_t p097_timestamp[LAST_TOUCH_INPUT_INDEX] = { 0 }; +DRAM_ATTR uint32_t p097_pinTouched = 0; +DRAM_ATTR uint32_t p097_pinTouchedPrev = 0; +DRAM_ATTR uint32_t p097_timestamp[LAST_TOUCH_INPUT_INDEX] = { 0 }; boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) { @@ -65,7 +66,6 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) Device[deviceCount].TimerOption = false; Device[deviceCount].TimerOptional = true; Device[deviceCount].GlobalSyncOption = true; - Device[deviceCount].OutputDataType = Output_Data_type_t::All; break; } @@ -76,7 +76,7 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) } case PLUGIN_GET_DEVICEVALUENAMES: - { + { strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_097)); strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_097)); ExtraTaskSettings.TaskDeviceValueDecimals[0] = 0; @@ -86,15 +86,16 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_SET_DEFAULTS: { - P097_SEND_TOUCH_EVENT = 1; - P097_SEND_RELEASE_EVENT = 1; + P097_SEND_TOUCH_EVENT = 1; + P097_SEND_RELEASE_EVENT = 1; P097_SEND_DURATION_EVENT = 0; - //P097_LONG_PRESS_TIME = 1000; - #if defined(ESP32S2) || defined(ESP32S3) + + // P097_LONG_PRESS_TIME = 1000; + # if defined(ESP32S2) || defined(ESP32S3) P097_TOUCH_THRESHOLD = 1500; - #else + # else // if defined(ESP32S2) || defined(ESP32S3) P097_TOUCH_THRESHOLD = 20; - #endif + # endif // if defined(ESP32S2) || defined(ESP32S3) break; } @@ -103,18 +104,21 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) addRowLabel(F("Analog Pin")); addADC_PinSelect(AdcPinSelectPurpose::TouchOnly, F("taskdevicepin1"), CONFIG_PIN1); + addFormCheckBox(F("Toggle State"), F("typetoggle"), P097_TYPE_TOGGLE); + addFormCheckBox(F("Wake Up from Sleep"), F("sleepwakeup"), P097_SLEEP_WAKEUP); + # if defined(ESP32S2) || defined(ESP32S3) + addFormNote(F("Wake up from sleep is only supported on one touch pin!")); + # endif // if defined(ESP32S2) || defined(ESP32S3) + addFormSubHeader(F("Touch Settings")); - addFormCheckBox(F("Send Touch Event"), F("sendtouch"), P097_SEND_TOUCH_EVENT); - addFormCheckBox(F("Send Release Event"), F("sendrelease"), P097_SEND_RELEASE_EVENT); - //addFormCheckBox(F("Send Long Press Event"), F("sendlongpress"), P097_SEND_LONG_PRESS_EVENT); - //addFormNumericBox(F("Long Press Time"), F("longpress"), P097_LONG_PRESS_TIME, 0, P097_MAX_LONGPRESS_VALUE); + addFormCheckBox(F("Send Touch Event"), F("sendtouch"), P097_SEND_TOUCH_EVENT); + addFormCheckBox(F("Send Release Event"), F("sendrelease"), P097_SEND_RELEASE_EVENT); + + // addFormCheckBox(F("Send Long Press Event"), F("sendlongpress"), P097_SEND_LONG_PRESS_EVENT); + // addFormNumericBox(F("Long Press Time"), F("longpress"), P097_LONG_PRESS_TIME, 0, P097_MAX_LONGPRESS_VALUE); addFormCheckBox(F("Send Duration Event"), F("sendduration"), P097_SEND_DURATION_EVENT); addFormNumericBox(F("Touch Threshold"), F("threshold"), P097_TOUCH_THRESHOLD, 0, P097_MAX_ADC_VALUE); - addFormCheckBox(F("Wake Up from sleep"), F("sleepwakeup"), P097_SLEEP_WAKEUP); - #if defined(ESP32S2) || defined(ESP32S3) - addFormNote(F("Wake up from sleep is only supported on one touch pin!")); - #endif // Show current value addRowLabel(F("Current Pressure")); @@ -126,20 +130,23 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_WEBFORM_SAVE: { - P097_SEND_TOUCH_EVENT = isFormItemChecked(F("sendtouch")); - P097_SEND_RELEASE_EVENT = isFormItemChecked(F("sendrelease")); - //P097_SEND_LONG_PRESS_EVENT = isFormItemChecked(F("sendlongpress")); - //P097_LONG_PRESS_TIME = getFormItemInt(F("longpress")); + P097_SEND_TOUCH_EVENT = isFormItemChecked(F("sendtouch")); + P097_SEND_RELEASE_EVENT = isFormItemChecked(F("sendrelease")); + P097_TYPE_TOGGLE = isFormItemChecked(F("typetoggle")); + + // P097_SEND_LONG_PRESS_EVENT = isFormItemChecked(F("sendlongpress")); + // P097_LONG_PRESS_TIME = getFormItemInt(F("longpress")); P097_SEND_DURATION_EVENT = isFormItemChecked(F("sendduration")); P097_TOUCH_THRESHOLD = getFormItemInt(F("threshold")); P097_SLEEP_WAKEUP = isFormItemChecked(F("sleepwakeup")); - success = true; + success = true; break; } case PLUGIN_INIT: { P097_setEventParams(CONFIG_PIN1, P097_TOUCH_THRESHOLD); + if (P097_SLEEP_WAKEUP) { touchSleepWakeUpEnable(CONFIG_PIN1, P097_TOUCH_THRESHOLD); } @@ -155,43 +162,53 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) int adc, ch, t; if (getADC_gpio_info(CONFIG_PIN1, adc, ch, t)) { - const bool touched = bitRead(p097_pinTouched, t); - #ifdef ESP32_CLASSIC + const bool touched = bitRead(p097_pinTouched, t); + # ifdef ESP32_CLASSIC const bool touched_prev = bitRead(p097_pinTouchedPrev, t); - #endif + # endif // ifdef ESP32_CLASSIC + + int toggle; + + # if defined(ESP32S2) || defined(ESP32S3) - #if defined(ESP32S2) || defined(ESP32S3) if (touched) { bitClear(p097_pinTouched, t); UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); - + if (touchInterruptGetLastStatus(CONFIG_PIN1)) { - UserVar.setFloat(event->TaskIndex, 1, 1); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 1); - - if (P097_SEND_TOUCH_EVENT) { - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); - } - - } else { + if (P097_TYPE_TOGGLE) { + toggle = !UserVar.getInt32(event->TaskIndex, 1); + } else { + toggle = 1; + } + UserVar.setFloat(event->TaskIndex, 1, toggle); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), toggle); + + if (P097_SEND_TOUCH_EVENT) { + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); + } + } else { + if (!P097_TYPE_TOGGLE) { UserVar.setFloat(event->TaskIndex, 1, 0); eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); - - if (P097_SEND_RELEASE_EVENT) { - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); - } + } + + if (P097_SEND_RELEASE_EVENT) { + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); + } - if (P097_SEND_DURATION_EVENT) { - if (Settings.UseRules) { - eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t])); - } + if (P097_SEND_DURATION_EVENT) { + if (Settings.UseRules) { + eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t])); } - + } + p097_timestamp[t] = 0; - } + } } - #else + # else // if defined(ESP32S2) || defined(ESP32S3) + if (touched) { bitClear(p097_pinTouched, t); } @@ -201,18 +218,25 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); if (touched) { - UserVar.setFloat(event->TaskIndex, 1, 1); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 1); + if (P097_TYPE_TOGGLE) { + toggle = !UserVar.getInt32(event->TaskIndex, 1); + } else { + toggle = 1; + } + UserVar.setFloat(event->TaskIndex, 1, toggle); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), toggle); if (P097_SEND_TOUCH_EVENT) { - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); } bitSet(p097_pinTouchedPrev, t); - } else { + } else { // Touch released - UserVar.setFloat(event->TaskIndex, 1, 0); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); + if (!P097_TYPE_TOGGLE) { + UserVar.setFloat(event->TaskIndex, 1, 0); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); + } if (P097_SEND_RELEASE_EVENT) { eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); @@ -223,13 +247,13 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t])); } } - + bitClear(p097_pinTouchedPrev, t); p097_timestamp[t] = 0; } } - #endif - } + # endif // if defined(ESP32S2) || defined(ESP32S3) + } } success = true; break; @@ -258,9 +282,9 @@ void P097_setEventParams(int pin, uint16_t threshold) { if (getADC_gpio_info(pin, adc, ch, t)) { switch (t) { -#if HAS_T0_INPUT +# if HAS_T0_INPUT case 0: touchAttachInterrupt(T0, P097_got_T0, threshold); break; -#endif +# endif // if HAS_T0_INPUT case 1: touchAttachInterrupt(T1, P097_got_T1, threshold); break; case 2: touchAttachInterrupt(T2, P097_got_T2, threshold); break; case 3: touchAttachInterrupt(T3, P097_got_T3, threshold); break; @@ -270,22 +294,23 @@ void P097_setEventParams(int pin, uint16_t threshold) { case 7: touchAttachInterrupt(T7, P097_got_T7, threshold); break; case 8: touchAttachInterrupt(T8, P097_got_T8, threshold); break; case 9: touchAttachInterrupt(T9, P097_got_T9, threshold); break; -#if HAS_T10_TO_T14 -/* - case 10: touchAttachInterrupt(T10, P097_got_T10, threshold); break; - case 11: touchAttachInterrupt(T11, P097_got_T11, threshold); break; - case 12: touchAttachInterrupt(T12, P097_got_T12, threshold); break; - case 13: touchAttachInterrupt(T13, P097_got_T13, threshold); break; - case 14: touchAttachInterrupt(T14, P097_got_T14, threshold); break; -*/ -#endif +# if HAS_T10_TO_T14 + + /* + case 10: touchAttachInterrupt(T10, P097_got_T10, threshold); break; + case 11: touchAttachInterrupt(T11, P097_got_T11, threshold); break; + case 12: touchAttachInterrupt(T12, P097_got_T12, threshold); break; + case 13: touchAttachInterrupt(T13, P097_got_T13, threshold); break; + case 14: touchAttachInterrupt(T14, P097_got_T14, threshold); break; + */ +# endif // if HAS_T10_TO_T14 } } } -#if HAS_T0_INPUT +# if HAS_T0_INPUT void P097_got_T0() IRAM_ATTR; -#endif +# endif // if HAS_T0_INPUT void P097_got_T1() IRAM_ATTR; void P097_got_T2() IRAM_ATTR; void P097_got_T3() IRAM_ATTR; @@ -295,20 +320,21 @@ void P097_got_T6() IRAM_ATTR; void P097_got_T7() IRAM_ATTR; void P097_got_T8() IRAM_ATTR; void P097_got_T9() IRAM_ATTR; -#if HAS_T10_TO_T14 +# if HAS_T10_TO_T14 void P097_got_T10() IRAM_ATTR; void P097_got_T11() IRAM_ATTR; void P097_got_T12() IRAM_ATTR; void P097_got_T13() IRAM_ATTR; void P097_got_T14() IRAM_ATTR; -#endif +# endif // if HAS_T10_TO_T14 void P097_got_Touched(int pin) IRAM_ATTR; -#if HAS_T0_INPUT +# if HAS_T0_INPUT void P097_got_T0() { P097_got_Touched(0); } -#endif + +# endif // if HAS_T0_INPUT void P097_got_T1() { P097_got_Touched(1); @@ -346,7 +372,7 @@ void P097_got_T9() { P097_got_Touched(9); } -#if HAS_T10_TO_T14 +# if HAS_T10_TO_T14 void P097_got_T10() { P097_got_Touched(10); } @@ -367,14 +393,15 @@ void P097_got_T14() { P097_got_Touched(14); } -#endif +# endif // if HAS_T10_TO_T14 void P097_got_Touched(int pin) { bitSet(p097_pinTouched, pin); if (p097_timestamp[pin] == 0) { p097_timestamp[pin] = millis(); } } -#endif + +# endif // if defined(ESP32) && !defined(ESP32C2) && !defined(ESP32C3) && !defined(ESP32C6) #endif // USES_P097 From b932e81e6831ef0bd03cb7e3d8c18d1e4e78d7f8 Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:04:39 +0100 Subject: [PATCH 06/16] Update _P097_Esp32Touch.ino - added "long press" event - disabled "Single event with all values" since it is not working with the recent code (suggestions are welcome) but there is also the question if it is necessary --- src/_P097_Esp32Touch.ino | 94 ++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index ee3f3f56de..93843264a7 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -17,7 +17,6 @@ # define HAS_T0_INPUT 0 # define HAS_T10_TO_T14 1 # define LAST_TOUCH_INPUT_INDEX 15 - # endif // if defined(ESP32S2) || defined(ESP32S3) @@ -36,14 +35,16 @@ # define P097_TOUCH_THRESHOLD PCONFIG(3) # define P097_TYPE_TOGGLE PCONFIG(4) # define P097_SLEEP_WAKEUP PCONFIG(5) - -// # define P097_SEND_LONG_PRESS_EVENT PCONFIG(6) -// # define P097_LONG_PRESS_TIME PCONFIG(7) +# define P097_SEND_LONG_PRESS_EVENT PCONFIG(6) +# define P097_LONG_PRESS_TIME PCONFIG(7) // Share this bitmap among all instances of this plugin -DRAM_ATTR uint32_t p097_pinTouched = 0; -DRAM_ATTR uint32_t p097_pinTouchedPrev = 0; -DRAM_ATTR uint32_t p097_timestamp[LAST_TOUCH_INPUT_INDEX] = { 0 }; +DRAM_ATTR uint32_t p097_pinTouched = 0; +DRAM_ATTR uint32_t p097_pinTouchedLong = 0; +DRAM_ATTR uint32_t p097_pinTouchedPrev = 0; +DRAM_ATTR uint32_t p097_timestamp[LAST_TOUCH_INPUT_INDEX] = { 0 }; +DRAM_ATTR uint32_t p097_touchstart[LAST_TOUCH_INPUT_INDEX] = { 0 }; +IRAM_ATTR uint32_t p097_togglevalue[LAST_TOUCH_INPUT_INDEX] = { 0 }; boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) { @@ -61,11 +62,11 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) Device[deviceCount].InverseLogicOption = false; Device[deviceCount].FormulaOption = true; Device[deviceCount].ValueCount = 2; - Device[deviceCount].SendDataOption = true; - Device[deviceCount].DecimalsOnly = false; - Device[deviceCount].TimerOption = false; - Device[deviceCount].TimerOptional = true; - Device[deviceCount].GlobalSyncOption = true; + + // Device[deviceCount].SendDataOption = true; //not working and not necessary? + Device[deviceCount].DecimalsOnly = false; + Device[deviceCount].TimerOption = false; + Device[deviceCount].TimerOptional = true; break; } @@ -89,8 +90,8 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) P097_SEND_TOUCH_EVENT = 1; P097_SEND_RELEASE_EVENT = 1; P097_SEND_DURATION_EVENT = 0; + P097_LONG_PRESS_TIME = 1000; - // P097_LONG_PRESS_TIME = 1000; # if defined(ESP32S2) || defined(ESP32S3) P097_TOUCH_THRESHOLD = 1500; # else // if defined(ESP32S2) || defined(ESP32S3) @@ -109,14 +110,14 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) # if defined(ESP32S2) || defined(ESP32S3) addFormNote(F("Wake up from sleep is only supported on one touch pin!")); # endif // if defined(ESP32S2) || defined(ESP32S3) + addFormCheckBox(F("Send Long Press Event"), F("sendlongpress"), P097_SEND_LONG_PRESS_EVENT); + addFormNumericBox(F("Long Press Time"), F("longpress"), P097_LONG_PRESS_TIME, 500, P097_MAX_LONGPRESS_VALUE); + addUnit(F("500..10000 msec.")); addFormSubHeader(F("Touch Settings")); - addFormCheckBox(F("Send Touch Event"), F("sendtouch"), P097_SEND_TOUCH_EVENT); - addFormCheckBox(F("Send Release Event"), F("sendrelease"), P097_SEND_RELEASE_EVENT); - - // addFormCheckBox(F("Send Long Press Event"), F("sendlongpress"), P097_SEND_LONG_PRESS_EVENT); - // addFormNumericBox(F("Long Press Time"), F("longpress"), P097_LONG_PRESS_TIME, 0, P097_MAX_LONGPRESS_VALUE); + addFormCheckBox(F("Send Touch Event"), F("sendtouch"), P097_SEND_TOUCH_EVENT); + addFormCheckBox(F("Send Release Event"), F("sendrelease"), P097_SEND_RELEASE_EVENT); addFormCheckBox(F("Send Duration Event"), F("sendduration"), P097_SEND_DURATION_EVENT); addFormNumericBox(F("Touch Threshold"), F("threshold"), P097_TOUCH_THRESHOLD, 0, P097_MAX_ADC_VALUE); @@ -134,12 +135,12 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) P097_SEND_RELEASE_EVENT = isFormItemChecked(F("sendrelease")); P097_TYPE_TOGGLE = isFormItemChecked(F("typetoggle")); - // P097_SEND_LONG_PRESS_EVENT = isFormItemChecked(F("sendlongpress")); - // P097_LONG_PRESS_TIME = getFormItemInt(F("longpress")); - P097_SEND_DURATION_EVENT = isFormItemChecked(F("sendduration")); - P097_TOUCH_THRESHOLD = getFormItemInt(F("threshold")); - P097_SLEEP_WAKEUP = isFormItemChecked(F("sleepwakeup")); - success = true; + P097_SEND_LONG_PRESS_EVENT = isFormItemChecked(F("sendlongpress")); + P097_LONG_PRESS_TIME = getFormItemInt(F("longpress")); + P097_SEND_DURATION_EVENT = isFormItemChecked(F("sendduration")); + P097_TOUCH_THRESHOLD = getFormItemInt(F("threshold")); + P097_SLEEP_WAKEUP = isFormItemChecked(F("sleepwakeup")); + success = true; break; } @@ -156,6 +157,14 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_TEN_PER_SECOND: { + if (P097_SEND_LONG_PRESS_EVENT && + (p097_touchstart[CONFIG_PIN1] >= 1) && + (timePassedSince(p097_touchstart[CONFIG_PIN1]) >= P097_LONG_PRESS_TIME)) { + UserVar.setFloat(event->TaskIndex, 1, 10); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 10); + p097_touchstart[CONFIG_PIN1] = 0; + } + if ((p097_pinTouched != 0) || (p097_pinTouchedPrev != 0)) { // Some pin has been touched or released. // Check if it is 'our' pin @@ -167,8 +176,6 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) const bool touched_prev = bitRead(p097_pinTouchedPrev, t); # endif // ifdef ESP32_CLASSIC - int toggle; - # if defined(ESP32S2) || defined(ESP32S3) if (touched) { @@ -176,21 +183,28 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); if (touchInterruptGetLastStatus(CONFIG_PIN1)) { + if (p097_touchstart[CONFIG_PIN1] == 0) { p097_touchstart[CONFIG_PIN1] = millis(); } + if (P097_TYPE_TOGGLE) { - toggle = !UserVar.getInt32(event->TaskIndex, 1); + p097_togglevalue[CONFIG_PIN1] = !UserVar.getInt32(event->TaskIndex, 1); } else { - toggle = 1; + p097_togglevalue[CONFIG_PIN1] = 1; } - UserVar.setFloat(event->TaskIndex, 1, toggle); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), toggle); + UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[CONFIG_PIN1]); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), p097_togglevalue[CONFIG_PIN1]); if (P097_SEND_TOUCH_EVENT) { eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); } - } else { + } else { // Touch released + p097_touchstart[CONFIG_PIN1] = 0; + if (!P097_TYPE_TOGGLE) { UserVar.setFloat(event->TaskIndex, 1, 0); eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); + } else { + // set value back to previous state after long press release + if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[CONFIG_PIN1]); } } if (P097_SEND_RELEASE_EVENT) { @@ -218,24 +232,30 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); if (touched) { + if (p097_touchstart[CONFIG_PIN1] == 0) { p097_touchstart[CONFIG_PIN1] = millis(); } + if (P097_TYPE_TOGGLE) { - toggle = !UserVar.getInt32(event->TaskIndex, 1); + p097_togglevalue[CONFIG_PIN1] = !UserVar.getInt32(event->TaskIndex, 1); } else { - toggle = 1; + p097_togglevalue[CONFIG_PIN1] = 1; } - UserVar.setFloat(event->TaskIndex, 1, toggle); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), toggle); + UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[CONFIG_PIN1]); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), p097_togglevalue[CONFIG_PIN1]); if (P097_SEND_TOUCH_EVENT) { eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); } bitSet(p097_pinTouchedPrev, t); - } else { - // Touch released + } else { // Touch released + p097_touchstart[CONFIG_PIN1] = 0; + if (!P097_TYPE_TOGGLE) { UserVar.setFloat(event->TaskIndex, 1, 0); eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); + } else { + // set value back to previous state after long press release + if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[CONFIG_PIN1]); } } if (P097_SEND_RELEASE_EVENT) { From 7f32370f023205edae3cee19c4da71c3b7fff510 Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:45:25 +0100 Subject: [PATCH 07/16] Update _P097_Esp32Touch.ino --- src/_P097_Esp32Touch.ino | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index 93843264a7..a9df542e3f 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -157,12 +157,17 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_TEN_PER_SECOND: { - if (P097_SEND_LONG_PRESS_EVENT && - (p097_touchstart[CONFIG_PIN1] >= 1) && - (timePassedSince(p097_touchstart[CONFIG_PIN1]) >= P097_LONG_PRESS_TIME)) { - UserVar.setFloat(event->TaskIndex, 1, 10); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 10); - p097_touchstart[CONFIG_PIN1] = 0; + const int START_PIN = HAS_T0_INPUT ? 0 : 1; + const int END_PIN = LAST_TOUCH_INPUT_INDEX - HAS_T0_INPUT; + + if ((CONFIG_PIN1 >= START_PIN) && (CONFIG_PIN1 <= END_PIN)) { + if (P097_SEND_LONG_PRESS_EVENT && + (p097_touchstart[CONFIG_PIN1] >= 1) && + (timePassedSince(p097_touchstart[CONFIG_PIN1]) >= P097_LONG_PRESS_TIME)) { + UserVar.setFloat(event->TaskIndex, 1, 10); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 10); + p097_touchstart[CONFIG_PIN1] = 0; + } } if ((p097_pinTouched != 0) || (p097_pinTouchedPrev != 0)) { @@ -203,7 +208,7 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) UserVar.setFloat(event->TaskIndex, 1, 0); eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); } else { - // set value back to previous state after long press release + // set only the taskvalue back to previous state after long press release if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[CONFIG_PIN1]); } } @@ -254,7 +259,7 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) UserVar.setFloat(event->TaskIndex, 1, 0); eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); } else { - // set value back to previous state after long press release + // set only the taskvalue back to previous state after long press release if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[CONFIG_PIN1]); } } From 721d7bf891263802a3147f509a8678611f6ad5cf Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Wed, 27 Nov 2024 11:52:35 +0100 Subject: [PATCH 08/16] Update _P097_Esp32Touch.ino --- src/_P097_Esp32Touch.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index a9df542e3f..d99a9177cf 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -44,7 +44,7 @@ DRAM_ATTR uint32_t p097_pinTouchedLong = 0; DRAM_ATTR uint32_t p097_pinTouchedPrev = 0; DRAM_ATTR uint32_t p097_timestamp[LAST_TOUCH_INPUT_INDEX] = { 0 }; DRAM_ATTR uint32_t p097_touchstart[LAST_TOUCH_INPUT_INDEX] = { 0 }; -IRAM_ATTR uint32_t p097_togglevalue[LAST_TOUCH_INPUT_INDEX] = { 0 }; +DRAM_ATTR uint32_t p097_togglevalue[LAST_TOUCH_INPUT_INDEX] = { 0 }; boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) { From cff15576dcf997974001848e5e7065e7b5160a6a Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:41:46 +0100 Subject: [PATCH 09/16] Update _P097_Esp32Touch.ino --- src/_P097_Esp32Touch.ino | 56 +++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index d99a9177cf..ae1a4a1769 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -16,7 +16,7 @@ # if defined(ESP32S2) || defined(ESP32S3) # define HAS_T0_INPUT 0 # define HAS_T10_TO_T14 1 - # define LAST_TOUCH_INPUT_INDEX 15 + # define LAST_TOUCH_INPUT_INDEX 14 # endif // if defined(ESP32S2) || defined(ESP32S3) @@ -157,25 +157,22 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_TEN_PER_SECOND: { - const int START_PIN = HAS_T0_INPUT ? 0 : 1; - const int END_PIN = LAST_TOUCH_INPUT_INDEX - HAS_T0_INPUT; + int adc, ch, t; - if ((CONFIG_PIN1 >= START_PIN) && (CONFIG_PIN1 <= END_PIN)) { + if (getADC_gpio_info(CONFIG_PIN1, adc, ch, t)) { if (P097_SEND_LONG_PRESS_EVENT && - (p097_touchstart[CONFIG_PIN1] >= 1) && - (timePassedSince(p097_touchstart[CONFIG_PIN1]) >= P097_LONG_PRESS_TIME)) { + (p097_touchstart[t] >= 1) && + (timePassedSince(p097_touchstart[t]) >= P097_LONG_PRESS_TIME)) { UserVar.setFloat(event->TaskIndex, 1, 10); eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 10); - p097_touchstart[CONFIG_PIN1] = 0; + p097_touchstart[t] = 0; } - } - if ((p097_pinTouched != 0) || (p097_pinTouchedPrev != 0)) { - // Some pin has been touched or released. - // Check if it is 'our' pin - int adc, ch, t; - if (getADC_gpio_info(CONFIG_PIN1, adc, ch, t)) { + if ((p097_pinTouched != 0) || (p097_pinTouchedPrev != 0)) { + // Some pin has been touched or released. + // Check if it is 'our' pin + const bool touched = bitRead(p097_pinTouched, t); # ifdef ESP32_CLASSIC const bool touched_prev = bitRead(p097_pinTouchedPrev, t); @@ -188,28 +185,28 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); if (touchInterruptGetLastStatus(CONFIG_PIN1)) { - if (p097_touchstart[CONFIG_PIN1] == 0) { p097_touchstart[CONFIG_PIN1] = millis(); } + if (p097_touchstart[t] == 0) { p097_touchstart[t] = millis(); } if (P097_TYPE_TOGGLE) { - p097_togglevalue[CONFIG_PIN1] = !UserVar.getInt32(event->TaskIndex, 1); + p097_togglevalue[t] = !UserVar.getInt32(event->TaskIndex, 1); } else { - p097_togglevalue[CONFIG_PIN1] = 1; + p097_togglevalue[t] = 1; } - UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[CONFIG_PIN1]); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), p097_togglevalue[CONFIG_PIN1]); + UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), p097_togglevalue[t]); if (P097_SEND_TOUCH_EVENT) { eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); } } else { // Touch released - p097_touchstart[CONFIG_PIN1] = 0; + p097_touchstart[t] = 0; if (!P097_TYPE_TOGGLE) { UserVar.setFloat(event->TaskIndex, 1, 0); eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); } else { // set only the taskvalue back to previous state after long press release - if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[CONFIG_PIN1]); } + if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); } } if (P097_SEND_RELEASE_EVENT) { @@ -237,15 +234,15 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); if (touched) { - if (p097_touchstart[CONFIG_PIN1] == 0) { p097_touchstart[CONFIG_PIN1] = millis(); } + if (p097_touchstart[t] == 0) { p097_touchstart[t] = millis(); } if (P097_TYPE_TOGGLE) { - p097_togglevalue[CONFIG_PIN1] = !UserVar.getInt32(event->TaskIndex, 1); + p097_togglevalue[t] = !UserVar.getInt32(event->TaskIndex, 1); } else { - p097_togglevalue[CONFIG_PIN1] = 1; + p097_togglevalue[t] = 1; } - UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[CONFIG_PIN1]); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), p097_togglevalue[CONFIG_PIN1]); + UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), p097_togglevalue[t]); if (P097_SEND_TOUCH_EVENT) { eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); @@ -253,14 +250,14 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) bitSet(p097_pinTouchedPrev, t); } else { // Touch released - p097_touchstart[CONFIG_PIN1] = 0; + p097_touchstart[t] = 0; if (!P097_TYPE_TOGGLE) { UserVar.setFloat(event->TaskIndex, 1, 0); eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); } else { // set only the taskvalue back to previous state after long press release - if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[CONFIG_PIN1]); } + if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); } } if (P097_SEND_RELEASE_EVENT) { @@ -279,9 +276,9 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) } # endif // if defined(ESP32S2) || defined(ESP32S3) } + success = true; + break; } - success = true; - break; } case PLUGIN_READ: @@ -296,6 +293,7 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) break; } } + return success; } From b6222a3cd482bb3b5d04dcf243bb1d14175a85f5 Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:03:34 +0100 Subject: [PATCH 10/16] Update _P097_Esp32Touch.ino - make all touch pins available on s2/s3 --- src/_P097_Esp32Touch.ino | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index ae1a4a1769..3e1b988b62 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -318,14 +318,12 @@ void P097_setEventParams(int pin, uint16_t threshold) { case 8: touchAttachInterrupt(T8, P097_got_T8, threshold); break; case 9: touchAttachInterrupt(T9, P097_got_T9, threshold); break; # if HAS_T10_TO_T14 + case 10: touchAttachInterrupt(T10, P097_got_T10, threshold); break; + case 11: touchAttachInterrupt(T11, P097_got_T11, threshold); break; + case 12: touchAttachInterrupt(T12, P097_got_T12, threshold); break; + case 13: touchAttachInterrupt(T13, P097_got_T13, threshold); break; + case 14: touchAttachInterrupt(T14, P097_got_T14, threshold); break; - /* - case 10: touchAttachInterrupt(T10, P097_got_T10, threshold); break; - case 11: touchAttachInterrupt(T11, P097_got_T11, threshold); break; - case 12: touchAttachInterrupt(T12, P097_got_T12, threshold); break; - case 13: touchAttachInterrupt(T13, P097_got_T13, threshold); break; - case 14: touchAttachInterrupt(T14, P097_got_T14, threshold); break; - */ # endif // if HAS_T10_TO_T14 } } From be4938e9a13f1703bc3d946a6da1012d695c0a5c Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:21:43 +0100 Subject: [PATCH 11/16] Update _P097_Esp32Touch.ino - check if touchpad exists --- src/_P097_Esp32Touch.ino | 174 ++++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 86 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index 3e1b988b62..530e37b647 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -160,124 +160,126 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) int adc, ch, t; if (getADC_gpio_info(CONFIG_PIN1, adc, ch, t)) { - if (P097_SEND_LONG_PRESS_EVENT && - (p097_touchstart[t] >= 1) && - (timePassedSince(p097_touchstart[t]) >= P097_LONG_PRESS_TIME)) { - UserVar.setFloat(event->TaskIndex, 1, 10); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 10); - p097_touchstart[t] = 0; - } + if (t >= 0) { //check if there is a touch pad "t" since "getADC_gpio_info" returns true even if there is no touch pad + if (P097_SEND_LONG_PRESS_EVENT && + (p097_touchstart[t] >= 1) && + (timePassedSince(p097_touchstart[t]) >= P097_LONG_PRESS_TIME)) { + UserVar.setFloat(event->TaskIndex, 1, 10); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 10); + p097_touchstart[t] = 0; + } - if ((p097_pinTouched != 0) || (p097_pinTouchedPrev != 0)) { - // Some pin has been touched or released. - // Check if it is 'our' pin + if ((p097_pinTouched != 0) || (p097_pinTouchedPrev != 0)) { + // Some pin has been touched or released. + // Check if it is 'our' pin - const bool touched = bitRead(p097_pinTouched, t); + const bool touched = bitRead(p097_pinTouched, t); # ifdef ESP32_CLASSIC - const bool touched_prev = bitRead(p097_pinTouchedPrev, t); + const bool touched_prev = bitRead(p097_pinTouchedPrev, t); # endif // ifdef ESP32_CLASSIC # if defined(ESP32S2) || defined(ESP32S3) - if (touched) { - bitClear(p097_pinTouched, t); - UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); + if (touched) { + bitClear(p097_pinTouched, t); + UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); - if (touchInterruptGetLastStatus(CONFIG_PIN1)) { - if (p097_touchstart[t] == 0) { p097_touchstart[t] = millis(); } + if (touchInterruptGetLastStatus(CONFIG_PIN1)) { + if (p097_touchstart[t] == 0) { p097_touchstart[t] = millis(); } - if (P097_TYPE_TOGGLE) { - p097_togglevalue[t] = !UserVar.getInt32(event->TaskIndex, 1); - } else { - p097_togglevalue[t] = 1; - } - UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), p097_togglevalue[t]); + if (P097_TYPE_TOGGLE) { + p097_togglevalue[t] = !UserVar.getInt32(event->TaskIndex, 1); + } else { + p097_togglevalue[t] = 1; + } + UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), p097_togglevalue[t]); - if (P097_SEND_TOUCH_EVENT) { - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); - } - } else { // Touch released - p097_touchstart[t] = 0; - - if (!P097_TYPE_TOGGLE) { - UserVar.setFloat(event->TaskIndex, 1, 0); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); - } else { - // set only the taskvalue back to previous state after long press release - if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); } - } + if (P097_SEND_TOUCH_EVENT) { + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); + } + } else { // Touch released + p097_touchstart[t] = 0; + + if (!P097_TYPE_TOGGLE) { + UserVar.setFloat(event->TaskIndex, 1, 0); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); + } else { + // set only the taskvalue back to previous state after long press release + if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); } + } - if (P097_SEND_RELEASE_EVENT) { - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); - } + if (P097_SEND_RELEASE_EVENT) { + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); + } - if (P097_SEND_DURATION_EVENT) { - if (Settings.UseRules) { - eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t])); + if (P097_SEND_DURATION_EVENT) { + if (Settings.UseRules) { + eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t])); + } } - } - p097_timestamp[t] = 0; + p097_timestamp[t] = 0; + } } - } # else // if defined(ESP32S2) || defined(ESP32S3) - if (touched) { - bitClear(p097_pinTouched, t); - } + if (touched) { + bitClear(p097_pinTouched, t); + } - if (touched != touched_prev) { - // state changed - UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); + if (touched != touched_prev) { + // state changed + UserVar.setFloat(event->TaskIndex, 0, touchRead(CONFIG_PIN1)); - if (touched) { - if (p097_touchstart[t] == 0) { p097_touchstart[t] = millis(); } + if (touched) { + if (p097_touchstart[t] == 0) { p097_touchstart[t] = millis(); } - if (P097_TYPE_TOGGLE) { - p097_togglevalue[t] = !UserVar.getInt32(event->TaskIndex, 1); - } else { - p097_togglevalue[t] = 1; - } - UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), p097_togglevalue[t]); + if (P097_TYPE_TOGGLE) { + p097_togglevalue[t] = !UserVar.getInt32(event->TaskIndex, 1); + } else { + p097_togglevalue[t] = 1; + } + UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), p097_togglevalue[t]); - if (P097_SEND_TOUCH_EVENT) { - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); - } + if (P097_SEND_TOUCH_EVENT) { + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); + } - bitSet(p097_pinTouchedPrev, t); - } else { // Touch released - p097_touchstart[t] = 0; + bitSet(p097_pinTouchedPrev, t); + } else { // Touch released + p097_touchstart[t] = 0; - if (!P097_TYPE_TOGGLE) { - UserVar.setFloat(event->TaskIndex, 1, 0); - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); - } else { - // set only the taskvalue back to previous state after long press release - if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); } - } + if (!P097_TYPE_TOGGLE) { + UserVar.setFloat(event->TaskIndex, 1, 0); + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 1)), 0); + } else { + // set only the taskvalue back to previous state after long press release + if (P097_SEND_LONG_PRESS_EVENT) { UserVar.setFloat(event->TaskIndex, 1, p097_togglevalue[t]); } + } - if (P097_SEND_RELEASE_EVENT) { - eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); - } + if (P097_SEND_RELEASE_EVENT) { + eventQueue.add(event->TaskIndex, (getTaskValueName(event->TaskIndex, 0)), UserVar.getFloat(event->TaskIndex, 0)); + } - if (P097_SEND_DURATION_EVENT) { - if (Settings.UseRules) { - eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t])); + if (P097_SEND_DURATION_EVENT) { + if (Settings.UseRules) { + eventQueue.add(event->TaskIndex, F("Duration"), timePassedSince(p097_timestamp[t])); + } } - } - bitClear(p097_pinTouchedPrev, t); - p097_timestamp[t] = 0; + bitClear(p097_pinTouchedPrev, t); + p097_timestamp[t] = 0; + } } - } # endif // if defined(ESP32S2) || defined(ESP32S3) + } + success = true; + break; } - success = true; - break; } } From cc3f3ad91cfd5f26f5afd66e09ec9a2915d23876 Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:50:41 +0100 Subject: [PATCH 12/16] Update _P097_Esp32Touch.ino - reverting T10_to_T14 support --- src/_P097_Esp32Touch.ino | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index 530e37b647..d350c14cbf 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -15,7 +15,9 @@ # endif // ifdef ESP32_CLASSIC # if defined(ESP32S2) || defined(ESP32S3) # define HAS_T0_INPUT 0 - # define HAS_T10_TO_T14 1 + +// temporary disabled since T10 to T14 are causing problems + # define HAS_T10_TO_T14 0 # define LAST_TOUCH_INPUT_INDEX 14 # endif // if defined(ESP32S2) || defined(ESP32S3) @@ -104,6 +106,9 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) { addRowLabel(F("Analog Pin")); addADC_PinSelect(AdcPinSelectPurpose::TouchOnly, F("taskdevicepin1"), CONFIG_PIN1); + # if (defined(ESP32S2) || defined(ESP32S3)) && !HASS_T10_TO_T14 + addFormNote(F("For now touch pins T10 to T14 are not supported!")); + # endif // if (defined(ESP32S2) || defined(ESP32S3)) && !HASS_T10_TO_T14 addFormCheckBox(F("Toggle State"), F("typetoggle"), P097_TYPE_TOGGLE); addFormCheckBox(F("Wake Up from Sleep"), F("sleepwakeup"), P097_SLEEP_WAKEUP); @@ -160,7 +165,7 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) int adc, ch, t; if (getADC_gpio_info(CONFIG_PIN1, adc, ch, t)) { - if (t >= 0) { //check if there is a touch pad "t" since "getADC_gpio_info" returns true even if there is no touch pad + if (t >= 0) { // check if there is a touch pad "t" since "getADC_gpio_info" returns true even if there is no touch pad if (P097_SEND_LONG_PRESS_EVENT && (p097_touchstart[t] >= 1) && (timePassedSince(p097_touchstart[t]) >= P097_LONG_PRESS_TIME)) { From 0dc0e7333b6086da2421f35e70b4624a413c2e21 Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Thu, 28 Nov 2024 14:41:46 +0100 Subject: [PATCH 13/16] Update _P097_Esp32Touch.ino - type of threshold now dependent on model (uin32_t for s2 and s3) - max threshold value now also dependent on the type of esp --- src/_P097_Esp32Touch.ino | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index d350c14cbf..74cbedb014 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -12,13 +12,15 @@ # define HAS_T0_INPUT 1 # define HAS_T10_TO_T14 0 # define LAST_TOUCH_INPUT_INDEX 10 + # define P097_MAX_THRESHOLD_VALUE 4095 # endif // ifdef ESP32_CLASSIC # if defined(ESP32S2) || defined(ESP32S3) # define HAS_T0_INPUT 0 -// temporary disabled since T10 to T14 are causing problems +// temporary disabled since T10 to T14 are causing problems # define HAS_T10_TO_T14 0 # define LAST_TOUCH_INPUT_INDEX 14 + # define P097_MAX_THRESHOLD_VALUE 500000 // couldn't find a max value but threshold for ESP32S2 & ESP32S3 is uint32_t # endif // if defined(ESP32S2) || defined(ESP32S3) @@ -27,10 +29,10 @@ # define PLUGIN_NAME_097 "Touch (ESP32) - internal" # define PLUGIN_VALUENAME1_097 "Touch" # define PLUGIN_VALUENAME2_097 "State" -# define P097_MAX_ADC_VALUE 4095 # define P097_MAX_LONGPRESS_VALUE 10000 + # define P097_SEND_TOUCH_EVENT PCONFIG(0) # define P097_SEND_RELEASE_EVENT PCONFIG(1) # define P097_SEND_DURATION_EVENT PCONFIG(2) @@ -106,7 +108,7 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) { addRowLabel(F("Analog Pin")); addADC_PinSelect(AdcPinSelectPurpose::TouchOnly, F("taskdevicepin1"), CONFIG_PIN1); - # if (defined(ESP32S2) || defined(ESP32S3)) && !HASS_T10_TO_T14 + # if (defined(ESP32S2) || defined(ESP32S3)) && !HAS_T10_TO_T14 addFormNote(F("For now touch pins T10 to T14 are not supported!")); # endif // if (defined(ESP32S2) || defined(ESP32S3)) && !HASS_T10_TO_T14 @@ -124,7 +126,7 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) addFormCheckBox(F("Send Touch Event"), F("sendtouch"), P097_SEND_TOUCH_EVENT); addFormCheckBox(F("Send Release Event"), F("sendrelease"), P097_SEND_RELEASE_EVENT); addFormCheckBox(F("Send Duration Event"), F("sendduration"), P097_SEND_DURATION_EVENT); - addFormNumericBox(F("Touch Threshold"), F("threshold"), P097_TOUCH_THRESHOLD, 0, P097_MAX_ADC_VALUE); + addFormNumericBox(F("Touch Threshold"), F("threshold"), P097_TOUCH_THRESHOLD, 0, P097_MAX_THRESHOLD_VALUE); // Show current value addRowLabel(F("Current Pressure")); @@ -177,7 +179,6 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) if ((p097_pinTouched != 0) || (p097_pinTouchedPrev != 0)) { // Some pin has been touched or released. - // Check if it is 'our' pin const bool touched = bitRead(p097_pinTouched, t); # ifdef ESP32_CLASSIC @@ -307,7 +308,7 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) /********************************************************************************** * Touch pin callback functions **********************************************************************************/ -void P097_setEventParams(int pin, uint16_t threshold) { +void P097_setEventParams(int pin, touch_value_t threshold) { int adc, ch, t; if (getADC_gpio_info(pin, adc, ch, t)) { From 8eab511786148cdab1ea9618750ced61f173691e Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Sun, 1 Dec 2024 15:50:58 +0100 Subject: [PATCH 14/16] Update _P097_Esp32Touch.ino - Hopefully fixed compile errors for non-touch ESP32 variants by standardizing the use of uint32_t for the threshold parameter on ESP32 Classic. The value remains limited by P097_MAX_THRESHOLD_VALUE to 4095. --- src/_P097_Esp32Touch.ino | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index 74cbedb014..8de1c5ef56 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -1,4 +1,5 @@ #include "_Plugin_Helper.h" + #ifdef USES_P097 // ####################################################################################################### @@ -8,21 +9,20 @@ # if defined(ESP32) && !defined(ESP32C2) && !defined(ESP32C3) && !defined(ESP32C6) -# ifdef ESP32_CLASSIC - # define HAS_T0_INPUT 1 - # define HAS_T10_TO_T14 0 - # define LAST_TOUCH_INPUT_INDEX 10 - # define P097_MAX_THRESHOLD_VALUE 4095 -# endif // ifdef ESP32_CLASSIC -# if defined(ESP32S2) || defined(ESP32S3) - # define HAS_T0_INPUT 0 - -// temporary disabled since T10 to T14 are causing problems - # define HAS_T10_TO_T14 0 - # define LAST_TOUCH_INPUT_INDEX 14 - # define P097_MAX_THRESHOLD_VALUE 500000 // couldn't find a max value but threshold for ESP32S2 & ESP32S3 is uint32_t -# endif // if defined(ESP32S2) || defined(ESP32S3) - +// Device-specific configuration +# if defined(ESP32_CLASSIC) + # define HAS_T0_INPUT 1 + # define HAS_T10_TO_T14 0 + # define LAST_TOUCH_INPUT_INDEX 10 + # define P097_MAX_THRESHOLD_VALUE 4095 +# elif defined(ESP32S2) || defined(ESP32S3) + # define HAS_T0_INPUT 0 + +// Temporary disabled since T10 to T14 are causing problems + # define HAS_T10_TO_T14 0 + # define LAST_TOUCH_INPUT_INDEX 14 + # define P097_MAX_THRESHOLD_VALUE 500000 // couldn't find a max value but threshold for ESP32S2 & ESP32S3 is uint32_t +# endif // if defined(ESP32_CLASSIC) # define PLUGIN_097 # define PLUGIN_ID_097 97 @@ -32,7 +32,6 @@ # define P097_MAX_LONGPRESS_VALUE 10000 - # define P097_SEND_TOUCH_EVENT PCONFIG(0) # define P097_SEND_RELEASE_EVENT PCONFIG(1) # define P097_SEND_DURATION_EVENT PCONFIG(2) @@ -308,7 +307,7 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) /********************************************************************************** * Touch pin callback functions **********************************************************************************/ -void P097_setEventParams(int pin, touch_value_t threshold) { +void P097_setEventParams(int pin, uint32_t threshold) { int adc, ch, t; if (getADC_gpio_info(pin, adc, ch, t)) { From dab591f936050520c225eefe751ef56057ed2f6d Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:01:26 +0100 Subject: [PATCH 15/16] Udated code + added documentation code: - changed order of device settings - added changelog --- docs/source/Plugin/P097.rst | 54 +++++++++++++++++++++++++---- docs/source/Plugin/P097_events.repl | 23 ++++++++++-- src/_P097_Esp32Touch.ino | 15 ++++---- 3 files changed, 77 insertions(+), 15 deletions(-) diff --git a/docs/source/Plugin/P097.rst b/docs/source/Plugin/P097.rst index 4cc3c4caf6..44f4b420cf 100644 --- a/docs/source/Plugin/P097.rst +++ b/docs/source/Plugin/P097.rst @@ -24,21 +24,58 @@ Used libraries: |P097_usedlibraries| Description ----------- -Touch pin support for ESP32. +Touch pin support for ESP32 based devices. (EPS32Classic, ESP32S2, ESP32S3) + +The ESP32Classic does have support for 10 touch pads and ESP32S2 and ESP32S3 have support for 14 touch pads. + +.. note:: For ESP32S2 and ESP32S3, the touchpad support from ``T10`` to ``T14`` has been disabled due to stability issues. -The ESP32 does have support for 10 touch pads. Such a touch pad can be as simple as a wire or a PCB pad connected to one of the GPIO pins labelled with ``T0`` ... ``T9``. -A touch pad pin can be considered as an analog input pin. -When not touched, the reported value is "High", for example 100. +A touch pad pin can be considered as an analog input pin. +If the pin is not touched, it will report a relatively high value on an ESP32Classic (e.g. 100) and a relatively low value on an ESP32S2 or ESP32S3 (e.g. 15000) compared to the value when the pin is touched. +This value is displayed in the settings of the touch plugin ("current pressue") and is reported as the first taskvalue (default name is "touch") whenever the pin is touched or released. + + +Task settings +~~~~~~~~~~~~~ + +* **Device**: Name of plugin +* **Name**: Name of the task +* **Enable**: Should the task be enabled or not + +Device Settings +^^^^^^^^^^^^^^^ +* **Analog Pin**: Choose the pin to be used +* **Toggle State**: When the pin is touched, the value of the second taskvalue (default: "state") toggles between 0 and 1. +* **Send Long Press Event**: A long press event is sent when the pin is pressed for longer than the time specified in the Long Press Time setting. The second taskvalue becomes 10 +* **Long Press Time:**: The time that you need to press the button before the long press event is triggered. +* **Wake Up from Sleep**: The device will wake up from sleep when the pin is touched. + +Touch Settings +^^^^^^^^^^^^^^ +* **Send Touch Event:**: An event is sent when the pin is touched +* **Send Release Event**: An event is sent when the pin is released +* **Send Duration Event**: After release, the duration of the touch is sent as an event +* **Touch Threshold**: see Threshold section... +* **Current Pressure**: The current pressure is the same as the first taskvalue. + +Threshold: +~~~~~~~~~~ +**ESP32Classic**: When touched, the capacity of the pin increases, which in return lowers the number of charge/discharge cycles. -A typical value for a touched pin is lower than 20. +A typical value for a touched pin is lower than 20 (compared to the initial threshold value). +A touch event occures when the touch value is lower then the "base value" minus the threshold value. -The user has to set a threshold value for when to consider a pin being touched. -The best value has to be determined by trial and error and may differ per use case. +**ESP32S2** and **ESP32S3**: +When touched, the threshold value increases. +A typical value for a touched pin is higher than 1500 (compared to the initial threshold value). +A touch event occures when the touch value is greater then the "base value" plus the threshold value. + +The best value has to be determined by trial and error and may differ per use case. Events ~~~~~~ @@ -54,3 +91,6 @@ Change log ... |added| 2020-04-25 + + |improved| 2023/12/11 Added all settings, a distinction between ESP32 models and the event for . + \ No newline at end of file diff --git a/docs/source/Plugin/P097_events.repl b/docs/source/Plugin/P097_events.repl index eb5522b57d..6c5138a0e8 100644 --- a/docs/source/Plugin/P097_events.repl +++ b/docs/source/Plugin/P097_events.repl @@ -3,7 +3,7 @@ :widths: 30, 20 " - ``#`` + ``#`` The regular events like in every other task. Only difference here is that you may have an event either when the touch pad is touched, released or both. "," @@ -11,7 +11,7 @@ .. code-block:: none on touch#Touch do - GPIO,2,1 //LED on + LogEntry,'Touch value %eventvalue%' endon " @@ -39,3 +39,22 @@ 6553655 : Info : Touch Duration 460 ms " + " + ``#`` + + An event is sent every time the state of changes. + + The state can be either **0** for released, **1** for touched and **10** for long press. + "," + + .. code-block:: none + + on touch#State do + if %eventvalue% != 10 + GPIO,2,%eventvalue% //LED on or off + else + GPIO,3,1 // on longpress turn on another LED + endif + endon + + " diff --git a/src/_P097_Esp32Touch.ino b/src/_P097_Esp32Touch.ino index 8de1c5ef56..13c120400b 100644 --- a/src/_P097_Esp32Touch.ino +++ b/src/_P097_Esp32Touch.ino @@ -1,11 +1,15 @@ #include "_Plugin_Helper.h" - #ifdef USES_P097 // ####################################################################################################### // #################################### Plugin 097: ESP32 Touch ########################################## // ####################################################################################################### +/** Changelog: + * 2024-12-11 chromoxdor: Added extra routine for ESP32S2 and ESP32S3. + * Added "Wake Up from Sleep", Switch like behaviour + toggle and long press option. + */ + # if defined(ESP32) && !defined(ESP32C2) && !defined(ESP32C3) && !defined(ESP32C6) @@ -31,7 +35,6 @@ # define PLUGIN_VALUENAME2_097 "State" # define P097_MAX_LONGPRESS_VALUE 10000 - # define P097_SEND_TOUCH_EVENT PCONFIG(0) # define P097_SEND_RELEASE_EVENT PCONFIG(1) # define P097_SEND_DURATION_EVENT PCONFIG(2) @@ -111,14 +114,14 @@ boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string) addFormNote(F("For now touch pins T10 to T14 are not supported!")); # endif // if (defined(ESP32S2) || defined(ESP32S3)) && !HASS_T10_TO_T14 - addFormCheckBox(F("Toggle State"), F("typetoggle"), P097_TYPE_TOGGLE); + addFormCheckBox(F("Toggle State"), F("typetoggle"), P097_TYPE_TOGGLE); + addFormCheckBox(F("Send Long Press Event"), F("sendlongpress"), P097_SEND_LONG_PRESS_EVENT); + addFormNumericBox(F("Long Press Time"), F("longpress"), P097_LONG_PRESS_TIME, 500, P097_MAX_LONGPRESS_VALUE); + addUnit(F("500..10000 msec.")); addFormCheckBox(F("Wake Up from Sleep"), F("sleepwakeup"), P097_SLEEP_WAKEUP); # if defined(ESP32S2) || defined(ESP32S3) addFormNote(F("Wake up from sleep is only supported on one touch pin!")); # endif // if defined(ESP32S2) || defined(ESP32S3) - addFormCheckBox(F("Send Long Press Event"), F("sendlongpress"), P097_SEND_LONG_PRESS_EVENT); - addFormNumericBox(F("Long Press Time"), F("longpress"), P097_LONG_PRESS_TIME, 500, P097_MAX_LONGPRESS_VALUE); - addUnit(F("500..10000 msec.")); addFormSubHeader(F("Touch Settings")); From 41c5c8ccc24c0f24b9c8e1eae4c2cff577e79ad0 Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:06:59 +0100 Subject: [PATCH 16/16] Update P097.rst I am lagging one year behind :) --- docs/source/Plugin/P097.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/Plugin/P097.rst b/docs/source/Plugin/P097.rst index 44f4b420cf..cd6fd0dba5 100644 --- a/docs/source/Plugin/P097.rst +++ b/docs/source/Plugin/P097.rst @@ -92,5 +92,5 @@ Change log |added| 2020-04-25 - |improved| 2023/12/11 Added all settings, a distinction between ESP32 models and the event for . + |improved| 2024/12/11 Added all settings, a distinction between ESP32 models and the event for . \ No newline at end of file