-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatleft
More file actions
executable file
·57 lines (41 loc) · 1.34 KB
/
Copy pathbatleft
File metadata and controls
executable file
·57 lines (41 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/awk -f
function readval(file) {
if (getline line < (path file) > 0)
return line
else
return 0
}
BEGIN {
path1 = "/sys/class/power_supply/BAT0/"
path2 = "/sys/class/power_supply/BAT1/"
if (readval(path1"present"))
path = path1
else
path = path2
status = readval("status")
capacity = readval("capacity")
voltage_now = readval("voltage_now") / 1000000
energy_now = readval("energy_now") / 1000
energy_full = readval("energy_full") / 1000
charge_now = readval("charge_now") / 1000
charge_full = readval("charge_full") / 1000
power_now = readval("power_now") / 1000
current_now = readval("current_now") / 1000
if (!energy_now)
energy_now = charge_now * voltage_now
if (!energy_full)
energy_full = charge_full * voltage_now
if (!power_now)
power_now = current_now * voltage_now
printf "Status: %s\n", status
printf "Charge: %d% (%d/%d mWh)\n", capacity, energy_now, energy_full
printf "Current: %d mA @ %.3f V\n", current_now, voltage_now
printf "Power usage: %.2f W\n", power_now / 1000
if (status == "Discharging")
time_left = energy_now / power_now
else if (status == "Charging")
time_left = (energy_full - energy_now) / power_now
hours_left = int(time_left)
minutes_left = int((time_left - hours_left) * 60)
printf "Time left: %dh%02dm\n", hours_left, minutes_left
}