Function: battery-android
battery-android is a byte-compiled function defined in battery.el.gz.
Signature
(battery-android)
Documentation
Get battery status information using Android.
The following %-sequences are provided:
%c Current capacity (mAh)
%r Current rate of charge or discharge (mA)
%L AC line status (verbose).
%B Battery status (verbose)
%b Battery status, empty means high, - means low,
+ means charging and ? means unknown.
%d Temperature (in degrees Celsius)
%p Battery load percentage.
%m Remaining time (to charge) in minutes.
%h Remaining time (to charge) in hours.
%t Remaining time (to charge) in the form h:min.
Source Code
;; Defined in /usr/src/emacs/lisp/battery.el.gz
(defun battery-android ()
"Get battery status information using Android.
The following %-sequences are provided:
%c Current capacity (mAh)
%r Current rate of charge or discharge (mA)
%L AC line status (verbose).
%B Battery status (verbose)
%b Battery status, empty means high, `-' means low,
`+' means charging and `?' means unknown.
%d Temperature (in degrees Celsius)
%p Battery load percentage.
%m Remaining time (to charge) in minutes.
%h Remaining time (to charge) in hours.
%t Remaining time (to charge) in the form `h:min'."
(when-let* ((status (android-query-battery)))
(let* ((percentage nil)
(capacity nil)
(sym-status nil)
(symbol nil)
(rate nil)
(remaining nil)
(hours nil)
(minutes nil)
(temperature nil))
;; Figure out the percentage.
(setq percentage (number-to-string (car status)))
;; Figure out the capacity
(setq capacity (number-to-string (/ (cadr status) 1000)))
;; Figure out the battery status.
(let ((percentage (car status)))
(cl-ecase (nth 4 status)
(2 (setq sym-status "charging" symbol "+"))
(3 (setq sym-status "discharging"
symbol (if (< percentage 15) "-" " ")))
(5 (setq sym-status "full" symbol " "))
(4 (setq sym-status "not charging"
symbol (if (< percentage 15) "-" " ")))
(1 (setq sym-status "unknown" symbol "?"))))
;; Figure out the rate of charge.
(setq rate (/ (nth 3 status) 1000))
;; Figure out the remaining time.
(let* ((time (nth 5 status))
(mins (/ time (* 1000 60)))
(hours-left (/ mins 60))
(mins (mod mins 60)))
(unless (eq time -1)
(setq remaining (format "%d:%d" hours-left mins)
hours (number-to-string hours-left)
minutes (number-to-string mins))))
;; Return the temperature, so long as its value is not downright
;; absurd (as when the sensor is faulty or the battery controller
;; driver does not provide temperature readouts).
(unless (or (< (nth 7 status) -1000)
(> (nth 7 status) 1000))
(setq temperature (/ (nth 7 status) 10.0)))
;; Return results.
(list (cons ?c capacity)
(cons ?p percentage)
(cons ?r rate)
(cons ?B sym-status)
(cons ?b symbol)
(cons ?m (or minutes "N/A"))
(cons ?h (or hours "N/A"))
(cons ?t (or remaining "N/A"))
(cons ?L (cl-case (nth 6 status)
(0 "off-line")
(1 "on-line")
(2 "on-line (USB)")
(4 "on-line (dock)")
(8 "on-line (wireless)")
(t "unknown")))
(cons ?t (/ (or (nth 7 status) 0) 10.0))
(cons ?d temperature)))))