summaryrefslogtreecommitdiff
path: root/src/ui/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/include')
-rw-r--r--src/ui/include/lvgl_task.hpp27
-rw-r--r--src/ui/include/screen_playing.hpp4
-rw-r--r--src/ui/include/screen_settings.hpp6
-rw-r--r--src/ui/include/ui_fsm.hpp25
-rw-r--r--src/ui/include/wheel_encoder.hpp4
5 files changed, 43 insertions, 23 deletions
diff --git a/src/ui/include/lvgl_task.hpp b/src/ui/include/lvgl_task.hpp
index 7e60c4b4..6b7e446e 100644
--- a/src/ui/include/lvgl_task.hpp
+++ b/src/ui/include/lvgl_task.hpp
@@ -12,15 +12,38 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
+#include "freertos/timers.h"
#include "display.hpp"
#include "relative_wheel.hpp"
+#include "screen.hpp"
#include "themes.hpp"
#include "touchwheel.hpp"
+#include "wheel_encoder.hpp"
namespace ui {
-auto StartLvgl(std::weak_ptr<drivers::RelativeWheel> touch_wheel,
- std::weak_ptr<drivers::Display> display) -> void;
+class UiTask {
+ public:
+ static auto Start() -> UiTask*;
+
+ ~UiTask();
+
+ // FIXME: Once we have more input devices, this function should accept a more
+ // generic interface.
+ auto SetInputDevice(std::shared_ptr<TouchWheelEncoder> dev) -> void;
+
+ private:
+ UiTask();
+
+ auto Main() -> void;
+
+ std::shared_ptr<TouchWheelEncoder> input_device_;
+ std::shared_ptr<Screen> current_screen_;
+
+ std::atomic<bool> quit_;
+ SemaphoreHandle_t frame_semaphore_;
+ TimerHandle_t frame_timer_;
+};
} // namespace ui
diff --git a/src/ui/include/screen_playing.hpp b/src/ui/include/screen_playing.hpp
index c684ddff..f2998c88 100644
--- a/src/ui/include/screen_playing.hpp
+++ b/src/ui/include/screen_playing.hpp
@@ -29,7 +29,7 @@ namespace screens {
class Playing : public Screen {
public:
explicit Playing(std::weak_ptr<database::Database> db,
- audio::TrackQueue* queue);
+ audio::TrackQueue& queue);
~Playing();
auto Tick() -> void override;
@@ -51,7 +51,7 @@ class Playing : public Screen {
auto ApplyNextUp(const std::vector<database::Track>& tracks) -> void;
std::weak_ptr<database::Database> db_;
- audio::TrackQueue* queue_;
+ audio::TrackQueue& queue_;
std::optional<database::Track> track_;
std::vector<database::Track> next_tracks_;
diff --git a/src/ui/include/screen_settings.hpp b/src/ui/include/screen_settings.hpp
index 61375fa9..0ec96d26 100644
--- a/src/ui/include/screen_settings.hpp
+++ b/src/ui/include/screen_settings.hpp
@@ -37,14 +37,14 @@ class Headphones : public MenuScreen {
class Appearance : public MenuScreen {
public:
- Appearance(drivers::NvsStorage* nvs, drivers::Display* display);
+ Appearance(drivers::NvsStorage& nvs, drivers::Display& display);
auto ChangeBrightness(uint_fast8_t) -> void;
auto CommitBrightness() -> void;
private:
- drivers::NvsStorage* nvs_;
- drivers::Display* display_;
+ drivers::NvsStorage& nvs_;
+ drivers::Display& display_;
lv_obj_t* current_brightness_label_;
uint_fast8_t current_brightness_;
diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp
index 1fa6bf26..12fe5c69 100644
--- a/src/ui/include/ui_fsm.hpp
+++ b/src/ui/include/ui_fsm.hpp
@@ -11,9 +11,12 @@
#include "audio_events.hpp"
#include "battery.hpp"
+#include "gpios.hpp"
+#include "lvgl_task.hpp"
#include "nvs.hpp"
#include "relative_wheel.hpp"
#include "screen_playing.hpp"
+#include "service_locator.hpp"
#include "tinyfsm.hpp"
#include "display.hpp"
@@ -24,15 +27,13 @@
#include "touchwheel.hpp"
#include "track_queue.hpp"
#include "ui_events.hpp"
+#include "wheel_encoder.hpp"
namespace ui {
class UiState : public tinyfsm::Fsm<UiState> {
public:
- static auto Init(drivers::IGpios*,
- std::shared_ptr<drivers::NvsStorage>,
- audio::TrackQueue*,
- std::shared_ptr<battery::Battery>) -> bool;
+ static auto InitBootSplash(drivers::IGpios&) -> bool;
virtual ~UiState() {}
@@ -46,7 +47,7 @@ class UiState : public tinyfsm::Fsm<UiState> {
/* Fallback event handler. Does nothing. */
void react(const tinyfsm::Event& ev) {}
- void react(const system_fsm::BatteryStateChanged&);
+ virtual void react(const system_fsm::BatteryStateChanged&);
virtual void react(const audio::PlaybackStarted&) {}
virtual void react(const audio::PlaybackUpdate&) {}
@@ -76,15 +77,10 @@ class UiState : public tinyfsm::Fsm<UiState> {
void PopScreen();
void UpdateTopBar();
- static drivers::IGpios* sIGpios;
- static audio::TrackQueue* sQueue;
-
- 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::shared_ptr<drivers::NvsStorage> sNvs;
- static std::weak_ptr<database::Database> sDb;
+ static std::unique_ptr<UiTask> sTask;
+ static std::shared_ptr<system_fsm::ServiceLocator> sServices;
+ static std::unique_ptr<drivers::Display> sDisplay;
+ static std::shared_ptr<TouchWheelEncoder> sEncoder;
static std::stack<std::shared_ptr<Screen>> sScreens;
static std::shared_ptr<Screen> sCurrentScreen;
@@ -97,6 +93,7 @@ class Splash : public UiState {
public:
void exit() override;
void react(const system_fsm::BootComplete&) override;
+ void react(const system_fsm::BatteryStateChanged&) override{};
using UiState::react;
};
diff --git a/src/ui/include/wheel_encoder.hpp b/src/ui/include/wheel_encoder.hpp
index c49e5929..fcac5edd 100644
--- a/src/ui/include/wheel_encoder.hpp
+++ b/src/ui/include/wheel_encoder.hpp
@@ -17,7 +17,7 @@ namespace ui {
class TouchWheelEncoder {
public:
- explicit TouchWheelEncoder(std::weak_ptr<drivers::RelativeWheel> wheel);
+ explicit TouchWheelEncoder(std::unique_ptr<drivers::RelativeWheel> wheel);
auto Read(lv_indev_data_t* data) -> void;
auto registration() -> lv_indev_t* { return registration_; }
@@ -27,7 +27,7 @@ class TouchWheelEncoder {
lv_indev_t* registration_;
lv_key_t last_key_;
- std::weak_ptr<drivers::RelativeWheel> wheel_;
+ std::unique_ptr<drivers::RelativeWheel> wheel_;
};
} // namespace ui