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
This commit is contained in:
guilhem.duche
2008-03-09 17:17:30 +00:00
parent 9e8c252b0c
commit d4783d698c
6 changed files with 146 additions and 176 deletions

View File

@@ -43,12 +43,11 @@ public class Tests implements WiimoteListener {
private static int DISPLAY_EACH_VALUE = 1; private static int DISPLAY_EACH_VALUE = 1;
private static int DUMP = 2; private static int DUMP = 2;
private static int MOVE_MOUSE = 3; private static int MOVE_MOUSE = 3;
private static int ORIENT_THRESH_CONT = 4;
private static int TEST_LEDS = 5; private static int TEST_LEDS = 5;
private Wiimote wiimote; private Wiimote wiimote;
int dump = DISPLAY_EACH_VALUE; int dump = DUMP;
public Tests(Wiimote wim) { public Tests(Wiimote wim) {
wiimote = wim; wiimote = wim;
@@ -232,13 +231,13 @@ public class Tests implements WiimoteListener {
System.out.println(e); System.out.println(e);
/* Activate all */ /* Activate all */
if (e.isButtonAJustPressed()) { if (e.isButtonAJustPressed()) {
System.out.println("IR Activated"); System.out.println("IR, rumble and motion sensing Activated");
wiimote.activateIRTRacking(); wiimote.activateIRTRacking();
wiimote.activateMotionSensing(); wiimote.activateMotionSensing();
wiimote.activateRumble(); wiimote.activateRumble();
} }
if (e.isButtonBJustPressed()) { if (e.isButtonBJustPressed()) {
System.out.println("IR Deactivated"); System.out.println("IR, rumble and motion sensing Deactivated");
wiimote.deactivateIRTRacking(); wiimote.deactivateIRTRacking();
wiimote.deactivateMotionSensing(); wiimote.deactivateMotionSensing();
wiimote.deactivateRumble(); wiimote.deactivateRumble();
@@ -276,42 +275,6 @@ public class Tests implements WiimoteListener {
robot.mouseRelease(InputEvent.BUTTON2_MASK); 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 */ /* leave test */
if (e.isButtonHomeJustPressed()) { if (e.isButtonHomeJustPressed()) {
System.out.println("LEAVING TEST"); System.out.println("LEAVING TEST");
@@ -342,11 +305,7 @@ public class Tests implements WiimoteListener {
} }
public void onIrEvent(IREvent e) { public void onIrEvent(IREvent e) {
if (dump == DISPLAY_EACH_VALUE) { if (dump == MOVE_MOUSE) {
System.out.println(e);
} else if (dump == DUMP) {
System.out.println(e);
} else if (dump == MOVE_MOUSE) {
IRSource[] list = e.getIRPoints(); IRSource[] list = e.getIRPoints();
if (list.length > 0) { if (list.length > 0) {
int x1 = (int) list[0].getX(); 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); int mousey = (int) Math.round(((double) y1 / 768.0) * 1024.0);
robot.mouseMove(mousex, mousey); robot.mouseMove(mousex, mousey);
} }
} else if (dump == ORIENT_THRESH_CONT) { } else {
System.out.println(e);
// @TODO add acceleration threshold test, add alpha smoothing test
} else if (dump == TEST_LEDS) {
wiimote.activateMotionSensing();
} }
System.out.println("");
} }
public void onMotionSensingEvent(MotionSensingEvent e) { public void onMotionSensingEvent(MotionSensingEvent e) {
@@ -376,10 +329,10 @@ public class Tests implements WiimoteListener {
// Display status variables // Display status variables
System.out.println(e); System.out.println(e);
} }
public void onDisconnectionEvent(DisconnectionEvent e) { public void onDisconnectionEvent(DisconnectionEvent e) {
System.out.println(e.getWiimoteId() System.out.println(" wiimote " + e.getWiimoteId()
+ " notify it's been disconnected !!"); + "has been disconnected !!");
} }
/** /**

View File

@@ -92,11 +92,11 @@ public class EventsGatherer {
* @param screenAsPectRatio * @param screenAsPectRatio
* IR sensor bar position. * IR sensor bar position.
*/ */
public void prepareIRevent(int x, int y, int z, int ax, int ay, public void prepareIRevent(int x, int y, int z, int ax, int ay, int xVRes,
int xVRes, int yVRes, int xOffset, int yOffset, int yVRes, int xOffset, int yOffset, short sensorBarPostion,
short sensorBarPostion, short screenAsPectRatio) { short screenAsPectRatio) {
genericEvent.prepareIRevent(x, y, z, ax, ay, xVRes, genericEvent.prepareIRevent(x, y, z, ax, ay, xVRes, yVRes, xOffset,
yVRes, xOffset, yOffset, sensorBarPostion, screenAsPectRatio); yOffset, sensorBarPostion, screenAsPectRatio);
} }
@@ -124,6 +124,16 @@ public class EventsGatherer {
/** /**
* Set orientation and gravity force of the prepared event. * 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 * @param r
* roll * roll
* @param p * @param p
@@ -143,10 +153,14 @@ public class EventsGatherer {
* @param zz * @param zz
* raw acceleration on z axis * raw acceleration on z axis
*/ */
public void addMotionSensingValues(float r, float p, float ya, float x, public void addMotionSensingValues(float orientationThreshold,
float y, float z, short xx, short yy, short zz) { 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) { 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 * attachment status
* @param rumbleState * @param rumbleState
* true if rumble is active * 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 * @param continuousState
* true if continuous flag is activated * true if continuous flag is activated
* @param smoothingState
* true if smoothing flag is activated
* @param irState * @param irState
* true if ir is active * true if ir is active
* @param motionSensingState * @param motionSensingState
@@ -196,13 +200,10 @@ public class EventsGatherer {
*/ */
public void addStatusEvent(int id, boolean connect, float batt, short led, public void addStatusEvent(int id, boolean connect, float batt, short led,
boolean speak, int attach, boolean rumbleState, boolean speak, int attach, boolean rumbleState,
float orientationThreshold, int accelerationThreshold, boolean continuousState, boolean irState, boolean motionSensingState) {
float alphaSmooth, boolean continuousState, boolean smoothingState,
boolean irState, boolean motionSensingState) {
StatusEvent evt = new StatusEvent(id, connect, batt, led, speak, StatusEvent evt = new StatusEvent(id, connect, batt, led, speak,
attach, rumbleState, orientationThreshold, attach, rumbleState, continuousState, irState,
accelerationThreshold, alphaSmooth, continuousState, motionSensingState);
smoothingState, irState, motionSensingState);
addEvent(evt); addEvent(evt);
} }

View File

@@ -100,7 +100,7 @@ public class GenericEvent extends WiiUseApiEvent {
public MotionSensingEvent getMotionSensingEvent() { public MotionSensingEvent getMotionSensingEvent() {
return motionSensingEvent; return motionSensingEvent;
} }
/** /**
* Prepare an IR event to populate. * Prepare an IR event to populate.
* *
@@ -160,6 +160,16 @@ public class GenericEvent extends WiiUseApiEvent {
/** /**
* Set the Motion Sensing Event. * 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 * @param r
* roll * roll
* @param p * @param p
@@ -179,10 +189,13 @@ public class GenericEvent extends WiiUseApiEvent {
* @param zz * @param zz
* raw acceleration on z axis * raw acceleration on z axis
*/ */
public void setMotionSensingEvent(float r, float p, float ya, float x, public void setMotionSensingEvent(float orientationThreshold,
float y, float z, short xx, short yy, short zz) { int accelerationThreshold, boolean smoothingState,
motionSensingEvent = new MotionSensingEvent(getWiimoteId(), r, p, ya, float alphaSmooth, float r, float p, float ya, float x, float y,
x, y, z, xx, yy, zz); 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 @Override

View File

@@ -279,6 +279,7 @@ public class IREvent extends WiimoteEvent {
out += IRPoints[i].toString(); out += IRPoints[i].toString();
} }
} }
out += "\n";
return out; return out;
} }
} }

View File

@@ -25,18 +25,33 @@ import wiiusej.values.RawAcceleration;
* *
* @author guiguito * @author guiguito
*/ */
public class MotionSensingEvent extends WiimoteEvent{ public class MotionSensingEvent extends WiimoteEvent {
/* Motion Sensing */ /* Motion Sensing */
private Orientation orientation; private Orientation orientation;
private GForce gforce; private GForce gforce;
private RawAcceleration acceleration; 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. * Constructor for a Motion Sensing Event.
* *
* @param id * @param id
* id of the wiimote concerned. * 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 * @param r
* roll * roll
* @param p * @param p
@@ -56,9 +71,15 @@ public class MotionSensingEvent extends WiimoteEvent{
* @param zz * @param zz
* raw acceleration on z axis * 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) { float z, short xx, short yy, short zz) {
super(id); super(id);
this.orientationThreshold = orientationThreshold;
this.accelerationThreshold = accelerationThreshold;
this.isSmoothingActive = smoothingState;
this.alphaSmoothing = alphaSmooth;
setOrientationAndGforce(r, p, ya, x, y, z, xx, yy, zz); setOrientationAndGforce(r, p, ya, x, y, z, xx, yy, zz);
} }
@@ -77,7 +98,7 @@ public class MotionSensingEvent extends WiimoteEvent{
* gravity force on y axis * gravity force on y axis
* @param z * @param z
* gravity force on z axis * gravity force on z axis
* @param xx * @param xx
* raw acceleration on x axis * raw acceleration on x axis
* @param yy * @param yy
* raw acceleration on y axis * raw acceleration on y axis
@@ -106,7 +127,7 @@ public class MotionSensingEvent extends WiimoteEvent{
public GForce getGforce() { public GForce getGforce() {
return gforce; return gforce;
} }
/** /**
* Get the raw acceleration. * Get the raw acceleration.
* *
@@ -116,12 +137,55 @@ public class MotionSensingEvent extends WiimoteEvent{
return acceleration; 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 @Override
public String toString() { public String toString() {
String out = ""; String out = "";
/* Motion sensing */ /* Motion sensing */
out += "/******** Motion sensing ********/\n"; out += "/******** Motion sensing ********/\n";
out += "--- Motion sensing : true \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 += "--- " + orientation + "\n";
out += "--- " + gforce + "\n"; out += "--- " + gforce + "\n";
out += "--- " + acceleration + "\n"; out += "--- " + acceleration + "\n";

View File

@@ -17,8 +17,9 @@
package wiiusej.wiiuseapievents; package wiiusej.wiiuseapievents;
/** /**
* Class used to represent a status event. * Class used to represent a status event. This class is used to know what are
* This class is used to know what are the settings of the wiimote. * the settings of the wiimote.
*
* @author guiguito * @author guiguito
*/ */
public class StatusEvent extends WiiUseApiEvent { public class StatusEvent extends WiiUseApiEvent {
@@ -29,7 +30,7 @@ public class StatusEvent extends WiiUseApiEvent {
private static short WIIMOTE_LED_4 = 8; private static short WIIMOTE_LED_4 = 8;
/* ATTACHMENT CONSTANTS */ /* ATTACHMENT CONSTANTS */
private static short EXP_NONE = 0; private static short EXP_NONE = 0;
private static short EXP_NUNCHUK = 1; private static short EXP_NUNCHUK = 1;
private static short EXP_CLASSIC = 2; private static short EXP_CLASSIC = 2;
@@ -48,16 +49,8 @@ public class StatusEvent extends WiiUseApiEvent {
private boolean isRumbleActive = false; private boolean isRumbleActive = false;
private float orientationThreshold = 0;
private int accelerationThreshold = 0;
private float alphaSmoothing = 0;
private boolean isContinuousActive = false; private boolean isContinuousActive = false;
private boolean isSmoothingActive = false;
private boolean isIrActive = false; private boolean isIrActive = false;
private boolean isMotionSensingActive = false; private boolean isMotionSensingActive = false;
@@ -89,18 +82,8 @@ public class StatusEvent extends WiiUseApiEvent {
* attachment status * attachment status
* @param rumbleState * @param rumbleState
* true if rumble is active * 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 * @param continuousState
* true if continuous flag is activated * true if continuous flag is activated
* @param smoothingState
* true if smoothing flag is activated
* @param irState * @param irState
* true if ir is active * true if ir is active
* @param motionSensingState * @param motionSensingState
@@ -108,9 +91,7 @@ public class StatusEvent extends WiiUseApiEvent {
*/ */
public StatusEvent(int id, boolean connect, float batt, short led, public StatusEvent(int id, boolean connect, float batt, short led,
boolean speak, int attach, boolean rumbleState, boolean speak, int attach, boolean rumbleState,
float orientationThreshold, int accelerationThreshold, boolean continuousState, boolean irState, boolean motionSensingState) {
float alphaSmooth, boolean continuousState, boolean smoothingState,
boolean irState, boolean motionSensingState) {
super(id, WiiUseApiEvent.STATUS_EVENT); super(id, WiiUseApiEvent.STATUS_EVENT);
connected = connect; connected = connect;
this.batteryLevel = batt; this.batteryLevel = batt;
@@ -118,11 +99,7 @@ public class StatusEvent extends WiiUseApiEvent {
this.isSpeakerEnabled = speak; this.isSpeakerEnabled = speak;
this.attachment = attach; this.attachment = attach;
isRumbleActive = rumbleState; isRumbleActive = rumbleState;
this.orientationThreshold = orientationThreshold;
this.accelerationThreshold = accelerationThreshold;
alphaSmoothing = alphaSmooth;
isContinuousActive = continuousState; isContinuousActive = continuousState;
isSmoothingActive = smoothingState;
isIrActive = irState; isIrActive = irState;
isMotionSensingActive = motionSensingState; isMotionSensingActive = motionSensingState;
} }
@@ -153,51 +130,55 @@ public class StatusEvent extends WiiUseApiEvent {
public short getLeds() { public short getLeds() {
return leds; return leds;
} }
/** /**
* Get led1 status. * Get led1 status.
*
* @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){ if ((leds & WIIMOTE_LED_1) > 0) {
return true; return true;
}else{ } else {
return false; return false;
} }
} }
/** /**
* Get led2 status. * Get led2 status.
*
* @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){ if ((leds & WIIMOTE_LED_2) > 0) {
return true; return true;
}else{ } else {
return false; return false;
} }
} }
/** /**
* Get led3 status. * Get led3 status.
*
* @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){ if ((leds & WIIMOTE_LED_3) > 0) {
return true; return true;
}else{ } else {
return false; return false;
} }
} }
/** /**
* Get led4 status. * Get led4 status.
*
* @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){ if ((leds & WIIMOTE_LED_4) > 0) {
return true; return true;
}else{ } else {
return false; return false;
} }
} }
@@ -229,33 +210,6 @@ public class StatusEvent extends WiiUseApiEvent {
return isRumbleActive; 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. * Tell if the CONTINUOUS option is activated.
* *
@@ -265,15 +219,6 @@ public class StatusEvent extends WiiUseApiEvent {
return isContinuousActive; return isContinuousActive;
} }
/**
* Tell if the option SMOOTHING is activated.
*
* @return the isSmoothingActive
*/
public boolean isSmoothingActive() {
return isSmoothingActive;
}
/** /**
* Tell if the IR Tracking is active. * Tell if the IR Tracking is active.
* *
@@ -304,14 +249,7 @@ public class StatusEvent extends WiiUseApiEvent {
out += "--- Speaker enabled : " + isSpeakerEnabled + "\n"; out += "--- Speaker enabled : " + isSpeakerEnabled + "\n";
out += "--- Attachment ? : " + attachment + "\n"; out += "--- Attachment ? : " + attachment + "\n";
out += "--- Rumble ? : " + isRumbleActive + "\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 += "--- Continuous ? : " + isContinuousActive + "\n";
out += "--- Smoothing ? : " + isSmoothingActive + "\n";
out += "--- IR active ? : " + isIrActive + "\n"; out += "--- IR active ? : " + isIrActive + "\n";
out += "--- Motion sensing active ? : " + isMotionSensingActive + "\n"; out += "--- Motion sensing active ? : " + isMotionSensingActive + "\n";
return out; return out;