forked from mholgatem/GPIOnext
-
Notifications
You must be signed in to change notification settings - Fork 1
/
usr-bin-gpionext
172 lines (154 loc) · 4.89 KB
/
usr-bin-gpionext
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
NONE='\033[00m'
CYAN='\033[36m'
# set case insensitive
shopt -s nocasematch
set_flag(){
sudo systemctl stop gpionext
sudo cp /lib/systemd/system/gpionext.service /tmp/gpionext.tmp
sudo sed -i -e "$1" /tmp/gpionext.tmp
sudo cp /tmp/gpionext.tmp /lib/systemd/system/gpionext.service
# reload daemon and restart
echo "Setting Flag and Restarting GPIOnext..."
sudo systemctl daemon-reload
sudo systemctl start gpionext
}
case "$1" in
"STOP")
sudo systemctl stop gpionext
;;
"START")
sudo systemctl enable gpionext
sudo systemctl start gpionext
;;
"CONFIG")
#Run config with any supplied arguments
sudo python3 $CONFIG_PATH "${@:2}"
;;
"DISABLE")
sudo systemctl disable gpionext
;;
"RELOAD")
sudo systemctl stop gpionext
sudo systemctl daemon-reload
sudo systemctl start gpionext
;;
"UPDATE")
echo -e "${CYAN}Starting Update...${NONE}"
sudo bash ~/GPIOnext/update.sh
;;
"JOURNAL")
if ! [[ $(grep "\-\-dev" /lib/systemd/system/gpionext.service) ]]; then
echo "use 'gpionext set dev true' before running this command to get more information"
fi
echo -e "${CYAN}Press Ctrl + C to exit${NONE}";
sudo journalctl -u gpionext -f
;;
"TEST")
hash jstest >/dev/null || { echo >&2 "Installing Joystick for test module"; sudo apt-get install joystick; }
(for i in /sys/devices/virtual/input/input*; do
if [[ $(cat "$i/name") == "GPIOnext Joypad $2" ]]; then
event="/dev/input/"$(find $i -maxdepth 1 -type d -name 'js*' -printf '%f' -quit);
echo -e "${CYAN}Press Ctrl + C to exit${NONE}";
jstest --normal "$event";
fi
done) && echo "Could not find GPIOnext Joypad $2 in virtual devices"
;;
"SET")
wholeNumber='^[0-9]+$'
case "$2" in
"COMBO_DELAY")
if [[ $3 =~ $wholeNumber ]] ; then
set_flag 's/--combo_delay [0-9]*/--combo_delay '$3'/g'
else
echo -e "You must supply a ${CYAN}valid whole number${NONE} for $2"
fi
;;
"PINS")
case "$3" in
"DEFAULT")
echo "setting pins to default"
set_flag 's/[ ]*--pins [0-9/,]*//g'
;;
[0-9/,]*)
echo "setting pins $3"
set_flag 's/[ ]*--pins [0-9/,]*//g;s/^ExecStart=.*/& --pins '$3'/g'
;;
*)
echo -e "You must supply ${CYAN}comma separated pin numbers${NONE} [ex. set pins 3,5,7,11] or default";;
esac
;;
"DEBOUNCE")
if [[ $3 =~ $wholeNumber ]] ; then
set_flag 's/--debounce [0-9]*/--debounce '$3'/g'
else
echo -e "You must supply a ${CYAN}valid whole number${NONE} for $2"
fi
;;
"PULLDOWN")
case "$3" in
"TRUE")
if ! [[ $(grep "\-\-pulldown" /lib/systemd/system/gpionext.service) ]]; then
set_flag 's/^ExecStart=.*/& --pulldown/'
fi;;
"FALSE")
set_flag 's/[ ]*--pulldown//g'
;;
*)
echo -e "You must supply ${CYAN}TRUE${NONE} or ${CYAN}FALSE${NONE} for $2 option";;
esac
;;
"DEV")
case "$3" in
"TRUE")
if ! [[ $(grep "\-\-dev" /lib/systemd/system/gpionext.service) ]]; then
set_flag 's/^ExecStart=.*/& --dev/'
fi;;
"FALSE")
set_flag 's/[ ]*--dev//g'
;;
*)
echo -e "You must supply ${CYAN}TRUE${NONE} or ${CYAN}FALSE${NONE} for $2 option";;
esac
;;
"DEBUG")
case "$3" in
"TRUE")
if ! [[ $(grep "\-\-debug" /lib/systemd/system/gpionext.service) ]]; then
set_flag 's/^ExecStart=.*/& --debug/'
fi;;
"FALSE")
set_flag 's/[ ]*--debug//g'
;;
*)
echo -e "You must supply ${CYAN}TRUE${NONE} or ${CYAN}FALSE${NONE} for $2 option";;
esac
;;
*)
echo "Unrecognized Parameter: ${2}"
;;
esac
;;
*)
if ! [[ "$1" == "HELP" ]]; then
echo "Unrecognized Parameter: $1"
fi
echo "You can control the GPIOnext daemon using the following commands:
- gpionext start -> Enable + Start daemon
- gpionext stop -> Stop daemon until reboot or gpionext start is called
- gpionext reload -> Reload daemon
- gpionext config -> Run gpionext config
- gpionext disable -> Stop daemon/Disable auto-start on boot (type gpionext start to re-enable auto-start)
- gpionext journal -> Display any system output
- gpionext test [1-4] -> run jstest for gpionext virtual controller
-------------------------------------------------------------------------------------------------------------------------------
- gpionext set combo_delay [milliseconds] -> Delay in milliseconds to wait for additional buttons to be pressed for combos
- gpionext set debounce [milliseconds] -> Delay in milliseconds to wait to avoid multiple accidental presses
- gpionext set pins [default | pin numbers] -> default = all available pins or comma separated pin numbers (ex. 3,5,7,11,40)
- gpionext set pulldown [true | false] -> set pins to use pulldown resistors instead of pull up (excludes pins 3 + 5)
- gpionext set dev [true | false] -> output information to console while program in use (use 'gpionext journal' to view)
- gpionext set debug [true | false] -> output information to gpionext/logFile.txt
"
;;
esac
# set case match back to default
shopt -u nocasematch