forked from gizmo98/sixad
-
Notifications
You must be signed in to change notification settings - Fork 22
/
sixad
executable file
·192 lines (161 loc) · 3.64 KB
/
sixad
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
# sixad-bin wrapper
# written by falkTX
# modified by Dark-Show
DEBUG=0
LEGACY=0
. /etc/default/sixad
bt_device_checkr() {
if (! hciconfig dev &> /dev/null); then
return 0;
fi
return 1;
}
bt_device_check () {
if (which hciconfig > /dev/null); then
while (! hciconfig dev &> /dev/null); do
echo "No bluetooth adapters found on the system; will try again in 1 second."
sleep 1;
done
VER=`hciconfig default version | grep "HCI Ver" | awk '{print$3}'`
if [ "$VER" == "1.1" ]; then
echo "***** NOTICE *****"
echo "You're using a very old bluetooth dongle,"
echo "the Sixaxis will not work properly!"
elif [ "$VER" == "1.0" ]; then
echo "***** WARNING *****"
echo "You're using a _really_ old bluetooth dongle,"
echo "the Sixaxis will just not work!"
fi
bt_device_enable
fi
}
bt_device_enable () {
bt_device_up
bt_device_pscan
}
bt_device_up () {
hciconfig hci0 up
}
bt_device_pscan () {
hciconfig hci0 pscan
}
sixad_running_check () {
ps -e | grep sixad-bin > /dev/null
}
isroot_check () {
# check, if sudo is used
if [[ $(id -u) -ne 0 ]]; then
echo "Script must be run as root. Try 'sudo $0'"
exit 1
fi
}
bt_start () {
systemctl enable bluetooth 2>/dev/null
systemctl --no-block restart bluetooth
}
bt_stop () {
systemctl disable bluetooth 2>/dev/null
systemctl --no-block stop bluetooth
}
bt_start_and_stop () {
bt_start
bt_stop
}
sixad_watchdog (){
echo "Watching... (5s)"
while (true); do
if (bt_device_checkr); then
echo "Watchdog: Bluetooth disconnected, killing sixad."
pkill -KILL sixad-sixaxis
pkill -KILL sixad-remote
pkill -TERM sixad-bin
break
fi
if (hciconfig hci0 | grep "DOWN" &> /dev/null); then
echo "Watchdog: hci0 down, re-enabling."
bt_device_up
fi
if ! (hciconfig hci0 | grep "PSCAN" &> /dev/null); then
echo "Watchdog: PSCAN not set, resetting."
bt_device_pscan
fi
sleep 5;
done
sixad_start
}
sixad_start () {
bt_device_check
bt_start_and_stop
/usr/sbin/sixad-bin $DEBUG $LEGACY $REMOTE &
bt_device_enable
sixad_watchdog
}
case $1 in
--start|-start|start|-s)
isroot_check
#boot error fix attempt.
REMOTE=0
bt_device_check
if (sixad_running_check); then
echo "sixad is already running."
echo "run '$0 --stop' to stop it"
else
sixad_start
fi
;;
--stop|-stop|stop)
isroot_check
pkill -KILL sixad-sixaxis
pkill -KILL sixad-remote
pkill -TERM sixad-bin
bt_start
# rely on systemd to terminate remaining processes
# to avoid unnecessary failed service status
if ! service sixad status >/dev/null; then
sleep 1
pkill -TERM sixad
fi
;;
--remote|-remote|remote)
isroot_check
REMOTE=1
bt_device_check
bt_start_and_stop
/usr/sbin/sixad-bin $DEBUG $LEGACY $REMOTE
env sleep 2
sixad_watchdog
;;
--restore|-restore|restore|-r)
isroot_check
bt_start 2>/dev/null
;;
--boot-yes)
isroot_check
systemctl enable sixad 2>/dev/null
;;
--boot-no)
isroot_check
systemctl disable sixad 2>/dev/null
;;
--help|-help|help|-h)
echo "[Qt]SixA Daemon"
$0
;;
--version|-version|version|-v)
echo "[Qt]SixA Daemon - version 1.5.1"
;;
*)
echo "usage: $0 <command>
command can be:
-h, --help Show help (this message)
-v, --version Show sixad version
-s, --start Start sixad
--stop Stop sixad
--remote BD Remote mode
-r, --restore Restore regular bluetooth
--boot-yes Auto-starts sixad at boot time
--boot-no Does not auto-start sixad at boot time
You can also check: sixad-raw, sixad-notify"
;;
esac