Mercurial > emacs
comparison lisp/battery.el @ 55904:f3be7c4dc1e6
(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.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Fri, 04 Jun 2004 16:05:56 +0000 |
parents | b4d15685afef |
children | f5b70c70c08c 4c90ffeb71c5 |
comparison
equal
deleted
inserted
replaced
55903:822bab94f6a3 | 55904:f3be7c4dc1e6 |
---|---|
59 | 59 |
60 (defcustom battery-echo-area-format | 60 (defcustom battery-echo-area-format |
61 (cond ((eq battery-status-function 'battery-linux-proc-apm) | 61 (cond ((eq battery-status-function 'battery-linux-proc-apm) |
62 "Power %L, battery %B (%p%% load, remaining time %t)") | 62 "Power %L, battery %B (%p%% load, remaining time %t)") |
63 ((eq battery-status-function 'battery-linux-proc-acpi) | 63 ((eq battery-status-function 'battery-linux-proc-acpi) |
64 "Power %L, battery %B at %r mA (%p%% load, remaining time %t)")) | 64 "Power %L, battery %B at %r (%p%% load, remaining time %t)")) |
65 "*Control string formatting the string to display in the echo area. | 65 "*Control string formatting the string to display in the echo area. |
66 Ordinary characters in the control string are printed as-is, while | 66 Ordinary characters in the control string are printed as-is, while |
67 conversion specifications introduced by a `%' character in the control | 67 conversion specifications introduced by a `%' character in the control |
68 string are substituted as defined by the current value of the variable | 68 string are substituted as defined by the current value of the variable |
69 `battery-status-function'." | 69 `battery-status-function'." |
241 %L AC line status (verbose) | 241 %L AC line status (verbose) |
242 %p battery load percentage | 242 %p battery load percentage |
243 %m Remaining time in minutes | 243 %m Remaining time in minutes |
244 %h Remaining time in hours | 244 %h Remaining time in hours |
245 %t Remaining time in the form `h:min'" | 245 %t Remaining time in the form `h:min'" |
246 (let (capacity design-capacity rate charging-state warn low minutes hours) | 246 (let (capacity design-capacity rate rate-type charging-state warn low |
247 minutes hours) | |
247 (when (file-directory-p "/proc/acpi/battery/") | 248 (when (file-directory-p "/proc/acpi/battery/") |
248 ;; ACPI provides information about each battery present in the system in | 249 ;; ACPI provides information about each battery present in the system in |
249 ;; a separate subdirectory. We are going to merge the available | 250 ;; a separate subdirectory. We are going to merge the available |
250 ;; information together since displaying for a variable amount of | 251 ;; information together since displaying for a variable amount of |
251 ;; batteries seems overkill for format-strings. | 252 ;; batteries seems overkill for format-strings. |
259 "unknown")) | 260 "unknown")) |
260 ;; On most multi-battery systems, most of the time only one | 261 ;; On most multi-battery systems, most of the time only one |
261 ;; battery is "charging"/"discharging", the others are | 262 ;; battery is "charging"/"discharging", the others are |
262 ;; "unknown". | 263 ;; "unknown". |
263 (setq charging-state (match-string 1))) | 264 (setq charging-state (match-string 1))) |
264 (when (re-search-forward "present rate: +\\([0-9]+\\) mA$" nil t) | 265 (when (re-search-forward "present rate: +\\([0-9]+\\) \\(m[AW]\\)$" |
265 (setq rate (+ (or rate 0) (string-to-int (match-string 1))))) | 266 nil t) |
266 (when (re-search-forward "remaining capacity: +\\([0-9]+\\) mAh$" | 267 (setq rate (+ (or rate 0) (string-to-int (match-string 1))) |
268 rate-type (or (and rate-type | |
269 (if (string= rate-type (match-string 2)) | |
270 rate-type | |
271 (error | |
272 "Inconsistent rate types (%s vs. %s)" | |
273 rate-type (match-string 2)))) | |
274 (match-string 2)))) | |
275 (when (re-search-forward "remaining capacity: +\\([0-9]+\\) m[AW]h$" | |
267 nil t) | 276 nil t) |
268 (setq capacity | 277 (setq capacity |
269 (+ (or capacity 0) (string-to-int (match-string 1)))))) | 278 (+ (or capacity 0) (string-to-int (match-string 1)))))) |
270 (goto-char (point-max)) | 279 (goto-char (point-max)) |
271 (insert-file-contents (expand-file-name "info" dir)) | 280 (insert-file-contents (expand-file-name "info" dir)) |
272 (when (re-search-forward "present: +yes$" nil t) | 281 (when (re-search-forward "present: +yes$" nil t) |
273 (when (re-search-forward "design capacity: +\\([0-9]+\\) mAh$" | 282 (when (re-search-forward "design capacity: +\\([0-9]+\\) m[AW]h$" |
274 nil t) | 283 nil t) |
275 (setq design-capacity (+ (or design-capacity 0) | 284 (setq design-capacity (+ (or design-capacity 0) |
276 (string-to-int (match-string 1))))) | 285 (string-to-int (match-string 1))))) |
277 (when (re-search-forward "design capacity warning: +\\([0-9]+\\) mAh$" | 286 (when (re-search-forward "design capacity warning: +\\([0-9]+\\) m[AW]h$" |
278 nil t) | 287 nil t) |
279 (setq warn (+ (or warn 0) (string-to-int (match-string 1))))) | 288 (setq warn (+ (or warn 0) (string-to-int (match-string 1))))) |
280 (when (re-search-forward "design capacity low: +\\([0-9]+\\) mAh$" | 289 (when (re-search-forward "design capacity low: +\\([0-9]+\\) m[AW]h$" |
281 nil t) | 290 nil t) |
282 (setq low (+ (or low 0) | 291 (setq low (+ (or low 0) |
283 (string-to-int (match-string 1)))))))) | 292 (string-to-int (match-string 1)))))))) |
284 (directory-files "/proc/acpi/battery/" t "BAT"))) | 293 (directory-files "/proc/acpi/battery/" t "BAT"))) |
285 (and capacity rate | 294 (and capacity rate |
286 (setq minutes (floor (* (/ (float (if (string= charging-state | 295 (setq minutes (if (zerop rate) 0 |
287 "charging") | 296 (floor (* (/ (float (if (string= charging-state |
288 (- design-capacity capacity) | 297 "charging") |
289 capacity)) rate) 60)) | 298 (- design-capacity capacity) |
299 capacity)) rate) 60))) | |
290 hours (/ minutes 60))) | 300 hours (/ minutes 60))) |
291 (list (cons ?c (or (and capacity (number-to-string capacity)) "N/A")) | 301 (list (cons ?c (or (and capacity (number-to-string capacity)) "N/A")) |
292 (cons ?L (or (when (file-exists-p "/proc/acpi/ac_adapter/AC/state") | 302 (cons ?L (or (when (file-exists-p "/proc/acpi/ac_adapter/AC/state") |
293 (with-temp-buffer | 303 (with-temp-buffer |
294 (insert-file-contents | 304 (insert-file-contents |
302 (insert-file-contents | 312 (insert-file-contents |
303 "/proc/acpi/thermal_zone/THRM/temperature") | 313 "/proc/acpi/thermal_zone/THRM/temperature") |
304 (when (re-search-forward | 314 (when (re-search-forward |
305 "temperature: +\\([0-9]+\\) C$" nil t) | 315 "temperature: +\\([0-9]+\\) C$" nil t) |
306 (match-string 1)))) | 316 (match-string 1)))) |
317 (when (file-exists-p | |
318 "/proc/acpi/thermal_zone/THM/temperature") | |
319 (with-temp-buffer | |
320 (insert-file-contents | |
321 "/proc/acpi/thermal_zone/THM/temperature") | |
322 (when (re-search-forward | |
323 "temperature: +\\([0-9]+\\) C$" nil t) | |
324 (match-string 1)))) | |
307 "N/A")) | 325 "N/A")) |
308 (cons ?r (or (and rate (number-to-string rate)) "N/A")) | 326 (cons ?r (or (and rate (concat (number-to-string rate) " " |
327 rate-type)) "N/A")) | |
309 (cons ?B (or charging-state "N/A")) | 328 (cons ?B (or charging-state "N/A")) |
310 (cons ?b (or (and (string= charging-state "charging") "+") | 329 (cons ?b (or (and (string= charging-state "charging") "+") |
311 (and low (< capacity low) "!") | 330 (and low (< capacity low) "!") |
312 (and warn (< capacity warn) "-") | 331 (and warn (< capacity warn) "-") |
313 "")) | 332 "")) |