|
|
@ -4,66 +4,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
# This file is part of battery_status_led.
|
|
|
|
# This file is part of battery_status_led.
|
|
|
|
|
|
|
|
|
|
|
|
# battery_status_led is free software: you can redistribute it and/or modify it
|
|
|
|
# battery_status_led is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License v3 as published by the Free
|
|
|
|
# under the terms of the GNU General Public License v3 as published by the Free
|
|
|
|
# Software Foundation.
|
|
|
|
# Software Foundation.
|
|
|
|
|
|
|
|
|
|
|
|
# battery_status_led is distributed in the hope that it will be useful, but
|
|
|
|
# battery_status_led is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License v3 for
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License v3 for
|
|
|
|
# more details.
|
|
|
|
# more details.
|
|
|
|
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License v3 along
|
|
|
|
# You should have received a copy of the GNU General Public License v3 along
|
|
|
|
# with battery_status_led. If not, see
|
|
|
|
# with battery_status_led. If not, see
|
|
|
|
# https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
# https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
|
|
|
|
|
|
|
# limits in percentages
|
|
|
|
# limits in percentages
|
|
|
|
LOW=10 # flip LED every 2s
|
|
|
|
LOW=10 # flip LED every 2s
|
|
|
|
CRIT=5 # flip led every 0.5s
|
|
|
|
CRIT=5 # flip led every 0.5s
|
|
|
|
|
|
|
|
|
|
|
|
BAT_FULL=`cat /sys/class/power_supply/BAT0/energy_full_design`
|
|
|
|
BAT_FULL_DEV=/sys/class/power_supply/BAT0/energy_full_design
|
|
|
|
CAPSLOCK_LED=`cat /sys/class/leds/input4\:\:capslock/brightness`
|
|
|
|
BAT_STATUS_DEV=/sys/class/power_supply/BAT0/status
|
|
|
|
|
|
|
|
BAT_NOW_DEV=/sys/class/power_supply/BAT0/energy_now
|
|
|
|
|
|
|
|
CAPSLOCK_LED_DEV=/sys/class/leds/input4\:\:capslock/brightness
|
|
|
|
|
|
|
|
|
|
|
|
# If not set by the systemd service file
|
|
|
|
# If not set by the systemd service file
|
|
|
|
LED_DEV=${BATTERY_STATUS_LED_DEV:-/sys/class/leds/input4\:\:capslock/brightness}
|
|
|
|
LED_DEV=${BATTERY_STATUS_LED_DEV:-$CAPSLOCK_LED_DEV}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LED=0
|
|
|
|
CNT=0
|
|
|
|
|
|
|
|
while :
|
|
|
|
while :
|
|
|
|
do
|
|
|
|
do
|
|
|
|
# If charging, sleep 1m, then restart the cycle
|
|
|
|
# If charging, sleep 1m, then restart the cycle
|
|
|
|
STATUS=`cat /sys/class/power_supply/BAT0/status`
|
|
|
|
STATUS=cat $BAT_STATUS_DEV
|
|
|
|
if [ $STATUS == "Charging" ] ; then
|
|
|
|
if [ $STATUS == "Charging" ] ; then
|
|
|
|
echo 0 > $LED_DEV
|
|
|
|
echo 0 > $LED_DEV
|
|
|
|
sleep 1m
|
|
|
|
sleep 1m
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
BAT_NOW=`cat /sys/class/power_supply/BAT0/energy_now`
|
|
|
|
BAT_NOW=cat $BAT_NOW_DEV
|
|
|
|
BAT_PCT=$(($BAT_NOW * 100 / $BAT_FULL))
|
|
|
|
BAT_PCT=$(($BAT_NOW * 100 / $BAT_FULL))
|
|
|
|
|
|
|
|
|
|
|
|
# If battery has more than >10% left, sleep 1m then restart the cycle
|
|
|
|
# If battery has more than >10% left, sleep 1m then restart the cycle
|
|
|
|
if (($BAT_PCT > $LOW )) ; then
|
|
|
|
if (($BAT_PCT >= $LOW )) ; then
|
|
|
|
sleep 1m
|
|
|
|
sleep 1m
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
sleep 0.5s
|
|
|
|
# If battery is on low, but not crytical, flip LED every 2s
|
|
|
|
CNT=$((CNT+1))
|
|
|
|
if (( $BAT_PCT < $LOW )) && (( $BAT_PCT >= $CRIT)) ; then
|
|
|
|
|
|
|
|
LED=$((1 ^ $LED))
|
|
|
|
# If battery <5% (crytical) flip capslock LED every 0.5s
|
|
|
|
echo $LED > $LED_DEV
|
|
|
|
if (( $BAT_PCT <= $CRIT )) ; then
|
|
|
|
sleep 2s
|
|
|
|
CAPSLOCK_LED=$((1 ^ $CAPSLOCK_LED))
|
|
|
|
continue
|
|
|
|
echo $CAPSLOCK_LED > $LED_DEV
|
|
|
|
|
|
|
|
# If battery is on low, but not crytical, flip LED every 4th 0.5s (2s)
|
|
|
|
|
|
|
|
elif (( $BAT_PCT <= $LOW )) && (( $CNT % 4 == 1 )) ; then
|
|
|
|
|
|
|
|
CAPSLOCK_LED=$((1 ^ $CAPSLOCK_LED))
|
|
|
|
|
|
|
|
echo $CAPSLOCK_LED > $LED_DEV
|
|
|
|
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# not sure if i need this:
|
|
|
|
# If battery is on crytical flip capslock LED every 0.5s
|
|
|
|
if (( $CNT > 100000 )) ; then
|
|
|
|
if (( $BAT_PCT < $CRIT )) ; then
|
|
|
|
CNT=1
|
|
|
|
LED=$((1 ^ $LED))
|
|
|
|
|
|
|
|
echo $LED > $LED_DEV
|
|
|
|
|
|
|
|
sleep 0.5s
|
|
|
|
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|