summaryrefslogtreecommitdiff
path: root/src/audio
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-01-05 10:38:35 +1100
committerjacqueline <me@jacqueline.id.au>2024-01-05 10:38:35 +1100
commit34cae4e6e4bb00b3453bcdab084368a949c908a4 (patch)
tree024caadd70ea35ab2c73cc782f3a37c93a90702f /src/audio
parent938ba62f57ed2c002bae4aec236eeaeb200e4cba (diff)
downloadtangara-fw-34cae4e6e4bb00b3453bcdab084368a949c908a4.tar.gz
add an alerts module for lua, and implement a volume indicator with it
Diffstat (limited to 'src/audio')
-rw-r--r--src/audio/audio_fsm.cpp12
-rw-r--r--src/audio/i2s_audio_output.cpp1
-rw-r--r--src/audio/include/audio_events.hpp5
3 files changed, 13 insertions, 5 deletions
diff --git a/src/audio/audio_fsm.cpp b/src/audio/audio_fsm.cpp
index a5179156..a2f467cb 100644
--- a/src/audio/audio_fsm.cpp
+++ b/src/audio/audio_fsm.cpp
@@ -58,13 +58,19 @@ void AudioState::react(const system_fsm::KeyLockChanged& ev) {
void AudioState::react(const StepUpVolume& ev) {
if (sOutput->AdjustVolumeUp()) {
- events::Ui().Dispatch(VolumeChanged{});
+ events::Ui().Dispatch(VolumeChanged{
+ .percent = sOutput->GetVolumePct(),
+ .db = sOutput->GetVolumeDb(),
+ });
}
}
void AudioState::react(const StepDownVolume& ev) {
if (sOutput->AdjustVolumeDown()) {
- events::Ui().Dispatch(VolumeChanged{});
+ events::Ui().Dispatch(VolumeChanged{
+ .percent = sOutput->GetVolumePct(),
+ .db = sOutput->GetVolumeDb(),
+ });
}
}
@@ -77,7 +83,7 @@ void AudioState::react(const system_fsm::HasPhonesChanged& ev) {
}
void AudioState::react(const ChangeMaxVolume& ev) {
- ESP_LOGI(kTag, "new max volume %u db",
+ ESP_LOGI(kTag, "new max volume %i db",
(ev.new_max - drivers::wm8523::kLineLevelReferenceVolume) / 4);
sI2SOutput->SetMaxVolume(ev.new_max);
sServices->nvs().AmpMaxVolume(ev.new_max);
diff --git a/src/audio/i2s_audio_output.cpp b/src/audio/i2s_audio_output.cpp
index 29d70fb5..4043574e 100644
--- a/src/audio/i2s_audio_output.cpp
+++ b/src/audio/i2s_audio_output.cpp
@@ -93,7 +93,6 @@ auto I2SAudioOutput::SetMaxVolume(uint16_t max) -> void {
auto I2SAudioOutput::SetVolume(uint16_t vol) -> void {
current_volume_ = std::clamp(vol, kMinVolume, max_volume_);
- ESP_LOGI(kTag, "set volume to %u%% = %idB", GetVolumePct(), GetVolumeDb());
int32_t left_unclamped = current_volume_ + left_difference_;
uint16_t left = std::clamp<int32_t>(left_unclamped, kMinVolume, max_volume_);
diff --git a/src/audio/include/audio_events.hpp b/src/audio/include/audio_events.hpp
index 68efcafb..3c5ab723 100644
--- a/src/audio/include/audio_events.hpp
+++ b/src/audio/include/audio_events.hpp
@@ -47,7 +47,10 @@ struct PlayFile : tinyfsm::Event {
struct StepUpVolume : tinyfsm::Event {};
struct StepDownVolume : tinyfsm::Event {};
-struct VolumeChanged : tinyfsm::Event {};
+struct VolumeChanged : tinyfsm::Event {
+ uint_fast8_t percent;
+ int db;
+};
struct ChangeMaxVolume : tinyfsm::Event {
uint16_t new_max;
};