wiiremotej
Class WiiRemoteJ

java.lang.Object
  extended by wiiremotej.WiiRemoteJ

public class WiiRemoteJ
extends java.lang.Object

Library for connecting to and interacting with a Nintendo (R) Wii Remote (TM) and Balance Board (TM) via Bluetooth (R). See accompanying LICENSE for trademark information.

Note that Bluetooth must be available on class loading, as the library connects to the local device at this time. WiiRemoteJ also contains the Logger from the Java logging API. The logger is named "wiiremotej" (for those wishing to utilize the logging API). Note that a ConsoleHandler is provided to output messages to the standard output (System.out). If you remove this handler, then you will cease to receive messages on the console from this handler, even if you call one of the setConsoleLogging methods. By default, only error (warning and severe) messages are output to the console.

Note that the bulk of the information you will need to program using WiiRemoteJ is located in the header of the WiiRemote class in the API docs.

See Also:
WiiRemote

Field Summary
static int ALL
          Indicates all devices.
static int BALANCE_BOARD
          Indicates a Balance Board device.
static int WII_REMOTE
          Indicates a Wii Remote device.
 
Constructor Summary
WiiRemoteJ()
           
 
Method Summary
static int bytesToInt(byte[] bytes)
          Converts a byte array (big endian) to an int.
static int bytesToInt(byte[] bytes, boolean bigEndian)
          Converts a byte array (big endian) to an int.
static BalanceBoard connectToBalanceBoard(java.lang.String bluetoothAddress)
          Connects to the BalanceBoard with the specified bluetooth address.
static WiiRemote connectToRemote(java.lang.String bluetoothAddress)
          Connects to the Wii Remote with the specified bluetooth address.
static BalanceBoard findBalanceBoard()
          Searches for a BalanceBoard and pairs with it via Bluetooth.
static WiiDevice findDevice(int deviceType)
          Searches for a WiiDevice and pairs with it via Bluetooth.
static void findDevices(WiiDeviceDiscoveryListener listener, int deviceType)
          Searches for WiiDevices indefinitely, until stopFind() is called.
static void findDevices(WiiDeviceDiscoveryListener listener, int deviceType, int numDevices)
          Searches for WiiDevices until the given number of devices are found or until until stopFind() is called.
static WiiRemote findRemote()
          Searches for a WiiRemote and pairs with it via Bluetooth.
static void findRemotes(WiiDeviceDiscoveryListener listener)
          Searches for WiiRemotes indefinitely, until stopFind() is called.
static void findRemotes(WiiDeviceDiscoveryListener listener, int numRemotes)
          Searches for WiiRemotes until the given number are found or until stopFind() is called.
static byte[] intToBytes(int integer)
          Converts an int to a byte array (big endian).
static byte[] intToBytes(int integer, boolean bigEndian)
          Converts an int to a byte array.
static boolean isFindInProgress()
          Returns true if a find operation is in progress; otherwise false.
static void setConsoleLoggingAll()
          Outputs all messages to the console by default.
static void setConsoleLoggingErrors()
          Limits the types of messages output to the console by default to error (warning and severe) messages only.
static void setConsoleLoggingOff()
          Outputs no messages to the console by default.
static void stopFind()
          Cancels a search for multiple devices initiated by findDevices(...).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WII_REMOTE

public static final int WII_REMOTE
Indicates a Wii Remote device.

See Also:
Constant Field Values

BALANCE_BOARD

public static final int BALANCE_BOARD
Indicates a Balance Board device.

See Also:
Constant Field Values

ALL

public static final int ALL
Indicates all devices.

See Also:
Constant Field Values
Constructor Detail

WiiRemoteJ

public WiiRemoteJ()
Method Detail

intToBytes

public static byte[] intToBytes(int integer)
Converts an int to a byte array (big endian). Convenience for intToBytes(integer, true).

Parameters:
integer - an int to convert.
Returns:
the int as a byte array of length 4.

intToBytes

public static byte[] intToBytes(int integer,
                                boolean bigEndian)
Converts an int to a byte array.

Parameters:
integer - an int to convert.
bigEndian - if true, the byte order will be big endian; if false, the byte order will be little endian.
Returns:
the int as a byte array of length 4.

bytesToInt

public static int bytesToInt(byte[] bytes)
                      throws java.lang.IllegalArgumentException
Converts a byte array (big endian) to an int. Convenience for bytesToInt(bytes, true).

Parameters:
bytes - a byte array to convert.
Returns:
the byte array as an int.
Throws:
java.lang.IllegalArgumentException - if the byte array is longer than 4 bytes or is 0 bytes.

bytesToInt

public static int bytesToInt(byte[] bytes,
                             boolean bigEndian)
                      throws java.lang.IllegalArgumentException
Converts a byte array (big endian) to an int.

Parameters:
bytes - a byte array to convert.
bigEndian - if true,the input is considered to be big endian; if false, the input is considered to be little endian.
Returns:
the byte array as an int.
Throws:
java.lang.IllegalArgumentException - if the byte array is longer than 4 bytes or is 0 bytes.

connectToRemote

public static WiiRemote connectToRemote(java.lang.String bluetoothAddress)
                                 throws java.lang.IllegalStateException,
                                        java.io.IOException
Connects to the Wii Remote with the specified bluetooth address.

Parameters:
bluetoothAddress - the bluetooth address of the remote to connect to. Just a straight up address, no dashes, spaces, etc. Example: 0017AB322D14.
Returns:
the WiiRemote with the given bluetooth address.
Throws:
java.lang.IllegalStateException - on error intializing Bluetooth.
java.io.IOException - if there is an error connecting to the remote at given address.

connectToBalanceBoard

public static BalanceBoard connectToBalanceBoard(java.lang.String bluetoothAddress)
                                          throws java.lang.IllegalStateException,
                                                 java.io.IOException
Connects to the BalanceBoard with the specified bluetooth address.

Parameters:
bluetoothAddress - the bluetooth address of the balance baord to connect to. Just a straight up address, no dashes, spaces, etc. Example: 0017AB322D14.
Returns:
the BalanceBoard with the given bluetooth address.
Throws:
java.lang.IllegalStateException - on error intializing Bluetooth.
java.io.IOException - if there is an error connecting to the balance board at given address.

findDevice

public static WiiDevice findDevice(int deviceType)
                            throws java.lang.IllegalStateException,
                                   java.lang.InterruptedException,
                                   java.io.IOException
Searches for a WiiDevice and pairs with it via Bluetooth. Only does a standard inquiry before giving up. Blocks till inquiry complete. The WiiDevice is returned.

Note that only one "find" method can run at a time. It is the user's responsibility to ensure that the number of Bluetooth devices connected to the machine does not exceed the maximum of 7. The results are unspecified if this happens.

Parameters:
deviceType - the type of device to find. Can be a mask of multiple devices (simply add the devices you want together). See constants in WiiRemoteJ for options.
Returns:
a high-level interface to the found device or null if no device matching the deviceType is found.
Throws:
java.lang.IllegalStateException - on error intializing Bluetooth or starting inquiry.
java.lang.IllegalStateException - if devices were already being found.
java.lang.InterruptedException - on interruption while waiting for discovery.
java.io.IOException

findRemote

public static WiiRemote findRemote()
                            throws java.lang.IllegalStateException,
                                   java.lang.InterruptedException,
                                   java.io.IOException
Searches for a WiiRemote and pairs with it via Bluetooth. Only does a standard inquiry before giving up. Blocks till inquiry complete. The WiiRemote is returned. Convenience method for findDevice(WiiRemoteJ.WII_REMOTE).

Note that only one "find" method can run at a time. It is the user's responsibility to ensure that the number of Bluetooth devices connected to the machine does not exceed the maximum of 7. The results are unspecified if this happens.

Returns:
a high-level interface to the found remote or null if no remote is found.
Throws:
java.lang.IllegalStateException - on error intializing Bluetooth or starting inquiry.
java.lang.IllegalStateException - if devices were already being found.
java.lang.InterruptedException - on interruption while waiting for discovery.
java.io.IOException

findBalanceBoard

public static BalanceBoard findBalanceBoard()
                                     throws java.lang.IllegalStateException,
                                            java.lang.InterruptedException,
                                            java.io.IOException
Searches for a BalanceBoard and pairs with it via Bluetooth. Only does a standard inquiry before giving up. Blocks till inquiry complete. The BalanceBoard is returned. Convenience method for findDevice(WiiRemoteJ.BALANCE_BOARD).

Note that only one "find" method can run at a time. It is the user's responsibility to ensure that the number of Bluetooth devices connected to the machine does not exceed the maximum of 7. The results are unspecified if this happens.

Returns:
a high-level interface to the found balanceBoard or null if no balance board is found.
Throws:
java.lang.IllegalStateException - on error intializing Bluetooth or starting inquiry.
java.lang.IllegalStateException - if devices were already being found.
java.lang.InterruptedException - on interruption while waiting for discovery.
java.io.IOException

findDevices

public static void findDevices(WiiDeviceDiscoveryListener listener,
                               int deviceType)
                        throws java.lang.IllegalArgumentException,
                               java.lang.IllegalStateException
Searches for WiiDevices indefinitely, until stopFind() is called. Does not block. Devices discovered through this method are passed to the listener specified by the user. This method will never pass null to a listener. The time to attach listeners is in WiiDeviceDiscoveryListener's wiiDeviceDiscovered(...) method. Convenience method for findDevices(listener, deviceType, Integer.MAX_VALUE).

Note that only one "find" method can run at a time. It is the user's responsibility to ensure that the number of Bluetooth devices connected to the machine does not exceed the maximum of 7. The results are unspecified if this happens.

Parameters:
listener - listens for discovered WiiDevices. Whenever a device is discovered, it will be passed to this listener. Can not be null.
deviceType - the type of device to find. Can be a mask of multiple devices (simply add the devices you want together). See constants in WiiRemoteJ for options.
Throws:
java.lang.IllegalArgumentException - if listener is null.
java.lang.IllegalStateException - on error intializing Bluetooth or starting inquiry.
java.lang.IllegalStateException - if devices are already being found.

findDevices

public static void findDevices(WiiDeviceDiscoveryListener listener,
                               int deviceType,
                               int numDevices)
                        throws java.lang.IllegalArgumentException,
                               java.lang.IllegalStateException
Searches for WiiDevices until the given number of devices are found or until until stopFind() is called. Does not block. Devices discovered through this method are passed to the listener specified by the user. This method will never pass null to a listener. The time to attach listeners is in WiiDeviceDiscoveryListener's wiiDeviceDiscovered(...) method.

Note that only one "find" method can run at a time. It is the user's responsibility to ensure that the number of Bluetooth devices connected to the machine does not exceed the maximum of 7. The results are unspecified if this happens.

Parameters:
listener - listens for discovered WiiDevices. Whenever a device is discovered, it will be passed to this listener. Can not be null.
deviceType - the type of device to find. Can be a mask of multiple devices (simply add the devices you want together). See constants in WiiRemoteJ for options.
numDevices - the number of devices to search for.
Throws:
java.lang.IllegalArgumentException - if listener is null.
java.lang.IllegalStateException - on error intializing Bluetooth or starting inquiry.
java.lang.IllegalStateException - if devices are already being found.

findRemotes

public static void findRemotes(WiiDeviceDiscoveryListener listener)
                        throws java.lang.IllegalArgumentException,
                               java.lang.IllegalStateException
Searches for WiiRemotes indefinitely, until stopFind() is called. Does not block. Remotes discovered through this method are passed to the listener specified by the user. This method will never pass null to a listener. The time to attach WiiRemoteListeners is in WiiDeviceDiscoveryListener's wiiDeviceDiscovered(...) method. Convenience method for findDevices(listener, WiiRemoteJ.WII_REMOTE).

Note that only one "find" method can run at a time. It is the user's responsibility to ensure that the number of Bluetooth devices connected to the machine does not exceed the maximum of 7. The results are unspecified if this happens.

Parameters:
listener - listens for discovered WiiRemotes. Whenever a remote is discovered, it will be passed to this listener. Can not be null.
Throws:
java.lang.IllegalArgumentException - if listener is null.
java.lang.IllegalStateException - on error intializing Bluetooth or starting inquiry.
java.lang.IllegalStateException - if devices are already being found.

findRemotes

public static void findRemotes(WiiDeviceDiscoveryListener listener,
                               int numRemotes)
                        throws java.lang.IllegalArgumentException,
                               java.lang.IllegalStateException
Searches for WiiRemotes until the given number are found or until stopFind() is called. Does not block. Remotes discovered through this method are passed to the listener specified by the user. This method will never pass null to a listener. The time to attach WiiRemoteListeners is in WiiDeviceDiscoveryListener's wiiDeviceDiscovered(...) method. Convenience method for findDevices(listener, WiiRemoteJ.WII_REMOTE, numRemotes).

Note that only one "find" method can run at a time. It is the user's responsibility to ensure that the number of Bluetooth devices connected to the machine does not exceed the maximum of 7. The results are unspecified if this happens.

Parameters:
listener - listens for discovered WiiRemotes. Whenever a remote is discovered, it will be passed to this listener. Can not be null.
numRemotes - the number of remotes to search for.
Throws:
java.lang.IllegalArgumentException - if listener is null.
java.lang.IllegalStateException - on error intializing Bluetooth or starting inquiry.
java.lang.IllegalStateException - if devices are already being found.

stopFind

public static void stopFind()
Cancels a search for multiple devices initiated by findDevices(...). The current inquiry is terminated, and no further inquiries will begin until another call to findDevice(), or findDevices(...). If no inquiry is in progress, nothing happens.


isFindInProgress

public static boolean isFindInProgress()
Returns true if a find operation is in progress; otherwise false.

Returns:
true if a find operation is in progress; otherwise false.

setConsoleLoggingErrors

public static void setConsoleLoggingErrors()
Limits the types of messages output to the console by default to error (warning and severe) messages only. Note that if the Logger level is greater than WARNING, it will be changed to WARNING (i.e. if the Logger level is SEVERE, it will be changed to WARNING, but if it is FINE, it will not change).


setConsoleLoggingAll

public static void setConsoleLoggingAll()
Outputs all messages to the console by default. Note that the Logger level will be changed to ALL.


setConsoleLoggingOff

public static void setConsoleLoggingOff()
Outputs no messages to the console by default. The Logger level will not change.