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/ui_fsm.cpp | |
| 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/ui_fsm.cpp')
| -rw-r--r-- | src/ui/ui_fsm.cpp | 100 |
1 files changed, 23 insertions, 77 deletions
diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index 739c4598..1c296ac7 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -12,9 +12,14 @@ #include "bluetooth_types.hpp" #include "db_events.hpp" +#include "device_factory.hpp" #include "display_init.hpp" +#include "feedback_haptics.hpp" #include "freertos/portmacro.h" #include "freertos/projdefs.h" +#include "input_device.hpp" +#include "input_touch_wheel.hpp" +#include "input_volume_buttons.hpp" #include "lua.h" #include "lua.hpp" @@ -30,19 +35,18 @@ #include "lauxlib.h" #include "lua_thread.hpp" #include "luavgl.h" +#include "lvgl_input_driver.hpp" #include "memory_resource.hpp" #include "misc/lv_gc.h" #include "audio_events.hpp" #include "display.hpp" -#include "encoder_input.hpp" #include "event_queue.hpp" #include "gpios.hpp" #include "lua_registry.hpp" #include "lvgl_task.hpp" #include "nvs.hpp" #include "property.hpp" -#include "relative_wheel.hpp" #include "samd.hpp" #include "screen.hpp" #include "screen_lua.hpp" @@ -63,7 +67,9 @@ namespace ui { std::unique_ptr<UiTask> UiState::sTask; std::shared_ptr<system_fsm::ServiceLocator> UiState::sServices; std::unique_ptr<drivers::Display> UiState::sDisplay; -std::shared_ptr<EncoderInput> UiState::sInput; + +std::shared_ptr<input::LvglInputDriver> UiState::sInput; +std::unique_ptr<input::DeviceFactory> UiState::sDeviceFactory; std::stack<std::shared_ptr<Screen>> UiState::sScreens; std::shared_ptr<Screen> UiState::sCurrentScreen; @@ -234,52 +240,6 @@ lua::Property UiState::sDisplayBrightness{ return true; }}; -lua::Property UiState::sControlsScheme{ - 0, [](const lua::LuaValue& val) { - if (!std::holds_alternative<int>(val)) { - return false; - } - drivers::NvsStorage::InputModes mode; - switch (std::get<int>(val)) { - case 0: - mode = drivers::NvsStorage::InputModes::kButtonsOnly; - break; - case 1: - mode = drivers::NvsStorage::InputModes::kButtonsWithWheel; - break; - case 2: - mode = drivers::NvsStorage::InputModes::kDirectionalWheel; - break; - case 3: - mode = drivers::NvsStorage::InputModes::kRotatingWheel; - break; - default: - return false; - } - sServices->nvs().PrimaryInput(mode); - sInput->mode(mode); - return true; - }}; - -lua::Property UiState::sScrollSensitivity{ - 0, [](const lua::LuaValue& val) { - std::optional<int> sensitivity = 0; - std::visit( - [&](auto&& v) { - using T = std::decay_t<decltype(v)>; - if constexpr (std::is_same_v<T, int>) { - sensitivity = v; - } - }, - val); - if (!sensitivity) { - return false; - } - sInput->scroll_sensitivity(*sensitivity); - sServices->nvs().ScrollSensitivity(*sensitivity); - return true; - }}; - lua::Property UiState::sLockSwitch{false}; lua::Property UiState::sDatabaseUpdating{false}; @@ -368,13 +328,6 @@ void UiState::react(const system_fsm::SamdUsbStatusChanged& ev) { drivers::Samd::UsbStatus::kAttachedBusy); } -void UiState::react(const internal::ControlSchemeChanged&) { - if (!sInput) { - return; - } - sInput->mode(sServices->nvs().PrimaryInput()); -} - void UiState::react(const database::event::UpdateStarted&) { sDatabaseUpdating.Update(true); } @@ -478,22 +431,11 @@ void Splash::react(const system_fsm::BootComplete& ev) { sDisplayBrightness.Update(brightness); sDisplay->SetBrightness(brightness); - auto touchwheel = sServices->touchwheel(); - if (touchwheel) { - sInput = std::make_shared<EncoderInput>(sServices->gpios(), **touchwheel); + sDeviceFactory = std::make_unique<input::DeviceFactory>(sServices); + sInput = std::make_shared<input::LvglInputDriver>(sServices->nvs(), + *sDeviceFactory); - auto mode = sServices->nvs().PrimaryInput(); - sInput->mode(mode); - sControlsScheme.Update(static_cast<int>(mode)); - - auto sensitivity = sServices->nvs().ScrollSensitivity(); - sInput->scroll_sensitivity(sensitivity); - sScrollSensitivity.Update(static_cast<int>(sensitivity)); - - sTask->input(sInput); - } else { - ESP_LOGE(kTag, "no input devices initialised!"); - } + sTask->input(sInput); } void Splash::react(const system_fsm::StorageMounted&) { @@ -550,12 +492,16 @@ void Lua::entry() { {"brightness", &sDisplayBrightness}, }); - registry.AddPropertyModule("controls", - { - {"scheme", &sControlsScheme}, - {"scroll_sensitivity", &sScrollSensitivity}, - {"lock_switch", &sLockSwitch}, - }); + registry.AddPropertyModule("controls", { + {"scheme", &sInput->mode()}, + {"lock_switch", &sLockSwitch}, + }); + + if (sDeviceFactory->touch_wheel()) { + registry.AddPropertyModule( + "controls", {{"scroll_sensitivity", + &sDeviceFactory->touch_wheel()->sensitivity()}}); + } registry.AddPropertyModule( "backstack", |
