summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2023-08-28 14:59:52 +1000
committerailurux <ailuruxx@gmail.com>2023-08-28 14:59:52 +1000
commitdb601935c6145445467692c0a4ff2b81e27cf6ce (patch)
treee2eed4a38abd03f14dba504ce5e8dedee0da6a12 /src/ui
parent6f4ace1dd4b9b34f95af1ba365b68624e209d147 (diff)
parent3a0c42f9240eedfbc6a1e94ad3a59c52664fb5b5 (diff)
downloadtangara-fw-db601935c6145445467692c0a4ff2b81e27cf6ce.tar.gz
Merge branch 'main' of git.sr.ht:~jacqueline/tangara-fw
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/CMakeLists.txt2
-rw-r--r--src/ui/include/screen_settings.hpp29
-rw-r--r--src/ui/include/ui_fsm.hpp8
-rw-r--r--src/ui/screen_playing.cpp8
-rw-r--r--src/ui/ui_fsm.cpp16
-rw-r--r--src/ui/widget_top_bar.cpp23
6 files changed, 53 insertions, 33 deletions
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<Screen> bluetooth_;
- std::shared_ptr<Screen> headphones_;
- std::shared_ptr<Screen> appearance_;
- std::shared_ptr<Screen> input_method_;
- std::shared_ptr<Screen> storage_;
- std::shared_ptr<Screen> firmware_update_;
- std::shared_ptr<Screen> about_;
+
+ private:
+ std::shared_ptr<Screen> bluetooth_;
+ std::shared_ptr<Screen> headphones_;
+ std::shared_ptr<Screen> appearance_;
+ std::shared_ptr<Screen> input_method_;
+ std::shared_ptr<Screen> storage_;
+ std::shared_ptr<Screen> firmware_update_;
+ std::shared_ptr<Screen> 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 <stack>
#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<UiState> {
public:
- static auto Init(drivers::IGpios*, audio::TrackQueue*) -> bool;
+ static auto Init(drivers::IGpios*,
+ audio::TrackQueue*,
+ std::shared_ptr<battery::Battery>) -> bool;
virtual ~UiState() {}
@@ -41,7 +44,7 @@ class UiState : public tinyfsm::Fsm<UiState> {
/* 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<UiState> {
static std::shared_ptr<drivers::TouchWheel> sTouchWheel;
static std::shared_ptr<drivers::RelativeWheel> sRelativeWheel;
static std::shared_ptr<drivers::Display> sDisplay;
+ static std::shared_ptr<battery::Battery> sBattery;
static std::weak_ptr<database::Database> sDb;
static std::stack<std::shared_ptr<Screen>> sScreens;
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 <sys/_stdint.h>
#include <memory>
+#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<database::Database> 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_,
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);
diff --git a/src/ui/widget_top_bar.cpp b/src/ui/widget_top_bar.cpp
index 458038a2..24c5e5bd 100644
--- a/src/ui/widget_top_bar.cpp
+++ b/src/ui/widget_top_bar.cpp
@@ -68,17 +68,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