From 3a0c42f9240eedfbc6a1e94ad3a59c52664fb5b5 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 28 Aug 2023 13:26:53 +1000 Subject: Move battery measurement to its own class --- src/ui/ui_fsm.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/ui/ui_fsm.cpp') 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 +#include "battery.hpp" #include "core/lv_obj.h" #include "misc/lv_gc.h" @@ -43,16 +44,19 @@ audio::TrackQueue* UiState::sQueue; std::shared_ptr UiState::sTouchWheel; std::shared_ptr UiState::sRelativeWheel; std::shared_ptr UiState::sDisplay; +std::shared_ptr UiState::sBattery; std::weak_ptr UiState::sDb; std::stack> UiState::sScreens; std::shared_ptr UiState::sCurrentScreen; std::shared_ptr 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) -> 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( + battery_state.has_value() ? battery_state->percent : 100), + .is_charging = !battery_state.has_value() || battery_state->is_charging, }; if (sCurrentScreen) { sCurrentScreen->UpdateTopBar(state); -- cgit v1.2.3