PebbleOS
Loading...
Searching...
No Matches
Enumerations | Functions
Battery curve

Conversion between battery voltage, charge percentage and time remaining. More...

Enumerations

enum  BatteryCurveVoltageCompensationKey { BATTERY_CURVE_COMPENSATE_STATUS_LED , BATTERY_CURVE_COMPENSATE_COUNT }
 Source of a voltage compensation. More...
 

Functions

void battery_curve_set_compensation (BatteryCurveVoltageCompensationKey key, int mv)
 Set a compensation added to the measured voltage when computing the charge.
 
void battery_curve_set_full_voltage (uint16_t voltage)
 Move the 100 % point of the discharge curve.
 
uint32_t battery_curve_sample_ratio32_charge_percent (uint32_t battery_mv, bool is_charging)
 Get the charge for a voltage, applying the compensations.
 
int32_t battery_curve_lookup_percent_with_scaling_factor (int battery_mv, bool is_charging, uint32_t scaling_factor)
 Get the charge for a voltage, scaled by a factor, without compensations.
 
uint32_t battery_curve_get_hours_remaining (uint32_t percent_remaining)
 Get the hours of use left before low power mode.
 
uint32_t battery_curve_get_percent_remaining (uint32_t hours)
 Get the charge needed for some hours of use before low power mode.
 
uint32_t battery_curve_lookup_voltage_by_percent (uint32_t percent, bool is_charging)
 Get the voltage for a charge percentage.
 

Detailed Description

Conversion between battery voltage, charge percentage and time remaining.

The voltage curve backend uses per-board charge and discharge curves; with the nRF fuel gauge only the time remaining conversions are functional.

Enumeration Type Documentation

◆ BatteryCurveVoltageCompensationKey

Source of a voltage compensation.

Enumerator
BATTERY_CURVE_COMPENSATE_STATUS_LED 

Load of the status LED.

BATTERY_CURVE_COMPENSATE_COUNT 

Number of compensation sources.

Function Documentation

◆ battery_curve_get_hours_remaining()

uint32_t battery_curve_get_hours_remaining ( uint32_t  percent_remaining)

Get the hours of use left before low power mode.

Parameters
percent_remainingCharge in percent, including the low power reserve.
Returns
Hours remaining.

◆ battery_curve_get_percent_remaining()

uint32_t battery_curve_get_percent_remaining ( uint32_t  hours)

Get the charge needed for some hours of use before low power mode.

Inverse of battery_curve_get_hours_remaining().

Parameters
hoursHours of use.
Returns
Charge in percent, including the low power reserve.

◆ battery_curve_lookup_percent_with_scaling_factor()

int32_t battery_curve_lookup_percent_with_scaling_factor ( int  battery_mv,
bool  is_charging,
uint32_t  scaling_factor 
)

Get the charge for a voltage, scaled by a factor, without compensations.

Interpolates linearly between curve points and clamps to the curve ends.

Parameters
battery_mvBattery voltage in mV.
is_chargingtrue to use the charge curve.
scaling_factorValue of 1 %.
Returns
Charge in units of scaling_factor per percent.

◆ battery_curve_lookup_voltage_by_percent()

uint32_t battery_curve_lookup_voltage_by_percent ( uint32_t  percent,
bool  is_charging 
)

Get the voltage for a charge percentage.

Used by unit tests and QEMU.

Parameters
percentCharge in percent.
is_chargingtrue to use the charge curve.
Returns
Battery voltage in mV.

◆ battery_curve_sample_ratio32_charge_percent()

uint32_t battery_curve_sample_ratio32_charge_percent ( uint32_t  battery_mv,
bool  is_charging 
)

Get the charge for a voltage, applying the compensations.

Parameters
battery_mvBattery voltage in mV.
is_chargingtrue to use the charge curve.
Returns
Charge as a ratio32.

◆ battery_curve_set_compensation()

void battery_curve_set_compensation ( BatteryCurveVoltageCompensationKey  key,
int  mv 
)

Set a compensation added to the measured voltage when computing the charge.

For example, a constantly lit LED makes the measured voltage drop due to the internal resistance of the battery.

Parameters
keyCompensation source.
mvCompensation in mV.

◆ battery_curve_set_full_voltage()

void battery_curve_set_full_voltage ( uint16_t  voltage)

Move the 100 % point of the discharge curve.

Clamped so it stays above the next point of the curve.

Parameters
voltageNew 100 % voltage in mV.