Moved InfraredEvent. Divided DeviceListenerInterface to ButtonListener and AccelerationListener. Added RotationListener for basic Wii Motion Plus support (isn't used for gesture recognition yet), but readout works. wiigee is one of the first libs to support the wii motion plus. Thanks to anyone, who contributed to find out the initialization procedure (wiibrew-wiki, cwiid).
git-svn-id: svn://svn.code.sf.net/p/wiigee/code/trunk@93 c7eff9ee-dd40-0410-8832-91a4d88773cf
This commit is contained in:
@@ -33,7 +33,7 @@ import org.wiigee.util.Log;
|
||||
public class Wiigee {
|
||||
|
||||
protected static String version = "1.5 alpha";
|
||||
protected static String releasedate = "20090605";
|
||||
protected static String releasedate = "20090617";
|
||||
|
||||
protected Wiigee() {
|
||||
Log.write("This is wiigee version "+version+" ("+releasedate+")");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* wiigee - accelerometerbased gesture recognition
|
||||
* Copyright (C) 2007, 2008 Benjamin Poppinga
|
||||
* Copyright (C) 2007, 2008, 2009 Benjamin Poppinga
|
||||
*
|
||||
* Developed at University of Oldenburg
|
||||
* Contact: benjamin.poppinga@informatik.uni-oldenburg.de
|
||||
@@ -45,17 +45,19 @@ public class Device {
|
||||
protected boolean accelerationenabled;
|
||||
|
||||
// Filters, can filter the data stream
|
||||
protected Vector<Filter> filters = new Vector<Filter>();
|
||||
protected Vector<Filter> accfilters = new Vector<Filter>();
|
||||
|
||||
// Listeners, receive generated events
|
||||
protected Vector<DeviceListener> devicelistener = new Vector<DeviceListener>();
|
||||
protected Vector<AccelerationListener> accelerationlistener = new Vector<AccelerationListener>();
|
||||
protected Vector<ButtonListener> buttonlistener = new Vector<ButtonListener>();
|
||||
protected ProcessingUnit processingunit = new TriggeredProcessingUnit();
|
||||
|
||||
public Device() {
|
||||
this.addFilter(new IdleStateFilter());
|
||||
this.addFilter(new MotionDetectFilter(this));
|
||||
this.addFilter(new DirectionalEquivalenceFilter());
|
||||
this.addDeviceListener(this.processingunit);
|
||||
this.addAccelerationListener(this.processingunit);
|
||||
this.addButtonListener(this.processingunit);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,31 +65,35 @@ public class Device {
|
||||
* @param filter The Filter instance.
|
||||
*/
|
||||
public void addFilter(Filter filter) {
|
||||
this.filters.add(filter);
|
||||
this.accfilters.add(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all the filters, which are resetable.
|
||||
* Resets all the accfilters, which are resetable.
|
||||
* Sometimes they have to be resettet if a new gesture starts.
|
||||
*/
|
||||
public void resetFilters() {
|
||||
for(int i=0; i<this.filters.size(); i++) {
|
||||
this.filters.elementAt(i).reset();
|
||||
for(int i=0; i<this.accfilters.size(); i++) {
|
||||
this.accfilters.elementAt(i).reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an WiimoteListener to the wiimote. Everytime an action
|
||||
* on the wiimote is performed the WiimoteListener would receive
|
||||
* Adds an AccelerationListener to the Device. Everytime an acceleration
|
||||
* on the Device is performed the AccelerationListener would receive
|
||||
* an event of this action.
|
||||
*
|
||||
*/
|
||||
public void addDeviceListener(DeviceListener listener) {
|
||||
this.devicelistener.add(listener);
|
||||
public void addAccelerationListener(AccelerationListener listener) {
|
||||
this.accelerationlistener.add(listener);
|
||||
}
|
||||
|
||||
public void addButtonListener(ButtonListener listener) {
|
||||
this.buttonlistener.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a GestureListener to the wiimote. Everytime a gesture
|
||||
* Adds a GestureListener to the Device. Everytime a gesture
|
||||
* is performed the GestureListener would receive an event of
|
||||
* this gesture.
|
||||
*/
|
||||
@@ -146,17 +152,13 @@ public class Device {
|
||||
// ###### Event-Methoden
|
||||
|
||||
/** Fires an acceleration event.
|
||||
* @param x
|
||||
* Acceleration in x direction
|
||||
* @param y
|
||||
* Acceleration in y direction
|
||||
* @param z
|
||||
* Acceleration in z direction
|
||||
* @param vector Consists of three values:
|
||||
* acceleration on X, Y and Z axis.
|
||||
*/
|
||||
public void fireAccelerationEvent(double[] vector) {
|
||||
for(int i=0; i<this.filters.size(); i++) {
|
||||
vector = this.filters.get(i).filter(vector);
|
||||
// cannot return here if null, because of time-dependent filters
|
||||
for(int i=0; i<this.accfilters.size(); i++) {
|
||||
vector = this.accfilters.get(i).filter(vector);
|
||||
// cannot return here if null, because of time-dependent accfilters
|
||||
}
|
||||
|
||||
// don't need to create an event if filtered away
|
||||
@@ -167,8 +169,8 @@ public class Device {
|
||||
|
||||
AccelerationEvent w = new AccelerationEvent(this,
|
||||
vector[0], vector[1], vector[2], absvalue);
|
||||
for(int i=0; i<this.devicelistener.size(); i++) {
|
||||
this.devicelistener.get(i).accelerationReceived(w);
|
||||
for(int i=0; i<this.accelerationlistener.size(); i++) {
|
||||
this.accelerationlistener.get(i).accelerationReceived(w);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,8 +182,8 @@ public class Device {
|
||||
*/
|
||||
public void fireButtonPressedEvent(int button) {
|
||||
ButtonPressedEvent w = new ButtonPressedEvent(this, button);
|
||||
for(int i=0; i<this.devicelistener.size(); i++) {
|
||||
this.devicelistener.get(i).buttonPressReceived(w);
|
||||
for(int i=0; i<this.buttonlistener.size(); i++) {
|
||||
this.buttonlistener.get(i).buttonPressReceived(w);
|
||||
}
|
||||
|
||||
if(w.isRecognitionInitEvent() || w.isTrainInitEvent()) {
|
||||
@@ -193,8 +195,8 @@ public class Device {
|
||||
*/
|
||||
public void fireButtonReleasedEvent() {
|
||||
ButtonReleasedEvent w = new ButtonReleasedEvent(this);
|
||||
for(int i=0; i<this.devicelistener.size(); i++) {
|
||||
this.devicelistener.get(i).buttonReleaseReceived(w);
|
||||
for(int i=0; i<this.buttonlistener.size(); i++) {
|
||||
this.buttonlistener.get(i).buttonReleaseReceived(w);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,8 +205,8 @@ public class Device {
|
||||
*/
|
||||
public void fireMotionStartEvent() {
|
||||
MotionStartEvent w = new MotionStartEvent(this);
|
||||
for(int i=0; i<this.devicelistener.size(); i++) {
|
||||
this.devicelistener.get(i).motionStartReceived(w);
|
||||
for(int i=0; i<this.accelerationlistener.size(); i++) {
|
||||
this.accelerationlistener.get(i).motionStartReceived(w);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,8 +215,8 @@ public class Device {
|
||||
*/
|
||||
public void fireMotionStopEvent() {
|
||||
MotionStopEvent w = new MotionStopEvent(this);
|
||||
for(int i=0; i<this.devicelistener.size(); i++) {
|
||||
this.devicelistener.get(i).motionStopReceived(w);
|
||||
for(int i=0; i<this.accelerationlistener.size(); i++) {
|
||||
this.accelerationlistener.get(i).motionStopReceived(w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* wiigee - accelerometerbased gesture recognition
|
||||
* Copyright (C) 2007, 2008 Benjamin Poppinga
|
||||
* Copyright (C) 2007, 2008, 2009 Benjamin Poppinga
|
||||
*
|
||||
* Developed at University of Oldenburg
|
||||
* Contact: benjamin.poppinga@informatik.uni-oldenburg.de
|
||||
@@ -32,7 +32,7 @@ import org.wiigee.device.*;
|
||||
* This Event would be generated if an acceleration has been detected.
|
||||
* It contains information about the force applied to the device in each
|
||||
* direction (x, y, z). Further it contains the absolute value of this
|
||||
* vector and the source which generated this event (wiimote).
|
||||
* vector and the source which generated this event (Device).
|
||||
*
|
||||
* @author Benjamin 'BePo' Poppinga
|
||||
*
|
||||
@@ -41,10 +41,9 @@ public class AccelerationEvent extends EventObject {
|
||||
|
||||
double X, Y, Z;
|
||||
double absvalue;
|
||||
Device source;
|
||||
|
||||
/**
|
||||
* Create a WiimoteAccelerationEvent with a specific source,
|
||||
* Create an AccelerationEvent with a specific source,
|
||||
* all the three acceleration values and the calculated absolute
|
||||
* value.
|
||||
*
|
||||
@@ -56,17 +55,12 @@ public class AccelerationEvent extends EventObject {
|
||||
*/
|
||||
public AccelerationEvent(Device source, double X, double Y, double Z, double absvalue) {
|
||||
super(source);
|
||||
this.source=source;
|
||||
this.X=X;
|
||||
this.Y=Y;
|
||||
this.Z=Z;
|
||||
this.absvalue=absvalue;
|
||||
}
|
||||
|
||||
public Device getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return X;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* wiigee - accelerometerbased gesture recognition
|
||||
* Copyright (C) 2007, 2008 Benjamin Poppinga
|
||||
* Copyright (C) 2007, 2008, 2009 Benjamin Poppinga
|
||||
*
|
||||
* Developed at University of Oldenburg
|
||||
* Contact: benjamin.poppinga@informatik.uni-oldenburg.de
|
||||
@@ -28,40 +28,24 @@ import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* This interface has to be implemented if the application should react
|
||||
* to pure acceleration data or button press/release. This could be
|
||||
* useful if you want to graphically display the acceleration data or
|
||||
* something else in your application.
|
||||
* to pure acceleration data. This could be useful if you want to e.g.
|
||||
* graphically display the acceleration data in your application.
|
||||
*
|
||||
* @author Benjamin 'BePo' Poppinga
|
||||
*/
|
||||
public interface DeviceListener extends EventListener {
|
||||
public interface AccelerationListener extends EventListener {
|
||||
|
||||
/**
|
||||
* This method would be called if a Wiimote source has been accelerated.
|
||||
* 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 Wiimote 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 Wiimote 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 Wiimote is in idle state and then a
|
||||
* motion starts or if a Wiimote is in motion and then the motion stops and
|
||||
* the Wiimote is in idle state.
|
||||
* 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.
|
||||
@@ -69,15 +53,13 @@ public interface DeviceListener extends EventListener {
|
||||
public abstract void motionStartReceived(MotionStartEvent event);
|
||||
|
||||
/**
|
||||
* This method would be called if a Wiimote is in motion and then the motion
|
||||
* stops and the Wiimote is in idle state.
|
||||
* 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 Wiimote is now
|
||||
* @param event This is the event which contains if the Device is now
|
||||
* in motion or not.
|
||||
*/
|
||||
public abstract void motionStopReceived(MotionStopEvent event);
|
||||
|
||||
public abstract void infraredReceived(InfraredEvent event);
|
||||
|
||||
|
||||
}
|
||||
53
src/org/wiigee/event/InfraredEvent.java → src/org/wiigee/event/ButtonListener.java
Executable file → Normal file
53
src/org/wiigee/event/InfraredEvent.java → src/org/wiigee/event/ButtonListener.java
Executable file → Normal file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* wiigee - accelerometerbased gesture recognition
|
||||
* Copyright (C) 2007, 2008 Benjamin Poppinga
|
||||
* Copyright (C) 2007, 2008, 2009 Benjamin Poppinga
|
||||
*
|
||||
* Developed at University of Oldenburg
|
||||
* Contact: benjamin.poppinga@informatik.uni-oldenburg.de
|
||||
@@ -24,40 +24,31 @@
|
||||
|
||||
package org.wiigee.event;
|
||||
|
||||
import java.util.EventObject;
|
||||
import org.wiigee.device.Device;
|
||||
import java.util.EventListener;
|
||||
|
||||
public class InfraredEvent extends EventObject {
|
||||
/**
|
||||
* This interface has to be implemented if the application should react
|
||||
* to button press/releases.
|
||||
*
|
||||
* @author Benjamin 'BePo' Poppinga
|
||||
*/
|
||||
public interface ButtonListener extends EventListener {
|
||||
|
||||
protected Device wiimote;
|
||||
protected int[][] coordinates;
|
||||
protected int[] size;
|
||||
protected boolean[] valid;
|
||||
|
||||
public InfraredEvent(Device source, int[][] coordinates, int[] size) {
|
||||
super(source);
|
||||
this.coordinates=coordinates;
|
||||
this.size=size;
|
||||
this.valid = new boolean[4];
|
||||
for(int i=0; i<this.coordinates.length; i++) {
|
||||
this.valid[i] = (this.coordinates[i][0]<1023 && this.coordinates[i][1]<1023);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
|
||||
public Device getSource() {
|
||||
return this.wiimote;
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
|
||||
public boolean isValid(int i) {
|
||||
return this.valid[i];
|
||||
}
|
||||
|
||||
public int[][] getCoordinates() {
|
||||
return this.coordinates;
|
||||
}
|
||||
|
||||
public int[] getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,14 +26,6 @@ package org.wiigee.filter;
|
||||
|
||||
public abstract class Filter {
|
||||
|
||||
public Filter() {
|
||||
// nothing, but should be called via SUPER.
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
// reset filter, if necessary.
|
||||
}
|
||||
|
||||
/***
|
||||
* 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
|
||||
@@ -60,4 +52,6 @@ public abstract class Filter {
|
||||
*/
|
||||
abstract public double[] filterAlgorithm(double[] vector);
|
||||
|
||||
abstract public void reset();
|
||||
|
||||
}
|
||||
|
||||
@@ -40,12 +40,17 @@ public class HighPassFilter extends Filter {
|
||||
public HighPassFilter() {
|
||||
super();
|
||||
this.factor = 0.1;
|
||||
this.prevAcc = new double[] {0.0, 0.0, 0.0};
|
||||
this.reset();
|
||||
}
|
||||
|
||||
public HighPassFilter(double factor) {
|
||||
super();
|
||||
this.factor = factor;
|
||||
this.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.prevAcc = new double[] {0.0, 0.0, 0.0};
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,12 @@ public class IdleStateFilter extends Filter {
|
||||
this.sensivity = 0.1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
// not needed
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] filterAlgorithm(double[] vector) {
|
||||
// calculate values needed for filtering:
|
||||
// absolute value
|
||||
|
||||
@@ -40,12 +40,17 @@ public class LowPassFilter extends Filter {
|
||||
public LowPassFilter() {
|
||||
super();
|
||||
this.factor = 0.01;
|
||||
this.prevAcc = new double[] {0.0, 0.0, 0.0};
|
||||
this.reset();
|
||||
}
|
||||
|
||||
public LowPassFilter(double factor) {
|
||||
super();
|
||||
this.factor = factor;
|
||||
this.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
this.prevAcc = new double[] {0.0, 0.0, 0.0};
|
||||
}
|
||||
|
||||
|
||||
@@ -48,12 +48,12 @@ public class MotionDetectFilter extends Filter {
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
super.reset();
|
||||
this.motionstartstamp=System.currentTimeMillis();
|
||||
this.nowinmotion=false;
|
||||
this.motionchangetime=190;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double[] filter(double[] vector) {
|
||||
|
||||
if(this.nowinmotion &&
|
||||
|
||||
@@ -5,16 +5,16 @@ import java.util.Vector;
|
||||
import org.wiigee.event.AccelerationEvent;
|
||||
import org.wiigee.event.ButtonPressedEvent;
|
||||
import org.wiigee.event.ButtonReleasedEvent;
|
||||
import org.wiigee.event.DeviceListener;
|
||||
import org.wiigee.event.AccelerationListener;
|
||||
import org.wiigee.event.ButtonListener;
|
||||
import org.wiigee.event.GestureEvent;
|
||||
import org.wiigee.event.GestureListener;
|
||||
import org.wiigee.event.InfraredEvent;
|
||||
import org.wiigee.event.MotionStartEvent;
|
||||
import org.wiigee.event.MotionStopEvent;
|
||||
import org.wiigee.event.StateEvent;
|
||||
import org.wiigee.util.Log;
|
||||
|
||||
public abstract class ProcessingUnit implements DeviceListener {
|
||||
public abstract class ProcessingUnit implements AccelerationListener, ButtonListener {
|
||||
|
||||
// Classifier
|
||||
protected Classifier classifier;
|
||||
@@ -57,8 +57,6 @@ public abstract class ProcessingUnit implements DeviceListener {
|
||||
|
||||
public abstract void buttonReleaseReceived(ButtonReleasedEvent event);
|
||||
|
||||
public abstract void infraredReceived(InfraredEvent event);
|
||||
|
||||
public abstract void motionStartReceived(MotionStartEvent event);
|
||||
|
||||
public abstract void motionStopReceived(MotionStopEvent event);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* wiigee - accelerometerbased gesture recognition
|
||||
* Copyright (C) 2007, 2008 Benjamin Poppinga
|
||||
* Copyright (C) 2007, 2008, 2009 Benjamin Poppinga
|
||||
*
|
||||
* Developed at University of Oldenburg
|
||||
* Contact: benjamin.poppinga@informatik.uni-oldenburg.de
|
||||
@@ -29,7 +29,7 @@ import org.wiigee.event.*;
|
||||
import org.wiigee.util.Log;
|
||||
|
||||
/**
|
||||
* This class analyzes the WiimoteAccelerationEvents emitted from a Wiimote
|
||||
* This class analyzes the AccelerationEvents emitted from a Wiimote
|
||||
* and further creates and manages the different models for each type
|
||||
* of gesture.
|
||||
*
|
||||
@@ -82,11 +82,6 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
|
||||
this.handleStopEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void infraredReceived(InfraredEvent event) {
|
||||
// NOTHING TO DO HERE
|
||||
}
|
||||
|
||||
public void motionStartReceived(MotionStartEvent event) {
|
||||
this.handleStartEvent(event);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user