-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrollerPoller
More file actions
56 lines (49 loc) · 1.42 KB
/
Copy pathcontrollerPoller
File metadata and controls
56 lines (49 loc) · 1.42 KB
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
#!/bin/bash
#Replace MACs with those of your controller(s).
controller1=<MAC OF CONTROLLER #1>
controller2=<MAC OF CONTROLLER #2>
pythonPath="<PATH TO PYTHON SCRIPT>"
anyConnect="hcitool con | grep \"$controller1\|$controller2\" | grep \"state 1\" | wc -l"
counter=1
#try to connect to any controller if none are connected
#longest this will run is 55 seconds
while [ $(eval $anyConnect) -eq 0 ] && [ $counter -lt 6 ]
do
bluetoothctl -- connect $controller1
sleep 5
bluetoothctl -- connect $controller2
sleep 5
((counter++))
done
#If there is 1 controller connected, listen for the touchpad button to be pressed
if [ $(eval $anyConnect) -eq 1 ]
then
#check to see which controller is connected
oneConnect=$(hcitool con | grep "$controller1" | grep "state 1" | wc -l)
#check to see if already scanning for input, and if so kill the process
buttonPressProcID=$(ps -aelf | grep "python $pythonPath" | grep "poll_s")
array=($buttonPressProcID)
procID=$(eval echo ${array[@]:3:1})
if [ ! -z "$procID" ]
then
kill $procID
fi
#check for touchpad button press
buttonPress=$(python $pythonPath)
if [ $buttonPress -eq 1 ]
then
counter=1
#for next 15 seconds try to connect to other controller
while [ $(eval $anyConnect) -eq 1 ] && [ $counter -lt 4 ]
do
if [ $oneConnect -eq 1 ]
then
bluetoothctl -- connect $controller2
else
bluetoothctl -- connect $controller1
fi
sleep 5
((counter++))
done
fi
fi