diff --git a/src/main/java/org/wiigee/device/Device.java b/src/main/java/org/wiigee/device/Device.java index 796b952..56bc3b3 100644 --- a/src/main/java/org/wiigee/device/Device.java +++ b/src/main/java/org/wiigee/device/Device.java @@ -175,7 +175,7 @@ public class Device { // don't need to create an event if filtered away if (vector != null) { - // calculate the absolute value for the accelerationevent + // calculate the absolute value for the accelerationevent double absvalue = Math.sqrt((vector[0] * vector[0]) + (vector[1] * vector[1]) + (vector[2] * vector[2])); @@ -190,7 +190,7 @@ public class Device { /** Fires a button pressed event. * @param button - * Integer value of the pressed button. + * Integer value of the pressed button. */ public void fireButtonPressedEvent(int button) { ButtonPressedEvent w = new ButtonPressedEvent(this, button); diff --git a/src/main/java/org/wiigee/event/AccelerationEvent.java b/src/main/java/org/wiigee/event/AccelerationEvent.java index 2f54741..8483ba5 100644 --- a/src/main/java/org/wiigee/event/AccelerationEvent.java +++ b/src/main/java/org/wiigee/event/AccelerationEvent.java @@ -38,42 +38,42 @@ import org.wiigee.device.*; * */ public class AccelerationEvent extends EventObject { - - double X, Y, Z; - double absvalue; - - /** - * Create an AccelerationEvent with a specific source, - * all the three acceleration values and the calculated absolute - * value. - * - * @param source The source which has been accelerated (Wiimote). - * @param X The value of acceleration in the x direction. - * @param Y The value of acceleration in the y direction. - * @param Z The value of acceleration in the z direction. - * @param absvalue The absolute value of this acceleration vector. - */ - public AccelerationEvent(Device source, double X, double Y, double Z, double absvalue) { - super(source); - this.X=X; - this.Y=Y; - this.Z=Z; - this.absvalue=absvalue; - } + + double X, Y, Z; + double absvalue; + + /** + * Create an AccelerationEvent with a specific source, + * all the three acceleration values and the calculated absolute + * value. + * + * @param source The source which has been accelerated (Wiimote). + * @param X The value of acceleration in the x direction. + * @param Y The value of acceleration in the y direction. + * @param Z The value of acceleration in the z direction. + * @param absvalue The absolute value of this acceleration vector. + */ + public AccelerationEvent(Device source, double X, double Y, double Z, double absvalue) { + super(source); + this.X=X; + this.Y=Y; + this.Z=Z; + this.absvalue=absvalue; + } - public double getX() { - return X; - } + public double getX() { + return X; + } - public double getY() { - return Y; - } + public double getY() { + return Y; + } - public double getZ() { - return Z; - } - - public double getAbsValue() { - return absvalue; - } + public double getZ() { + return Z; + } + + public double getAbsValue() { + return absvalue; + } } diff --git a/src/main/java/org/wiigee/event/AccelerationListener.java b/src/main/java/org/wiigee/event/AccelerationListener.java index e70707a..f75b7d7 100644 --- a/src/main/java/org/wiigee/event/AccelerationListener.java +++ b/src/main/java/org/wiigee/event/AccelerationListener.java @@ -34,32 +34,32 @@ import java.util.EventListener; * @author Benjamin 'BePo' Poppinga */ public interface AccelerationListener extends EventListener { - - /** - * This method would be called if a Device source has been accelerated. - * - * @param event The acceleration representation as an event. - */ - public abstract void accelerationReceived(AccelerationEvent event); - - /** - * This method would be called if a Device is in idle state and then a - * motion starts or if a Device is in motion and then the motion stops and - * the Device is in idle state. - * - * @param event This is the event which contains if the Wiimote is now - * in motion or not. - */ - public abstract void motionStartReceived(MotionStartEvent event); - - /** - * This method would be called if a Device is in motion and then the motion - * stops and the Device is in idle state. - * - * @param event This is the event which contains if the Device is now - * in motion or not. - */ - public abstract void motionStopReceived(MotionStopEvent event); - + + /** + * This method would be called if a Device source has been accelerated. + * + * @param event The acceleration representation as an event. + */ + public abstract void accelerationReceived(AccelerationEvent event); + + /** + * This method would be called if a Device is in idle state and then a + * motion starts or if a Device is in motion and then the motion stops and + * the Device is in idle state. + * + * @param event This is the event which contains if the Wiimote is now + * in motion or not. + */ + public abstract void motionStartReceived(MotionStartEvent event); + + /** + * This method would be called if a Device is in motion and then the motion + * stops and the Device is in idle state. + * + * @param event This is the event which contains if the Device is now + * in motion or not. + */ + public abstract void motionStopReceived(MotionStopEvent event); + } diff --git a/src/main/java/org/wiigee/event/ActionStartEvent.java b/src/main/java/org/wiigee/event/ActionStartEvent.java index 9cdfab8..60a4d14 100644 --- a/src/main/java/org/wiigee/event/ActionStartEvent.java +++ b/src/main/java/org/wiigee/event/ActionStartEvent.java @@ -37,48 +37,48 @@ import org.wiigee.device.Device; */ public class ActionStartEvent extends EventObject { - protected boolean trainbutton; - protected boolean recognitionbutton; - protected boolean closegesturebutton; - - public ActionStartEvent(Device source) { - super(source); - } - - /** - * Is true if this button press has been done by the - * individual defined RecognitionButton which has to be - * set during initialization of a Wiimote. - * - * @return Is this button press initiated by the recognition button. - * @see device.Wiimote#setRecognitionButton(int) setRecognitionButton() - */ - public boolean isRecognitionInitEvent() { - return this.recognitionbutton; - } - - /** - * Is true if this button press has been done by the - * individual defined TrainButton which has to be - * set during initialization of a Wiimote. - * - * @return Is this button pres initiated by the training button. - * @see device.Wiimote#setTrainButton(int) setTrainButton() - */ - public boolean isTrainInitEvent() { - return this.trainbutton; - } - - /** - * Is true if this button press has been done by the - * individual defined CloseGestureButton which has to be - * set during initialization of a Wiimote. - * - * @return Is this button press initiated by the close gesture button. - * @see device.Wiimote#setCloseGestureButton(int) setCloseGestureButton() - */ - public boolean isCloseGestureInitEvent() { - return this.closegesturebutton; - } + protected boolean trainbutton; + protected boolean recognitionbutton; + protected boolean closegesturebutton; + + public ActionStartEvent(Device source) { + super(source); + } + + /** + * Is true if this button press has been done by the + * individual defined RecognitionButton which has to be + * set during initialization of a Wiimote. + * + * @return Is this button press initiated by the recognition button. + * @see device.Wiimote#setRecognitionButton(int) setRecognitionButton() + */ + public boolean isRecognitionInitEvent() { + return this.recognitionbutton; + } + + /** + * Is true if this button press has been done by the + * individual defined TrainButton which has to be + * set during initialization of a Wiimote. + * + * @return Is this button pres initiated by the training button. + * @see device.Wiimote#setTrainButton(int) setTrainButton() + */ + public boolean isTrainInitEvent() { + return this.trainbutton; + } + + /** + * Is true if this button press has been done by the + * individual defined CloseGestureButton which has to be + * set during initialization of a Wiimote. + * + * @return Is this button press initiated by the close gesture button. + * @see device.Wiimote#setCloseGestureButton(int) setCloseGestureButton() + */ + public boolean isCloseGestureInitEvent() { + return this.closegesturebutton; + } } diff --git a/src/main/java/org/wiigee/event/ActionStopEvent.java b/src/main/java/org/wiigee/event/ActionStopEvent.java index c4379e2..400bdb6 100644 --- a/src/main/java/org/wiigee/event/ActionStopEvent.java +++ b/src/main/java/org/wiigee/event/ActionStopEvent.java @@ -35,9 +35,9 @@ import org.wiigee.device.Device; * @author Benjamin 'BePo' Poppinga */ public class ActionStopEvent extends EventObject { - - public ActionStopEvent(Device source) { - super(source); - } + + public ActionStopEvent(Device source) { + super(source); + } } diff --git a/src/main/java/org/wiigee/event/ButtonListener.java b/src/main/java/org/wiigee/event/ButtonListener.java index 296c6ae..b2bbf0e 100644 --- a/src/main/java/org/wiigee/event/ButtonListener.java +++ b/src/main/java/org/wiigee/event/ButtonListener.java @@ -35,20 +35,20 @@ import java.util.EventListener; public interface ButtonListener extends EventListener { - /** - * This method would be called if a Device button has been pressed. - * - * @param event The button representation as an event. - */ - public abstract void buttonPressReceived(ButtonPressedEvent event); + /** + * This method would be called if a Device button has been pressed. + * + * @param event The button representation as an event. + */ + public abstract void buttonPressReceived(ButtonPressedEvent event); - /** - * This method would be called if a Device button has been released. - * - * @param event This is actually a meta-event NOT containing which button - * has been released. - */ - public abstract void buttonReleaseReceived(ButtonReleasedEvent event); + /** + * This method would be called if a Device button has been released. + * + * @param event This is actually a meta-event NOT containing which button + * has been released. + */ + public abstract void buttonReleaseReceived(ButtonReleasedEvent event); } diff --git a/src/main/java/org/wiigee/event/ButtonPressedEvent.java b/src/main/java/org/wiigee/event/ButtonPressedEvent.java index 36d54a4..ff9d55f 100644 --- a/src/main/java/org/wiigee/event/ButtonPressedEvent.java +++ b/src/main/java/org/wiigee/event/ButtonPressedEvent.java @@ -37,44 +37,44 @@ import org.wiigee.device.*; * @author Benjamin 'BePo' Poppinga */ public class ButtonPressedEvent extends ActionStartEvent { - - // Fixed number values. - public static final int BUTTON_2 = 1; - public static final int BUTTON_1 = 2; - public static final int BUTTON_B = 3; - public static final int BUTTON_A = 4; - public static final int BUTTON_MINUS = 5; - public static final int BUTTON_HOME = 8; - public static final int BUTTON_LEFT = 9; - public static final int BUTTON_RIGHT = 10; - public static final int BUTTON_DOWN = 11; - public static final int BUTTON_UP = 12; - public static final int BUTTON_PLUS = 13; - - int button; + + // Fixed number values. + public static final int BUTTON_2 = 1; + public static final int BUTTON_1 = 2; + public static final int BUTTON_B = 3; + public static final int BUTTON_A = 4; + public static final int BUTTON_MINUS = 5; + public static final int BUTTON_HOME = 8; + public static final int BUTTON_LEFT = 9; + public static final int BUTTON_RIGHT = 10; + public static final int BUTTON_DOWN = 11; + public static final int BUTTON_UP = 12; + public static final int BUTTON_PLUS = 13; + + int button; - /** - * Create a WiimoteButtonPressedEvent with the Wiimote source whose - * Button has been pressed and the integer representation of the button. - * - * @param source - * @param button - */ - public ButtonPressedEvent(Device source, int button) { - super(source); - this.button=button; - - if(source.getRecognitionButton()==button) { - this.recognitionbutton=true; - } else if(source.getTrainButton()==button) { - this.trainbutton=true; - } else if(source.getCloseGestureButton()==button) { - this.closegesturebutton=true; - } - } - - public int getButton() { - return this.button; - } - + /** + * Create a WiimoteButtonPressedEvent with the Wiimote source whose + * Button has been pressed and the integer representation of the button. + * + * @param source + * @param button + */ + public ButtonPressedEvent(Device source, int button) { + super(source); + this.button=button; + + if(source.getRecognitionButton()==button) { + this.recognitionbutton=true; + } else if(source.getTrainButton()==button) { + this.trainbutton=true; + } else if(source.getCloseGestureButton()==button) { + this.closegesturebutton=true; + } + } + + public int getButton() { + return this.button; + } + } diff --git a/src/main/java/org/wiigee/event/ButtonReleasedEvent.java b/src/main/java/org/wiigee/event/ButtonReleasedEvent.java index 45de43b..dbada77 100644 --- a/src/main/java/org/wiigee/event/ButtonReleasedEvent.java +++ b/src/main/java/org/wiigee/event/ButtonReleasedEvent.java @@ -37,13 +37,13 @@ public class ButtonReleasedEvent extends ActionStopEvent { int button; - public ButtonReleasedEvent(Device source, int button) { - super(source); + public ButtonReleasedEvent(Device source, int button) { + super(source); this.button = button; - } + } public int getButton() { return this.button; } - + } diff --git a/src/main/java/org/wiigee/event/GestureListener.java b/src/main/java/org/wiigee/event/GestureListener.java index f076ed9..6b2b967 100644 --- a/src/main/java/org/wiigee/event/GestureListener.java +++ b/src/main/java/org/wiigee/event/GestureListener.java @@ -36,12 +36,12 @@ import java.util.EventListener; */ public interface GestureListener extends EventListener { - /** - * This method would be called if a gesture has been recognized. - * - * @param event The GestureEvent containing information about - * the recognized gesture. - */ - public abstract void gestureReceived(GestureEvent event); - + /** + * This method would be called if a gesture has been recognized. + * + * @param event The GestureEvent containing information about + * the recognized gesture. + */ + public abstract void gestureReceived(GestureEvent event); + } diff --git a/src/main/java/org/wiigee/event/MotionStartEvent.java b/src/main/java/org/wiigee/event/MotionStartEvent.java index e669ba6..a79acea 100644 --- a/src/main/java/org/wiigee/event/MotionStartEvent.java +++ b/src/main/java/org/wiigee/event/MotionStartEvent.java @@ -32,32 +32,32 @@ import org.wiigee.device.Device; * @author Benjamin 'BePo' Poppinga */ public class MotionStartEvent extends ActionStartEvent { - - public MotionStartEvent(Device source) { - super(source); - - if(source.getRecognitionButton()==Device.MOTION) { - this.recognitionbutton=true; - } else if(source.getTrainButton()==Device.MOTION) { - this.trainbutton=true; - } else if(source.getCloseGestureButton()==Device.MOTION) { - this.closegesturebutton=true; - } - } - - @Override - public boolean isTrainInitEvent() { - return this.trainbutton; - } - - @Override - public boolean isCloseGestureInitEvent() { - return this.closegesturebutton; - } - - @Override - public boolean isRecognitionInitEvent() { - return this.recognitionbutton; - } + + public MotionStartEvent(Device source) { + super(source); + + if(source.getRecognitionButton()==Device.MOTION) { + this.recognitionbutton=true; + } else if(source.getTrainButton()==Device.MOTION) { + this.trainbutton=true; + } else if(source.getCloseGestureButton()==Device.MOTION) { + this.closegesturebutton=true; + } + } + + @Override + public boolean isTrainInitEvent() { + return this.trainbutton; + } + + @Override + public boolean isCloseGestureInitEvent() { + return this.closegesturebutton; + } + + @Override + public boolean isRecognitionInitEvent() { + return this.recognitionbutton; + } } diff --git a/src/main/java/org/wiigee/event/MotionStopEvent.java b/src/main/java/org/wiigee/event/MotionStopEvent.java index d5f8747..edc531e 100644 --- a/src/main/java/org/wiigee/event/MotionStopEvent.java +++ b/src/main/java/org/wiigee/event/MotionStopEvent.java @@ -35,8 +35,8 @@ import org.wiigee.device.Device; */ public class MotionStopEvent extends ActionStopEvent { - public MotionStopEvent(Device source) { - super(source); - } - + public MotionStopEvent(Device source) { + super(source); + } + } diff --git a/src/main/java/org/wiigee/filter/DirectionalEquivalenceFilter.java b/src/main/java/org/wiigee/filter/DirectionalEquivalenceFilter.java index e5098dd..358e21c 100644 --- a/src/main/java/org/wiigee/filter/DirectionalEquivalenceFilter.java +++ b/src/main/java/org/wiigee/filter/DirectionalEquivalenceFilter.java @@ -31,40 +31,40 @@ package org.wiigee.filter; * @author Benjamin 'BePo' Poppinga */ public class DirectionalEquivalenceFilter extends Filter { - - private double sensivity; - private double[] reference; + + private double sensivity; + private double[] reference; - public DirectionalEquivalenceFilter() { - super(); - this.reset(); - } - - public void reset() { - this.sensivity=0.2; - this.reference = new double[] {0.0, 0.0, 0.0}; - } - - public double[] filterAlgorithm(double[] vector) { - if(vector[0]reference[0]+this.sensivity || - vector[1]reference[1]+this.sensivity || - vector[2]reference[2]+this.sensivity) { - this.reference=vector; - return vector; - } else { - return null; - } - } - - public void setSensivity(double sensivity) { - this.sensivity=sensivity; - } - - public double getSensivity() { - return this.sensivity; - } + public DirectionalEquivalenceFilter() { + super(); + this.reset(); + } + + public void reset() { + this.sensivity=0.2; + this.reference = new double[] {0.0, 0.0, 0.0}; + } + + public double[] filterAlgorithm(double[] vector) { + if(vector[0]reference[0]+this.sensivity || + vector[1]reference[1]+this.sensivity || + vector[2]reference[2]+this.sensivity) { + this.reference=vector; + return vector; + } else { + return null; + } + } + + public void setSensivity(double sensivity) { + this.sensivity=sensivity; + } + + public double getSensivity() { + return this.sensivity; + } } diff --git a/src/main/java/org/wiigee/filter/Filter.java b/src/main/java/org/wiigee/filter/Filter.java index e97d4a9..ec347a4 100644 --- a/src/main/java/org/wiigee/filter/Filter.java +++ b/src/main/java/org/wiigee/filter/Filter.java @@ -30,33 +30,33 @@ package org.wiigee.filter; * @author Benjamin 'BePo' Poppinga */ public abstract class Filter { - - /*** - * The actual called method to filter anything. It checks if the vector is - * already set to NULL by another filter and won't process it anymore. If it's - * not NULL it would be forwarded to the actual implemented method - filterAlgorithm(). - * @param vector The acceleration vector, encoding: 0/x, 1/y, 2/z - * @return a new, filtered acceleration vector, encoded the same way - */ - public double[] filter(double[] vector) { - if(vector==null) { - return null; - } else { - return filterAlgorithm(vector); - } - } - - /*** - * A filter receives a triple of acceleration values within the variable 'vector'. - * It's encoded as vector[0]=x, vector[1]=y, vector[2]=z. This is not an object since the - * processing of the filter should be really fast, since every acceleration of the wiimote - * passes the filter. - * @param vector - * @param absvalue - * @return - */ - abstract public double[] filterAlgorithm(double[] vector); + + /*** + * The actual called method to filter anything. It checks if the vector is + * already set to NULL by another filter and won't process it anymore. If it's + * not NULL it would be forwarded to the actual implemented method - filterAlgorithm(). + * @param vector The acceleration vector, encoding: 0/x, 1/y, 2/z + * @return a new, filtered acceleration vector, encoded the same way + */ + public double[] filter(double[] vector) { + if(vector==null) { + return null; + } else { + return filterAlgorithm(vector); + } + } + + /*** + * A filter receives a triple of acceleration values within the variable 'vector'. + * It's encoded as vector[0]=x, vector[1]=y, vector[2]=z. This is not an object since the + * processing of the filter should be really fast, since every acceleration of the wiimote + * passes the filter. + * @param vector + * @param absvalue + * @return + */ + abstract public double[] filterAlgorithm(double[] vector); abstract public void reset(); - + } diff --git a/src/main/java/org/wiigee/filter/IdleStateFilter.java b/src/main/java/org/wiigee/filter/IdleStateFilter.java index b816e0b..26e1c92 100644 --- a/src/main/java/org/wiigee/filter/IdleStateFilter.java +++ b/src/main/java/org/wiigee/filter/IdleStateFilter.java @@ -31,18 +31,18 @@ package org.wiigee.filter; * @author Benjamin 'BePo' Poppinga */ public class IdleStateFilter extends Filter { - - private double sensivity; - - /** - * Since an acceleration sensor usually provides information even - * if it doesn't move, this filter removes the data if it's in the - * idle state. - */ - public IdleStateFilter() { - super(); - this.sensivity = 0.1; - } + + private double sensivity; + + /** + * Since an acceleration sensor usually provides information even + * if it doesn't move, this filter removes the data if it's in the + * idle state. + */ + public IdleStateFilter() { + super(); + this.sensivity = 0.1; + } @Override public void reset() { @@ -50,37 +50,37 @@ public class IdleStateFilter extends Filter { } @Override - public double[] filterAlgorithm(double[] vector) { - // calculate values needed for filtering: - // absolute value - double absvalue = Math.sqrt((vector[0]*vector[0])+ - (vector[1]*vector[1])+(vector[2]*vector[2])); - - // filter formulaes and return values - if(absvalue > 1+this.sensivity || - absvalue < 1-this.sensivity) { - return vector; - } else { - return null; - } - } - - /** - * Defines the absolute value when the wiimote should react to acceleration. - * This is a parameter for the first of the two filters: idle state - * filter. For example: sensivity=0.2 makes the wiimote react to acceleration - * where the absolute value is equal or greater than 1.2g. The default value 0.1 - * should work well. Only change if you are sure what you're doing. - * - * @param sensivity - * acceleration data values smaller than this value wouldn't be detected. - */ - public void setSensivity(double sensivity) { - this.sensivity = sensivity; - } - - public double getSensivity() { - return this.sensivity; - } + public double[] filterAlgorithm(double[] vector) { + // calculate values needed for filtering: + // absolute value + double absvalue = Math.sqrt((vector[0]*vector[0])+ + (vector[1]*vector[1])+(vector[2]*vector[2])); + + // filter formulaes and return values + if(absvalue > 1+this.sensivity || + absvalue < 1-this.sensivity) { + return vector; + } else { + return null; + } + } + + /** + * Defines the absolute value when the wiimote should react to acceleration. + * This is a parameter for the first of the two filters: idle state + * filter. For example: sensivity=0.2 makes the wiimote react to acceleration + * where the absolute value is equal or greater than 1.2g. The default value 0.1 + * should work well. Only change if you are sure what you're doing. + * + * @param sensivity + * acceleration data values smaller than this value wouldn't be detected. + */ + public void setSensivity(double sensivity) { + this.sensivity = sensivity; + } + + public double getSensivity() { + return this.sensivity; + } } diff --git a/src/main/java/org/wiigee/filter/MotionDetectFilter.java b/src/main/java/org/wiigee/filter/MotionDetectFilter.java index b13124a..4931b88 100644 --- a/src/main/java/org/wiigee/filter/MotionDetectFilter.java +++ b/src/main/java/org/wiigee/filter/MotionDetectFilter.java @@ -34,69 +34,69 @@ import org.wiigee.device.Device; */ public class MotionDetectFilter extends Filter { - private int motionchangetime; - private boolean nowinmotion; - private long motionstartstamp; - private Device device; - - /*** - * Detects wheather the wiimote receives acceleration or not and - * raises an event, if the device starts or stops. This is actual a - * null filter, not manipulating anything. But looks pretty good in - * this datatype since it could be removed easily. - * - * @param wiimote The Wiimote object which is controlled by the filter. - */ - public MotionDetectFilter(Device device) { - super(); - this.device=device; - this.reset(); - } - - public void reset() { - this.motionstartstamp=System.currentTimeMillis(); - this.nowinmotion=false; - this.motionchangetime=190; - } - + private int motionchangetime; + private boolean nowinmotion; + private long motionstartstamp; + private Device device; + + /*** + * Detects wheather the wiimote receives acceleration or not and + * raises an event, if the device starts or stops. This is actual a + * null filter, not manipulating anything. But looks pretty good in + * this datatype since it could be removed easily. + * + * @param wiimote The Wiimote object which is controlled by the filter. + */ + public MotionDetectFilter(Device device) { + super(); + this.device=device; + this.reset(); + } + + public void reset() { + this.motionstartstamp=System.currentTimeMillis(); + this.nowinmotion=false; + this.motionchangetime=190; + } + @Override - public double[] filter(double[] vector) { - - if(this.nowinmotion && - (System.currentTimeMillis()-this.motionstartstamp)>= - this.motionchangetime) { - this.nowinmotion=false; - this.device.fireMotionStopEvent(); - } // fi - - return filterAlgorithm(vector); - } - - public double[] filterAlgorithm(double[] vector) { - if(vector!=null) { - this.motionstartstamp=System.currentTimeMillis(); - if(!this.nowinmotion) { - this.nowinmotion=true; - this.motionstartstamp=System.currentTimeMillis(); - this.device.fireMotionStartEvent(); - } - } - - return vector; - } - - /** - * Defines the time the wiimote has to be in idle state before a new motion change - * event appears. The default value 500ms should work well, only change it if you are sure - * about what you're doing. - * @param time Time in ms - */ - public void setMotionChangeTime(int time) { - this.motionchangetime=time; - } - - public int getMotionChangeTime() { - return this.motionchangetime; - } + public double[] filter(double[] vector) { + + if(this.nowinmotion && + (System.currentTimeMillis()-this.motionstartstamp)>= + this.motionchangetime) { + this.nowinmotion=false; + this.device.fireMotionStopEvent(); + } // fi + + return filterAlgorithm(vector); + } + + public double[] filterAlgorithm(double[] vector) { + if(vector!=null) { + this.motionstartstamp=System.currentTimeMillis(); + if(!this.nowinmotion) { + this.nowinmotion=true; + this.motionstartstamp=System.currentTimeMillis(); + this.device.fireMotionStartEvent(); + } + } + + return vector; + } + + /** + * Defines the time the wiimote has to be in idle state before a new motion change + * event appears. The default value 500ms should work well, only change it if you are sure + * about what you're doing. + * @param time Time in ms + */ + public void setMotionChangeTime(int time) { + this.motionchangetime=time; + } + + public int getMotionChangeTime() { + return this.motionchangetime; + } } diff --git a/src/main/java/org/wiigee/logic/Classifier.java b/src/main/java/org/wiigee/logic/Classifier.java index a8f1b5a..9f6260b 100644 --- a/src/main/java/org/wiigee/logic/Classifier.java +++ b/src/main/java/org/wiigee/logic/Classifier.java @@ -28,82 +28,82 @@ import java.util.Vector; public class Classifier { - private Vector gesturemodel; // each gesturetype got its own - // gesturemodel in this vector - private double lastprob; - - public Classifier() { - this.gesturemodel=new Vector(); - this.lastprob=0.0; - } - - /** - * This method recognize a specific gesture, given to the procedure. - * For classification a bayes classification algorithm is used. - * - * @param g gesture to classify - */ - public int classifyGesture(Gesture g) { - //Log.write("Recognizing gesture..."); - - // Wert im Nenner berechnen, nach Bayes - double sum = 0; - for(int i=0; irecogprob) { - probgesture=tmpgesture; - probmodel=tmpmodel; - recogprob=((tmpmodel*tmpgesture)/sum); - recognized=i; - } - } - - // a gesture could be recognized - if(recogprob>0 && probmodel>0 && probgesture>0 && sum>0) { - this.lastprob=recogprob; - return recognized; - } else { - // no gesture could be recognized - return -1; - } - - } - - public double getLastProbability() { - return this.lastprob; - } - - public void addGestureModel(GestureModel gm) { - this.gesturemodel.add(gm); - } + private Vector gesturemodel; // each gesturetype got its own + // gesturemodel in this vector + private double lastprob; + + public Classifier() { + this.gesturemodel=new Vector(); + this.lastprob=0.0; + } + + /** + * This method recognize a specific gesture, given to the procedure. + * For classification a bayes classification algorithm is used. + * + * @param g gesture to classify + */ + public int classifyGesture(Gesture g) { + //Log.write("Recognizing gesture..."); + + // Wert im Nenner berechnen, nach Bayes + double sum = 0; + for(int i=0; irecogprob) { + probgesture=tmpgesture; + probmodel=tmpmodel; + recogprob=((tmpmodel*tmpgesture)/sum); + recognized=i; + } + } + + // a gesture could be recognized + if(recogprob>0 && probmodel>0 && probgesture>0 && sum>0) { + this.lastprob=recogprob; + return recognized; + } else { + // no gesture could be recognized + return -1; + } + + } + + public double getLastProbability() { + return this.lastprob; + } + + public void addGestureModel(GestureModel gm) { + this.gesturemodel.add(gm); + } - public GestureModel getGestureModel(int id) { - return this.gesturemodel.elementAt(id); - } - - public Vector getGestureModels() { - return this.gesturemodel; - } + public GestureModel getGestureModel(int id) { + return this.gesturemodel.elementAt(id); + } + + public Vector getGestureModels() { + return this.gesturemodel; + } public int getCountOfGestures() { return this.gesturemodel.size(); } - - public void clear() { - this.gesturemodel = new Vector(); - } - + + public void clear() { + this.gesturemodel = new Vector(); + } + } diff --git a/src/main/java/org/wiigee/logic/Gesture.java b/src/main/java/org/wiigee/logic/Gesture.java index 2d1976a..4daeeb0 100644 --- a/src/main/java/org/wiigee/logic/Gesture.java +++ b/src/main/java/org/wiigee/logic/Gesture.java @@ -36,120 +36,120 @@ import org.wiigee.event.AccelerationEvent; public class Gesture implements Cloneable { - /** Min/MaxAcceleration setup manually? */ - private boolean minmaxmanual; - private double minacc; - private double maxacc; - - /** The complete trajectory as WiimoteAccelerationEvents - * as a vector. It's a vector because we don't want to - * loose the chronology of the stored events. - */ - private Vector data; + /** Min/MaxAcceleration setup manually? */ + private boolean minmaxmanual; + private double minacc; + private double maxacc; + + /** The complete trajectory as WiimoteAccelerationEvents + * as a vector. It's a vector because we don't want to + * loose the chronology of the stored events. + */ + private Vector data; - /** - * Create an empty Gesture. - */ - public Gesture() { - this.data = new Vector(); - } + /** + * Create an empty Gesture. + */ + public Gesture() { + this.data = new Vector(); + } - /** - * Make a deep copy of another Gesture object. - * - * @param original Another Gesture object - */ - public Gesture(Gesture original) { - this.data = new Vector(); - Vector origin = original.getData(); - for (int i = 0; i < origin.size(); i++) { - this.add((AccelerationEvent) origin.get(i)); - } - } + /** + * Make a deep copy of another Gesture object. + * + * @param original Another Gesture object + */ + public Gesture(Gesture original) { + this.data = new Vector(); + Vector origin = original.getData(); + for (int i = 0; i < origin.size(); i++) { + this.add((AccelerationEvent) origin.get(i)); + } + } - /** - * Adds a new acceleration event to this gesture. - * - * @param event The WiimoteAccelerationEvent to add. - */ - public void add(AccelerationEvent event) { - this.data.add(event); - } + /** + * Adds a new acceleration event to this gesture. + * + * @param event The WiimoteAccelerationEvent to add. + */ + public void add(AccelerationEvent event) { + this.data.add(event); + } - /** - * Returns the last acceleration added to this gesture. - * - * @return the last acceleration event added. - */ - public AccelerationEvent getLastData() { - return (AccelerationEvent) this.data.get(this.data.size() - 1); - } + /** + * Returns the last acceleration added to this gesture. + * + * @return the last acceleration event added. + */ + public AccelerationEvent getLastData() { + return (AccelerationEvent) this.data.get(this.data.size() - 1); + } - /** - * Returns the whole chronological sequence of accelerations as - * a vector. - * - * @return chronological sequence of accelerations. - */ - public Vector getData() { - return this.data; - } - - /** - * Removes the first element of the acceleration queue of a gesture - */ - public void removeFirstData() { - this.data.remove(0); - } - - public int getCountOfData() { - return this.data.size(); - } - - public void setMaxAndMinAcceleration(double max, double min) { - this.maxacc = max; - this.minacc = min; - this.minmaxmanual = true; - } - - public double getMaxAcceleration() { - if(!this.minmaxmanual) { - double maxacc = Double.MIN_VALUE; - for(int i=0; i maxacc) { - maxacc=Math.abs(this.data.get(i).getX()); - } - if(Math.abs(this.data.get(i).getY()) > maxacc) { - maxacc=Math.abs(this.data.get(i).getY()); - } - if(Math.abs(this.data.get(i).getZ()) > maxacc) { - maxacc=Math.abs(this.data.get(i).getZ()); - } - } - return maxacc; - } else { - return this.maxacc; - } - } - - public double getMinAcceleration() { - if(!this.minmaxmanual) { - double minacc = Double.MAX_VALUE; - for(int i=0; i getData() { + return this.data; + } + + /** + * Removes the first element of the acceleration queue of a gesture + */ + public void removeFirstData() { + this.data.remove(0); + } + + public int getCountOfData() { + return this.data.size(); + } + + public void setMaxAndMinAcceleration(double max, double min) { + this.maxacc = max; + this.minacc = min; + this.minmaxmanual = true; + } + + public double getMaxAcceleration() { + if(!this.minmaxmanual) { + double maxacc = Double.MIN_VALUE; + for(int i=0; i maxacc) { + maxacc=Math.abs(this.data.get(i).getX()); + } + if(Math.abs(this.data.get(i).getY()) > maxacc) { + maxacc=Math.abs(this.data.get(i).getY()); + } + if(Math.abs(this.data.get(i).getZ()) > maxacc) { + maxacc=Math.abs(this.data.get(i).getZ()); + } + } + return maxacc; + } else { + return this.maxacc; + } + } + + public double getMinAcceleration() { + if(!this.minmaxmanual) { + double minacc = Double.MAX_VALUE; + for(int i=0; i