From a42c4688b6cd3ce5ea47e15756d53c7614afb247 Mon Sep 17 00:00:00 2001 From: "Felix A. Epp" Date: Tue, 14 Jul 2020 02:25:00 +0300 Subject: [PATCH 1/9] Add ADC filter to remove jitters on touchRead --- src/EasyButtonTouch.cpp | 5 +++-- src/EasyButtonTouch.h | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/EasyButtonTouch.cpp b/src/EasyButtonTouch.cpp index 68090b8..f77305b 100644 --- a/src/EasyButtonTouch.cpp +++ b/src/EasyButtonTouch.cpp @@ -1,6 +1,6 @@ /** * EasyButtonTouch.cpp - * @author Evert Arias, Gutierrez PS + * @author Evert Arias, Gutierrez PS, Felix A. Epp * @version 2.0.0 * @license MIT */ @@ -19,7 +19,8 @@ void EasyButtonTouch::begin() bool EasyButtonTouch::_readPin() { - return touchRead(_pin) < _touch_threshold; + ADCFilter.Filter(touchRead(_pin)); + return ADCFilter.Current() < _touch_threshold; } #endif \ No newline at end of file diff --git a/src/EasyButtonTouch.h b/src/EasyButtonTouch.h index 188da54..ae6a378 100644 --- a/src/EasyButtonTouch.h +++ b/src/EasyButtonTouch.h @@ -1,6 +1,6 @@ /** * EasyButtonTouch.h - * @author Evert Arias, Gutierrez PS + * @author Evert Arias, Gutierrez PS, Felix A. Epp * @version 2.0.0 * @license MIT */ @@ -9,16 +9,18 @@ #define _EasyButtonTouch_h #include +#include #include "EasyButton.h" class EasyButtonTouch : public EasyButton { public: - EasyButtonTouch(uint8_t pin, uint32_t debounce_time = 35, uint16_t threshold = 50) : EasyButton(pin, debounce_time, false, false), _touch_threshold(threshold) {} + EasyButtonTouch(uint8_t pin, uint32_t debounce_time = 35, uint16_t threshold = 50) : EasyButton(pin, debounce_time, false, false), _touch_threshold(threshold), ADCFilter(5, threshold) {} void begin(); private: uint16_t _touch_threshold; // If touchRead() is below the threshold, the button is considered pressed. + ExponentialFilter ADCFilter; bool _readPin(); }; From f5388894ace5c842407de6f915810ee25988aa38 Mon Sep 17 00:00:00 2001 From: "Felix A. Epp" Date: Wed, 9 Dec 2020 16:41:31 +0200 Subject: [PATCH 2/9] Add functions to change touch threshold after init --- src/EasyButtonTouch.cpp | 11 +++++++++++ src/EasyButtonTouch.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/EasyButtonTouch.cpp b/src/EasyButtonTouch.cpp index f77305b..8cf68cf 100644 --- a/src/EasyButtonTouch.cpp +++ b/src/EasyButtonTouch.cpp @@ -8,6 +8,17 @@ #if defined(ESP32) #include "EasyButtonTouch.h" +void EasyButtonTouch::setThreshold(int threshold) +{ + _touch_threshold = threshold; +} + +void EasyButtonTouch::begin(int threshold) +{ + _touch_threshold = threshold; + begin(); +} + void EasyButtonTouch::begin() { _current_state = _readPin(); diff --git a/src/EasyButtonTouch.h b/src/EasyButtonTouch.h index ae6a378..dc8e48d 100644 --- a/src/EasyButtonTouch.h +++ b/src/EasyButtonTouch.h @@ -17,6 +17,8 @@ class EasyButtonTouch : public EasyButton public: EasyButtonTouch(uint8_t pin, uint32_t debounce_time = 35, uint16_t threshold = 50) : EasyButton(pin, debounce_time, false, false), _touch_threshold(threshold), ADCFilter(5, threshold) {} void begin(); + void begin(int threshold); + void setThreshold(int threshold); private: uint16_t _touch_threshold; // If touchRead() is below the threshold, the button is considered pressed. From e305f1c645d64b192336e71ec374a727b05e3fe4 Mon Sep 17 00:00:00 2001 From: "Felix A. Epp" Date: Mon, 10 May 2021 17:49:05 +0300 Subject: [PATCH 3/9] Added dependency for platformio --- platformio.ini | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 platformio.ini diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..52cab9b --- /dev/null +++ b/platformio.ini @@ -0,0 +1,5 @@ +# platformio.ini – project configuration file +[env] +framework = arduino +lib_deps = + megunolink/MegunoLink @ ^1.33 \ No newline at end of file From ecfaa6835248a582ba05fad361afff247071676b Mon Sep 17 00:00:00 2001 From: "Felix A. Epp" Date: Mon, 10 May 2021 18:36:23 +0300 Subject: [PATCH 4/9] Add library property files --- library.json | 27 +++++++++++++++++++++++++++ library.properties | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 library.json diff --git a/library.json b/library.json new file mode 100644 index 0000000..21fb163 --- /dev/null +++ b/library.json @@ -0,0 +1,27 @@ +{ + "name": "EasyButton", + "keywords": "IO, button, sensor, arduino", + "description": "EasyButton is an small Arduino library for debouncing momentary contact switches like tactile buttons. It uses events and callbacks to trigger actions when a button is pressed once or held for a given duration. It also provides a sequence counter to be able to rise an event when a given pattern of presses has been matched.", + "version": "2.0.1", + "repository": { + "type": "git", + "url": "https://github.com/evert-arias/EasyButton" + }, + "url": "https://easybtn.earias.me", + "frameworks": "arduino", + "platforms": "espressif8266, espressif32", + "dependencies": [ + { "megunolink/MegunoLink": "^1.33"} + ], + "authors": [ + { + "name": "Evert Arias", + "email": "evert.arias@hotmail.com" + }, + { + "name": "Felix A. Epp", + "url": "https://github.com/eppfel" + } + ] +} + diff --git a/library.properties b/library.properties index 66d69e0..c86c327 100644 --- a/library.properties +++ b/library.properties @@ -6,4 +6,5 @@ sentence=Arduino library for debouncing momentary contact switches, detect press paragraph=EasyButton is an small Arduino library for debouncing momentary contact switches like tactile buttons. It uses events and callbacks to trigger actions when a button is pressed once or held for a given duration. It also provides a sequence counter to be able to rise an event when a given pattern of presses has been matched. category=Signal Input/Output url=https://easybtn.earias.me -architectures=* \ No newline at end of file +architectures=* +depends=MegunoLink \ No newline at end of file From 047fd17ee4bc9ebf1f0f9b3f20619e75fefa11b8 Mon Sep 17 00:00:00 2001 From: "Felix A. Epp" Date: Mon, 10 May 2021 20:00:49 +0300 Subject: [PATCH 5/9] Add compatibility to older pio versions --- library.json | 53 ++++++++++++++++++++++++++------------------------ platformio.ini | 5 ----- 2 files changed, 28 insertions(+), 30 deletions(-) delete mode 100644 platformio.ini diff --git a/library.json b/library.json index 21fb163..d78d3f0 100644 --- a/library.json +++ b/library.json @@ -1,27 +1,30 @@ { - "name": "EasyButton", - "keywords": "IO, button, sensor, arduino", - "description": "EasyButton is an small Arduino library for debouncing momentary contact switches like tactile buttons. It uses events and callbacks to trigger actions when a button is pressed once or held for a given duration. It also provides a sequence counter to be able to rise an event when a given pattern of presses has been matched.", - "version": "2.0.1", - "repository": { - "type": "git", - "url": "https://github.com/evert-arias/EasyButton" + "name": "EasyButton", + "keywords": "IO, button, sensor, arduino", + "description": "EasyButton is an small Arduino library for debouncing momentary contact switches like tactile buttons. It uses events and callbacks to trigger actions when a button is pressed once or held for a given duration. It also provides a sequence counter to be able to rise an event when a given pattern of presses has been matched.", + "version": "2.0.1", + "repository": { + "type": "git", + "url": "https://github.com/evert-arias/EasyButton" + }, + "url": "https://easybtn.earias.me", + "frameworks": "arduino", + "platforms": "espressif8266, espressif32", + "dependencies": [ + { + "owner": "megunolink", + "name": "MegunoLink", + "version": "^1.33" + } + ], + "authors": [ + { + "name": "Evert Arias", + "email": "evert.arias@hotmail.com" }, - "url": "https://easybtn.earias.me", - "frameworks": "arduino", - "platforms": "espressif8266, espressif32", - "dependencies": [ - { "megunolink/MegunoLink": "^1.33"} - ], - "authors": [ - { - "name": "Evert Arias", - "email": "evert.arias@hotmail.com" - }, - { - "name": "Felix A. Epp", - "url": "https://github.com/eppfel" - } - ] -} - + { + "name": "Felix A. Epp", + "url": "https://github.com/eppfel" + } + ] +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini deleted file mode 100644 index 52cab9b..0000000 --- a/platformio.ini +++ /dev/null @@ -1,5 +0,0 @@ -# platformio.ini – project configuration file -[env] -framework = arduino -lib_deps = - megunolink/MegunoLink @ ^1.33 \ No newline at end of file From 212387841300a45b59d460cad2d8bb4e37845366 Mon Sep 17 00:00:00 2001 From: Nick Reynolds Date: Wed, 26 Apr 2023 11:05:00 +0100 Subject: [PATCH 6/9] Conditional inclusion of touch features Ensure touch features are only included on ESP32 variants that supports touch. Relies on include/soc/soc_caps.h in recent versions of the IDF --- src/EasyButtonTouch.cpp | 3 ++- src/EasyButtonTouch.h | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/EasyButtonTouch.cpp b/src/EasyButtonTouch.cpp index 8cf68cf..8843855 100644 --- a/src/EasyButtonTouch.cpp +++ b/src/EasyButtonTouch.cpp @@ -7,6 +7,7 @@ #if defined(ESP32) #include "EasyButtonTouch.h" +#if defined(SOC_TOUCH_SENSOR_SUPPORTED) void EasyButtonTouch::setThreshold(int threshold) { @@ -33,5 +34,5 @@ bool EasyButtonTouch::_readPin() ADCFilter.Filter(touchRead(_pin)); return ADCFilter.Current() < _touch_threshold; } - +#endif #endif \ No newline at end of file diff --git a/src/EasyButtonTouch.h b/src/EasyButtonTouch.h index dc8e48d..7de0b0b 100644 --- a/src/EasyButtonTouch.h +++ b/src/EasyButtonTouch.h @@ -7,6 +7,8 @@ #if !defined(_EasyButtonTouch_h) and defined(ESP32) #define _EasyButtonTouch_h +#include +#if defined(SOC_TOUCH_SENSOR_SUPPORTED) #include #include @@ -26,5 +28,5 @@ class EasyButtonTouch : public EasyButton bool _readPin(); }; - +#endif #endif \ No newline at end of file From f118f0eec0c930f4ef5309bca9b4e1bcf38bb7fd Mon Sep 17 00:00:00 2001 From: Nick Reynolds Date: Wed, 26 Apr 2023 11:58:25 +0100 Subject: [PATCH 7/9] Better detection of touch feature Add secondary way of detecting if touch is enabled, using the 'number of touch sensors'. --- src/EasyButtonTouch.cpp | 2 +- src/EasyButtonTouch.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EasyButtonTouch.cpp b/src/EasyButtonTouch.cpp index 8843855..ecf4a7b 100644 --- a/src/EasyButtonTouch.cpp +++ b/src/EasyButtonTouch.cpp @@ -7,7 +7,7 @@ #if defined(ESP32) #include "EasyButtonTouch.h" -#if defined(SOC_TOUCH_SENSOR_SUPPORTED) +#if defined(SOC_TOUCH_SENSOR_SUPPORTED) || (defined(SOC_TOUCH_SENSOR_NUM) && SOC_TOUCH_SENSOR_NUM > 1) void EasyButtonTouch::setThreshold(int threshold) { diff --git a/src/EasyButtonTouch.h b/src/EasyButtonTouch.h index 7de0b0b..88aef5a 100644 --- a/src/EasyButtonTouch.h +++ b/src/EasyButtonTouch.h @@ -8,7 +8,7 @@ #if !defined(_EasyButtonTouch_h) and defined(ESP32) #define _EasyButtonTouch_h #include -#if defined(SOC_TOUCH_SENSOR_SUPPORTED) +#if defined(SOC_TOUCH_SENSOR_SUPPORTED) || (defined(SOC_TOUCH_SENSOR_NUM) && SOC_TOUCH_SENSOR_NUM > 1) #include #include From 852351a1c1510b3e70f0712cde26385743fd9e15 Mon Sep 17 00:00:00 2001 From: webmonkey Date: Sun, 21 May 2023 23:44:21 +0100 Subject: [PATCH 8/9] Bump version number in library.properties fixes #79 --- library.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index c86c327..8954708 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=EasyButton -version=2.0.1 +version=2.0.2 author=Evert Arias maintainer=Evert Arias sentence=Arduino library for debouncing momentary contact switches, detect press, release, long press and sequences with event definitions and callbacks. @@ -7,4 +7,4 @@ paragraph=EasyButton is an small Arduino library for debouncing momentary contac category=Signal Input/Output url=https://easybtn.earias.me architectures=* -depends=MegunoLink \ No newline at end of file +depends=MegunoLink From 0fbf97716b06e69158a1d0f4716aa34bf03990df Mon Sep 17 00:00:00 2001 From: Evert Arias Date: Tue, 4 Jul 2023 11:36:22 -0400 Subject: [PATCH 9/9] Increment version --- library.json | 2 +- library.properties | 2 +- src/EasyButton.cpp | 2 +- src/EasyButton.h | 2 +- src/EasyButtonBase.cpp | 2 +- src/EasyButtonBase.h | 2 +- src/EasyButtonTouch.cpp | 2 +- src/EasyButtonTouch.h | 2 +- src/EasyButtonVirtual.cpp | 2 +- src/EasyButtonVirtual.h | 2 +- src/Sequence.cpp | 2 +- src/Sequence.h | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/library.json b/library.json index d78d3f0..732c7d7 100644 --- a/library.json +++ b/library.json @@ -2,7 +2,7 @@ "name": "EasyButton", "keywords": "IO, button, sensor, arduino", "description": "EasyButton is an small Arduino library for debouncing momentary contact switches like tactile buttons. It uses events and callbacks to trigger actions when a button is pressed once or held for a given duration. It also provides a sequence counter to be able to rise an event when a given pattern of presses has been matched.", - "version": "2.0.1", + "version": "2.0.3", "repository": { "type": "git", "url": "https://github.com/evert-arias/EasyButton" diff --git a/library.properties b/library.properties index 8954708..309945c 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=EasyButton -version=2.0.2 +version=2.0.3 author=Evert Arias maintainer=Evert Arias sentence=Arduino library for debouncing momentary contact switches, detect press, release, long press and sequences with event definitions and callbacks. diff --git a/src/EasyButton.cpp b/src/EasyButton.cpp index eef4384..2201144 100644 --- a/src/EasyButton.cpp +++ b/src/EasyButton.cpp @@ -1,7 +1,7 @@ /** * EasyButton.cpp * @author Evert Arias - * @version 2.0.0 + * @version 2.0.3 * @license MIT */ diff --git a/src/EasyButton.h b/src/EasyButton.h index f04fba7..6bfac87 100644 --- a/src/EasyButton.h +++ b/src/EasyButton.h @@ -1,7 +1,7 @@ /** * EasyButton.h * @author Evert Arias - * @version 2.0.0 + * @version 2.0.3 * @license MIT */ diff --git a/src/EasyButtonBase.cpp b/src/EasyButtonBase.cpp index f50ce76..c508eea 100644 --- a/src/EasyButtonBase.cpp +++ b/src/EasyButtonBase.cpp @@ -1,7 +1,7 @@ /** * EasyButtonBase.h * @author Evert Arias - * @version 2.0.0 + * @version 2.0.3 * @license MIT */ diff --git a/src/EasyButtonBase.h b/src/EasyButtonBase.h index 33a875a..6f6526b 100644 --- a/src/EasyButtonBase.h +++ b/src/EasyButtonBase.h @@ -1,7 +1,7 @@ /** * EasyButtonBase.h * @author Evert Arias - * @version 2.0.0 + * @version 2.0.3 * @license MIT */ diff --git a/src/EasyButtonTouch.cpp b/src/EasyButtonTouch.cpp index ecf4a7b..0cf9665 100644 --- a/src/EasyButtonTouch.cpp +++ b/src/EasyButtonTouch.cpp @@ -1,7 +1,7 @@ /** * EasyButtonTouch.cpp * @author Evert Arias, Gutierrez PS, Felix A. Epp - * @version 2.0.0 + * @version 2.0.3 * @license MIT */ diff --git a/src/EasyButtonTouch.h b/src/EasyButtonTouch.h index 88aef5a..b31c929 100644 --- a/src/EasyButtonTouch.h +++ b/src/EasyButtonTouch.h @@ -1,7 +1,7 @@ /** * EasyButtonTouch.h * @author Evert Arias, Gutierrez PS, Felix A. Epp - * @version 2.0.0 + * @version 2.0.3 * @license MIT */ diff --git a/src/EasyButtonVirtual.cpp b/src/EasyButtonVirtual.cpp index dc87e56..b0d57d2 100644 --- a/src/EasyButtonVirtual.cpp +++ b/src/EasyButtonVirtual.cpp @@ -1,7 +1,7 @@ /** * EasyButtonVirtual.h * @author Evert Arias, Jose Gabriel Companioni Benitez - * @version 2.0.0 + * @version 2.0.3 * @license MIT */ diff --git a/src/EasyButtonVirtual.h b/src/EasyButtonVirtual.h index 65ba4b4..4add431 100644 --- a/src/EasyButtonVirtual.h +++ b/src/EasyButtonVirtual.h @@ -1,7 +1,7 @@ /** * EasyButtonVirtual.h * @author Evert Arias, Jose Gabriel Companioni Benitez - * @version 2.0.0 + * @version 2.0.3 * @license MIT */ diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 68a7b9f..ab91393 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -1,7 +1,7 @@ /** * Sequence.h * @author Evert Arias, Jose Gabriel Companioni Benitez - * @version 2.0.0 + * @version 2.0.3 * @license MIT */ diff --git a/src/Sequence.h b/src/Sequence.h index bdfe392..27c3723 100644 --- a/src/Sequence.h +++ b/src/Sequence.h @@ -1,7 +1,7 @@ /** * Sequence.h * @author Evert Arias, Jose Gabriel Companioni Benitez - * @version 2.0.0 + * @version 2.0.3 * @license MIT */