64 lines
1.4 KiB
Bash
64 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
# 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 orange when it reaches 30%, red at 20%, and blinking red & orange at 10%
|
|
|
|
. /etc/profile
|
|
|
|
# Set export GPIO for Power LED
|
|
if [ ! -d "/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}" ]; then
|
|
echo ${DEVICE_PWR_LED_GPIO} > /sys/class/gpio/export
|
|
fi
|
|
|
|
function set_led() {
|
|
case $1 in
|
|
red)
|
|
echo out >/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}/direction
|
|
echo 1 >/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}/value
|
|
;;
|
|
green)
|
|
echo out >/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}/direction
|
|
echo 0 >/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}/value
|
|
;;
|
|
orange)
|
|
echo in >/sys/class/gpio/gpio${DEVICE_PWR_LED_GPIO}/direction
|
|
;;
|
|
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} <= 50 ))
|
|
#then
|
|
# for ctr in $(seq 1 1 5)
|
|
# do
|
|
# set_led orange
|
|
# sleep .5
|
|
# set_led red
|
|
# sleep .5
|
|
# done
|
|
# continue
|
|
#elif (( ${CAP} <= 20 ))
|
|
if (( ${CAP} <= 20 ))
|
|
then
|
|
set_led red
|
|
elif (( ${CAP} <= 30 ))
|
|
then
|
|
set_led orange
|
|
else
|
|
set_led green
|
|
fi
|
|
elif (( ${CAP} >= 95 ))
|
|
then
|
|
set_led green
|
|
fi
|
|
sleep 15
|
|
done
|