-
Notifications
You must be signed in to change notification settings - Fork 0
/
battery
executable file
·68 lines (58 loc) · 1.65 KB
/
battery
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
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# max_voltage=${1:-3800}
max_voltage=3800
charging_enabled="/sys/class/power_supply/battery/charging_enabled"
log() {
date=`date +[%Y.%m.%d\ %H:%M:%S]`
echo "$date $1"
}
status() {
# ctype=`cat /sys/class/power_supply/battery/charge_type`
capacity=`cat /sys/class/power_supply/battery/capacity`
charging=`cat $charging_enabled`
# health=`cat /sys/class/power_supply/battery/health`
status=`cat /sys/class/power_supply/battery/status`
current=`cat /sys/class/power_supply/battery/current_now`
voltage=`cat /sys/class/power_supply/battery/voltage_now`
temp=`cat /sys/class/power_supply/battery/temp`
echo "Capacity: $capacity # Charging: $charging # Voltage: $voltage # Current: $current # Status: $status # Temp: $temp"
}
# this is needed so charging won't be stopped from protection (/sys/class/power_supply/battery/chg_protect_status)
last_charge_update=0
pause_charge() {
now=`date +%s`
if (( $now < ($last_charge_update + 3600 * 9) )); then # every 9 hours
return
fi
# log "Updating charge..."
echo 0 > $charging_enabled
sleep 9 # pause for 9 seconds (protection status check is ever 6 seconds)
echo 1 > $charging_enabled
last_charge_update=$now
}
update() {
pause_charge
voltage=`cat /sys/class/power_supply/battery/voltage_max`
# echo $voltage
if [[ $voltage != $max_voltage ]]; then
log "Updating voltage_max to $max_voltage..."
echo $max_voltage > /sys/class/power_supply/battery/voltage_max
fi
}
monitor() {
while true
do
update
sleep 60
done
}
case "$1" in
update)
update
;;
monitor)
monitor
;;
*)
status
esac