| Crates.io | battery_cycles |
| lib.rs | battery_cycles |
| version | 0.1.0 |
| created_at | 2025-09-03 16:03:47.770602+00 |
| updated_at | 2025-09-03 16:03:47.770602+00 |
| description | Count battery discharge cycles using the Full Equivalent Cycle (FEC) method. |
| homepage | |
| repository | https://github.com/felixwatts/battery_cycles |
| max_upload_size | |
| id | 1822743 |
| size | 7,335 |
Count battery discharge cycles using the Full Equivalent Cycle (FEC) method.
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.");