From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: jmarant@nerim.net (=?iso-8859-15?q?J=E9r=F4me_Marant?=) Newsgroups: gmane.emacs.devel Subject: Re: [Mario Lang] battery.el ACPI update Date: Thu, 27 May 2004 22:26:11 +0200 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <8765ahy5uk.fsf@marant.org> References: <87u0yaavt7.fsf@marant.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1085701868 14561 80.91.224.253 (27 May 2004 23:51:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 27 May 2004 23:51:08 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Fri May 28 01:51:00 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BTUeK-0001NY-00 for ; Fri, 28 May 2004 01:51:00 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1BTUeJ-0006oH-00 for ; Fri, 28 May 2004 01:51:00 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BTSpU-00084t-Ci for emacs-devel@quimby.gnus.org; Thu, 27 May 2004 17:54:24 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.34) id 1BTSoj-000820-FP for emacs-devel@gnu.org; Thu, 27 May 2004 17:53:37 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.34) id 1BTSSq-0006HG-Rr for emacs-devel@gnu.org; Thu, 27 May 2004 17:31:33 -0400 Original-Received: from [62.4.17.104] (helo=mallaury.noc.nerim.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BTRPq-0003tF-00 for emacs-devel@gnu.org; Thu, 27 May 2004 16:23:50 -0400 Original-Received: from amboise (jmarant.net1.nerim.net [62.212.105.6]) by mallaury.noc.nerim.net (Postfix) with ESMTP id 9550262D5A for ; Thu, 27 May 2004 22:23:45 +0200 (CEST) Original-Received: by amboise (Postfix, from userid 1000) id 3A9BD2C318; Thu, 27 May 2004 22:26:12 +0200 (CEST) Original-To: emacs-devel@gnu.org In-Reply-To: <87u0yaavt7.fsf@marant.org> =?iso-8859-15?q?=28J=E9r=F4me?= Marant's message of "Fri, 21 May 2004 13:01:08 +0200") User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:24040 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:24040 Could someone please take care of this? jmarant@nerim.net (J=E9r=F4me Marant) writes: > Hi, > > Mario Lang asked me to forward this message. > > Cheers, > > --=3D=3D-=3D-=3D > Content-Type: message/rfc822 > Content-Disposition: inline > Content-Transfer-Encoding: 8bit > > To: emacs-devel@gnu.org > Subject: battery.el ACPI update > From: Mario Lang > X-Draft-From: ("nnml:mail.emacs-devel" "") > Date: Wed, 19 May 2004 17:44:16 +0200 > Message-ID: <87n0447773.fsf@lexx.delysid.org> > User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) > Xref: lexx.delysid.org archive:2333 > MIME-Version: 1.0 > Content-Type: multipart/signed; boundary=3D"=3D-=3D-=3D" > Lines: 178 > > --=3D-=3D-=3D > > Hi. > > The following patch makes `battery-linux-proc-acpi' works with more > different systems and fixes an anoying division-by-zero bug > in the remaining-time calculation. Please install. > > 2004-05-19 Mario Lang > > * battery.el (battery-linux-proc-acpi): mA was hardcored, but some > systems appear to use mW, make the code handle this. Fix a > division-by-zero bug while at it, and handle kernels with > a slightly different layout in /proc/acpi. > > Index: lisp/battery.el > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > RCS file: /cvsroot/emacs/emacs/lisp/battery.el,v > retrieving revision 1.18 > diff -u -r1.18 battery.el > --- lisp/battery.el 10 Sep 2003 19:51:01 -0000 1.18 > +++ lisp/battery.el 19 May 2004 15:36:34 -0000 > @@ -61,7 +61,7 @@ > (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 mA (%p%% load, remaining time %t)")) > + "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 > @@ -243,50 +243,59 @@ > %m Remaining time in minutes > %h Remaining time in hours > %t Remaining time in the form `h:min'" > - (let (capacity design-capacity rate charging-state warn low minutes ho= urs) > - (when (file-directory-p "/proc/acpi/battery/") > - ;; ACPI provides information about each battery present in the sys= tem in > - ;; a separate subdirectory. We are going to merge the available > - ;; information together since displaying for a variable amount of > - ;; batteries seems overkill for format-strings. > - (mapc > - (lambda (dir) > - (with-temp-buffer > - (insert-file-contents (expand-file-name "state" dir)) > - (when (re-search-forward "present: +yes$" nil t) > - (and (re-search-forward "charging state: +\\(.*\\)$" nil t) > - (or (null charging-state) (string=3D charging-state > - "unknown")) > - ;; On most multi-battery systems, most of the time only one > - ;; battery is "charging"/"discharging", the others are > - ;; "unknown". > - (setq charging-state (match-string 1))) > - (when (re-search-forward "present rate: +\\([0-9]+\\) mA$" nil t) > - (setq rate (+ (or rate 0) (string-to-int (match-string 1))))) > - (when (re-search-forward "remaining capacity: +\\([0-9]+\\) mAh$" > - nil t) > - (setq capacity > - (+ (or capacity 0) (string-to-int (match-string 1)))))) > - (goto-char (point-max)) > - (insert-file-contents (expand-file-name "info" dir)) > - (when (re-search-forward "present: +yes$" nil t) > - (when (re-search-forward "design capacity: +\\([0-9]+\\) mAh$" > - nil t) > - (setq design-capacity (+ (or design-capacity 0) > - (string-to-int (match-string 1))))) > - (when (re-search-forward "design capacity warning: +\\([0-9]+\\) m= Ah$" > - nil t) > - (setq warn (+ (or warn 0) (string-to-int (match-string 1))))) > - (when (re-search-forward "design capacity low: +\\([0-9]+\\) mAh$" > - nil t) > - (setq low (+ (or low 0) > - (string-to-int (match-string 1)))))))) > - (directory-files "/proc/acpi/battery/" t "BAT"))) > + (let (capacity design-capacity rate rate-type charging-state warn low > + minutes hours) > + ;; ACPI provides information about each battery present in the syste= m in > + ;; a separate subdirectory. We are going to merge the available > + ;; information together since displaying for a variable amount of > + ;; batteries seems overkill for format-strings. > + (mapc > + (lambda (dir) > + (with-temp-buffer > + (insert-file-contents (expand-file-name "state" dir)) > + (when (re-search-forward "present: +yes$" nil t) > + (and (re-search-forward "charging state: +\\(.*\\)$" nil t) > + (or (null charging-state) (string=3D charging-state > + "unknown")) > + ;; On most multi-battery systems, most of the time only one > + ;; battery is "charging"/"discharging", the others are > + ;; "unknown". > + (setq charging-state (match-string 1))) > + (when (re-search-forward "present rate: +\\([0-9]+\\) \\(m[AW]\\)$" > + nil t) > + (setq rate (+ (or rate 0) (string-to-int (match-string 1))) > + rate-type (or (and rate-type > + (if (string=3D rate-type (match-string 2)) > + rate-type > + (error > + "Inconsistent rate types (%s vs. %s)" > + rate-type (match-string 2)))) > + (match-string 2)))) > + (when (re-search-forward "remaining capacity: +\\([0-9]+\\) m[AW]h$" > + nil t) > + (setq capacity > + (+ (or capacity 0) (string-to-int (match-string 1)))))) > + (goto-char (point-max)) > + (insert-file-contents (expand-file-name "info" dir)) > + (when (re-search-forward "present: +yes$" nil t) > + (when (re-search-forward "design capacity: +\\([0-9]+\\) m[AW]h$" > + nil t) > + (setq design-capacity (+ (or design-capacity 0) > + (string-to-int (match-string 1))))) > + (when (re-search-forward "design capacity warning: +\\([0-9]+\\) m[A= W]h$" > + nil t) > + (setq warn (+ (or warn 0) (string-to-int (match-string 1))))) > + (when (re-search-forward "design capacity low: +\\([0-9]+\\) m[AW]h$" > + nil t) > + (setq low (+ (or low 0) > + (string-to-int (match-string 1)))))))) > + (directory-files "/proc/acpi/battery/" t "BAT")) > (and capacity rate > - (setq minutes (floor (* (/ (float (if (string=3D charging-state > - "charging") > - (- design-capacity capacity) > - capacity)) rate) 60)) > + (setq minutes (if (zerop rate) 0 > + (floor (* (/ (float (if (string=3D charging-state > + "charging") > + (- design-capacity capacity) > + capacity)) rate) 60))) > hours (/ minutes 60))) > (list (cons ?c (or (and capacity (number-to-string capacity)) "N/A")) > (cons ?L (or (when (file-exists-p "/proc/acpi/ac_adapter/AC/state") > @@ -304,13 +313,22 @@ > (when (re-search-forward > "temperature: +\\([0-9]+\\) C$" nil t) > (match-string 1)))) > + (when (file-exists-p > + "/proc/acpi/thermal_zone/THM/temperature") > + (with-temp-buffer > + (insert-file-contents > + "/proc/acpi/thermal_zone/THM/temperature") > + (when (re-search-forward > + "temperature: +\\([0-9]+\\) C$" nil t) > + (match-string 1)))) > "N/A")) > - (cons ?r (or (and rate (number-to-string rate)) "N/A")) > + (cons ?r (or (and rate (concat (number-to-string rate) " " > + rate-type)) "N/A")) > (cons ?B (or charging-state "N/A")) > (cons ?b (or (and (string=3D charging-state "charging") "+") > (and low (< capacity low) "!") > - (and warn (< capacity warn) "-") > - "")) > + (and warn (< capacity warn) "-") > + "")) > (cons ?h (or (and hours (number-to-string hours)) "N/A")) > (cons ?m (or (and minutes (number-to-string minutes)) "N/A")) > (cons ?t (or (and minutes > > --=20 > CYa, > Mario | Debian Developer > | Get my public key via finger mlang@db.debian.org > | 1024D/7FC1A0854909BCCDBE6C102DDFFC022A6B113E44 > > --=3D=3D-=3D-=3D > > --=20 > J=E9r=F4me Marant > > > _______________________________________________ > Emacs-devel mailing list > Emacs-devel@gnu.org > http://mail.gnu.org/mailman/listinfo/emacs-devel > --=20 J=E9r=F4me Marant