perjantai 14. kesäkuuta 2013

Using Wiimote as mouse

I have wanted to use my Wiimotes with my HTPC since they would be great for things like point-and-shoot games etc. Maybe for media center too, but I haven't tried that yet.

Anyways, there are multiple tutorials on the net for getting wiimote to work, like CWiiD tutorial on Ubuntu wiki or XWiimote tutorial on Arch wiki.

Basically, this is how I understood, CWiiD is the older driver which is no longer developed and XWiimote is the newer one which behaves better.

XWiimote has driver for xorg and you pair the Wiimote just like any other bluetooth device. So it should be the method of choice. However, it does not yet support the IR pointer which I want to use. So until that it's a no-go.

CWiiD requires an user-space application which handles the Wiimote communication, and an evdev driver (some generic driver I think) communicates with xorg. CWiiD has IR-pointer support, and after few days of messing around, I got it to work.

First, I installed the necessary packages: bluetooth which installed bluez and wminput. Those installed all other libraries etc that were needed.

Then running wminput -c ir_ptr -w and pressing 1+2 on the Wiimote connected the mote and everything worked, except for the IR pointer. After reading xorg.log and browsing around the net I found the solution.

Problem is that the driver reports both relative and absolute movement, and ir pointer uses absolute which was discarded for some reason. Also, as the driver is loaded runtime using udev and everything, normal configs added to xorg.conf do not work. I worked around this by creating a new input class config for evdev; /usr/share/X11/xorg.conf.d/61-evdev-wiimote.conf which contains following:


Section "InputClass"
 Identifier "Nintendo Wiimote"
 MatchProduct "Nintendo Wiimote"
 MatchDevicePath "/dev/input/event*"
 Driver  "evdev"
 Option  "IgnoreAbsoluteAxes" "false"
 Option  "IgnoreRelativeAxes" "true"
EndSection

This forces xorg to use the reported absolute pointer location (IR pointer) instead of relative location (acceleration sensors etc), so now the pointer works. Only missing is a proper IR source, but a flashlight works fine until then.

Also one should note that the ir_ptr config is located in /etc/cwiid/wminput/ and from there the button and axis mappings can be changed.

Hopefully this helps others too, it took quite a while to figure that input class thing out.