summaryrefslogtreecommitdiff
path: root/src/ui/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-10-04 10:18:31 +1100
committerjacqueline <me@jacqueline.id.au>2023-10-04 10:18:31 +1100
commit5c04e2ad8d14616ce3ca09b658d25bab3d8d2460 (patch)
tree411b269ca33ddadb0a95ac74a171b53a5fc7ac07 /src/ui/include
parentc851b789faf71d0ef2092ae7d8cd3190c13d85c9 (diff)
downloadtangara-fw-5c04e2ad8d14616ce3ca09b658d25bab3d8d2460.tar.gz
Neaten up the various kinds of inputs, and move volumes to The New Way
Diffstat (limited to 'src/ui/include')
-rw-r--r--src/ui/include/encoder_input.hpp29
1 files changed, 23 insertions, 6 deletions
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 <stdint.h>
#include <deque>
#include <memory>
+#include <set>
#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<Keys, uint64_t> touch_time_ms_;
- std::unordered_map<Keys, bool> short_press_fired_;
- std::unordered_map<Keys, bool> long_press_fired_;
+ // Set of keys that were released during the current update.
+ std::set<Keys> just_released_;
+ // Set of keys that have had an event fired for them since being pressed.
+ std::set<Keys> 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 {