Skip to content

Commit dbd3887

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: HFP_AG: Set battery level
Add a function `bt_hfp_ag_battery_level` to set the battery level. Signed-off-by: Lyle Zhu <[email protected]>
1 parent 04c4abd commit dbd3887

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

include/zephyr/bluetooth/classic/hfp_ag.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,17 @@ int bt_hfp_ag_signal_strength(struct bt_hfp_ag *ag, uint8_t strength);
725725
*/
726726
int bt_hfp_ag_roaming_status(struct bt_hfp_ag *ag, uint8_t status);
727727

728+
/** @brief Set battery level
729+
*
730+
* Set battery level.
731+
*
732+
* @param ag HFP AG object.
733+
* @param level battery level.
734+
*
735+
* @return 0 in case of success or negative value in case of error.
736+
*/
737+
int bt_hfp_ag_battery_level(struct bt_hfp_ag *ag, uint8_t level);
738+
728739
#ifdef __cplusplus
729740
}
730741
#endif

subsys/bluetooth/host/classic/hfp_ag.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4672,3 +4672,29 @@ int bt_hfp_ag_roaming_status(struct bt_hfp_ag *ag, uint8_t status)
46724672

46734673
return err;
46744674
}
4675+
4676+
int bt_hfp_ag_battery_level(struct bt_hfp_ag *ag, uint8_t level)
4677+
{
4678+
int err;
4679+
4680+
LOG_DBG("");
4681+
4682+
if (ag == NULL) {
4683+
return -EINVAL;
4684+
}
4685+
4686+
hfp_ag_lock(ag);
4687+
if (ag->state != BT_HFP_CONNECTED) {
4688+
hfp_ag_unlock(ag);
4689+
return -ENOTCONN;
4690+
}
4691+
hfp_ag_unlock(ag);
4692+
4693+
err = hfp_ag_update_indicator(ag, BT_HFP_AG_BATTERY_IND, level,
4694+
NULL, NULL);
4695+
if (err) {
4696+
LOG_ERR("Fail to set battery level err :(%d)", err);
4697+
}
4698+
4699+
return err;
4700+
}

0 commit comments

Comments
 (0)