new stuffs for 0.12. Need to be tested !!!!

git-svn-id: http://wiiusej.googlecode.com/svn/trunk@130 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
guilhem.duche
2008-05-05 22:52:37 +00:00
parent eaeed82fda
commit 1fa4ca85e9
7 changed files with 314 additions and 163 deletions

View File

@@ -39,41 +39,36 @@ public class WiiUseApi {
static WiiUseApi getInstance() { static WiiUseApi getInstance() {
return instance; return instance;
} }
/** /**
* Connect to a wiimote or wiimotes once an address is known. * Connect to a wiimote or wiimotes once an address is known.
* @param nbWiimotes The number of wiimotes. *
* @param nbWiimotes
* The number of wiimotes.
* @return The number of wiimotes that successfully connected. * @return The number of wiimotes that successfully connected.
*/ */
synchronized native int connect(int nbWiimotes); synchronized native int connect(int nbWiimotes);
/** /**
* Find a wiimote or wiimotes. * Find a wiimote or wiimotes.
* @param nbMaxWiimotes The number of wiimotes. *
* @param timeout The number of seconds before the search times out. * @param nbMaxWiimotes
* The number of wiimotes.
* @param timeout
* The number of seconds before the search times out.
* @return The number of wiimotes found. * @return The number of wiimotes found.
*/ */
synchronized native int find(int nbMaxWiimotes, int timeout); synchronized native int find(int nbMaxWiimotes, int timeout);
/** /**
* Initialize an array of wiimote structures (for the C side of the library). * Initialize an array of wiimote structures (for the C side of the
* @param nbPossibleWiimotes size of the array. * library).
*
* @param nbPossibleWiimotes
* size of the array.
*/ */
synchronized native void init(int nbPossibleWiimotes); synchronized native void init(int nbPossibleWiimotes);
/**
* Try to connect to 2 wiimotes. Make them rumble to show they are
* connected.
*
* @param nb
* number of wiimotes to connect
* @param rumble
* make the connected wiimotes rumble
* @return 0 if there is an error otherwise it returns the number of
* wiimotes connected.
*/
synchronized native int doConnections(int nb, boolean rumble);
/** /**
* Close connection to the wiimote with the given id. * Close connection to the wiimote with the given id.
* *
@@ -81,9 +76,21 @@ public class WiiUseApi {
synchronized native void closeConnection(int id); synchronized native void closeConnection(int id);
/** /**
* Shutdown Wiiuse API. * Get unique id of a wiimote in the wiimotes array. Please make sure you
* call an existing index with a wiimote initialized at this index, other
* wise you'll get a wrong value.
*
* @param index
* index of the wiimote in the wiimotes array.
* @return the unid of the wiimote, or a wrong value if the index was false.
*
*/ */
synchronized native void shutdownApi(); synchronized native int getUnId(int index);
/**
* CleanUp Wiiuse API.
*/
synchronized native void cleanUp();
/** /**
* Activate rumble on the wiimote with the given id. * Activate rumble on the wiimote with the given id.
@@ -280,17 +287,15 @@ public class WiiUseApi {
* *
* @param id * @param id
* the id of the wiimote concerned. * the id of the wiimote concerned.
* @param nbWiimote
* Number of wiimotes connected.
* @param normalTimeout * @param normalTimeout
* The timeout in milliseconds for a normal read. * The timeout in milliseconds for a normal read.
* @param expansionTimeout * @param expansionTimeout
* The timeout in millisecondsd to wait for an expansion * The timeout in millisecondsd to wait for an expansion
* handshake. * handshake.
*/ */
synchronized native void setTimeout(int id, int nbWiimote, synchronized native void setTimeout(int id, short normalTimeout,
short normalTimeout, short expansionTimeout); short expansionTimeout);
/** /**
* Set the IR sensitivity. * Set the IR sensitivity.
* *
@@ -302,13 +307,13 @@ public class WiiUseApi {
* level will be set to 5. * level will be set to 5.
*/ */
synchronized native void setIrSensitivity(int id, int level); synchronized native void setIrSensitivity(int id, int level);
/** /**
* Check for new Events and Get it. * Check for new Events and Get it.
* *
* @param gath * @param gath
* the object where we store all the new events. * the object where we store all the new events.
*/ */
synchronized native void specialPoll(EventsGatherer gath); native void specialPoll(EventsGatherer gath);
} }

View File

@@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.event.EventListenerList; import javax.swing.event.EventListenerList;
import wiiusej.wiiuseapievents.EventsGatherer; import wiiusej.wiiuseapievents.EventsGatherer;
import wiiusej.wiiuseapievents.StatusEvent;
import wiiusej.wiiuseapievents.WiiUseApiEvent; import wiiusej.wiiuseapievents.WiiUseApiEvent;
import wiiusej.wiiuseapievents.WiiUseApiListener; import wiiusej.wiiuseapievents.WiiUseApiListener;
@@ -63,10 +64,38 @@ public class WiiUseApiManager extends Thread {
if (manager.connected <= 0 && !manager.running.get()) { if (manager.connected <= 0 && !manager.running.get()) {
int nbWiimotes = manager.connectWiimotes(nb, rumble); int nbWiimotes = manager.connectWiimotes(nb, rumble);
manager.wiimotes = new Wiimote[nbWiimotes]; manager.wiimotes = new Wiimote[nbWiimotes];
for (int i = 1; i <= nbWiimotes; i++) { for (int i = 0; i < nbWiimotes; i++) {
Wiimote wim = new Wiimote(i, manager); Wiimote wim = new Wiimote(WiiUseApi.getInstance().getUnId(i),
manager.wiimotes[i - 1] = wim; manager);
manager.addWiiUseApiListener(wim); manager.wiimotes[i] = wim;
manager.addWiiUseApiListener(wim);
}
//Set leds on wiimote
for (Wiimote wiimote : manager.wiimotes) {
int id = wiimote.getId();
short leds = 0;
if (id%4==0){
wiimote.setLeds(true, true, true, true);
}else if (id%4==1){
wiimote.setLeds(true, false, false, false);
}else if (id%4==2){
wiimote.setLeds(true, true, false, false);
}else if (id%4==3){
wiimote.setLeds(true, true, true, false);
}
}
//make the connected wiimotes rumble
if (rumble) {
for (Wiimote wiimote : manager.wiimotes) {
wiimote.activateRumble();
}
try {
sleep(500);
} catch (InterruptedException e) {
}
for (Wiimote wiimote : manager.wiimotes) {
wiimote.deactivateRumble();
}
} }
} }
@@ -92,7 +121,10 @@ public class WiiUseApiManager extends Thread {
*/ */
private int connectWiimotes(int nb, boolean rumble) { private int connectWiimotes(int nb, boolean rumble) {
if (connected <= 0) { if (connected <= 0) {
connected = wiiuse.doConnections(nb, rumble); int nbWiimotesFound;
wiiuse.init(nb);
nbWiimotesFound = wiiuse.find(nb, 3);
connected = wiiuse.connect(nbWiimotesFound);
return connected; return connected;
} else {// library not loaded, no wiimotes connected } else {// library not loaded, no wiimotes connected
return 0; return 0;
@@ -106,17 +138,26 @@ public class WiiUseApiManager extends Thread {
* id of the wiimote to disconnect. * id of the wiimote to disconnect.
*/ */
public void closeConnection(int id) { public void closeConnection(int id) {
removeWiiUseApiListener(wiimotes[id - 1]); int index = 0;
wiimotes[id - 1] = null; boolean found = false;
connected--; while (index < wiimotes.length && !found) {
if (connected == 0) {// stop this thread if there is if (wiimotes[index].getId() == id) {// we have a wiimote with this
// no more wiimotes connected. // id
// stop thread // remove the wiimote
shutdown(); removeWiiUseApiListener(wiimotes[index]);
wiimotes[index] = null;
connected--;
if (connected == 0) {// stop this thread if there is
// no more wiimotes connected.
// stop thread
shutdown();
}
/* Close connection in wiiuse */
wiiuse.closeConnection(index);
}
index++;
} }
/* Close connections requests */
wiiuse.closeConnection(id);
} }
/** /**
@@ -139,7 +180,7 @@ public class WiiUseApiManager extends Thread {
} }
} }
running.set(false); running.set(false);
wiiuse.shutdownApi(); wiiuse.cleanUp();
} }
/** /**
@@ -372,6 +413,35 @@ public class WiiUseApiManager extends Thread {
wiiuse.getStatus(id); wiiuse.getStatus(id);
} }
/**
* Set the normal and expansion handshake timeouts.
*
* @param id
* the id of the wiimote concerned.
* @param normalTimeout
* The timeout in milliseconds for a normal read.
* @param expansionTimeout
* The timeout in millisecondsd to wait for an expansion
* handshake.
*/
public void setTimeout(int id, short normalTimeout, short expansionTimeout) {
wiiuse.setTimeout(id, normalTimeout, expansionTimeout);
}
/**
* Set the IR sensitivity.
*
* @param id
* the id of the wiimote concerned.
* @param 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.
*/
public void setIrSensitivity(int id, int level) {
wiiuse.setIrSensitivity(id, level);
}
@Override @Override
public void run() { public void run() {
@@ -386,11 +456,6 @@ public class WiiUseApiManager extends Thread {
/* Polling */ /* Polling */
wiiuse.specialPoll(gather); wiiuse.specialPoll(gather);
try {
wiiuse.notify();
} catch (Exception e) {
// TODO: handle exception
}
/* deal with events gathered in Wiiuse API */ /* deal with events gathered in Wiiuse API */
for (WiiUseApiEvent evt : gather.getEvents()) { for (WiiUseApiEvent evt : gather.getEvents()) {
@@ -459,4 +524,11 @@ public class WiiUseApiManager extends Thread {
} }
} }
/**
* Called by the garbage collector at the end.
*/
protected void finalize() throws Throwable {
shutdown();
}
} }

View File

@@ -26,40 +26,50 @@ import wiiusej.wiiuseapievents.WiiUseApiListener;
import wiiusej.wiiuseapievents.WiimoteListener; import wiiusej.wiiuseapievents.WiimoteListener;
/** /**
* Class that represents a wiimote. * Class that represents a wiimote. You can register as an observer of this
* You can register as an observer of this wiimote to listen events from it. * wiimote to listen events from it. You manage it.
* You manage it. *
* @author guiguito * @author guiguito
*/ */
public class Wiimote implements WiiUseApiListener { public class Wiimote implements WiiUseApiListener {
private int id = -1;//wiimote id private int id = -1;// wiimote id
private EventListenerList listeners = new EventListenerList(); private EventListenerList listeners = new EventListenerList();
private WiiUseApiManager manager; private WiiUseApiManager manager;
/** /**
* Constructor. * Constructor.
* @param idd id of the wiimote *
* @param manager manager wo built it. * @param idd
* id of the wiimote
* @param manager
* manager wo built it.
*/ */
public Wiimote(int idd, WiiUseApiManager manager){ public Wiimote(int idd, WiiUseApiManager manager) {
id = idd; id = idd;
this.manager = manager; this.manager = manager;
} }
/**
* Get the unique id of the wiimote.
* @return the id
*/
public int getId() {
return id;
}
/** /**
* Disconnect this wiimote. * Disconnect this wiimote.
*/ */
public void disconnect(){ public void disconnect() {
deactivateIRTRacking(); deactivateIRTRacking();
deactivateMotionSensing(); deactivateMotionSensing();
deactivateRumble(); deactivateRumble();
manager.closeConnection(id); manager.closeConnection(id);
} }
/** /**
* Activate the rumble. * Activate the rumble.
*/ */
@@ -73,7 +83,7 @@ public class Wiimote implements WiiUseApiListener {
public void deactivateRumble() { public void deactivateRumble() {
manager.deactivateRumble(id); manager.deactivateRumble(id);
} }
/** /**
* Activate IR Tracking. * Activate IR Tracking.
*/ */
@@ -87,7 +97,7 @@ public class Wiimote implements WiiUseApiListener {
public void deactivateIRTRacking() { public void deactivateIRTRacking() {
manager.deactivateIRTRacking(id); manager.deactivateIRTRacking(id);
} }
/** /**
* Activate motion sensing. * Activate motion sensing.
*/ */
@@ -101,7 +111,7 @@ public class Wiimote implements WiiUseApiListener {
public void deactivateMotionSensing() { public void deactivateMotionSensing() {
manager.deactivateMotionSensing(id); manager.deactivateMotionSensing(id);
} }
/** /**
* Activate smoothing. * Activate smoothing.
*/ */
@@ -128,9 +138,9 @@ public class Wiimote implements WiiUseApiListener {
*/ */
public void deactivateContinuous() { public void deactivateContinuous() {
manager.deactivateContinuous(id); manager.deactivateContinuous(id);
} }
/** /**
* Set leds status. * Set leds status.
* *
@@ -148,69 +158,74 @@ public class Wiimote implements WiiUseApiListener {
} }
/** /**
* Set the orientation threshold (minimum angle between two degrees with accelerometer). * Set the orientation threshold (minimum angle between two degrees with
* accelerometer).
*
* @param th * @param th
* threshold in degrees * threshold in degrees
*/ */
public void setOrientationThreshold(float th) { public void setOrientationThreshold(float th) {
manager.setOrientationThreshold(id,th); manager.setOrientationThreshold(id, th);
} }
/** /**
* Set the acceleration threshold . * Set the acceleration threshold .
*
* @param th * @param th
* threshold * threshold
*/ */
public void setAccelerationThreshold(int th) { public void setAccelerationThreshold(int th) {
manager.setAccelerationThreshold(id,th); manager.setAccelerationThreshold(id, th);
} }
/** /**
* Set the alpha smoothing value. * Set the alpha smoothing value.
*
* @param th * @param th
* threshold * threshold
*/ */
public void setAlphaSmoothingValue(float th) { public void setAlphaSmoothingValue(float th) {
manager.setAlphaSmoothing(id,th); manager.setAlphaSmoothing(id, th);
} }
/** /**
* Set the screen aspect ratio to be considered as 4/3. * Set the screen aspect ratio to be considered as 4/3.
*/ */
public void setScreenAspectRatio43() { public void setScreenAspectRatio43() {
manager.setScreenAspectRatio43(id); manager.setScreenAspectRatio43(id);
} }
/** /**
* Set the screen aspect ratio to be considered as 16/9. * Set the screen aspect ratio to be considered as 16/9.
*/ */
public void setScreenAspectRatio169() { public void setScreenAspectRatio169() {
manager.setScreenAspectRatio169(id); manager.setScreenAspectRatio169(id);
} }
/** /**
* Set the sensor bar to be considered above the screen. * Set the sensor bar to be considered above the screen.
*/ */
public void setSensorBarAboveScreen() { public void setSensorBarAboveScreen() {
manager.setSensorBarAboveScreen(id); manager.setSensorBarAboveScreen(id);
} }
/** /**
* Set the sensor bar to be considered below the screen. * Set the sensor bar to be considered below the screen.
*/ */
public void setSensorBarBelowScreen() { public void setSensorBarBelowScreen() {
manager.setSensorBarBelowScreen(id); manager.setSensorBarBelowScreen(id);
} }
/** /**
* Set the screen resolution of the you are pointing at * Set the screen resolution of the you are pointing at with your wiimote.
* with your wiimote.
* *
* @param x x resolution. * @param x
* @param y y resolution. * x resolution.
* @param y
* y resolution.
*/ */
public void setVirtualResolution(int x, int y) { public void setVirtualResolution(int x, int y) {
manager.setVirtualResolution(id, x ,y); manager.setVirtualResolution(id, x, y);
} }
/** /**
@@ -221,39 +236,55 @@ public class Wiimote implements WiiUseApiListener {
} }
/** /**
* Ask for the status of the wiimote. * Ask for the status of the wiimote. The result will be received in a
* The result will be received in a status event object. * status event object. Implements onStatusEvent on wiimote listener to get
* Implements onStatusEvent on wiimote listener to get it. * it.
*/ */
public void getStatus() { public void getStatus() {
manager.getStatus(id); manager.getStatus(id);
} }
/**
* Set the IR sensitivity.
*
* @param 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.
*/
public void setIrSensitivity(int level) {
manager.setIrSensitivity(id, level);
}
/** /**
* Method called when a WiiUseApiEvent occurs. * Method called when a WiiUseApiEvent occurs.
* @param e the WiiUseApiEvent. *
* @param e
* the WiiUseApiEvent.
*/ */
public void onWiiUseApiEvent(WiiUseApiEvent e) { public void onWiiUseApiEvent(WiiUseApiEvent e) {
if (e.getWiimoteId() == id){ if (e.getWiimoteId() == id) {
if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT){ if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT) {
notifyWiiMoteEventListeners((GenericEvent)e); notifyWiiMoteEventListeners((GenericEvent) e);
}else if (e.getEventType() == WiiUseApiEvent.STATUS_EVENT } else if (e.getEventType() == WiiUseApiEvent.STATUS_EVENT
||e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_INSERTED || e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_INSERTED
||e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_REMOVED || e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_REMOVED
||e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_INSERTED || e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_INSERTED
||e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_REMOVED || e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_REMOVED
||e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_INSERTED || e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_INSERTED
||e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_REMOVED){ || e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_REMOVED) {
notifyStatusEventListeners((StatusEvent)e); notifyStatusEventListeners((StatusEvent) e);
}else if (e.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT){ } else if (e.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT) {
notifyDisconnectionEventListeners((DisconnectionEvent)e); notifyDisconnectionEventListeners((DisconnectionEvent) e);
} }
} }
} }
/** /**
* Add a WiimoteListener to the listeners list. * Add a WiimoteListener to the listeners list.
* @param listener a WiimoteListener *
* @param listener
* a WiimoteListener
*/ */
public void addWiiMoteEventListeners(WiimoteListener listener) { public void addWiiMoteEventListeners(WiimoteListener listener) {
listeners.add(WiimoteListener.class, listener); listeners.add(WiimoteListener.class, listener);
@@ -261,7 +292,9 @@ public class Wiimote implements WiiUseApiListener {
/** /**
* Remove a WiimoteListener from the listeners list. * Remove a WiimoteListener from the listeners list.
* @param listener a WiimoteListener *
* @param listener
* a WiimoteListener
*/ */
public void removeWiiMoteEventListeners(WiimoteListener listener) { public void removeWiiMoteEventListeners(WiimoteListener listener) {
listeners.remove(WiimoteListener.class, listener); listeners.remove(WiimoteListener.class, listener);
@@ -269,6 +302,7 @@ public class Wiimote implements WiiUseApiListener {
/** /**
* Get the list of WiimoteListener. * Get the list of WiimoteListener.
*
* @return the list of WiimoteListener. * @return the list of WiimoteListener.
*/ */
public WiimoteListener[] getWiiMoteEventListeners() { public WiimoteListener[] getWiiMoteEventListeners() {
@@ -276,47 +310,52 @@ public class Wiimote implements WiiUseApiListener {
} }
/** /**
* Notify WiimoteListeners that an event occured. * Notify WiimoteListeners that an event occured. Notify in first the
* Notify in first the listeners for Buttons Events. * listeners for Buttons Events. In second the listeners for IR Events. In
* In second the listeners for IR Events. * third the listeners for Motion sensing events.
* In third the listeners for Motion sensing events. *
* @param evt WiimoteEvent occured * @param evt
* WiimoteEvent occured
*/ */
private void notifyWiiMoteEventListeners(GenericEvent evt) { private void notifyWiiMoteEventListeners(GenericEvent evt) {
for (WiimoteListener listener : getWiiMoteEventListeners()) { for (WiimoteListener listener : getWiiMoteEventListeners()) {
listener.onButtonsEvent(evt.getButtonsEvent()); listener.onButtonsEvent(evt.getButtonsEvent());
if (evt.isThereIrEvent()){ if (evt.isThereIrEvent()) {
listener.onIrEvent(evt.getIREvent()); listener.onIrEvent(evt.getIREvent());
} }
if (evt.isThereMotionSensingEvent()){ if (evt.isThereMotionSensingEvent()) {
listener.onMotionSensingEvent(evt.getMotionSensingEvent()); listener.onMotionSensingEvent(evt.getMotionSensingEvent());
} }
} }
} }
/** /**
* Notify WiimoteListener that a status event occured. * Notify WiimoteListener that a status event occured.
* @param evt status event occured *
* @param evt
* status event occured
*/ */
private void notifyStatusEventListeners(StatusEvent evt) { private void notifyStatusEventListeners(StatusEvent evt) {
for (WiimoteListener listener : getWiiMoteEventListeners()) { for (WiimoteListener listener : getWiiMoteEventListeners()) {
listener.onStatusEvent(evt); listener.onStatusEvent(evt);
} }
} }
/** /**
* Notify WiimoteListener that a status event occured. * Notify WiimoteListener that a status event occured.
* @param evt status event occured *
* @param evt
* status event occured
*/ */
private void notifyDisconnectionEventListeners(DisconnectionEvent evt) { private void notifyDisconnectionEventListeners(DisconnectionEvent evt) {
for (WiimoteListener listener : getWiiMoteEventListeners()) { for (WiimoteListener listener : getWiiMoteEventListeners()) {
listener.onDisconnectionEvent(evt); listener.onDisconnectionEvent(evt);
} }
} }
@Override @Override
public String toString() { public String toString() {
return "Wiimote with ID : "+id; return "Wiimote with ID : " + id;
} }
} }

View File

@@ -91,12 +91,17 @@ public class EventsGatherer {
* aspect ratio of the screen. * aspect ratio of the screen.
* @param screenAsPectRatio * @param screenAsPectRatio
* IR sensor bar position. * IR sensor bar position.
* @param irSensitivity
* Sensitivity of the infrared camera.
* @param distance
* Pixel Distance between first two dots
*/ */
public void prepareIRevent(int x, int y, int z, int ax, int ay, int xVRes, public void prepareIRevent(int x, int y, int z, int ax, int ay, int xVRes,
int yVRes, int xOffset, int yOffset, short sensorBarPostion, int yVRes, int xOffset, int yOffset, short sensorBarPostion,
short screenAsPectRatio) { short screenAsPectRatio, short irSensitivity, float distance) {
genericEvent.prepareIRevent(x, y, z, ax, ay, xVRes, yVRes, xOffset, genericEvent.prepareIRevent(x, y, z, ax, ay, xVRes, yVRes, xOffset,
yOffset, sensorBarPostion, screenAsPectRatio); yOffset, sensorBarPostion, screenAsPectRatio, irSensitivity,
distance);
} }
@@ -159,8 +164,8 @@ public class EventsGatherer {
*/ */
public void addMotionSensingValues(float orientationThreshold, public void addMotionSensingValues(float orientationThreshold,
int accelerationThreshold, boolean smoothingState, int accelerationThreshold, boolean smoothingState,
float alphaSmooth, float r, float p, float ya, float ar, float ap, float x, float y, float alphaSmooth, float r, float p, float ya, float ar, float ap,
float z, short xx, short yy, short zz) { float x, float y, float z, short xx, short yy, short zz) {
if (genericEvent != null) { if (genericEvent != null) {
genericEvent.setMotionSensingEvent(orientationThreshold, genericEvent.setMotionSensingEvent(orientationThreshold,
accelerationThreshold, smoothingState, alphaSmooth, r, p, accelerationThreshold, smoothingState, alphaSmooth, r, p,

View File

@@ -126,14 +126,18 @@ public class GenericEvent extends WiiUseApiEvent {
* aspect ratio of the screen. * aspect ratio of the screen.
* @param screenAsPectRatio * @param screenAsPectRatio
* IR sensor bar position. * IR sensor bar position.
* @param irSensitivity
* Sensitivity of the infrared camera.
* @param distance
* Pixel Distance between first two dots
*/ */
public void prepareIRevent(int x, int y, int z, int ax, int ay, int xVRes, public void prepareIRevent(int x, int y, int z, int ax, int ay, int xVRes,
int yVRes, int xOffset, int yOffset, short sensorBarPostion, int yVRes, int xOffset, int yOffset, short sensorBarPostion,
short screenAsPectRatio) { short screenAsPectRatio, short irSensitivity, float distance) {
if (infraredEvent == null) { if (infraredEvent == null) {
infraredEvent = new IREvent(getWiimoteId(), x, y, z, ax, ay, xVRes, infraredEvent = new IREvent(getWiimoteId(), x, y, z, ax, ay, xVRes,
yVRes, xOffset, yOffset, sensorBarPostion, yVRes, xOffset, yOffset, sensorBarPostion,
screenAsPectRatio); screenAsPectRatio, irSensitivity, distance);
} }
} }

View File

@@ -39,6 +39,8 @@ public class IREvent extends WiimoteEvent {
private int yOffset; private int yOffset;
private short sensorBarPostion; private short sensorBarPostion;
private short screenAsPectRatio; private short screenAsPectRatio;
private short irSensitivity;
private float distance;
static private short WIIUSE_IR_ABOVE = 0; static private short WIIUSE_IR_ABOVE = 0;
static private short WIIUSE_IR_BELOW = 1; static private short WIIUSE_IR_BELOW = 1;
@@ -74,10 +76,14 @@ public class IREvent extends WiimoteEvent {
* aspect ratio of the screen. * aspect ratio of the screen.
* @param screenAsPectRatio * @param screenAsPectRatio
* IR sensor bar position. * IR sensor bar position.
* @param irSensitivity
* Sensitivity of the infrared camera.
* @param distance
* Pixel Distance between first two dots
*/ */
public IREvent(int id, int x, int y, int z, int ax, int ay, int xVRes, public IREvent(int id, int x, int y, int z, int ax, int ay, int xVRes,
int yVRes, int xOffset, int yOffset, short sensorBarPostion, int yVRes, int xOffset, int yOffset, short sensorBarPostion,
short screenAsPectRatio) { short screenAsPectRatio, short irSensitivity, float distance) {
super(id); super(id);
this.x = x; this.x = x;
this.y = y; this.y = y;
@@ -90,6 +96,8 @@ public class IREvent extends WiimoteEvent {
this.yOffset = yOffset; this.yOffset = yOffset;
this.sensorBarPostion = sensorBarPostion; this.sensorBarPostion = sensorBarPostion;
this.screenAsPectRatio = screenAsPectRatio; this.screenAsPectRatio = screenAsPectRatio;
this.irSensitivity = irSensitivity;
this.distance = distance;
IRPoints = new IRSource[NB_POINTS]; IRPoints = new IRSource[NB_POINTS];
} }
@@ -248,6 +256,27 @@ public class IREvent extends WiimoteEvent {
return screenAsPectRatio; return screenAsPectRatio;
} }
/**
* The sensitivity of the IR camera can be turned up or down depending on
* your needs. Like the Wii, wiiusej and wiiuse can set the camera
* sensitivity to a degree between 1 (lowest) and 5 (highest). The default
* is 3.
*
* @return the irSensitivity
*/
public short getIrSensitivity() {
return irSensitivity;
}
/**
* Pixel distance between first 2 dots.
*
* @return the distance between first 2 dots.
*/
public float getDistance() {
return distance;
}
@Override @Override
public String toString() { public String toString() {
String out = ""; String out = "";

View File

@@ -24,10 +24,10 @@ package wiiusej.wiiuseapievents;
*/ */
public class StatusEvent extends WiiUseApiEvent { public class StatusEvent extends WiiUseApiEvent {
private static short WIIMOTE_LED_1 = 1; protected static short WIIMOTE_LED_1 = 1;
private static short WIIMOTE_LED_2 = 2; protected static short WIIMOTE_LED_2 = 2;
private static short WIIMOTE_LED_3 = 4; protected static short WIIMOTE_LED_3 = 4;
private static short WIIMOTE_LED_4 = 8; protected static short WIIMOTE_LED_4 = 8;
/* ATTACHMENT CONSTANTS */ /* ATTACHMENT CONSTANTS */
@@ -130,6 +130,19 @@ public class StatusEvent extends WiiUseApiEvent {
public short getLeds() { public short getLeds() {
return leds; return leds;
} }
/**
* Tells if the given led is turned on according to the leds status int.
* @param led the int encoding a led.
* @return true if the led is turned on false otherwise.
*/
private boolean ledStatusCheck(short led) {
if ((leds & led) > 0) {
return true;
} else {
return false;
}
}
/** /**
* Get led1 status. * Get led1 status.
@@ -137,11 +150,7 @@ public class StatusEvent extends WiiUseApiEvent {
* @return true if the led is set. * @return true if the led is set.
*/ */
public boolean isLed1Set() { public boolean isLed1Set() {
if ((leds & WIIMOTE_LED_1) > 0) { return ledStatusCheck(WIIMOTE_LED_1);
return true;
} else {
return false;
}
} }
/** /**
@@ -150,11 +159,7 @@ public class StatusEvent extends WiiUseApiEvent {
* @return true if the led is set. * @return true if the led is set.
*/ */
public boolean isLed2Set() { public boolean isLed2Set() {
if ((leds & WIIMOTE_LED_2) > 0) { return ledStatusCheck(WIIMOTE_LED_2);
return true;
} else {
return false;
}
} }
/** /**
@@ -163,11 +168,7 @@ public class StatusEvent extends WiiUseApiEvent {
* @return true if the led is set. * @return true if the led is set.
*/ */
public boolean isLed3Set() { public boolean isLed3Set() {
if ((leds & WIIMOTE_LED_3) > 0) { return ledStatusCheck(WIIMOTE_LED_3);
return true;
} else {
return false;
}
} }
/** /**
@@ -176,11 +177,7 @@ public class StatusEvent extends WiiUseApiEvent {
* @return true if the led is set. * @return true if the led is set.
*/ */
public boolean isLed4Set() { public boolean isLed4Set() {
if ((leds & WIIMOTE_LED_4) > 0) { return ledStatusCheck(WIIMOTE_LED_4);
return true;
} else {
return false;
}
} }
/** /**