blob: 9e81259a9e86551bc4e8151c967c35984d474310 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#pragma once
#include <stdint.h>
#include <sys/_stdint.h>
#include <memory>
#include <stack>
#include "audio_events.hpp"
#include "battery.hpp"
#include "bindey/property.h"
#include "db_events.hpp"
#include "gpios.hpp"
#include "lua_thread.hpp"
#include "lvgl_task.hpp"
#include "model_playback.hpp"
#include "model_top_bar.hpp"
#include "nvs.hpp"
#include "property.hpp"
#include "relative_wheel.hpp"
#include "screen_playing.hpp"
#include "screen_settings.hpp"
#include "service_locator.hpp"
#include "tinyfsm.hpp"
#include "display.hpp"
#include "encoder_input.hpp"
#include "modal.hpp"
#include "screen.hpp"
#include "storage.hpp"
#include "system_events.hpp"
#include "touchwheel.hpp"
#include "track.hpp"
#include "track_queue.hpp"
#include "ui_events.hpp"
namespace ui {
class UiState : public tinyfsm::Fsm<UiState> {
public:
static auto InitBootSplash(drivers::IGpios&) -> bool;
virtual ~UiState() {}
static auto current_screen() -> std::shared_ptr<Screen> {
return sCurrentScreen;
}
virtual void entry() {}
virtual void exit() {}
/* Fallback event handler. Does nothing. */
void react(const tinyfsm::Event& ev) {}
virtual void react(const system_fsm::BatteryStateChanged&);
virtual void react(const audio::PlaybackStarted&);
virtual void react(const audio::PlaybackFinished&);
void react(const audio::PlaybackUpdate&);
void react(const audio::QueueUpdate&);
virtual void react(const system_fsm::KeyLockChanged&);
virtual void react(const OnLuaError&) {}
virtual void react(const internal::RecordSelected&) {}
virtual void react(const internal::IndexSelected&) {}
virtual void react(const internal::BackPressed&) {}
virtual void react(const internal::ShowNowPlaying&){};
virtual void react(const internal::ShowSettingsPage&){};
virtual void react(const internal::ModalCancelPressed&) {
sCurrentModal.reset();
}
virtual void react(const internal::ModalConfirmPressed&) {
sCurrentModal.reset();
}
virtual void react(const internal::OnboardingNavigate&) {}
void react(const internal::ControlSchemeChanged&);
virtual void react(const internal::ReindexDatabase&){};
virtual void react(const database::event::UpdateStarted&){};
virtual void react(const database::event::UpdateProgress&){};
virtual void react(const database::event::UpdateFinished&){};
virtual void react(const system_fsm::DisplayReady&) {}
virtual void react(const system_fsm::BootComplete&) {}
virtual void react(const system_fsm::StorageMounted&) {}
virtual void react(const system_fsm::BluetoothDevicesChanged&) {}
protected:
void PushScreen(std::shared_ptr<Screen>);
int PopScreen();
static std::unique_ptr<UiTask> sTask;
static std::shared_ptr<system_fsm::ServiceLocator> sServices;
static std::unique_ptr<drivers::Display> sDisplay;
static std::shared_ptr<EncoderInput> sInput;
static std::stack<std::shared_ptr<Screen>> sScreens;
static std::shared_ptr<Screen> sCurrentScreen;
static std::shared_ptr<Modal> sCurrentModal;
static std::shared_ptr<lua::LuaThread> sLua;
static std::weak_ptr<screens::Bluetooth> bluetooth_screen_;
static models::Playback sPlaybackModel;
static models::TopBar sTopBarModel;
};
namespace states {
class Splash : public UiState {
public:
void exit() override;
void react(const system_fsm::BootComplete&) override;
void react(const system_fsm::StorageMounted&) override;
using UiState::react;
};
class Lua : public UiState {
public:
void entry() override;
void exit() override;
void react(const OnLuaError&) override;
void react(const internal::IndexSelected&) override;
void react(const internal::ShowNowPlaying&) override;
void react(const internal::ShowSettingsPage&) override;
void react(const system_fsm::BatteryStateChanged&) override;
void react(const audio::PlaybackStarted&) override;
void react(const audio::PlaybackFinished&) override;
using UiState::react;
private:
auto PushLuaScreen(lua_State*) -> int;
auto PopLuaScreen(lua_State*) -> int;
std::shared_ptr<lua::Property> battery_pct_;
std::shared_ptr<lua::Property> battery_mv_;
std::shared_ptr<lua::Property> battery_charging_;
std::shared_ptr<lua::Property> bluetooth_en_;
std::shared_ptr<lua::Property> playback_playing_;
std::shared_ptr<lua::Property> playback_track_;
};
class Onboarding : public UiState {
public:
void entry() override;
void react(const internal::OnboardingNavigate&) override;
using UiState::react;
private:
uint8_t progress_;
bool has_formatted_;
};
class Browse : public UiState {
public:
void entry() override;
void react(const internal::RecordSelected&) override;
void react(const internal::BackPressed&) override;
void react(const internal::ShowNowPlaying&) override;
void react(const internal::ShowSettingsPage&) override;
void react(const internal::ReindexDatabase&) override;
void react(const system_fsm::BluetoothDevicesChanged&) override;
using UiState::react;
};
class Playing : public UiState {
public:
void entry() override;
void exit() override;
void react(const internal::BackPressed&) override;
using UiState::react;
};
class Indexing : public UiState {
public:
void entry() override;
void exit() override;
void react(const database::event::UpdateStarted&) override;
void react(const database::event::UpdateProgress&) override;
void react(const database::event::UpdateFinished&) override;
using UiState::react;
};
class FatalError : public UiState {};
} // namespace states
} // namespace ui
|