Support play/pause toggling
This commit is contained in:
+11
-1
@@ -133,6 +133,12 @@ void Standby::react(const QueueUpdate& ev) {
|
||||
sFileSource->SetPath(db->GetTrackPath(*current_track));
|
||||
}
|
||||
|
||||
void Standby::react(const TogglePlayPause& ev) {
|
||||
if (sCurrentTrack) {
|
||||
transit<Playback>();
|
||||
}
|
||||
}
|
||||
|
||||
void Playback::entry() {
|
||||
ESP_LOGI(kTag, "beginning playback");
|
||||
sOutput->SetInUse(true);
|
||||
@@ -142,7 +148,7 @@ void Playback::exit() {
|
||||
ESP_LOGI(kTag, "finishing playback");
|
||||
// TODO(jacqueline): Second case where it's useful to wait for the i2s buffer
|
||||
// to drain.
|
||||
vTaskDelay(pdMS_TO_TICKS(250));
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
sOutput->SetInUse(false);
|
||||
|
||||
events::System().Dispatch(PlaybackFinished{});
|
||||
@@ -170,6 +176,10 @@ void Playback::react(const QueueUpdate& ev) {
|
||||
sFileSource->SetPath(db->GetTrackPath(*current_track));
|
||||
}
|
||||
|
||||
void Playback::react(const TogglePlayPause& ev) {
|
||||
transit<Standby>();
|
||||
}
|
||||
|
||||
void Playback::react(const PlaybackUpdate& ev) {
|
||||
ESP_LOGI(kTag, "elapsed: %lu, total: %lu", ev.seconds_elapsed,
|
||||
ev.seconds_total);
|
||||
|
||||
@@ -37,6 +37,8 @@ struct PlayFile : tinyfsm::Event {
|
||||
|
||||
struct VolumeChanged : tinyfsm::Event {};
|
||||
|
||||
struct TogglePlayPause : tinyfsm::Event {};
|
||||
|
||||
namespace internal {
|
||||
|
||||
struct InputFileOpened : tinyfsm::Event {};
|
||||
|
||||
@@ -57,6 +57,7 @@ class AudioState : public tinyfsm::Fsm<AudioState> {
|
||||
virtual void react(const PlayFile&) {}
|
||||
virtual void react(const QueueUpdate&) {}
|
||||
virtual void react(const PlaybackUpdate&) {}
|
||||
virtual void react(const TogglePlayPause&) {}
|
||||
|
||||
virtual void react(const internal::InputFileOpened&) {}
|
||||
virtual void react(const internal::InputFileClosed&) {}
|
||||
@@ -90,6 +91,7 @@ class Standby : public AudioState {
|
||||
void react(const PlayFile&) override;
|
||||
void react(const internal::InputFileOpened&) override;
|
||||
void react(const QueueUpdate&) override;
|
||||
void react(const TogglePlayPause&) override;
|
||||
|
||||
using AudioState::react;
|
||||
};
|
||||
@@ -102,6 +104,7 @@ class Playback : public AudioState {
|
||||
void react(const PlayFile&) override;
|
||||
void react(const QueueUpdate&) override;
|
||||
void react(const PlaybackUpdate&) override;
|
||||
void react(const TogglePlayPause&) override;
|
||||
|
||||
void react(const internal::InputFileOpened&) override;
|
||||
void react(const internal::InputFileClosed&) override;
|
||||
|
||||
@@ -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_,
|
||||
|
||||
Reference in New Issue
Block a user