Zephyr API Documentation 4.0.0-rc2
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Battery Service (BAS)

Battery Service (BAS) . More...

Enumerations

enum  bt_bas_bcs_flags { BT_BAS_BCS_BATTERY_CRITICAL_STATE = BIT(0) , BT_BAS_BCS_IMMEDIATE_SERVICE_REQUIRED = BIT(1) }
 Battery Critical Status Characteristic flags. More...
 
enum  bt_bas_bls_flags { BT_BAS_BLS_FLAG_IDENTIFIER_PRESENT = BIT(0) , BT_BAS_BLS_FLAG_BATTERY_LEVEL_PRESENT = BIT(1) , BT_BAS_BLS_FLAG_ADDITIONAL_STATUS_PRESENT = BIT(2) }
 Battery Level Status Characteristic flags. More...
 
enum  bt_bas_bls_battery_present { BT_BAS_BLS_BATTERY_NOT_PRESENT = 0 , BT_BAS_BLS_BATTERY_PRESENT = 1 }
 Battery Present Status. More...
 
enum  bt_bas_bls_wired_power_source { BT_BAS_BLS_WIRED_POWER_NOT_CONNECTED = 0 , BT_BAS_BLS_WIRED_POWER_CONNECTED = 1 , BT_BAS_BLS_WIRED_POWER_UNKNOWN = 2 }
 Wired External Power Source Status. More...
 
enum  bt_bas_bls_wireless_power_source { BT_BAS_BLS_WIRELESS_POWER_NOT_CONNECTED = 0 , BT_BAS_BLS_WIRELESS_POWER_CONNECTED = 1 , BT_BAS_BLS_WIRELESS_POWER_UNKNOWN = 2 }
 Wireless External Power Source Status. More...
 
enum  bt_bas_bls_battery_charge_state { BT_BAS_BLS_CHARGE_STATE_UNKNOWN = 0 , BT_BAS_BLS_CHARGE_STATE_CHARGING = 1 , BT_BAS_BLS_CHARGE_STATE_DISCHARGING_ACTIVE = 2 , BT_BAS_BLS_CHARGE_STATE_DISCHARGING_INACTIVE = 3 }
 Battery Charge State. More...
 
enum  bt_bas_bls_battery_charge_level { BT_BAS_BLS_CHARGE_LEVEL_UNKNOWN = 0 , BT_BAS_BLS_CHARGE_LEVEL_GOOD = 1 , BT_BAS_BLS_CHARGE_LEVEL_LOW = 2 , BT_BAS_BLS_CHARGE_LEVEL_CRITICAL = 3 }
 Battery Charge Level. More...
 
enum  bt_bas_bls_battery_charge_type {
  BT_BAS_BLS_CHARGE_TYPE_UNKNOWN = 0 , BT_BAS_BLS_CHARGE_TYPE_CONSTANT_CURRENT = 1 , BT_BAS_BLS_CHARGE_TYPE_CONSTANT_VOLTAGE = 2 , BT_BAS_BLS_CHARGE_TYPE_TRICKLE = 3 ,
  BT_BAS_BLS_CHARGE_TYPE_FLOAT = 4
}
 Battery Charge Type. More...
 
enum  bt_bas_bls_charging_fault_reason { BT_BAS_BLS_FAULT_REASON_NONE = 0 , BT_BAS_BLS_FAULT_REASON_BATTERY = BIT(0) , BT_BAS_BLS_FAULT_REASON_EXTERNAL_POWER = BIT(1) , BT_BAS_BLS_FAULT_REASON_OTHER = BIT(2) }
 Charging Fault Reason. More...
 
enum  bt_bas_bls_service_required { BT_BAS_BLS_SERVICE_REQUIRED_FALSE = 0 , BT_BAS_BLS_SERVICE_REQUIRED_TRUE = 1 , BT_BAS_BLS_SERVICE_REQUIRED_UNKNOWN = 2 }
 Service Required Status. More...
 
enum  bt_bas_bls_battery_fault { BT_BAS_BLS_BATTERY_FAULT_NO = 0 , BT_BAS_BLS_BATTERY_FAULT_YES = 1 }
 Battery Fault Status. More...
 

Functions

uint8_t bt_bas_get_battery_level (void)
 Read battery level value.
 
int bt_bas_set_battery_level (uint8_t level)
 Update battery level value.
 
void bt_bas_bls_set_battery_present (enum bt_bas_bls_battery_present present)
 Set the battery present status.
 
void bt_bas_bls_set_wired_external_power_source (enum bt_bas_bls_wired_power_source source)
 Set the wired external power source status.
 
void bt_bas_bls_set_wireless_external_power_source (enum bt_bas_bls_wireless_power_source source)
 Set the wireless external power source status.
 
void bt_bas_bls_set_battery_charge_state (enum bt_bas_bls_battery_charge_state state)
 Set the battery charge state.
 
void bt_bas_bls_set_battery_charge_level (enum bt_bas_bls_battery_charge_level level)
 Set the battery charge level.
 
void bt_bas_bls_set_battery_charge_type (enum bt_bas_bls_battery_charge_type type)
 Set the battery charge type.
 
void bt_bas_bls_set_charging_fault_reason (enum bt_bas_bls_charging_fault_reason reason)
 Set the charging fault reason.
 
void bt_bas_bls_set_identifier (uint16_t identifier)
 Set the identifier of the battery.
 
void bt_bas_bls_set_service_required (enum bt_bas_bls_service_required value)
 Set the service required status.
 
void bt_bas_bls_set_battery_fault (enum bt_bas_bls_battery_fault value)
 Set the battery fault status.
 

Detailed Description

Battery Service (BAS) .

[Experimental] Users should note that the APIs can change as a part of ongoing development.

Enumeration Type Documentation

◆ bt_bas_bcs_flags

#include <zephyr/bluetooth/services/bas.h>

Battery Critical Status Characteristic flags.

Enumeration for the flags indicating the presence of various fields in the Battery Critical Status characteristic.

Enumerator
BT_BAS_BCS_BATTERY_CRITICAL_STATE 

Battery Critical Status Bit 0: Critical Power State.

BT_BAS_BCS_IMMEDIATE_SERVICE_REQUIRED 

Battery Critical Status Bit 1: Immediate Service Required.

◆ bt_bas_bls_battery_charge_level

#include <zephyr/bluetooth/services/bas.h>

Battery Charge Level.

Enumeration for the level of charge in the battery.

Enumerator
BT_BAS_BLS_CHARGE_LEVEL_UNKNOWN 

Battery charge level is unknown.

BT_BAS_BLS_CHARGE_LEVEL_GOOD 

Battery charge level is good.

BT_BAS_BLS_CHARGE_LEVEL_LOW 

Battery charge level is low.

BT_BAS_BLS_CHARGE_LEVEL_CRITICAL 

Battery charge level is critical.

◆ bt_bas_bls_battery_charge_state

#include <zephyr/bluetooth/services/bas.h>

Battery Charge State.

Enumeration for the charge state of the battery.

Enumerator
BT_BAS_BLS_CHARGE_STATE_UNKNOWN 

Battery charge state is unknown.

BT_BAS_BLS_CHARGE_STATE_CHARGING 

Battery is currently charging.

BT_BAS_BLS_CHARGE_STATE_DISCHARGING_ACTIVE 

Battery is discharging actively.

BT_BAS_BLS_CHARGE_STATE_DISCHARGING_INACTIVE 

Battery is discharging but inactive.

◆ bt_bas_bls_battery_charge_type

#include <zephyr/bluetooth/services/bas.h>

Battery Charge Type.

Enumeration for the type of charging applied to the battery.

Enumerator
BT_BAS_BLS_CHARGE_TYPE_UNKNOWN 

Battery charge type is unknown or not charging.

BT_BAS_BLS_CHARGE_TYPE_CONSTANT_CURRENT 

Battery is charged using constant current.

BT_BAS_BLS_CHARGE_TYPE_CONSTANT_VOLTAGE 

Battery is charged using constant voltage.

BT_BAS_BLS_CHARGE_TYPE_TRICKLE 

Battery is charged using trickle charge.

BT_BAS_BLS_CHARGE_TYPE_FLOAT 

Battery is charged using float charge.

◆ bt_bas_bls_battery_fault

#include <zephyr/bluetooth/services/bas.h>

Battery Fault Status.

Enumeration for the fault status of the battery.

Enumerator
BT_BAS_BLS_BATTERY_FAULT_NO 

No battery fault.

BT_BAS_BLS_BATTERY_FAULT_YES 

Battery fault present.

◆ bt_bas_bls_battery_present

#include <zephyr/bluetooth/services/bas.h>

Battery Present Status.

Enumeration for the presence of the battery.

Enumerator
BT_BAS_BLS_BATTERY_NOT_PRESENT 

Battery is not present.

BT_BAS_BLS_BATTERY_PRESENT 

Battery is present.

◆ bt_bas_bls_charging_fault_reason

#include <zephyr/bluetooth/services/bas.h>

Charging Fault Reason.

Enumeration for the reasons of charging faults.

Enumerator
BT_BAS_BLS_FAULT_REASON_NONE 

No charging fault.

BT_BAS_BLS_FAULT_REASON_BATTERY 

Charging fault due to battery issue.

BT_BAS_BLS_FAULT_REASON_EXTERNAL_POWER 

Charging fault due to external power source issue.

BT_BAS_BLS_FAULT_REASON_OTHER 

Charging fault for other reasons.

◆ bt_bas_bls_flags

#include <zephyr/bluetooth/services/bas.h>

Battery Level Status Characteristic flags.

Enumeration for the flags indicating the presence of various fields in the Battery Level Status characteristic.

Enumerator
BT_BAS_BLS_FLAG_IDENTIFIER_PRESENT 

Bit indicating that the Battery Level Status identifier is present.

BT_BAS_BLS_FLAG_BATTERY_LEVEL_PRESENT 

Bit indicating that the Battery Level is present.

BT_BAS_BLS_FLAG_ADDITIONAL_STATUS_PRESENT 

Bit indicating that additional status information is present.

◆ bt_bas_bls_service_required

#include <zephyr/bluetooth/services/bas.h>

Service Required Status.

Enumeration for whether the service is required.

Enumerator
BT_BAS_BLS_SERVICE_REQUIRED_FALSE 

Service is not required.

BT_BAS_BLS_SERVICE_REQUIRED_TRUE 

Service is required.

BT_BAS_BLS_SERVICE_REQUIRED_UNKNOWN 

Service requirement is unknown.

◆ bt_bas_bls_wired_power_source

#include <zephyr/bluetooth/services/bas.h>

Wired External Power Source Status.

Enumeration for the status of the wired external power source.

Enumerator
BT_BAS_BLS_WIRED_POWER_NOT_CONNECTED 

Wired external power source is not connected.

BT_BAS_BLS_WIRED_POWER_CONNECTED 

Wired external power source is connected.

BT_BAS_BLS_WIRED_POWER_UNKNOWN 

Wired external power source status is unknown.

◆ bt_bas_bls_wireless_power_source

#include <zephyr/bluetooth/services/bas.h>

Wireless External Power Source Status.

Enumeration for the status of the wireless external power source.

Enumerator
BT_BAS_BLS_WIRELESS_POWER_NOT_CONNECTED 

Wireless external power source is not connected.

BT_BAS_BLS_WIRELESS_POWER_CONNECTED 

Wireless external power source is connected.

BT_BAS_BLS_WIRELESS_POWER_UNKNOWN 

Wireless external power source status is unknown.

Function Documentation

◆ bt_bas_bls_set_battery_charge_level()

void bt_bas_bls_set_battery_charge_level ( enum bt_bas_bls_battery_charge_level level)

#include <zephyr/bluetooth/services/bas.h>

Set the battery charge level.

Parameters
levelThe battery charge level to set.

◆ bt_bas_bls_set_battery_charge_state()

void bt_bas_bls_set_battery_charge_state ( enum bt_bas_bls_battery_charge_state state)

#include <zephyr/bluetooth/services/bas.h>

Set the battery charge state.

Parameters
stateThe battery charge state to set.

◆ bt_bas_bls_set_battery_charge_type()

void bt_bas_bls_set_battery_charge_type ( enum bt_bas_bls_battery_charge_type type)

#include <zephyr/bluetooth/services/bas.h>

Set the battery charge type.

Parameters
typeThe battery charge type to set.

◆ bt_bas_bls_set_battery_fault()

void bt_bas_bls_set_battery_fault ( enum bt_bas_bls_battery_fault value)

#include <zephyr/bluetooth/services/bas.h>

Set the battery fault status.

Attention
Available only when the following Kconfig option is enabled:
CONFIG_BT_BAS_BLS_ADDITIONAL_STATUS_PRESENT 
.
Parameters
valueBattery fault status to set.

◆ bt_bas_bls_set_battery_present()

void bt_bas_bls_set_battery_present ( enum bt_bas_bls_battery_present present)

#include <zephyr/bluetooth/services/bas.h>

Set the battery present status.

Parameters
presentThe battery present status to set.

◆ bt_bas_bls_set_charging_fault_reason()

void bt_bas_bls_set_charging_fault_reason ( enum bt_bas_bls_charging_fault_reason reason)

#include <zephyr/bluetooth/services/bas.h>

Set the charging fault reason.

Parameters
reasonThe charging fault reason to set.

◆ bt_bas_bls_set_identifier()

void bt_bas_bls_set_identifier ( uint16_t identifier)

#include <zephyr/bluetooth/services/bas.h>

Set the identifier of the battery.

Attention
Available only when the following Kconfig option is enabled:
CONFIG_BT_BAS_BLS_IDENTIFIER_PRESENT 
.
Parameters
identifierIdentifier to set.

◆ bt_bas_bls_set_service_required()

void bt_bas_bls_set_service_required ( enum bt_bas_bls_service_required value)

#include <zephyr/bluetooth/services/bas.h>

Set the service required status.

Attention
Available only when the following Kconfig option is enabled:
CONFIG_BT_BAS_BLS_ADDITIONAL_STATUS_PRESENT 
.
Parameters
valueService required status to set.

◆ bt_bas_bls_set_wired_external_power_source()

void bt_bas_bls_set_wired_external_power_source ( enum bt_bas_bls_wired_power_source source)

#include <zephyr/bluetooth/services/bas.h>

Set the wired external power source status.

Parameters
sourceThe wired external power source status to set.

◆ bt_bas_bls_set_wireless_external_power_source()

void bt_bas_bls_set_wireless_external_power_source ( enum bt_bas_bls_wireless_power_source source)

#include <zephyr/bluetooth/services/bas.h>

Set the wireless external power source status.

Parameters
sourceThe wireless external power source status to set.

◆ bt_bas_get_battery_level()

uint8_t bt_bas_get_battery_level ( void )

#include <zephyr/bluetooth/services/bas.h>

Read battery level value.

Read the characteristic value of the battery level

Returns
The battery level in percent.

◆ bt_bas_set_battery_level()

int bt_bas_set_battery_level ( uint8_t level)

#include <zephyr/bluetooth/services/bas.h>

Update battery level value.

Update the characteristic value of the battery level This will send a GATT notification to all current subscribers.

Parameters
levelThe battery level in percent.
Returns
Zero in case of success and error code in case of error.