/sys/class/power_supply/BAT0/ 資料夾裡,有一系列的檔案存放著電池的資訊

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ ls /sys/class/power_supply/BAT0/
alarm                           charge_stop_threshold  serial_number
capacity                        current_now            status
capacity_level                  cycle_count            subsystem
charge_control_end_threshold    device                 technology
charge_control_start_threshold  hwmon1                 type
charge_full                     manufacturer           uevent
charge_full_design              model_name             voltage_min_design
charge_now                      power                  voltage_now
charge_start_threshold          present

只要是檔案類型的,都可以直接 cat 查看資料

查看電量 (百分比)

1
2
$ cat /sys/class/power_supply/BAT0/capacity
87

查看電池使用狀態 (Charging, Discharging, Full 等)

1
2
$ cat /sys/class/power_supply/BAT0/status
Charging

查看電池的材料

1
2
$ cat /sys/class/power_supply/BAT0/technology
Li-ion

查看全滿電量理論值 (µAh)

1
2
maple@debian:~$ cat /sys/class/power_supply/BAT0/charge_full_design
3513000

查看全滿電量實際值 (µAh)

1
2
maple@debian:~$ cat /sys/class/power_supply/BAT0/charge_full
3280000

查看目前電量 (µAh)

1
2
$ cat /sys/class/power_supply/BAT0/charge_now
3273000

查看所有的電池資訊

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
$ cat /sys/class/power_supply/BAT0/uevent
POWER_SUPPLY_NAME=BAT0
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_STATUS=Unknown
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_TECHNOLOGY=Li-ion
POWER_SUPPLY_CYCLE_COUNT=0
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11100000
POWER_SUPPLY_VOLTAGE_NOW=12196000
POWER_SUPPLY_CURRENT_NOW=0
POWER_SUPPLY_CHARGE_FULL_DESIGN=3513000
POWER_SUPPLY_CHARGE_FULL=3280000
POWER_SUPPLY_CHARGE_NOW=3273000
POWER_SUPPLY_CAPACITY=99
POWER_SUPPLY_CAPACITY_LEVEL=Normal
POWER_SUPPLY_MODEL_NAME=99X99999
POWER_SUPPLY_MANUFACTURER=XYZ
POWER_SUPPLY_SERIAL_NUMBER=123456

Reference