From 33919e9e3f419e13318fa6b8217d8c8dcd86c1eb Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 11 Apr 2024 15:16:35 +1000 Subject: Migrate all existing control schemes to the cool new world --- src/ui/include/ui_events.hpp | 1 - src/ui/include/ui_fsm.hpp | 9 +++-- src/ui/ui_fsm.cpp | 88 +++++++++++--------------------------------- 3 files changed, 27 insertions(+), 71 deletions(-) (limited to 'src/ui') 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 c238a447..8eafc6e0 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -13,8 +13,12 @@ #include "audio_events.hpp" #include "battery.hpp" #include "db_events.hpp" +#include "device_factory.hpp" #include "display.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" @@ -67,7 +71,6 @@ class UiState : public tinyfsm::Fsm { 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&){}; @@ -91,7 +94,9 @@ class UiState : public tinyfsm::Fsm { static std::unique_ptr sTask; static std::shared_ptr sServices; static std::unique_ptr sDisplay; + static std::shared_ptr sInput; + static std::unique_ptr sDeviceFactory; static std::stack> sScreens; static std::shared_ptr sCurrentScreen; @@ -125,8 +130,6 @@ class UiState : public tinyfsm::Fsm { static lua::Property sDisplayBrightness; - static lua::Property sControlsScheme; - static lua::Property sScrollSensitivity; static lua::Property sLockSwitch; static lua::Property sDatabaseUpdating; diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index a9c1d3a3..eaaef450 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" @@ -62,7 +67,9 @@ namespace ui { std::unique_ptr UiState::sTask; std::shared_ptr UiState::sServices; std::unique_ptr UiState::sDisplay; + std::shared_ptr UiState::sInput; +std::unique_ptr UiState::sDeviceFactory; std::stack> UiState::sScreens; std::shared_ptr UiState::sCurrentScreen; @@ -233,59 +240,6 @@ lua::Property UiState::sDisplayBrightness{ return true; }}; -lua::Property UiState::sControlsScheme{0, [](const lua::LuaValue& val) { - /* - if (!std::holds_alternative(val)) - { return false; - } - drivers::NvsStorage::InputModes mode; - switch (std::get(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 sensitivity = 0; - std::visit( - [&](auto&& v) { - using T = - std::decay_t; if - constexpr (std::is_same_v) { - 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}; @@ -374,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); } @@ -484,7 +431,10 @@ void Splash::react(const system_fsm::BootComplete& ev) { sDisplayBrightness.Update(brightness); sDisplay->SetBrightness(brightness); - sInput = std::make_shared(sServices); + sDeviceFactory = std::make_unique(sServices); + sInput = std::make_shared(sServices->nvs(), + *sDeviceFactory); + sTask->input(sInput); } @@ -542,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", -- cgit v1.2.3