-
Notifications
You must be signed in to change notification settings - Fork 0
/
kotel
executable file
·92 lines (79 loc) · 1.75 KB
/
kotel
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
91
92
#!/bin/bash
RELAY_A=24
RELAY_B=23
RELAY_C=17
RELAY_D=22
GPIO_PATH="/sys/class/gpio/"
function is_initialized {
if [[ -d ${GPIO_PATH}/gpio${RELAY_A} ]]; then
if [[ -d ${GPIO_PATH}/gpio${RELAY_B} ]]; then
return 0
fi
fi
return 1
}
function initialize {
# If we are already did the initialization, then ignore this
if is_initialized; then
return 0
fi
# Initialize the relay ports
(echo ${RELAY_A} > ${GPIO_PATH}/export) 2> /dev/null
(echo ${RELAY_B} > ${GPIO_PATH}/export) 2> /dev/null
echo out > ${GPIO_PATH}/gpio${RELAY_A}/direction
echo out > ${GPIO_PATH}/gpio${RELAY_B}/direction
}
function start_kotel {
echo 1 > ${GPIO_PATH}/gpio${RELAY_A}/value
echo 1 > ${GPIO_PATH}/gpio${RELAY_B}/value
}
function stop_kotel {
echo 1 > ${GPIO_PATH}/gpio${RELAY_A}/value
echo 0 > ${GPIO_PATH}/gpio${RELAY_B}/value
}
function manual_kotel {
echo 0 > ${GPIO_PATH}/gpio${RELAY_A}/value
echo 0 > ${GPIO_PATH}/gpio${RELAY_B}/value
}
function status_kotel {
A=$(cat ${GPIO_PATH}/gpio${RELAY_A}/value)
B=$(cat ${GPIO_PATH}/gpio${RELAY_B}/value)
if [[ ${B} -ne 0 ]]; then
echo "started"
return 0
fi
if [[ ${A} -ne 0 ]]; then
echo "stopped"
return 0
fi
echo "manual"
return 0
}
function print_help {
echo "Usage:"
echo " $(basename $0) start|stop|manual|status"
}
# Parse argument
case "$1" in
start*)
initialize
start_kotel
;;
stop*)
initialize
stop_kotel
;;
manual)
initialize
manual_kotel
;;
""|status)
initialize
status_kotel
;;
*)
print_help
exit 1
;;
esac
exit 0