|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwiiremotej.BalanceBoard
public class BalanceBoard
A class representing a Nintendo (R) Wii Balance Board (TM). It has commands to control all of the Balance Board features.
You can register a BalanceBoardListener with addBalanceBoardListener.
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.
When the balance board is disconnected (either via the disconnect() method or by an action from the board), the board clears pointers to all variables to free up
memory. Do not try to get status of the lights or any other information from the balance board after it has disconnected, as you will probably end up throwing.
NullPointerExceptions. The only methods guaranteed to work after the board has been disconnected are the isConnected() method (will always return false
)
and the getBluetoothAddress() method.
Field Summary | |
---|---|
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). |
Constructor Summary | |
---|---|
BalanceBoard(MassConstants massConstants)
Constructs a blank Balance BOard that is not connected to an actual Board using the passed in parameters. |
Method Summary | |
---|---|
void |
addBalanceBoardListener(BalanceBoardListener listener)
Adds the specified BalanceBoardListener to this BalanceBoard. |
void |
disconnect()
Disconnects from the Balance Board. |
boolean |
equals(java.lang.Object other)
Compares BalanceBoards based on their bluetooth addresses. |
java.lang.String |
getBluetoothAddress()
Returns the bluetooth address of the Balance Board. |
byte |
getInputReport()
Returns the input report the balance board is currently using to receive data. |
MassConstants |
getMassConstants()
Returns the mass constants located on the Balance Board. |
boolean |
isConnected()
Returns true if connected to the Balance Board; otherwise false . |
boolean |
isLEDIlluminated()
Returns true if the LED is illuminated; otherwise false . |
boolean |
isReadingData()
Returns true if reading data; otherwise false . |
int |
readData(byte[] address,
byte[] buffer,
int firstIndex,
int numBytes)
Reads data from the Balance Board at the specified address. |
byte[] |
readData(byte[] address,
int numBytes)
Reads data from the Balance Board at the specified address. |
void |
removeBalanceBoardListener(BalanceBoardListener listener)
Removes the specified BalanceBoardListener from this BalanceBoard. |
void |
requestStatus()
Requests status of the Balance Board, including battery level, LED status, etc. |
void |
setLEDIlluminated(boolean illuminated)
Sets the LED light to illuminated, where true is on and false is off. |
void |
waitForDataReadCompletion()
Waits for the current readData operation to complete before returning. |
void |
writeData(byte[] address,
byte[] data)
Writes data to the Balance Board at the specified address. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte I_EXTENSION
public static final byte I_EXTENSION2
Constructor Detail |
---|
public BalanceBoard(MassConstants massConstants)
massConstants
- information used in interpreting the Balance Board's mass sensor data.Method Detail |
---|
public void requestStatus() throws java.io.IOException
java.io.IOException
- if there is an error sending data to the Balance Board.public void setLEDIlluminated(boolean illuminated) throws java.lang.IllegalArgumentException, java.io.IOException
true
is on and false
is off.
illuminated
- if true
, turns the light on; otherwise, turns the light off.
java.io.IOException
- if there is an error sending data to the Balance Board.
java.lang.IllegalArgumentException
public void writeData(byte[] address, byte[] data) throws java.io.IOException, java.lang.IllegalArgumentException
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.
java.io.IOException
- if there is an error sending data to the Balance Board.
java.lang.IllegalArgumentException
- if address is not 4 bytes long.
java.lang.IllegalArgumentException
- if data.length is not between 1 and 16.public byte[] readData(byte[] address, int numBytes) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.InterruptedException
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).
java.io.IOException
- if there is an error sending data to the Balance Board.
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 BBDataEvent constant field values for details.
java.lang.InterruptedException
- if interrupted waiting for the data read to complete.waitForDataReadCompletion()
public int readData(byte[] address, byte[] buffer, int firstIndex, int numBytes) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.InterruptedException
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).
java.io.IOException
- if there is an error sending data to the Balance Board.
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 BBDataEvent constant field values for details.
java.lang.InterruptedException
- if interrupted waiting for the data read to complete.waitForDataReadCompletion()
public void waitForDataReadCompletion() throws java.lang.InterruptedException
java.lang.InterruptedException
- if interrupted waiting for the data read to complete.public void disconnect()
disconnect
in interface WiiDevice
public boolean isConnected()
true
if connected to the Balance Board; otherwise false
.
isConnected
in interface WiiDevice
true
if connected to the Balance Board; otherwise false
.public boolean isReadingData()
true
if reading data; otherwise false
.
true
if reading data; otherwise false
.public boolean isLEDIlluminated()
true
if the LED is illuminated; otherwise false
.
true
if the LED is illuminated; otherwise false
.public MassConstants getMassConstants()
public byte getInputReport()
public void addBalanceBoardListener(BalanceBoardListener listener)
listener
- the listener to add.public void removeBalanceBoardListener(BalanceBoardListener listener)
listener
- the listener to remove.public java.lang.String getBluetoothAddress()
getBluetoothAddress
in interface WiiDevice
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
true
if the BalanceBoards are the same (have the same Bluetooth address); otherwise false
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |