wiiremotej
Class WiiRemote

java.lang.Object
  extended by wiiremotej.WiiRemote
All Implemented Interfaces:
WiiDevice

public class WiiRemote
extends java.lang.Object
implements WiiDevice

A class representing a Nintendo (R) Wii Remote (TM). It has commands to control all of the WiiRemotes features. You can register a WiiRemoteListener with addWiiRemoteListener.
WiiRemoteJ uses the Java logging API. The log for the package is named "wiiremotej" and can be obtained through the java.util.logging.Logger class.

Note that this document uses the following notation to represent hexadecimal numbers: 0x--. A hexadecimal number is simply a number in base-16. This convention is used because it is easier to represent a single unsigned byte (256 in decimal) in hexadecimal: 0xFF.

Regarding data input reports (reports are sort of like channels): There are 11 input reports used for getting input from the buttons, accelerometer, IR sensor, and extension port. These various devices (accelerometer, IR sensor, and extension) have different modes requiring different amounts of data. Unfortunately, the Wii Remote does not support all three on their most data-intensive modes. Therefore, if you try to enable a device that requires a mode that lacks space for a currently enabled device, an IllegalStateException will be thrown. You must first disbale/change the mode of already enabled devices. Note that you can enable the extension-only report (which has no button data) without any warnings about lost button data; other inputs must still be disbaled. For details on the reports available, see the constant field values, labeled I_BUTTONS, I_ACCELEROMETER, etc (all of them have values greater than or equal to 0x30, which is 48 in decimal). Data is returned from the inputs whenever there is a change in the data. If continuous input is enabled (see enableContinuous()), data is returned at a rate of 100 reports per second (half that rate when using Full IR mode).

Note that reading data from the remote will disrupt all other data input (except buttons). So if you're using accelerometer data, for example, performing a data read will temporarily disrupt the accelerometer information stream. Also note that plugging in an extension will require a data read as calibration information is obtained. Keep this in mind when programming.
Regarding the various "setEnabled" methods: You can enable something that is already enabled. The program will send the usual enabling information, etc. and this should have no ill effects. Be aware, though, that any settings set on enabling will be reset to their default values.

Regarding extensions: You may add custom extensions (like the Nunchuk, Classic Controller, etc) using WiiRemoteExtensionFactory. When an extension is connected, WiiRemote asks the WiiRemoteExtensionFactory to return a WiiRemoteExtension object based on the extension's code (obtained by the application from the extension). Once a non-null WiiRemoteExtension is returned, that extension becomes the active extension. WiiRemoteExtensions specify payload information and provide a method to get an event for the given extension. You can add WiiRemoteExtensions to the factory with the WiiRemoteExtensionFactory.registerWiiRemoteExtension() method. Note the difference between an extension being connected and being enabled: "connected" refers to the physical state of the extension: is it plugged into the physical Wii Remote and set up for input? "Enabled" refers to the program's view of the extension: should WRExtensionEvents be passed to the listeners and do we need to use an input report that supports this extension? By default, the Nunchuk, the Wii Guitar, and the Classic Controller are registered.

When the remote is disconnected (either via the disconnect() method or by an action from the remote), the remote clears pointers to all variables to free up memory. Do not try to get status of the lights or any other information from the remote after it has disconnected, as you will probably end up throwing NullPointerExceptions. The only methods guaranteed to work after the remote has been disconnected are the isConnected() method (will always return false) and the getBluetoothAddress() method.


Field Summary
static byte I_ACCELEROMETER
          Input channel for button information (2 byte payload) and accelerometer information (3 byte payload).
static byte I_ACCELEROMETER_EXTENSION
          Input channel for button information (2 byte payload), accelerometer information (3 byte payload), and extension information (16 byte payload).
static byte I_ACCELEROMETER_IR
          Input channel for button information (2 byte payload), accelerometer information (3 byte payload), and extended IR information (12 byte payload).
static byte I_ACCELEROMETER_IR_EXTENSION
          Input channel for button information (2 byte payload), accelerometer information (3 byte payload), basic IR information (10 byte payload), and extension information (6 byte payload).
static byte I_BUTTONS
          Input channel for button information (2 byte payload) only.
static byte I_EXTENSION
          Input channel for button information (2 byte payload) and extension information (8 byte payload).
static byte I_EXTENSION2
          Input channel for button information (2 byte payload) and extension information (19 byte payload).
static byte I_EXTENSION3
          Input channel for extension information (21 byte payload).
static byte I_INTERLEAVED_ACCELEROMETER_IR1
          Interleaved input channel for button information (2 byte payload), accelerometer information (1 byte payload), and full IR information (18 byte payload).
static byte I_INTERLEAVED_ACCELEROMETER_IR2
          Interleaved input channel for button information (2 byte payload), accelerometer information (1 byte payload), and full IR information (18 byte payload).
static byte I_IR_EXTENSION
          Input channel for button information (2 byte payload), basic IR information (10 byte payload), and extension information (9 byte payload).
 int reportsProcessed
           
static byte SF_ADPCM4U
          Speaker output format: unsigned 4-bit ADPCM (Yamaha variant).
static byte SF_PCM8S
          Speaker output format: signed 8-bit PCM.
 
Constructor Summary
WiiRemote(AccelerationConstants accelConstants)
          Constructs a blank WiiRemote that is not connected to an actual Wii Remote using the passed in parameters.
 
Method Summary
 void addWiiRemoteListener(WiiRemoteListener listener)
          Adds the specified WiiRemoteListener to this WiiRemote.
static PrebufferedSound bufferSound(javax.sound.sampled.AudioInputStream audioIn)
          Creates a prebuffered sound from the given AudioInputStream by reading audio data and packing it into ready-to-go sound reports.
 void disconnect()
          Disconnects from the Wii Remote.
 void enableContinuous()
          Enables a continuous data stream.
 boolean equals(java.lang.Object other)
          Compares WiiRemotes based on their bluetooth addresses.
 AccelerationConstants getAccelerationConstants()
          Returns the acceleration constants located on the WiiRemote.
 java.lang.String getBluetoothAddress()
          Returns the bluetooth address of the WiiRemote.
 java.util.Vector<ButtonMap> getButtonMaps()
          Returns the Vector containing all the button mappings (button(s) -> action(s)).
 WiiRemoteExtension getExtension()
          Returns the currently connected extension or null if no extension is connected.
 WiiRemoteExtensionFactory getExtensionFactory()
          Returns the extension factory responsible for recognizing connected extensions and creating WiiRemoteExtension objects.
 byte getInputReport()
          Returns the input report the remote is currently using to receive data.
 int getIRMode()
          Returns the current IRMode.
 boolean[] getLEDLights()
          Returns the status of the LED lights.
 WiiRemoteMouse getMouse()
          Returns the current mouse.
 double getSpeakerVolume()
          Returns the current volume of the playing speaker as a percent from 0 to 1.
 boolean getUseMouse()
          Gets the value of useMouse.
 boolean isAccelerometerEnabled()
          Returns true if the accelerometer is enabled; otherwise false.
 boolean isConnected()
          Returns true if connected to the Wii Remote; otherwise false.
 boolean isContinuousEnabled()
          Returns true if continuous data streaming is enabled; otherwise false.
 boolean isExtensionConnected()
          Returns true if an extension is connected and set up for input; otherwise false.
 boolean isExtensionEnabled()
          Returns true if the extension is enabled (events will fire); otherwise false.
 boolean isIRSensorEnabled()
          Returns true if the IR sensor is enabled; otherwise false.
 boolean isLEDIlluminated(int light)
          Returns true if the specified LED is illuminated; otherwise false.
 boolean isModulatedVibrating()
          Returns true if the remote is modulated vibrating; otherwise false.
 boolean isPlayingSound()
          Returns true if the speaker is currently playing sound; otherwise false.
 boolean isReadingData()
          Returns true if reading data; otherwise false.
 boolean isSpeakerEnabled()
          Returns true if the speaker is enabled (sound can be played); otherwise false.
 boolean isSpeakerMuted()
          Returns true if the speaker is muted; otherwise false.
 boolean isVibrating()
          Returns true if the remote is vibrating; otherwise false.
 void modulatedVibrateFor(long time, long interval)
          Vibrates for the specified time, turning on and off at the specified interval.
 void muteSpeaker()
          Mutes the speaker.
 void playPrebufferedSound(PrebufferedSound soundIn, byte format)
          Plays the given PrebufferedSound in the given format over the speaker.
 void playSound(javax.sound.sampled.AudioInputStream audioIn, byte format)
          Plays the given AudioInputStream in the given format over the speaker.
 int readData(byte[] address, byte[] buffer, int firstIndex, int numBytes)
          Reads data from the WiiRemote at the specified address.
 byte[] readData(byte[] address, int numBytes)
          Reads data from the WiiRemote at the specified address.
 void removeWiiRemoteListener(WiiRemoteListener listener)
          Removes the specified WiiRemoteListener from this WiiRemote.
 void requestStatus()
          Requests status of the WiiRemote, including battery level, LED status, etc.
 void setAccelerometerEnabled(boolean enabled)
          Enables or disables the accelerometer.
 void setExtensionEnabled(boolean enabled)
          Enables or disables the extension port.
 void setExtensionPayload(int payload)
          Changes the extension payload to the specified value, if possible.
 void setIRSensorEnabled(boolean enabled, int mode)
          Enables or disables the IR sensor.
 void setIRSensorEnabled(boolean enabled, int mode, byte[] sens1, byte[] sens2)
          Deprecated. As of release 1.5, replaced by setIRSensorEnabled(boolean enabled, int mode, IRSensitivitySettings sensitivitySettings). This method may be made private in future releases!
 void setIRSensorEnabled(boolean enabled, int mode, IRSensitivitySettings sensitivitySettings)
          Enables or disables the IR sensor.
 void setLEDIlluminated(int light, boolean illuminated)
          Sets the specified LED light to illuminated, where true is on and false is off.
 void setLEDLights(boolean[] lightStatus)
          Sets all of the lights to the values specified in the status array, where true is on and false is off.
 void setMouse(WiiRemoteMouse mouse)
          Turns the WiiRemote into a mouse.
 void setSpeakerEnabled(boolean enabled)
          Enables or disables the speaker.
 void setSpeakerVolume(double volume)
          Sets the speaker volume to the given volume (percent).
 void setUseMouse(boolean useMouse)
          Sets the value of useMouse to the given value.
 void startModulatedVibrating(long interval)
          Starts modulated vibrating, turning on and off at the specified interval.
 void startVibrating()
          Starts vibration.
 void stopModulatedVibrating()
          Stops modulated vibration.
 void stopSound()
          Cuts off the current sound.
 void stopVibrating()
          Stops vibration.
 void unmuteSpeaker()
          Unmutes the speaker.
 void vibrateFor(long time)
          Vibrates for the specified time.
 void waitForDataReadCompletion()
          Waits for the current readData operation to complete before returning.
 void writeData(byte[] address, byte[] data)
          Writes data to the WiiRemote at the specified address.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reportsProcessed

public int reportsProcessed

SF_PCM8S

public static final byte SF_PCM8S
Speaker output format: signed 8-bit PCM.

See Also:
Constant Field Values

SF_ADPCM4U

public static final byte SF_ADPCM4U
Speaker output format: unsigned 4-bit ADPCM (Yamaha variant).

See Also:
Constant Field Values

I_BUTTONS

public static final byte I_BUTTONS
Input channel for button information (2 byte payload) only.

See Also:
Constant Field Values

I_ACCELEROMETER

public static final byte I_ACCELEROMETER
Input channel for button information (2 byte payload) and accelerometer information (3 byte payload).

See Also:
Constant Field Values

I_EXTENSION

public static final byte I_EXTENSION
Input channel for button information (2 byte payload) and extension information (8 byte payload).

See Also:
Constant Field Values

I_ACCELEROMETER_IR

public static final byte I_ACCELEROMETER_IR
Input channel for button information (2 byte payload), accelerometer information (3 byte payload), and extended IR information (12 byte payload).

See Also:
Constant Field Values

I_EXTENSION2

public static final byte I_EXTENSION2
Input channel for button information (2 byte payload) and extension information (19 byte payload).

See Also:
Constant Field Values

I_ACCELEROMETER_EXTENSION

public static final byte I_ACCELEROMETER_EXTENSION
Input channel for button information (2 byte payload), accelerometer information (3 byte payload), and extension information (16 byte payload).

See Also:
Constant Field Values

I_IR_EXTENSION

public static final byte I_IR_EXTENSION
Input channel for button information (2 byte payload), basic IR information (10 byte payload), and extension information (9 byte payload).

See Also:
Constant Field Values

I_ACCELEROMETER_IR_EXTENSION

public static final byte I_ACCELEROMETER_IR_EXTENSION
Input channel for button information (2 byte payload), accelerometer information (3 byte payload), basic IR information (10 byte payload), and extension information (6 byte payload).

See Also:
Constant Field Values

I_EXTENSION3

public static final byte I_EXTENSION3
Input channel for extension information (21 byte payload). Note: No buttons!

See Also:
Constant Field Values

I_INTERLEAVED_ACCELEROMETER_IR1

public static final byte I_INTERLEAVED_ACCELEROMETER_IR1
Interleaved input channel for button information (2 byte payload), accelerometer information (1 byte payload), and full IR information (18 byte payload).

See Also:
Constant Field Values

I_INTERLEAVED_ACCELEROMETER_IR2

public static final byte I_INTERLEAVED_ACCELEROMETER_IR2
Interleaved input channel for button information (2 byte payload), accelerometer information (1 byte payload), and full IR information (18 byte payload).

See Also:
Constant Field Values
Constructor Detail

WiiRemote

public WiiRemote(AccelerationConstants accelConstants)
Constructs a blank WiiRemote that is not connected to an actual Wii Remote using the passed in parameters. Note: events involving Extensions can not be created with this blank WiiRemote! Extension calibration data is needed and its harder to set that on a static basis.

Parameters:
accelConstants - information used in interpreting the Wii Remote's accelerometer data.
Method Detail

requestStatus

public void requestStatus()
                   throws java.io.IOException
Requests status of the WiiRemote, including battery level, LED status, etc. Note that status is not returned, but sent to a WRStatusEvent.

Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.

setLEDIlluminated

public void setLEDIlluminated(int light,
                              boolean illuminated)
                       throws java.lang.IllegalArgumentException,
                              java.io.IOException
Sets the specified LED light to illuminated, where true is on and false is off.

Parameters:
light - the light to set. 0 specifies the first light, 1 the second, etc.
illuminated - if true, turns the light on; otherwise, turns the light off.
Throws:
java.lang.IllegalArgumentException - if light is not an integer from 0 to 3.
java.io.IOException - if there is an error sending data to the Wii Remote.

setLEDLights

public void setLEDLights(boolean[] lightStatus)
                  throws java.lang.IllegalArgumentException,
                         java.io.IOException
Sets all of the lights to the values specified in the status array, where true is on and false is off.

Parameters:
lightStatus - the status of each light. Every true in the array represents a light that is on, every false a light that is off.
Throws:
java.lang.IllegalArgumentException - if status does not have four entries.
java.io.IOException - if there is an error sending data to the Wii Remote.

bufferSound

public static PrebufferedSound bufferSound(javax.sound.sampled.AudioInputStream audioIn)
                                    throws java.io.IOException
Creates a prebuffered sound from the given AudioInputStream by reading audio data and packing it into ready-to-go sound reports. This method blocks. Note that there is a limit to the length of the sound as the sound needs to be put in an array of bytes. So memory and max array size limits set by the runtime environment will limit the amount of audio you can buffer. The array length will be number of bytes in audio/20+1. The memory required (in bytes) will be roughly the original song's size + (3 * the array length).

Parameters:
audioIn - the audio to buffer, correctly encoded in the format you plan to play it in.
Throws:
java.io.IOException - if there's an error reading the sound file.

playPrebufferedSound

public void playPrebufferedSound(PrebufferedSound soundIn,
                                 byte format)
                          throws java.io.IOException,
                                 java.lang.IllegalStateException,
                                 java.lang.IllegalArgumentException
Plays the given PrebufferedSound in the given format over the speaker. No conversions are performed by this method. Note that the Wii Remote does have limits; namely, I can't seem to get more than about 16000 bytes per second output. So, if you're in 8-bit mode, for example, your sample rate is capped at about 2000 Hz (2 kHz). Keep this in mind when playing audio!

Parameters:
soundIn - the sound to play.
format - a speaker format specified by a constant prefaced with SF_.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalArgumentException - if format is not a valid format.
java.lang.IllegalStateException - if the speaker is not enabled.
java.lang.IllegalStateException - if the speaker is already playing sound.
See Also:
SF_PCM8S

playSound

public void playSound(javax.sound.sampled.AudioInputStream audioIn,
                      byte format)
               throws java.io.IOException,
                      java.lang.IllegalStateException,
                      java.lang.IllegalArgumentException
Plays the given AudioInputStream in the given format over the speaker. Note that the stream must be preformatted. No conversions are performed by this method. Note that the Wii Remote does have limits; namely, I can't seem to get more than about 16000 bytes per second output. So, if you're in 8-bit mode, for example, your sample rate is capped at about 2000 Hz (2 kHz). Keep this in mind when playing audio!

Parameters:
audioIn - the audio to play, correctly encoded in the given format.
format - a speaker format specified by a constant prefaced with SF_.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalArgumentException - if format is not a valid format.
java.lang.IllegalStateException - if the speaker is not enabled.
java.lang.IllegalStateException - if the speaker is already playing sound.
See Also:
SF_PCM8S

stopSound

public void stopSound()
               throws java.lang.IllegalStateException
Cuts off the current sound. You will not be able to resume from where you stopped. If no sound is playing, nothing happens. The speaker must be enabled for you to call this method.

Throws:
java.lang.IllegalStateException - if the speaker is not enabled.

writeData

public void writeData(byte[] address,
                      byte[] data)
               throws java.io.IOException,
                      java.lang.IllegalArgumentException
Writes data to the WiiRemote at the specified address.

Parameters:
address - the address to write to. Must be 4 bytes. The first byte of the address indicates whether to write to memory (0x00) or registers (0x04).
data - the data to write. Must be between 1 and 16 bytes in length.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalArgumentException - if address is not 4 bytes long.
java.lang.IllegalArgumentException - if data.length is not between 1 and 16.

readData

public byte[] readData(byte[] address,
                       int numBytes)
                throws java.io.IOException,
                       java.lang.IllegalArgumentException,
                       java.lang.IllegalStateException,
                       java.lang.InterruptedException
Reads data from the WiiRemote at the specified address. Only one data read operation can happen at a time. If you try to read data twice at the same time, the second read will throw an IllegalStateException. The WiiRemote class also reads data on its own sometimes, such as when an extension is plugged in. Therefore, there is no guarantee of the data being read when calling this method. The only way you can guarantee the success of a call to this method is to check isReadingData() immediately before calling it; even then, there is a slight chance the library could call readData between the time you call isReadingData() and readData. All of that said, the library does not call this method randomly: readData is called when the remote is first connected and when extensions are insterted/removed, so in general, you should be fine. Just be aware that your user could try inserting an extension right when you try to read data from the remote. This method blocks until the specified amount of data has been read or an exception is thrown.

Parameters:
address - the address to read from. Must be 4 bytes. The first byte of the address indicates whether to read from memory (0x00) or registers (0x04).
numBytes - the length of the data to read (in bytes).
Returns:
a byte array of length numBytes containing all of the data read.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalArgumentException - if address is not 4 bytes in length or if numBytes is less than 1.
java.lang.IllegalStateException - if data is already being read.
java.io.IOException - if there is an error reading the data. See WRDataEvent constant field values for details.
java.lang.InterruptedException - if interrupted waiting for the data read to complete.
See Also:
waitForDataReadCompletion()

readData

public int readData(byte[] address,
                    byte[] buffer,
                    int firstIndex,
                    int numBytes)
             throws java.io.IOException,
                    java.lang.IllegalArgumentException,
                    java.lang.IllegalStateException,
                    java.lang.InterruptedException
Reads data from the WiiRemote at the specified address. Only one data read can happen at a time. If you try to read data twice at the same time, the second read will throw an IllegalStateException. The WiiRemote class also reads data on its own sometimes, such as when an extension is plugged in. Therefore, there is no guarantee of the data being read when calling this method. The only way you can guarantee the success of a call to this method is to check isReadingData() immediately before calling it; even then, there is a slight chance the library could call readData between the time you call isReadingData() and readData. All of that said, the library does not call this method randomly: readData is called when the remote is first connected and when extensions are insterted/removed, so in general, you should be fine. Just be aware that your user could try inserting an extension right when you try to read data from the remote. This method blocks until the specified amount of data has been read or an exception is thrown.

Parameters:
address - the address to read from. Must be 4 bytes. The first byte of the address indicates whether to read from memory (0x00) or registers (0x04).
buffer - the array to read data into.
firstIndex - the first index of buffer to add data to.
numBytes - the length of the data to read (in bytes). Must be between 1 and 65535 (0xFFFF).
Returns:
the number of bytes read.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalArgumentException - if address is not 4 bytes in length or if numBytes is less than 1 or greater than 65535 (0xFFFF).
java.lang.IllegalStateException - if data is already being read.
java.io.IOException - if there is an error reading the data. See WRDataEvent constant field values for details.
java.lang.InterruptedException - if interrupted waiting for the data read to complete.
See Also:
waitForDataReadCompletion()

waitForDataReadCompletion

public void waitForDataReadCompletion()
                               throws java.lang.InterruptedException
Waits for the current readData operation to complete before returning.

Throws:
java.lang.InterruptedException - if interrupted waiting for the data read to complete.

enableContinuous

public void enableContinuous()
                      throws java.io.IOException
Enables a continuous data stream. This just means that data is returned constantly (100 reports per second) instead of just when changes occur. This is useful for accelerometer and IR reporting. Once turned on, this mode can not be turned off except by turning off the remote itself.

Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.

setAccelerometerEnabled

public void setAccelerometerEnabled(boolean enabled)
                             throws java.io.IOException,
                                    java.lang.IllegalStateException
Enables or disables the accelerometer.

Parameters:
enabled - if true, enables the accelerometer; otherwise, it disables the accelerometer.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalStateException - if there are no input reports that will support the addition of the accelerometer. This is rare, as most reports support the accelerometer. See static variables I_BUTTONS, I_ACCELEROMETER, etc for details.

setIRSensorEnabled

public void setIRSensorEnabled(boolean enabled,
                               int mode)
                        throws java.io.IOException,
                               java.lang.IllegalArgumentException,
                               java.lang.IllegalStateException
Enables or disables the IR sensor. A default sensitivity setting (Wii Level 3) is used. Note, if enabled is false, the other inputs are ignored.

Parameters:
enabled - if true, enables the IR sensor and continuous input; otherwise, it disables the IR sensor.
mode - the mode of the IR Sensor, specified in WRIREvent.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalArgumentException - enabled is true and the specified mode is not recgonized.
java.lang.IllegalStateException - if enabled is true and there are no input reports that will support the addition of the given mode of IR. The payload must match exactly (i.e. you can not use basic IR (10 bytes) with a report that supports extended (12 bytes)). If Full mode is enabled, no extensions can be enabled.

setIRSensorEnabled

public void setIRSensorEnabled(boolean enabled,
                               int mode,
                               IRSensitivitySettings sensitivitySettings)
                        throws java.io.IOException,
                               java.lang.IllegalArgumentException,
                               java.lang.IllegalStateException
Enables or disables the IR sensor. You must supply sensitivty settings. Note, if enabled is false, the other inputs are ignored.

Parameters:
enabled - if true, enables the IR sensor and continuous input; otherwise, it disables the IR sensor.
mode - the mode of the IR Sensor, specified in WRIREvent.
sensitivitySettings - sensitivity settings for the IR camera.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalArgumentException - enabled is true and the specified mode is not recgonized.
java.lang.IllegalStateException - if enabled is true and there are no input reports that will support the addition of the given mode of IR. The payload must match exactly (i.e. you can not use basic IR (10 bytes) with a report that supports extended (12 bytes)). If Full mode is enabled, no extensions can be enabled.

setIRSensorEnabled

@Deprecated
public void setIRSensorEnabled(boolean enabled,
                                          int mode,
                                          byte[] sens1,
                                          byte[] sens2)
                        throws java.io.IOException,
                               java.lang.IllegalArgumentException,
                               java.lang.IllegalStateException
Deprecated. As of release 1.5, replaced by setIRSensorEnabled(boolean enabled, int mode, IRSensitivitySettings sensitivitySettings). This method may be made private in future releases!

Enables or disables the IR sensor. You must supply sensitivty settings. Note, if enabled is false, the other inputs are ignored.

Parameters:
enabled - if true, enables the IR sensor and continuous input; otherwise, it disables the IR sensor.
mode - the mode of the IR Sensor, specified in WRIREvent.
sens1 - the first sensitivity settings array. Must be 9 bytes long!
sens2 - the second sensitivity settings array. Must be 2 bytes long!
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalArgumentException - enabled is true and the specified mode is not recgonized.
java.lang.IllegalStateException - if enabled is true and there are no input reports that will support the addition of the given mode of IR. The payload must match exactly (i.e. you can not use basic IR (10 bytes) with a report that supports extended (12 bytes)). If Full mode is enabled, no extensions can be enabled.

setSpeakerEnabled

public void setSpeakerEnabled(boolean enabled)
                       throws java.io.IOException
Enables or disables the speaker. As part of this process, the speaker is muted and then unmuted. Be aware that if you call this method while playing sound your sound will be interrupted briefly. Disabling the speaker stops the currently playing sound.

Parameters:
enabled - if true, enables the speaker; otherwise, it disables the speaker.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.

muteSpeaker

public void muteSpeaker()
                 throws java.io.IOException
Mutes the speaker.

Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.

unmuteSpeaker

public void unmuteSpeaker()
                   throws java.io.IOException
Unmutes the speaker.

Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.

setExtensionEnabled

public void setExtensionEnabled(boolean enabled)
                         throws java.io.IOException,
                                java.lang.IllegalStateException
Enables or disables the extension port.

Parameters:
enabled - if true, enables the extension port; otherwise, it disables the extension port.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalStateException - if enabled is true and the extension is not connected.
java.lang.IllegalStateException - if there are no input reports that will support the addition of the current extension. See static variables I_BUTTONS, I_ACCELEROMETER, etc for details.

setExtensionPayload

public void setExtensionPayload(int payload)
                         throws java.io.IOException,
                                java.lang.IllegalStateException,
                                java.lang.IllegalArgumentException
Changes the extension payload to the specified value, if possible. This lasts until the extension is unplugged.

Parameters:
payload - the new extension payload.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalStateException - if the extension is not enabled.
java.lang.IllegalArgumentException - if the payload is not valid for this extension.
java.lang.IllegalStateException - if there are no input reports that will support the modified payload (in addition to accelerometer, IR, etc: whatever's enabled). See static variables I_BUTTONS, I_ACCELEROMETER, etc for details.

startVibrating

public void startVibrating()
                    throws java.io.IOException
Starts vibration.

Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.

startModulatedVibrating

public void startModulatedVibrating(long interval)
Starts modulated vibrating, turning on and off at the specified interval. This can be used to create the feeling of different intensity vibrations.

Parameters:
interval - the the number of milliseconds to modulate with. Smaller values will produce lower-intensity vibrations over all. Note that values under 10 ms have caused problems on Windows computers. Do not use modulated vibration unless it is necessary, and keep the interval above 10 ms if you plan on deploying to Windows machines.

stopVibrating

public void stopVibrating()
                   throws java.io.IOException
Stops vibration.

Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.

stopModulatedVibrating

public void stopModulatedVibrating()
                            throws java.io.IOException
Stops modulated vibration.

Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.

modulatedVibrateFor

public void modulatedVibrateFor(long time,
                                long interval)
                         throws java.lang.IllegalArgumentException
Vibrates for the specified time, turning on and off at the specified interval. This can be used to create the feeling of different intensity vibrations.

Parameters:
time - the number of milliseconds to vibrate for.
interval - the the number of milliseconds to modulate with. Note that values under 10 ms have caused problems on Windows computers. Do not use modulated vibration unless it is necessary, and keep the interval above 10 ms if you plan on deploying to Windows machines.
Throws:
java.lang.IllegalArgumentException - if interval is greater than time.

vibrateFor

public void vibrateFor(long time)
                throws java.io.IOException
Vibrates for the specified time. Does not block.

Parameters:
time - the number of milliseconds to vibrate for.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.

disconnect

public void disconnect()
Disconnects from the Wii Remote. If the Wii Remote is already disconnected, no action is taken and no exceptions are thrown. Note that the WiiRemoteListeners' disconnected() method will NOT be called.

Specified by:
disconnect in interface WiiDevice

isConnected

public boolean isConnected()
Returns true if connected to the Wii Remote; otherwise false.

Specified by:
isConnected in interface WiiDevice
Returns:
true if connected to the Wii Remote; otherwise false.

isContinuousEnabled

public boolean isContinuousEnabled()
Returns true if continuous data streaming is enabled; otherwise false. If true, data is returned at a rate of 100 reports per second.

Returns:
true if continuous data streaming is enabled; otherwise false.

isAccelerometerEnabled

public boolean isAccelerometerEnabled()
Returns true if the accelerometer is enabled; otherwise false.

Returns:
true if the accelerometer is enabled; otherwise false.

isIRSensorEnabled

public boolean isIRSensorEnabled()
Returns true if the IR sensor is enabled; otherwise false.

Returns:
true if the IR sensor is enabled; otherwise false.

isVibrating

public boolean isVibrating()
Returns true if the remote is vibrating; otherwise false.

Returns:
true if the remote is vibrating; otherwise false.

isModulatedVibrating

public boolean isModulatedVibrating()
Returns true if the remote is modulated vibrating; otherwise false. Modulated vibrating simply means that the remote is turning vibration on and off at a given interval to create different intensity vibrations. Therefore, isVibrating() could return true or false depending on where in the cycle the modulated vibrating thread is (though there is more vibrating than not, so chances are it will return true).

Returns:
true if the remote is modulated vibrating; otherwise false.

isExtensionConnected

public boolean isExtensionConnected()
Returns true if an extension is connected and set up for input; otherwise false.

Returns:
true if an extension is connected and set up for input; otherwise false.

isExtensionEnabled

public boolean isExtensionEnabled()
Returns true if the extension is enabled (events will fire); otherwise false.

Returns:
true if the extension is enabled (events will fire); otherwise false.

isSpeakerEnabled

public boolean isSpeakerEnabled()
Returns true if the speaker is enabled (sound can be played); otherwise false. Note that if sound is currently being played, this method will still return true, but attempting to play sound will result in an exception.

Returns:
true if the speaker is enabled (sound can be played); otherwise false.

isSpeakerMuted

public boolean isSpeakerMuted()
Returns true if the speaker is muted; otherwise false. Note that you can still call playSound() on a muted speaker, however, you just won't hear anything. If the speaker is unmuted in the middle of the sound, the sound will pick up where it was before.

Returns:
true if the speaker is muted; otherwise false.

isPlayingSound

public boolean isPlayingSound()
Returns true if the speaker is currently playing sound; otherwise false. You can only play one sound at a time.

Returns:
true if the speaker is currently playing sound; otherwise false.

isReadingData

public boolean isReadingData()
Returns true if reading data; otherwise false.

Returns:
true if reading data; otherwise false.

getLEDLights

public boolean[] getLEDLights()
Returns the status of the LED lights. true means illuminated.

Returns:
the status of the LED lights.

isLEDIlluminated

public boolean isLEDIlluminated(int light)
Returns true if the specified LED is illuminated; otherwise false.

Parameters:
light - the number of the light to check. Ranges from 0 to 3.
Returns:
true if the specified LED is illuminated; otherwise false.
Throws:
java.lang.IllegalArgumentException - if light is not an integer from 0 to 3.

getSpeakerVolume

public double getSpeakerVolume()
Returns the current volume of the playing speaker as a percent from 0 to 1. The actual values stored in the Wii Remote vary based on the type of sound currently playing (or last playing). If the sound playing is in 4-bit ADPCM format, (int)(volume percentage*0x40) is the actual value. If the sound playing is in 8-bit PCM format, (int)(volume percentage*0xFF) is the actual value.

Returns:
the current volume of the playing speaker.

setSpeakerVolume

public void setSpeakerVolume(double volume)
                      throws java.io.IOException,
                             java.lang.IllegalArgumentException
Sets the speaker volume to the given volume (percent). Must be a number between 0 and 1. The actual values stored in the Wii Remote vary based on the type of sound currently playing (or last playing). If the sound playing is in 4-bit ADPCM format, (int)(volume percentage*0x40) is the actual value. If the sound playing is in 8-bit PCM format, (int)(volume percentage*0xFF) is the actual value.

Parameters:
volume - the volume as a percent from 0 to 1.
Throws:
java.io.IOException - if there is an error sending data to the Wii Remote.
java.lang.IllegalArgumentException - if volume is less than 0 or greater than 1.

getIRMode

public int getIRMode()
Returns the current IRMode. See WRIREvent for the meanings of the different modes. Note that this value has no meaning if the IR sensor is not enabled.

Returns:
the current IRMode.

getExtension

public WiiRemoteExtension getExtension()
Returns the currently connected extension or null if no extension is connected.

Returns:
the currently connected extension or null if no extension is connected.

getExtensionFactory

public WiiRemoteExtensionFactory getExtensionFactory()
Returns the extension factory responsible for recognizing connected extensions and creating WiiRemoteExtension objects. Can be used to add new types of extensions.

Returns:
the extension factory responsible for recognizing connected extensions and creating WiiRemoteExtension objects.

getAccelerationConstants

public AccelerationConstants getAccelerationConstants()
Returns the acceleration constants located on the WiiRemote. These values can be used to convert raw accelerations into Gs.

Returns:
the acceleration constants located on the WiiRemote.

setMouse

public void setMouse(WiiRemoteMouse mouse)
Turns the WiiRemote into a mouse. Note that the Wii Remote will begin to behave as a mouse immediately after a valid WiiRemoteMouse is passed to this method, unless the inputs the mouse is using are disabled. If the inputs the mouse is using are disabled, no exception will be thrown, but the mouse will not work. Pass null to disable the mouse.

Parameters:
mouse - the mouse to enable or null to disable.

getMouse

public WiiRemoteMouse getMouse()
Returns the current mouse. This value may be null, in which case the mouse is disabled.

Returns:
the current mouse.

getButtonMaps

public java.util.Vector<ButtonMap> getButtonMaps()
Returns the Vector containing all the button mappings (button(s) -> action(s)). You can use this vector to assign button mappings. If the value returned is null, then button mapping is not supported. The button maps are parsed in order. Multiple actions may be mapped to one button and multiple buttons may be mapped to one action (and anything in between). Maps are parsed in whatever order they are in the button maps vector. So, for example, if you mapped A to the h key on the keyboard, and then mapped A to the i key on the keyboard, pressing A would produce "hi" because you added the h map first.

Returns:
the Vector containing all the button mappings (button(s) -> action(s)).

getInputReport

public byte getInputReport()
Returns the input report the remote is currently using to receive data.

Returns:
the input report the remote is currently using to receive data.

addWiiRemoteListener

public void addWiiRemoteListener(WiiRemoteListener listener)
Adds the specified WiiRemoteListener to this WiiRemote. If the specified listener is null, no action is taken.

Parameters:
listener - the listener to add.

removeWiiRemoteListener

public void removeWiiRemoteListener(WiiRemoteListener listener)
Removes the specified WiiRemoteListener from this WiiRemote. If the specified listener was not previously added or is null, no action is taken.

Parameters:
listener - the listener to remove.

getBluetoothAddress

public java.lang.String getBluetoothAddress()
Returns the bluetooth address of the WiiRemote. This information persists even after the remote has been disconnected.

Specified by:
getBluetoothAddress in interface WiiDevice
Returns:
the bluetooth address of this remote.

setUseMouse

public void setUseMouse(boolean useMouse)
Sets the value of useMouse to the given value. If useMouse is true, then the WiiRemote will parse all mouse actions when processing events. If false, then the WiiRemote will omit parsing some mouse actions so that devices without mice may still use the program. However, it is still the user's responsibility not to add mice or to map mice to button presses, etc.

Parameters:
useMouse - true if mice should be used. false otherwise.

getUseMouse

public boolean getUseMouse()
Gets the value of useMouse. If useMouse is true, then the WiiRemote will parse all mouse actions when processing events. If false, then the WiiRemote will omit parsing some mouse actions so that devices without mice may still use the program. However, it is still the user's responsibility not to add mice or to map mice to button presses, etc.

Returns:
the value of useMouse.

equals

public boolean equals(java.lang.Object other)
Compares WiiRemotes based on their bluetooth addresses.

Overrides:
equals in class java.lang.Object
Returns:
true if the WiiRemotes are the same (have the same Bluetooth address); otherwise false.