Fix some bt device issues
- Don't allow adjusting volume if there's no device - Cap bt nvs values correctly - Persist bt volumes correctly even when the encoded for has a null byte (facepalm 4 me)
This commit is contained in:
@@ -90,7 +90,7 @@ auto BluetoothAudioOutput::SetVolumeDb(int_fast16_t val) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto BluetoothAudioOutput::AdjustVolumeUp() -> bool {
|
auto BluetoothAudioOutput::AdjustVolumeUp() -> bool {
|
||||||
if (volume_ == 100) {
|
if (volume_ == 100 || !bluetooth_.IsConnected()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
volume_++;
|
volume_++;
|
||||||
@@ -99,7 +99,7 @@ auto BluetoothAudioOutput::AdjustVolumeUp() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto BluetoothAudioOutput::AdjustVolumeDown() -> bool {
|
auto BluetoothAudioOutput::AdjustVolumeDown() -> bool {
|
||||||
if (volume_ == 0) {
|
if (volume_ == 0 || !bluetooth_.IsConnected()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
volume_--;
|
volume_--;
|
||||||
|
|||||||
+3
-3
@@ -273,7 +273,7 @@ auto NvsStorage::BluetoothVolume(const bluetooth::mac_addr_t& mac) -> uint8_t {
|
|||||||
// Note we don't set the dirty flag here, even though it's an LRU cache, so
|
// Note we don't set the dirty flag here, even though it's an LRU cache, so
|
||||||
// that we can avoid constantly re-writing this setting to flash when the
|
// that we can avoid constantly re-writing this setting to flash when the
|
||||||
// user hasn't actually been changing their volume.
|
// user hasn't actually been changing their volume.
|
||||||
return bt_volumes_.Get(mac).value_or(10);
|
return bt_volumes_.Get(mac).value_or(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NvsStorage::BluetoothVolume(const bluetooth::mac_addr_t& mac, uint8_t vol)
|
auto NvsStorage::BluetoothVolume(const bluetooth::mac_addr_t& mac, uint8_t vol)
|
||||||
@@ -405,7 +405,7 @@ class VolumesParseClient : public cppbor::ParseClient {
|
|||||||
std::copy(data.begin(), data.end(), mac_->begin());
|
std::copy(data.begin(), data.end(), mac_->begin());
|
||||||
} else if (item->type() == cppbor::UINT && state_ == State::kPair) {
|
} else if (item->type() == cppbor::UINT && state_ == State::kPair) {
|
||||||
vol_ =
|
vol_ =
|
||||||
std::clamp<uint64_t>(item->asUint()->unsignedValue(), 0, UINT8_MAX);
|
std::clamp<uint64_t>(item->asUint()->unsignedValue(), 0, UINT16_MAX);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -470,7 +470,7 @@ auto NvsStorage::writeBtVolumes() -> void {
|
|||||||
cppbor::Uint{vol->second}});
|
cppbor::Uint{vol->second}});
|
||||||
}
|
}
|
||||||
std::string encoded = enc.toString();
|
std::string encoded = enc.toString();
|
||||||
nvs_set_str(handle_, kKeyBluetoothVolumes, encoded.c_str());
|
nvs_set_blob(handle_, kKeyBluetoothVolumes, encoded.data(), encoded.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace drivers
|
} // namespace drivers
|
||||||
|
|||||||
Reference in New Issue
Block a user