From 5c04e2ad8d14616ce3ca09b658d25bab3d8d2460 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 4 Oct 2023 10:18:31 +1100 Subject: Neaten up the various kinds of inputs, and move volumes to The New Way --- src/ui/include/encoder_input.hpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/ui/include/encoder_input.hpp') diff --git a/src/ui/include/encoder_input.hpp b/src/ui/include/encoder_input.hpp index e685a7a2..2386b5c9 100644 --- a/src/ui/include/encoder_input.hpp +++ b/src/ui/include/encoder_input.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "core/lv_group.h" #include "gpios.hpp" @@ -51,6 +52,7 @@ class EncoderInput { drivers::NvsStorage::InputModes mode_; bool is_locked_; + // Every kind of distinct input that we could map to an action. enum class Keys { kVolumeUp, kVolumeDown, @@ -62,14 +64,29 @@ class EncoderInput { kDirectionalLeft, }; + // Map from a Key, to the time that it was first touched in ms. If the key is + // currently released, where will be no entry. std::unordered_map touch_time_ms_; - std::unordered_map short_press_fired_; - std::unordered_map long_press_fired_; + // Set of keys that were released during the current update. + std::set just_released_; + // Set of keys that have had an event fired for them since being pressed. + std::set fired_; + + enum class Trigger { + kNone, + // Regular short-click. Triggered on release for long-pressable keys, + // triggered on the initial press for repeatable keys. + kClick, + kLongPress, + }; + + enum class KeyStyle { + kRepeat, + kLongPress, + }; - auto HandleKey(Keys key, uint64_t ms, bool clicked) -> void; - auto ShortPressTrigger(Keys key) -> bool; - auto ShortPressTriggerRepeating(Keys key, uint64_t ms) -> bool; - auto LongPressTrigger(Keys key, uint64_t ms) -> bool; + auto HandleKeyState(Keys key, uint64_t ms, bool clicked) -> void; + auto TriggerKey(Keys key, KeyStyle t, uint64_t ms) -> Trigger; }; class Scroller { -- cgit v1.2.3