* Darwin support for lisp/battery.el.
@ 2005-07-02 12:21 Lute Kamstra
2005-07-02 13:49 ` David Kastrup
2005-07-03 20:42 ` Richard M. Stallman
0 siblings, 2 replies; 23+ messages in thread
From: Lute Kamstra @ 2005-07-02 12:21 UTC (permalink / raw)
Currently, lisp/battery.el supports only Linux. I've added support
for Darwin. See the patch below. Is it ok to install this now, or
should I wait until after the release?
Lute.
2005-07-02 Lute Kamstra <lute@gnu.org>
* battery.el: Add support for Darwin (with much debugging help
from Samuel Lauber <sam124@operamail.com>).
(battery-status-function, battery-echo-area-format)
(battery-mode-line-format): Add support for pmset on Darwin.
(battery-load-low, battery-load-critical): New user options.
(battery-pmset): New function.
Index: lisp/battery.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/battery.el,v
retrieving revision 1.26
diff -c -r1.26 battery.el
*** lisp/battery.el 1 Jul 2005 11:02:16 -0000 1.26
--- lisp/battery.el 2 Jul 2005 11:59:04 -0000
***************
*** 25,33 ****
;;; Commentary:
! ;; There is at present support for interpreting the new `/proc/apm'
! ;; file format of Linux version 1.3.58 or newer and for the `/proc/acpi/'
! ;; directory structure of Linux 2.4.20 and 2.6.
;;; Code:
--- 25,34 ----
;;; Commentary:
! ;; There is at present support for Linux and Darwin. This library
! ;; supports both the `/proc/apm' file format of Linux version 1.3.58
! ;; or newer and the `/proc/acpi/' directory structure of Linux 2.4.20
! ;; and 2.6. Darwin is supported by using the `pmset' program.
;;; Code:
***************
*** 46,52 ****
'battery-linux-proc-apm)
((and (eq system-type 'gnu/linux)
(file-directory-p "/proc/acpi/battery"))
! 'battery-linux-proc-acpi))
"*Function for getting battery status information.
The function has to return an alist of conversion definitions.
Its cons cells are of the form
--- 47,57 ----
'battery-linux-proc-apm)
((and (eq system-type 'gnu/linux)
(file-directory-p "/proc/acpi/battery"))
! 'battery-linux-proc-acpi)
! ((and (eq system-type 'darwin)
! (ignore-errors
! (eq (call-process "pmset" nil nil nil "-g" "ps") 0)))
! 'battery-pmset))
"*Function for getting battery status information.
The function has to return an alist of conversion definitions.
Its cons cells are of the form
***************
*** 62,68 ****
(cond ((eq battery-status-function 'battery-linux-proc-apm)
"Power %L, battery %B (%p%% load, remaining time %t)")
((eq battery-status-function 'battery-linux-proc-acpi)
! "Power %L, battery %B at %r (%p%% load, remaining time %t)"))
"*Control string formatting the string to display in the echo area.
Ordinary characters in the control string are printed as-is, while
conversion specifications introduced by a `%' character in the control
--- 67,75 ----
(cond ((eq battery-status-function 'battery-linux-proc-apm)
"Power %L, battery %B (%p%% load, remaining time %t)")
((eq battery-status-function 'battery-linux-proc-acpi)
! "Power %L, battery %B at %r (%p%% load, remaining time %t)")
! ((eq battery-status-function 'battery-pmset)
! "%L power, battery %B (%p%% load, remaining time %t)"))
"*Control string formatting the string to display in the echo area.
Ordinary characters in the control string are printed as-is, while
conversion specifications introduced by a `%' character in the control
***************
*** 79,85 ****
(cond ((eq battery-status-function 'battery-linux-proc-apm)
"[%b%p%%]")
((eq battery-status-function 'battery-linux-proc-acpi)
! "[%b%p%%,%d°C]"))
"*Control string formatting the string to display in the mode line.
Ordinary characters in the control string are printed as-is, while
conversion specifications introduced by a `%' character in the control
--- 86,94 ----
(cond ((eq battery-status-function 'battery-linux-proc-apm)
"[%b%p%%]")
((eq battery-status-function 'battery-linux-proc-acpi)
! "[%b%p%%,%d°C]")
! ((eq battery-status-function 'battery-pmset)
! "[%b%p%%]"))
"*Control string formatting the string to display in the mode line.
Ordinary characters in the control string are printed as-is, while
conversion specifications introduced by a `%' character in the control
***************
*** 93,98 ****
--- 102,119 ----
:type 'integer
:group 'battery)
+ (defcustom battery-load-low 25
+ "*Upper bound of low battery load percentage.
+ A battery load percentage below this number is considered low."
+ :type 'integer
+ :group 'battery)
+
+ (defcustom battery-load-critical 10
+ "*Upper bound of critical battery load percentage.
+ A battery load percentage below this number is considered critical."
+ :type 'integer
+ :group 'battery)
+
(defvar battery-update-timer nil
"Interval timer object.")
***************
*** 343,348 ****
--- 364,421 ----
"N/A")))))
\f
+ ;;; `pmset' interface for Darwin.
+
+ (defun battery-pmset ()
+ "Get battery status information using `pmset'.
+
+ The following %-sequences are provided:
+ %L Power source (verbose)
+ %B Battery status (verbose)
+ %b Battery status, empty means high, `-' means low,
+ `!' means critical, and `+' means charging
+ %p Battery load percentage
+ %h Remaining time in hours
+ %m Remaining time in minutes
+ %t Remaining time in the form `h:min'"
+ (let (power-source load-percentage battery-status battery-status-symbol
+ remaining-time hours minutes)
+ (with-temp-buffer
+ (ignore-errors (call-process "pmset" nil t nil "-g" "ps"))
+ (goto-char (point-min))
+ (when (re-search-forward "Currentl?y drawing from '\\(AC\\|Battery\\) Power'" nil t)
+ (setq power-source (match-string 1))
+ (when (re-search-forward "^ -InternalBattery-0[ \t]+" nil t)
+ (when (looking-at "\\([0-9]\\{1,3\\}\\)%")
+ (setq load-percentage (match-string 1))
+ (goto-char (match-end 0))
+ (cond ((looking-at "; charging")
+ (setq battery-status "charging"
+ battery-status-symbol "+"))
+ ((< (string-to-number load-percentage) battery-load-low)
+ (setq battery-status "low"
+ battery-status-symbol "-"))
+ ((< (string-to-number load-percentage) battery-load-critical)
+ (setq battery-status "critical"
+ battery-status-symbol "!"))
+ (t
+ (setq battery-status "high"
+ battery-status-symbol "")))
+ (when (re-search-forward "\\(\\([0-9]+\\):\\([0-9]+\\)\\) remaining" nil t)
+ (setq remaining-time (match-string 1))
+ (let ((h (string-to-number (match-string 2)))
+ (m (string-to-number (match-string 3))))
+ (setq hours (number-to-string (+ h (if (< m 30) 0 1)))
+ minutes (number-to-string (+ (* h 60) m)))))))))
+ (list (cons ?L (or power-source "N/A"))
+ (cons ?p (or load-percentage "N/A"))
+ (cons ?B (or battery-status "N/A"))
+ (cons ?b (or battery-status-symbol ""))
+ (cons ?h (or hours "N/A"))
+ (cons ?m (or minutes "N/A"))
+ (cons ?t (or remaining-time "N/A")))))
+
+ \f
;;; Private functions.
(defun battery-format (format alist)
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
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-03 20:42 ` Richard M. Stallman
1 sibling, 1 reply; 23+ messages in thread
From: David Kastrup @ 2005-07-02 13:49 UTC (permalink / raw)
Cc: emacs-devel
Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:
> Currently, lisp/battery.el supports only Linux. I've added support
> for Darwin. See the patch below. Is it ok to install this now, or
> should I wait until after the release?
Can you get a tester base for most of the systems that would be
affected by this code? Does this code do anything if the mode is not
explicitly enabled?
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-02 13:49 ` David Kastrup
@ 2005-07-02 14:33 ` Lute Kamstra
2005-07-02 15:16 ` David Kastrup
0 siblings, 1 reply; 23+ messages in thread
From: Lute Kamstra @ 2005-07-02 14:33 UTC (permalink / raw)
Cc: emacs-devel
David Kastrup <dak@gnu.org> writes:
> Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:
>
>> Currently, lisp/battery.el supports only Linux. I've added support
>> for Darwin. See the patch below. Is it ok to install this now, or
>> should I wait until after the release?
>
> Can you get a tester base for most of the systems that would be
> affected by this code? Does this code do anything if the mode is
> not explicitly enabled?
The systems that are affected by this change are those whose
`system-type' is equal to darwin (and that have the "pmset" program
available). What changes for the users of those systems is that they
will be able to use display-battery-mode when they choose to do so.
(That mode just didn't do anything for them previously.)
display-battery-mode is not enabled by default.
I don't use Darwin so I couldn't really test the code myself. Samuel
Lauber was so kind to do that for me. I think there are quite some
people with laptops running OS X and using CVS Emacs. So I guess that
the code will get some decent testing when it is committed now.
Lute.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-02 14:33 ` Lute Kamstra
@ 2005-07-02 15:16 ` David Kastrup
0 siblings, 0 replies; 23+ messages in thread
From: David Kastrup @ 2005-07-02 15:16 UTC (permalink / raw)
Cc: emacs-devel
Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:
> David Kastrup <dak@gnu.org> writes:
>
> The systems that are affected by this change are those whose
> `system-type' is equal to darwin (and that have the "pmset" program
> available). What changes for the users of those systems is that
> they will be able to use display-battery-mode when they choose to do
> so. (That mode just didn't do anything for them previously.)
> display-battery-mode is not enabled by default.
>
> I don't use Darwin so I couldn't really test the code myself.
> Samuel Lauber was so kind to do that for me. I think there are
> quite some people with laptops running OS X and using CVS Emacs. So
> I guess that the code will get some decent testing when it is
> committed now.
It would appear that the worst thing that could happen is that
display-battery-mode fails to work on platforms on which it did not
work previously. Personally, I would not regard this as
release-critical as long as you make sure that it really is just
darwin that is affected.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-02 12:21 Darwin support for lisp/battery.el Lute Kamstra
2005-07-02 13:49 ` David Kastrup
@ 2005-07-03 20:42 ` Richard M. Stallman
2005-07-03 21:28 ` David Kastrup
2005-07-03 22:32 ` Lute Kamstra
1 sibling, 2 replies; 23+ messages in thread
From: Richard M. Stallman @ 2005-07-03 20:42 UTC (permalink / raw)
Cc: emacs-devel
The changes are ok (presuming they work), but there is a problem in
the comments:
! ;; There is at present support for Linux and Darwin.
Darwin is a complete operating system. To include "Linux" in that
list implies that it too is a complete operating system. That's
unfair to the GNU Project, so we won't say do that.
The current comment says "Linux" because it refers specifically to the
kernel and its version numbers. (There are no generally meaningful
version numbers for the GNU/Linux system as a whole.)
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-03 20:42 ` Richard M. Stallman
@ 2005-07-03 21:28 ` David Kastrup
2005-07-03 22:34 ` Lute Kamstra
2005-07-04 14:51 ` Richard M. Stallman
2005-07-03 22:32 ` Lute Kamstra
1 sibling, 2 replies; 23+ messages in thread
From: David Kastrup @ 2005-07-03 21:28 UTC (permalink / raw)
Cc: Lute Kamstra, emacs-devel
"Richard M. Stallman" <rms@gnu.org> writes:
> The changes are ok (presuming they work), but there is a problem in
> the comments:
>
> ! ;; There is at present support for Linux and Darwin.
>
> Darwin is a complete operating system.
Since when? AFAIK, the complete system is called MacOS.
> To include "Linux" in that list implies that it too is a complete
> operating system.
But the communication is just with the kernel, via the proc file
system.
> That's unfair to the GNU Project, so we won't say do that.
I can't see that naming the kernel when clearly the kernel is meant is
problematic.
The kernel of MacOS is Darwin. The kernel of GNU/Linux is Linux.
> The current comment says "Linux" because it refers specifically to
> the kernel and its version numbers. (There are no generally
> meaningful version numbers for the GNU/Linux system as a whole.)
Well, I don't get it. What do you want to call the MacOS kernel if
not Darwin?
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-03 21:28 ` David Kastrup
@ 2005-07-03 22:34 ` Lute Kamstra
2005-07-03 22:46 ` David Kastrup
2005-07-04 14:51 ` Richard M. Stallman
1 sibling, 1 reply; 23+ messages in thread
From: Lute Kamstra @ 2005-07-03 22:34 UTC (permalink / raw)
Cc: rms, emacs-devel
David Kastrup <dak@gnu.org> writes:
> "Richard M. Stallman" <rms@gnu.org> writes:
>
>> The changes are ok (presuming they work), but there is a problem in
>> the comments:
>>
>> ! ;; There is at present support for Linux and Darwin.
>>
>> Darwin is a complete operating system.
>
> Since when? AFAIK, the complete system is called MacOS.
>
>> To include "Linux" in that list implies that it too is a complete
>> operating system.
>
> But the communication is just with the kernel, via the proc file
> system.
>
>> That's unfair to the GNU Project, so we won't say do that.
>
> I can't see that naming the kernel when clearly the kernel is meant is
> problematic.
>
> The kernel of MacOS is Darwin. The kernel of GNU/Linux is Linux.
>
>> The current comment says "Linux" because it refers specifically to
>> the kernel and its version numbers. (There are no generally
>> meaningful version numbers for the GNU/Linux system as a whole.)
>
> Well, I don't get it. What do you want to call the MacOS kernel if
> not Darwin?
As I understand it, Darwin is a subset of OS X that includes the Mach
kernel and more.
Lute.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-03 22:34 ` Lute Kamstra
@ 2005-07-03 22:46 ` David Kastrup
2005-07-04 2:41 ` Ken Raeburn
0 siblings, 1 reply; 23+ messages in thread
From: David Kastrup @ 2005-07-03 22:46 UTC (permalink / raw)
Cc: rms, emacs-devel
Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:
> David Kastrup <dak@gnu.org> writes:
>
>> The kernel of MacOS is Darwin. The kernel of GNU/Linux is Linux.
>>
>>> The current comment says "Linux" because it refers specifically to
>>> the kernel and its version numbers. (There are no generally
>>> meaningful version numbers for the GNU/Linux system as a whole.)
>>
>> Well, I don't get it. What do you want to call the MacOS kernel if
>> not Darwin?
>
> As I understand it, Darwin is a subset of OS X that includes the
> Mach kernel and more.
Mach is only the Microkernel.
<URL:http://developer.apple.com/darwin/>
Looks like the definition of Darwin _does_ include command line
utilities.
So the proper verbage in this context would be "Linux" and "Darwin
kernel". In neither case does GNU come into play. If one wants to
drive home some point, one can say "Linux kernel" and "Darwin
kernel". But GNU/Linux is simply wrong in this context.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-03 22:46 ` David Kastrup
@ 2005-07-04 2:41 ` Ken Raeburn
2005-07-04 7:39 ` Lute Kamstra
0 siblings, 1 reply; 23+ messages in thread
From: Ken Raeburn @ 2005-07-04 2:41 UTC (permalink / raw)
On Jul 3, 2005, at 18:46, David Kastrup wrote:
> So the proper verbage in this context would be "Linux" and "Darwin
> kernel". In neither case does GNU come into play. If one wants to
> drive home some point, one can say "Linux kernel" and "Darwin
> kernel".
I don't think the two cases are quite that similar. In one case, Emacs
is interacting with a file or directory interface provided by the Linux
kernel; in the other, Emacs is communicating with a program called
"pmset", the implementation of which, in theory, doesn't have to be
tied to any particular OS kernel.
(And, BTW, the "-g ps" arguments given don't seem to do anything on my
laptop running 10.3, kernel 7.9.0; I don't know if that means it's just
not a supported option on my laptop for some reason, which would seem
kind of strange, or if the "ps" option wasn't added until 10.4.)
Ken
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
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:31 ` Ken Raeburn
0 siblings, 2 replies; 23+ messages in thread
From: Lute Kamstra @ 2005-07-04 7:39 UTC (permalink / raw)
Cc: emacs-devel
Ken Raeburn <raeburn@raeburn.org> writes:
[...]
> (And, BTW, the "-g ps" arguments given don't seem to do anything on my
> laptop running 10.3, kernel 7.9.0; I don't know if that means it's
> just not a supported option on my laptop for some reason, which would
> seem kind of strange, or if the "ps" option wasn't added until 10.4.)
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?
Do you know of a way to get battery information on your system?
Lute.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-04 7:39 ` Lute Kamstra
@ 2005-07-04 8:28 ` Arne Jørgensen
2005-07-04 9:44 ` Lute Kamstra
2005-07-04 9:31 ` Ken Raeburn
1 sibling, 1 reply; 23+ messages in thread
From: Arne Jørgensen @ 2005-07-04 8:28 UTC (permalink / raw)
Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:
> Ken Raeburn <raeburn@raeburn.org> writes:
>
> [...]
>
>> (And, BTW, the "-g ps" arguments given don't seem to do anything on my
>> laptop running 10.3, kernel 7.9.0; I don't know if that means it's
>> just not a supported option on my laptop for some reason, which would
>> seem kind of strange, or if the "ps" option wasn't added until 10.4.)
>
> 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?
On my iBook G4 with Mac OS X 10.3 "pmset -g ps" has zero as exit code
and no information as output.
> Do you know of a way to get battery information on your system?
No.
Kind regards,
--
Arne Jørgensen <http://arnested.dk/>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-04 8:28 ` Arne Jørgensen
@ 2005-07-04 9:44 ` Lute Kamstra
[not found] ` <87pstysxke.fsf@seamus.arnested.dk>
0 siblings, 1 reply; 23+ messages in thread
From: Lute Kamstra @ 2005-07-04 9:44 UTC (permalink / raw)
Cc: emacs-devel
Arne Jørgensen <arne@arnested.dk> writes:
> Lute Kamstra <Lute.Kamstra.lists@xs4all.nl> writes:
>
> [...]
>
>> 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?
>
> On my iBook G4 with Mac OS X 10.3 "pmset -g ps" has zero as exit code
> and no information as output.
Apparently that option was added in OS X 10.4. Strange that pmset
doesn't signal an error with its exit code when it gets passed an
unknown option. Maybe I can test for a working version of pmset in
some other way. Could you eval this:
(with-temp-file "~/pmset.txt"
(ignore-errors (call-process "pmset" nil t nil "-g" "ps")))
and send me the "~/pmset.txt" file it creates as an attachment?
Lute.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-04 7:39 ` Lute Kamstra
2005-07-04 8:28 ` Arne Jørgensen
@ 2005-07-04 9:31 ` Ken Raeburn
2005-07-04 9:40 ` Ken Raeburn
2005-07-06 11:42 ` Lute Kamstra
1 sibling, 2 replies; 23+ messages in thread
From: Ken Raeburn @ 2005-07-04 9:31 UTC (permalink / raw)
Cc: emacs-devel
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
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-04 9:31 ` Ken Raeburn
@ 2005-07-04 9:40 ` Ken Raeburn
2005-07-06 11:42 ` Lute Kamstra
1 sibling, 0 replies; 23+ messages in thread
From: Ken Raeburn @ 2005-07-04 9:40 UTC (permalink / raw)
Cc: emacs-devel
On Jul 4, 2005, at 05:31, Ken Raeburn wrote:
> 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".
Actually, that script didn't have a license in it, but perhaps the
author will let us just distribute it under suitable terms, for use on
OS versions where pmset doesn't give the info. That'll push the big
number parsing off onto awk...
Ken
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-04 9:31 ` Ken Raeburn
2005-07-04 9:40 ` Ken Raeburn
@ 2005-07-06 11:42 ` Lute Kamstra
2005-07-06 13:05 ` Sean O'Rourke
1 sibling, 1 reply; 23+ messages in thread
From: Lute Kamstra @ 2005-07-06 11:42 UTC (permalink / raw)
Cc: emacs-devel
Ken Raeburn <raeburn@raeburn.org> writes:
[...]
>> Do you know of a way to get battery information on your system?
[... lots of useful info ...]
Thanks. This looks too complicated to hack on for me (I don't have
access to OS X). Maybe someone else would like to add support for
versions of OS X that don't have "pmset -g ps"?
Lute.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-03 21:28 ` David Kastrup
2005-07-03 22:34 ` Lute Kamstra
@ 2005-07-04 14:51 ` Richard M. Stallman
2005-07-04 15:30 ` David Kastrup
1 sibling, 1 reply; 23+ messages in thread
From: Richard M. Stallman @ 2005-07-04 14:51 UTC (permalink / raw)
Cc: Lute.Kamstra.lists, emacs-devel
But the communication is just with the kernel, via the proc file
system.
If this comment should talk about the kernels, that is ok. Just as
long as it does so in a clear and unambiguous way, that reinforces
the distinction between the kernels and the larger systems.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-04 14:51 ` Richard M. Stallman
@ 2005-07-04 15:30 ` David Kastrup
2005-07-05 16:12 ` Richard M. Stallman
0 siblings, 1 reply; 23+ messages in thread
From: David Kastrup @ 2005-07-04 15:30 UTC (permalink / raw)
Cc: Lute.Kamstra.lists, emacs-devel
"Richard M. Stallman" <rms@gnu.org> writes:
> But the communication is just with the kernel, via the proc file
> system.
>
> If this comment should talk about the kernels, that is ok. Just as
> long as it does so in a clear and unambiguous way, that reinforces
> the distinction between the kernels and the larger systems.
Well, looks like with Linux, the communication is just with the
kernel, but with MacOSX/Darwin, the communication is with a command
line utility.
Sometimes accuracy is an annoying goal.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-04 15:30 ` David Kastrup
@ 2005-07-05 16:12 ` Richard M. Stallman
2005-07-05 20:27 ` Aidan Kehoe
0 siblings, 1 reply; 23+ messages in thread
From: Richard M. Stallman @ 2005-07-05 16:12 UTC (permalink / raw)
Cc: Lute.Kamstra.lists, emacs-devel
Well, looks like with Linux, the communication is just with the
kernel, but with MacOSX/Darwin, the communication is with a command
line utility.
It is surely possible to say these things AND achieve the goal
of not being misinterpreted as talking about an operating system
called "Linux".
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-05 16:12 ` Richard M. Stallman
@ 2005-07-05 20:27 ` Aidan Kehoe
0 siblings, 0 replies; 23+ messages in thread
From: Aidan Kehoe @ 2005-07-05 20:27 UTC (permalink / raw)
Ar an cúigiú lá de mí Iúil, scríobh Richard M. Stallman:
> Well, looks like with Linux, the communication is just with the
> kernel, but with MacOSX/Darwin, the communication is with a command
> line utility.
>
> It is surely possible to say these things AND achieve the goal
> of not being misinterpreted as talking about an operating system
> called "Linux".
Or a kernel called “GNU/Linux.”
--
“I, for instance, am gung-ho about open source because my family is being
held hostage in Rob Malda’s basement. But who fact-checks me, or Enderle,
when we say something in public? No-one!” -- Danny O’Brien
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: Darwin support for lisp/battery.el.
2005-07-03 20:42 ` Richard M. Stallman
2005-07-03 21:28 ` David Kastrup
@ 2005-07-03 22:32 ` Lute Kamstra
1 sibling, 0 replies; 23+ messages in thread
From: Lute Kamstra @ 2005-07-03 22:32 UTC (permalink / raw)
Cc: emacs-devel
"Richard M. Stallman" <rms@gnu.org> writes:
> The changes are ok (presuming they work), but there is a problem in
> the comments:
>
> ! ;; There is at present support for Linux and Darwin.
>
> Darwin is a complete operating system. To include "Linux" in that
> list implies that it too is a complete operating system. That's
> unfair to the GNU Project, so we won't say do that.
>
> The current comment says "Linux" because it refers specifically to the
> kernel and its version numbers. (There are no generally meaningful
> version numbers for the GNU/Linux system as a whole.)
Ok, I've changed the comments.
Lute.
Index: lisp/battery.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/battery.el,v
retrieving revision 1.26
diff -c -r1.26 battery.el
*** lisp/battery.el 1 Jul 2005 11:02:16 -0000 1.26
--- lisp/battery.el 3 Jul 2005 22:28:25 -0000
***************
*** 25,33 ****
;;; Commentary:
! ;; There is at present support for interpreting the new `/proc/apm'
! ;; file format of Linux version 1.3.58 or newer and for the `/proc/acpi/'
! ;; directory structure of Linux 2.4.20 and 2.6.
;;; Code:
--- 25,34 ----
;;; Commentary:
! ;; There is at present support for GNU/Linux and OS X. This library
! ;; supports both the `/proc/apm' file format of Linux version 1.3.58
! ;; or newer and the `/proc/acpi/' directory structure of Linux 2.4.20
! ;; and 2.6. Darwin (OS X) is supported by using the `pmset' program.
;;; Code:
***************
*** 46,52 ****
'battery-linux-proc-apm)
((and (eq system-type 'gnu/linux)
(file-directory-p "/proc/acpi/battery"))
! 'battery-linux-proc-acpi))
"*Function for getting battery status information.
The function has to return an alist of conversion definitions.
Its cons cells are of the form
--- 47,57 ----
'battery-linux-proc-apm)
((and (eq system-type 'gnu/linux)
(file-directory-p "/proc/acpi/battery"))
! 'battery-linux-proc-acpi)
! ((and (eq system-type 'darwin)
! (ignore-errors
! (eq (call-process "pmset" nil nil nil "-g" "ps") 0)))
! 'battery-pmset))
"*Function for getting battery status information.
The function has to return an alist of conversion definitions.
Its cons cells are of the form
***************
*** 62,68 ****
(cond ((eq battery-status-function 'battery-linux-proc-apm)
"Power %L, battery %B (%p%% load, remaining time %t)")
((eq battery-status-function 'battery-linux-proc-acpi)
! "Power %L, battery %B at %r (%p%% load, remaining time %t)"))
"*Control string formatting the string to display in the echo area.
Ordinary characters in the control string are printed as-is, while
conversion specifications introduced by a `%' character in the control
--- 67,75 ----
(cond ((eq battery-status-function 'battery-linux-proc-apm)
"Power %L, battery %B (%p%% load, remaining time %t)")
((eq battery-status-function 'battery-linux-proc-acpi)
! "Power %L, battery %B at %r (%p%% load, remaining time %t)")
! ((eq battery-status-function 'battery-pmset)
! "%L power, battery %B (%p%% load, remaining time %t)"))
"*Control string formatting the string to display in the echo area.
Ordinary characters in the control string are printed as-is, while
conversion specifications introduced by a `%' character in the control
***************
*** 79,85 ****
(cond ((eq battery-status-function 'battery-linux-proc-apm)
"[%b%p%%]")
((eq battery-status-function 'battery-linux-proc-acpi)
! "[%b%p%%,%d°C]"))
"*Control string formatting the string to display in the mode line.
Ordinary characters in the control string are printed as-is, while
conversion specifications introduced by a `%' character in the control
--- 86,94 ----
(cond ((eq battery-status-function 'battery-linux-proc-apm)
"[%b%p%%]")
((eq battery-status-function 'battery-linux-proc-acpi)
! "[%b%p%%,%d°C]")
! ((eq battery-status-function 'battery-pmset)
! "[%b%p%%]"))
"*Control string formatting the string to display in the mode line.
Ordinary characters in the control string are printed as-is, while
conversion specifications introduced by a `%' character in the control
***************
*** 93,98 ****
--- 102,119 ----
:type 'integer
:group 'battery)
+ (defcustom battery-load-low 25
+ "*Upper bound of low battery load percentage.
+ A battery load percentage below this number is considered low."
+ :type 'integer
+ :group 'battery)
+
+ (defcustom battery-load-critical 10
+ "*Upper bound of critical battery load percentage.
+ A battery load percentage below this number is considered critical."
+ :type 'integer
+ :group 'battery)
+
(defvar battery-update-timer nil
"Interval timer object.")
***************
*** 343,348 ****
--- 364,421 ----
"N/A")))))
\f
+ ;;; `pmset' interface for Darwin (OS X).
+
+ (defun battery-pmset ()
+ "Get battery status information using `pmset'.
+
+ The following %-sequences are provided:
+ %L Power source (verbose)
+ %B Battery status (verbose)
+ %b Battery status, empty means high, `-' means low,
+ `!' means critical, and `+' means charging
+ %p Battery load percentage
+ %h Remaining time in hours
+ %m Remaining time in minutes
+ %t Remaining time in the form `h:min'"
+ (let (power-source load-percentage battery-status battery-status-symbol
+ remaining-time hours minutes)
+ (with-temp-buffer
+ (ignore-errors (call-process "pmset" nil t nil "-g" "ps"))
+ (goto-char (point-min))
+ (when (re-search-forward "Currentl?y drawing from '\\(AC\\|Battery\\) Power'" nil t)
+ (setq power-source (match-string 1))
+ (when (re-search-forward "^ -InternalBattery-0[ \t]+" nil t)
+ (when (looking-at "\\([0-9]\\{1,3\\}\\)%")
+ (setq load-percentage (match-string 1))
+ (goto-char (match-end 0))
+ (cond ((looking-at "; charging")
+ (setq battery-status "charging"
+ battery-status-symbol "+"))
+ ((< (string-to-number load-percentage) battery-load-low)
+ (setq battery-status "low"
+ battery-status-symbol "-"))
+ ((< (string-to-number load-percentage) battery-load-critical)
+ (setq battery-status "critical"
+ battery-status-symbol "!"))
+ (t
+ (setq battery-status "high"
+ battery-status-symbol "")))
+ (when (re-search-forward "\\(\\([0-9]+\\):\\([0-9]+\\)\\) remaining" nil t)
+ (setq remaining-time (match-string 1))
+ (let ((h (string-to-number (match-string 2)))
+ (m (string-to-number (match-string 3))))
+ (setq hours (number-to-string (+ h (if (< m 30) 0 1)))
+ minutes (number-to-string (+ (* h 60) m)))))))))
+ (list (cons ?L (or power-source "N/A"))
+ (cons ?p (or load-percentage "N/A"))
+ (cons ?B (or battery-status "N/A"))
+ (cons ?b (or battery-status-symbol ""))
+ (cons ?h (or hours "N/A"))
+ (cons ?m (or minutes "N/A"))
+ (cons ?t (or remaining-time "N/A")))))
+
+ \f
;;; Private functions.
(defun battery-format (format alist)
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2005-07-09 10:13 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).