bluez5: Add battery level reporting via AT+XEVENT

This commit is contained in:
delaosa 2022-05-09 17:42:15 +02:00 committed by Wim Taymans
parent 0333ddff45
commit 65ddd0a42b

View file

@ -684,6 +684,18 @@ static bool device_supports_required_mSBC_transport_modes(
static int codec_switch_start_timer(struct rfcomm *rfcomm, int timeout_msec);
static void process_xevent_indicator(struct rfcomm *rfcomm, unsigned int batt_p1, unsigned int batt_p2)
{
struct impl *backend = rfcomm->backend;
spa_log_debug(backend->log, "batt_p1:%u batt_p2:%u", batt_p1, batt_p2);
uint8_t level = (batt_p1 * 100) / batt_p2;
spa_log_debug(backend->log, "battery level: %d%%", (int) level);
// TODO: report without Battery Provider (using props)
spa_bt_device_report_battery_level(rfcomm->device, level);
}
static void process_iphoneaccev_indicator(struct rfcomm *rfcomm, unsigned int key, unsigned int value)
{
struct impl *backend = rfcomm->backend;
@ -760,6 +772,8 @@ static bool rfcomm_hfp_ag(struct rfcomm *rfcomm, char* buf)
unsigned int indicator;
unsigned int indicator_value;
unsigned int value;
unsigned int xevent_batt_p1;
unsigned int xevent_batt_p2;
int xapl_vendor;
int xapl_product;
int xapl_features;
@ -1069,6 +1083,10 @@ next_indicator:
rfcomm_send_reply(rfcomm, "+XAPL=iPhone,%u", SPA_BT_HFP_HF_XAPL_FEATURE_BATTERY_REPORTING);
}
rfcomm_send_reply(rfcomm, "OK");
} else if (spa_strstartswith(buf, "AT+XEVENT=USER-AGENT")) {
rfcomm_send_reply(rfcomm, "OK");
} else if (sscanf(buf, "AT+XEVENT=BATTERY,%u,%u,%*u,%*u", &xevent_batt_p1, &xevent_batt_p2) == 2) {
process_xevent_indicator(rfcomm, xevent_batt_p1, xevent_batt_p2);
} else if (sscanf(buf, "AT+IPHONEACCEV=%u%n", &count, &r) == 1) {
if (count < 1 || count > 100)
return false;