From: Stefan Monnier Date: Sat, 7 Mar 2015 04:42:10 +0000 (-0500) Subject: * lisp/battery.el: Make it work on my MSI Wind X-Git-Tag: emacs-25.0.90~2564^2~209 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0ea68311a5597f0a74c902519ae7a5f1920ed2e9;p=emacs.git * lisp/battery.el: Make it work on my MSI Wind * lisp/battery.el (battery-echo-area-format): Simplify default. (battery-linux-sysfs): Standardize on energy&power. Accept ADP1 for AC adapter. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1bd45c07c3e..0b277c7c518 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,12 +1,16 @@ 2015-03-07 Stefan Monnier + * battery.el (battery-echo-area-format): Simplify default. + (battery-linux-sysfs): Standardize on energy&power. Accept ADP1 + for AC adapter. + * emacs-lisp/byte-opt.el (byte-optimize-form-code-walker): Don't try to unfold `closure's since byte-compile-unfold-lambda doesn't know how to do it. 2015-03-06 Oscar Fuentes - * net/browse-url.el (browse-url-firefox): Removed outdated + * net/browse-url.el (browse-url-firefox): Remove outdated MS-Windows limitations. 2015-03-06 Thomas Fitzsimmons @@ -16,8 +20,8 @@ (eudc-ldap-cleanup-record-filtering-addresses): Add docstring. Don't clean up postal addresses if ldap-ignore-attribute-codings is set. Combine mail addresses into one field. (Bug#17720) - (eudc-ldap-simple-query-internal): Call - eudc-ldap-cleanup-record-filtering-addresses instead of + (eudc-ldap-simple-query-internal): + Call eudc-ldap-cleanup-record-filtering-addresses instead of eudc-ldap-cleanup-record-simple. (eudc-ldap-get-field-list): Likewise. diff --git a/lisp/battery.el b/lisp/battery.el index 41e5979f1f2..b9ce5b49093 100644 --- a/lisp/battery.el +++ b/lisp/battery.el @@ -44,27 +44,27 @@ (defcustom battery-status-function (cond ((and (eq system-type 'gnu/linux) (file-readable-p "/proc/apm")) - 'battery-linux-proc-apm) + #'battery-linux-proc-apm) ((and (eq system-type 'gnu/linux) (file-directory-p "/proc/acpi/battery")) - 'battery-linux-proc-acpi) + #'battery-linux-proc-acpi) ((and (eq system-type 'gnu/linux) (file-directory-p "/sys/class/power_supply/") (directory-files "/sys/class/power_supply/" nil battery--linux-sysfs-regexp)) - 'battery-linux-sysfs) + #'battery-linux-sysfs) ((and (eq system-type 'berkeley-unix) (file-executable-p "/usr/sbin/apm")) - 'battery-bsd-apm) + #'battery-bsd-apm) ((and (eq system-type 'darwin) (condition-case nil (with-temp-buffer (and (eq (call-process "pmset" nil t nil "-g" "ps") 0) (> (buffer-size) 0))) (error nil))) - 'battery-pmset) + #'battery-pmset) ((fboundp 'w32-battery-status) - 'w32-battery-status)) + #'w32-battery-status)) "Function for getting battery status information. The function has to return an alist of conversion definitions. Its cons cells are of the form @@ -77,14 +77,7 @@ introduced by a `%' character in a control string." :group 'battery) (defcustom battery-echo-area-format - (cond ((eq battery-status-function 'battery-linux-proc-acpi) - "Power %L, battery %B at %r (%p%% load, remaining time %t)") - ((eq battery-status-function 'battery-linux-sysfs) - "Power %L, battery %B (%p%% load, remaining time %t)") - ((eq battery-status-function 'battery-pmset) - "%L power, battery %B (%p%% load, remaining time %t)") - (battery-status-function - "Power %L, battery %B (%p%% load, remaining time %t)")) + "Power %L, battery %B (%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 @@ -436,11 +429,15 @@ The following %-sequences are provided: %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 (charging-state rate temperature hours - (charge-full 0.0) - (charge-now 0.0) + (let (charging-state temperature hours + ;; Some batteries report charges and current, other energy and power. + ;; In order to reliably be able to combine those data, we convert them + ;; all to energy/power (since we can't combine different charges if + ;; they're not at the same voltage). (energy-full 0.0) - (energy-now 0.0)) + (energy-now 0.0) + (power-now 0.0) + (voltage-now 10.8)) ;Arbitrary default, in case the info is missing. ;; SysFS provides information about each battery present in the ;; system in a separate subdirectory. We are going to merge the ;; available information together. @@ -452,6 +449,11 @@ The following %-sequences are provided: (erase-buffer) (ignore-errors (insert-file-contents (expand-file-name "uevent" dir))) + (goto-char (point-min)) + (when (re-search-forward + "POWER_SUPPLY_VOLTAGE_NOW=\\([0-9]*\\)$" nil t) + (setq voltage-now (/ (string-to-number (match-string 1)) 1000000.0))) + (goto-char (point-min)) (when (re-search-forward "POWER_SUPPLY_PRESENT=1$" nil t) (goto-char (point-min)) (and (re-search-forward "POWER_SUPPLY_STATUS=\\(.*\\)$" nil t) @@ -461,7 +463,10 @@ The following %-sequences are provided: (when (re-search-forward "POWER_SUPPLY_\\(CURRENT\\|POWER\\)_NOW=\\([0-9]*\\)$" nil t) - (setq rate (float (string-to-number (match-string 2))))) + (cl-incf power-now + (* (float (string-to-number (match-string 2))) + (if (eq (char-after (match-beginning 1)) ?C) + voltage-now 1.0)))) (goto-char (point-min)) (when (re-search-forward "POWER_SUPPLY_TEMP=\\([0-9]*\\)$" nil t) (setq temperature (match-string 1))) @@ -475,10 +480,10 @@ The following %-sequences are provided: (re-search-forward "POWER_SUPPLY_CHARGE_NOW=\\([0-9]*\\)$" nil t) (setq now-string (match-string 1))) - (setq charge-full (+ charge-full - (string-to-number full-string)) - charge-now (+ charge-now - (string-to-number now-string)))) + (cl-incf energy-full (* (string-to-number full-string) + voltage-now)) + (cl-incf energy-now (* (string-to-number now-string) + voltage-now))) ((and (progn (goto-char (point-min)) t) (re-search-forward "POWER_SUPPLY_ENERGY_FULL=\\([0-9]*\\)$" nil t) @@ -486,27 +491,20 @@ The following %-sequences are provided: (re-search-forward "POWER_SUPPLY_ENERGY_NOW=\\([0-9]*\\)$" nil t) (setq now-string (match-string 1))) - (setq energy-full (+ energy-full - (string-to-number full-string)) - energy-now (+ energy-now - (string-to-number now-string)))))) + (cl-incf energy-full (string-to-number full-string)) + (cl-incf energy-now (string-to-number now-string))))) (goto-char (point-min)) - (when (and energy-now rate (not (zerop rate)) - (re-search-forward - "POWER_SUPPLY_VOLTAGE_NOW=\\([0-9]*\\)$" nil t)) + (unless (zerop power-now) (let ((remaining (if (string= charging-state "Discharging") energy-now (- energy-full energy-now)))) - (setq hours (/ (/ (* remaining (string-to-number - (match-string 1))) - rate) - 10000000.0))))))) - (list (cons ?c (cond ((or (> charge-full 0) (> charge-now 0)) - (number-to-string charge-now)) - ((or (> energy-full 0) (> energy-now 0)) - (number-to-string energy-now)) + (setq hours (/ remaining power-now))))))) + (list (cons ?c (cond ((or (> energy-full 0) (> energy-now 0)) + (number-to-string (/ energy-now voltage-now))) (t "N/A"))) - (cons ?r (if rate (format "%.1f" (/ rate 1000000.0)) "N/A")) + (cons ?r (if (> power-now 0.0) + (format "%.1f" (/ power-now 1000000.0)) + "N/A")) (cons ?m (if hours (format "%d" (* hours 60)) "N/A")) (cons ?h (if hours (format "%d" hours) "N/A")) (cons ?t (if hours @@ -514,21 +512,24 @@ The following %-sequences are provided: "N/A")) (cons ?d (or temperature "N/A")) (cons ?B (or charging-state "N/A")) - (cons ?p (cond ((and (> charge-full 0) (> charge-now 0)) - (format "%.1f" - (/ (* 100 charge-now) charge-full))) - ((> energy-full 0) + (cons ?p (cond ((and (> energy-full 0) (> energy-now 0)) (format "%.1f" (/ (* 100 energy-now) energy-full))) (t "N/A"))) - (cons ?L (if (file-readable-p "/sys/class/power_supply/AC/online") - (if (battery-search-for-one-match-in-files - (list "/sys/class/power_supply/AC/online" - "/sys/class/power_supply/ACAD/online") - "1" 0) - "AC" - "BAT") - "N/A"))))) + (cons ?L (cond + ((battery-search-for-one-match-in-files + (list "/sys/class/power_supply/AC/online" + "/sys/class/power_supply/ACAD/online" + "/sys/class/power_supply/ADP1/online") + "1" 0) + "AC") + ((battery-search-for-one-match-in-files + (list "/sys/class/power_supply/AC/online" + "/sys/class/power_supply/ACAD/online" + "/sys/class/power_supply/ADP1/online") + "0" 0) + "BAT") + (t "N/A")))))) ;;; `apm' interface for BSD.