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;