diff options
| author | cooljqln <cooljqln@noreply.codeberg.org> | 2024-04-11 07:02:53 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-04-11 07:02:53 +0000 |
| commit | dd1ea595a7753706d4fa5f19b66f3dc1cbd56a02 (patch) | |
| tree | 60bfa4569af0f9506ccffe85f19e89bbe2a83332 /src/ui/include | |
| parent | f580928cbab797e4e8a3eae5ae1c0b18b8066066 (diff) | |
| parent | 33919e9e3f419e13318fa6b8217d8c8dcd86c1eb (diff) | |
| download | tangara-fw-dd1ea595a7753706d4fa5f19b66f3dc1cbd56a02.tar.gz | |
Merge pull request 'jqln/input-devices' (#62) from jqln/input-devices into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/62
Reviewed-by: ailurux <ailurux@noreply.codeberg.org>
Diffstat (limited to 'src/ui/include')
| -rw-r--r-- | src/ui/include/encoder_input.hpp | 107 | ||||
| -rw-r--r-- | src/ui/include/lvgl_task.hpp | 7 | ||||
| -rw-r--r-- | src/ui/include/ui_events.hpp | 1 | ||||
| -rw-r--r-- | src/ui/include/ui_fsm.hpp | 14 |
4 files changed, 11 insertions, 118 deletions
diff --git a/src/ui/include/encoder_input.hpp b/src/ui/include/encoder_input.hpp deleted file mode 100644 index 7dfac071..00000000 --- a/src/ui/include/encoder_input.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include <stdint.h> -#include <deque> -#include <memory> -#include <set> - -#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. - * - * As far as LVGL is concerned, this class represents an ordinary rotary - * encoder, supporting only left and right ticks, and clicking. - */ -class EncoderInput { - public: - EncoderInput(drivers::IGpios& gpios, drivers::TouchWheel& wheel); - - auto Read(lv_indev_data_t* data) -> void; - auto registration() -> lv_indev_t* { return registration_; } - - auto mode(drivers::NvsStorage::InputModes mode) { mode_ = mode; } - auto scroll_sensitivity(uint8_t val) -> void; // Value between 0-255, used to scale the threshold - auto lock(bool l) -> void { is_locked_ = l; } - - private: - lv_indev_drv_t driver_; - lv_indev_t* registration_; - - 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_; - uint8_t scroll_sensitivity_; - - // Every kind of distinct input that we could map to an action. - enum class Keys { - kVolumeUp, - kVolumeDown, - kTouchWheel, - kTouchWheelCenter, - kDirectionalUp, - kDirectionalRight, - kDirectionalDown, - 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_; - // 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_; - - bool is_scrolling_wheel_; - - 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 UpdateKeyState(Keys key, uint64_t ms, bool clicked) -> void; - auto TriggerKey(Keys key, KeyStyle t, uint64_t ms) -> Trigger; -}; - -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 diff --git a/src/ui/include/lvgl_task.hpp b/src/ui/include/lvgl_task.hpp index f212ab9d..8efcbf35 100644 --- a/src/ui/include/lvgl_task.hpp +++ b/src/ui/include/lvgl_task.hpp @@ -15,8 +15,7 @@ #include "freertos/timers.h" #include "display.hpp" -#include "encoder_input.hpp" -#include "relative_wheel.hpp" +#include "lvgl_input_driver.hpp" #include "screen.hpp" #include "themes.hpp" #include "touchwheel.hpp" @@ -28,14 +27,14 @@ class UiTask { static auto Start() -> UiTask*; ~UiTask(); - auto input(std::shared_ptr<EncoderInput> input) -> void; + auto input(std::shared_ptr<input::LvglInputDriver> input) -> void; private: UiTask(); auto Main() -> void; - std::shared_ptr<EncoderInput> input_; + std::shared_ptr<input::LvglInputDriver> input_; std::shared_ptr<Screen> current_screen_; }; diff --git a/src/ui/include/ui_events.hpp b/src/ui/include/ui_events.hpp index 5c033b0c..81e0543a 100644 --- a/src/ui/include/ui_events.hpp +++ b/src/ui/include/ui_events.hpp @@ -32,7 +32,6 @@ struct DumpLuaStack : tinyfsm::Event {}; namespace internal { -struct ControlSchemeChanged : tinyfsm::Event {}; struct ReindexDatabase : tinyfsm::Event {}; struct BackPressed : tinyfsm::Event {}; diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 2bab487d..8eafc6e0 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -13,15 +13,18 @@ #include "audio_events.hpp" #include "battery.hpp" #include "db_events.hpp" +#include "device_factory.hpp" #include "display.hpp" -#include "encoder_input.hpp" +#include "feedback_haptics.hpp" #include "gpios.hpp" +#include "input_touch_wheel.hpp" +#include "input_volume_buttons.hpp" #include "lua_thread.hpp" +#include "lvgl_input_driver.hpp" #include "lvgl_task.hpp" #include "modal.hpp" #include "nvs.hpp" #include "property.hpp" -#include "relative_wheel.hpp" #include "screen.hpp" #include "service_locator.hpp" #include "storage.hpp" @@ -68,7 +71,6 @@ class UiState : public tinyfsm::Fsm<UiState> { void react(const system_fsm::SamdUsbStatusChanged&); void react(const internal::DismissAlerts&); - void react(const internal::ControlSchemeChanged&); void react(const database::event::UpdateStarted&); void react(const database::event::UpdateProgress&){}; @@ -92,7 +94,9 @@ class UiState : public tinyfsm::Fsm<UiState> { static std::unique_ptr<UiTask> sTask; static std::shared_ptr<system_fsm::ServiceLocator> sServices; static std::unique_ptr<drivers::Display> sDisplay; - static std::shared_ptr<EncoderInput> sInput; + + static std::shared_ptr<input::LvglInputDriver> sInput; + static std::unique_ptr<input::DeviceFactory> sDeviceFactory; static std::stack<std::shared_ptr<Screen>> sScreens; static std::shared_ptr<Screen> sCurrentScreen; @@ -126,8 +130,6 @@ class UiState : public tinyfsm::Fsm<UiState> { static lua::Property sDisplayBrightness; - static lua::Property sControlsScheme; - static lua::Property sScrollSensitivity; static lua::Property sLockSwitch; static lua::Property sDatabaseUpdating; |
