Boxee + Wiimote = ♥

I’ve been using Boxee on my Linux system at home for several months now and I am really happy with it. However, one thing that is kind of a pain is having to get up and reach for the keyboard just to control Boxee. Ever since I got a Wii a month ago, I had resolved to correct this shortcoming and the recent upgrade to Ubuntu Intrepid seemed like a perfect time to dive in. So herewith are my short notes on how to control Boxee with a Wiimote!

The basic idea here is that the Wiimote communicates with the Wii console using bluetooth. So if your computer supports bluetooth, it can start talking to the Wiimote over bluetooth using some custom bits of software. Note that this does not involve the use of the Wii’s IR sensor bar. Leave that connected to your TV!

First thing you’ll need to do is to install a bunch of packages that enable interaction with the Wiimote.

$ sudo apt-get install wminput wmgui lswm

Once these packages are installed, run lswm to see if your Wii got detected.

$ lswm
Put Wiimotes in discoverable mode now (press 1+2)...

Follow the instructions and you should soon see lswm print out your Wiimote’s bluetooth MAC address. This would be something like 00:1E:35:09:9A:9A. If lswm exits before discovery is complete, just re-run it till you see the MAC address. Make note of the address.

Next, to verify that all the Wiimote button presses can be detected by your computer, run wmgui and use the File > Connect option to connect to the Wii. You may be asked to put the Wii in discoverable mode again. Once the Wiimote is connected, just press the buttons on your Wiimote & wmgui will show what buttons you pressed.

Now that this basic test procedure is done, we are ready to use the Wiimote as a mouse. This requires the use of a kernel module called uinput. Load it up:

$ sudo modprobe uinput

Now enable mouse mode by typing:

$ sudo wminput 00:1E:35:09:9A:9A

Take care to replace the bluetooth address in the above command with your own Wiimote’s address! With wminput running, you should be able to control the mouse (in a bizarre way) by tilting your Wiimote & pressing the A or B buttons. Once this works, hit Ctrl+C to exit wminput.

If you noticed, in the default mouse mode, the Wiimote’s A button was mapped to left click while the button B was mapped to right click. The wminput tools allows you to map the buttons in whatever manner suits you. We’ll setup a key mapping that makes sense to use with Boxee.

$ cd /etc/cwiid/wminput
$ sudo cp buttons boxee-buttons
$ sudo vim boxee-buttons

In the boxee-buttons file, you’ll find the default key mappings for the Wiimote as well as the Nunchuck & the Nintendo Classic controller. Ignore the latter two and replace the Wiimote’s key mapping lines with these:

#buttons
Wiimote.A       = KEY_KPENTER
Wiimote.B       = KEY_ESC
Wiimote.Up      = KEY_UP
Wiimote.Down    = KEY_DOWN
Wiimote.Left    = KEY_LEFT
Wiimote.Right   = KEY_RIGHT
Wiimote.Minus   = KEY_KPMINUS
Wiimote.Plus    = KEY_KPPLUS
Wiimote.Home    = KEY_H
Wiimote.1       = KEY_SPACE
Wiimote.2       = KEY_S

The above mapping should be obvious. You can get a list of supported key codes from the wminput source. With the mapping file in place, re-run wminput but specifying this custom mapping file.

$ sudo wminput -c boxee-buttons 00:1E:35:09:9A:9A

Once wminput is running, fire up Boxee and you should now be able to control it using your Wiimote!

It is time to make all these settings permanent. First, the loading of the kernel module is automated by adding the module name uinput to a new line at the end of the file /etc/modules

If you noticed, we were running wminput with superuser privileges. We’ll remedy this by adding a udev rule that lets any user in the plugdev group access the uinput module. Create a file (as root) named 50-cwiid-input.rules in the /etc/udev/rules.d directory with the following line in the file:

KERNEL=="uinput", GROUP="plugdev"

Typically, your user will be in the plugdev group. If not, replace the group with something else like admin, etc.

Finally, create a startup script that starts wminput when you log in to your X session. For KDE, this would mean creating a script in ~/.kde/Autostart

$ cd ~/.kde/Autostart
$ echo '#!/bin/sh' > wminput.sh
$ echo 'wminput -dc boxee-buttons 00:1E:35:09:9A:9A' >> wminput.sh
$ chmod +x wminput.sh

That’s it! Once you restart your computer, your Wiimote will be ready to use! If you find it’s not working, try putting it in discoverable mode and the already running wminput daemon will pick it up.

Have fun!