summaryrefslogtreecommitdiff
path: root/src/ui/ui_fsm.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-05-19 21:21:27 +1000
committerjacqueline <me@jacqueline.id.au>2023-05-19 21:21:27 +1000
commita6ab1504058304012791281f9eb42c262745888f (patch)
treef82379cd1e66a8ae2f1afbae5cf083a8ab7acc53 /src/ui/ui_fsm.cpp
parentb320a6a863cf1c10dc79254af41f573730935564 (diff)
downloadtangara-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.cpp38
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)