From a6ab1504058304012791281f9eb42c262745888f Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 19 May 2023 21:21:27 +1000 Subject: Add tinyfsm, start converting core functions to an FSM-based event loop --- src/ui/ui_fsm.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/ui/ui_fsm.cpp (limited to 'src/ui/ui_fsm.cpp') diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp new file mode 100644 index 00000000..8ca201e2 --- /dev/null +++ b/src/ui/ui_fsm.cpp @@ -0,0 +1,38 @@ +#include "ui_fsm.hpp" +#include "display.hpp" +#include "lvgl_task.hpp" +#include "system_events.hpp" +#include "touchwheel.hpp" + +namespace ui { + +drivers::GpioExpander* UiState::sGpioExpander; +std::weak_ptr UiState::sTouchWheel; +std::weak_ptr UiState::sDisplay; +std::weak_ptr UiState::sDatabase; +std::atomic UiState::sTaskQuit; + +auto UiState::Init(drivers::GpioExpander* gpio_expander, + std::weak_ptr touchwheel, + std::weak_ptr display, + std::weak_ptr database) -> void { + sGpioExpander = gpio_expander; + sTouchWheel = touchwheel; + sDisplay = display; + sDatabase = database; +} + +namespace states { + +void PreBoot::react(const system_fsm::DisplayReady& ev) { + transit([&]() { StartLvgl(sTouchWheel, sDisplay, &sTaskQuit); }); +} + +void Splash::react(const system_fsm::BootComplete& ev) { + transit(); +} + +} // namespace states +} // namespace ui + +FSM_INITIAL_STATE(ui::UiState, ui::states::PreBoot) -- cgit v1.2.3