From ed82063af5f83530afa5cfb5bf5bd516f3d05f2a Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 10 Apr 2024 16:56:10 +1000 Subject: WIP decompose our giant LVGL driver into smaller classes --- src/ui/ui_fsm.cpp | 122 +++++++++++++++++++++++++----------------------------- 1 file changed, 57 insertions(+), 65 deletions(-) (limited to 'src/ui/ui_fsm.cpp') diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index 28733123..a9c1d3a3 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -30,19 +30,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 +62,7 @@ namespace ui { std::unique_ptr UiState::sTask; std::shared_ptr UiState::sServices; std::unique_ptr UiState::sDisplay; -std::shared_ptr UiState::sInput; +std::shared_ptr UiState::sInput; std::stack> UiState::sScreens; std::shared_ptr UiState::sCurrentScreen; @@ -234,51 +233,58 @@ 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::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}; @@ -372,7 +378,7 @@ void UiState::react(const internal::ControlSchemeChanged&) { if (!sInput) { return; } - sInput->mode(sServices->nvs().PrimaryInput()); + // sInput->mode(sServices->nvs().PrimaryInput()); } void UiState::react(const database::event::UpdateStarted&) { @@ -478,22 +484,8 @@ void Splash::react(const system_fsm::BootComplete& ev) { sDisplayBrightness.Update(brightness); sDisplay->SetBrightness(brightness); - auto touchwheel = sServices->touchwheel(); - if (touchwheel) { - sInput = std::make_shared(sServices->gpios(), **touchwheel); - - auto mode = sServices->nvs().PrimaryInput(); - sInput->mode(mode); - sControlsScheme.Update(static_cast(mode)); - - auto sensitivity = sServices->nvs().ScrollSensitivity(); - sInput->scroll_sensitivity(sensitivity); - sScrollSensitivity.Update(static_cast(sensitivity)); - - sTask->input(sInput); - } else { - ESP_LOGE(kTag, "no input devices initialised!"); - } + sInput = std::make_shared(sServices); + sTask->input(sInput); } void Splash::react(const system_fsm::StorageMounted&) { -- cgit v1.2.3 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/ui_fsm.cpp | 88 +++++++++++++------------------------------------------ 1 file changed, 21 insertions(+), 67 deletions(-) (limited to 'src/ui/ui_fsm.cpp') 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