wiiremotej
Class WiiRemoteExtension

java.lang.Object
  extended by wiiremotej.WiiRemoteExtension
Direct Known Subclasses:
ClassicControllerExtension, GuitarExtension, NunchukExtension

public abstract class WiiRemoteExtension
extends java.lang.Object

A class representing a Nintendo (R) Wii Remote (TM) extension, such as the Nunchuk. It has information about the extension and can create WRExtensionEvents. WiiRemoteExtensions do support dynamic payloads, but the size of the payload must be controlled from WiiRemote.


Constructor Summary
WiiRemoteExtension(int payload)
          Creates a new WRExtension with the given payload.
 
Method Summary
abstract  WRExtensionEvent createWRExtensionEvent(WiiRemote source, byte[] input, int offset)
          Creates and returns a new WRExtensionEvent from the given input.
abstract  void decryptExtensionInput(byte[] bytes, int firstIndex, int len)
          Applies any necessary transformation to the specified byte array to decrypt extension input.
abstract  short getCode()
          Returns the extension code for this extension, used by WRExtensionFactories in determining what kind of extension this is.
 int getPayload()
          Returns the number of maximum number of bytes that should be received on input from this extension.
abstract  boolean isPayloadValid(int payload)
          Checks if the given payload is valid for this extension.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WiiRemoteExtension

public WiiRemoteExtension(int payload)
Creates a new WRExtension with the given payload.

Parameters:
payload - the number of bytes needed to create an event with this extension.
Method Detail

getPayload

public int getPayload()
Returns the number of maximum number of bytes that should be received on input from this extension.

Returns:
the number of maximum number of bytes that should be received on input from this extension.

isPayloadValid

public abstract boolean isPayloadValid(int payload)
Checks if the given payload is valid for this extension. This is used to ensure the Wii Remote only sets valid payloads for an extension. The programmer should provide information on valid payloads to the user as well (i.e. through docs), as obtaining it from this method is not practical.

Parameters:
payload - the payload to check.
Returns:
true if this extension will accept the given payload; otherwise, false.

decryptExtensionInput

public abstract void decryptExtensionInput(byte[] bytes,
                                           int firstIndex,
                                           int len)
Applies any necessary transformation to the specified byte array to decrypt extension input.

Parameters:
bytes - the byte array to decrypt.
firstIndex - the first index to decrypt.
len - the number of bytes to decrypt.

getCode

public abstract short getCode()
Returns the extension code for this extension, used by WRExtensionFactories in determining what kind of extension this is. Note this is the decrypted code and it should be the same for all extensions of the same type.

Returns:
the extension code for this extension.

createWRExtensionEvent

public abstract WRExtensionEvent createWRExtensionEvent(WiiRemote source,
                                                        byte[] input,
                                                        int offset)
Creates and returns a new WRExtensionEvent from the given input. Subclasses are intended to override this method with their own implementations returning events of their respective types, i.e. WRNunchukExtension's createWRExtensionEvent method returns a WRNunchukExtensionEvent.

Parameters:
source - the WiiRemote triggering this event.
input - the data input from the extension port.
offset - the position of the first byte of extension data in input.
Returns:
a new WRExtensionEvent.