From d4783d698c6116359ef0390975cc44471e403ecf Mon Sep 17 00:00:00 2001 From: "guilhem.duche" Date: Sun, 9 Mar 2008 17:17:30 +0000 Subject: [PATCH] moved some stuff from status events to motion sensing events git-svn-id: http://wiiusej.googlecode.com/svn/trunk@78 ae48ae66-6a45-0410-b38e-211266189506 --- WiiUseJ/src/wiiusej/test/Tests.java | 65 ++-------- .../wiiuseapievents/EventsGatherer.java | 49 ++++---- .../wiiusej/wiiuseapievents/GenericEvent.java | 23 +++- .../src/wiiusej/wiiuseapievents/IREvent.java | 1 + .../wiiuseapievents/MotionSensingEvent.java | 72 ++++++++++- .../wiiusej/wiiuseapievents/StatusEvent.java | 112 ++++-------------- 6 files changed, 146 insertions(+), 176 deletions(-) diff --git a/WiiUseJ/src/wiiusej/test/Tests.java b/WiiUseJ/src/wiiusej/test/Tests.java index 6926be0..c24ce9d 100644 --- a/WiiUseJ/src/wiiusej/test/Tests.java +++ b/WiiUseJ/src/wiiusej/test/Tests.java @@ -43,12 +43,11 @@ public class Tests implements WiimoteListener { private static int DISPLAY_EACH_VALUE = 1; private static int DUMP = 2; private static int MOVE_MOUSE = 3; - private static int ORIENT_THRESH_CONT = 4; private static int TEST_LEDS = 5; private Wiimote wiimote; - int dump = DISPLAY_EACH_VALUE; + int dump = DUMP; public Tests(Wiimote wim) { wiimote = wim; @@ -232,13 +231,13 @@ public class Tests implements WiimoteListener { System.out.println(e); /* Activate all */ if (e.isButtonAJustPressed()) { - System.out.println("IR Activated"); + System.out.println("IR, rumble and motion sensing Activated"); wiimote.activateIRTRacking(); wiimote.activateMotionSensing(); wiimote.activateRumble(); } if (e.isButtonBJustPressed()) { - System.out.println("IR Deactivated"); + System.out.println("IR, rumble and motion sensing Deactivated"); wiimote.deactivateIRTRacking(); wiimote.deactivateMotionSensing(); wiimote.deactivateRumble(); @@ -276,42 +275,6 @@ public class Tests implements WiimoteListener { robot.mouseRelease(InputEvent.BUTTON2_MASK); } - /* leave test */ - if (e.isButtonHomeJustPressed()) { - System.out.println("LEAVING TEST"); - wiimote.disconnect(); - } - } else if (dump == ORIENT_THRESH_CONT) { - wiimote.activateMotionSensing(); - if (e.isButtonOneJustPressed()) { - System.out.println("Continous activated"); - wiimote.activateContinuous(); - } - if (e.isButtonTwoJustPressed()) { - System.out.println("Continous deactivated"); - wiimote.deactivateContinuous(); - } - if (e.isButtonAJustPressed()) { - System.out.println("Smoothing activated"); - wiimote.activateSmoothing(); - } - if (e.isButtonBJustPressed()) { - System.out.println("Smoothing deactivated"); - wiimote.deactivateSmoothing(); - } - if (e.isButtonPlusJustPressed()) { - System.out.println("Threshold orientation 10 degrees"); - wiimote.setOrientationThreshold(10); - } - if (e.isButtonMinusJustPressed()) { - System.out.println("Threshold orientation 0.5 degrees"); - wiimote.setOrientationThreshold((float) 0.5); - } - - // @TODO add accelereation threshold test, add alpha smoothing test - - System.out.println(e); - /* leave test */ if (e.isButtonHomeJustPressed()) { System.out.println("LEAVING TEST"); @@ -342,11 +305,7 @@ public class Tests implements WiimoteListener { } public void onIrEvent(IREvent e) { - if (dump == DISPLAY_EACH_VALUE) { - System.out.println(e); - } else if (dump == DUMP) { - System.out.println(e); - } else if (dump == MOVE_MOUSE) { + if (dump == MOVE_MOUSE) { IRSource[] list = e.getIRPoints(); if (list.length > 0) { int x1 = (int) list[0].getX(); @@ -356,15 +315,9 @@ public class Tests implements WiimoteListener { int mousey = (int) Math.round(((double) y1 / 768.0) * 1024.0); robot.mouseMove(mousex, mousey); } - } else if (dump == ORIENT_THRESH_CONT) { - - // @TODO add acceleration threshold test, add alpha smoothing test - } else if (dump == TEST_LEDS) { - wiimote.activateMotionSensing(); - + } else { + System.out.println(e); } - - System.out.println(""); } public void onMotionSensingEvent(MotionSensingEvent e) { @@ -376,10 +329,10 @@ public class Tests implements WiimoteListener { // Display status variables System.out.println(e); } - + public void onDisconnectionEvent(DisconnectionEvent e) { - System.out.println(e.getWiimoteId() - + " notify it's been disconnected !!"); + System.out.println(" wiimote " + e.getWiimoteId() + + "has been disconnected !!"); } /** diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java b/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java index 7fcb57c..b83c33e 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java @@ -92,11 +92,11 @@ public class EventsGatherer { * @param screenAsPectRatio * IR sensor bar position. */ - 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) { - genericEvent.prepareIRevent(x, y, z, ax, ay, xVRes, - yVRes, xOffset, yOffset, sensorBarPostion, screenAsPectRatio); + 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) { + genericEvent.prepareIRevent(x, y, z, ax, ay, xVRes, yVRes, xOffset, + yOffset, sensorBarPostion, screenAsPectRatio); } @@ -124,6 +124,16 @@ public class EventsGatherer { /** * Set orientation and gravity force of the prepared event. * + * @param orientationThreshold + * value of the minimum angle between two events with the + * accelerometer + * @param accelerationThreshold + * value of the value variation between two events with the + * accelerometer + * @param smoothingState + * true if smoothing flag is activated + * @param alphaSmooth + * value of the alpha smoothing parameter * @param r * roll * @param p @@ -143,10 +153,14 @@ public class EventsGatherer { * @param zz * raw acceleration on z axis */ - public void addMotionSensingValues(float r, float p, float ya, float x, - float y, float z, short xx, short yy, short zz) { + public void addMotionSensingValues(float orientationThreshold, + int accelerationThreshold, boolean smoothingState, + float alphaSmooth, float r, float p, float ya, float x, float y, + float z, short xx, short yy, short zz) { if (genericEvent != null) { - genericEvent.setMotionSensingEvent(r, p, ya, x, y, z, xx, yy, zz); + genericEvent.setMotionSensingEvent(orientationThreshold, + accelerationThreshold, smoothingState, alphaSmooth, r, p, + ya, x, y, z, xx, yy, zz); } } @@ -177,18 +191,8 @@ public class EventsGatherer { * attachment status * @param rumbleState * true if rumble is active - * @param orientationThreshold - * value of the minimum angle between two events with the - * accelerometer - * @param accelerationThreshold - * value of the value variation between two events with the - * accelerometer - * @param alphaSmooth - * value of the alpha smoothing parameter * @param continuousState * true if continuous flag is activated - * @param smoothingState - * true if smoothing flag is activated * @param irState * true if ir is active * @param motionSensingState @@ -196,13 +200,10 @@ public class EventsGatherer { */ public void addStatusEvent(int id, boolean connect, float batt, short led, boolean speak, int attach, boolean rumbleState, - float orientationThreshold, int accelerationThreshold, - float alphaSmooth, boolean continuousState, boolean smoothingState, - boolean irState, boolean motionSensingState) { + boolean continuousState, boolean irState, boolean motionSensingState) { StatusEvent evt = new StatusEvent(id, connect, batt, led, speak, - attach, rumbleState, orientationThreshold, - accelerationThreshold, alphaSmooth, continuousState, - smoothingState, irState, motionSensingState); + attach, rumbleState, continuousState, irState, + motionSensingState); addEvent(evt); } diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java index 0671ff8..9a7e31e 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java @@ -100,7 +100,7 @@ public class GenericEvent extends WiiUseApiEvent { public MotionSensingEvent getMotionSensingEvent() { return motionSensingEvent; } - + /** * Prepare an IR event to populate. * @@ -160,6 +160,16 @@ public class GenericEvent extends WiiUseApiEvent { /** * Set the Motion Sensing Event. * + * @param orientationThreshold + * value of the minimum angle between two events with the + * accelerometer + * @param accelerationThreshold + * value of the value variation between two events with the + * accelerometer + * @param smoothingState + * true if smoothing flag is activated + * @param alphaSmooth + * value of the alpha smoothing parameter * @param r * roll * @param p @@ -179,10 +189,13 @@ public class GenericEvent extends WiiUseApiEvent { * @param zz * raw acceleration on z axis */ - public void setMotionSensingEvent(float r, float p, float ya, float x, - float y, float z, short xx, short yy, short zz) { - motionSensingEvent = new MotionSensingEvent(getWiimoteId(), r, p, ya, - x, y, z, xx, yy, zz); + public void setMotionSensingEvent(float orientationThreshold, + int accelerationThreshold, boolean smoothingState, + float alphaSmooth, float r, float p, float ya, float x, float y, + float z, short xx, short yy, short zz) { + motionSensingEvent = new MotionSensingEvent(getWiimoteId(), + orientationThreshold, accelerationThreshold, smoothingState, + alphaSmooth, r, p, ya, x, y, z, xx, yy, zz); } @Override diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java index 9950327..4a99b1c 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java @@ -279,6 +279,7 @@ public class IREvent extends WiimoteEvent { out += IRPoints[i].toString(); } } + out += "\n"; return out; } } diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/MotionSensingEvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/MotionSensingEvent.java index c15127d..6ec7712 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/MotionSensingEvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/MotionSensingEvent.java @@ -25,18 +25,33 @@ import wiiusej.values.RawAcceleration; * * @author guiguito */ -public class MotionSensingEvent extends WiimoteEvent{ +public class MotionSensingEvent extends WiimoteEvent { /* Motion Sensing */ private Orientation orientation; private GForce gforce; private RawAcceleration acceleration; + private float orientationThreshold = 0; + private int accelerationThreshold = 0; + private float alphaSmoothing = 0; + private boolean isSmoothingActive = false; + /** * Constructor for a Motion Sensing Event. * * @param id * id of the wiimote concerned. + * @param orientationThreshold + * value of the minimum angle between two events with the + * accelerometer + * @param accelerationThreshold + * value of the value variation between two events with the + * accelerometer + * @param smoothingState + * true if smoothing flag is activated + * @param alphaSmooth + * value of the alpha smoothing parameter * @param r * roll * @param p @@ -56,9 +71,15 @@ public class MotionSensingEvent extends WiimoteEvent{ * @param zz * raw acceleration on z axis */ - public MotionSensingEvent(int id, float r, float p, float ya, float x, float y, + public MotionSensingEvent(int id, float orientationThreshold, + int accelerationThreshold, boolean smoothingState, + float alphaSmooth, float r, float p, float ya, float x, float y, float z, short xx, short yy, short zz) { super(id); + this.orientationThreshold = orientationThreshold; + this.accelerationThreshold = accelerationThreshold; + this.isSmoothingActive = smoothingState; + this.alphaSmoothing = alphaSmooth; setOrientationAndGforce(r, p, ya, x, y, z, xx, yy, zz); } @@ -77,7 +98,7 @@ public class MotionSensingEvent extends WiimoteEvent{ * gravity force on y axis * @param z * gravity force on z axis - * @param xx + * @param xx * raw acceleration on x axis * @param yy * raw acceleration on y axis @@ -106,7 +127,7 @@ public class MotionSensingEvent extends WiimoteEvent{ public GForce getGforce() { return gforce; } - + /** * Get the raw acceleration. * @@ -116,12 +137,55 @@ public class MotionSensingEvent extends WiimoteEvent{ return acceleration; } + /** + * Get orientation threshold. + * + * @return the orientationThreshold + */ + public float getOrientationThreshold() { + return orientationThreshold; + } + + /** + * Get acceleration threshold. + * + * @return the accelerationThreshold + */ + public int getAccelerationThreshold() { + return accelerationThreshold; + } + + /** + * Get alpha smoothing. + * + * @return the alphaSmoothing + */ + public float getAlphaSmoothing() { + return alphaSmoothing; + } + + /** + * Tell if the option SMOOTHING is activated. + * + * @return the isSmoothingActive + */ + public boolean isSmoothingActive() { + return isSmoothingActive; + } + @Override public String toString() { String out = ""; /* Motion sensing */ out += "/******** Motion sensing ********/\n"; out += "--- Motion sensing : true \n"; + out += "--- Orientation threshold value ? : " + orientationThreshold + + "\n"; + out += "--- Acceleration threshold value ? : " + accelerationThreshold + + "\n"; + out += "--- Alpha smoothing threshold value ? : " + alphaSmoothing + + "\n"; + out += "--- Smoothing ? : " + isSmoothingActive + "\n"; out += "--- " + orientation + "\n"; out += "--- " + gforce + "\n"; out += "--- " + acceleration + "\n"; diff --git a/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java b/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java index 7367ced..7a365fc 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java +++ b/WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java @@ -17,8 +17,9 @@ package wiiusej.wiiuseapievents; /** - * Class used to represent a status event. - * This class is used to know what are the settings of the wiimote. + * Class used to represent a status event. This class is used to know what are + * the settings of the wiimote. + * * @author guiguito */ public class StatusEvent extends WiiUseApiEvent { @@ -29,7 +30,7 @@ public class StatusEvent extends WiiUseApiEvent { private static short WIIMOTE_LED_4 = 8; /* ATTACHMENT CONSTANTS */ - + private static short EXP_NONE = 0; private static short EXP_NUNCHUK = 1; private static short EXP_CLASSIC = 2; @@ -48,16 +49,8 @@ public class StatusEvent extends WiiUseApiEvent { private boolean isRumbleActive = false; - private float orientationThreshold = 0; - - private int accelerationThreshold = 0; - - private float alphaSmoothing = 0; - private boolean isContinuousActive = false; - private boolean isSmoothingActive = false; - private boolean isIrActive = false; private boolean isMotionSensingActive = false; @@ -89,18 +82,8 @@ public class StatusEvent extends WiiUseApiEvent { * attachment status * @param rumbleState * true if rumble is active - * @param orientationThreshold - * value of the minimum angle between two events with the - * accelerometer - * @param accelerationThreshold - * value of the value variation between two events with the - * accelerometer - * @param alphaSmooth - * value of the alpha smoothing parameter * @param continuousState * true if continuous flag is activated - * @param smoothingState - * true if smoothing flag is activated * @param irState * true if ir is active * @param motionSensingState @@ -108,9 +91,7 @@ public class StatusEvent extends WiiUseApiEvent { */ public StatusEvent(int id, boolean connect, float batt, short led, boolean speak, int attach, boolean rumbleState, - float orientationThreshold, int accelerationThreshold, - float alphaSmooth, boolean continuousState, boolean smoothingState, - boolean irState, boolean motionSensingState) { + boolean continuousState, boolean irState, boolean motionSensingState) { super(id, WiiUseApiEvent.STATUS_EVENT); connected = connect; this.batteryLevel = batt; @@ -118,11 +99,7 @@ public class StatusEvent extends WiiUseApiEvent { this.isSpeakerEnabled = speak; this.attachment = attach; isRumbleActive = rumbleState; - this.orientationThreshold = orientationThreshold; - this.accelerationThreshold = accelerationThreshold; - alphaSmoothing = alphaSmooth; isContinuousActive = continuousState; - isSmoothingActive = smoothingState; isIrActive = irState; isMotionSensingActive = motionSensingState; } @@ -153,51 +130,55 @@ public class StatusEvent extends WiiUseApiEvent { public short getLeds() { return leds; } - + /** * Get led1 status. + * * @return true if the led is set. */ - public boolean isLed1Set(){ - if ((leds & WIIMOTE_LED_1) > 0){ + public boolean isLed1Set() { + if ((leds & WIIMOTE_LED_1) > 0) { return true; - }else{ + } else { return false; } } - + /** * Get led2 status. + * * @return true if the led is set. */ - public boolean isLed2Set(){ - if ((leds & WIIMOTE_LED_2) > 0){ + public boolean isLed2Set() { + if ((leds & WIIMOTE_LED_2) > 0) { return true; - }else{ + } else { return false; } } - + /** * Get led3 status. + * * @return true if the led is set. */ - public boolean isLed3Set(){ - if ((leds & WIIMOTE_LED_3) > 0){ + public boolean isLed3Set() { + if ((leds & WIIMOTE_LED_3) > 0) { return true; - }else{ + } else { return false; } } - + /** * Get led4 status. + * * @return true if the led is set. */ - public boolean isLed4Set(){ - if ((leds & WIIMOTE_LED_4) > 0){ + public boolean isLed4Set() { + if ((leds & WIIMOTE_LED_4) > 0) { return true; - }else{ + } else { return false; } } @@ -229,33 +210,6 @@ public class StatusEvent extends WiiUseApiEvent { return isRumbleActive; } - /** - * Get orientation threshold. - * - * @return the orientationThreshold - */ - public float getOrientationThreshold() { - return orientationThreshold; - } - - /** - * Get acceleration threshold. - * - * @return the accelerationThreshold - */ - public int getAccelerationThreshold() { - return accelerationThreshold; - } - - /** - * Get alpha smoothing. - * - * @return the alphaSmoothing - */ - public float getAlphaSmoothing() { - return alphaSmoothing; - } - /** * Tell if the CONTINUOUS option is activated. * @@ -265,15 +219,6 @@ public class StatusEvent extends WiiUseApiEvent { return isContinuousActive; } - /** - * Tell if the option SMOOTHING is activated. - * - * @return the isSmoothingActive - */ - public boolean isSmoothingActive() { - return isSmoothingActive; - } - /** * Tell if the IR Tracking is active. * @@ -304,14 +249,7 @@ public class StatusEvent extends WiiUseApiEvent { out += "--- Speaker enabled : " + isSpeakerEnabled + "\n"; out += "--- Attachment ? : " + attachment + "\n"; out += "--- Rumble ? : " + isRumbleActive + "\n"; - out += "--- Orientation threshold value ? : " + orientationThreshold - + "\n"; - out += "--- Acceleration threshold value ? : " + accelerationThreshold - + "\n"; - out += "--- Alpha smoothing threshold value ? : " + alphaSmoothing - + "\n"; out += "--- Continuous ? : " + isContinuousActive + "\n"; - out += "--- Smoothing ? : " + isSmoothingActive + "\n"; out += "--- IR active ? : " + isIrActive + "\n"; out += "--- Motion sensing active ? : " + isMotionSensingActive + "\n"; return out;