SCLOrkWiimote:
Filter:
SCLOrkTools/Classes (extension) | Quarks > SCLOrkTools

SCLOrkWiimote
ExtensionExtension

Wrapper class around HID access to Wiimotes.

Description

SCLOrkWiimote offers an abstraction around raw Bluetooth HID packet communication with the Wiimote. It was developed and tested on Linux. MacOS support is unknown, and the HID library is not currently supported on Windows.

NOTE: Without setting permissions as detailed in in the HID permissions help article the code will not be able to connect to the Wiimote.

Class Methods

.new

Creates a new SCLOrkWiimote instance and returns it. There is currently only one supported instance of SCLOrkWiimote per computer, so if the SCLOrkWiimote instance has already been created, this method will return that instance. By default the accelerometer is disabled when the SCLOrkWiimote object is first created.

.isConnected

Returns a boolean which is true if there is a Wiimote detected as connected to the host computer.

Instance Methods

.onButton

Provide a function to be called whenever a button press or release is detected.

A function to call. The function will be called with three arguments. The first argument is a symbol, and will be one of:

\dPadLeft
\dPadRight
\dPadDown
\dPadUp
\plus
\minus
\one
\two
\home
\a
\b

depending on which button on the Wiimote has changed state. The second argument is a boolean which will be true if the button has been pressed, and false if the button has been released. The third and final argument is the SCLOrkWiimote instance that detected the button press.

.isUsingAccelerometer

Returns a boolean. If true the accelerometer is currently enabled. If false, it is not.

.accelerometerBus

Returns the Bus number that represents the 3-channel bus holding the x,y, and z accelerometer values respectively. The values are updated at approximately 200Hz and range from -1 to +1.

.isBatteryLow

Returns a boolean. If true the battery is critically low on the Wiimote and should be replaced.

.batteryLevel

Returns a number between 0 and 1 indicating the current percentage on the battery level.

.leds

Get current state or set the state of the 4 LEDs on the bottom of the front face of the Wiimote. The value is an integer using the first four bits to control the light states. See the examples below for some help setting and clearing bits to control lights.

NOTE: For basic usability of the Wiimote its advisable to keep at least one light on while the Wiimote is connected to SuperCollider. This allows a user to easily distinguish an active, connected Wiimote from one that is disconnected and powered down.

.rumble

A boolean controlling the state of the rumble motor inside the Wiimote. If true, the rumble motor is enabled. If false it is disabled.

.buttonStates

An IdentityDictionary containing the current states of the buttons. The keys are the names of the buttons as documented in the onButton method, the values are booleans that are true if the button is pressed or false if not pressed.

.xAccel

If the accelerometer is enabled, returns the current value of the x accelerometer.

.yAccel

If the accelerometer is enabled, returns the current value of the y accelerometer.

.zAccel

If the accelerometer is enabled, returns the current value of the z accelerometer.

.enableAccelerometer

Enables accelerometer reporting on the Wiimote. The accelerometer reports back 3-axis acceleration data at roughly 200Hz, which drains the battery much faster than when just reporting the buttons. Therefore the accelerometer is disabled by default. In an effort to increase efficiency the data are sent directly to the synthesis server on a control Bus, and can be accessed in SynthDefs with the InBus UGen. If accessing in the language the values are continuously updated and can be accessed by polling the values of the xAccel, yAccel, and zAccel variables.

Arguments:

server

An optional Server argument. If not provided, the class uses Server.default.

.disableAccelerometer

Turns off the accelerometer reporting on the Wiimote, to save the battery.

.free

Disconnect from the Wiimote from SuperCollider and free the associated resources. If the accelerometer is required again, it can be re-enabled with another call to enableAccelerometer.

Examples