Created
October 15, 2023 18:04
-
-
Save jiggak/8b2a285a944c70b503bdf4eb743db8aa to your computer and use it in GitHub Desktop.
Basic shutdown script for WittyPi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HALT_PIN=4 # halt by GPIO-4 (BCM naming) | |
SYSUP_PIN=17 # output SYS_UP signal on GPIO-17 (BCM naming) | |
export PATH=/usr/bin:/usr/sbin:/storage/.kodi/addons/virtual.system-tools/bin | |
export LD_LIBRARY_PATH=/usr/lib:/storage/.kodi/addons/script.module.certifi/lib:/storage/.kodi/addons/script.module.chardet/lib:/storage/.kodi/addons/script.module.idna/lib:/storage/.kodi/addons/script.module.requests/lib:/storage/.kodi/addons/script.module.urllib3/lib:/storage/.kodi/addons/virtual.system-tools/lib:/usr/lib/pulseaudio | |
gpio_in() { | |
gpioget gpiochip0 $1 | |
} | |
gpio_out() { | |
gpioset gpiochip0 ${1}=$2 | |
} | |
gpio_wait() { | |
gpiomon --silent --num-events=1 --falling-edge --bias=pull-up gpiochip0 $1 | |
} | |
# wait for RTC ready | |
sleep 2 | |
# indicates system is up | |
echo "Send out the SYS_UP signal via GPIO-$SYSUP_PIN pin." | |
gpio_out ${SYSUP_PIN} 1 | |
sleep 0.5 | |
gpio_out ${SYSUP_PIN} 0 | |
# delay until GPIO pin state gets stable | |
counter=0 | |
while [ $counter -lt 5 ]; do # increase this value if it needs more time | |
if [ $(gpio_in $HALT_PIN) == "1" ] ; then | |
counter=$(($counter+1)) | |
else | |
counter=0 | |
fi | |
sleep 1 | |
done | |
# wait for GPIO-4 (BCM naming) falling | |
echo "Waiting for shutdown command..." | |
gpio_wait $HALT_PIN | |
# shutdown Raspberry Pi | |
echo "Shutdown" | |
halt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment