diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-10-03 14:33:36 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-10-03 14:33:36 +1100 |
| commit | 09f129662e41108fd86255c02623a38e07cbbb27 (patch) | |
| tree | 2bfbfbcd0f3c509e1eae1a11016e6f7c0cb37206 /src/ui/include | |
| parent | 7d5536e2abca61f503ed68521603bd30700a7e5e (diff) | |
| download | tangara-fw-09f129662e41108fd86255c02623a38e07cbbb27.tar.gz | |
Add scroll velocity + more input methods
Diffstat (limited to 'src/ui/include')
| -rw-r--r-- | src/ui/include/encoder_input.hpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/ui/include/encoder_input.hpp b/src/ui/include/encoder_input.hpp index 9c114e80..e685a7a2 100644 --- a/src/ui/include/encoder_input.hpp +++ b/src/ui/include/encoder_input.hpp @@ -6,17 +6,22 @@ #pragma once +#include <stdint.h> +#include <deque> #include <memory> #include "core/lv_group.h" #include "gpios.hpp" #include "hal/lv_hal_indev.h" +#include "nvs.hpp" #include "relative_wheel.hpp" #include "touchwheel.hpp" namespace ui { +class Scroller; + /* * Main input device abstracting that handles turning lower-level input device * drivers into events and LVGL inputs. @@ -31,6 +36,7 @@ class EncoderInput { auto Read(lv_indev_data_t* data) -> void; auto registration() -> lv_indev_t* { return registration_; } + auto mode(drivers::NvsStorage::InputModes mode) { mode_ = mode; } auto lock(bool l) -> void { is_locked_ = l; } private: @@ -40,8 +46,41 @@ class EncoderInput { drivers::IGpios& gpios_; drivers::TouchWheel& raw_wheel_; std::unique_ptr<drivers::RelativeWheel> relative_wheel_; + std::unique_ptr<Scroller> scroller_; + drivers::NvsStorage::InputModes mode_; bool is_locked_; + + enum class Keys { + kVolumeUp, + kVolumeDown, + kTouchWheel, + kTouchWheelCenter, + kDirectionalUp, + kDirectionalRight, + kDirectionalDown, + kDirectionalLeft, + }; + + 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_; + + 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; +}; + +class Scroller { + public: + Scroller() : last_input_ms_(0), velocity_(0) {} + + auto AddInput(uint64_t, int) -> int; + + private: + uint64_t last_input_ms_; + int velocity_; }; } // namespace ui |
