Working on LED Battery Status Service

This commit is contained in:
mason 2023-07-10 04:03:40 +00:00
parent 3fe336ab58
commit f962a948c5
No known key found for this signature in database
GPG key ID: 84D9278A11FA112B
5 changed files with 83 additions and 0 deletions

View file

@ -14,6 +14,7 @@ DEVICE_JACK="8"
DEVICE_HEADPHONE_DEV="/dev/input/by-path/platform-es8316-sound-event"
DEVICE_HAS_HDMI=true
DEVICE_HDMI_GPIO="54"
DEVICE_BATTERY_LED_STATUS=true
UI_SERVICE="weston.service"
DEVICE_TEMP_SENSOR=("/sys/devices/virtual/thermal/thermal_zone0/temp" "/sys/devices/virtual/thermal/thermal_zone1/temp")

View file

@ -12,6 +12,7 @@ export SLOW_CORES \
GPU_FREQ \
DEVICE_AUDIO_MIXER \
DEVICE_BRIGHTNESS \
DEVICE_BATTERY_LED_STATUS \
DEVICE_FAKE_JACKSENSE \
DEVICE_FUNC_KEYA_MODIFIER \
DEVICE_FUNC_KEYB_MODIFIER \

View file

@ -35,3 +35,11 @@ then
else
nohup systemctl stop hdmi &
fi
if [ "${DEVICE_BATTERY_LED_STATUS}" == "true" ]
then
tocon "Starting battery led status service..."
nohup systemctl start batteryledstatus &
else
nohup systemctl stop batteryledstatus &
fi

View file

@ -0,0 +1,61 @@
# 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

View file

@ -0,0 +1,12 @@
[Unit]
Description=Battery LED Status
Before=jelos.target
[Service]
Environment=HOME=/storage
EnvironmentFile=/etc/profile
ExecStart=/usr/bin/battery_led_status
Restart=on-failure
[Install]
WantedBy=multi-user.target