From 1fa4ca85e94f6fac5dbad9b91ac6b4fc6e20ca6e Mon Sep 17 00:00:00 2001 From: "guilhem.duche" Date: Mon, 5 May 2008 22:52:37 +0000 Subject: [PATCH] new stuffs for 0.12. Need to be tested !!!! git-svn-id: http://wiiusej.googlecode.com/svn/trunk@130 ae48ae66-6a45-0410-b38e-211266189506 --- WiiUseJ/src/wiiusej/WiiUseApi.java | 67 +++--- WiiUseJ/src/wiiusej/WiiUseApiManager.java | 112 ++++++++-- WiiUseJ/src/wiiusej/Wiimote.java | 201 +++++++++++------- .../wiiuseapievents/EventsGatherer.java | 13 +- .../wiiusej/wiiuseapievents/GenericEvent.java | 8 +- .../src/wiiusej/wiiuseapievents/IREvent.java | 31 ++- .../wiiusej/wiiuseapievents/StatusEvent.java | 45 ++-- 7 files changed, 314 insertions(+), 163 deletions(-) diff --git a/WiiUseJ/src/wiiusej/WiiUseApi.java b/WiiUseJ/src/wiiusej/WiiUseApi.java index 33d601f..480c30d 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApi.java +++ b/WiiUseJ/src/wiiusej/WiiUseApi.java @@ -39,41 +39,36 @@ public class WiiUseApi { static WiiUseApi getInstance() { return instance; } - + /** * 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. */ synchronized native int connect(int nbWiimotes); - + /** * 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. */ synchronized native int find(int nbMaxWiimotes, int timeout); - + /** - * Initialize an array of wiimote structures (for the C side of the library). - * @param nbPossibleWiimotes size of the array. + * Initialize an array of wiimote structures (for the C side of the + * library). + * + * @param nbPossibleWiimotes + * size of the array. */ 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. * @@ -81,9 +76,21 @@ public class WiiUseApi { 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. @@ -280,17 +287,15 @@ public class WiiUseApi { * * @param id * the id of the wiimote concerned. - * @param nbWiimote - * Number of wiimotes connected. * @param normalTimeout * The timeout in milliseconds for a normal read. * @param expansionTimeout * The timeout in millisecondsd to wait for an expansion * handshake. */ - synchronized native void setTimeout(int id, int nbWiimote, - short normalTimeout, short expansionTimeout); - + synchronized native void setTimeout(int id, short normalTimeout, + short expansionTimeout); + /** * Set the IR sensitivity. * @@ -302,13 +307,13 @@ public class WiiUseApi { * level will be set to 5. */ synchronized native void setIrSensitivity(int id, int level); - + /** * Check for new Events and Get it. * * @param gath * the object where we store all the new events. */ - synchronized native void specialPoll(EventsGatherer gath); + native void specialPoll(EventsGatherer gath); } diff --git a/WiiUseJ/src/wiiusej/WiiUseApiManager.java b/WiiUseJ/src/wiiusej/WiiUseApiManager.java index 172070f..f336d49 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApiManager.java +++ b/WiiUseJ/src/wiiusej/WiiUseApiManager.java @@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.swing.event.EventListenerList; import wiiusej.wiiuseapievents.EventsGatherer; +import wiiusej.wiiuseapievents.StatusEvent; import wiiusej.wiiuseapievents.WiiUseApiEvent; import wiiusej.wiiuseapievents.WiiUseApiListener; @@ -63,10 +64,38 @@ public class WiiUseApiManager extends Thread { if (manager.connected <= 0 && !manager.running.get()) { int nbWiimotes = manager.connectWiimotes(nb, rumble); manager.wiimotes = new Wiimote[nbWiimotes]; - for (int i = 1; i <= nbWiimotes; i++) { - Wiimote wim = new Wiimote(i, manager); - manager.wiimotes[i - 1] = wim; - manager.addWiiUseApiListener(wim); + for (int i = 0; i < nbWiimotes; i++) { + Wiimote wim = new Wiimote(WiiUseApi.getInstance().getUnId(i), + manager); + 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) { if (connected <= 0) { - connected = wiiuse.doConnections(nb, rumble); + int nbWiimotesFound; + wiiuse.init(nb); + nbWiimotesFound = wiiuse.find(nb, 3); + connected = wiiuse.connect(nbWiimotesFound); return connected; } else {// library not loaded, no wiimotes connected return 0; @@ -106,17 +138,26 @@ public class WiiUseApiManager extends Thread { * id of the wiimote to disconnect. */ public void closeConnection(int id) { - removeWiiUseApiListener(wiimotes[id - 1]); - wiimotes[id - 1] = null; - connected--; - if (connected == 0) {// stop this thread if there is - // no more wiimotes connected. - // stop thread - shutdown(); + int index = 0; + boolean found = false; + while (index < wiimotes.length && !found) { + if (wiimotes[index].getId() == id) {// we have a wiimote with this + // id + // remove the wiimote + 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); - wiiuse.shutdownApi(); + wiiuse.cleanUp(); } /** @@ -372,6 +413,35 @@ public class WiiUseApiManager extends Thread { 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 public void run() { @@ -386,11 +456,6 @@ public class WiiUseApiManager extends Thread { /* Polling */ wiiuse.specialPoll(gather); - try { - wiiuse.notify(); - } catch (Exception e) { - // TODO: handle exception - } /* deal with events gathered in Wiiuse API */ 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(); + } + } diff --git a/WiiUseJ/src/wiiusej/Wiimote.java b/WiiUseJ/src/wiiusej/Wiimote.java index db48be6..9504aee 100644 --- a/WiiUseJ/src/wiiusej/Wiimote.java +++ b/WiiUseJ/src/wiiusej/Wiimote.java @@ -26,40 +26,50 @@ import wiiusej.wiiuseapievents.WiiUseApiListener; import wiiusej.wiiuseapievents.WiimoteListener; /** - * Class that represents a wiimote. - * You can register as an observer of this wiimote to listen events from it. - * You manage it. + * Class that represents a wiimote. You can register as an observer of this + * wiimote to listen events from it. You manage it. + * * @author guiguito */ public class Wiimote implements WiiUseApiListener { - private int id = -1;//wiimote id - + private int id = -1;// wiimote id + private EventListenerList listeners = new EventListenerList(); - + private WiiUseApiManager manager; - - + /** * 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; this.manager = manager; } - + + /** + * Get the unique id of the wiimote. + * @return the id + */ + public int getId() { + return id; + } + /** * Disconnect this wiimote. */ - public void disconnect(){ + public void disconnect() { deactivateIRTRacking(); deactivateMotionSensing(); deactivateRumble(); manager.closeConnection(id); } - + /** * Activate the rumble. */ @@ -73,7 +83,7 @@ public class Wiimote implements WiiUseApiListener { public void deactivateRumble() { manager.deactivateRumble(id); } - + /** * Activate IR Tracking. */ @@ -87,7 +97,7 @@ public class Wiimote implements WiiUseApiListener { public void deactivateIRTRacking() { manager.deactivateIRTRacking(id); } - + /** * Activate motion sensing. */ @@ -101,7 +111,7 @@ public class Wiimote implements WiiUseApiListener { public void deactivateMotionSensing() { manager.deactivateMotionSensing(id); } - + /** * Activate smoothing. */ @@ -128,9 +138,9 @@ public class Wiimote implements WiiUseApiListener { */ public void deactivateContinuous() { manager.deactivateContinuous(id); - + } - + /** * 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 * threshold in degrees */ public void setOrientationThreshold(float th) { - manager.setOrientationThreshold(id,th); + manager.setOrientationThreshold(id, th); } - + /** * Set the acceleration threshold . + * * @param th * threshold */ public void setAccelerationThreshold(int th) { - manager.setAccelerationThreshold(id,th); + manager.setAccelerationThreshold(id, th); } - + /** * Set the alpha smoothing value. + * * @param th * threshold */ public void setAlphaSmoothingValue(float th) { - manager.setAlphaSmoothing(id,th); + manager.setAlphaSmoothing(id, th); } - + /** * Set the screen aspect ratio to be considered as 4/3. */ public void setScreenAspectRatio43() { manager.setScreenAspectRatio43(id); } - + /** * Set the screen aspect ratio to be considered as 16/9. */ public void setScreenAspectRatio169() { manager.setScreenAspectRatio169(id); } - + /** * Set the sensor bar to be considered above the screen. */ public void setSensorBarAboveScreen() { manager.setSensorBarAboveScreen(id); } - + /** * Set the sensor bar to be considered below the screen. */ public void setSensorBarBelowScreen() { manager.setSensorBarBelowScreen(id); } - + /** - * Set the screen resolution of the you are pointing at - * with your wiimote. + * Set the screen resolution of the you are pointing at with your wiimote. * - * @param x x resolution. - * @param y y resolution. + * @param x + * x resolution. + * @param y + * y resolution. */ 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. - * The result will be received in a status event object. - * Implements onStatusEvent on wiimote listener to get it. + * Ask for the status of the wiimote. The result will be received in a + * status event object. Implements onStatusEvent on wiimote listener to get + * it. */ public void getStatus() { 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. - * @param e the WiiUseApiEvent. + * + * @param e + * the WiiUseApiEvent. */ public void onWiiUseApiEvent(WiiUseApiEvent e) { - if (e.getWiimoteId() == id){ - if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT){ - notifyWiiMoteEventListeners((GenericEvent)e); - }else if (e.getEventType() == WiiUseApiEvent.STATUS_EVENT - ||e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_INSERTED - ||e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_REMOVED - ||e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_INSERTED - ||e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_REMOVED - ||e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_INSERTED - ||e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_REMOVED){ - notifyStatusEventListeners((StatusEvent)e); - }else if (e.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT){ - notifyDisconnectionEventListeners((DisconnectionEvent)e); - } - } - } - + if (e.getWiimoteId() == id) { + if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT) { + notifyWiiMoteEventListeners((GenericEvent) e); + } else if (e.getEventType() == WiiUseApiEvent.STATUS_EVENT + || e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_INSERTED + || e.getEventType() == WiiUseApiEvent.WIIUSE_NUNCHUK_REMOVED + || e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_INSERTED + || e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_REMOVED + || e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_INSERTED + || e.getEventType() == WiiUseApiEvent.WIIUSE_GUITAR_HERO_3_CTRL_REMOVED) { + notifyStatusEventListeners((StatusEvent) e); + } else if (e.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT) { + notifyDisconnectionEventListeners((DisconnectionEvent) e); + } + } + } + /** * Add a WiimoteListener to the listeners list. - * @param listener a WiimoteListener + * + * @param listener + * a WiimoteListener */ public void addWiiMoteEventListeners(WiimoteListener listener) { listeners.add(WiimoteListener.class, listener); @@ -261,7 +292,9 @@ public class Wiimote implements WiiUseApiListener { /** * Remove a WiimoteListener from the listeners list. - * @param listener a WiimoteListener + * + * @param listener + * a WiimoteListener */ public void removeWiiMoteEventListeners(WiimoteListener listener) { listeners.remove(WiimoteListener.class, listener); @@ -269,6 +302,7 @@ public class Wiimote implements WiiUseApiListener { /** * Get the list of WiimoteListener. + * * @return the list of WiimoteListener. */ public WiimoteListener[] getWiiMoteEventListeners() { @@ -276,47 +310,52 @@ public class Wiimote implements WiiUseApiListener { } /** - * Notify WiimoteListeners that an event occured. - * Notify in first the listeners for Buttons Events. - * In second the listeners for IR Events. - * In third the listeners for Motion sensing events. - * @param evt WiimoteEvent occured + * Notify WiimoteListeners that an event occured. Notify in first the + * listeners for Buttons Events. In second the listeners for IR Events. In + * third the listeners for Motion sensing events. + * + * @param evt + * WiimoteEvent occured */ - private void notifyWiiMoteEventListeners(GenericEvent evt) { - for (WiimoteListener listener : getWiiMoteEventListeners()) { + private void notifyWiiMoteEventListeners(GenericEvent evt) { + for (WiimoteListener listener : getWiiMoteEventListeners()) { listener.onButtonsEvent(evt.getButtonsEvent()); - if (evt.isThereIrEvent()){ - listener.onIrEvent(evt.getIREvent()); + if (evt.isThereIrEvent()) { + listener.onIrEvent(evt.getIREvent()); } - if (evt.isThereMotionSensingEvent()){ - listener.onMotionSensingEvent(evt.getMotionSensingEvent()); + if (evt.isThereMotionSensingEvent()) { + listener.onMotionSensingEvent(evt.getMotionSensingEvent()); } } } - + /** * Notify WiimoteListener that a status event occured. - * @param evt status event occured + * + * @param evt + * status event occured */ - private void notifyStatusEventListeners(StatusEvent evt) { - for (WiimoteListener listener : getWiiMoteEventListeners()) { + private void notifyStatusEventListeners(StatusEvent evt) { + for (WiimoteListener listener : getWiiMoteEventListeners()) { listener.onStatusEvent(evt); } } - + /** * Notify WiimoteListener that a status event occured. - * @param evt status event occured + * + * @param evt + * status event occured */ - private void notifyDisconnectionEventListeners(DisconnectionEvent evt) { - for (WiimoteListener listener : getWiiMoteEventListeners()) { + private void notifyDisconnectionEventListeners(DisconnectionEvent evt) { + for (WiimoteListener listener : getWiiMoteEventListeners()) { listener.onDisconnectionEvent(evt); } } - + @Override - public String toString() { - return "Wiimote with ID : "+id; - } + public String toString() { + return "Wiimote with ID : " + id; + } } diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java b/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java index ef2f85f..aae5ca2 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java @@ -91,12 +91,17 @@ public class EventsGatherer { * aspect ratio of the screen. * @param screenAsPectRatio * 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, 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, - yOffset, sensorBarPostion, screenAsPectRatio); + yOffset, sensorBarPostion, screenAsPectRatio, irSensitivity, + distance); } @@ -159,8 +164,8 @@ public class EventsGatherer { */ public void addMotionSensingValues(float orientationThreshold, int accelerationThreshold, boolean smoothingState, - float alphaSmooth, float r, float p, float ya, float ar, float ap, float x, float y, - float z, short xx, short yy, short zz) { + float alphaSmooth, float r, float p, float ya, float ar, float ap, + float x, float y, float z, short xx, short yy, short zz) { if (genericEvent != null) { genericEvent.setMotionSensingEvent(orientationThreshold, accelerationThreshold, smoothingState, alphaSmooth, r, p, diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java index 2ceb3a6..d9142a2 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java @@ -126,14 +126,18 @@ public class GenericEvent extends WiiUseApiEvent { * aspect ratio of the screen. * @param screenAsPectRatio * 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, int yVRes, int xOffset, int yOffset, short sensorBarPostion, - short screenAsPectRatio) { + short screenAsPectRatio, short irSensitivity, float distance) { if (infraredEvent == null) { infraredEvent = new IREvent(getWiimoteId(), x, y, z, ax, ay, xVRes, yVRes, xOffset, yOffset, sensorBarPostion, - screenAsPectRatio); + screenAsPectRatio, irSensitivity, distance); } } diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java index 6007e97..28add02 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java @@ -39,6 +39,8 @@ public class IREvent extends WiimoteEvent { private int yOffset; private short sensorBarPostion; private short screenAsPectRatio; + private short irSensitivity; + private float distance; static private short WIIUSE_IR_ABOVE = 0; static private short WIIUSE_IR_BELOW = 1; @@ -74,10 +76,14 @@ public class IREvent extends WiimoteEvent { * aspect ratio of the screen. * @param screenAsPectRatio * 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, int yVRes, int xOffset, int yOffset, short sensorBarPostion, - short screenAsPectRatio) { + short screenAsPectRatio, short irSensitivity, float distance) { super(id); this.x = x; this.y = y; @@ -90,6 +96,8 @@ public class IREvent extends WiimoteEvent { this.yOffset = yOffset; this.sensorBarPostion = sensorBarPostion; this.screenAsPectRatio = screenAsPectRatio; + this.irSensitivity = irSensitivity; + this.distance = distance; IRPoints = new IRSource[NB_POINTS]; } @@ -248,6 +256,27 @@ public class IREvent extends WiimoteEvent { 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 public String toString() { String out = ""; diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java index 7a365fc..e219da3 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java @@ -24,10 +24,10 @@ package wiiusej.wiiuseapievents; */ public class StatusEvent extends WiiUseApiEvent { - private static short WIIMOTE_LED_1 = 1; - private static short WIIMOTE_LED_2 = 2; - private static short WIIMOTE_LED_3 = 4; - private static short WIIMOTE_LED_4 = 8; + protected static short WIIMOTE_LED_1 = 1; + protected static short WIIMOTE_LED_2 = 2; + protected static short WIIMOTE_LED_3 = 4; + protected static short WIIMOTE_LED_4 = 8; /* ATTACHMENT CONSTANTS */ @@ -130,6 +130,19 @@ public class StatusEvent extends WiiUseApiEvent { public short getLeds() { 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. @@ -137,11 +150,7 @@ public class StatusEvent extends WiiUseApiEvent { * @return true if the led is set. */ public boolean isLed1Set() { - if ((leds & WIIMOTE_LED_1) > 0) { - return true; - } else { - return false; - } + return ledStatusCheck(WIIMOTE_LED_1); } /** @@ -150,11 +159,7 @@ public class StatusEvent extends WiiUseApiEvent { * @return true if the led is set. */ public boolean isLed2Set() { - if ((leds & WIIMOTE_LED_2) > 0) { - return true; - } else { - return false; - } + return ledStatusCheck(WIIMOTE_LED_2); } /** @@ -163,11 +168,7 @@ public class StatusEvent extends WiiUseApiEvent { * @return true if the led is set. */ public boolean isLed3Set() { - if ((leds & WIIMOTE_LED_3) > 0) { - return true; - } else { - return false; - } + return ledStatusCheck(WIIMOTE_LED_3); } /** @@ -176,11 +177,7 @@ public class StatusEvent extends WiiUseApiEvent { * @return true if the led is set. */ public boolean isLed4Set() { - if ((leds & WIIMOTE_LED_4) > 0) { - return true; - } else { - return false; - } + return ledStatusCheck(WIIMOTE_LED_4); } /**