diff --git a/WiiUseJ/src/tests/Tests.java b/WiiUseJ/src/tests/Tests.java index 4528e62..628c330 100644 --- a/WiiUseJ/src/tests/Tests.java +++ b/WiiUseJ/src/tests/Tests.java @@ -9,9 +9,10 @@ import wiiusej.WiiUseApiListener; import wiiusej.WiiUseApiManager; /** - * This class used to test this API. + * This class used to test this API. + * * @author gduche - * + * */ public class Tests implements WiiUseApiListener { @@ -35,12 +36,12 @@ public class Tests implements WiiUseApiListener { @Override public void wiimoteEvent(WiiMoteEvent e) { - - /* leave if nothing is connected */ + + /* leave if nothing is connected */ if (WiiUseApiManager.getInstance().getNbConnectedWiimotes() == 0) { WiiUseApiManager.getInstance().shutdown(); } - + if (dump == DISPLAY_EACH_VALUE) { if (e.isConnected()) { // System.out.println("*********** WIIMOTE ID : "+ @@ -167,7 +168,7 @@ public class Tests implements WiiUseApiListener { } /* get status */ - if (e.isButtonMinusJustPressed()&&e.isButtonPlusJustPressed()) { + if (e.isButtonMinusJustPressed() && e.isButtonPlusJustPressed()) { WiiUseApiManager.getInstance().getStatus(1); } @@ -192,13 +193,13 @@ public class Tests implements WiiUseApiListener { } /* Activate Motion sensing */ - if (e.isButtonPlusJustPressed()){ + if (e.isButtonPlusJustPressed()) { System.out.println("Motion sensing Activated"); - WiiUseApiManager.getInstance().activateMotionSensing(1); + WiiUseApiManager.getInstance().activateMotionSensing(1); } - if (e.isButtonMinusJustPressed()){ + if (e.isButtonMinusJustPressed()) { System.out.println("Motion sensing Deactivated"); - WiiUseApiManager.getInstance().deactivateMotionSensing(1); + WiiUseApiManager.getInstance().deactivateMotionSensing(1); } /* display status */ @@ -206,7 +207,16 @@ public class Tests implements WiiUseApiListener { System.out .println("battery level : " + e.getBatteryLevel()); System.out.println("= --- Leds : " + e.getLeds() + "\n"); - System.out.println("= --- Rumble : " + e.isRumbleActive() + "\n"); + System.out.println("= --- Rumble : " + e.isRumbleActive() + + "\n"); + System.out.println("= --- Continous : " + + e.isContinuousActive() + "\n"); + System.out.println("= --- Smoothing : " + + e.isSmoothingActive() + "\n"); + System.out.println("= --- Speaker : " + + e.isSpeakerEnabled() + "\n"); + System.out.println("= --- Attachment : " + + e.isThereAttachment() + "\n"); } /* display ir points */ @@ -219,21 +229,22 @@ public class Tests implements WiiUseApiListener { } System.out.println(""); } - + /* display motion sensing */ - if (e.isMotionSensingActive()){ - System.out.println("Motion Sensing :"+e.getOrientation()+" , "+e.getGforce()); + if (e.isMotionSensingActive()) { + System.out.println("Motion Sensing :" + e.getOrientation() + + " , " + e.getGforce()); } - + /* leave test */ if (e.isButtonHomeJustPressed()) { System.out.println("LEAVING TEST"); - WiiUseApiManager.getInstance().closeConnection(1); + WiiUseApiManager.getInstance().closeConnection(1); } } else { System.out.println(" WIIMOTE ID : " + e.getWiimoteId() + " DISCONNECTED !!!!!"); - WiiUseApiManager.getInstance().closeConnection(1); + WiiUseApiManager.getInstance().closeConnection(1); } } else if (dump == DUMP) { System.out.println(e); @@ -250,7 +261,7 @@ public class Tests implements WiiUseApiListener { WiiUseApiManager.getInstance().deactivateMotionSensing(1); WiiUseApiManager.getInstance().deactivateRumble(1); } - + /* leave test */ if (e.isButtonHomeJustPressed()) { System.out.println("LEAVING TEST"); @@ -296,13 +307,13 @@ public class Tests implements WiiUseApiListener { int mousey = (int) Math.round(((double) y1 / 768.0) * 1024.0); robot.mouseMove(mousex, mousey); } - + /* leave test */ if (e.isButtonHomeJustPressed()) { System.out.println("LEAVING TEST"); - WiiUseApiManager.getInstance().closeConnection(1); + WiiUseApiManager.getInstance().closeConnection(1); } - }else if(dump == ORIENT_THRESH_CONT){ + } else if (dump == ORIENT_THRESH_CONT) { WiiUseApiManager.getInstance().activateMotionSensing(1); if (e.isButtonOneJustPressed()) { System.out.println("Continous activated"); @@ -326,35 +337,39 @@ public class Tests implements WiiUseApiListener { } if (e.isButtonMinusJustPressed()) { System.out.println("Threshold orientation 0.5 degrees"); - WiiUseApiManager.getInstance().setOrientationThreshold(1, (float)0.5); + WiiUseApiManager.getInstance().setOrientationThreshold(1, + (float) 0.5); } System.out.println(e); - - + /* leave test */ if (e.isButtonHomeJustPressed()) { System.out.println("LEAVING TEST"); - WiiUseApiManager.getInstance().closeConnection(1); + WiiUseApiManager.getInstance().closeConnection(1); } - }else if(dump == TEST_LEDS){ + } else if (dump == TEST_LEDS) { WiiUseApiManager.getInstance().activateMotionSensing(1); - if (e.isButtonUpJustPressed()) { - WiiUseApiManager.getInstance().setLeds(1, true, false, false, false); + if (e.isButtonUpJustPressed()) { + WiiUseApiManager.getInstance().setLeds(1, true, false, false, + false); } - if (e.isButtonDownJustPressed()) { - WiiUseApiManager.getInstance().setLeds(1, false, true, false, false); + if (e.isButtonDownJustPressed()) { + WiiUseApiManager.getInstance().setLeds(1, false, true, false, + false); } - if (e.isButtonLeftJustPressed()) { - WiiUseApiManager.getInstance().setLeds(1, false, false, true, false); + if (e.isButtonLeftJustPressed()) { + WiiUseApiManager.getInstance().setLeds(1, false, false, true, + false); } - if (e.isButtonRightJustPressed()) { - WiiUseApiManager.getInstance().setLeds(1, false, false, false, true); + if (e.isButtonRightJustPressed()) { + WiiUseApiManager.getInstance().setLeds(1, false, false, false, + true); } - + /* leave test */ if (e.isButtonHomeJustPressed()) { System.out.println("LEAVING TEST"); - WiiUseApiManager.getInstance().closeConnection(1); + WiiUseApiManager.getInstance().closeConnection(1); } } } @@ -369,8 +384,8 @@ public class Tests implements WiiUseApiListener { manager.loadLibrary(); manager.connectWiimotes(); manager.start(); -// java.util.Timer timer = new java.util.Timer(); -// timer.scheduleAtFixedRate(new LedsTask(), 0, 100); + // java.util.Timer timer = new java.util.Timer(); + // timer.scheduleAtFixedRate(new LedsTask(), 0, 100); } diff --git a/WiiUseJ/src/wiiusej/WiiMoteEvent.java b/WiiUseJ/src/wiiusej/WiiMoteEvent.java index 663298d..8e2ee7c 100644 --- a/WiiUseJ/src/wiiusej/WiiMoteEvent.java +++ b/WiiUseJ/src/wiiusej/WiiMoteEvent.java @@ -143,16 +143,6 @@ public class WiiMoteEvent { return batteryLevel; } - /** - * Set level battery. - * - * @param batteryLevel - * must be between 0 and 1 - */ - void setBatteryLevel(float batteryLevel) { - this.batteryLevel = batteryLevel; - } - /** * Get status of the leds . * @@ -162,15 +152,6 @@ public class WiiMoteEvent { return leds; } - /** - * Set Status of the leds. - * - * @param leds - */ - void setLeds(short leds) { - this.leds = leds; - } - /** * Tell if the speaker is enable for this wiimote * @@ -180,20 +161,6 @@ public class WiiMoteEvent { return isSpeakerEnabled; } - /** - * Set the flag for the speaker to "enabled" - */ - void setSpeakerEnabled() { - this.isSpeakerEnabled = true; - } - - /** - * Set the flag for the speaker to "disabled" - */ - void setSpeakerDisabled() { - this.isSpeakerEnabled = false; - } - /** * Tell if there is an attachment to the Wiimote * @@ -204,17 +171,25 @@ public class WiiMoteEvent { } /** - * Set the flag for the attachment to true + * Set battery level, leds, speaker state and attachment in one method. + * These method is called (and those variables are filled) only when a + * status has been requested on this wiimote. + * + * @param batt + * battery level + * @param led + * status of leds + * @param speak + * speakers status + * @param attach + * attachment status */ - void setThereIsAnAttachment() { - this.isThereAttachment = true; - } - - /** - * Set the flag for the attachment to false - */ - void setThereIsNoAttachment() { - this.isThereAttachment = false; + void setBatteryLedsSpeakerAttachment(float batt, short led, boolean speak, + boolean attach) { + this.batteryLevel = batt; + this.leds = led; + this.isSpeakerEnabled = speak; + this.isThereAttachment = attach; } /** @@ -226,13 +201,6 @@ public class WiiMoteEvent { return isRumbleActive; } - /** - * Set Rumble flag to Active. - */ - void setRumbleActive() { - this.isRumbleActive = true; - } - /** * Set Rumble flag to Inactive. */ @@ -249,16 +217,6 @@ public class WiiMoteEvent { return orientationThreshold; } - /** - * Set the orientation threshold. - * - * @param orientationThreshold - * the orientationThreshold to set - */ - void setOrientationThreshold(float orientationThreshold) { - this.orientationThreshold = orientationThreshold; - } - /** * Tell if the CONTINUOUS option is activated. * @@ -268,20 +226,6 @@ public class WiiMoteEvent { return isContinuousActive; } - /** - * Set the CONTINUOUS option active. - */ - void setContinuousActive() { - this.isContinuousActive = true; - } - - /** - * Set the CONTINUOUS option inactive. - */ - void setContinuousInactive() { - this.isContinuousActive = false; - } - /** * Tell if the option SMOOTHING is activated. * @@ -290,21 +234,7 @@ public class WiiMoteEvent { public boolean isSmoothingActive() { return isSmoothingActive; } - - /** - * Set SMOOTHING option to active. - */ - void setSmoothingActive() { - this.isSmoothingActive = true; - } - - /** - * Set SMOOTHING option to inactive. - */ - void setSmoothingInactive() { - this.isSmoothingActive = false; - } - + /** * Get the short storing the buttons just pressed * @@ -314,15 +244,6 @@ public class WiiMoteEvent { return buttonsJustPressed; } - /** - * set the short storing the buttons just pressed - * - * @param buttonsJustPressed - */ - void setButtonsJustPressed(short buttonsJustPressed) { - this.buttonsJustPressed = buttonsJustPressed; - } - /** * Get the short storing the buttons just released * @@ -332,15 +253,6 @@ public class WiiMoteEvent { return buttonsJustReleased; } - /** - * set the short storing the buttons just released - * - * @param buttonsJustReleased - */ - void setButtonsJustReleased(short buttonsJustReleased) { - this.buttonsJustReleased = buttonsJustReleased; - } - /** * get the short storing the buttons held * @@ -351,11 +263,16 @@ public class WiiMoteEvent { } /** - * set the short storing the buttons held + * Set all buttons in one method. * + * @param buttonsJustPressed + * @param buttonsJustReleased * @param buttonsHeld */ - void setButtonsHeld(short buttonsHeld) { + void setAllButtons(short buttonsJustPressed, short buttonsJustReleased, + short buttonsHeld) { + this.buttonsJustPressed = buttonsJustPressed; + this.buttonsJustReleased = buttonsJustReleased; this.buttonsHeld = buttonsHeld; } @@ -368,20 +285,6 @@ public class WiiMoteEvent { return isIrActive; } - /** - * Set the value isIrActive to true - */ - void setIrActive() { - this.isIrActive = true; - } - - /** - * Set the value isIrActive to true - */ - void setIrInactive() { - this.isIrActive = false; - } - /** * Get list of IR points. * @@ -428,19 +331,40 @@ public class WiiMoteEvent { } /** - * Set the motion sensing flag to active. + * Set status variables always filled during an event. + * + * @param id + * id of the wiimote + * @param connect + * true if the wiimote is connected + * @param irState + * true if ir is active + * @param rumbleState + * true if rumble is active + * @param motionSensingState + * true if accelerometer is active + * @param orientationThreshold + * value of the minimum angle between two events with the + * accelerometer + * @param continuousState + * true if continuous flag is activated + * @param smoothingState + * true if smoothing flag is activated */ - void setMotionSensingActive() { - this.isMotionSensingActive = true; + void setPermanentStatus(int id, boolean connect, boolean irState, + boolean rumbleState, boolean motionSensingState, + float orientationThreshold, boolean continuousState, + boolean smoothingState) { + wiimoteId = id; + connected = connect; + isIrActive = irState; + isRumbleActive = rumbleState; + isMotionSensingActive = motionSensingState; + this.orientationThreshold = orientationThreshold; + isContinuousActive = continuousState; + isSmoothingActive = smoothingState; } - - /** - * Set the motion sensing flag to inactive. - */ - void setMotionSensingInactive() { - this.isMotionSensingActive = false; - } - + /** * @return the orientation */ @@ -448,20 +372,6 @@ public class WiiMoteEvent { return orientation; } - /** - * Set orientation of the wiimote. - * - * @param r - * roll - * @param p - * pitch - * @param y - * yaw - */ - void setOrientation(float r, float p, float y) { - this.orientation = new Orientation(r, p, y); - } - /** * Get the gravity force. * @@ -472,8 +382,14 @@ public class WiiMoteEvent { } /** - * Set the gravity force. + * Set orientation and gravity force. * + * @param r + * roll + * @param p + * pitch + * @param ya + * yaw * @param x * gravity force on x axis * @param y @@ -481,7 +397,9 @@ public class WiiMoteEvent { * @param z * gravity force on z axis */ - void setGforce(float x, float y, float z) { + void setOrientationAndGforce(float r, float p, float ya, float x, float y, + float z) { + this.orientation = new Orientation(r, p, ya); this.gforce = new GForce(x, y, z); } @@ -667,7 +585,7 @@ public class WiiMoteEvent { out += "/*********** WIIMOTE ID :" + wiimoteId + " ********/\n"; out += "--- connected : " + connected + "\n"; out += "--- Battery level : " + batteryLevel + "\n"; - out += "= --- Leds : " + leds + "\n"; + out += "--- Leds : " + leds + "\n"; out += "--- Speaker enabled : " + isSpeakerEnabled + "\n"; out += "--- Attachment ? : " + isThereAttachment + "\n"; out += "--- Rumble ? : " + isRumbleActive + "\n"; diff --git a/WiiUseJ/src/wiiusej/WiiUseApiManager.java b/WiiUseJ/src/wiiusej/WiiUseApiManager.java index 178e0c4..b2e06e1 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApiManager.java +++ b/WiiUseJ/src/wiiusej/WiiUseApiManager.java @@ -338,32 +338,32 @@ public class WiiUseApiManager extends Thread { } /** - * - * @param listener + * Add WiiUseApiListener to the listeners list. + * @param listener a WiiUseApiListener */ public void addWiiUseApiListener(WiiUseApiListener listener) { listeners.add(WiiUseApiListener.class, listener); } /** - * - * @param listener + * Remove WiiUseApiListener from the listeners list. + * @param listener a WiiUseApiListener */ public void removeWiiUseApiListener(WiiUseApiListener listener) { listeners.remove(WiiUseApiListener.class, listener); } /** - * - * @return + * Get the list of WiiUseApiListeners. + * @return the list of WiiUseApiListeners. */ public WiiUseApiListener[] getWiiUseApiListeners() { return listeners.getListeners(WiiUseApiListener.class); } /** - * - * @param evt + * Notify WiiUseApiListeners that an event occured. + * @param evt WiimoteEvent occured */ public void notifyWiiUseApiListener(WiiMoteEvent evt) { for (WiiUseApiListener listener : getWiiUseApiListeners()) {