Interacting with your Haskell Games using the Wiimote
Quite recently we have been focusing our attention on using new input devices in Haskell games. Wiimotes have many sensors, they are very cheap, and people have been hacking them for a long time.
Sadly enough, until just a few weeks ago, wiimotes enjoyed very limited support in Haskell: only the basic buttons, some leds and rumbling were supported.
We are happy to announce that a new version of Hcwiid, 0.0.5, has been released, and the following new features are available:
Infrared support. This is essential if you want to use the sensor bar, which provides more accurate (absolute) pointing.
Accelerometer support. This can be used to detect how fast the wiimote is being moved (and also the gravity vector).
Improved API. The last version covered only a limited subset of cwiid. The new version, although it does not export all of cwiid, provides access to all the key features.
Documentation. An effort is being made to provide not only haddock documentation, but also several tests that demonstrate the features of this library.
But what the heck is a wiimote?!!!
A wiimote (forearm and hand not included in the package)
A wiimote is a very neat input device that accompanies Nintendo’s Wii console. It has buttons, accelerometers, an IR camera, a rumbler, a (tiny) loudspeaker, led indicators, and an expansion port. It communicates using bluetooth, and it runs on good-old AA batteries.
It often comes with a sensor bar, which projects two IR dots at a known, fixed distance from one another. This can be used to calculate the position of the player with respect to the TV, and also to know what the wiimote is pointing at.
Neat! What can you do with the wiimote?
Johnny Lee demonstrates realistic 3D screens using a wiimote to track people.
The wiimote is very cool. Among the most amazing projects that use the wii, apart from Wii games, are Johnny Chung Lee’s projects (http://johnnylee.net/projects/wii/, a TED talk here: http://www.ted.com/talks/johnny_lee_demos_wii_remote_hacks). There are many possibilities, and you can combine several wiimotes to do more things. Also, even though the sensor bar only has two leds, you can add another extra 2 IR sources.
How can you possibly use it in Haskell? Can Haskell run on the Wii? How long have I been asleep?
The answers to those questions are “I don’t know”, “No”, and “For 3 years now”. But not in that order.
The wiimote communicates with the Wii using bluetooth. It turns out that there are several free (in all senses) userspace drivers that enable communication with the Wiimote. One such library is cwiid, for which a haskell binding has existed since 2011. (And you haven’t been asleep for 3 years, and as far as I know, you cannot compile Haskell code for the Wii, but I would love to be proven wrong.)
The haskell bindings of that library can be installed using cabal and the library is called hcwiid. The hackage package can be found here.
What does the library support? What can I do with it?
Hcwiid supports the following features:
The interface is really tiny. Even though cwiid is low-level, effort has been made to provide additional functions that enable compile-time type checks and higher-level functions.
If you want to see an example, you should take a look at this test. It’s only 10 lines long.
Which features are not supported yet?
A wiimote with a nunchuck connected to it. I have no idea what to use it for.
Nunchucks, speaker, wiimote plus, reading and writing data from the wiimote’s memory are not yet supported. However, this might change in the near future. If you want to get up to date information, you should check the github repo or the hackage page (and the changelog).
Multiple wiimotes should be supported but I have not tried it yet. It you try it, please let me know how it works.
Is this stable? Can it be realistically used in games?
I am not selling anything here, so me (or Keera Studios) cannot be held responsible for any failures. That being said, in my opinion this is more than ready. We are already using all the supported features in a game that will be published in the near future.
Oh! There’s going to be a game? What kind of game?
A classic, revisited. Details will come when they come. The best thing you can do is follow us on facebook and twitter. You’ll get frequent updates (everything we publish is related to FP, gaming and/or Haskell).
I like what you do. Is there any way I can help?
Sure. There are many ways you can help. Here are a few suggestions:
Try the library. Write a haskell game with it. Share it with the community.
Improve the library, its documentation, and support for untested features. Submit a pull request.
Follow us on twitter and facebook. Star/follow us on github (my profile). Read our blog. Tell your friends to do the same. Public awareness is key when you are doing something so special, something no one has ever done before. You’ll be helping us more than you think.
Donate money so that we can create and publish free (as in beer & freedom) games and maintain haskell libraries.
Try other programs and libraries we have created (including Keera Posture, Keera Hails, and the game when it’s published).
What will you be doing next?
Apart from the game we are writing, we are also experimenting with Kinect, joysticks and other (much cooler) input devices. Our game will give users the choice of using several kinds of input controllers.
Also, we are using (and trying to improve upon) existing FRP and non-FRP reactive frameworks (Yampa, keera hails), both for games and for GUI programming. Well be publishing improvements to both frameworks (I am the official maintainer of both).
Questions? Comments? A pat on the back?
Please, leave your comments below. If you can’t get through the anti-spam system, let me know (email me at ivan dot perez at keera dot co dot uk).