Handle charging above 100% gracefully
When calibrating a battery it's possible to go above 100%. Handle that gracefully by just presenting the battery as full and 100%.
This commit is contained in:
parent
a7056f7cce
commit
e0cdcb6e30
|
@ -115,6 +115,11 @@ const std::tuple<uint8_t, float, std::string> waybar::modules::Battery::getInfos
|
||||||
time_remaining = (float)total_energy / total_power;
|
time_remaining = (float)total_energy / total_power;
|
||||||
} else if (status == "Charging" && total_power != 0) {
|
} else if (status == "Charging" && total_power != 0) {
|
||||||
time_remaining = -(float)(total_energy_full - total_energy) / total_power;
|
time_remaining = -(float)(total_energy_full - total_energy) / total_power;
|
||||||
|
if (time_remaining > 0.0f) {
|
||||||
|
// If we've turned positive it means the battery is past 100% and so
|
||||||
|
// just report that as no time remaining
|
||||||
|
time_remaining = 0.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
float capacity = ((float)total_energy * 100.0f / (float) total_energy_full);
|
float capacity = ((float)total_energy * 100.0f / (float) total_energy_full);
|
||||||
// Handle full-at
|
// Handle full-at
|
||||||
|
@ -127,6 +132,12 @@ const std::tuple<uint8_t, float, std::string> waybar::modules::Battery::getInfos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (capacity > 100.f) {
|
||||||
|
// This can happen when the battery is calibrating and goes above 100%
|
||||||
|
// Handle it gracefully by clamping at 100% and presenting it as full
|
||||||
|
capacity = 100.f;
|
||||||
|
status = "Full";
|
||||||
|
}
|
||||||
return {capacity, time_remaining, status};
|
return {capacity, time_remaining, status};
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
spdlog::error("Battery: {}", e.what());
|
spdlog::error("Battery: {}", e.what());
|
||||||
|
|
Loading…
Reference in New Issue