-
Notifications
You must be signed in to change notification settings - Fork 0
/
led-linuxgpio.sh
executable file
·90 lines (77 loc) · 1.29 KB
/
led-linuxgpio.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
if [ "$#" -lt 2 ]; then
echo "Not enough paramters!"
return 1
fi
NUM=$1
GPIO=$2
if [ "$#" -gt 2 ]; then
ON=0
OFF=1
else
ON=1
OFF=0
fi
if [ ! -f "/sys/class/gpio/gpio$GPIO/value" ]; then
echo $GPIO > /sys/class/gpio/export
fi
sleep 2
echo "out" > /sys/class/gpio/gpio$GPIO/direction
echo 0 > /sys/class/gpio/gpio$GPIO/value
rm /tmp/ledpipe$NUM
if [ ! -p "/tmp/ledpipe$NUM" ]; then
mkfifo /tmp/ledpipe$NUM
fi
function led_on {
echo $ON > /sys/class/gpio/gpio$GPIO/value
}
function led_off {
echo $OFF > /sys/class/gpio/gpio$GPIO/value
}
function led_blink {
while true; do
echo $ON > /sys/class/gpio/gpio$GPIO/value
sleep 0.3
echo $OFF > /sys/class/gpio/gpio$GPIO/value
sleep 0.15
done
}
function led_blink_f {
while true; do
echo $ON > /sys/class/gpio/gpio$GPIO/value
sleep 0.1
echo $OFF > /sys/class/gpio/gpio$GPIO/value
sleep 0.05
done
}
#trap led_on SIGUSR1
#trap led_off SIGUSR2
for (( ; ; )); do
#echo "New round"
while read SIGNAL; do
case "$SIGNAL" in
*EXIT*)break;;
*ON*)
kill $!
led_on
;;
*OFF*)
kill $!
led_off
;;
*BLINK*)
kill $!
led_blink &
;;
*FASTER*)
kill $!
led_blink_f &
;;
*)echo "Signal $SIGNAL is unsupported" > /dev/stderr;;
esac
# echo $SIGNAL
sleep 0.2
done < /tmp/ledpipe$NUM
#wait
#kill %1
done