-
Notifications
You must be signed in to change notification settings - Fork 1
/
door_lock.sh
executable file
·50 lines (46 loc) · 1.02 KB
/
door_lock.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
#! /bin/sh
GPIO_OPEN=23
GPIO_CLOSE=24
GPIO_CLIP=22
GPIO_SWITCH=21
SLEEP=4
CLOSE_TIMEOUT=15
for i in $GPIO_OPEN $GPIO_CLOSE $GPIO_CLIP; do
echo "$i" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio${i}/direction
done
echo "$GPIO_SWITCH" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio${GPIO_SWITCH}/direction
case $1 in
open)
echo "1" > /sys/class/gpio/gpio${GPIO_OPEN}/value
sleep $SLEEP
echo "0" > /sys/class/gpio/gpio${GPIO_OPEN}/value
;;
close)
TIMER=$(($CLOSE_TIMEOUT*10))
while [ $TIMER -ge 0 ]; do
{
SWITCH=$(cat /sys/class/gpio/gpio${GPIO_SWITCH}/value)
if [ $SWITCH -eq 1 ]; then
{
echo "1" > /sys/class/gpio/gpio${GPIO_CLOSE}/value
sleep $SLEEP
echo "0" > /sys/class/gpio/gpio${GPIO_CLOSE}/value
break
}
fi
sleep .1
TIMER=$(($TIMER-1))
}
done
;;
clip)
echo "1" > /sys/class/gpio/gpio${GPIO_CLIP}/value
sleep $SLEEP
echo "0" > /sys/class/gpio/gpio${GPIO_CLIP}/value
;;
*)
echo "valid commands are \"open\", \"close\" and \"clip\""
;;
esac