[LINUX] HOW-TO enhance your emulation experience with Wii Classic Controllers
#1
Star 
Long time lurker, first time poster. I've pulled a lot of great information from this forum and since I haven't seen anything on emulation using a wii controller specifically, I thought maybe I could give back to the community. If a guide has already been written and I missed it, my apologies.

The specific system that I know this guide will work on is:
XBMC 10.1 (Dharma stable)
Ubuntu Lucid

I won't get into specific emulation setup, but I had relied heavily on this guide by Izod517.

Additionally, I'm set up with Angelscry's Advanced Launcher.

This setup will use wminput to convert controller button presses into key presses, which can then be used to trigger actions within the emulator as if that is how your emulator control input is laid out.

I'm not sure what (if any) complications will arise with the wii in standby mode. I made sure to turn mine off before pairing any wiimotes.

1. Acquire a Bluetooth dongle
Ok, first off, you're going to need bluetooth. Fortunately, it can be had for cheap. I'm using an ASUS USB-BT211 Mini USB Bluetooth V2.1 and there haven't been any problems. If you need one, go purchase one. Otherwise, we will get to it shortly, so you can set it aside for now.

2. Setup the uinput module
We need to use the uinput module, but my understanding is that recent linux distributions should have it already, it just might not be active (as was the case in Lucid for me). You can use modprobe to check to see if you have it available, and lsmod to see if it's active.

Code:
$ modprobe -l | grep uinput
kernel/drivers/input/misc/uinput.ko

If modprobe returns the kernel location for you, check to see if it's loaded.

Code:
$ lsmod | grep uinput
uinput                  6312  0

If it's loaded already, skip ahead to step 3. For me, it was available but not loading.

To get uinput to load automatically, we're going to add it to the "/etc/modules" file.

Code:
$ sudo nano /etc/modules

/etc/modules will look something like this:
Code:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

loop
lp

Add "uinput" to the end. Save and close.

3. Create a udev rule for the uinput device
In order to connect to the Wiimote as a regular user though, you need to add a new udev rule to extend permissions to the uinput device. You can create a new group for this or you can use a pre-existing one. The group plugdev should hopefully exist with your default xbmc user already attached, so that helps simplify things.

Just to make sure the group exists:
Code:
$ more /etc/group | grep plugdev
plugdev:x:46:xbmc

If you see "plugdev" with "xbmc" (or whatever your default group is called) at the end of the line you're in good shape.

Create the new udev file:
Code:
$ sudo touch /etc/udev/rules.d/95-uinput.rules

Edit that file and add the following line:
Code:
KERNEL=="uinput", GROUP="plugdev"

At this point you may need to reboot to make sure uinput is loaded and that it's using the new udev rules. Alternatively, I *think* running modprobe on uinput and reloading udev will accomplish what we need. I can't say for certain because I had a couple reboots in there before I eventually moved onto the next step.

Code:
$ modprobe uinput
$ sudo reload udev

4. Install wminput
Now it's time to install wminput.

Code:
$ sudo apt-get update
$ sudo apt-get install wminput

5. Setup Bluetooth
Plug in your dongle and install bluez and some python.

Code:
$ sudo apt-get install bluez python-gobject python-dbus

At this point your bluetooth should be working. Double check with hcitool dev.

Code:
$ hcitool dev
Devices:
     hci0    00:11:95:00:1A:CF

If all is good, you'll see "hciX" followed by the address of the dongle.

For more confirmation that everything is working, we can now find the address of the wiimote. Run hcitool scan and then press buttons 1+2 on the wiimote to put it into discoverable mode:

Code:
$ hcitool scan
Scanning ...
     E0:E7:51:A0:A9:94       Nintendo RVL-CNT-01

At this point you should be able to connect your wiimote and use it as a mouse. Test that by running wminput.

Code:
$ sudo wminput
Put Wiimote in discoverable mode now (press 1+2)...
Ready.

Now, if you're like me, you're pretty giddy because tilting the wiimote is causing the mouse pointer to move across the screen. Take a deep breath and relax, because it only gets better from here.

6. Install lswm
Running "lswm" while the wiimote is in discoverable mode will return the wiimote's address, similar to "hcitool scan". The difference is that "lswm" will only return the address and not "Nintendo RVL...". This will be useful for our launch script.

Code:
$ sudo apt-get install lswm

7. Update /etc/sudoers so that wminput can be run without entering a password
wminput needs to be run as root, which is fine if you plan on connecting your wiimotes from a terminal every time. Once we get around having to enter a password to run wminput we can make a simple "connect wiimote" script that can be initiated from within XBMC via Advanced Launcher. To do this, we have to edit the "/etc/sudoers" file.

Code:
$ sudo visudo

Scroll down to the end and add the following line. Replace "xbmc" with your user name (if you didn't set it up as xbmc).

Code:
%xbmc ALL=NOPASSWD: /usr/bin/wminput

8. Create wminput configure files
Make a directory structure in your home directory for ".cwiid/wminput". And within that "wminput" directory, you'll make a configuration file for player1 and player2.

Code:
$ mkdir -p ~/.cwiid/wminput
$ touch ~/.cwiid/wminput/buttons-player1
$ touch ~/.cwiid/wminput/buttons-player2

The "buttons-player1" and "buttons-player2" files will contain the key mappings for your wiimote and classic controller and should look something like this:

buttons-player1
Code:
Plugin.led.Led1 = 1

Wiimote.A      = KEY_ENTER
Wiimote.B      = KEY_BACKSPACE
Wiimote.Up      = KEY_UP
Wiimote.Down    = KEY_DOWN
Wiimote.Left    = KEY_LEFT
Wiimote.Right   = KEY_RIGHT
Wiimote.Minus   = KEY_BACKSPACE
Wiimote.Plus    = KEY_ENTER
#Wiimote.Home
#Wiimote.1
#Wiimote.2

Classic.Up      = KEY_A
Classic.Down    = KEY_B
Classic.Left    = KEY_C
Classic.Right   = KEY_D
Classic.Minus   = KEY_E
Classic.Plus    = KEY_F
Classic.Home    = KEY_ESC
Classic.A       = KEY_G
Classic.B       = KEY_H
Classic.X       = KEY_I
Classic.Y       = KEY_J
Classic.L       = KEY_K
Classic.R       = KEY_L
Classic.ZL      = KEY_M
Classic.ZR      = KEY_N

buttons-player2
Code:
Plugin.led.Led2 = 1

Wiimote.A      = KEY_ENTER
Wiimote.B      = KEY_BACKSPACE
Wiimote.Up      = KEY_UP
Wiimote.Down    = KEY_DOWN
Wiimote.Left    = KEY_LEFT
Wiimote.Right   = KEY_RIGHT
Wiimote.Minus   = KEY_BACKSPACE
Wiimote.Plus    = KEY_ENTER
#Wiimote.Home
#Wiimote.1
#Wiimote.2

Classic.Up      = KEY_O
Classic.Down    = KEY_P
Classic.Left    = KEY_Q
Classic.Right   = KEY_R
Classic.Minus   = KEY_S
Classic.Plus    = KEY_T
Classic.Home    = KEY_ESC
Classic.A       = KEY_U
Classic.B       = KEY_V
Classic.X       = KEY_W
Classic.Y       = KEY_X
Classic.L       = KEY_Y
Classic.R       = KEY_Z
Classic.ZL      = KEY_9
Classic.ZR      = KEY_0

What I chose to do here was rather than map out the d-pad as wsad and the buttons as something like buttonB=o buttonA=p, I simply mapped player1's buttons to letters A-N and player2's buttons to O-Z (plus 9 and 0). This just makes it easier to keep track of which ones have been used.

Also, the wiimote itself will be used to navigate within XBMC and the classic controller 'home' button is mapped to the escape key for the added bonus of exiting the emulator.

8. Update the emulator configure files with the new keyboard input layout

For mednafen it'll be found in ~/.mednafen/mednafen.cfg

For zsnes it's in ~/zsnes/zinput.cfg

9. Create script(s) to connect the wiimote(s)
You can make this step a little more complex if you like and write a script that takes arguments which you can pass into a launcher so that one script will connect multiple wiimotes. Or you can make a shell script for each wiimote and be done with it. (remember to make it executable)

Something like this:
Code:
#!/bin/bash
sudo /usr/bin/wminput -w -c ~/.cwiid/wminput/buttons-player1 $(lswm) &

Here we capture the output from "lswm" which returns the address for the current wiimote in discoverable mode which is then associated with the buttons-player1 config file.



And there you have it. A wiimote to navigate XBMC and a classic controller to control your emulators. When you're done, you can power off the wiimote to close wminput.


References
wminput docs
wminput.list (doc link is broken)
How-to on wiimote install/config for linux
How-to wiimote in ubuntu
Ubuntu bluetooth installation
Reply


Messages In This Thread
[LINUX] HOW-TO enhance your emulation experience with Wii Classic Controllers - by MooseTracks - 2011-10-20, 21:12
[No subject] - by MooseTracks - 2011-10-20, 22:01
[No subject] - by Vietomatic - 2011-10-23, 20:19
[No subject] - by MooseTracks - 2011-10-24, 04:52
[No subject] - by Vietomatic - 2011-10-28, 01:14
[No subject] - by MooseTracks - 2011-10-28, 01:43
[No subject] - by Vietomatic - 2011-10-28, 02:13
[No subject] - by MooseTracks - 2011-10-28, 02:20
[No subject] - by Vietomatic - 2011-10-28, 02:44
[No subject] - by Vietomatic - 2011-10-28, 02:46
[No subject] - by MooseTracks - 2011-10-28, 03:43
[No subject] - by Vietomatic - 2011-10-28, 06:13
Logout Mark Read Team Forum Stats Members Help
[LINUX] HOW-TO enhance your emulation experience with Wii Classic Controllers0