diff options
Diffstat (limited to 'src/audio')
| -rw-r--r-- | src/audio/audio_fsm.cpp | 3 | ||||
| -rw-r--r-- | src/audio/bt_audio_output.cpp | 28 | ||||
| -rw-r--r-- | src/audio/include/bt_audio_output.hpp | 8 |
3 files changed, 30 insertions, 9 deletions
diff --git a/src/audio/audio_fsm.cpp b/src/audio/audio_fsm.cpp index b060d3e4..31d006fe 100644 --- a/src/audio/audio_fsm.cpp +++ b/src/audio/audio_fsm.cpp @@ -171,7 +171,8 @@ void Uninitialised::react(const system_fsm::BootComplete& ev) { sFileSource.reset( new FatfsAudioInput(sServices->tag_parser(), sServices->bg_worker())); sI2SOutput.reset(new I2SAudioOutput(stream, sServices->gpios())); - sBtOutput.reset(new BluetoothAudioOutput(stream, sServices->bluetooth())); + sBtOutput.reset(new BluetoothAudioOutput(stream, sServices->bluetooth(), + sServices->bg_worker())); auto& nvs = sServices->nvs(); sI2SOutput->SetMaxVolume(nvs.AmpMaxVolume()); diff --git a/src/audio/bt_audio_output.cpp b/src/audio/bt_audio_output.cpp index 0c11481b..41c89069 100644 --- a/src/audio/bt_audio_output.cpp +++ b/src/audio/bt_audio_output.cpp @@ -21,6 +21,7 @@ #include "i2c.hpp" #include "i2s_dac.hpp" #include "result.hpp" +#include "tasks.hpp" #include "wm8523.hpp" [[maybe_unused]] static const char* kTag = "BTOUT"; @@ -28,8 +29,9 @@ namespace audio { BluetoothAudioOutput::BluetoothAudioOutput(StreamBufferHandle_t s, - drivers::Bluetooth& bt) - : IAudioOutput(s), bluetooth_(bt) {} + drivers::Bluetooth& bt, + tasks::WorkerPool& p) + : IAudioOutput(s), bluetooth_(bt), bg_worker_(p), volume_(10) {} BluetoothAudioOutput::~BluetoothAudioOutput() {} @@ -43,14 +45,16 @@ auto BluetoothAudioOutput::SetMode(Modes mode) -> void { auto BluetoothAudioOutput::SetVolumeImbalance(int_fast8_t balance) -> void {} -auto BluetoothAudioOutput::SetVolume(uint16_t) -> void {} +auto BluetoothAudioOutput::SetVolume(uint16_t v) -> void { + volume_ = std::clamp<uint16_t>(v, 0, 0x7f); +} auto BluetoothAudioOutput::GetVolume() -> uint16_t { - return 0; + return volume_; } auto BluetoothAudioOutput::GetVolumePct() -> uint_fast8_t { - return 0; + return static_cast<uint_fast8_t>(static_cast<int>(volume_) * 100 / 0x7f); } auto BluetoothAudioOutput::GetVolumeDb() -> int_fast16_t { @@ -58,11 +62,21 @@ auto BluetoothAudioOutput::GetVolumeDb() -> int_fast16_t { } auto BluetoothAudioOutput::AdjustVolumeUp() -> bool { - return false; + if (volume_ == 0x7f) { + return false; + } + volume_++; + bg_worker_.Dispatch<void>([&]() { bluetooth_.SetVolume(volume_); }); + return true; } auto BluetoothAudioOutput::AdjustVolumeDown() -> bool { - return false; + if (volume_ == 0) { + return false; + } + volume_--; + bg_worker_.Dispatch<void>([&]() { bluetooth_.SetVolume(volume_); }); + return true; } auto BluetoothAudioOutput::PrepareFormat(const Format& orig) -> Format { diff --git a/src/audio/include/bt_audio_output.hpp b/src/audio/include/bt_audio_output.hpp index f23ccd6a..f6d2200c 100644 --- a/src/audio/include/bt_audio_output.hpp +++ b/src/audio/include/bt_audio_output.hpp @@ -6,6 +6,7 @@ #pragma once +#include <stdint.h> #include <cstdint> #include <memory> #include <vector> @@ -16,12 +17,15 @@ #include "bluetooth.hpp" #include "gpios.hpp" #include "i2s_dac.hpp" +#include "tasks.hpp" namespace audio { class BluetoothAudioOutput : public IAudioOutput { public: - BluetoothAudioOutput(StreamBufferHandle_t, drivers::Bluetooth& bt); + BluetoothAudioOutput(StreamBufferHandle_t, + drivers::Bluetooth& bt, + tasks::WorkerPool&); ~BluetoothAudioOutput(); auto SetMode(Modes) -> void override; @@ -46,6 +50,8 @@ class BluetoothAudioOutput : public IAudioOutput { private: drivers::Bluetooth& bluetooth_; + tasks::WorkerPool& bg_worker_; + uint8_t volume_; }; } // namespace audio |
