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). 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 name "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.

See Also:
WiiRemote

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 WiiRemote findRemote()
          Searches for a WiiRemote and pairs with it via Bluetooth.
static void findRemotes(WiiRemoteDiscoveryListener listener)
          Searches for WiiRemotes indefinitely, until stopFind() is called.
static void findRemotes(WiiRemoteDiscoveryListener listener, int number)
          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 remotes initiated by findRemotes(...).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.

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.

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 remotes were already being found.
java.lang.InterruptedException - on interruption while waiting for discovery.
java.io.IOException

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.

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.

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 remotes were already being found.
java.lang.InterruptedException - on interruption while waiting for discovery.
java.io.IOException

findRemotes

public static void findRemotes(WiiRemoteDiscoveryListener 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 WiiRemoteDiscoveryListener's wiiRemoteDiscovered(...) 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 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 remotes are already being found.

findRemotes

public static void findRemotes(WiiRemoteDiscoveryListener listener,
                               int number)
                        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 WiiRemoteDiscoveryListener's wiiRemoteDiscovered(...) 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 WiiRemotes. Whenever a remote is discovered, it will be passed to this listener. Can not be null.
number - 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 remotes are already being found.

stopFind

public static void stopFind()
Cancels a search for multiple remotes initiated by findRemotes(...). The current inquiry is terminated, and no further inquiries will begin until another call to findRemote(), findBalanceBoard(), or findRemotes(...). 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.