From 09f129662e41108fd86255c02623a38e07cbbb27 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 3 Oct 2023 14:33:36 +1100 Subject: Add scroll velocity + more input methods --- src/ui/include/encoder_input.hpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (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 9c114e80..e685a7a2 100644 --- a/src/ui/include/encoder_input.hpp +++ b/src/ui/include/encoder_input.hpp @@ -6,17 +6,22 @@ #pragma once +#include +#include #include #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 relative_wheel_; + std::unique_ptr scroller_; + drivers::NvsStorage::InputModes mode_; bool is_locked_; + + enum class Keys { + kVolumeUp, + kVolumeDown, + kTouchWheel, + kTouchWheelCenter, + kDirectionalUp, + kDirectionalRight, + kDirectionalDown, + kDirectionalLeft, + }; + + std::unordered_map touch_time_ms_; + std::unordered_map short_press_fired_; + std::unordered_map 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 -- cgit v1.2.3