summaryrefslogtreecommitdiff
path: root/src/ui/ui_fsm.cpp
blob: f12104e6c98fb921f006649c93988fea7f2c8882 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * Copyright 2023 jacqueline <me@jacqueline.id.au>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#include "ui_fsm.hpp"
#include "display.hpp"
#include "lvgl_task.hpp"
#include "relative_wheel.hpp"
#include "screen.hpp"
#include "screen_menu.hpp"
#include "screen_splash.hpp"
#include "system_events.hpp"
#include "touchwheel.hpp"

namespace ui {

drivers::GpioExpander* UiState::sGpioExpander;
std::weak_ptr<drivers::RelativeWheel> UiState::sTouchWheel;
std::weak_ptr<drivers::Display> UiState::sDisplay;

std::shared_ptr<Screen> UiState::sCurrentScreen;

auto UiState::Init(drivers::GpioExpander* gpio_expander,
                   std::weak_ptr<drivers::RelativeWheel> touchwheel,
                   std::weak_ptr<drivers::Display> display) -> void {
  sGpioExpander = gpio_expander;
  sTouchWheel = touchwheel;
  sDisplay = display;
}

namespace states {

void PreBoot::react(const system_fsm::DisplayReady& ev) {
  transit<Splash>([&]() { StartLvgl(sTouchWheel, sDisplay); });
}

void Splash::entry() {
  sCurrentScreen.reset(new screens::Splash());
}

void Splash::react(const system_fsm::BootComplete& ev) {
  transit<Interactive>();
}

void Interactive::entry() {
  //sCurrentScreen.reset(new screens::Menu());
}

}  // namespace states
}  // namespace ui

FSM_INITIAL_STATE(ui::UiState, ui::states::PreBoot)