distribution/packages/sysutils/system-utils/sources/devices/RK3399/battery_led_status

62 lines
1.3 KiB
Text
Raw Normal View History

2023-07-10 04:03:40 +00:00
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2020-present Fewtarius
# Simple script to watch the battery capacity and
# turn the power LED red when it reaches 25%
. /etc/profile
function set_led() {
case $1 in
red)
echo 0 > /sys/class/leds/battery_green/brightness
echo 1 > /sys/class/leds/battery_red/brightness
;;
green)
echo 1 > /sys/class/leds/battery_green/brightness
echo 0 > /sys/class/leds/battery_red/brightness
;;
orange)
echo 1 > /sys/class/leds/battery_green/brightness
echo 1 > /sys/class/leds/battery_red/brightness
;;
off)
echo 0 > /sys/class/leds/battery_green/brightness
echo 0 > /sys/class/leds/battery_red/brightness
;;
esac
}
while true
do
CAP=$(cat /sys/class/power_supply/battery/capacity)
STAT=$(cat /sys/class/power_supply/battery/status)
if [ ${STAT} == "Discharging" ]
then
if (( ${CAP} <= 10 ))
then
for ctr in $(seq 1 1 5)
do
set_led red
sleep .5
set_led off
sleep .5
done
continue
elif (( ${CAP} <= 25 ))
then
set_led red
elif (( ${CAP} <= 49 ))
then
set_led orange
else
set_led green
fi
elif (( ${CAP} >= 95 ))
then
set_led green
fi
sleep 15
done