battery

Hardware-independent interpretation of fuel gauge readings.

Attributes

Functions

charge_state(rate)

Classify a charge rate in percent per hour.

on_external_power(rate[, awake, usb, percent])

Whether the board runs on USB power.

format_status(percent, voltage, rate)

One-line human-readable battery status.

as_dict(percent, voltage, rate)

Battery readings as a JSON-friendly dict.

Module Contents

battery.CHARGING = 'charging'
battery.DISCHARGING = 'discharging'
battery.STABLE = 'stable'
battery.STATE_LABELS
battery.RATE_DEADBAND = 0.1
battery.charge_state(rate)

Classify a charge rate in percent per hour.

battery.AWAKE_EXIT_RATE = -1.5
battery.FULL_PERCENT = 99.0
battery.on_external_power(rate, awake=False, usb=None, percent=None)

Whether the board runs on USB power.

usb is the reading of a VBUS sense pin (see board.usb_power) and decides if available. Otherwise the fuel gauge decides: awake mode starts while the battery is charging, or while it is full (percent from FULL_PERCENT) and stable, as a full battery on USB is not charged. A “stable” battery below that is on battery: in the deep-sleep cycle the discharge is below the gauge’s resolution and reads as 0. Once awake, the mode ends only on a clear discharge (AWAKE_EXIT_RATE), which awake mode on battery soon produces. The gauge averages over minutes, so changes show up with that delay.

battery.format_status(percent, voltage, rate)

One-line human-readable battery status.

battery.as_dict(percent, voltage, rate)

Battery readings as a JSON-friendly dict.