Monday, August 6th, 2007
The Wii Remote API: Now your userbase is four.
The Opera folk have released an API that allows you, the developer, to be able to monitor all of the remotes that are connected with The Wii Remote API.
This means that you can watch up to four people buzzing around the screen:
Polling the status of a remote
The Wii Remote data is accessed through the opera.wiiremote object. This object offers a single method opera.wiiremote.update(n) which is used to obtain the status of an individual Wii Remote. The method expects a single parameter; the Wii Remote number. The number is zero-based, so it starts at 0 for the first remote, and ends at 3 for the fourth remote. The method returns a KpadStatus object, which has several properties that give information about the remote.
This update method can be called as often as is needed to obtain a fluid response, but note that the Wii is not as powerful as most desktop computers, so it is important to make sure that it is polled only as often as the script that uses that data can process it. For example, if a script uses the Wii Remote status to update the display of a canvas element, and that update will take perhaps 50 ms to update in Opera on a desktop computer, it may take over 100 ms on a Wii. Attempting to use a polling interval of less than 100 ms will cause the response to appear very sluggish.
Note that the opera.wiiremote object only exists in Opera on Wii, so it is important to check for its existence, as well as the existence of the opera object, before attempting to use it.
Examples
-
-
//Obtaining the roll of the third Wii remote in degrees
-
-
var remote, roll = 0;
-
//check if the browser provides access to the Wii Remote data
-
if( window.opera && opera.wiiremote ) {
-
//get the KpadStatus object for the third Wii Remote
-
remote = opera.wiiremote.update(2);
-
//check that the remote is enabled
-
if( remote.isEnabled ) {
-
//get the roll angle in radians
-
roll = Math.atan2( remote.dpdRollY, remote.dpdRollX );
-
//convert the roll to degrees
-
roll = roll * ( 180 / Math.PI );
-
}
-
}
-
-
// Checking what buttons are pressed on the second remote
-
var remote, buttons = {};
-
//check if the browser provides access to the Wii Remote data
-
if( window.opera && opera.wiiremote ) {
-
//get the KpadStatus object for the third Wii Remote
-
remote = opera.wiiremote.update(1);
-
//check that the remote is enabled
-
if( remote.isEnabled ) {
-
//use the bitwise AND operator to compare against the bitmasks
-
buttons.pressedLeft = remote.hold & 1;
-
buttons.pressedRight = remote.hold & 2;
-
buttons.pressedDown = remote.hold & 4;
-
buttons.pressedUp = remote.hold & 8;
-
buttons.pressedPlus = remote.hold & 16;
-
buttons.pressed2 = remote.hold & 256;
-
buttons.pressed1 = remote.hold & 512;
-
buttons.pressedB = remote.hold & 1024;
-
buttons.pressedA = remote.hold & 2048;
-
buttons.pressedMinus = remote.hold & 4096;
-
buttons.pressedZ = remote.hold & 8192;
-
buttons.pressedC = remote.hold & 16384;
-
}
-
}
-
There are a bunch of demonstrations, including a simple game.
I can't wait to see the Star Wars light sabre web game... and then see a Comet based app that grows beyond the four connected devices!












…that is so freakin cool… awesome
can’t wait to test it ^^
Why polling? Why not defining event handlers? Sounds very lame for me. While these news are cool news, the situation is a bit strange for me…
I hope this works!
Ya as ‘András Bártházi’ said, why polling?
sudhir
jYog.com
The real problem is there is no information about the accelerometers. Not sure why opera exposed the other things. Detecting the remotes motion is what would be useful in an online game. Hopefully that will be released in the near future.
Ryan
There is even the roll vale, looks interesting.
The accelerometer info is not so easy to handle, you need a quite complex code to correctly parse them, perhaps too much for a javascript code.
András, the problem with events in this case is that even with the Wiimote just lying on a table, the values for for instance dpdRollX and dpdRollY will continously change, in which case raising events don’t make much sense. Since you have to poll anyway, you can just as well do that for the buttons too. If you do want events, you can do this yourself, as is being done in this library.
polling is less resource consuming than event triggering. This must be why they implemeted it so on a hardware that’s no so powerfull as a classic computer.
Arve, gizmo: thanks for the answer. After my message I was wondering about the same thing, this solution was quite strange. However, keep up your great work!
Is it just me or they removed the article, when I try the link it tells me access is denied, even when I’m logged in.
Shameless Plus:
Wii Opera SDK - http://hullbreachonline.com/wii/sdk.html
Great stuff!
While trying it out I noticed that it only can get a roll value when the remote cursor is on the screen. Does anyone know why this is?