blob: dd5161ed56c223f712eeb976f3cc5bd695b7caf7 (
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
|
/*
* Copyright 2023 jacqueline <me@jacqueline.id.au>
*
* SPDX-License-Identifier: GPL-3.0-only
*/
#include "system_fsm.hpp"
#include "audio_fsm.hpp"
#include "event_queue.hpp"
#include "relative_wheel.hpp"
#include "system_events.hpp"
namespace system_fsm {
std::shared_ptr<drivers::GpioExpander> SystemState::sGpioExpander;
std::shared_ptr<drivers::Samd> SystemState::sSamd;
std::shared_ptr<drivers::TouchWheel> SystemState::sTouch;
std::shared_ptr<drivers::RelativeWheel> SystemState::sRelativeTouch;
std::shared_ptr<drivers::Battery> SystemState::sBattery;
std::shared_ptr<drivers::SdStorage> SystemState::sStorage;
std::shared_ptr<drivers::Display> SystemState::sDisplay;
std::shared_ptr<database::Database> SystemState::sDatabase;
console::AppConsole* SystemState::sAppConsole;
void SystemState::react(const FatalError& err) {
if (!is_in_state<states::Error>()) {
transit<states::Error>();
}
}
void SystemState::react(const internal::GpioInterrupt& ev) {
ESP_LOGI("sys", "gpios changed");
bool prev_key_up = sGpioExpander->get_input(drivers::GpioExpander::KEY_UP);
bool prev_key_down =
sGpioExpander->get_input(drivers::GpioExpander::KEY_DOWN);
bool prev_key_lock =
sGpioExpander->get_input(drivers::GpioExpander::KEY_LOCK);
bool prev_has_headphones =
sGpioExpander->get_input(drivers::GpioExpander::PHONE_DETECT);
sGpioExpander->Read();
bool key_up = sGpioExpander->get_input(drivers::GpioExpander::KEY_UP);
bool key_down = sGpioExpander->get_input(drivers::GpioExpander::KEY_DOWN);
bool key_lock = sGpioExpander->get_input(drivers::GpioExpander::KEY_LOCK);
bool has_headphones =
sGpioExpander->get_input(drivers::GpioExpander::PHONE_DETECT);
if (key_up != prev_key_up) {
events::Dispatch<KeyUpChanged, audio::AudioState, ui::UiState>(
{.falling = prev_key_up});
}
if (key_down != prev_key_down) {
events::Dispatch<KeyDownChanged, audio::AudioState, ui::UiState>(
{.falling = prev_key_down});
}
if (key_lock != prev_key_lock) {
events::Dispatch<KeyLockChanged, SystemState, ui::UiState>(
{.falling = prev_key_lock});
}
if (has_headphones != prev_has_headphones) {
events::Dispatch<HasPhonesChanged, audio::AudioState>(
{.falling = prev_has_headphones});
}
}
} // namespace system_fsm
FSM_INITIAL_STATE(system_fsm::SystemState, system_fsm::states::Booting)
|