diff options
| author | ailurux <ailuruxx@gmail.com> | 2023-08-28 14:59:52 +1000 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2023-08-28 14:59:52 +1000 |
| commit | db601935c6145445467692c0a4ff2b81e27cf6ce (patch) | |
| tree | e2eed4a38abd03f14dba504ce5e8dedee0da6a12 /src/ui/ui_fsm.cpp | |
| parent | 6f4ace1dd4b9b34f95af1ba365b68624e209d147 (diff) | |
| parent | 3a0c42f9240eedfbc6a1e94ad3a59c52664fb5b5 (diff) | |
| download | tangara-fw-db601935c6145445467692c0a4ff2b81e27cf6ce.tar.gz | |
Merge branch 'main' of git.sr.ht:~jacqueline/tangara-fw
Diffstat (limited to 'src/ui/ui_fsm.cpp')
| -rw-r--r-- | src/ui/ui_fsm.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index 508fb740..32032978 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -8,6 +8,7 @@ #include <memory> +#include "battery.hpp" #include "core/lv_obj.h" #include "misc/lv_gc.h" @@ -43,16 +44,19 @@ audio::TrackQueue* UiState::sQueue; std::shared_ptr<drivers::TouchWheel> UiState::sTouchWheel; std::shared_ptr<drivers::RelativeWheel> UiState::sRelativeWheel; std::shared_ptr<drivers::Display> UiState::sDisplay; +std::shared_ptr<battery::Battery> UiState::sBattery; std::weak_ptr<database::Database> UiState::sDb; std::stack<std::shared_ptr<Screen>> UiState::sScreens; std::shared_ptr<Screen> UiState::sCurrentScreen; std::shared_ptr<Modal> UiState::sCurrentModal; -auto UiState::Init(drivers::IGpios* gpio_expander, audio::TrackQueue* queue) - -> bool { +auto UiState::Init(drivers::IGpios* gpio_expander, + audio::TrackQueue* queue, + std::shared_ptr<battery::Battery> battery) -> bool { sIGpios = gpio_expander; sQueue = queue; + sBattery = battery; lv_init(); sDisplay.reset( @@ -100,15 +104,17 @@ void UiState::react(const system_fsm::KeyLockChanged& ev) { sRelativeWheel->SetEnabled(ev.falling); } -void UiState::react(const system_fsm::BatteryPercentChanged&) { +void UiState::react(const system_fsm::BatteryStateChanged&) { UpdateTopBar(); } void UiState::UpdateTopBar() { + auto battery_state = sBattery->State(); widgets::TopBar::State state{ .playback_state = widgets::TopBar::PlaybackState::kIdle, - .battery_percent = 50, - .is_charging = true, + .battery_percent = static_cast<uint_fast8_t>( + battery_state.has_value() ? battery_state->percent : 100), + .is_charging = !battery_state.has_value() || battery_state->is_charging, }; if (sCurrentScreen) { sCurrentScreen->UpdateTopBar(state); |
