From a1327763ab70dbf4996e032dd227de368f78f4ad Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 28 Aug 2023 10:36:18 +1000 Subject: Support play/pause toggling --- src/ui/screen_playing.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/ui') diff --git a/src/ui/screen_playing.cpp b/src/ui/screen_playing.cpp index ce0f71d6..7538d093 100644 --- a/src/ui/screen_playing.cpp +++ b/src/ui/screen_playing.cpp @@ -8,6 +8,7 @@ #include #include +#include "audio_events.hpp" #include "core/lv_event.h" #include "core/lv_obj.h" #include "core/lv_obj_scroll.h" @@ -63,6 +64,10 @@ static void below_fold_focus_cb(lv_event_t* ev) { instance->OnFocusBelowFold(); } +static void play_pause_cb(lv_event_t* ev) { + events::Audio().Dispatch(audio::TogglePlayPause{}); +} + static lv_style_t scrubber_style; auto info_label(lv_obj_t* parent) -> lv_obj_t* { @@ -159,7 +164,10 @@ Playing::Playing(std::weak_ptr db, audio::TrackQueue* queue) LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); play_pause_control_ = control_button(controls_container, LV_SYMBOL_PLAY); + lv_obj_add_event_cb(play_pause_control_, play_pause_cb, LV_EVENT_CLICKED, + NULL); lv_group_add_obj(group_, play_pause_control_); + lv_group_add_obj(group_, control_button(controls_container, LV_SYMBOL_PREV)); lv_group_add_obj(group_, control_button(controls_container, LV_SYMBOL_NEXT)); lv_group_add_obj(group_, -- cgit v1.2.3 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/CMakeLists.txt | 2 +- src/ui/include/screen_settings.hpp | 29 +++++++++++++++-------------- src/ui/include/ui_fsm.hpp | 8 ++++++-- src/ui/ui_fsm.cpp | 16 +++++++++++----- src/ui/widget_top_bar.cpp | 23 ++++++++++++----------- 5 files changed, 45 insertions(+), 33 deletions(-) (limited to 'src/ui') diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index fa3f2bc1..6b5c393a 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -9,5 +9,5 @@ idf_component_register( "modal_progress.cpp" "modal.cpp" "modal_confirm.cpp" "screen_settings.cpp" "splash.c" "font_fusion.c" "font_symbols.c" INCLUDE_DIRS "include" - REQUIRES "drivers" "lvgl" "tinyfsm" "events" "system_fsm" "database" "esp_timer") + REQUIRES "drivers" "lvgl" "tinyfsm" "events" "system_fsm" "database" "esp_timer" "battery") target_compile_options(${COMPONENT_LIB} PRIVATE ${EXTRA_WARNINGS}) diff --git a/src/ui/include/screen_settings.hpp b/src/ui/include/screen_settings.hpp index ebc5bf7d..66124164 100644 --- a/src/ui/include/screen_settings.hpp +++ b/src/ui/include/screen_settings.hpp @@ -21,14 +21,15 @@ class Settings : public MenuScreen { public: Settings(); ~Settings(); - private: - std::shared_ptr bluetooth_; - std::shared_ptr headphones_; - std::shared_ptr appearance_; - std::shared_ptr input_method_; - std::shared_ptr storage_; - std::shared_ptr firmware_update_; - std::shared_ptr about_; + + private: + std::shared_ptr bluetooth_; + std::shared_ptr headphones_; + std::shared_ptr appearance_; + std::shared_ptr input_method_; + std::shared_ptr storage_; + std::shared_ptr firmware_update_; + std::shared_ptr about_; }; class Bluetooth : public MenuScreen { @@ -36,32 +37,32 @@ class Bluetooth : public MenuScreen { Bluetooth(); }; -class Headphones : public MenuScreen { +class Headphones : public MenuScreen { public: Headphones(); }; -class Appearance : public MenuScreen { +class Appearance : public MenuScreen { public: Appearance(); }; -class InputMethod : public MenuScreen { +class InputMethod : public MenuScreen { public: InputMethod(); }; -class Storage : public MenuScreen { +class Storage : public MenuScreen { public: Storage(); }; -class FirmwareUpdate : public MenuScreen { +class FirmwareUpdate : public MenuScreen { public: FirmwareUpdate(); }; -class About : public MenuScreen { +class About : public MenuScreen { public: About(); }; diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 80c01c68..8f1aa1bc 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -10,6 +10,7 @@ #include #include "audio_events.hpp" +#include "battery.hpp" #include "relative_wheel.hpp" #include "screen_playing.hpp" #include "tinyfsm.hpp" @@ -27,7 +28,9 @@ namespace ui { class UiState : public tinyfsm::Fsm { public: - static auto Init(drivers::IGpios*, audio::TrackQueue*) -> bool; + static auto Init(drivers::IGpios*, + audio::TrackQueue*, + std::shared_ptr) -> bool; virtual ~UiState() {} @@ -41,7 +44,7 @@ class UiState : public tinyfsm::Fsm { /* Fallback event handler. Does nothing. */ void react(const tinyfsm::Event& ev) {} - void react(const system_fsm::BatteryPercentChanged&); + void react(const system_fsm::BatteryStateChanged&); virtual void react(const audio::PlaybackStarted&) {} virtual void react(const audio::PlaybackUpdate&) {} @@ -76,6 +79,7 @@ class UiState : public tinyfsm::Fsm { static std::shared_ptr sTouchWheel; static std::shared_ptr sRelativeWheel; static std::shared_ptr sDisplay; + static std::shared_ptr sBattery; static std::weak_ptr sDb; static std::stack> sScreens; 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); diff --git a/src/ui/widget_top_bar.cpp b/src/ui/widget_top_bar.cpp index 7d4ef98c..851b617f 100644 --- a/src/ui/widget_top_bar.cpp +++ b/src/ui/widget_top_bar.cpp @@ -65,17 +65,18 @@ auto TopBar::Update(const State& state) -> void { break; } - if (state.battery_percent >= 95) { - lv_label_set_text(battery_, "100"); - } else if (state.battery_percent >= 70) { - lv_label_set_text(battery_, ">70"); - } else if (state.battery_percent >= 40) { - lv_label_set_text(battery_, ">40"); - } else if (state.battery_percent >= 10) { - lv_label_set_text(battery_, ">10"); - } else { - lv_label_set_text(battery_, "0"); - } + lv_label_set_text(battery_, std::to_string(state.battery_percent).c_str()); + // if (state.battery_percent >= 95) { + // lv_label_set_text(battery_, "100"); + // } else if (state.battery_percent >= 70) { + // lv_label_set_text(battery_, ">70"); + // } else if (state.battery_percent >= 40) { + // lv_label_set_text(battery_, ">40"); + // } else if (state.battery_percent >= 10) { + // lv_label_set_text(battery_, ">10"); + // } else { + // lv_label_set_text(battery_, "0"); + // } } } // namespace widgets -- cgit v1.2.3