Last active
July 2, 2021 07:02
-
-
Save pfeerick/00b04df3ce65979158b117b4e1f7c168 to your computer and use it in GitHub Desktop.
Shell script that makes the Pine64 System LED do a double flash heartbeat approximatley every 10 seconds
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 | |
function openGPIO | |
{ | |
#test if GPIO sysfs entry exists, create if necessary | |
if [ ! -e "/sys/class/gpio/gpio359" ]; then | |
# echo "DEBUG: export 359" | |
echo 359 > "/sys/class/gpio/export" | |
fi | |
#test direction is set correctly, set if necessary | |
GPIO_359_DIRECTION=$(</sys/class/gpio/gpio359/direction) | |
if [ "$GPIO_359_DIRECTION" != "out" ]; then | |
# echo "DEBUG: direction out" | |
echo out > /sys/class/gpio/gpio359/direction | |
fi | |
} | |
function closeGPIO | |
{ | |
#turn off, unexport GPIO sysfs entry, and quit nicely | |
echo 1 > "/sys/class/gpio/gpio359/value" | |
echo 359 > "/sys/class/gpio/unexport" | |
} | |
function cleanup | |
{ | |
closeGPIO | |
exit 0 | |
} | |
#unexport and exit nicely if Ctrl-C pressed, SIGTERM, etc sent | |
trap cleanup SIGHUP SIGINT SIGTERM | |
openGPIO | |
#absorb likely error from first access to GPIO value | |
echo 0 | tee "/sys/class/gpio/gpio359/value" > /dev/null 2>&1 | |
#momentary pause to let udev do its magic | |
sleep 0.1 | |
#main loop | |
while true | |
do | |
echo 0 > "/sys/class/gpio/gpio359/value" #on | |
sleep 0.1s | |
echo 1 > "/sys/class/gpio/gpio359/value" #off | |
sleep 0.1s | |
echo 0 > "/sys/class/gpio/gpio359/value" #on | |
sleep 0.1s | |
echo 1 > "/sys/class/gpio/gpio359/value" #off | |
sleep 0.1s | |
echo 1 > "/sys/class/gpio/gpio359/value" #off | |
sleep 9.7s | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
r3 adds a oneshot change to the GPIO value with a redirect for resulting permission error message, as udev will trigger the permission change after that, and everything should be fine.