You are not logged in.

#1 2024-06-05 16:33:14

Norma Jenkins
Member
Registered: 2023-09-19
Posts: 19

[SOLVED] Battery is at 101%

101 Fastfetch
As shown here, fastfetch returned 101 as battery %, is it just a bug or is the reader just broken?

EDIT: marking as resolved by recent reply by @lmn

Last edited by Norma Jenkins (2024-06-05 20:02:19)

Offline

#2 2024-06-05 17:08:33

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [SOLVED] Battery is at 101%

What's the output from `cat /sys/class/power_supply/BAT?/capacity`?  If that shows 101, then something is odd with your battery or the kernel's handling of it.

It's far more likely a fastfetch bug though.  I glanced at the code and it seems to retrieve the string representation of an integer value of the percent from sysfs, but then converts that string to a floating point number only later to convert it back to an integer and then string for printing.  Such repeated (and needless) conversions can result in "rounding" errors.

Last edited by Trilby (2024-06-05 17:13:34)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2024-06-05 17:15:43

Norma Jenkins
Member
Registered: 2023-09-19
Posts: 19

Re: [SOLVED] Battery is at 101%

Trilby wrote:

What's the output from `cat /sys/class/power_supply/BAT?/capacity`?  If that shows 101, then something is odd with your battery or the kernel's handling of it.

It's far more likely a fastfetch bug though.  I glanced at the code and it seems to retrieve the string representation of an integer value of the percent from sysfs, but then converts that string to a floating point number only later to convert it back to an integer and then string for printing.  Such repeated (and needless) conversions can result in "rounding" errors.

Actually it did output 101, in my xorg bar I have

xsetroot -name "$(cat /sys/class/power_supply/BAT1/capacity)%

and from that I saw 101, later I checked fastfetch to see if one was wrong. WHat do you reccomend me to do?

Offline

#4 2024-06-05 19:43:20

lmn
Member
Registered: 2021-05-09
Posts: 88
Website

Re: [SOLVED] Battery is at 101%

The values read by the kernel from the battery are affected by the (self) calibration of the hardware. Batteries decay over time and to compensate for this behavior modern batteries routinely update their maximum capacity readings. The curve is not monotonically decreasing but can temporarily jump upwards. Whats seems to have happened here is that the current capacity surpasses the calibrated max capacity and as a result it show a value over 100%. When the next calibration is triggered the value should normalize to 100%.

Edit: As I also use this value to display the remaining capacity, i too have observed this behavior.
For those interested here is a link to graph of a real device.

Last edited by lmn (2024-06-05 19:51:43)

Offline

Board footer

Powered by FluxBB