mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
daemon: clamp battery discharge rate to a maximum of 100%/hour
This commit is contained in:
parent
f71534f7ef
commit
4fcfeb073d
1 changed files with 6 additions and 2 deletions
|
@ -191,13 +191,17 @@ impl SystemHistory {
|
||||||
(self.last_battery_percentage, self.last_battery_timestamp)
|
(self.last_battery_percentage, self.last_battery_timestamp)
|
||||||
{
|
{
|
||||||
let elapsed_hours = last_timestamp.elapsed().as_secs_f32() / 3600.0;
|
let elapsed_hours = last_timestamp.elapsed().as_secs_f32() / 3600.0;
|
||||||
if elapsed_hours > 0.0 && !battery.ac_connected {
|
// Only calculate discharge rate if at least 30 seconds have passed
|
||||||
|
// and we're not on AC power
|
||||||
|
if elapsed_hours > 0.0083 && !battery.ac_connected { // 0.0083 hours = 30 seconds
|
||||||
// Calculate discharge rate in percent per hour
|
// Calculate discharge rate in percent per hour
|
||||||
let percent_change = last_percentage - current_percent;
|
let percent_change = last_percentage - current_percent;
|
||||||
if percent_change > 0.0 {
|
if percent_change > 0.0 {
|
||||||
// Only if battery is discharging
|
// Only if battery is discharging
|
||||||
let hourly_rate = percent_change / elapsed_hours;
|
let hourly_rate = percent_change / elapsed_hours;
|
||||||
self.battery_discharge_rate = Some(hourly_rate);
|
// Clamp the discharge rate to a reasonable maximum value (100%/hour)
|
||||||
|
let clamped_rate = hourly_rate.min(100.0);
|
||||||
|
self.battery_discharge_rate = Some(clamped_rate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue