Audio fsm usability tweaks

- persist the current volume when the screen locks
 - pause playback if headphones are removed
custom
jacqueline 1 year ago
parent ae72566c0e
commit 414f139ae3
  1. 18
      src/audio/audio_fsm.cpp
  2. 5
      src/audio/include/audio_fsm.hpp
  3. 2
      src/system_fsm/include/system_events.hpp
  4. 3
      src/system_fsm/system_fsm.cpp

@ -50,6 +50,12 @@ std::shared_ptr<IAudioOutput> AudioState::sOutput;
std::optional<database::TrackId> AudioState::sCurrentTrack; std::optional<database::TrackId> AudioState::sCurrentTrack;
void AudioState::react(const system_fsm::KeyLockChanged& ev) {
if (ev.locking && sServices) {
sServices->nvs().AmpCurrentVolume(sOutput->GetVolume());
}
}
void AudioState::react(const StepUpVolume& ev) { void AudioState::react(const StepUpVolume& ev) {
if (sOutput->AdjustVolumeUp()) { if (sOutput->AdjustVolumeUp()) {
events::Ui().Dispatch(VolumeChanged{}); events::Ui().Dispatch(VolumeChanged{});
@ -63,10 +69,10 @@ void AudioState::react(const StepDownVolume& ev) {
} }
void AudioState::react(const system_fsm::HasPhonesChanged& ev) { void AudioState::react(const system_fsm::HasPhonesChanged& ev) {
if (ev.falling) { if (ev.has_headphones) {
// ESP_LOGI(kTag, "headphones in!"); ESP_LOGI(kTag, "headphones in!");
} else { } else {
// ESP_LOGI(kTag, "headphones out!"); ESP_LOGI(kTag, "headphones out!");
} }
} }
@ -186,6 +192,12 @@ void Playback::exit() {
events::Ui().Dispatch(PlaybackFinished{}); events::Ui().Dispatch(PlaybackFinished{});
} }
void Playback::react(const system_fsm::HasPhonesChanged& ev) {
if (!ev.has_headphones) {
transit<Standby>();
}
}
void Playback::react(const QueueUpdate& ev) { void Playback::react(const QueueUpdate& ev) {
if (!ev.current_changed) { if (!ev.current_changed) {
return; return;

@ -43,11 +43,12 @@ class AudioState : public tinyfsm::Fsm<AudioState> {
void react(const StepUpVolume&); void react(const StepUpVolume&);
void react(const StepDownVolume&); void react(const StepDownVolume&);
void react(const system_fsm::HasPhonesChanged&); virtual void react(const system_fsm::HasPhonesChanged&);
void react(const ChangeMaxVolume&); void react(const ChangeMaxVolume&);
void react(const OutputModeChanged&); void react(const OutputModeChanged&);
virtual void react(const system_fsm::BootComplete&) {} virtual void react(const system_fsm::BootComplete&) {}
void react(const system_fsm::KeyLockChanged&);
virtual void react(const PlayFile&) {} virtual void react(const PlayFile&) {}
virtual void react(const QueueUpdate&) {} virtual void react(const QueueUpdate&) {}
@ -97,6 +98,8 @@ class Playback : public AudioState {
void entry() override; void entry() override;
void exit() override; void exit() override;
void react(const system_fsm::HasPhonesChanged&) override;
void react(const PlayFile&) override; void react(const PlayFile&) override;
void react(const QueueUpdate&) override; void react(const QueueUpdate&) override;
void react(const PlaybackUpdate&) override; void react(const PlaybackUpdate&) override;

@ -46,7 +46,7 @@ struct KeyLockChanged : tinyfsm::Event {
bool locking; bool locking;
}; };
struct HasPhonesChanged : tinyfsm::Event { struct HasPhonesChanged : tinyfsm::Event {
bool falling; bool has_headphones;
}; };
struct ChargingStatusChanged : tinyfsm::Event {}; struct ChargingStatusChanged : tinyfsm::Event {};

@ -57,10 +57,11 @@ void SystemState::react(const internal::GpioInterrupt&) {
if (key_lock != prev_key_lock) { if (key_lock != prev_key_lock) {
KeyLockChanged ev{.locking = key_lock}; KeyLockChanged ev{.locking = key_lock};
events::System().Dispatch(ev); events::System().Dispatch(ev);
events::Audio().Dispatch(ev);
events::Ui().Dispatch(ev); events::Ui().Dispatch(ev);
} }
if (has_headphones != prev_has_headphones) { if (has_headphones != prev_has_headphones) {
HasPhonesChanged ev{.falling = prev_has_headphones}; HasPhonesChanged ev{.has_headphones = has_headphones};
events::Audio().Dispatch(ev); events::Audio().Dispatch(ev);
} }
} }

Loading…
Cancel
Save