From 320fdeb9d8355d3c361d5c6d60de8afc64501af9 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 30 Aug 2023 16:48:10 +1000 Subject: Use a service locator instead of passing around subsets of drivers between FSMs --- src/ui/include/ui_fsm.hpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'src/ui/include/ui_fsm.hpp') diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 1fa6bf26..12fe5c69 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -11,9 +11,12 @@ #include "audio_events.hpp" #include "battery.hpp" +#include "gpios.hpp" +#include "lvgl_task.hpp" #include "nvs.hpp" #include "relative_wheel.hpp" #include "screen_playing.hpp" +#include "service_locator.hpp" #include "tinyfsm.hpp" #include "display.hpp" @@ -24,15 +27,13 @@ #include "touchwheel.hpp" #include "track_queue.hpp" #include "ui_events.hpp" +#include "wheel_encoder.hpp" namespace ui { class UiState : public tinyfsm::Fsm { public: - static auto Init(drivers::IGpios*, - std::shared_ptr, - audio::TrackQueue*, - std::shared_ptr) -> bool; + static auto InitBootSplash(drivers::IGpios&) -> bool; virtual ~UiState() {} @@ -46,7 +47,7 @@ class UiState : public tinyfsm::Fsm { /* Fallback event handler. Does nothing. */ void react(const tinyfsm::Event& ev) {} - void react(const system_fsm::BatteryStateChanged&); + virtual void react(const system_fsm::BatteryStateChanged&); virtual void react(const audio::PlaybackStarted&) {} virtual void react(const audio::PlaybackUpdate&) {} @@ -76,15 +77,10 @@ class UiState : public tinyfsm::Fsm { void PopScreen(); void UpdateTopBar(); - static drivers::IGpios* sIGpios; - static audio::TrackQueue* sQueue; - - static std::shared_ptr sTouchWheel; - static std::shared_ptr sRelativeWheel; - static std::shared_ptr sDisplay; - static std::shared_ptr sBattery; - static std::shared_ptr sNvs; - static std::weak_ptr sDb; + static std::unique_ptr sTask; + static std::shared_ptr sServices; + static std::unique_ptr sDisplay; + static std::shared_ptr sEncoder; static std::stack> sScreens; static std::shared_ptr sCurrentScreen; @@ -97,6 +93,7 @@ class Splash : public UiState { public: void exit() override; void react(const system_fsm::BootComplete&) override; + void react(const system_fsm::BatteryStateChanged&) override{}; using UiState::react; }; -- cgit v1.2.3