Battery

lpf2.battery groups the battery-voltage tracker plus an optional ADC divider reader. All methods are @staticmethod.

Voltage window

Set the full-charge / cutoff voltages (millivolts). Defaults: max 9000, min 6000, current = max.

lpf2.battery.setMaxVoltage(8400)
lpf2.battery.setMinVoltage(6400)

print(lpf2.battery.getMaxVoltage(), lpf2.battery.getMinVoltage())

Manual voltage updates

If you sample the battery yourself, publish the value so the tracker can compute percent:

lpf2.battery.setCurrentVoltage(7350)
print(lpf2.battery.getCurrentVoltage())
print(lpf2.battery.getPercent())

Custom percent mapping

Replace the default linear mapping with any Python callable fn(mV, vmin, vmax) -> int:

def li_ion(mv, vmin, vmax):
    # non-linear discharge curve
    ...

lpf2.battery.setPercentFunc(li_ion)
lpf2.battery.setPercentFunc(None)     # restore default

Built-in ADC reader

Configure the ESP-IDF ADC for a resistive divider from battery → tap → GND:

ok = lpf2.battery.setupAdcDivider(
    adc_channel=6,     # ESP-IDF adc_channel_t
    adc_unit=0,        # ESP-IDF adc_unit_t
    r_top_ohms=100_000,
    r_bottom_ohms=33_000,
    vref_mv=3300,
    samples=8,
)

Then poll it as often as you like:

mv = lpf2.battery.readBatteryVoltage()   # also updates current

Reference: lpf2.battery.