diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-05-19 21:21:27 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-05-19 21:21:27 +1000 |
| commit | a6ab1504058304012791281f9eb42c262745888f (patch) | |
| tree | f82379cd1e66a8ae2f1afbae5cf083a8ab7acc53 /src/ui/ui_fsm.cpp | |
| parent | b320a6a863cf1c10dc79254af41f573730935564 (diff) | |
| download | tangara-fw-a6ab1504058304012791281f9eb42c262745888f.tar.gz | |
Add tinyfsm, start converting core functions to an FSM-based event loop
Diffstat (limited to 'src/ui/ui_fsm.cpp')
| -rw-r--r-- | src/ui/ui_fsm.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
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<drivers::TouchWheel> UiState::sTouchWheel; +std::weak_ptr<drivers::Display> UiState::sDisplay; +std::weak_ptr<database::Database> UiState::sDatabase; +std::atomic<bool> UiState::sTaskQuit; + +auto UiState::Init(drivers::GpioExpander* gpio_expander, + std::weak_ptr<drivers::TouchWheel> touchwheel, + std::weak_ptr<drivers::Display> display, + std::weak_ptr<database::Database> database) -> void { + sGpioExpander = gpio_expander; + sTouchWheel = touchwheel; + sDisplay = display; + sDatabase = database; +} + +namespace states { + +void PreBoot::react(const system_fsm::DisplayReady& ev) { + transit<Splash>([&]() { StartLvgl(sTouchWheel, sDisplay, &sTaskQuit); }); +} + +void Splash::react(const system_fsm::BootComplete& ev) { + transit<Interactive>(); +} + +} // namespace states +} // namespace ui + +FSM_INITIAL_STATE(ui::UiState, ui::states::PreBoot) |
