-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpine64-SYSLED-heartbeat.sh
executable file
·63 lines (50 loc) · 1.45 KB
/
pine64-SYSLED-heartbeat.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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.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