2 summary:: use the Nintendo (tm) Wii Remote
3 related:: Classes/GeneralHID
4 categories:: External Control
7 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.
9 subsection::Some Important Issues Regarding WiiMote
11 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.
12 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.
14 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).
18 private::initClass, prStart, prStop, prDiscover
22 Should not be called directly. See link::#*discover::.
26 Starts the eventloop. Called automatically by link::#*discover::, so no real need to call this method.
29 updatetime of the eventloop in milliseconds.
32 Discovers a new device. This calls for the creation of a new device and class instance by calling the method link::#*new::. ( strong::new:: should not be called directly). This method is synchronous, and will block until a device is found or until it times out.
34 When discover is called, the buttons 1 and 2 on the Wii Remote should be pushed to put the device in discovery mode.
36 returns:: A new WiiMote object for the device discovered, or code::nil:: if no device was discovered.
41 w = WiiMote.discover; // discover a new device
42 w.battery; // post the battery status of the device
45 WiiMote.closeAll; // close all devices
50 Returns an link::Classes/Array:: with all WiiMote devices.
53 Close all WiiMote devices.
56 Stops the eventloop. Only really necessary on Mac, but use it for cross platform robustness.
60 private::prInit, prOpen, prClose, prAddress, prConnect, prDisconnect, prCalibration, prEnable, prEnableExpansion, prEnableIRSensor, prEnableMotionSensor, prEnableButtons, prSetVibration, prWiiSetLED, prHandleBatteryEvent, prHandleExtensionEvent, prHandleButtonEvent, prHandleNunchukEvent, prHandleClassicEvent, prHandleIREvent, prHandleAccEvent, prHandleEvent, prReadError, prConnectAction, prDisconnectAction
63 dump incoming events for debugging purposes.
66 Returns the device specification, with symbolic names for each item. Each name links to the current value.
69 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.
72 Set an action to be performed when the device closes.
75 Set an action to be performed when the device connects.
77 method::disconnectAction
78 Set an action to be performed when the device disconnects.
81 Get the value of a device property at the given key.
84 Set an action to be performed when the value of strong::key:: changes. The key name must be one that occurs in the spec.
87 Remove the previously defined action at the strong::key::.
92 subsection::The properties of the Wii Remote
95 Returns the current battery status of the device.
98 Returns the extension type that is connected.
100 method::remote_buttons
101 Returns an link::Classes/Array:: with the current button values.
103 method::remote_motion
104 Returns an link::Classes/Array:: with the current acceleration values (x,y,z, orientation). Orientation is Mac only.
107 Returns an link::Classes/Array:: with the found IR objects. (not tested!).
110 Returns an link::Classes/Array:: with the current LED values.
113 Set the LED with number strong::id:: to value strong::value:: (1=on, 0=off).
116 Turn on the rumble, strong::value:: (1=on, 0=off).
121 method::enableExpansion
122 Enable the device expansion (nunchuk or classic controller).
124 method::enableButtons
125 Enable the buttons on the device.
127 method::enableMotionSensor
128 Enable the motion sensor on the device.
130 method::enableIRSensor
131 Enable the IR sensor on the device.
133 subsection::The properties of the NunChuk
135 method::nunchuk_buttons
136 Returns an link::Classes/Array:: with the current button values.
138 method::nunchuk_motion
139 Returns an link::Classes/Array:: with the current acceleration values (x,y,z, orientation). Orientation is Mac only.
141 method::nunchuk_stick
142 Returns an link::Classes/Array:: with the current stick values.
144 subsection::The properties of the Classic Controller
146 method::classic_buttons
147 Returns an link::Classes/Array:: with the current button values.
149 method::classic_stick1
150 Returns an link::Classes/Array:: with the current stick values of stick 1.
152 method::classic_stick2
153 Returns an link::Classes/Array:: with the current stick values of stick 2.
155 method::classic_analog
156 Returns an link::Classes/Array:: with the current analog values.
161 // Example to start up and view values
162 WiiMote.start; // start the eventloop
163 w = WiiMote.discover; // discover a new device (wait for post about connected)
165 WiiMote.all; // post an array of all devices
167 x = WiiMoteGUI.new( w ); // create a GUI (only covers the WiiMote and NunChuk currently)
169 w.enableMotionSensor( 1 );
170 w.enableExpansion( 1 );
172 w.setLEDState( 0,1 ); // turn the first LED on
173 w.rumble( 1 ); // rumble the device
174 w.rumble( 0 ); // rumble the device
176 w.setAction( \bA, { |v| v.postln; } ); // post the value when button A changes.
177 w.removeAction( \bA );
179 // (MacOSX) if you do not see any changes in the motion sensors, then the connection is bad.
180 // push the red button inside the battery compartment, or the buttons 1 and 2 on the WiiMote and start over again to discover...
182 WiiMote.discover; // discover a new device
183 WiiMote.all; // post an array of all devices
186 x.w.close; // close previous window
187 x = WiiMoteGUI.new( w ); // create a GUI (only covers the WiiMote and NunChuk currently)
189 // now it should work..., if not, repeat the exercise...
193 WiiMote.closeAll; // close all devices
198 subsection:: IR tracking
199 This example shows a window displaying the objects being tracked by the WiiMote IR camera.
203 q = WiiMote.discover;
205 "No wiimote found, aborting.".error;
208 w = Window("IR sensor", Rect(100, 100, 400, 400)).front;
209 w.onClose = { q.close };
210 u = UserView(w, Rect(0, 0, 400, 400));
211 u.background = Color.black;
214 q.remote_ir.do {|ir, i|
216 p = Point(ir.posx*400, ir.posy*400);
217 Pen.addArc(p, ir.size*500.0, 0, pi*2);
218 Pen.fillColor = Color.hsv(i/5, 1, 1);
227 Font(Font.defaultSansFace, 9),