aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2012-04-11 22:04:29 -0400
committerStefan Monnier2012-04-11 22:04:29 -0400
commit6decb6c2291942f6e9cce17fb9ae7f4e2c603227 (patch)
tree61a7a2ca6c22d1ed2b2f2191e879e2da8a33ced8
parent6622e4169bdd3a7b73af6d2f8d006740954cca96 (diff)
downloademacs-6decb6c2291942f6e9cce17fb9ae7f4e2c603227.tar.gz
emacs-6decb6c2291942f6e9cce17fb9ae7f4e2c603227.zip
Make generic sysfs support apply for yeeloong as well.
* lisp/battery.el (battery--linux-sysfs-regexp): New const. (battery-status-function): Use it. Remove yeeloong special case. (battery-yeeloong-sysfs): Remove. (battery-echo-area-format): Remove yeeloong special case.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/battery.el100
2 files changed, 14 insertions, 93 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 265a456242a..d4217ba1112 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12012-04-12 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * battery.el (battery--linux-sysfs-regexp): New const.
4 (battery-status-function): Use it. Remove yeeloong special case.
5 (battery-yeeloong-sysfs): Remove.
6 (battery-echo-area-format): Remove yeeloong special case.
7
12012-04-11 Stefan Monnier <monnier@iro.umontreal.ca> 82012-04-11 Stefan Monnier <monnier@iro.umontreal.ca>
2 9
3 * imenu.el (imenu-add-to-menubar): `current-local-map' can be nil. 10 * imenu.el (imenu-add-to-menubar): `current-local-map' can be nil.
diff --git a/lisp/battery.el b/lisp/battery.el
index 5cb10252539..78898534a47 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -39,6 +39,9 @@
39 :prefix "battery-" 39 :prefix "battery-"
40 :group 'hardware) 40 :group 'hardware)
41 41
42;; Either BATn or yeeloong-bat, basically.
43(defconst battery--linux-sysfs-regexp "[bB][aA][tT][0-9]?$")
44
42(defcustom battery-status-function 45(defcustom battery-status-function
43 (cond ((and (eq system-type 'gnu/linux) 46 (cond ((and (eq system-type 'gnu/linux)
44 (file-readable-p "/proc/apm")) 47 (file-readable-p "/proc/apm"))
@@ -48,12 +51,9 @@
48 'battery-linux-proc-acpi) 51 'battery-linux-proc-acpi)
49 ((and (eq system-type 'gnu/linux) 52 ((and (eq system-type 'gnu/linux)
50 (file-directory-p "/sys/class/power_supply/") 53 (file-directory-p "/sys/class/power_supply/")
51 (directory-files "/sys/class/power_supply/" nil "BAT[0-9]$")) 54 (directory-files "/sys/class/power_supply/" nil
55 battery--linux-sysfs-regexp))
52 'battery-linux-sysfs) 56 'battery-linux-sysfs)
53 ((and (eq system-type 'gnu/linux)
54 (file-directory-p "/sys/class/power_supply/yeeloong-bat/")
55 (directory-files "/sys/class/power_supply/yeeloong-bat/" nil "charge_"))
56 'battery-yeeloong-sysfs)
57 ((and (eq system-type 'darwin) 57 ((and (eq system-type 'darwin)
58 (condition-case nil 58 (condition-case nil
59 (with-temp-buffer 59 (with-temp-buffer
@@ -81,8 +81,6 @@ introduced by a `%' character in a control string."
81 "Power %L, battery %B (%p%% load)") 81 "Power %L, battery %B (%p%% load)")
82 ((eq battery-status-function 'battery-pmset) 82 ((eq battery-status-function 'battery-pmset)
83 "%L power, battery %B (%p%% load, remaining time %t)") 83 "%L power, battery %B (%p%% load, remaining time %t)")
84 ((eq battery-status-function 'battery-yeeloong-sysfs)
85 "%L power, battery %B (%p%% load, remaining time %t)")
86 (battery-status-function 84 (battery-status-function
87 "Power %L, battery %B (%p%% load, remaining time %t)")) 85 "Power %L, battery %B (%p%% load, remaining time %t)"))
88 "Control string formatting the string to display in the echo area. 86 "Control string formatting the string to display in the echo area.
@@ -448,7 +446,8 @@ The following %-sequences are provided:
448 (with-temp-buffer 446 (with-temp-buffer
449 (dolist (dir (ignore-errors 447 (dolist (dir (ignore-errors
450 (directory-files 448 (directory-files
451 "/sys/class/power_supply/" t "BAT[0-9]$"))) 449 "/sys/class/power_supply/" t
450 battery--linux-sysfs-regexp)))
452 (erase-buffer) 451 (erase-buffer)
453 (ignore-errors (insert-file-contents 452 (ignore-errors (insert-file-contents
454 (expand-file-name "uevent" dir))) 453 (expand-file-name "uevent" dir)))
@@ -525,91 +524,6 @@ The following %-sequences are provided:
525 "AC" 524 "AC"
526 "BAT") 525 "BAT")
527 "N/A"))))) 526 "N/A")))))
528
529(defun battery-yeeloong-sysfs ()
530 "Get ACPI status information from Linux (the kernel).
531This function works only on the Lemote Yeeloong.
532
533The following %-sequences are provided:
534%c Current capacity (mAh)
535%r Current rate
536%B Battery status (verbose)
537%b Battery status, empty means high, `-' means low,
538 `!' means critical, and `+' means charging
539%L AC line status (verbose)
540%p Battery load percentage
541%m Remaining time (to charge or discharge) in minutes
542%h Remaining time (to charge or discharge) in hours
543%t Remaining time (to charge or discharge) in the form `h:min'"
544
545 (let (capacity
546 capacity-level
547 status
548 ac-online
549 hours
550 current-now
551 charge-full
552 charge-now)
553
554 (with-temp-buffer
555 (ignore-errors
556 (insert-file-contents "/sys/class/power_supply/yeeloong-bat/uevent")
557 (goto-char 1)
558 (search-forward "POWER_SUPPLY_CHARGE_NOW=")
559 (setq charge-now (read (current-buffer)))
560 (goto-char 1)
561 (search-forward "POWER_SUPPLY_CHARGE_FULL=")
562 (setq charge-full (read (current-buffer)))
563 (goto-char 1)
564 (search-forward "POWER_SUPPLY_CURRENT_NOW=")
565 (setq current-now (read (current-buffer)))
566 (goto-char 1)
567 (search-forward "POWER_SUPPLY_CAPACITY_LEVEL=")
568 (setq capacity-level (buffer-substring (point) (line-end-position)))
569 (goto-char 1)
570 (search-forward "POWER_SUPPLY_STATUS=")
571 (setq status (buffer-substring (point) (line-end-position))))
572
573 (erase-buffer)
574 (ignore-errors
575 (insert-file-contents
576 "/sys/class/power_supply/yeeloong-ac/online")
577 (goto-char 1)
578 (setq ac-online (read (current-buffer)))
579 (erase-buffer)))
580
581
582 (setq capacity (round (/ (* charge-now 100.0) charge-full)))
583 (when (and current-now (not (= current-now 0)))
584 (if (< current-now 0)
585 ;; Charging
586 (setq hours (/ (- charge-now charge-full) (+ 0.0 current-now)))
587 ;; Discharging
588 (setq hours (/ charge-now (+ 0.0 current-now)))))
589
590 (list (cons ?c (if charge-now
591 (number-to-string charge-now)
592 "N/A"))
593 (cons ?r current-now)
594 (cons ?B (cond ((equal capacity-level "Full") "full")
595 ((equal status "Charging") "charging")
596 ((equal capacity-level "Low") "low")
597 ((equal capacity-level "Critical") "critical")
598 (t "high")))
599 (cons ?b (cond ((equal capacity-level "Full") " ")
600 ((equal status "Charging") "+")
601 ((equal capacity-level "Low") "-")
602 ((equal capacity-level "Critical") "!")
603 (t " ")))
604 (cons ?h (if hours (number-to-string hours) "N/A"))
605 (cons ?m (if hours (number-to-string (* 60 hours)) "N/A"))
606 (cons ?t (if hours
607 (format "%d:%d"
608 (/ (round (* 60 hours)) 60)
609 (% (round (* 60 hours)) 60))
610 "N/A"))
611 (cons ?p (if capacity (number-to-string capacity) "N/A"))
612 (cons ?L (if (eq ac-online 1) "AC" "BAT")))))
613 527
614;;; `pmset' interface for Darwin (OS X). 528;;; `pmset' interface for Darwin (OS X).
615 529