From 2b5f2d57733f8e77a31ce9f8b6adc0a20980ef7a Mon Sep 17 00:00:00 2001 From: eshifri Date: Mon, 16 Aug 2021 21:53:45 -0700 Subject: [PATCH] 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;