temp = battery.getIntExtra (BatteryManager.EXTRA_TEMPERATURE, 0);
return new long[] { capacity, chargeCounter, currentAvg,
- currentNow, remaining, status, plugged,
+ currentNow, status, remaining, plugged,
temp, };
}
}
return new long[] { capacity, chargeCounter, currentAvg,
- currentNow, remaining, status, plugged,
+ currentNow, status, remaining, plugged,
temp, };
}
;; - BSD by using the `apm' program.
;; - Darwin (macOS) by using the `pmset' program.
;; - Windows via the GetSystemPowerStatus API call.
-;; - Android 5 or later via the BatteryManager APIs.
+;; - Android via the BatteryManager APIs.
;;; Code:
;; Note that even though the Linux kernel APIs are sometimes
;; available on Android, they are badly implemented by Android
;; kernels, so avoid using those.
- ((eq system-type 'android)
+ ((fboundp 'android-query-battery)
#'battery-android)
((and (eq system-type 'berkeley-unix)
(file-executable-p "/usr/sbin/apm"))
(rate nil)
(remaining nil)
(hours nil)
- (minutes nil))
+ (minutes nil)
+ (temperature nil))
;; Figure out the percentage.
(setq percentage (number-to-string (car status)))
;; Figure out the capacity
(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 ?L (cl-case (nth 6 status)
(0 "off-line")
(1 "on-line")
- (2 "on-line (dock)")
- (3 "on-line (USB)")
- (4 "on-line (wireless)")
+ (2 "on-line (USB)")
+ (4 "on-line (dock)")
+ (8 "on-line (wireless)")
(t "unknown")))
- (cons ?t (/ (or (nth 7 status) 0) 10.0))))))
+ (cons ?t (/ (or (nth 7 status) 0) 10.0))
+ (cons ?d temperature)))))
\f
;;; Private functions.
status->charge_counter = longs[1];
status->current_average = longs[2];
status->current_now = longs[3];
- status->remaining = longs[4];
- status->status = longs[5];
+ status->status = longs[4];
+ status->remaining = longs[5];
status->plugged = longs[6];
status->temperature = longs[7];