diff options
Diffstat (limited to 'src/ui/include')
| -rw-r--r-- | src/ui/include/encoder_input.hpp | 47 | ||||
| -rw-r--r-- | src/ui/include/lvgl_task.hpp | 9 | ||||
| -rw-r--r-- | src/ui/include/ui_fsm.hpp | 4 | ||||
| -rw-r--r-- | src/ui/include/wheel_encoder.hpp | 33 |
4 files changed, 52 insertions, 41 deletions
diff --git a/src/ui/include/encoder_input.hpp b/src/ui/include/encoder_input.hpp new file mode 100644 index 00000000..9c114e80 --- /dev/null +++ b/src/ui/include/encoder_input.hpp @@ -0,0 +1,47 @@ +/* + * Copyright 2023 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <memory> + +#include "core/lv_group.h" +#include "gpios.hpp" +#include "hal/lv_hal_indev.h" + +#include "relative_wheel.hpp" +#include "touchwheel.hpp" + +namespace ui { + +/* + * 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 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_; + + bool is_locked_; +}; + +} // namespace ui diff --git a/src/ui/include/lvgl_task.hpp b/src/ui/include/lvgl_task.hpp index 4362249b..f212ab9d 100644 --- a/src/ui/include/lvgl_task.hpp +++ b/src/ui/include/lvgl_task.hpp @@ -15,30 +15,27 @@ #include "freertos/timers.h" #include "display.hpp" +#include "encoder_input.hpp" #include "relative_wheel.hpp" #include "screen.hpp" #include "themes.hpp" #include "touchwheel.hpp" -#include "wheel_encoder.hpp" namespace ui { class UiTask { public: static auto Start() -> UiTask*; - ~UiTask(); - // FIXME: Once we have more input devices, this function should accept a more - // generic interface. - auto SetInputDevice(std::shared_ptr<TouchWheelEncoder> dev) -> void; + auto input(std::shared_ptr<EncoderInput> input) -> void; private: UiTask(); auto Main() -> void; - std::shared_ptr<TouchWheelEncoder> input_device_; + std::shared_ptr<EncoderInput> input_; std::shared_ptr<Screen> current_screen_; }; diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 24f0c270..4db8257d 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -26,6 +26,7 @@ #include "tinyfsm.hpp" #include "display.hpp" +#include "encoder_input.hpp" #include "modal.hpp" #include "screen.hpp" #include "storage.hpp" @@ -34,7 +35,6 @@ #include "track.hpp" #include "track_queue.hpp" #include "ui_events.hpp" -#include "wheel_encoder.hpp" namespace ui { @@ -87,7 +87,7 @@ 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<TouchWheelEncoder> sEncoder; + static std::shared_ptr<EncoderInput> sInput; static std::stack<std::shared_ptr<Screen>> sScreens; static std::shared_ptr<Screen> sCurrentScreen; diff --git a/src/ui/include/wheel_encoder.hpp b/src/ui/include/wheel_encoder.hpp deleted file mode 100644 index fcac5edd..00000000 --- a/src/ui/include/wheel_encoder.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include <memory> - -#include "core/lv_group.h" -#include "hal/lv_hal_indev.h" - -#include "relative_wheel.hpp" - -namespace ui { - -class TouchWheelEncoder { - public: - explicit TouchWheelEncoder(std::unique_ptr<drivers::RelativeWheel> wheel); - - auto Read(lv_indev_data_t* data) -> void; - auto registration() -> lv_indev_t* { return registration_; } - - private: - lv_indev_drv_t driver_; - lv_indev_t* registration_; - - lv_key_t last_key_; - std::unique_ptr<drivers::RelativeWheel> wheel_; -}; - -} // namespace ui |
