From 17dfb7d15225b2ccbd77e4f19da4ddebc2b428e6 Mon Sep 17 00:00:00 2001 From: Erik R Norell Date: Fri, 7 Jan 2022 09:57:29 +0300 Subject: [PATCH] Touch on T-Echo to refresh e-ink screen --- src/configuration.h | 4 ++++ src/main.cpp | 49 +++++++++++++++++++++++++++++++++++++++ variants/t-echo/variant.h | 1 + 3 files changed, 54 insertions(+) diff --git a/src/configuration.h b/src/configuration.h index 89fa106ff..57469bfd5 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -84,6 +84,10 @@ along with this program. If not, see . #define BUTTON_PIN_ALT PIN_BUTTON2 #endif +#ifdef PIN_BUTTON_TOUCH +#define BUTTON_PIN_TOUCH PIN_BUTTON_TOUCH +#endif + // FIXME, use variant.h defs for all of this!!! (even on the ESP32 targets) #elif defined(CubeCell_BoardPlus) diff --git a/src/main.cpp b/src/main.cpp index 41d504e40..15085034d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -187,6 +187,9 @@ class ButtonThread : public OSThread #endif #ifdef BUTTON_PIN_ALT OneButton userButtonAlt; +#endif +#ifdef BUTTON_PIN_TOUCH + OneButton userButtonTouch; #endif static bool shutdown_on_long_stop; @@ -222,6 +225,21 @@ class ButtonThread : public OSThread userButtonAlt.attachLongPressStop(userButtonPressedLongStop); wakeOnIrq(BUTTON_PIN_ALT, FALLING); #endif + +#ifdef BUTTON_PIN_TOUCH + userButtonTouch = OneButton(BUTTON_PIN_TOUCH, true, true); +#ifdef INPUT_PULLUP_SENSE + // Some platforms (nrf52) have a SENSE variant which allows wake from sleep - override what OneButton did + pinMode(BUTTON_PIN_TOUCH, INPUT_PULLUP_SENSE); +#endif + userButtonTouch.attachClick(touchPressed); + userButtonTouch.attachDuringLongPress(touchPressedLong); + userButtonTouch.attachDoubleClick(touchDoublePressed); + userButtonTouch.attachLongPressStart(touchPressedLongStart); + userButtonTouch.attachLongPressStop(touchPressedLongStop); + wakeOnIrq(BUTTON_PIN_TOUCH, FALLING); +#endif + } protected: @@ -237,6 +255,10 @@ class ButtonThread : public OSThread #ifdef BUTTON_PIN_ALT userButtonAlt.tick(); canSleep &= userButtonAlt.isIdle(); +#endif +#ifdef BUTTON_PIN_TOUCH + userButtonTouch.tick(); + canSleep &= userButtonTouch.isIdle(); #endif // if (!canSleep) DEBUG_MSG("Supressing sleep!\n"); // else DEBUG_MSG("sleep ok\n"); @@ -245,6 +267,33 @@ class ButtonThread : public OSThread } private: + static void touchPressed() + { + screen->forceDisplay(); + DEBUG_MSG("touch press!\n"); + } + static void touchDoublePressed() + { + DEBUG_MSG("touch double press!\n"); + } + static void touchPressedLong() + { + DEBUG_MSG("touch press long!\n"); + } + static void touchDoublePressedLong() + { + DEBUG_MSG("touch double pressed!\n"); + } + static void touchPressedLongStart() + { + DEBUG_MSG("touch long press start!\n"); + } + static void touchPressedLongStop() + { + DEBUG_MSG("touch long press stop!\n"); + } + + static void userButtonPressed() { // DEBUG_MSG("press!\n"); diff --git a/variants/t-echo/variant.h b/variants/t-echo/variant.h index df57ee913..a1471c67b 100644 --- a/variants/t-echo/variant.h +++ b/variants/t-echo/variant.h @@ -120,6 +120,7 @@ extern "C" { */ #define PIN_BUTTON1 (32 + 10) #define PIN_BUTTON2 (0 + 18) // 0.18 is labeled on the board as RESET but we configure it in the bootloader as a regular GPIO +#define PIN_BUTTON_TOUCH (0 + 11) // 0.11 is the soft touch button on T-Echo /* * Analog pins