-
Notifications
You must be signed in to change notification settings - Fork 34
/
xwiibind.sh
executable file
·134 lines (119 loc) · 4.84 KB
/
xwiibind.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
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
#!/bin/sh
#
# XWiimote - tools
# Written 2011-2013 by David Herrmann
# Dedicated to the Public Domain
#
# Modified very slightly by Ryan Myers to clarify instructions for a Wiiboard
# and automatically trust the device so it can
# reconnect with no user interaction.
#
# This script enables auto-reconnect on your wiimote. This script should only be
# used if you really require auto-reconnect now. There is work going on to get
# auto-reconnect of wiimotes into upstream bluez repository.
# If you need this feature now, you may read below, but be aware that this
# method described here is neither fast nor reliable. It is a small hack to get
# it work.
#
# Please specify your device bdaddr as first argument to this script.
#
# To run this tool, you need:
# - "simple-agent"
# - "test-device"
# - "test-input"
# from the "test" directory of the bluez distribution. They are available here:
# http://git.kernel.org/?p=bluetooth/bluez.git;a=tree;f=test
# They are GPL licensed and hence not included here. They are simple python
# scripts and can be just copied into this directory.
# The scripts uses "bluez-" as default prefix for these tools. You can pass
# another prefix as second argument to overwrite this.
# You can also specify BIN_TESTINP, BIN_TESTDEV, BIN_SIMPLEA as environment
# variables with the absolute/relative path to the given binaries. The prefix
# will not be applied in this case.
#
# The python scripts need "python2" and are not python3 compatible, so specify
# the python interpreter as "PYTHON" below if the default value does not work.
# Or pass PYTHON="<path>" as environment variable.
#
# This script REQUIRES that you have the "wiimote.so" plugin enabled in your
# bluetoothd daemon. It is often NOT part of the official distribution package
# so check whether it is installed and enabled.
#
# Please disable gnome-bluetooth, blueman or any similar bluetooth applet to
# avoid inter-process conflicts.
#
# This script does not check for error codes, so if you see errors, abort the
# script with ctrl+c. This script first removes the device. Then it connects to
# the device without pairing and without connecting to the input service. It
# does this just to retrieve SDP values. After that you should disconnect the
# device again by pressing the power-button for 3 seconds.
# Then press the red-sync button again, the script will now connect to the
# device and perform pairing. If the script asks you for PIN input, then you did
# not install the "wiimote.so" plugin for bluetoothd.
# If you did, bluetoothd chooses the right PIN for you. After pairing it
# directly connects to the input device. If this succeeds, the wiimote is ready
# for auto-reconnect.
#
# To test auto-reconnect, disconnect your wiimote. Then invoke
# "python2 ./simple-agent"
# And you will have an agent that listens for incoming connections. Now a single
# key-press on the remote should be enough to make the wiimote connect to your
# host. You only need to acknowledge the connection in the simple-agent by
# writing "yes" when it prompts you.
#
# pass PYTHON=xy to overwrite this
if test "x$PYTHON" = "x" ; then
PYTHON="python2"
fi
# first argument is bdaddr
DEV="$1"
if test "x$1" = "x" ; then
echo "Please specify bdaddr of wiimote as first argument"
exit 1
fi
# optional second argument is binary prefix (default: "bluez-")
PREFIX="bluez-"
if test $# -gt 1 ; then
PREFIX="$2"
fi
# Pass BIN_TESTDEV=test-device, BIN_SIMPLEA=simple-agent, BIN_TESTINP=test-input
# to overwrite the "which" statements.
ERR=0
if test "x$BIN_TESTDEV" = "x" ; then
BIN_TESTDEV=`which "${PREFIX}test-device" 2>/dev/null`
ERR=$(($ERR + $?))
fi
if test "x$BIN_SIMPLEA" = "x" ; then
BIN_SIMPLEA=`which "${PREFIX}simple-agent" 2>/dev/null`
ERR=$(($ERR + $?))
fi
if test "x$BIN_TESTINP" = "x" ; then
BIN_TESTINP=`which "${PREFIX}test-input" 2>/dev/null`
ERR=$(($ERR + $?))
fi
if test ! "x$ERR" = "x0" ; then
echo "Cannot find bluez '${PREFIX}test-device', '${PREFIX}simple-agent' or '${PREFIX}test-input' scripts"
exit 1
fi
echo "Removing device..."
"$PYTHON" "$BIN_TESTDEV" remove "$DEV"
echo "Device removed, press any key to continue"
read tmp
echo "Please press red sync-button on the back of the wiimote and press any key
to continue"
echo "If this asks you for PIN input, then your bluetoothd daemon does not
include the wiimote.so plugin. Please install it or contact your distributor."
read tmp
"$PYTHON" "$BIN_TESTDEV" create "$DEV"
echo "Please disconnect the device by removing a battery and then press
any key to continue"
read tmp
echo "Now press the red-sync button again and press any key to continue"
read tmp
echo "Pairing with the remote device..."
"$PYTHON" "$BIN_SIMPLEA" "hci0" "$DEV"
echo "Connecting to input device..."
"$PYTHON" "$BIN_TESTINP" connect "$DEV"
echo "Trusting the remote device..."
"$PYTHON" "$BIN_TESTDEV" trusted "$DEV" yes
echo "Connected to input device. Autoconnect should be enabled now."