-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtc-mon
executable file
·42 lines (42 loc) · 978 Bytes
/
rtc-mon
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
#!/bin/bash
BATSYS="/sys/devices/platform/soc*/soc*:rpi_rtc/rtc/rtc0/battery_voltage"
LOWV="275"
HIGHV="300"
CHGSYS="/sys/devices/platform/soc*/soc*:rpi_rtc/rtc/rtc0/charging_voltage"
CFGF="/boot/config.txt /boot/tryboot.txt"
DTP="dtparam=rtc_bbat_vchg=3000000"
getbatv() {
cut -c1-3 ${BATSYS}
}
chgon() {
sed -i "s/#${DTP}/${DTP}/" ${CFGF}
sleep 30
systemctl reboot
}
chgoff() {
sed -i "s/${DTP}/#${DTP}/" ${CFGF}
sleep 30
systemctl reboot
}
if [ "${UID}" -ne 0 ]; then
exec sudo $0 $@
fi
if [ "$(getbatv)" -le "${LOWV}" ]; then
#ENABLE CHARGE, reboot 11
echo "Low rtc battery, rebooting to enable charging"
chgon
elif [ "$(getbatv)" -ge "${HIGHV}" ]; then
if [ $(cat ${CHGSYS}) -ne 0 ]; then
#stop charge, reboot
echo "Rtc battery charged, rebooting to stop"
chgoff
else
echo "Battery high charge but not charging"
fi
else
echo "Battery between high and low level"
echo -n "voltage: "
getbatv
echo -n "Charge voltage: "
cut -c1-3 ${CHGSYS}
fi