From 0535fcee5e0d4e55ae84aacf75c364fcfcfea373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Sun, 23 Jul 2017 17:17:48 +0200 Subject: [PATCH] Issue #170. Using updated DebounceEvent library to allow disabling double click option and get faster click responses --- code/espurna/button.ino | 12 ++++++------ code/espurna/config/general.h | 6 ++++-- code/platformio.ini | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/code/espurna/button.ino b/code/espurna/button.ino index 439ab31c..47c46739 100644 --- a/code/espurna/button.ino +++ b/code/espurna/button.ino @@ -68,8 +68,8 @@ uint8_t mapEvent(uint8_t event, uint8_t count, uint16_t length) { if (event == EVENT_CHANGED) return BUTTON_EVENT_CLICK; if (event == EVENT_RELEASED) { if (count == 1) { - if (length > BUTTON_LNGLNGCLICK_LENGTH) return BUTTON_EVENT_LNGLNGCLICK; - if (length > BUTTON_LNGCLICK_LENGTH) return BUTTON_EVENT_LNGCLICK; + if (length > BUTTON_LNGLNGCLICK_DELAY) return BUTTON_EVENT_LNGLNGCLICK; + if (length > BUTTON_LNGCLICK_DELAY) return BUTTON_EVENT_LNGCLICK; return BUTTON_EVENT_CLICK; } if (count == 2) return BUTTON_EVENT_DBLCLICK; @@ -121,25 +121,25 @@ void buttonSetup() { #ifdef BUTTON1_PIN { unsigned int actions = buttonStore(BUTTON1_PRESS, BUTTON1_CLICK, BUTTON1_DBLCLICK, BUTTON1_LNGCLICK, BUTTON1_LNGLNGCLICK); - _buttons.push_back({new DebounceEvent(BUTTON1_PIN, BUTTON1_MODE), actions, BUTTON1_RELAY}); + _buttons.push_back({new DebounceEvent(BUTTON1_PIN, BUTTON1_MODE, BUTTON_DEBOUNCE_DELAY, BUTTON_DBLCLICK_DELAY), actions, BUTTON1_RELAY}); } #endif #ifdef BUTTON2_PIN { unsigned int actions = buttonStore(BUTTON2_PRESS, BUTTON2_CLICK, BUTTON2_DBLCLICK, BUTTON2_LNGCLICK, BUTTON2_LNGLNGCLICK); - _buttons.push_back({new DebounceEvent(BUTTON2_PIN, BUTTON2_MODE), actions, BUTTON2_RELAY}); + _buttons.push_back({new DebounceEvent(BUTTON2_PIN, BUTTON2_MODE, BUTTON_DEBOUNCE_DELAY, BUTTON_DBLCLICK_DELAY), actions, BUTTON2_RELAY}); } #endif #ifdef BUTTON3_PIN { unsigned int actions = buttonStore(BUTTON3_PRESS, BUTTON3_CLICK, BUTTON3_DBLCLICK, BUTTON3_LNGCLICK, BUTTON3_LNGLNGCLICK); - _buttons.push_back({new DebounceEvent(BUTTON3_PIN, BUTTON3_MODE), actions, BUTTON3_RELAY}); + _buttons.push_back({new DebounceEvent(BUTTON3_PIN, BUTTON3_MODE, BUTTON_DEBOUNCE_DELAY, BUTTON_DBLCLICK_DELAY), actions, BUTTON3_RELAY}); } #endif #ifdef BUTTON4_PIN { unsigned int actions = buttonStore(BUTTON4_PRESS, BUTTON4_CLICK, BUTTON4_DBLCLICK, BUTTON4_LNGCLICK, BUTTON4_LNGLNGCLICK); - _buttons.push_back({new DebounceEvent(BUTTON4_PIN, BUTTON4_MODE), actions, BUTTON4_RELAY}); + _buttons.push_back({new DebounceEvent(BUTTON4_PIN, BUTTON4_MODE, BUTTON_DEBOUNCE_DELAY, BUTTON_DBLCLICK_DELAY), actions, BUTTON4_RELAY}); } #endif diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 432c1e51..3ca10245 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -69,8 +69,10 @@ PROGMEM const char* const custom_reset_string[] = { // BUTTON //-------------------------------------------------------------------------------- -#define BUTTON_LNGCLICK_LENGTH 1000 -#define BUTTON_LNGLNGCLICK_LENGTH 10000 +#define BUTTON_DEBOUNCE_DELAY 50 +#define BUTTON_DBLCLICK_DELAY 500 +#define BUTTON_LNGCLICK_DELAY 1000 +#define BUTTON_LNGLNGCLICK_DELAY 10000 #define BUTTON_EVENT_NONE 0 #define BUTTON_EVENT_PRESSED 1 diff --git a/code/platformio.ini b/code/platformio.ini index 53322d05..154aa6d0 100644 --- a/code/platformio.ini +++ b/code/platformio.ini @@ -26,7 +26,7 @@ lib_deps = https://bitbucket.org/xoseperez/fauxmoesp.git#2.1.0 https://bitbucket.org/xoseperez/nofuss.git#0.2.2 https://bitbucket.org/xoseperez/emonliteesp.git#0.1.2 - https://bitbucket.org/xoseperez/debounceevent.git#2.0.0 + https://bitbucket.org/xoseperez/debounceevent.git#2.0.1 https://github.com/xoseperez/my9291#1.0.0 https://github.com/xoseperez/RemoteSwitch-arduino-library.git lib_ignore =