mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-03 09:01:50 -05:00
bluetooth: Provide (HSP/HFP-received) battery level as device property
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/482>
This commit is contained in:
parent
d2c97190ef
commit
c667befe9a
4 changed files with 42 additions and 0 deletions
|
|
@ -103,6 +103,7 @@ struct userdata {
|
|||
pa_core *core;
|
||||
|
||||
pa_hook_slot *device_connection_changed_slot;
|
||||
pa_hook_slot *device_battery_level_changed_slot;
|
||||
pa_hook_slot *transport_state_changed_slot;
|
||||
pa_hook_slot *transport_sink_volume_changed_slot;
|
||||
pa_hook_slot *transport_source_volume_changed_slot;
|
||||
|
|
@ -2157,6 +2158,12 @@ static int add_card(struct userdata *u) {
|
|||
data.name = pa_sprintf_malloc("bluez_card.%s", d->address);
|
||||
data.namereg_fail = false;
|
||||
|
||||
if (d->has_battery_level) {
|
||||
// See device_battery_level_changed_cb
|
||||
uint8_t level = d->battery_level;
|
||||
pa_proplist_setf(data.proplist, "bluetooth.battery", "%d%%", level);
|
||||
}
|
||||
|
||||
create_card_ports(u, data.ports);
|
||||
|
||||
PA_HASHMAP_FOREACH(uuid, d->uuids, state) {
|
||||
|
|
@ -2295,6 +2302,22 @@ static pa_hook_result_t device_connection_changed_cb(pa_bluetooth_discovery *y,
|
|||
return PA_HOOK_OK;
|
||||
}
|
||||
|
||||
static pa_hook_result_t device_battery_level_changed_cb(pa_bluetooth_discovery *y, const pa_bluetooth_device *d, struct userdata *u) {
|
||||
uint8_t level;
|
||||
|
||||
pa_assert(d);
|
||||
pa_assert(u);
|
||||
|
||||
if (d != u->device || !d->has_battery_level)
|
||||
return PA_HOOK_OK;
|
||||
|
||||
level = d->battery_level;
|
||||
|
||||
pa_proplist_setf(u->card->proplist, "bluetooth.battery", "%d%%", level);
|
||||
|
||||
return PA_HOOK_OK;
|
||||
}
|
||||
|
||||
/* Run from main thread */
|
||||
static pa_hook_result_t transport_state_changed_cb(pa_bluetooth_discovery *y, pa_bluetooth_transport *t, struct userdata *u) {
|
||||
pa_assert(t);
|
||||
|
|
@ -2691,6 +2714,10 @@ int pa__init(pa_module* m) {
|
|||
pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_CONNECTION_CHANGED),
|
||||
PA_HOOK_NORMAL, (pa_hook_cb_t) device_connection_changed_cb, u);
|
||||
|
||||
u->device_battery_level_changed_slot =
|
||||
pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_DEVICE_BATTERY_LEVEL_CHANGED),
|
||||
PA_HOOK_NORMAL, (pa_hook_cb_t) device_battery_level_changed_cb, u);
|
||||
|
||||
u->transport_state_changed_slot =
|
||||
pa_hook_connect(pa_bluetooth_discovery_hook(u->discovery, PA_BLUETOOTH_HOOK_TRANSPORT_STATE_CHANGED),
|
||||
PA_HOOK_NORMAL, (pa_hook_cb_t) transport_state_changed_cb, u);
|
||||
|
|
@ -2767,6 +2794,9 @@ void pa__done(pa_module *m) {
|
|||
if (u->device_connection_changed_slot)
|
||||
pa_hook_slot_free(u->device_connection_changed_slot);
|
||||
|
||||
if (u->device_battery_level_changed_slot)
|
||||
pa_hook_slot_free(u->device_battery_level_changed_slot);
|
||||
|
||||
if (u->transport_state_changed_slot)
|
||||
pa_hook_slot_free(u->transport_state_changed_slot);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue