The WiiMote class allows you to access the WiiMote from SuperCollider, both to receive data from the device, as well as send data to the device.
This class has been developed to work both on the Mac and on Linux. The interface is mostly the same, but there are some usage issues on the Mac. Personally, I found that it works better with an external BlueTooth receiver, than with the internal one (tested on the MacBook Pro). I also found that on the Mac, I have to connect, disconnect and then reconnect to get everything to work properly.
The IR options, as well as the Classic controller have not been tested (due to lack of access to either complementary device by the developer).
This class is not implemented for Windows, and thus will not work on that platform.
Starts the eventloop. Called automatically by *discover, so no real need to call this method.
updtime |
updatetime of the eventloop in milliseconds. |
Discovers a new device. This calls for the creation of a new device and class instance by calling the method *new. ( new should not be called directly). This method is synchronous, and will block until a device is found or until it times out.
When discover is called, the buttons 1 and 2 on the Wii Remote should be pushed to put the device in discovery mode.
A new WiiMote object for the device discovered, or nil
if no device was discovered.
Example to start up:
w = WiiMote.discover; // discover a new device w.battery; // post the battery status of the device // cleanup: WiiMote.closeAll; // close all devices WiiMote.stop;
Returns an Array with all WiiMote devices.
Close all WiiMote devices.
Stops the eventloop. Only really necessary on Mac, but use it for cross platform robustness.
dump incoming events for debugging purposes.
Returns the device specification, with symbolic names for each item. Each name links to the current value.
Returns the device action specification, with symbolic names for each item. Each name in the dictionary links to an action to be performed upon receiving a new value.
Set an action to be performed when the device closes.
Set an action to be performed when the device connects.
Set an action to be performed when the device disconnects.
Get the value of a device property at the given key.
Set an action to be performed when the value of key changes. The key name must be one that occurs in the spec.
Remove the previously defined action at the key.
Close the device.
Returns the current battery status of the device.
Returns the extension type that is connected.
Returns an Array with the current button values.
Returns an Array with the current acceleration values (x,y,z, orientation). Orientation is Mac only.
Returns an Array with the found IR objects. (not tested!).
Returns an Array with the current LED values.
Set the LED with number id to value value (1=on, 0=off).
Turn on the rumble, value (1=on, 0=off).
Enable the device.
Enable the device expansion (nunchuk or classic controller).
Enable the buttons on the device.
Enable the motion sensor on the device.
Enable the IR sensor on the device.
Returns an Array with the current button values.
Returns an Array with the current acceleration values (x,y,z, orientation). Orientation is Mac only.
Returns an Array with the current stick values.
Returns an Array with the current button values.
Returns an Array with the current stick values of stick 1.
Returns an Array with the current stick values of stick 2.
Returns an Array with the current analog values.
// Example to start up and view values WiiMote.start; // start the eventloop w = WiiMote.discover; // discover a new device (wait for post about connected) WiiMote.all; // post an array of all devices x = WiiMoteGUI.new( w ); // create a GUI (only covers the WiiMote and NunChuk currently) w.enableMotionSensor( 1 ); w.enableExpansion( 1 ); w.setLEDState( 0,1 ); // turn the first LED on w.rumble( 1 ); // rumble the device w.rumble( 0 ); // rumble the device w.setAction( \bA, { |v| v.postln; } ); // post the value when button A changes. w.removeAction( \bA ); // (macOS) if you do not see any changes in the motion sensors, then the connection is bad. // push the red button inside the battery compartment, or the buttons 1 and 2 on the WiiMote and start over again to discover... WiiMote.discover; // discover a new device WiiMote.all; // post an array of all devices w = WiiMote.all[1]; x.w.close; // close previous window x = WiiMoteGUI.new( w ); // create a GUI (only covers the WiiMote and NunChuk currently) // now it should work..., if not, repeat the exercise... // clean up WiiMote.closeAll; // close all devices WiiMote.stop; x.w.close;
This example shows a window displaying the objects being tracked by the WiiMote IR camera.
( var q, w, u; q = WiiMote.discover; if(q.isNil) { "No wiimote found, aborting.".error; } { q.enableIRSensor(1); w = Window("IR sensor", Rect(100, 100, 400, 400)).front; w.onClose = { q.close }; u = UserView(w, Rect(0, 0, 400, 400)); u.background = Color.black; u.drawFunc = { var p; q.remote_ir.do {|ir, i| if(ir.valid>0) { p = Point(ir.posx*400, ir.posy*400); Pen.addArc(p, ir.size*500.0, 0, pi*2); Pen.fillColor = Color.hsv(i/5, 1, 1); Pen.fill; Pen.stringAtPoint( "% @ % %".format( ir.posx.round(0.01), ir.posy.round(0.01), (ir.size*1000).floor ), p, Font(Font.defaultSansFace, 9), Color.white ); }; }; }; u.animate = true; }; )