Repository navigation
fix(battery): round capacity instead of truncating it - #5398
Merged
Alexays merged 1 commit intoOct 19, 2026
Merged
Conversation
The capacity computed from charge_now/charge_full or energy_now/energy_full used integer division, so 79.5% read as 79%. With full-at that error gets scaled up: a battery stopped at an 80% threshold showed 99% (79 * 100 / 80) and never reached 100%. Fixes Alexays#5392
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5392.
The capacity computed from
charge_now/charge_fullorenergy_now/energy_fullused integer division, so it was truncated rather than rounded. Withfull-atthat error gets scaled up. With the numbers from the issue (energy_now45420000,energy_full57120000):full-at: 80: 79 * 100 / 80 = 98.75, which shows as 99% and never reaches 100%Rounding with
std::lroundgives 80, which shows 80% withoutfull-atand 100% withfull-at: 80.Testing
meson test --suite waybarin a container fromDockerfiles/debian(arm64): build OK, 3/3 tests pass, no warnings inbattery.cppclang-format --dry-run --Werroris clean