Saturday, August 08, 2009

Wiimote on Ubuntu 8.10
















Been a while - forgot I even *had* a blog ;)

Anyway, I decided that packing boxes required music. Since my laptop (Vostro 1500) has bluetooth, and I have Wiimote handy I decided that it was time to hook up the Wiimote as a remote control.

A few details on the setup:
- I'm using XFCE (Gnome is really getting on my nerves lately!)
- My preferred media player is Amarok
- I've already set up the multimedia keys on the front of the laptop, which saved me a step in getting the Wiimote working.

OK - first things first. I already had cwiid installed - you need to install this first. Google around :) Next, I added a udev rule:
KERNEL=="uinput", GROUP="uinput"
I put mine in /etc/udev/rules.d/91-uinput-cr33.rules

Next, I added a group 'uinput' and added myself and root to the group.

Then I restarted udev - which was a mistake ;) Better to reboot (unless of course you LIKE watching Xorg barf over and over...).

At this point, I was able to run the command 'wmgui' and connect to the Wiimote. So far, so good - pressing buttons lights up the wmgui interface. Killed wmgui.

Now - the tricky part: getting the buttons to control Amarok. Like I said above, I already had the media keys on the front of the laptop working. IIRC, in Applications->Settings->Settings Manager, I went to the Keyboard settings, then the Shortcuts tab. I don't remember exactly where I got the keycodes (maybe 'showkey -k' on VT1), but my shortcuts look like:
amarok XF86AudioMedia
aumix -v0 XF86AudioMute (similar for volume up/down)
dcop amarok player next XF86AudioNext (similar for other playback buttons - note the use of dcop)

So, with that already set up, all I needed was a conf file for wminput. Easy right? not so much - I finally found a list of all keys for wminput in the source code, then matched them up to the keycodes given by 'showkey -k': http://abstrakraft.org/cwiid/browser/trunk/wminput/action_enum.txt

Once I had my amarok.conf file, I started wminput thusly:
wminput -w -c /home/cr33/amarok.conf

So my amarok.conf ended up looking like this:
#acc_ptr

Wiimote.A = KEY_PLAYPAUSE
Wiimote.B = KEY_STOPCD
Wiimote.Up = KEY_VOLUMEUP
Wiimote.Down = KEY_VOLUMEDOWN
Wiimote.Left = KEY_LEFT
Wiimote.Right = KEY_RIGHT
Wiimote.Minus = KEY_PREVIOUSSONG
Wiimote.Plus = KEY_NEXTSONG
Wiimote.Home = KEY_MEDIA
Wiimote.1 = KEY_MUTE
#Wiimote.2 = KEY_MUTE

#Plugin.led.Battery = 1
Plugin.led.Button = BTN_2

#Plugin.acc.X = REL_X
#Plugin.acc.Y = REL_Y
Notice that #acc_ptr is commented out - this keeps the Wiimote tilt from affecting the pointer position. I also ended up commenting out Button 2 - as you can see, I've installed the nifty led plugin, which can be found here:
http://abstrakraft.org/cwiid/attachment/ticket/65/led.py
It needs to go into ~/.cwiid/plugins (note the lowercase cwiid - some of the docs are wrong)


I edited the plugin on lines 9-10 to look like:
Battery = 1
Button = cwiid.BTN_2
That's probably wrong - since I get an error on starting wminput: "Invalid plugin button: led.Button". Oh well - it works though. Pressing Button 2 on the Wiimote shows me how much battery charge is left.

Anyway, that's a wrap. I just wanted to document this, since it look longer to get this working than it should have :)

Image courtesy of: http://nand-magazine.net

No comments: