You are not logged in.

#1 2015-11-06 06:54:49

Ocypheum
Member
Registered: 2015-09-26
Posts: 58

[Solved] Calculate battery capacity

One of the statusbar examples on the dwm page has the following formula for calculating battery capacity:

DWM_BATTERY=$(( `cat /sys/class/power_supply/BAT0/energy_now` * 100 / `cat /sys/class/power_supply/BAT0/energy_full` ));

I noticed on my system this can be replaced with:

DWM_BATTERY=$( cat /sys/class/power_supply/BAT1/capacity )

Aside from the fact that my battery is named BAT1 instead of BAT0, can laptop users generally count on this file being present? If so then the example can be simplified.

Last edited by Ocypheum (2015-11-07 22:36:10)

Offline

#2 2015-11-06 06:59:53

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [Solved] Calculate battery capacity

Not necessarily. The example could certainly be made more efficient, but different models of laptop tend to report different information.

In any event, example in the wiki should just be considered examples, not canonical references: people are expected to adapt them to their own situations, not just copy and paste.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2015-11-06 07:48:21

dice
Member
From: Germany
Registered: 2014-02-10
Posts: 413

Re: [Solved] Calculate battery capacity

Just out of curiosity I checked if I have that capacity_level file because I have some battery related scripts and wanted to see if there is something useful in there.

$ cat /sys/class/power_supply/BAT0/capacity_level 
Normal

Well...nice to know. I guess when the battery is low of charge it reports 'Low' instead.
So yeah, these information and their structure is machine dependent and there is no one script fits it all.


I put at button on it. Yes. I wish to press it, but I'm not sure what will happen if I do.  (Gune | Titan A.E.)

Offline

#4 2015-11-07 22:35:06

Ocypheum
Member
Registered: 2015-09-26
Posts: 58

Re: [Solved] Calculate battery capacity

dice wrote:

Well...nice to know. I guess when the battery is low of charge it reports 'Low' instead.

Oops, that's because I said the wrong file. Check out /sys/class/power_supply/BAT0/capacity instead.

Anyways, point taken smile

(I also fixed my original post.)

Last edited by Ocypheum (2015-11-07 22:35:59)

Offline

Board footer

Powered by FluxBB