unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ken Raeburn <raeburn@raeburn.org>
Cc: emacs-devel@gnu.org
Subject: Re: Darwin support for lisp/battery.el.
Date: Mon, 4 Jul 2005 05:31:56 -0400	[thread overview]
Message-ID: <c5127847fa380b018a4319d71d2577eb@raeburn.org> (raw)
In-Reply-To: <87y88nvx36.fsf@xs4all.nl>

On Jul 4, 2005, at 03:39, Lute Kamstra wrote:
> My patch tries to test whether pmset supports "-g ps" by looking at
> the exit code.  Does "pmset -g ps" return a non-zero exit code on your
> system?

No, it looks like "pmset -g anything" will give a zero exit status; it  
just doesn't print out anything unless you give it one of the supported  
options.  "pmset -g golf-ball" quite happily returns a zero exit  
status.

> Do you know of a way to get battery information on your system?

 From the command line... not yet.  From some poking around through  
Google, it looks like the output of "ioreg -w0 -l | grep Capacity" may  
have some or all of the data you'd want; I'm not sure yet.

I get:

     | | |   "IOBatteryInfo" = ({"Capacity"=4520,"Amperage"=0,"Cycle  
Count"=139,"Current"=4278,"Voltage"=12368,"Flags"=1090519045,"AbsoluteMa 
xCapacity"=5400})
     | |   |   |     "IOBatteryInfo" =  
({"Capacity"=4520,"Amperage"=0,"Cycle  
Count"=139,"Current"=4278,"Voltage"=12368,"Flags"=1090519045,"AbsoluteMa 
xCapacity"=5400})

on AC current and

     | | |   "IOBatteryInfo" = ({"Capacity"=4520,"Amperage"=0,"Cycle  
Count"=139,"Current"=4278,"Voltage"=12368,"Flags"=4,"AbsoluteMaxCapacity 
"=5400})
     | |   |   |     "IOBatteryInfo" =  
({"Capacity"=4520,"Amperage"=0,"Cycle  
Count"=139,"Current"=4278,"Voltage"=12368,"Flags"=4,"AbsoluteMaxCapacity 
"=5400})

on battery.  (The leading vertical bars seem to be part of an ASCII  
graphical diagram of a hierarchy of registry keys and values.  "-w0"  
seems to mean "width 0", i.e., don't truncate the output lines.)

The Flags field is described a little bit at  
http://www.macosxhints.com/comment.php? 
mode=display&sid=20030311220217671&title=Give+your+battery+a+thorough+ch 
eckup&pid=0
as having value 0x004 on battery and 0x005 on AC (the value 1090519045  
above is 0x41000005) and 0x08x or 0x09x values when power gets low.  I  
didn't find any mention of "battery" in the system header files, nor  
any relevant mention of "power".

It also seems, from some of the other comments, that Current/Capacity  
should be the current level of charge in the battery (so I'm at 94%,  
kind of disappointing immediately after unplugging the power, but the  
Mac GUI display agrees with it).

http://www.dssw.co.uk/sleepcentre/threads/ 
ioreg_bat_sh_was_re_10_3_6_what_.html
indicates that "ioreg -p IODeviceTree -n battery -w 0" may be a better  
choice (it only produces 108 lines of output on my system, versus 4238  
for "ioreg -l -w 0"), but the output still has to be filtered for the  
IOBatteryInfo capacity line.

http://www.macosxhints.com/article.php?story=20030311220217671
has an awk script for reformatting the data, and a claim that
 >> The results for "capacity" and "current" are in microamperes per  
hour (mAh).
I always thought "mAh" was milliamp-hours (times hours, not per hour),  
but some math suggests that 10**6 is probably the right scaling factor  
in there somewhere.

I'm running 10.3.9, and at  
http://www.mitt-eget.com/software/macosx/#battery it says that the  
ioreg output format changed in 10.3.8, and again in 10.4, so parsing  
this may be a little annoying.  However, there's also a link to a  
script which can parse the output, and comments describing what the  
author thinks many of the flags are; following its logic shouldn't be  
too hard.  The tough part may be dealing with the amperage when it's  
nonzero -- apparently it's a 64-bit value which can be negative, but is  
displayed as unsigned.  The emacs I've got on my system parses  
"18446744073709549763" and comes up with "-1", when what we want is  
"-1853".

I'll see if I can poke at this a little more, later...

Ken

  parent reply	other threads:[~2005-07-04  9:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-02 12:21 Darwin support for lisp/battery.el Lute Kamstra
2005-07-02 13:49 ` David Kastrup
2005-07-02 14:33   ` Lute Kamstra
2005-07-02 15:16     ` David Kastrup
2005-07-03 20:42 ` Richard M. Stallman
2005-07-03 21:28   ` David Kastrup
2005-07-03 22:34     ` Lute Kamstra
2005-07-03 22:46       ` David Kastrup
2005-07-04  2:41         ` Ken Raeburn
2005-07-04  7:39           ` Lute Kamstra
2005-07-04  8:28             ` Arne Jørgensen
2005-07-04  9:44               ` Lute Kamstra
     [not found]                 ` <87pstysxke.fsf@seamus.arnested.dk>
2005-07-04 10:43                   ` Lute Kamstra
2005-07-04  9:31             ` Ken Raeburn [this message]
2005-07-04  9:40               ` Ken Raeburn
2005-07-06 11:42               ` Lute Kamstra
2005-07-06 13:05                 ` Sean O'Rourke
2005-07-09 10:13                   ` Lute Kamstra
2005-07-04 14:51     ` Richard M. Stallman
2005-07-04 15:30       ` David Kastrup
2005-07-05 16:12         ` Richard M. Stallman
2005-07-05 20:27           ` Aidan Kehoe
2005-07-03 22:32   ` Lute Kamstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c5127847fa380b018a4319d71d2577eb@raeburn.org \
    --to=raeburn@raeburn.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).