You are not logged in.

#1 2012-05-12 07:48:23

neurolysis
Member
Registered: 2011-02-23
Posts: 112
Website

cellout - simple battery status printer

cellout is a simple battery status printer for the console, written in POSIX awk.

Usage:

cellout [-g] battery

Example output for 97% capacity, charging:

97C

Example output with graphical charge meter for 49% capacity, discharging:

[##--] 49D

It is available on the AUR at https://aur.archlinux.org/packages.php?ID=59222.

Feedback appreciated!

Last edited by neurolysis (2012-05-24 10:40:49)

Offline

#2 2012-05-12 23:18:02

ninian
Member
From: United Kingdom
Registered: 2008-02-24
Posts: 726
Website

Re: cellout - simple battery status printer

Ah, so that's how you work out the battery charge! Some quick comments:
- I'm getting the graphical charge meter regardless of whether I specify -g or not.
- Graphical charge meter would be more reasonable in 10% steps; 25% is too coarse.
- Could you assume battery is always BATn so you just need to specify n on the command line?
- Defaulting battery to BAT0 would be convenient

Offline

#3 2012-05-13 03:55:38

neurolysis
Member
Registered: 2011-02-23
Posts: 112
Website

Re: cellout - simple battery status printer

ninian wrote:

Ah, so that's how you work out the battery charge! Some quick comments:
- I'm getting the graphical charge meter regardless of whether I specify -g or not.

Can't reproduce this... odd.

$ cellout BAT1
100F
$ cellout -g BAT1
[####] 100F
ninian wrote:

- Graphical charge meter would be more reasonable in 10% steps; 25% is too coarse.

Fundamentally disagree from a usability perspective, it should be readable at a glance with accuracy provided by the numeric output. Perhaps 5 steps would be better, but I don't know.

ninian wrote:

- Could you assume battery is always BATn so you just need to specify n on the command line?

It isn't always (I've had computers where it is called other things, for example, ACAD0).

ninian wrote:

- Defaulting battery to BAT0 would be convenient

I really don't like implicit defaults from a usability perspective, I find them kind of against my philosophy.

Thanks for the feedback!

Last edited by neurolysis (2012-05-13 03:59:45)

Offline

#4 2012-05-13 08:00:29

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

Re: cellout - simple battery status printer

Nice app.

ninian wrote:

I'm getting the graphical charge meter regardless of whether I specify -g or not.

Same issue here:

┌─[Archer ~]
└─╼ cellout BAT0
[####] 100F
┌─[Archer ~]
└─╼ cellout -g BAT0
Could not read /sys/class/power_supply/-g/charge_full

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2012-05-13 08:59:47

ivoarch
Member
Registered: 2011-03-31
Posts: 436

Re: cellout - simple battery status printer

I have the same problem

~ >> cellout  C174   
[####] 98U

~ >> cellout  -g C174
Could not read /sys/class/power_supply/-g/charge_full
~ >>


I love GnuEmacs, GnuScreen, ratpoison, and conkeror.
Github )||( Weblog

Offline

#6 2012-05-22 18:27:47

neurolysis
Member
Registered: 2011-02-23
Posts: 112
Website

Re: cellout - simple battery status printer

I really don't understand why that is happening, it doesn't happen for me. Although, having said that, where is this "Could not read" text coming from? That's not anywhere in the source...

Last edited by neurolysis (2012-05-22 18:33:31)

Offline

#7 2012-05-22 19:11:32

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

Re: cellout - simple battery status printer

I assumed it had something to do with an error relating to the path

Could not read /sys/class/power_supply/-g/charge_full

...the -g switch is being dumped in there somehow.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#8 2012-05-22 21:07:55

neurolysis
Member
Registered: 2011-02-23
Posts: 112
Website

Re: cellout - simple battery status printer

jasonwryan wrote:

I assumed it had something to do with an error relating to the path

Could not read /sys/class/power_supply/-g/charge_full

...the -g switch is being dumped in there somehow.

Yes, but I have no string in the source that says "Could not read ...".

Last edited by neurolysis (2012-05-22 21:08:28)

Offline

#9 2012-05-22 21:49:27

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

Re: cellout - simple battery status printer

This?

┌─[Veles ~]
└─╼ grep -R "Could not read" Build/cellout/
Build/cellout/src/cellout:    [ -r "${_file}" ] || _die "Could not read ${_file}"
Build/cellout/pkg/usr/bin/cellout:    [ -r "${_file}" ] || _die "Could not read ${_file}"

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#10 2012-05-22 22:11:37

dammannj
Member
Registered: 2009-01-28
Posts: 44

Re: cellout - simple battery status printer

Here my experiences:
When I suspend and then resume the charge filenames change.
The variables given by 'uevent' change as well.
Must be a kernel bug; but I didn't have the time to report it yet, and I haven't reported any bug til now, and am not sure how to do it.

I use a simple shell script for my battery status needs:

. "/sys/bus/acpi/drivers/battery/PNP0C0A:00/power_supply/BAT0/uevent"

[ -z "${POWER_SUPPLY_ENERGY_NOW}" ] && prefix=CHARGE || prefix=ENERGY

eval now=\${POWER_SUPPLY_${prefix}_NOW}
eval full=\${POWER_SUPPLY_${prefix}_FULL}
eval full_design=\${POWER_SUPPLY_${prefix}_FULL_DESIGN}

Solves it for my needs at the moment, maybe you can check for the filenames, too?

Edit for clarity: after resume, /sys/class/power_supply/foo/charge_full might become  /sys/class/power_supply/foo/energy_full (or the other way around, no battery plugged in atm, so can't check)

Last edited by dammannj (2012-05-22 22:13:46)

Offline

#11 2012-05-22 22:20:07

neurolysis
Member
Registered: 2011-02-23
Posts: 112
Website

Re: cellout - simple battery status printer

jasonwryan wrote:

This?

┌─[Veles ~]
└─╼ grep -R "Could not read" Build/cellout/
Build/cellout/src/cellout:    [ -r "${_file}" ] || _die "Could not read ${_file}"
Build/cellout/pkg/usr/bin/cellout:    [ -r "${_file}" ] || _die "Could not read ${_file}"

The package is cellout-git, not cellout! (I really need to get my old packages removed from AUR).

Last edited by neurolysis (2012-05-22 22:20:54)

Offline

#12 2012-05-22 22:34:42

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

Re: cellout - simple battery status printer

neurolysis wrote:
jasonwryan wrote:

This?

┌─[Veles ~]
└─╼ grep -R "Could not read" Build/cellout/
Build/cellout/src/cellout:    [ -r "${_file}" ] || _die "Could not read ${_file}"
Build/cellout/pkg/usr/bin/cellout:    [ -r "${_file}" ] || _die "Could not read ${_file}"

The package is cellout-git, not cellout! (I really need to get my old packages removed from AUR).

LOL. I wondered why it was orphaned... tongue


# edit:

┌─[Veles ~]
└─╼ cellout -g BAT0
[###-] 99U
┌─[Veles ~]
└─╼ cellout BAT0
[###-] 99U

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#13 2012-05-22 23:10:53

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: cellout - simple battery status printer

Doesn't work on my T420S, where these files are named differently:

 ls /sys/class/power_supply/BAT1
power  cycle_count  energy_full         energy_now    model_name  present        status     technology  uevent              voltage_now
alarm  device       energy_full_design  manufacturer  power_now   serial_number  subsystem  type        voltage_min_design

And IMO, C seems a bit awkward for something like this. Awk feels more appropriate: http://paste.xinu.at/vfwW5/

Last edited by falconindy (2012-05-22 23:13:07)

Offline

#14 2012-05-22 23:43:47

neurolysis
Member
Registered: 2011-02-23
Posts: 112
Website

Re: cellout - simple battery status printer

Hmm, I guess I will try to make this more robust. I wonder why the names differ?

Offline

#15 2012-05-24 10:40:36

neurolysis
Member
Registered: 2011-02-23
Posts: 112
Website

Re: cellout - simple battery status printer

Now rewritten in POSIX awk with substantiative contributions from falconindy.

Offline

#16 2012-05-24 13:54:07

Rolinh
Member
From: Switzerland
Registered: 2011-05-07
Posts: 144
Website

Re: cellout - simple battery status printer

I also thought C was a bit awkward for this purpose.

However:

[robin@thor ~/Hacking/git/cellout] % ./cellout
usage: cellout [-g] battery
!1! [robin@thor ~/Hacking/git/cellout] % ./cellout -g
[robin@thor ~/Hacking/git/cellout] % ./cellout BAT0
94D
[robin@thor ~/Hacking/git/cellout] % ./cellout BAT0 -g
usage: cellout [-g] battery
!1! [robin@thor ~/Hacking/git/cellout] % ./cellout -g BAT0
[robin@thor ~/Hacking/git/cellout] %  

So yes, it does not display anything when using -g option.

I am not familiar with awk but why test the length of ARGV? isn't it possible to use ARGC?

EDIT:
I can confirm we can definitely use ARGC in awk:

diff --git a/cellout b/cellout
index 7c4b8b6..69526ef 100755
--- a/cellout
+++ b/cellout
@@ -20,10 +20,10 @@ function display_graphical(now, full, status) {
 }
 
 BEGIN {
-    if (length(ARGV) == 2) {
+    if (ARGC == 2) {
         graphical = 0
         battery = ARGV[1]
-    } else if ((length(ARGV) == 3) && (ARGV[1] == "-g")) {
+    } else if ((ARGC == 3) && (ARGV[1] == "-g")) {
         graphical = 1
         battery = ARGV[2]
     } else {

Last edited by Rolinh (2012-05-24 13:59:05)

Offline

#17 2012-05-25 07:55:49

dammannj
Member
Registered: 2009-01-28
Posts: 44

Re: cellout - simple battery status printer

I see you have incorporated the fix I tried to describe.
Just in case anyone would prefer a POSIX sh version, here it is (using uevent):

#!/bin/sh

display_graphical()
{
        echo -n '['
        i=0;
        while [ $i -lt $(( $now_percent / 25 )) ]; do
                echo -n '#'
                i=$(( $i + 1 ))
        done
        while [ $i -lt 4 ]; do
                echo -n '-'
                i=$(( $i + 1 ))
        done
        echo -n '] '
}

graphical=false

for o in "${@}"; do
        case "${o}" in -g) graphical=true;; *) battery="${o}" ;; esac
done
[ -z "${battery}" ] && echo "usage: cellout [-g] <battery>" && exit 1

. "/sys/bus/acpi/drivers/battery/PNP0C0A:00/power_supply/${battery}/uevent"

[ -z "${POWER_SUPPLY_ENERGY_NOW}" ] && prefix=CHARGE || prefix=ENERGY

eval now=\${POWER_SUPPLY_${prefix}_NOW}
eval full=\${POWER_SUPPLY_${prefix}_FULL}

now_percent=$(( ${now} * 100 / ${full} ))
status=$(printf '%c' ${POWER_SUPPLY_STATUS})

${graphical} && display_graphical
echo "${now_percent}${status}"

It's a shameless "feature copy" of cellout, so I used the name, hope you don't mind wink
This does only depend on a POSIX like shell, and is a little bit shorter smile
EDIT: fixed a little typo...

Last edited by dammannj (2012-05-25 07:59:34)

Offline

#18 2012-05-25 23:45:43

neurolysis
Member
Registered: 2011-02-23
Posts: 112
Website

Re: cellout - simple battery status printer

Rolinh wrote:

It does not display anything when using -g option.

As shown in the manual, the option must come before the battery ID.

Rolinh wrote:

I am not familiar with awk but why test the length of ARGV? isn't it possible to use ARGC?

True, I just copied it verbatim from falconindy's snippet. Done now.

Offline

#19 2012-05-26 18:57:12

Rolinh
Member
From: Switzerland
Registered: 2011-05-07
Posts: 144
Website

Re: cellout - simple battery status printer

neurolysis wrote:

As shown in the manual, the option must come before the battery ID.

As you can see in what I posted: I tried both without success wink

Offline

#20 2012-05-31 16:07:58

neurolysis
Member
Registered: 2011-02-23
Posts: 112
Website

Re: cellout - simple battery status printer

I finally worked out what it is.

Your version of awk is interpreting -g as an option. Try:

cellout -- -g BAT0

Offline

#21 2012-05-31 17:08:20

Rolinh
Member
From: Switzerland
Registered: 2011-05-07
Posts: 144
Website

Re: cellout - simple battery status printer

Yep, that did it:

[robin@thor ~/Hacking/git/cellout] % ./cellout -g BAT0
[robin@thor ~/Hacking/git/cellout] % ./cellout -- -g BAT0
[####] 99U

Weird though.

Offline

Board footer

Powered by FluxBB