nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches

◆ bt_fast_pair_fmdn_battery_level_set()

int bt_fast_pair_fmdn_battery_level_set ( uint8_t  percentage_level)

#include <include/bluetooth/services/fast_pair/fmdn.h>

Set the current battery level.

This function sets the current battery level. It is recommended to initialize the battery level with this API before you enable Fast Pair with the bt_fast_pair_enable API.

By default, the BT_FAST_PAIR_FMDN_BATTERY_LEVEL_NONE value is used, which means that battery levels do not show in the advertising payload. If you do not want to support the battery level indication, you should ignore this API and never call it in their application.

However, if the

embed:rst:inline :kconfig:option:`CONFIG_BT_FAST_PAIR_FMDN_BATTERY_DULT` 

Kconfig is enabled, you must initialize battery level with this API before you enable Fast Pair with the bt_fast_pair_enable API. This requirement is necessary as the DULT battery mechanism does not support unknown battery levels. As a result, you must not call this API with the BT_FAST_PAIR_FMDN_BATTERY_LEVEL_NONE value in this configuration variant.

To keep the Android battery level indications accurate, you should set the battery level to the new value with the help of this API as soon as the device battery level changes.

The exact mapping of the battery percentage to the battery level as defined by the FMDN Accessory specification in the advertising payload is implementation-specific. The mapping configuration is controlled by the following Kconfig options:

embed:rst:inline :kconfig:option:`CONFIG_BT_FAST_PAIR_FMDN_BATTERY_LEVEL_LOW_THR` 

and

embed:rst:inline :kconfig:option:`CONFIG_BT_FAST_PAIR_FMDN_BATTERY_LEVEL_CRITICAL_THR` 

.

Parameters
percentage_levelBattery level as a percentage [0-100%] or BT_FAST_PAIR_FMDN_BATTERY_LEVEL_NONE value if the battery level is unknown.
Returns
0 if the operation was successful. Otherwise, a (negative) error code is returned.