+ (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")))))