BLEBatteryClient Class

BLEBatteryClient Class

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

Syntax
class BLEBatteryClient

Members

Public Constructors
BLEBatteryClient::BLEBatteryClientOnly one instance of this class should be created
Public Methods 
BLEBatteryClient::addClientAdd the battery service to the BLE stack
BLEBatteryClient::discoverServicesCheck if Battery Service is available on a connected device
BLEBatteryClient::readLevelRead the current battery level on the connected device
BLEBatteryClient::readNotificationStateDetermine the current notification setting
BLEBatteryClient::setNotificationStateSet the notification setting for a connected device
BLEBatteryClient::setReadCallbackAdd a callback function for reading battery level
BLEBatteryClient::setNotificationCallbackAdd a callback function for receiving battery level notifications
BLEBatteryClient::setDiscoveryCallbackAdd a callback function for checking Battery Service availability

BLEBatteryClient::BLEBatteryClient

Description
Create an instance of the BLEBatteryClient object.

Syntax
void BLEBatteryClient(void);

Parameters
The function requires no input parameter.

Returns
The function returns nothing.

Example Code
Example: BLEBatteryClient

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

BLEBatteryClient::addClient

Description
Add the battery client to the BLE stack.

Syntax
void addClient(uint8_t max_link_num);

Parameters
max_link_num: maximum number of connections required.

Returns
The function returns nothing.

Example Code
Example: BLEBatteryClient

Notes and Warnings
Call this member function to add the client to the BLE stack and enable communication with Battery Service devices.
 

BLEBatteryClient::discoverServices

Description
Check if Battery Service is available on a connected device.

Syntax
bool discoverServices(uint8_t conn_id);

Parameters
conn_id: Connection ID of connected device to check for Battery Service.

Returns
True if operation succeeded, false if operation failed.

Example Code
Example: BLEBatteryClient

Notes and Warnings
Results are returned through callback function registered with BLEBatteryClient::setDiscoveryCallback.
 

BLEBatteryClient::readLevel

Description
Read the current battery level on the connected device.

Syntax
bool readLevel(uint8_t conn_id);

Parameters
conn_id: Connection ID of connected device to read battery level.

Returns
True if operation succeeded, false if operation failed.

Example Code
Example: BLEBatteryClient

Notes and Warnings
Results are returned through callback function registered with BLEBatteryClient::setReadCallback.
 

BLEBatteryClient::readNotificationState

Description
Determine the current notification setting for a connected device.

Syntax
bool readNotificationState(uint8_t conn_id);

Parameters
conn_id: Connection ID of connected device to read notification state.

Returns
True if notification is enabled, false if disabled.

Example Code
Example: BLEBatteryClient

Notes and Warnings
NA
 

BLEBatteryClient::setNotificationState

Description
Set the notification setting for a connected device.

Syntax
bool setNotificationState(uint8_t conn_id, bool notifyEnable);

Parameters
conn_id: Connection ID of connected device to set notification state.
notifyEnable: True to enable notifications, false to disable.

Returns
True if operation succeeded, false if operation failed.

Example Code
Example: BLEBatteryClient

Notes and Warnings
NA
 

BLEBatteryClient::setReadCallback

Description
Add a callback function for reading battery level.

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

Parameters
fCallback: A function that returns void and takes in two unsigned integers as parameters, the first parameter for connection ID, and the second parameter for battery level.

Returns
The function returns nothing.

Example Code
Example: BLEBatteryClient

Notes and Warnings
Call this member function to add a function that will be called after the battery level read result is received.
 

BLEBatteryClient::setNotificationCallback

Description
Add a callback function for receiving battery level notifications.

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

Parameters
fCallback: A function that returns void and takes in two unsigned integers as parameters, the first parameter for connection ID, and the second parameter for battery level.

Returns
The function returns nothing.

Example Code
Example: BLEBatteryClient

Notes and Warnings
Call this member function to add a function that will be called when the Battery Service device sends a notification about the battery level.
 

BLEBatteryClient::setDiscoveryCallback

Description
Add a callback function for checking Battery Service availability.

Syntax
void setDiscoveryCallback(void (*fCallback)(uint8_t, bool));

Parameters
fCallback: A function that returns void and takes in an unsigned integer and a boolean as parameters, the first parameter for connection ID, and the second parameter for the availability of a Battery Service on the device.

Returns
The function returns nothing.

Example Code
Example: BLEBatteryClient

Notes and Warnings
NA
 

Copyrights ©瑞晟微电子(苏州)有限公司 2021. All rights reserved.
Please confirm that QQ communication software is installed