Merge branch 'main' of codeberg.org:cool-tech-zone/tangara-fw
This commit is contained in:
@@ -1379,7 +1379,7 @@ end
|
|||||||
--- @field pad_gap? integer
|
--- @field pad_gap? integer
|
||||||
--- @field bg_color? integer | string text color in hex integer or #RGB or #RRGGBB format
|
--- @field bg_color? integer | string text color in hex integer or #RGB or #RRGGBB format
|
||||||
--- @field bg_opa? integer
|
--- @field bg_opa? integer
|
||||||
--- @field bg_grad_color? integer
|
--- @field bg_grad_color? integer | string text color in hex integer or #RGB or #RRGGBB format
|
||||||
--- @field bg_grad_dir? integer
|
--- @field bg_grad_dir? integer
|
||||||
--- @field bg_main_stop? integer
|
--- @field bg_main_stop? integer
|
||||||
--- @field bg_grad_stop? integer
|
--- @field bg_grad_stop? integer
|
||||||
|
|||||||
+18
-1
@@ -276,7 +276,24 @@ void AudioState::react(const system_fsm::HasPhonesChanged& ev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AudioState::react(const SetVolume& ev) {
|
void AudioState::react(const SetVolume& ev) {
|
||||||
// TODO.
|
if (ev.db.has_value()) {
|
||||||
|
if (sOutput->SetVolumeDb(ev.db.value())) {
|
||||||
|
commitVolume();
|
||||||
|
events::Ui().Dispatch(VolumeChanged{
|
||||||
|
.percent = sOutput->GetVolumePct(),
|
||||||
|
.db = sOutput->GetVolumeDb(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (ev.percent.has_value()) {
|
||||||
|
if (sOutput->SetVolumePct(ev.percent.value())) {
|
||||||
|
commitVolume();
|
||||||
|
events::Ui().Dispatch(VolumeChanged{
|
||||||
|
.percent = sOutput->GetVolumePct(),
|
||||||
|
.db = sOutput->GetVolumeDb(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioState::react(const SetVolumeLimit& ev) {
|
void AudioState::react(const SetVolumeLimit& ev) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cmath>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
@@ -54,11 +55,30 @@ auto BluetoothAudioOutput::GetVolume() -> uint16_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto BluetoothAudioOutput::GetVolumePct() -> uint_fast8_t {
|
auto BluetoothAudioOutput::GetVolumePct() -> uint_fast8_t {
|
||||||
return static_cast<uint_fast8_t>(static_cast<int>(volume_) * 100 / 0x7f);
|
return static_cast<uint_fast8_t>(round(static_cast<int>(volume_) * 100.0 / 0x7f));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BluetoothAudioOutput::SetVolumePct(uint_fast8_t val) -> bool {
|
||||||
|
if (val > 100) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint16_t vol = (val * (0x7f))/100;
|
||||||
|
SetVolume(vol);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto BluetoothAudioOutput::GetVolumeDb() -> int_fast16_t {
|
auto BluetoothAudioOutput::GetVolumeDb() -> int_fast16_t {
|
||||||
return 0;
|
double pct = GetVolumePct()/100.0;
|
||||||
|
if (pct <= 0) {
|
||||||
|
pct = 0.01;
|
||||||
|
}
|
||||||
|
int_fast16_t db = log(pct) * 20;
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto BluetoothAudioOutput::SetVolumeDb(int_fast16_t val) -> bool {
|
||||||
|
double pct = exp(val / 20.0) * 100;
|
||||||
|
return SetVolumePct(pct);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto BluetoothAudioOutput::AdjustVolumeUp() -> bool {
|
auto BluetoothAudioOutput::AdjustVolumeUp() -> bool {
|
||||||
|
|||||||
@@ -111,6 +111,15 @@ auto I2SAudioOutput::GetVolumePct() -> uint_fast8_t {
|
|||||||
return (current_volume_ - kMinVolume) * 100 / (max_volume_ - kMinVolume);
|
return (current_volume_ - kMinVolume) * 100 / (max_volume_ - kMinVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto I2SAudioOutput::SetVolumePct(uint_fast8_t val) -> bool {
|
||||||
|
if (val > 100) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint16_t vol = (val * (max_volume_ - kMinVolume))/100 + kMinVolume;
|
||||||
|
SetVolume(vol);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
auto I2SAudioOutput::GetVolumeDb() -> int_fast16_t {
|
auto I2SAudioOutput::GetVolumeDb() -> int_fast16_t {
|
||||||
// Add two before dividing in order to round correctly.
|
// Add two before dividing in order to round correctly.
|
||||||
return (static_cast<int>(current_volume_) -
|
return (static_cast<int>(current_volume_) -
|
||||||
@@ -118,6 +127,11 @@ auto I2SAudioOutput::GetVolumeDb() -> int_fast16_t {
|
|||||||
4;
|
4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto I2SAudioOutput::SetVolumeDb(int_fast16_t val) -> bool {
|
||||||
|
SetVolume(val * 4 + static_cast<int>(drivers::wm8523::kLineLevelReferenceVolume) - 2);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
auto I2SAudioOutput::AdjustVolumeUp() -> bool {
|
auto I2SAudioOutput::AdjustVolumeUp() -> bool {
|
||||||
if (GetVolume() >= max_volume_) {
|
if (GetVolume() >= max_volume_) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ class IAudioOutput {
|
|||||||
virtual auto GetVolumePct() -> uint_fast8_t = 0;
|
virtual auto GetVolumePct() -> uint_fast8_t = 0;
|
||||||
virtual auto GetVolumeDb() -> int_fast16_t = 0;
|
virtual auto GetVolumeDb() -> int_fast16_t = 0;
|
||||||
|
|
||||||
|
virtual auto SetVolumePct(uint_fast8_t) -> bool = 0;
|
||||||
|
virtual auto SetVolumeDb(int_fast16_t) -> bool = 0;
|
||||||
|
|
||||||
virtual auto AdjustVolumeUp() -> bool = 0;
|
virtual auto AdjustVolumeUp() -> bool = 0;
|
||||||
virtual auto AdjustVolumeDown() -> bool = 0;
|
virtual auto AdjustVolumeDown() -> bool = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ class BluetoothAudioOutput : public IAudioOutput {
|
|||||||
auto GetVolume() -> uint16_t override;
|
auto GetVolume() -> uint16_t override;
|
||||||
|
|
||||||
auto GetVolumePct() -> uint_fast8_t override;
|
auto GetVolumePct() -> uint_fast8_t override;
|
||||||
|
auto SetVolumePct(uint_fast8_t val) -> bool override;
|
||||||
auto GetVolumeDb() -> int_fast16_t override;
|
auto GetVolumeDb() -> int_fast16_t override;
|
||||||
|
auto SetVolumeDb(int_fast16_t) -> bool override;
|
||||||
|
|
||||||
auto AdjustVolumeUp() -> bool override;
|
auto AdjustVolumeUp() -> bool override;
|
||||||
auto AdjustVolumeDown() -> bool override;
|
auto AdjustVolumeDown() -> bool override;
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ class I2SAudioOutput : public IAudioOutput {
|
|||||||
auto GetVolume() -> uint16_t override;
|
auto GetVolume() -> uint16_t override;
|
||||||
|
|
||||||
auto GetVolumePct() -> uint_fast8_t override;
|
auto GetVolumePct() -> uint_fast8_t override;
|
||||||
|
auto SetVolumePct(uint_fast8_t val) -> bool override;
|
||||||
auto GetVolumeDb() -> int_fast16_t override;
|
auto GetVolumeDb() -> int_fast16_t override;
|
||||||
|
auto SetVolumeDb(int_fast16_t) -> bool override;
|
||||||
|
|
||||||
auto AdjustVolumeUp() -> bool override;
|
auto AdjustVolumeUp() -> bool override;
|
||||||
auto AdjustVolumeDown() -> bool override;
|
auto AdjustVolumeDown() -> bool override;
|
||||||
|
|||||||
Reference in New Issue
Block a user