Skip to main content

Module battery

Module battery 

Source
Expand description

Battery status reader.

Provides a platform-abstracted API for reading battery state. On Linux, LinuxSysfsReader walks /sys/class/power_supply/ for the first Battery-typed entry and reads capacity, status, energy_now, power_now (or charge_now / current_now as fallback).

Non-Linux targets get UnsupportedReader which always returns BatteryError::Unsupported. default_reader picks the right implementation for the current platform.

§Example

use krypt_core::battery::default_reader;

let reader = default_reader();
match reader.read() {
    Ok(r) => println!("{}% ({})", r.percent, r.status),
    Err(e) => eprintln!("battery error: {e}"),
}

Structs§

BatteryReading
A single battery reading.
LinuxSysfsReader
Reads battery state from the Linux sysfs power-supply interface.
MockBatteryReader
A mock BatteryReader that returns a fixed result.
UnsupportedReader
Battery reader for platforms where sysfs is unavailable.

Enums§

BatteryError
Errors that can occur while reading battery state.
BatteryStatus
Battery charge/discharge status.

Traits§

BatteryReader
Abstraction over battery hardware.

Functions§

default_reader
Return the best BatteryReader for the current platform.