Hi all,

I've been playing around with the Wii Remote (wiimote) under Linux.  The Wii
Remote is a Bluetooth device and some people (not me) at wiili.org have
figured out some of the specifics of how to talk to the thing.  Their sample
code lets you use the Wii Remote as a pointer, map the buttons to keyboard
buttons via xlib, and so on.

Their sample code is also written in Python, which means it was trivial to
code up a simple Wii Pong game in Pygame (which I did this afternoon :))

However, the sample code is a bit... hackish, and doesn't really work well
within the Pygame paradigm.  So I'm thinking of working on adding proper Wii
Remote support to pygame, as another type of input device, similar to
pygame.mouse and pygame.joystick.  For now I am simply writing my own Python
module, but I'm trying to make the interface match the usual Pygame device
interface so that, once it's stable, it can hopefully be dropped in to
Pygame directly (sometime after 1.8).

Here's the most interesting stuff that the Wii Remote reports:

1) Accelerations in x, y, and z (at around 100 Hz)

2) Status of all 11 buttons (4 for the D-Pad, A, B, 1, 2, +, -, and Home)

3) "Dots" sensed by the IR sensor (there is a sensor bar with two IR
emitters placed a known distance apart)

So it can't really be handled as an ordinary keyboard/mouse/joystick device;
it's more like a 3-axis mouse (the accelerometer readings) combined with a
joystick (the buttons) and another 2-axis mouse (the screen position pointed
to, determined by looking at the sensor-bar dots).

It also needs its own module just because we talk to it completely
differently than a normal keyboard/joystick... we have to have a bluetooth
socket around to send and receive control/data packets, for example.

So here is my rough proposal:

* New pygame.wiimote module.  The init() function isn't called by normal
pygame.init(), because pygame.wiimote depends on the Python bluetooth
module, which is not standard.  So you have to init() wiimote manually to
get Wiimote support.  (The bluetooth module won't be loaded until init() is
called, so Pygame as a whole will not depend on the bluetooth module, unless
a game specifically requests wiimote support).

* Similar interface as joystick for setting up the Wiimotes, with
wiimote.get_count() (which will have to discover them via bluetooth) and a
constructor, pygame.wiimote.Wiimote(id), that initializes a single Wiimote.

* get_* methods in the Wiimote object for polling

* New event types in pygame.event for event-based operation

* Actually generating these events on the event queue when needed

I welcome any comments or suggestions :)

At the moment I am concentrating my efforts on the Linux platform, but
expect to make a cross-platform compatability layer for Windows (and maybe
Mac) once the initial effort is off the ground.

Thanks,
robomancer

Reply via email to