67 lines
1.4 KiB
Bash
Executable file
67 lines
1.4 KiB
Bash
Executable file
#!/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 to different states:
|
|
# 0-10% flashing blue and teal
|
|
# 11-20% teal
|
|
# 21+% blue
|
|
# charging purple
|
|
# fully charged white
|
|
|
|
. /etc/profile
|
|
|
|
function set_led() {
|
|
case $1 in
|
|
white)
|
|
echo 1 > /sys/class/leds/red\:charging/brightness
|
|
echo 1 > /sys/class/leds/green\:status/brightness
|
|
;;
|
|
purple)
|
|
echo 1 > /sys/class/leds/red\:charging/brightness
|
|
echo 0 > /sys/class/leds/green\:status/brightness
|
|
;;
|
|
blue)
|
|
echo 0 > /sys/class/leds/red\:charging/brightness
|
|
echo 0 > /sys/class/leds/green\:status/brightness
|
|
;;
|
|
teal)
|
|
echo 0 > /sys/class/leds/red\:charging/brightness
|
|
echo 1 > /sys/class/leds/green\:status/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 teal
|
|
sleep .5
|
|
set_led blue
|
|
sleep .5
|
|
done
|
|
continue
|
|
elif (( ${CAP} <= 20 ))
|
|
then
|
|
set_led teal
|
|
else
|
|
set_led blue
|
|
fi
|
|
elif (( ${CAP} <= 95 ))
|
|
then
|
|
set_led purple
|
|
else
|
|
set_led white
|
|
fi
|
|
sleep 15
|
|
done
|