PebbleOS
Loading...
Searching...
No Matches
Modules | Data Structures | Functions
Battery

Battery state of charge, charger state and power state handling. More...

Modules

 Battery curve
 Conversion between battery voltage, charge percentage and time remaining.
 
 Battery monitor
 Power state control in response to battery state changes.
 

Data Structures

struct  PreciseBatteryChargeState
 Structure for retrieval of the exact battery charge state. More...
 

Functions

BatteryChargeState battery_get_charge_state (void)
 Get the current battery charge state.
 
void battery_state_force_update (void)
 Sample the battery now instead of waiting for the next periodic update.
 
void battery_state_init (void)
 Initialize battery state tracking and take the first sample.
 
void battery_state_handle_connection_event (bool is_connected)
 Handle a charger connection change.
 
void battery_state_reset_filter (void)
 Reset the voltage filter to the current reading.
 
uint16_t battery_state_get_voltage (void)
 Get the last recorded battery voltage.
 
int32_t battery_state_get_temperature (void)
 Get the last recorded battery temperature.
 
TimerID battery_state_get_periodic_timer_id (void)
 Get the periodic sampling timer, for unit tests.
 

Detailed Description

Battery state of charge, charger state and power state handling.

The battery state module samples the battery through the driver, filters the readings and emits a PEBBLE_BATTERY_STATE_CHANGE_EVENT when the state changes; it is implemented either on a voltage curve or on the nRF fuel gauge, selected at build time. The battery monitor reacts to those changes with low power mode and standby.


Data Structure Documentation

◆ PreciseBatteryChargeState

struct PreciseBatteryChargeState

Structure for retrieval of the exact battery charge state.

Data Fields
uint32_t charge_percent The battery's percentage as a ratio32.
bool is_charging WARNING: This maps to battery_charge_controller_thinks_we_are_charging() as opposed to the user-facing definition of whether we're charging (100% battery).
bool is_plugged True if the charger cable is connected.
uint8_t pct The battery percentage 0-100.

Function Documentation

◆ battery_get_charge_state()

BatteryChargeState battery_get_charge_state ( void  )

Get the current battery charge state.

Returns
A BatteryChargeState struct with the current charge state.

◆ battery_state_force_update()

void battery_state_force_update ( void  )

Sample the battery now instead of waiting for the next periodic update.

The update is scheduled from a timer, so the new state is not available on return.

◆ battery_state_get_periodic_timer_id()

TimerID battery_state_get_periodic_timer_id ( void  )

Get the periodic sampling timer, for unit tests.

Returns
Timer id.

◆ battery_state_get_temperature()

int32_t battery_state_get_temperature ( void  )

Get the last recorded battery temperature.

Returns
Temperature in thousandths of a degree Celsius.

◆ battery_state_get_voltage()

uint16_t battery_state_get_voltage ( void  )

Get the last recorded battery voltage.

Returns
Voltage in mV.

◆ battery_state_handle_connection_event()

void battery_state_handle_connection_event ( bool  is_connected)

Handle a charger connection change.

Schedules an update after a short delay, to let the readings settle and debounce reconnection.

Parameters
is_connectedtrue if the charger was connected.

◆ battery_state_init()

void battery_state_init ( void  )

Initialize battery state tracking and take the first sample.

◆ battery_state_reset_filter()

void battery_state_reset_filter ( void  )

Reset the voltage filter to the current reading.

Voltage curve backend only.