in reply to Re: Laptop Battery Percentage
in thread Laptop Battery Percentage

the state file is kinda static, as in it shows the current state, from which one cannot deduce the percentage.

The info file is much more informative:

$ cat /proc/acpi/battery/BAT0/info present: yes design capacity: 5144 mAh last full capacity: 5144 mAh battery technology: rechargeable design voltage: 10800 mV design capacity warning: 200 mAh design capacity low: 100 mAh cycle count: 0 capacity granularity 1: 100 mAh capacity granularity 2: 100 mAh model number: Primary serial number: 49233 2011/02/25 battery type: LIon OEM info: Hewlett-Packard

Combining the two gets you to:

$ cat /proc/acpi/battery/*/* | grep capacity: design capacity: 5144 mAh last full capacity: 5144 mAh remaining capacity: 5144 mAh $

Or in perl:

$ perl -MDP -e'while(<>){/^(.*)\s+capacity:\s*((\d+).*)/ and$i{$1}=[$2 +,$3]}print"$_: $i{$_}[0], "for keys%i;printf"%5.1f%%\n",100*$i{remain +ing}[1]/$i{design}[1]' /proc/acpi/battery/*/* remaining: 5144 mAh, design: 5144 mAh, last full: 5144 mAh, 100.0%

Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^3: Laptop Battery Percentage
by jimmy.tty (Scribe) on Aug 02, 2011 at 23:36 UTC

    I use this code in gnu screen's statusbar:

    backtick 1 1 1 sh -c 'perl -ne "/^(la|re|st)[^:]+:\s+(\S+)\s/and \$h{\ +$1}=\$2}{\$h{st}=~s/of.*/-/;\$h{st}=~s/on.*/+/;printfq(%.0f%%%s),\$h{ +re}*100/\$h{la},\$h{st}" /proc/acpi/battery/BAT0/* /proc/acpi/ac_adap +ter/ACAD/state'
Re^3: Laptop Battery Percentage
by strredwolf (Chaplain) on Aug 05, 2011 at 03:18 UTC
    But what if you have two batteries? Some laptops allow that. You will have multiple lines.
    Information doesn't want to be free. It wants to be feline.

      Accumulate? Untested concept:

      $ perl -MDP -e'while(<>){/^(.*)\s+capacity:\s*((\d+).*)/||next;$i{$1}[ +0]+=$2;$i{$1}[1]//=$3}print"$_: $i{$_}[0], "for keys%i;printf"%5.1f%% +\n",100*$i{remaining}[1]/$i{design}[1]' /proc/acpi/battery/*/*

      Enjoy, Have FUN! H.Merijn