BLEBatteryService Class

BLEBatteryService Class

Description
A class used for managing a BLE battery service running on the device

Syntax
class BLEBatteryService

Members

Public Constructors 
BLEBatteryService:: BLEBatteryServiceOnly one instance of this class should be created
Public Methods 
BLEBatteryService::addServiceAdd the battery service to the BLE stack
BLEBatteryService::setReadCallbackAdd a callback function for when the battery level is read
BLEBatteryService::setNotificationCallbackAdd a callback function for when the notification setting is changed
BLEBatteryService::notifyEnabledDetermine if the notification setting is currently enabled
BLEBatteryService::setLevelSet the current battery level
BLEBatteryService::sendNotificationSend a notification on the current battery level

BLEBatteryService::BLEBatteryService

Description
Create an instance of the BLEBatteryService object.

Syntax
void BLEBatteryService(void);

Parameters
The function requires no input parameter.

Returns
The function returns nothing.

Example Code
Example: BLEBatteryService
Details of the code can be found in BLEAdvert::setAdvType.

Notes and Warnings
Only one instance of this class / service should be created.
 

BLEBatteryService::addService

Description
Add the battery service to the BLE stack.

Syntax
void addService(void);

Parameters
The function requires no input parameter.

Returns
The function returns nothing.

Example Code
Example: BLEBatteryService
Details of the code can be found in BLEAdvert::setAdvType.

Notes and Warnings
Call this member function to add the service to the BLE stack and enable connecting devices to discover it. Services can only be added when the device is not operating in BLE Peripheral or Central mode.
 

BLEBatteryService::setReadCallback

Description
Add a callback function for when the battery level is read.

Syntax
void setReadCallback(void (*fCallback)(void));

Parameters
fCallback: A function that returns void and takes no parameters.

Returns
The function returns nothing.

Example Code
Example: BLEBatteryService
Details of the code can be found in BLEAdvert::setAdvType.

Notes and Warnings
Call this member function to add a function that will be called when a client reads the battery level.
 

BLEBatteryService::setNotificationCallback

Description
Add a callback function for when the notification setting is changed.

Syntax
void setNotificationCallback(void (*fCallback)(uint8_t));

Parameters
fCallback: A function that returns void and takes in an unsigned integer indicating the current notification setting.

Returns
The function returns nothing.

Example Code
Example: BLEBatteryService
Details of the code can be found in BLEAdvert::setAdvType.

Notes and Warnings
Call this member function to add a function that will be called when a client changes the notification setting. The new notification setting will be passed to the callback function, with notification enabled represented by 1 and notification disabled represented by 2.
 

BLEBatteryService::notifyEnabled

Description
Determine if the notification setting is currently enabled

Syntax
bool notifyEnabled(void);

Parameters
The function requires no input parameter.

Returns
The function returns Boolean value of “True” or “False”.

Example Code
Example: BLEBatteryService
Details of the code can be found in BLEAdvert::setAdvType.

Notes and Warnings
Call this member function to determine if battery level notifications are enabled by the client.
 

BLEBatteryService::setLevel

Description
Set the current battery level.

Syntax
void setLevel(uint8_t level);

Parameters
level: An unsigned integer indicating the current battery level as a percentage from 0% to 100%.

Returns
The function returns nothing.

Example Code
Example: BLEBatteryService
Details of the code can be found in BLEAdvert::setAdvType.

Notes and Warnings
Battery values above 100% are not defined and interpretation is dependent on the connecting client.
 

BLEBatteryService::sendNotification

Description
Send a notification on the current battery level.

Syntax
void sendNotification(uint8_t level);

Parameters
level: An unsigned integer indicating the current battery level as a percentage from 0% to 100%.

Returns
The function returns nothing.

Example Code
Example: BLEBatteryService
Details of the code can be found in BLEAdvert::setAdvType.

Notes and Warnings
Battery values above 100% are not defined and interpretation is dependent on the connecting client.

Copyrights ©瑞晟微电子(苏州)有限公司 2021. All rights reserved.
請先確認已安裝QQ通訊軟體