summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-09-05 09:51:10 +1000
committerjacqueline <me@jacqueline.id.au>2023-09-05 09:51:10 +1000
commit0032896251d8ddc6c2775495445da8fceffba98e (patch)
tree5a7f981a832977c153bc9a292305b61605b8eb66 /src/ui
parent382d82a14b1427f18a05eae7fb7763d4fa5bc319 (diff)
downloadtangara-fw-0032896251d8ddc6c2775495445da8fceffba98e.tar.gz
Move UI task to priority 0 during playback
Also other misc task cleanup
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/include/lvgl_task.hpp4
-rw-r--r--src/ui/include/ui_fsm.hpp5
-rw-r--r--src/ui/lvgl_task.cpp26
-rw-r--r--src/ui/ui_fsm.cpp9
4 files changed, 15 insertions, 29 deletions
diff --git a/src/ui/include/lvgl_task.hpp b/src/ui/include/lvgl_task.hpp
index 6b7e446e..4362249b 100644
--- a/src/ui/include/lvgl_task.hpp
+++ b/src/ui/include/lvgl_task.hpp
@@ -40,10 +40,6 @@ class UiTask {
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/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp
index 12fe5c69..7ac9c7b6 100644
--- a/src/ui/include/ui_fsm.hpp
+++ b/src/ui/include/ui_fsm.hpp
@@ -48,10 +48,9 @@ class UiState : public tinyfsm::Fsm<UiState> {
void react(const tinyfsm::Event& ev) {}
virtual void react(const system_fsm::BatteryStateChanged&);
-
- virtual void react(const audio::PlaybackStarted&) {}
+ virtual void react(const audio::PlaybackStarted&);
+ virtual void react(const audio::PlaybackFinished&);
virtual void react(const audio::PlaybackUpdate&) {}
- virtual void react(const audio::PlaybackFinished&) {}
virtual void react(const audio::QueueUpdate&) {}
virtual void react(const system_fsm::KeyLockChanged&);
diff --git a/src/ui/lvgl_task.cpp b/src/ui/lvgl_task.cpp
index a0f14f7d..74f68cf5 100644
--- a/src/ui/lvgl_task.cpp
+++ b/src/ui/lvgl_task.cpp
@@ -49,24 +49,8 @@
namespace ui {
static const char* kTag = "ui_task";
-static const TickType_t kMaxFrameRate = pdMS_TO_TICKS(100);
-static auto next_frame(TimerHandle_t t) {
- SemaphoreHandle_t sem =
- reinterpret_cast<SemaphoreHandle_t>(pvTimerGetTimerID(t));
- xSemaphoreGive(sem);
-}
-
-UiTask::UiTask()
- : quit_(false),
- frame_semaphore_(xSemaphoreCreateBinary()),
- frame_timer_(xTimerCreate("ui_frame",
- kMaxFrameRate,
- pdTRUE,
- frame_semaphore_,
- next_frame)) {
- xTimerStart(frame_timer_, portMAX_DELAY);
-}
+UiTask::UiTask() {}
UiTask::~UiTask() {
assert(false);
@@ -98,10 +82,8 @@ auto UiTask::Main() -> void {
current_screen_->Tick();
}
- lv_task_handler();
-
- // Wait for the signal to loop again.
- xSemaphoreTake(frame_semaphore_, portMAX_DELAY);
+ TickType_t delay = lv_timer_handler();
+ vTaskDelay(pdMS_TO_TICKS(std::clamp<TickType_t>(delay, 0, 100)));
}
}
@@ -114,7 +96,7 @@ auto UiTask::SetInputDevice(std::shared_ptr<TouchWheelEncoder> dev) -> void {
auto UiTask::Start() -> UiTask* {
UiTask* ret = new UiTask();
- tasks::StartPersistent<tasks::Type::kUi>(0, [=]() { ret->Main(); });
+ tasks::StartPersistent<tasks::Type::kUi>([=]() { ret->Main(); });
return ret;
}
diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp
index e874418b..c463933f 100644
--- a/src/ui/ui_fsm.cpp
+++ b/src/ui/ui_fsm.cpp
@@ -90,6 +90,13 @@ void UiState::react(const system_fsm::BatteryStateChanged&) {
UpdateTopBar();
}
+void UiState::react(const audio::PlaybackStarted&) {
+ vTaskPrioritySet(NULL, 0);
+}
+void UiState::react(const audio::PlaybackFinished&) {
+ vTaskPrioritySet(NULL, 10);
+}
+
void UiState::UpdateTopBar() {
auto battery_state = sServices->battery().State();
bool has_queue = sServices->track_queue().GetCurrent().has_value();
@@ -251,6 +258,7 @@ void Playing::exit() {
}
void Playing::react(const audio::PlaybackStarted& ev) {
+ vTaskPrioritySet(NULL, 0);
UpdateTopBar();
sPlayingScreen->OnTrackUpdate();
}
@@ -261,6 +269,7 @@ void Playing::react(const audio::PlaybackUpdate& ev) {
void Playing::react(const audio::PlaybackFinished& ev) {
UpdateTopBar();
+ vTaskPrioritySet(NULL, 10);
}
void Playing::react(const audio::QueueUpdate& ev) {