org.wiigee.device
Class Wiimote

java.lang.Object
  extended by org.wiigee.device.Device
      extended by org.wiigee.device.Wiimote

public class Wiimote
extends org.wiigee.device.Device

This class represents the basic functions of the wiimote. If you want your wiimote to e.g. vibrate you'll do this here.


Field Summary
static int BUTTON_1
           
static int BUTTON_2
           
static int BUTTON_A
           
static int BUTTON_B
           
static int BUTTON_DOWN
           
static int BUTTON_HOME
           
static int BUTTON_LEFT
           
static int BUTTON_MINUS
           
static int BUTTON_PLUS
           
static int BUTTON_RIGHT
           
static int BUTTON_UP
           
static byte CMD_SET_REPORT
           
protected  java.util.Vector<InfraredListener> infraredlistener
           
static byte IR_MODE_EXTENDED
           
static byte IR_MODE_STANDARD
           
static byte MODE_BUTTONS
           
static byte MODE_BUTTONS_ACCELERATION
           
static byte MODE_BUTTONS_ACCELERATION_INFRARED
           
protected  java.util.Vector<RotationListener> rotationListener
           
protected  java.util.Vector<org.wiigee.filter.Filter> rotfilters
           
 
Fields inherited from class org.wiigee.device.Device
accelerationEnabled, accelerationlistener, accfilters, buttonlistener, closegesturebutton, MOTION, processingunit, recognitionbutton, trainbutton
 
Constructor Summary
Wiimote(java.lang.String btaddress, boolean autofiltering, boolean autoconnect)
          Creates a new wiimote-device with a specific bluetooth mac-adress.
 
Method Summary
 void addInfraredListener(InfraredListener listener)
          The added Listener will be notified about detected infrated events.
 void addRotationFilter(org.wiigee.filter.Filter filter)
          Adds a filter to process the rotation speed data of the wiimote with an attached Wii Motion Plus.
 void addRotationListener(RotationListener listener)
          The added Listener will be notified about detected orientation changes.
 void connect()
          Creates the two needed connections to send and receive commands to and from the wiimote-device.
 void disconnect()
          Disconnects the wiimote and closes the two connections.
 void fireInfraredEvent(int[][] coordinates, int[] size)
          Fires a infrared event, containig coordinate pairs (x,y) and a size of the detected IR spot.
 void fireRotationEvent(double pitch, double roll, double yaw)
          Fires the current relative orientation of the Wiimote to all RotationListeners.
 void fireRotationSpeedEvent(double[] vector)
          If a Wii Motion Plus is attached and activated properly this event could be fired within every change of orientation of the device.
 double getPitch()
           
 javax.bluetooth.L2CAPConnection getReceiveConnection()
           
 double getRoll()
           
 double getYaw()
           
 void readEEPROM(byte[] offset, byte[] size)
          Reads data out of the EEPROM of the wiimote.
 void readRegister(byte[] offset, byte[] size)
          Makes the Wiimote respond the data of an register.
 void resetRotationFilters()
          Resets all filters which are applied to the rotation data from the Wii Motion Plus.
 void sendRaw(byte[] raw)
          Sends pure hexdata to the wiimote.
 void setAccelerationEnabled(boolean enabled)
          Activates the acceleration sensor.
 void setInfraredCameraEnabled(boolean enabled)
          Enables or disables the infrared camera of the wiimote with the default values.
 void setInfraredCameraEnabled(boolean enabled, byte infraredMode)
          Enables the infrared camera in front of the wiimote to track IR sources in the field of view of the camera.
 void setLED(int value)
          Enables one or more LEDs, where the value could be between 0 and 8.
 void setWiiMotionPlusEnabled(boolean enabled)
          To enable the Wii Motion Plus extension.
 void streamData(boolean value)
          This method makes the Wiimote-Class reacting to incoming data.
 void vibrateForTime(long milliseconds)
          With this method you gain access over the vibrate function of the wiimote.
 void writeRegister(byte[] offset, byte[] data)
          Write data to a register inside of the wiimote.
 
Methods inherited from class org.wiigee.device.Device
addAccelerationFilter, addAccelerationListener, addButtonListener, addGestureListener, fireAccelerationEvent, fireButtonPressedEvent, fireButtonReleasedEvent, fireMotionStartEvent, fireMotionStopEvent, getCloseGestureButton, getProcessingUnit, getRecognitionButton, getTrainButton, loadGesture, resetAccelerationFilters, saveGesture, setCloseGestureButton, setRecognitionButton, setTrainButton
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUTTON_2

public static final int BUTTON_2
See Also:
Constant Field Values

BUTTON_1

public static final int BUTTON_1
See Also:
Constant Field Values

BUTTON_B

public static final int BUTTON_B
See Also:
Constant Field Values

BUTTON_A

public static final int BUTTON_A
See Also:
Constant Field Values

BUTTON_MINUS

public static final int BUTTON_MINUS
See Also:
Constant Field Values

BUTTON_HOME

public static final int BUTTON_HOME
See Also:
Constant Field Values

BUTTON_LEFT

public static final int BUTTON_LEFT
See Also:
Constant Field Values

BUTTON_RIGHT

public static final int BUTTON_RIGHT
See Also:
Constant Field Values

BUTTON_DOWN

public static final int BUTTON_DOWN
See Also:
Constant Field Values

BUTTON_UP

public static final int BUTTON_UP
See Also:
Constant Field Values

BUTTON_PLUS

public static final int BUTTON_PLUS
See Also:
Constant Field Values

CMD_SET_REPORT

public static final byte CMD_SET_REPORT
See Also:
Constant Field Values

IR_MODE_STANDARD

public static final byte IR_MODE_STANDARD
See Also:
Constant Field Values

IR_MODE_EXTENDED

public static final byte IR_MODE_EXTENDED
See Also:
Constant Field Values

MODE_BUTTONS

public static final byte MODE_BUTTONS
See Also:
Constant Field Values

MODE_BUTTONS_ACCELERATION

public static final byte MODE_BUTTONS_ACCELERATION
See Also:
Constant Field Values

MODE_BUTTONS_ACCELERATION_INFRARED

public static final byte MODE_BUTTONS_ACCELERATION_INFRARED
See Also:
Constant Field Values

rotfilters

protected java.util.Vector<org.wiigee.filter.Filter> rotfilters

infraredlistener

protected java.util.Vector<InfraredListener> infraredlistener

rotationListener

protected java.util.Vector<RotationListener> rotationListener
Constructor Detail

Wiimote

public Wiimote(java.lang.String btaddress,
               boolean autofiltering,
               boolean autoconnect)
        throws java.io.IOException
Creates a new wiimote-device with a specific bluetooth mac-adress.

Parameters:
btaddress - String representation of the mac-adress e.g. 00191D68B57C.
autofiltering - If set the wiimote would automatically add the IdleStateFilter.
autoconnect - If set the wiimote would automatically be connected.
Throws:
java.io.IOException
Method Detail

connect

public void connect()
             throws java.io.IOException
Creates the two needed connections to send and receive commands to and from the wiimote-device.

Throws:
java.io.IOException

disconnect

public void disconnect()
Disconnects the wiimote and closes the two connections.


getReceiveConnection

public javax.bluetooth.L2CAPConnection getReceiveConnection()
Returns:
Receiving data connection

streamData

public void streamData(boolean value)
This method makes the Wiimote-Class reacting to incoming data. For just controlling and sending commands to the wiimote (vibration, LEDs, ...) it's not necessary to call this method.

Parameters:
value - true, if the class should react to incoming data. false, if you only want to send commands to wiimote and only the control-connection is used.

addInfraredListener

public void addInfraredListener(InfraredListener listener)
The added Listener will be notified about detected infrated events.

Parameters:
listener - The Listener to be added.

addRotationListener

public void addRotationListener(RotationListener listener)
The added Listener will be notified about detected orientation changes.

Parameters:
listener - The Listener to be added.

addRotationFilter

public void addRotationFilter(org.wiigee.filter.Filter filter)
Adds a filter to process the rotation speed data of the wiimote with an attached Wii Motion Plus.

Parameters:
filter - The Filter to be added.

resetRotationFilters

public void resetRotationFilters()
Resets all filters which are applied to the rotation data from the Wii Motion Plus. Also resets _all_ determined orientation angles, which should be extended with a consideration of other external datas - maybe irda events.


writeRegister

public void writeRegister(byte[] offset,
                          byte[] data)
                   throws java.io.IOException
Write data to a register inside of the wiimote.

Parameters:
offset - The memory offset, 3 bytes.
data - The data to be written, max. 16 bytes.
Throws:
java.io.IOException

readRegister

public void readRegister(byte[] offset,
                         byte[] size)
                  throws java.io.IOException
Makes the Wiimote respond the data of an register. The wiimotestreamer doesn't react to the reponse yet.

Parameters:
offset - The memory offset.
size - The size which has to be read out.
Throws:
java.io.IOException

readEEPROM

public void readEEPROM(byte[] offset,
                       byte[] size)
                throws java.io.IOException
Reads data out of the EEPROM of the wiimote. At the moment this method is only used to read out the calibration data, so the wiimotestreamer doesn't react for every answer on this request.

Parameters:
offset - The memory offset.
size - The size.
Throws:
java.io.IOException

sendRaw

public void sendRaw(byte[] raw)
             throws java.io.IOException
Sends pure hexdata to the wiimote. If you want your wiimote to vibrate use sendRaw(new byte[] {0x52, 0x13, 0x01}). For other raw-commands use the specific wiki-sites around the web (wiili.org, wiibrew.org, ...)

Parameters:
raw - byte representation of an command
Throws:
java.io.IOException

setLED

public void setLED(int value)
            throws java.io.IOException
Enables one or more LEDs, where the value could be between 0 and 8. If value=1 only the left LED would light up, for value=2 the second led would light up, for value=3 the first and second led would light up, and so on...

Parameters:
value - Between 0 and 8, indicating which LEDs should light up
Throws:
java.io.IOException

setAccelerationEnabled

public void setAccelerationEnabled(boolean enabled)
                            throws java.io.IOException
Activates the acceleration sensor. You have to call the streamData(true) method to react to this acceleration data. Otherwise the wiimote would send data the whole time and nothing else would happen.

Overrides:
setAccelerationEnabled in class org.wiigee.device.Device
Throws:
java.io.IOException

setInfraredCameraEnabled

public void setInfraredCameraEnabled(boolean enabled)
                              throws java.io.IOException
Enables or disables the infrared camera of the wiimote with the default values.

Parameters:
e - Should the Infrared Camera be enabled.
Throws:
java.io.IOException - In case of a connection error.

setInfraredCameraEnabled

public void setInfraredCameraEnabled(boolean enabled,
                                     byte infraredMode)
                              throws java.io.IOException
Enables the infrared camera in front of the wiimote to track IR sources in the field of view of the camera. This could be used to a lot of amazing stuff. Using this Mode could slow down the recognition of acceleration gestures during the increased data size transmitted.

Parameters:
e - Should the Infrared Camera be enabled.
infraredMode - The choosen Infrared Camera Mode.
Throws:
java.io.IOException - In case of a connection error.

setWiiMotionPlusEnabled

public void setWiiMotionPlusEnabled(boolean enabled)
                             throws java.io.IOException
To enable the Wii Motion Plus extension. The wiimote will further get every other information, like acceleration, infrared camera (loss of precision) and button presses.

Throws:
java.io.IOException

vibrateForTime

public void vibrateForTime(long milliseconds)
                    throws java.io.IOException
With this method you gain access over the vibrate function of the wiimote. You got to try which time in milliseconds would fit your requirements.

Parameters:
milliseconds - Time the wiimote would approx. vibrate.
Throws:
java.io.IOException

getPitch

public double getPitch()

getYaw

public double getYaw()

getRoll

public double getRoll()

fireInfraredEvent

public void fireInfraredEvent(int[][] coordinates,
                              int[] size)
Fires a infrared event, containig coordinate pairs (x,y) and a size of the detected IR spot.

Parameters:
coordinates - X and Y display coordinates.
size - The size of the spot.

fireRotationEvent

public void fireRotationEvent(double pitch,
                              double roll,
                              double yaw)
Fires the current relative orientation of the Wiimote to all RotationListeners.

Parameters:
yaw - Orientation around Z axis.
roll - Orientation around Y axis.
pitch - Orientation around X axis.

fireRotationSpeedEvent

public void fireRotationSpeedEvent(double[] vector)
If a Wii Motion Plus is attached and activated properly this event could be fired within every change of orientation of the device. The orientation is not used to do gesture recognition, yet.

Parameters:
vector - The rotational speed vector, containing: phi - Rotational speed of x axis (pitch) theta - Rotational speed of y axis (roll) psi - Rotational speed of z axis (yaw)