wiiusej
Class WiiUseApiManager

java.lang.Object
  extended by java.lang.Thread
      extended by wiiusej.WiiUseApiManager
All Implemented Interfaces:
java.lang.Runnable

public class WiiUseApiManager
extends java.lang.Thread

Class that manages the use of Wiiuse API.

Author:
guiguito

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  int connected
           
private static WiiUseApiManager instance
           
private  boolean leave
           
private  javax.swing.event.EventListenerList listeners
           
private  java.util.concurrent.atomic.AtomicBoolean running
           
private  java.util.concurrent.Semaphore semaphore
           
private  Wiimote[] wiimotes
           
private  WiiUseApi wiiuse
           
static int WIIUSE_STACK_BLUESOLEIL
           
static int WIIUSE_STACK_MS
           
static int WIIUSE_STACK_UNKNOWN
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
WiiUseApiManager()
           
 
Method Summary
protected  void activateContinuous(int id)
          Activate continuous for the wiimotes with the given id.
protected  void activateIRTRacking(int id)
          Activate IR Tracking for the wiimote with the given id.
protected  void activateMotionSensing(int id)
          Activate motion sensing for the wiimote with the given id.
protected  void activateRumble(int id)
          Activate the rumble for the wiimote with the given id.
protected  void activateSmoothing(int id)
          Activate smoothing the wiimotes with the given id.
protected  void addWiiUseApiListener(WiiUseApiListener listener)
          Add WiiUseApiListener to the listeners list.
protected  void closeConnection(int id)
          Ask the thread to close a connection.
private  int connectWiimotes(int nb, boolean rumble, boolean forceStackType, int stackType)
          Connect wiimote and get the number of wiimotes connected.
protected  void deactivateContinuous(int id)
          Deactivate continuous for the wiimotes with the given id.
protected  void deactivateIRTRacking(int id)
          Deactivate IR Tracking for the wiimote with the given id.
protected  void deactivateMotionSensing(int id)
          Deactivate motion sensing for the wiimoter with the given id.
protected  void deactivateRumble(int id)
          Deactivate the rumble for the wiimote with the given id.
protected  void deactivateSmoothing(int id)
          Deactivate smoothing the wiimotes with the given id.
static void definitiveShutdown()
          Stop wiiuseJ definitively for this program.
protected  void finalize()
          Called by the garbage collector at the end.
private static WiiUseApiManager getInstance()
           
static int getNbConnectedWiimotes()
          Get the number of wiimotes connected.
protected  void getStatus(int id)
          Get Status for the wiimote for the given id.
static Wiimote[] getWiimotes(int nb, boolean rumble)
          Get wiimotes.
static Wiimote[] getWiimotes(int nb, boolean rumble, int stackType)
          Get wiimotes.
private static Wiimote[] getWiimotesPrivate(int nb, boolean rumble, boolean forceStackType, int stackType)
          Get wiimotes.
protected  WiiUseApiListener[] getWiiUseApiListeners()
          Get the list of WiiUseApiListeners.
private  void notifyWiiUseApiListener(WiiUseApiEvent evt)
          Notify WiiUseApiListeners that an event occured.
protected  void removeWiiUseApiListener(WiiUseApiListener listener)
          Remove WiiUseApiListener from the listeners list.
protected  void reSync(int id)
          Try to resync with the wiimote by starting a new handshake.
 void run()
           
protected  void setAccelerationThreshold(int id, int th)
          Set the acceleration threshold for the given id.
protected  void setAlphaSmoothing(int id, float th)
          Set alpha smoothing for the given id.
private  void setBlueToothstackType(int type)
          Force the bluetooth stack type.
protected  void setIrSensitivity(int id, int level)
          Set the IR sensitivity.
protected  void setLeds(int id, boolean l1, boolean l2, boolean l3, boolean l4)
          Set leds for the wiimotes with the given id.
protected  void setNunchukAccelerationThreshold(int id, int th)
          Set the nunchuk acceleration threshold for the given id.
protected  void setNunchukOrientationThreshold(int id, float th)
          Set the nunchuk orientation threshold for the given id.
protected  void setOrientationThreshold(int id, float th)
          Set the orientation threshold for the given id.
protected  void setScreenAspectRatio169(int id)
          Set screen aspect ratio to 16/9 for the given id.
protected  void setScreenAspectRatio43(int id)
          Set screen aspect ratio to 4/3 for the given id.
protected  void setSensorBarAboveScreen(int id)
          Set the sensor bar to be above the screen.
protected  void setSensorBarBelowScreen(int id)
          Set the sensor bar to be below the screen.
protected  void setTimeout(int id, short normalTimeout, short expansionTimeout)
          Set the normal and expansion handshake timeouts.
protected  void setVirtualResolution(int id, int x, int y)
          Set virtual resolution.
static void shutdown()
          Stop thread and shutdown wiiuse Api.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

instance

private static WiiUseApiManager instance

listeners

private final javax.swing.event.EventListenerList listeners

semaphore

private java.util.concurrent.Semaphore semaphore

wiimotes

private Wiimote[] wiimotes

wiiuse

private WiiUseApi wiiuse

connected

private int connected

running

private java.util.concurrent.atomic.AtomicBoolean running

leave

private boolean leave

WIIUSE_STACK_UNKNOWN

public static int WIIUSE_STACK_UNKNOWN

WIIUSE_STACK_MS

public static int WIIUSE_STACK_MS

WIIUSE_STACK_BLUESOLEIL

public static int WIIUSE_STACK_BLUESOLEIL
Constructor Detail

WiiUseApiManager

public WiiUseApiManager()
Method Detail

getInstance

private static WiiUseApiManager getInstance()

getWiimotes

public static Wiimote[] getWiimotes(int nb,
                                    boolean rumble)
Get wiimotes. Load library if necessary. Connect to wiimotes if necessary. Start polling if necessary. Return an array with the connected wiimotes.

Parameters:
nb - try to connect nb wiimotes.
rumble - make the connected wiimotes rumble.
Returns:
an array with connected wiimotes or NULL.

getWiimotes

public static Wiimote[] getWiimotes(int nb,
                                    boolean rumble,
                                    int stackType)
Get wiimotes. Load library if necessary. Connect to wiimotes if necessary. Start polling if necessary. Return an array with the connected wiimotes.

Parameters:
nb - try to connect nb wiimotes.
rumble - make the connected wiimotes rumble.*
stackType - the stack type : WiiUseApiManager.WIIUSE_STACK_UNKNOWN or WiiUseApiManager.WIIUSE_STACK_MS or WiiUseApiManager.WIIUSE_STACK_BLUESOLEIL
Returns:
an array with connected wiimotes or NULL.

getWiimotesPrivate

private static Wiimote[] getWiimotesPrivate(int nb,
                                            boolean rumble,
                                            boolean forceStackType,
                                            int stackType)
Get wiimotes. Load library if necessary. Connect to wiimotes if necessary. Start polling if necessary. Return an array with the connected wiimotes.

Parameters:
nb - try to connect nb wiimotes.
rumble - make the connected wiimotes rumble.*
forceStackType - true if we want to force the stack type.
stackType - the stack type : WiiUseApiManager.WIIUSE_STACK_UNKNOWN or WiiUseApiManager.WIIUSE_STACK_MS or WiiUseApiManager.WIIUSE_STACK_BLUESOLEIL
Returns:
an array with connected wiimotes or NULL.

connectWiimotes

private int connectWiimotes(int nb,
                            boolean rumble,
                            boolean forceStackType,
                            int stackType)
Connect wiimote and get the number of wiimotes connected. Supposed to be used once.

Parameters:
nb - try to connect nb wiimotes
rumble - make the connected wiimotes rumble
forceStackType - true if we want to force the stack type.
stackType - the stack type : WiiUseApiManager.WIIUSE_STACK_UNKNOWN or WiiUseApiManager.WIIUSE_STACK_MS or WiiUseApiManager.WIIUSE_STACK_BLUESOLEIL
Returns:
0 if nothing connected or the number of wiimotes connected.

closeConnection

protected void closeConnection(int id)
Ask the thread to close a connection.

Parameters:
id - id of the wiimote to disconnect.

getNbConnectedWiimotes

public static int getNbConnectedWiimotes()
Get the number of wiimotes connected.

Returns:
the number of wiimotes connected.

shutdown

public static void shutdown()
Stop thread and shutdown wiiuse Api.


definitiveShutdown

public static void definitiveShutdown()
Stop wiiuseJ definitively for this program. It finishes Wiiusej thread and shutdown wiiuse API.


activateRumble

protected void activateRumble(int id)
Activate the rumble for the wiimote with the given id.

Parameters:
id - id of the wiimote.

deactivateRumble

protected void deactivateRumble(int id)
Deactivate the rumble for the wiimote with the given id.

Parameters:
id - id of the wiimote.

activateIRTRacking

protected void activateIRTRacking(int id)
Activate IR Tracking for the wiimote with the given id.

Parameters:
id - id of the wiimote.

deactivateIRTRacking

protected void deactivateIRTRacking(int id)
Deactivate IR Tracking for the wiimote with the given id.

Parameters:
id - id of the wiimote.

activateMotionSensing

protected void activateMotionSensing(int id)
Activate motion sensing for the wiimote with the given id.

Parameters:
id - id of the wiimote.

deactivateMotionSensing

protected void deactivateMotionSensing(int id)
Deactivate motion sensing for the wiimoter with the given id.

Parameters:
id - id of the wiimote.

activateSmoothing

protected void activateSmoothing(int id)
Activate smoothing the wiimotes with the given id.

Parameters:
id - id of the wiimote.

deactivateSmoothing

protected void deactivateSmoothing(int id)
Deactivate smoothing the wiimotes with the given id.

Parameters:
id - id of the wiimote.

activateContinuous

protected void activateContinuous(int id)
Activate continuous for the wiimotes with the given id.

Parameters:
id - id of the wiimote.

deactivateContinuous

protected void deactivateContinuous(int id)
Deactivate continuous for the wiimotes with the given id.

Parameters:
id - id of the wiimote.

setLeds

protected void setLeds(int id,
                       boolean l1,
                       boolean l2,
                       boolean l3,
                       boolean l4)
Set leds for the wiimotes with the given id.

Parameters:
id - id of the wiimote
l1 - status of led1. True : ON, False : OFF.
l2 - status of led2. True : ON, False : OFF.
l3 - status of led3. True : ON, False : OFF.
l4 - status of led4. True : ON, False : OFF.

setOrientationThreshold

protected void setOrientationThreshold(int id,
                                       float th)
Set the orientation threshold for the given id. (minimum angle between two events)

Parameters:
id - id of the wiimote.
th - threshold in degrees.

setAccelerationThreshold

protected void setAccelerationThreshold(int id,
                                        int th)
Set the acceleration threshold for the given id. (minimum angle between two events)

Parameters:
id - id of the wiimote.
th - threshold.

setAlphaSmoothing

protected void setAlphaSmoothing(int id,
                                 float th)
Set alpha smoothing for the given id.

Parameters:
id - id of the wiimote.
th - threshold.

reSync

protected void reSync(int id)
Try to resync with the wiimote by starting a new handshake.

Parameters:
id - id of the wiimote.

setScreenAspectRatio43

protected void setScreenAspectRatio43(int id)
Set screen aspect ratio to 4/3 for the given id.

Parameters:
id - id of the wiimote.

setScreenAspectRatio169

protected void setScreenAspectRatio169(int id)
Set screen aspect ratio to 16/9 for the given id.

Parameters:
id - id of the wiimote.

setSensorBarAboveScreen

protected void setSensorBarAboveScreen(int id)
Set the sensor bar to be above the screen.

Parameters:
id - id of the wiimote.

setSensorBarBelowScreen

protected void setSensorBarBelowScreen(int id)
Set the sensor bar to be below the screen.

Parameters:
id - id of the wiimote.

setVirtualResolution

protected void setVirtualResolution(int id,
                                    int x,
                                    int y)
Set virtual resolution. It is used to automatically compute the position of a cursor on this virtual screen using the sensor bar. These results come in the IREvent.

Parameters:
id - id of the wiimote.
x - x resolution.
y - y resolution.

getStatus

protected void getStatus(int id)
Get Status for the wiimote for the given id.

Parameters:
id - id of the wiimote.

setTimeout

protected void setTimeout(int id,
                          short normalTimeout,
                          short expansionTimeout)
Set the normal and expansion handshake timeouts.

Parameters:
id - the id of the wiimote concerned.
normalTimeout - The timeout in milliseconds for a normal read.
expansionTimeout - The timeout in millisecondsd to wait for an expansion handshake.

setIrSensitivity

protected void setIrSensitivity(int id,
                                int level)
Set the IR sensitivity.

Parameters:
id - the id of the wiimote concerned.
level - 1-5, same as Wii system sensitivity setting. If the level is < 1, then level will be set to 1. If the level is > 5, then level will be set to 5.

setNunchukOrientationThreshold

protected void setNunchukOrientationThreshold(int id,
                                              float th)
Set the nunchuk orientation threshold for the given id. (minimum angle between two events)

Parameters:
id - id of the wiimote.
th - threshold in degrees.

setNunchukAccelerationThreshold

protected void setNunchukAccelerationThreshold(int id,
                                               int th)
Set the nunchuk acceleration threshold for the given id. (minimum angle between two events)

Parameters:
id - id of the wiimote.
th - threshold.

setBlueToothstackType

private void setBlueToothstackType(int type)
Force the bluetooth stack type.(useful only for windows)

Parameters:
type - must be WIIUSE_STACK_UNKNOWN or WIIUSE_STACK_MS or WIIUSE_STACK_BLUESOLEIL.

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

addWiiUseApiListener

protected void addWiiUseApiListener(WiiUseApiListener listener)
Add WiiUseApiListener to the listeners list.

Parameters:
listener - a WiiUseApiListener

removeWiiUseApiListener

protected void removeWiiUseApiListener(WiiUseApiListener listener)
Remove WiiUseApiListener from the listeners list.

Parameters:
listener - a WiiUseApiListener

getWiiUseApiListeners

protected WiiUseApiListener[] getWiiUseApiListeners()
Get the list of WiiUseApiListeners.

Returns:
the list of WiiUseApiListeners.

notifyWiiUseApiListener

private void notifyWiiUseApiListener(WiiUseApiEvent evt)
Notify WiiUseApiListeners that an event occured.

Parameters:
evt - GenericEvent occured

finalize

protected void finalize()
                 throws java.lang.Throwable
Called by the garbage collector at the end.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable