Skip to content

Instantly share code, notes, and snippets.

@pfeerick
Last active April 15, 2021 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfeerick/13c3268501c8dd44b223f706aa0b4c01 to your computer and use it in GitHub Desktop.
Save pfeerick/13c3268501c8dd44b223f706aa0b4c01 to your computer and use it in GitHub Desktop.
Flash the SYSLED of the pine64/clusterboard
#!/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"
sleep 0.1
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
sleep 0.1
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.5s
echo 1 > "/sys/class/gpio/gpio359/value" #off
sleep 0.5s
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment