Using WiiMote’s with your AIR for Android Applications
NOTE: I use WiiMote app now instead of WiiController. I also use a Motorola Atrix and the WebTop app.
I demoed an application at my MAX session using 2 Wiimotes, a Droid X, and HDMI out to a TV. I am finally getting around to blog about the Wiimote and AIR Android setup. I have the code of the game I wrote for the demo, the art work was inspired by my 5 yr’s drawings. The code is actually quite simple to make this work but it takes some explaining on how to setup and how it works.
First here is a picture of the game and the two Wiimotes connected to the Droid X.
First thing is to understand Android’s support for Input Method Emulators (IME). The IME on Android is kind of like window’s IME where it supports different language input methods. On Android the IME’s are typically used for difference keyboard input methods, for example the Swype that comes with the Droid X is just another IME that is turned on by default over the default Android virtual keyboard. This leaves us with the question what does that have to do with Wiimotes?
What this means is a developer has created an Android application that uses Bluetooth to connect the Wiimotes and then translates the Wiimote button’s into actual keystrokes. The accelerometer on Wiimote is not supported as that produces more data then a simple keystroke.
Steps to setup the WiiControllerIME
- Enable and turn on Bluetooth on the Android device.
- Download and Install the WiimoteController application from Android marketplace.
- Launch WiimoteController application.
- Click on the 1 & 2 buttons on both Wiimotes, it supports up to 4. This put the Wiimotes into Bluetooth discovery mode.
- Then quickly while the wiimotes are blinking on the Android Wiimote Controller application click the “Init and Connect” Button. Give it 10-20 seconds for the Wiimotes to connect, which once they do, your should see some output text in the application like this image:
- Now you need to switch the IME to the WiimoteController application, the app provides a button to do this for you so you don’t have to go into the settings area to do it. Click on the Select WiiControllerIME button and then select the correct IME in the dialog.
- Now start the Eiden1 game and play with the arrow keys to move and 1&2 to swing the guys arms. Thats it, now all input for the Android application is coming from the Wiimotes.
What does it take to access the Wiimotes in your application?
Since Android’s IME just remaps inputs to keyboard events its pretty simple to access the data in your application. As a developer you just listen for keyboard events and figure out what keycodes each button is mapped to. In the case for 2 wiimotes (it can support up to 4) the button’s are mapped to different keycodes, ie: Wiimote 1 button 1 is mapped to X keycode and Wiimote 2 button 2 is mapped to Y keycode.
MAX Demo and HDMI out
For the MAX demo I also used a Real HDMI android application from the Android marketplace that is specific only for the Droid X. It allows for applications to be outputted through the HDMI out, where the built in app only supports images and videos. The demo was cool because it was basically like having a console in your pocket, where you can pull it out and play games on a TV with Wiimotes.
A few notes about this setup
- All keyboard events are coming from Wiimotes and you won’t be able to type into TextFields in your applications as the Wiimotes buttons are map to specific set of key inputs (which can be remapped in WiimoteController application’s settings).
- I didn’t find an easy way to turn off the Bluetooth pairing to key the Wiimotes from draining battery after doing the demo, so I just go and kill the WiimoteController application.
- The Droid X HDMI hack is specific to Droid X and an Android application that was pulled from the marketplace right before MAX. It looks like it might be back on the marketplace now, but beware it might be pulled. It’s called Real HDMI and made by gmanapps.
Like I mentioned in the first part of the post the source for the game I used is available on github pull down the source and read the README file as it requires a library that I used for multiple of my demos.