Re: [dev] How to monitor battery status

From: Ethan Grammatikidis <eekee57_AT_fastmail.fm>
Date: Mon, 4 Jul 2011 13:13:04 +0100

On Mon, 20 Jun 2011 06:47:35 -0400
Kurt H Maier <karmaflux_AT_gmail.com> wrote:

> On Mon, Jun 20, 2011 at 5:59 AM, ilf <ilf_AT_zeromail.org> wrote:
> > I have done this the /proc/acpi/battery/BAT0/state | shell way for years and
> > found it to be way more resource intense then calling acpi -b.
> >
> > Let's face it, the Shell/Perl/Python/whatever scripting is relatively easy,
> > but very inefficient.
>
> I update my status bar every 50 seconds. I sacrifice, for this,
> approximately thirty seconds of battery life on a battery that lasts
> on the order of seven hours to a charge. I'm not particularly
> concerned by this 'inefficiency,' to be honest.

Heh, thanks for that, the talk of inefficiency had me worried for a minute. I should know better, I've observed most usage of the word "inefficiency" is worthless talk anyway, particularly in a computing context.

My offering; I made this to run in 9vx when I run it full-screen for long periods. NOTE: has some issues with a kfs-root due to the fid bug in 9vx.

#!/bin/rc

# battery monitor for recent Linux machines
# if running under p9p, remove all '#Z'
# if 9vx, canopenpath must be unset

fn cd

cd '#Z'/sys/class/power_supply/BAT0

bat = `{hoc -e `{cat charge_now } ^ / ^ `{cat charge_full} ^ '*100' | sed 's/\..*//'}

charging=''
cd '#Z'/sys/class/power_supply/AC0

if(~ `{cat online} 1) {
        if(~ $bat 100)
                charging = ' charged'
        if not
                charging = ' charging'
}

echo $"bat ^ % ^ $charging
Received on Mon Jul 04 2011 - 14:13:04 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 04 2011 - 14:24:02 CEST