简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!
优质专栏:Audio工程师进阶系列【原创干货持续更新中……】
人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.
本篇目的:在Emacs获取电池是否充电 、电池电量、电池剩余多长时间关机等状态。
;;每次执行完,需要执行此句才能生效
(display-battery-mode 1)
;;显示电池百分比,剩余时间,是否充电状态.
(setq battery-mode-line-format " Bty:%p% [%t] %b")
(setq battery-mode-line-format " Battery:%p% [%t] %L")
;;充电或放电的电流
(setq battery-mode-line-format " Battery:%r")
;;电流容量(mAh或mWh)
(setq battery-mode-line-format " Battery:%c")
(setq battery-mode-line-format " Battery:%B")
;;显示电池百分比.
(setq battery-mode-line-format " Battery:%p%")
;;电池显示可用时间.
(setq battery-mode-line-format " Battery:%t")
;;是否充电状态:如果是充电显示:"on-line"; 没有充电,显示"off-line".
(setq battery-mode-line-format " Battery:%L")
;;如果是充电显示:"+"号; 没有充电,什么也不显示,耗电状态是:"-"号.
(setq battery-mode-line-format " Battery:%b")
;;充电预计在多长时间充满,可以用小时,分钟,秒来计算.
(setq battery-mode-line-format " Battery:%h %m %s")
(battery-format battery-echo-area-format (funcall battery-status-function))
(funcall battery-status-function)参数解释
(funcall battery-status-function)
返回了一个关联列表,其中包含了关于电池状态的信息。每个键值对表示一个特定的属性和对应的值。
根据给出的键值对,这是对照表解释每个键的意义:
99
:电池剩余容量百分比114
:电池当前功耗76
:电源接入状态(“on-line” 表示接入电源,“off-line” 表示未接入电源)66
:充电状态(“charging” 表示正在充电,“discharging” 表示未充电)98
:电池充电等级符号(例如 “+” 表示正在充电,“-” 表示正在放电,“=” 表示已充满)116
:估计的剩余/充电时间(如果不可用,则为 “N/A”)112
:电源插头状态(“0” 表示未插入电源插头,“1” 表示插入电源插头)115
:电池电压109
:最大电池容量104
:电池温度每个键对应的值则提供了相应属性的具体数值或状态,了解了键值以后,根据每个键值或电池的状态。
(display-battery-mode 1)
(defun display-battery-info ()
(setq battery-info (funcall battery-status-function))
(when battery-info
(let ((battery-level (cdr (assoc 112 battery-info)))
(battery-status (cdr (assoc 98 battery-info)))
(battery-charge-time (cdr (assoc 116 battery-info)))
(battery-power-consumption (cdr (assoc 114 battery-info)))
(battery-charge-state (cdr (assoc 76 battery-info)))
(battery-voltage (cdr (assoc 115 battery-info)))
(battery-temperature (cdr (assoc 104 battery-info)))
)
(message "电池电量:%s%% 电池状态:%s 冲电/剩余时间: %s 功耗:%s 充电状态:%s 电池电压:%s 电池温度:%s" battery-level battery-status battery-charge-time battery-power-consumption battery-charge-state battery-voltage battery-temperature)
)))
(display-battery-info)
打印:
(display-battery-mode 1)
(funcall battery-status-function)
;;v1.0
(defun display-battery-info ()
(setq battery-info (funcall battery-status-function))
(when battery-info
(let ((battery-level (cdr (assoc 112 battery-info)))
(battery-status (cdr (assoc 98 battery-info)))
(battery-charge-time (cdr (assoc 116 battery-info)))
(battery-power-consumption (cdr (assoc 114 battery-info)))
(battery-power-access (cdr (assoc 76 battery-info)))
(battery-voltage (cdr (assoc 115 battery-info)))
(battery-charge-state (cdr (assoc 66 battery-info)))
)
(message "电池电量:%s%% 电池符号:%s 冲电/剩余时间: %s 功耗:%s 电源插入状态:%s 电压:%s 充电状态:%s" battery-level battery-status battery-charge-time battery-power-consumption battery-power-access battery-voltage battery-charge-state)
)))
(display-battery-info)