From 1ad865f08a39b79a87a5dce088cc9ba60f0f5bbd Mon Sep 17 00:00:00 2001 From: kevinkoenig Date: Tue, 7 Sep 2021 07:53:01 -0400 Subject: [PATCH 1/2] Implement long touch to launch curves in mixes and inputs --- radio/src/gui/colorlcd/choiceex.cpp | 36 +++++++++++++++++++++++++---- radio/src/gui/colorlcd/choiceex.h | 6 ++++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/radio/src/gui/colorlcd/choiceex.cpp b/radio/src/gui/colorlcd/choiceex.cpp index 88974b87c..8bf86b6f0 100644 --- a/radio/src/gui/colorlcd/choiceex.cpp +++ b/radio/src/gui/colorlcd/choiceex.cpp @@ -28,13 +28,12 @@ void ChoiceEx::setLongPressHandler(std::function handler) ChoiceEx::ChoiceEx(FormGroup * parent, const rect_t & rect, int vmin, int vmax, std::function getValue, std::function setValue, WindowFlags windowFlags) : Choice(parent, rect, vmin, vmax, getValue, setValue, windowFlags) { +#if defined(HARDWARE_TOUCH) + duration10ms = 0; +#endif } -bool ChoiceEx::onTouchEnd(coord_t x, coord_t y) -{ - return Choice::onTouchEnd(x,y); -} - +#if defined(HARDWARE_KEYS) void ChoiceEx::onEvent(event_t event) { if (event == EVT_KEY_LONG(KEY_ENTER)) { @@ -47,4 +46,31 @@ void ChoiceEx::onEvent(event_t event) Choice::onEvent(event); } +#endif + +#if defined(HARDWARE_TOUCH) +bool ChoiceEx::onTouchStart(coord_t x, coord_t y) +{ + if (duration10ms == 0) { + duration10ms = get_tmr10ms(); + } + + return Choice::onTouchStart(x, y); +} + +bool ChoiceEx::onTouchEnd(coord_t x, coord_t y) +{ + tmr10ms_t curTimer = get_tmr10ms(); + if (duration10ms != 0 && curTimer - duration10ms > LONG_PRESS_10MS) { + if (longPressHandler) { + longPressHandler(0); + duration10ms = 0; + return false; + } + } + + duration10ms = 0; + return Choice::onTouchEnd(x,y); +} +#endif diff --git a/radio/src/gui/colorlcd/choiceex.h b/radio/src/gui/colorlcd/choiceex.h index bdf7f9792..23cee0514 100644 --- a/radio/src/gui/colorlcd/choiceex.h +++ b/radio/src/gui/colorlcd/choiceex.h @@ -32,16 +32,20 @@ class ChoiceEx : public Choice #if defined(HARDWARE_TOUCH) bool onTouchEnd(coord_t x, coord_t y) override; + bool onTouchStart(coord_t x, coord_t y) override; #endif #if defined(DEBUG_WINDOWS) std::string getName() const override { - return "CurvesListChoice"; + return "ChoceEx"; } #endif protected: std::function longPressHandler = nullptr; +#if defined(HARDWARE_TOUCH) + tmr10ms_t duration10ms; +#endif }; From cb24ef92362218f5670a6cf9b5c3383ccbcdc2bb Mon Sep 17 00:00:00 2001 From: "kkoenig1@optonline.com" Date: Tue, 7 Sep 2021 09:30:15 -0400 Subject: [PATCH 2/2] enhanced long touch to handle it without lifting finger. Now works exactly like other areas of system --- radio/src/gui/colorlcd/choiceex.cpp | 27 +++++++++++++++++++++++++-- radio/src/gui/colorlcd/choiceex.h | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/radio/src/gui/colorlcd/choiceex.cpp b/radio/src/gui/colorlcd/choiceex.cpp index 8bf86b6f0..735f03b65 100644 --- a/radio/src/gui/colorlcd/choiceex.cpp +++ b/radio/src/gui/colorlcd/choiceex.cpp @@ -58,10 +58,33 @@ bool ChoiceEx::onTouchStart(coord_t x, coord_t y) return Choice::onTouchStart(x, y); } -bool ChoiceEx::onTouchEnd(coord_t x, coord_t y) +bool ChoiceEx::isLongPress() { tmr10ms_t curTimer = get_tmr10ms(); - if (duration10ms != 0 && curTimer - duration10ms > LONG_PRESS_10MS) { + return (duration10ms != 0 && curTimer - duration10ms > LONG_PRESS_10MS); +} + +void ChoiceEx::checkEvents(void) +{ + event_t event = getEvent(); + + if (isLongPress()) { + if (longPressHandler) { + longPressHandler(event); + duration10ms = 0; + } + } + + if (hasFocus()) + onEvent(event); + else + pushEvent(event); +} + + +bool ChoiceEx::onTouchEnd(coord_t x, coord_t y) +{ + if (isLongPress()) { if (longPressHandler) { longPressHandler(0); duration10ms = 0; diff --git a/radio/src/gui/colorlcd/choiceex.h b/radio/src/gui/colorlcd/choiceex.h index 23cee0514..5a3f33cda 100644 --- a/radio/src/gui/colorlcd/choiceex.h +++ b/radio/src/gui/colorlcd/choiceex.h @@ -33,6 +33,8 @@ class ChoiceEx : public Choice #if defined(HARDWARE_TOUCH) bool onTouchEnd(coord_t x, coord_t y) override; bool onTouchStart(coord_t x, coord_t y) override; + void checkEvents(void) override; + bool isLongPress(); #endif #if defined(DEBUG_WINDOWS)