Conversion between battery voltage, charge percentage and time remaining.
More...
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.
◆ 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.
|
◆ 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_remaining | Charge 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
-
- 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_mv | Battery voltage in mV. |
| is_charging | true to use the charge curve. |
| scaling_factor | Value 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
-
| percent | Charge in percent. |
| is_charging | true 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_mv | Battery voltage in mV. |
| is_charging | true to use the charge curve. |
- Returns
- Charge as a ratio32.
◆ battery_curve_set_compensation()
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
-
| key | Compensation source. |
| mv | Compensation 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
-
| voltage | New 100 % voltage in mV. |