emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r107876: Make generic sysfs support a


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r107876: Make generic sysfs support apply for yeeloong as well.
Date: Wed, 11 Apr 2012 22:04:29 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 107876
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Wed 2012-04-11 22:04:29 -0400
message:
  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.
modified:
  lisp/ChangeLog
  lisp/battery.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-04-11 21:37:13 +0000
+++ b/lisp/ChangeLog    2012-04-12 02:04:29 +0000
@@ -1,3 +1,10 @@
+2012-04-12  Stefan Monnier  <address@hidden>
+
+       * 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.
+
 2012-04-11  Stefan Monnier  <address@hidden>
 
        * imenu.el (imenu-add-to-menubar): `current-local-map' can be nil.

=== modified file 'lisp/battery.el'
--- a/lisp/battery.el   2012-04-10 23:24:31 +0000
+++ b/lisp/battery.el   2012-04-12 02:04:29 +0000
@@ -39,6 +39,9 @@
   :prefix "battery-"
   :group 'hardware)
 
+;; Either BATn or yeeloong-bat, basically.
+(defconst battery--linux-sysfs-regexp "[bB][aA][tT][0-9]?$")
+
 (defcustom battery-status-function
   (cond ((and (eq system-type 'gnu/linux)
              (file-readable-p "/proc/apm"))
@@ -48,12 +51,9 @@
         'battery-linux-proc-acpi)
        ((and (eq system-type 'gnu/linux)
              (file-directory-p "/sys/class/power_supply/")
-             (directory-files "/sys/class/power_supply/" nil "BAT[0-9]$"))
+             (directory-files "/sys/class/power_supply/" nil
+                               battery--linux-sysfs-regexp))
         'battery-linux-sysfs)
-       ((and (eq system-type 'gnu/linux)
-             (file-directory-p "/sys/class/power_supply/yeeloong-bat/")
-             (directory-files "/sys/class/power_supply/yeeloong-bat/" nil 
"charge_"))
-        'battery-yeeloong-sysfs)
        ((and (eq system-type 'darwin)
              (condition-case nil
                  (with-temp-buffer
@@ -81,8 +81,6 @@
         "Power %L, battery %B (%p%% load)")
        ((eq battery-status-function 'battery-pmset)
         "%L power, battery %B (%p%% load, remaining time %t)")
-       ((eq battery-status-function 'battery-yeeloong-sysfs)
-        "%L power, battery %B (%p%% load, remaining time %t)")
        (battery-status-function
         "Power %L, battery %B (%p%% load, remaining time %t)"))
   "Control string formatting the string to display in the echo area.
@@ -448,7 +446,8 @@
     (with-temp-buffer
       (dolist (dir (ignore-errors
                    (directory-files
-                    "/sys/class/power_supply/" t "BAT[0-9]$")))
+                    "/sys/class/power_supply/" t
+                     battery--linux-sysfs-regexp)))
        (erase-buffer)
        (ignore-errors (insert-file-contents
                        (expand-file-name "uevent" dir)))
@@ -525,91 +524,6 @@
                           "AC"
                         "BAT")
                     "N/A")))))
-
-(defun battery-yeeloong-sysfs ()
-  "Get ACPI status information from Linux (the kernel).
-This function works only on the Lemote Yeeloong.
-
-The following %-sequences are provided:
-%c Current capacity (mAh)
-%r Current rate
-%B Battery status (verbose)
-%b Battery status, empty means high, `-' means low,
-   `!' means critical, and `+' means charging
-%L AC line status (verbose)
-%p Battery load percentage
-%m Remaining time (to charge or discharge) in minutes
-%h Remaining time (to charge or discharge) in hours
-%t Remaining time (to charge or discharge) in the form `h:min'"
-
-  (let (capacity
-       capacity-level
-       status
-       ac-online
-       hours
-       current-now
-       charge-full
-       charge-now)
-
-    (with-temp-buffer
-      (ignore-errors
-       (insert-file-contents "/sys/class/power_supply/yeeloong-bat/uevent")
-       (goto-char 1)
-       (search-forward "POWER_SUPPLY_CHARGE_NOW=")
-       (setq charge-now (read (current-buffer)))
-       (goto-char 1)
-       (search-forward "POWER_SUPPLY_CHARGE_FULL=")
-       (setq charge-full (read (current-buffer)))
-       (goto-char 1)
-       (search-forward "POWER_SUPPLY_CURRENT_NOW=")
-       (setq current-now (read (current-buffer)))
-       (goto-char 1)
-       (search-forward "POWER_SUPPLY_CAPACITY_LEVEL=")
-       (setq capacity-level (buffer-substring (point) (line-end-position)))
-       (goto-char 1)
-       (search-forward "POWER_SUPPLY_STATUS=")
-       (setq status (buffer-substring (point) (line-end-position))))
-       
-      (erase-buffer)
-      (ignore-errors
-       (insert-file-contents
-        "/sys/class/power_supply/yeeloong-ac/online")
-       (goto-char 1)
-       (setq ac-online (read (current-buffer)))
-       (erase-buffer)))
-
-
-    (setq capacity (round (/ (* charge-now 100.0) charge-full)))
-    (when (and current-now (not (= current-now 0)))
-      (if (< current-now 0)
-         ;; Charging
-         (setq hours (/ (- charge-now charge-full) (+ 0.0 current-now)))
-       ;; Discharging
-       (setq hours (/ charge-now (+ 0.0 current-now)))))
-
-    (list (cons ?c (if charge-now
-                      (number-to-string charge-now)
-                    "N/A"))
-         (cons ?r current-now)
-         (cons ?B (cond ((equal capacity-level "Full") "full")
-                        ((equal status "Charging") "charging")
-                        ((equal capacity-level "Low") "low")
-                        ((equal capacity-level "Critical") "critical")
-                        (t "high")))
-         (cons ?b (cond ((equal capacity-level "Full") " ")
-                        ((equal status "Charging") "+")
-                        ((equal capacity-level "Low") "-")
-                        ((equal capacity-level "Critical") "!")
-                        (t " ")))
-         (cons ?h (if hours (number-to-string hours) "N/A"))
-         (cons ?m (if hours (number-to-string (* 60 hours)) "N/A"))
-         (cons ?t (if hours
-                      (format "%d:%d"
-                              (/ (round (* 60 hours)) 60)
-                              (% (round (* 60 hours)) 60))
-                    "N/A"))
-         (cons ?p (if capacity (number-to-string capacity) "N/A"))
-         (cons ?L (if (eq ac-online 1) "AC" "BAT")))))
 
 ;;; `pmset' interface for Darwin (OS X).
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]