battery_cycles

Crates.iobattery_cycles
lib.rsbattery_cycles
version0.1.0
created_at2025-09-03 16:03:47.770602+00
updated_at2025-09-03 16:03:47.770602+00
descriptionCount battery discharge cycles using the Full Equivalent Cycle (FEC) method.
homepage
repositoryhttps://github.com/felixwatts/battery_cycles
max_upload_size
id1822743
size7,335
Felix Watts (felixwatts)

documentation

README

Battery Cycles

Count battery discharge cycles using the Full Equivalent Cycle (FEC) method.

Usage

use std::time::Duration;
use battery_cycles::BatteryCycleCounter;

let battery_capacity_ah = 10.0;
let initial_cycle_count = 0.0;

let mut battery_cycle_counter = BatteryCycleCounter::new(battery_capacity_ah, initial_cycle_count, None);

// Repeatedly update the BatteryCycleCounter with the current discharge current
for _ in 0..10 {
    // Some time passes
    // The shorter the time between updates the more accurately the cycles will be tracked
    std::thread::sleep(Duration::from_secs_f32(1.0));

    // Measure the current discharge current of your battery somehow
    // a positive number means it's discharging, a negative number means its charging
    let battery_discharge_current_a = 0.42;

    // Repeatedly update the BatteryCycleCounter with the current discharge current
    battery_cycle_counter.update(battery_discharge_current_a, None);
}

// Get the current equivalent cycle count via the `cycle_count` method
let cycle_count = battery_cycle_counter.cycle_count();
println!("The battery has completed {cycle_count} equivalent cycles.");
Commit count: 2

cargo fmt