Skip to content

Instantly share code, notes, and snippets.

@pfeerick
Last active July 2, 2021 07:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save pfeerick/00b04df3ce65979158b117b4e1f7c168 to your computer and use it in GitHub Desktop.
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
#!/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
@pfeerick
Copy link
Author

pfeerick commented Nov 7, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment