From 711187259e25583998943f5df61e54c9f5e42721 Mon Sep 17 00:00:00 2001 From: eshifri Date: Sun, 15 Aug 2021 10:37:14 -0700 Subject: [PATCH 1/6] long press or long touch open selection menu on the inverted switch --- radio/src/gui/colorlcd/switchchoice.cpp | 27 ++++++++++++++++++++++--- radio/src/gui/colorlcd/switchchoice.h | 16 +++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/radio/src/gui/colorlcd/switchchoice.cpp b/radio/src/gui/colorlcd/switchchoice.cpp index 9db366569..2fa88beaf 100644 --- a/radio/src/gui/colorlcd/switchchoice.cpp +++ b/radio/src/gui/colorlcd/switchchoice.cpp @@ -120,7 +120,11 @@ void SwitchChoice::onEvent(event_t event) { TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event); - if (event == EVT_KEY_BREAK(KEY_ENTER)) { + if (event == EVT_KEY_LONG(KEY_ENTER)) { + int16_t val = getValue(); + setValue(-val); + } + else if (event == EVT_KEY_BREAK(KEY_ENTER)) { editMode = true; invalidate(); openMenu(); @@ -132,11 +136,28 @@ void SwitchChoice::onEvent(event_t event) #endif #if defined(HARDWARE_TOUCH) -bool SwitchChoice::onTouchEnd(coord_t, coord_t) +bool SwitchChoice::onTouchStart(coord_t x, coord_t y) +{ + if (!duration10ms) { + duration10ms = get_tmr10ms(); + } + return FormField::onTouchStart(x, y); +} + +bool SwitchChoice::onTouchEnd(coord_t x, coord_t y) { setFocus(SET_FOCUS_DEFAULT); + + touchDuration10ms = get_tmr10ms() - duration10ms; + duration10ms = 0; + if (isLongPress()) { + int16_t val = getValue(); + setValue(-val); + } + setEditMode(true); openMenu(); - return true; + + return true; // FormField::onTouchEnd(x, y); } #endif diff --git a/radio/src/gui/colorlcd/switchchoice.h b/radio/src/gui/colorlcd/switchchoice.h index 65c9156ef..df4fcddb4 100644 --- a/radio/src/gui/colorlcd/switchchoice.h +++ b/radio/src/gui/colorlcd/switchchoice.h @@ -23,6 +23,8 @@ #include "form.h" +constexpr int LONG_PRESS_10MS = 100; + class Menu; bool isSwitchAvailableInMixes(int swtch); @@ -41,6 +43,10 @@ class SwitchChoice : public FormField getValue(std::move(getValue)), setValue(std::move(setValue)) { +#if defined(HARDWARE_TOUCH) + duration10ms = 0; + touchDuration10ms = 0; +#endif } #if defined(DEBUG_WINDOWS) @@ -55,8 +61,14 @@ class SwitchChoice : public FormField #if defined(HARDWARE_TOUCH) bool onTouchEnd(coord_t x, coord_t y) override; + bool onTouchStart(coord_t x, coord_t y) override; + inline bool isLongPress(tmr10ms_t longPressDuration = LONG_PRESS_10MS) + { + return (touchDuration10ms > longPressDuration) ? true : false; + }; #endif + void setAvailableHandler(std::function handler) { isValueAvailable = std::move(handler); @@ -65,6 +77,10 @@ class SwitchChoice : public FormField protected: int16_t vmin; int16_t vmax; +#if defined(HARDWARE_TOUCH) + tmr10ms_t duration10ms; + tmr10ms_t touchDuration10ms; +#endif std::function getValue; std::function setValue; std::function isValueAvailable = isSwitchAvailableInMixes; From 7e5bb1543284a538fe03aaed4e18af3cd63b58da Mon Sep 17 00:00:00 2001 From: eshifri Date: Mon, 16 Aug 2021 19:26:55 -0700 Subject: [PATCH 2/6] Visual feedback improved --- radio/src/gui/colorlcd/switchchoice.cpp | 25 ++++++++++++++++++++----- radio/src/gui/colorlcd/switchchoice.h | 1 + 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/radio/src/gui/colorlcd/switchchoice.cpp b/radio/src/gui/colorlcd/switchchoice.cpp index 2fa88beaf..fa5b5e9b4 100644 --- a/radio/src/gui/colorlcd/switchchoice.cpp +++ b/radio/src/gui/colorlcd/switchchoice.cpp @@ -136,6 +136,26 @@ void SwitchChoice::onEvent(event_t event) #endif #if defined(HARDWARE_TOUCH) +void SwitchChoice::checkEvents(void) +{ + event_t event = getEvent(); + + if (duration10ms > 1) { + touchDuration10ms = get_tmr10ms() - duration10ms; + + if (isLongPress()) { + int16_t val = getValue(); + setValue(-val); + duration10ms = 1; + } + } + + if (hasFocus()) + onEvent(event); + else + pushEvent(event); +} + bool SwitchChoice::onTouchStart(coord_t x, coord_t y) { if (!duration10ms) { @@ -148,12 +168,7 @@ bool SwitchChoice::onTouchEnd(coord_t x, coord_t y) { setFocus(SET_FOCUS_DEFAULT); - touchDuration10ms = get_tmr10ms() - duration10ms; duration10ms = 0; - if (isLongPress()) { - int16_t val = getValue(); - setValue(-val); - } setEditMode(true); openMenu(); diff --git a/radio/src/gui/colorlcd/switchchoice.h b/radio/src/gui/colorlcd/switchchoice.h index df4fcddb4..244456010 100644 --- a/radio/src/gui/colorlcd/switchchoice.h +++ b/radio/src/gui/colorlcd/switchchoice.h @@ -60,6 +60,7 @@ class SwitchChoice : public FormField #endif #if defined(HARDWARE_TOUCH) + void checkEvents(void) override; bool onTouchEnd(coord_t x, coord_t y) override; bool onTouchStart(coord_t x, coord_t y) override; inline bool isLongPress(tmr10ms_t longPressDuration = LONG_PRESS_10MS) From 2b5f2d57733f8e77a31ce9f8b6adc0a20980ef7a Mon Sep 17 00:00:00 2001 From: eshifri Date: Mon, 16 Aug 2021 21:53:45 -0700 Subject: [PATCH 3/6] Cleanup --- radio/src/gui/colorlcd/switchchoice.cpp | 22 ++++++++++++++-------- radio/src/gui/colorlcd/switchchoice.h | 7 +------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/radio/src/gui/colorlcd/switchchoice.cpp b/radio/src/gui/colorlcd/switchchoice.cpp index fa5b5e9b4..c4283b2a9 100644 --- a/radio/src/gui/colorlcd/switchchoice.cpp +++ b/radio/src/gui/colorlcd/switchchoice.cpp @@ -136,18 +136,24 @@ void SwitchChoice::onEvent(event_t event) #endif #if defined(HARDWARE_TOUCH) +bool SwitchChoice::isLongPress(tmr10ms_t longPressDuration) +{ + if (duration10ms > 1) { + tmr10ms_t touchDuration10ms = get_tmr10ms() - duration10ms; + + if (touchDuration10ms > longPressDuration) return true; + } + return false; +} + void SwitchChoice::checkEvents(void) { event_t event = getEvent(); - if (duration10ms > 1) { - touchDuration10ms = get_tmr10ms() - duration10ms; - - if (isLongPress()) { - int16_t val = getValue(); - setValue(-val); - duration10ms = 1; - } + if (isLongPress()) { + int16_t val = getValue(); + setValue(-val); + duration10ms = 1; } if (hasFocus()) diff --git a/radio/src/gui/colorlcd/switchchoice.h b/radio/src/gui/colorlcd/switchchoice.h index 244456010..ce92fb2ae 100644 --- a/radio/src/gui/colorlcd/switchchoice.h +++ b/radio/src/gui/colorlcd/switchchoice.h @@ -45,7 +45,6 @@ class SwitchChoice : public FormField { #if defined(HARDWARE_TOUCH) duration10ms = 0; - touchDuration10ms = 0; #endif } @@ -63,10 +62,7 @@ class SwitchChoice : public FormField void checkEvents(void) override; bool onTouchEnd(coord_t x, coord_t y) override; bool onTouchStart(coord_t x, coord_t y) override; - inline bool isLongPress(tmr10ms_t longPressDuration = LONG_PRESS_10MS) - { - return (touchDuration10ms > longPressDuration) ? true : false; - }; + inline bool isLongPress(tmr10ms_t longPressDuration = LONG_PRESS_10MS); #endif @@ -80,7 +76,6 @@ class SwitchChoice : public FormField int16_t vmax; #if defined(HARDWARE_TOUCH) tmr10ms_t duration10ms; - tmr10ms_t touchDuration10ms; #endif std::function getValue; std::function setValue; From cb42a7665a669195be15c22cbbdf9c8124306cec Mon Sep 17 00:00:00 2001 From: eshifri Date: Tue, 17 Aug 2021 17:15:07 -0700 Subject: [PATCH 4/6] Yet, one moe visual feedback improvement --- radio/src/gui/colorlcd/switchchoice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/radio/src/gui/colorlcd/switchchoice.cpp b/radio/src/gui/colorlcd/switchchoice.cpp index c4283b2a9..3c1a5a926 100644 --- a/radio/src/gui/colorlcd/switchchoice.cpp +++ b/radio/src/gui/colorlcd/switchchoice.cpp @@ -123,6 +123,7 @@ void SwitchChoice::onEvent(event_t event) if (event == EVT_KEY_LONG(KEY_ENTER)) { int16_t val = getValue(); setValue(-val); + invalidate(); } else if (event == EVT_KEY_BREAK(KEY_ENTER)) { editMode = true; @@ -153,6 +154,7 @@ void SwitchChoice::checkEvents(void) if (isLongPress()) { int16_t val = getValue(); setValue(-val); + invalidate(); duration10ms = 1; } From 9150e74f5078d83b8355369d76f18fe53349ad15 Mon Sep 17 00:00:00 2001 From: eshifri Date: Sun, 22 Aug 2021 11:14:38 -0700 Subject: [PATCH 5/6] Do not open menu on long press. Do not allow unavailable values. --- radio/src/gui/colorlcd/switchchoice.cpp | 37 +++++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/radio/src/gui/colorlcd/switchchoice.cpp b/radio/src/gui/colorlcd/switchchoice.cpp index 3c1a5a926..9f13e5397 100644 --- a/radio/src/gui/colorlcd/switchchoice.cpp +++ b/radio/src/gui/colorlcd/switchchoice.cpp @@ -120,15 +120,23 @@ void SwitchChoice::onEvent(event_t event) { TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event); + static bool longPress = false; if (event == EVT_KEY_LONG(KEY_ENTER)) { int16_t val = getValue(); - setValue(-val); - invalidate(); + if (isValueAvailable && isValueAvailable(-val) ) { + setValue(-val); + invalidate(); + longPress = true; + } } - else if (event == EVT_KEY_BREAK(KEY_ENTER)) { - editMode = true; - invalidate(); - openMenu(); + else if (event == EVT_KEY_BREAK(KEY_ENTER)) { + if(!longPress) { + editMode = true; + invalidate(); + openMenu(); + } else { + longPress = false; + } } else { FormField::onEvent(event); @@ -153,9 +161,11 @@ void SwitchChoice::checkEvents(void) if (isLongPress()) { int16_t val = getValue(); - setValue(-val); - invalidate(); - duration10ms = 1; + if (isValueAvailable && isValueAvailable(-val) ) { + setValue(-val); + invalidate(); + duration10ms = 1; + } } if (hasFocus()) @@ -176,10 +186,13 @@ bool SwitchChoice::onTouchEnd(coord_t x, coord_t y) { setFocus(SET_FOCUS_DEFAULT); - duration10ms = 0; + + if(duration10ms != 1) { + setEditMode(true); + openMenu(); + } - setEditMode(true); - openMenu(); + duration10ms = 0; return true; // FormField::onTouchEnd(x, y); } From bbe312a8fd4e2ca700b3e0fa6bdffcd7c02c7d54 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Wed, 25 Aug 2021 11:21:40 +1000 Subject: [PATCH 6/6] Cleanup --- radio/src/gui/colorlcd/switchchoice.cpp | 5 ++--- radio/src/gui/colorlcd/switchchoice.h | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/radio/src/gui/colorlcd/switchchoice.cpp b/radio/src/gui/colorlcd/switchchoice.cpp index 9f13e5397..13bf1b8f3 100644 --- a/radio/src/gui/colorlcd/switchchoice.cpp +++ b/radio/src/gui/colorlcd/switchchoice.cpp @@ -185,8 +185,7 @@ bool SwitchChoice::onTouchStart(coord_t x, coord_t y) bool SwitchChoice::onTouchEnd(coord_t x, coord_t y) { setFocus(SET_FOCUS_DEFAULT); - - + if(duration10ms != 1) { setEditMode(true); openMenu(); @@ -194,6 +193,6 @@ bool SwitchChoice::onTouchEnd(coord_t x, coord_t y) duration10ms = 0; - return true; // FormField::onTouchEnd(x, y); + return true; } #endif diff --git a/radio/src/gui/colorlcd/switchchoice.h b/radio/src/gui/colorlcd/switchchoice.h index ce92fb2ae..c31b966b4 100644 --- a/radio/src/gui/colorlcd/switchchoice.h +++ b/radio/src/gui/colorlcd/switchchoice.h @@ -65,7 +65,6 @@ class SwitchChoice : public FormField inline bool isLongPress(tmr10ms_t longPressDuration = LONG_PRESS_10MS); #endif - void setAvailableHandler(std::function handler) { isValueAvailable = std::move(handler);