wiiremotej
Class WRExtension

java.lang.Object
  extended by wiiremotej.WRExtension
Direct Known Subclasses:
WRClassicControllerExtension, WRNunchuckExtension

public abstract class WRExtension
extends java.lang.Object

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


Constructor Summary
WRExtension(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  short getCode()
          Returns the extension code for this extension, used by WRExtensionFactories in determining what kind of if the given extension is this kind of extension.
 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

WRExtension

public WRExtension(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.

getCode

public abstract short getCode()
Returns the extension code for this extension, used by WRExtensionFactories in determining what kind of if the given extension is this kind of extension. 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. WRNunchuckExtension's createWRExtensionEvent method returns a WRNunchuckExtensionEvent.

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.