diff options
| author | Eli Zaretskii | 2004-06-04 16:05:56 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2004-06-04 16:05:56 +0000 |
| commit | 062db3ecf4071c42579a7b6e0619a6f3dac1f40c (patch) | |
| tree | 454451cd0c9a66fead95121223f9c3db6109a7e9 | |
| parent | ccda4e3cef99aab9f620b587462cad5a1a54d236 (diff) | |
| download | emacs-062db3ecf4071c42579a7b6e0619a6f3dac1f40c.tar.gz emacs-062db3ecf4071c42579a7b6e0619a6f3dac1f40c.zip | |
(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.
| -rw-r--r-- | lisp/battery.el | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/lisp/battery.el b/lisp/battery.el index c82d3ac02b3..73d78067571 100644 --- a/lisp/battery.el +++ b/lisp/battery.el | |||
| @@ -61,7 +61,7 @@ introduced by a `%' character in a control string." | |||
| 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 |
| @@ -243,7 +243,8 @@ The following %-sequences are provided: | |||
| 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 |
| @@ -261,32 +262,41 @@ The following %-sequences are provided: | |||
| 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") |
| @@ -304,8 +314,17 @@ The following %-sequences are provided: | |||
| 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) "!") |