Basis voor Gesture herkenning toegevoegd / verbeterd. WiimoteDevice gebruikt nu ook een MotionDevice om MotionData op te slaan en opnieuw af te spelen.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<project default="jar" name="Build file for Project Mimis">
|
||||
<!-- All -->
|
||||
<target name="all" depends="javadoc, jar, launch4j"></target>
|
||||
|
||||
<!-- Javadoc -->
|
||||
<target name="javadoc">
|
||||
<javadoc access="private" author="true" classpath="cfg;resource;lib/log4j-1.2.16.jar;lib/jxinput.jar;lib/commons-logging-1.1.1.jar;lib/jacob-1.15-M3.jar" destdir="doc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" packagenames="mimis.exception.macro,mimis.device.network,wiiusej,mimis.application.itunes,mimis.exception.util,mimis.device.javainput,wiiusej.wiiusejevents,wiiusej.wiiusejevents.utils,mimis.util.swing,mimis.exception.worker,mimis.application.lirc,mimis.application.cmd.windows.winamp,wiiusej.values,mimis.exception.event,mimis.device.lirc.remote,mimis.device.panel,mimis.exception.device,mimis.exception.button,mimis.application.robot,mimis.application.lirc.ipod,mimis.exception.task.action,mimis.exception.application,wiiusej.wiiusejevents.wiiuseapievents,mimis.application.cmd.windows.gomplayer,mimis.application.mpc,org.wiigee.logic,mimis.device.lirc,mimis.sequence,mimis.manager,org.wiigee.util,mimis.event,mimis.application.cmd.windows.wmp,mimis.value,mimis.device.javainput.extreme3d,mimis.event.router,mimis.application.cmd,mimis.worker,org.wiigee.event,mimis.device.wiimote,mimis.device.wiimote.gesture.event,wiiusej.wiiusejevents.physicalevents,mimis.util.multiplexer,mimis,org.wiigee.control,mimis.exception.device.javainput,mimis.util,mimis.application.cmd.windows,com.dt.iTunesController,org.wiigee.device,mimis.application.vlc,mimis.device.wiimote.gesture,mimis.device.jintellitype,mimis.event.feedback,mimis.device,org.wiigee.filter,mimis.exception.application.windows,mimis.application,mimis.sequence.state,mimis.device.javainput.rumblepad,com.melloware.jintellitype,mimis.exception.event.router,mimis.exception.task,mimis.exception" source="1.6" sourcepath="src" splitindex="true" use="true" version="true" />
|
||||
|
||||
@@ -2,14 +2,14 @@ package mimis.device.lirc;
|
||||
|
||||
import mimis.application.cmd.CMDApplication;
|
||||
import mimis.device.Device;
|
||||
import mimis.device.lirc.button.ColorButton;
|
||||
import mimis.device.lirc.button.NumberButton;
|
||||
import mimis.device.lirc.remote.DenonRC176Button;
|
||||
import mimis.device.lirc.remote.PhiliphsRCLE011Button;
|
||||
import mimis.device.lirc.remote.SamsungBN5901015AButton;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.Button;
|
||||
import mimis.input.button.ColorButton;
|
||||
import mimis.input.button.NumberButton;
|
||||
import mimis.input.state.Press;
|
||||
import mimis.input.state.Release;
|
||||
import mimis.util.Multiplexer;
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package mimis.device.lirc.remote;
|
||||
|
||||
import mimis.input.Button;
|
||||
|
||||
public enum ColorButton implements Button {
|
||||
RED, GREEN, YELLOW, BLUE;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package mimis.device.wiimote;
|
||||
|
||||
import mimis.device.Device;
|
||||
import mimis.device.wiimote.gesture.GestureDevice;
|
||||
import mimis.device.wiimote.motion.MotionDevice;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.device.DeviceNotFoundException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
@@ -12,6 +13,7 @@ import mimis.input.state.Press;
|
||||
import mimis.input.state.Release;
|
||||
import mimis.util.ArrayCycle;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Signal;
|
||||
import mimis.worker.Component;
|
||||
import mimis.worker.Worker;
|
||||
|
||||
@@ -37,6 +39,7 @@ public class WiimoteDevice extends Component implements Device, GestureListener
|
||||
protected Wiimote wiimote;
|
||||
protected boolean connected;
|
||||
protected GestureDevice gestureDevice;
|
||||
protected MotionDevice motionDevice;
|
||||
protected int gestureId;
|
||||
protected LedWorker ledWorker;
|
||||
protected boolean disconnect;
|
||||
@@ -52,12 +55,15 @@ public class WiimoteDevice extends Component implements Device, GestureListener
|
||||
wiimoteDiscovery = new WiimoteDiscovery(this);
|
||||
gestureDevice = new GestureDevice();
|
||||
gestureDevice.add(this);
|
||||
motionDevice = new MotionDevice(this);
|
||||
gestureId = 0;
|
||||
ledWorker = new LedWorker();
|
||||
}
|
||||
|
||||
/* Worker */
|
||||
protected void activate() throws ActivateException {
|
||||
motionDevice.setRouter(router);
|
||||
motionDevice.start();
|
||||
parser(Action.ADD, taskMapCycle.player);
|
||||
wiimote = null;
|
||||
try {
|
||||
@@ -93,6 +99,7 @@ public class WiimoteDevice extends Component implements Device, GestureListener
|
||||
super.deactivate();
|
||||
ledWorker.stop();
|
||||
wiimoteDiscovery.stop();
|
||||
motionDevice.stop();
|
||||
if (disconnect) {
|
||||
if (wiimote != null) {
|
||||
wiimote.disconnect();
|
||||
@@ -111,6 +118,7 @@ public class WiimoteDevice extends Component implements Device, GestureListener
|
||||
}
|
||||
wiimoteService.exit();
|
||||
wiimoteDiscovery.exit();
|
||||
motionDevice.exit();
|
||||
}
|
||||
|
||||
/* Events */
|
||||
@@ -128,35 +136,46 @@ public class WiimoteDevice extends Component implements Device, GestureListener
|
||||
parser(Action.RESET, taskMapCycle.like);
|
||||
parser(Action.ADD, taskMapCycle.player);
|
||||
break;
|
||||
case RECOGNIZE:
|
||||
log.debug("Gesture recognize press");
|
||||
gestureDevice.recognize(Signal.BEGIN);
|
||||
break;
|
||||
case TRAIN:
|
||||
log.debug("Gesture train");
|
||||
gestureDevice.train();
|
||||
log.debug("Gesture train press");
|
||||
gestureDevice.train(Signal.BEGIN);
|
||||
break;
|
||||
case CLOSE:
|
||||
log.debug("Gesture close press");
|
||||
gestureDevice.close(Signal.BEGIN);
|
||||
break;
|
||||
case SAVE:
|
||||
log.debug("Gesture save");
|
||||
gestureDevice.close();
|
||||
gestureDevice.saveGesture(gestureId, "C:\\gesture-" + gestureId);
|
||||
gestureDevice.close(Signal.END);
|
||||
gestureDevice.saveGesture(gestureId, "tmp/gesture #" + gestureId);
|
||||
++gestureId;
|
||||
break;
|
||||
case LOAD:
|
||||
log.debug("Gesture load");
|
||||
for (int i = 0; i < gestureId; ++i) {
|
||||
gestureDevice.loadGesture("C:\\gesture-" + i);
|
||||
gestureDevice.loadGesture("tmp/gesture #" + gestureId);
|
||||
}
|
||||
break;
|
||||
case RECOGNIZE:
|
||||
log.debug("Gesture recognize");
|
||||
gestureDevice.recognize();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void end(Action action) {
|
||||
switch (action) {
|
||||
case TRAIN:
|
||||
case RECOGNIZE:
|
||||
log.debug("Gesture stop");
|
||||
gestureDevice.stop();
|
||||
log.debug("Gesture recognize release");
|
||||
gestureDevice.recognize(Signal.END);
|
||||
break;
|
||||
case TRAIN:
|
||||
log.debug("Gesture train release");
|
||||
gestureDevice.train(Signal.END);
|
||||
break;
|
||||
case CLOSE:
|
||||
log.debug("Gesture close release");
|
||||
gestureDevice.close(Signal.END);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -172,9 +191,9 @@ public class WiimoteDevice extends Component implements Device, GestureListener
|
||||
public synchronized void connect() throws DeviceNotFoundException {
|
||||
wiimote = wiimoteService.getDevice(this);
|
||||
//wiimote.activateContinuous();
|
||||
wiimote.activateMotionSensing();
|
||||
wiimoteDiscovery.stop();
|
||||
ledWorker.start();
|
||||
//sleep(10000);
|
||||
}
|
||||
|
||||
/* Listeners */
|
||||
@@ -196,6 +215,7 @@ public class WiimoteDevice extends Component implements Device, GestureListener
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent event) {
|
||||
gestureDevice.add(event.getGforce());
|
||||
motionDevice.add(event);
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent event) {
|
||||
@@ -203,6 +223,7 @@ public class WiimoteDevice extends Component implements Device, GestureListener
|
||||
}
|
||||
|
||||
public void gestureReceived(GestureEvent event) {
|
||||
log.debug(event.isValid());
|
||||
if (event.isValid()) {
|
||||
System.out.printf("id #%d, prob %.0f%%, valid %b\n", event.getId(), 100 * event.getProbability(), event.isValid());
|
||||
}
|
||||
|
||||
@@ -89,7 +89,6 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent event) {
|
||||
//log.debug(event);
|
||||
if (event.isConnected()) {
|
||||
WiimoteDevice wiimoteDevice = getWiimoteDevice(event);
|
||||
wiimoteDevice.connected = true;
|
||||
|
||||
@@ -20,10 +20,10 @@ public class WiimoteTaskMapCycle extends TaskMapCycle {
|
||||
|
||||
/* Gesture */
|
||||
gesture = new TaskMap();
|
||||
gesture.add(WiimoteButton.A, new Task(Action.TRAIN));
|
||||
gesture.add(WiimoteButton.B, new Task(Action.SAVE));
|
||||
gesture.add(WiimoteButton.DOWN, new Task(Action.LOAD));
|
||||
gesture.add(WiimoteButton.HOME, new Task(Action.RECOGNIZE));
|
||||
gesture.add(WiimoteButton.A, new Task(Action.TRAIN, Target.SELF));
|
||||
gesture.add(WiimoteButton.B, new Task(Action.SAVE, Target.SELF));
|
||||
gesture.add(WiimoteButton.DOWN, new Task(Action.LOAD, Target.SELF));
|
||||
gesture.add(WiimoteButton.HOME, new Task(Action.RECOGNIZE, Target.SELF));
|
||||
add(gesture);
|
||||
|
||||
/* Player */
|
||||
|
||||
@@ -1,29 +1,35 @@
|
||||
package mimis.device.wiimote.gesture;
|
||||
|
||||
import mimis.device.wiimote.gesture.event.Close;
|
||||
import mimis.device.wiimote.gesture.event.Recognize;
|
||||
import mimis.device.wiimote.gesture.event.Train;
|
||||
import mimis.value.Signal;
|
||||
|
||||
import org.wiigee.device.Device;
|
||||
import org.wiigee.event.AccelerationEvent;
|
||||
import org.wiigee.event.AccelerationListener;
|
||||
import org.wiigee.event.ButtonListener;
|
||||
import org.wiigee.event.ButtonPressedEvent;
|
||||
import org.wiigee.event.ButtonReleasedEvent;
|
||||
import org.wiigee.event.GestureListener;
|
||||
import org.wiigee.event.MotionStartEvent;
|
||||
import org.wiigee.event.MotionStopEvent;
|
||||
|
||||
import wiiusej.values.GForce;
|
||||
|
||||
public class GestureDevice extends Device /*implements AccelerationListener */{
|
||||
public class GestureDevice extends Device implements AccelerationListener {
|
||||
public static final boolean AUTOFILTERING = true;
|
||||
//public static final boolean AUTOMOTION = true;
|
||||
|
||||
public GestureDevice(boolean autofiltering/*, boolean automotion*/) {
|
||||
super(autofiltering);
|
||||
/*if (automotion) {
|
||||
addAccelerationListener(this);
|
||||
}*/
|
||||
}
|
||||
public static final boolean AUTOMOTION = false;
|
||||
|
||||
public GestureDevice() {
|
||||
this(AUTOFILTERING/*, AUTOMOTION*/);
|
||||
this(AUTOFILTERING, AUTOMOTION);
|
||||
}
|
||||
|
||||
public GestureDevice(boolean autofiltering, boolean automotion) {
|
||||
super(autofiltering);
|
||||
if (automotion) {
|
||||
addAccelerationListener(this);
|
||||
}
|
||||
this.setRecognitionButton(ButtonPressedEvent.BUTTON_A);
|
||||
this.setTrainButton(ButtonPressedEvent.BUTTON_B);
|
||||
this.setCloseGestureButton(ButtonPressedEvent.BUTTON_HOME);
|
||||
}
|
||||
|
||||
public void add(GestureListener gestureListener) {
|
||||
@@ -42,40 +48,65 @@ public class GestureDevice extends Device /*implements AccelerationListener */{
|
||||
fireAccelerationEvent(vector);
|
||||
}
|
||||
|
||||
public void recognize() {
|
||||
fireButtonPressedEvent(new Recognize(this));
|
||||
public void recognize(Signal signal) {
|
||||
switch (signal) {
|
||||
case BEGIN:
|
||||
fireButtonPressedEvent(ButtonPressedEvent.BUTTON_A);
|
||||
break;
|
||||
case END:
|
||||
fireButtonReleasedEvent(ButtonPressedEvent.BUTTON_A);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void train() {
|
||||
fireButtonPressedEvent(new Train(this));
|
||||
public void train(Signal signal) {
|
||||
switch (signal) {
|
||||
case BEGIN:
|
||||
fireButtonPressedEvent(ButtonPressedEvent.BUTTON_B);
|
||||
break;
|
||||
case END:
|
||||
fireButtonReleasedEvent(ButtonPressedEvent.BUTTON_B);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
fireButtonPressedEvent(new Close(this));
|
||||
public void close(Signal signal) {
|
||||
switch (signal) {
|
||||
case BEGIN:
|
||||
fireButtonPressedEvent(ButtonPressedEvent.BUTTON_HOME);
|
||||
break;
|
||||
case END:
|
||||
fireButtonReleasedEvent(ButtonPressedEvent.BUTTON_HOME);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
fireButtonReleasedEvent(0);
|
||||
}
|
||||
|
||||
public void fireButtonPressedEvent(ButtonPressedEvent buttonPressedEvent) {
|
||||
for (ButtonListener bttnLstnr : buttonlistener) {
|
||||
bttnLstnr.buttonPressReceived(buttonPressedEvent);
|
||||
public void fireButtonPressedEvent(int button) {
|
||||
ButtonPressedEvent buttonPressedEvent = new ButtonPressedEvent(this, button);
|
||||
for (ButtonListener buttonListener : buttonlistener) {
|
||||
buttonListener.buttonPressReceived(buttonPressedEvent);
|
||||
}
|
||||
if (buttonPressedEvent.isRecognitionInitEvent() || buttonPressedEvent.isTrainInitEvent()) {
|
||||
this.resetAccelerationFilters();
|
||||
resetAccelerationFilters();
|
||||
}
|
||||
}
|
||||
|
||||
/*public void accelerationReceived(AccelerationEvent event) {}
|
||||
public void fireButtonReleasedEvent(int button) {
|
||||
ButtonReleasedEvent buttonReleasedEvent = new ButtonReleasedEvent(this, button);
|
||||
for (ButtonListener buttonListener : buttonlistener) {
|
||||
buttonListener.buttonReleaseReceived(buttonReleasedEvent);
|
||||
}
|
||||
}
|
||||
|
||||
public void accelerationReceived(AccelerationEvent event) {}
|
||||
|
||||
public void motionStartReceived(MotionStartEvent event) {
|
||||
//System.out.println("Motion start!");
|
||||
recognize();
|
||||
System.out.println("Motion start !" + System.currentTimeMillis());
|
||||
recognize(Signal.BEGIN);
|
||||
}
|
||||
|
||||
public void motionStopReceived(MotionStopEvent event) {
|
||||
//System.out.println("Motion stop!");
|
||||
stop();
|
||||
}*/
|
||||
System.out.println("Motion stop! " + + System.currentTimeMillis());
|
||||
recognize(Signal.END);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package mimis.device.wiimote.gesture.event;
|
||||
|
||||
import org.wiigee.device.Device;
|
||||
import org.wiigee.event.ButtonPressedEvent;
|
||||
|
||||
public class Close extends ButtonPressedEvent {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public Close(Device device) {
|
||||
super(device, 0);
|
||||
}
|
||||
|
||||
public boolean isRecognitionInitEvent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isTrainInitEvent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCloseGestureInitEvent() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package mimis.device.wiimote.gesture.event;
|
||||
|
||||
import org.wiigee.device.Device;
|
||||
import org.wiigee.event.ButtonPressedEvent;
|
||||
|
||||
public class Recognize extends ButtonPressedEvent {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public Recognize(Device device) {
|
||||
super(device, 0);
|
||||
}
|
||||
|
||||
public boolean isRecognitionInitEvent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isTrainInitEvent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCloseGestureInitEvent() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package mimis.device.wiimote.gesture.event;
|
||||
|
||||
import org.wiigee.device.Device;
|
||||
import org.wiigee.event.ButtonPressedEvent;
|
||||
|
||||
public class Train extends ButtonPressedEvent {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public Train(Device device) {
|
||||
super(device, 0);
|
||||
}
|
||||
|
||||
public boolean isRecognitionInitEvent() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isTrainInitEvent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isCloseGestureInitEvent() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
29
java/src/mimis/device/wiimote/motion/MotionData.java
Normal file
29
java/src/mimis/device/wiimote/motion/MotionData.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package mimis.device.wiimote.motion;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
|
||||
public class MotionData implements Serializable {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
protected int time;
|
||||
protected MotionSensingEvent event;
|
||||
|
||||
public MotionData(long time, MotionSensingEvent event) {
|
||||
this((int) time, event);
|
||||
}
|
||||
|
||||
public MotionData(int time, MotionSensingEvent event) {
|
||||
this.time = time;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public MotionSensingEvent getEvent() {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
190
java/src/mimis/device/wiimote/motion/MotionDevice.java
Normal file
190
java/src/mimis/device/wiimote/motion/MotionDevice.java
Normal file
@@ -0,0 +1,190 @@
|
||||
package mimis.device.wiimote.motion;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mimis.device.lirc.LircButton;
|
||||
import mimis.device.lirc.remote.PhiliphsRCLE011Button;
|
||||
import mimis.device.wiimote.WiimoteDevice;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.Button;
|
||||
import mimis.input.button.ColorButton;
|
||||
import mimis.input.button.NumberButton;
|
||||
import mimis.input.state.State;
|
||||
import mimis.value.Action;
|
||||
import mimis.worker.Component;
|
||||
import mimis.worker.Worker;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
|
||||
public class MotionDevice extends Component {
|
||||
protected WiimoteDevice wiimoteDevice;
|
||||
protected int id;
|
||||
protected long start;
|
||||
protected boolean replay;
|
||||
protected Action action;
|
||||
|
||||
public ReplayWorker replayWorker;
|
||||
public ArrayList<MotionData> motionList;
|
||||
|
||||
public MotionDevice(WiimoteDevice wiimoteDevice) {
|
||||
this.wiimoteDevice = wiimoteDevice;
|
||||
id = 0;
|
||||
start = -1;
|
||||
replay = false;
|
||||
action = Action.TRAIN;
|
||||
replayWorker = new ReplayWorker();
|
||||
motionList = new ArrayList<MotionData>();
|
||||
}
|
||||
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
listen(State.class);
|
||||
}
|
||||
|
||||
public void deactivate() throws DeactivateException {
|
||||
replayWorker.stop();
|
||||
super.deactivate();
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
super.exit();
|
||||
replayWorker.exit();
|
||||
}
|
||||
|
||||
public void release(Button button) {
|
||||
if (button instanceof LircButton) {
|
||||
PhiliphsRCLE011Button lircButton = (PhiliphsRCLE011Button) button;
|
||||
log.debug(lircButton);
|
||||
switch (lircButton) {
|
||||
case CLOCK:
|
||||
action = Action.TRAIN;
|
||||
break;
|
||||
case OUT:
|
||||
action = Action.RECOGNIZE;
|
||||
break;
|
||||
case MUTE:
|
||||
wiimoteDevice.begin(Action.CLOSE);
|
||||
break;
|
||||
case SCREEN_UP:
|
||||
wiimoteDevice.begin(Action.SAVE);
|
||||
break;
|
||||
case SCREEN_DOWN:
|
||||
wiimoteDevice.begin(Action.LOAD);
|
||||
break;
|
||||
}
|
||||
} else if (button instanceof NumberButton) {
|
||||
NumberButton numberButton = (NumberButton) button;
|
||||
id = numberButton.ordinal();
|
||||
if (replay == false) {
|
||||
release(ColorButton.YELLOW);
|
||||
} else {
|
||||
log.debug("Set file to #" + id);
|
||||
}
|
||||
} else if (button instanceof ColorButton) {
|
||||
ColorButton colorButton = (ColorButton) button;
|
||||
log.debug(colorButton.name());
|
||||
synchronized (motionList) {
|
||||
switch (colorButton) {
|
||||
case GREEN:
|
||||
log.debug("Start capturing motion");
|
||||
motionList.clear();
|
||||
start = System.currentTimeMillis();
|
||||
break;
|
||||
case RED:
|
||||
if (replayWorker.active()) {
|
||||
log.debug("Stop replaying motion");
|
||||
replayWorker.stop();
|
||||
} else {
|
||||
log.debug("Writing motion to file #" + id);
|
||||
try {
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(String.format("tmp/motion #%d.bin", id));
|
||||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
|
||||
objectOutputStream.writeObject(motionList.size());
|
||||
for (MotionData motionData : motionList) {
|
||||
objectOutputStream.writeObject(motionData);
|
||||
}
|
||||
objectOutputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
}
|
||||
motionList.clear();
|
||||
start = -1;
|
||||
}
|
||||
break;
|
||||
case YELLOW:
|
||||
log.debug("Replaying motion from file #" + id);
|
||||
replay = true;
|
||||
replayWorker.start();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void add(MotionSensingEvent event) {
|
||||
if (start > 0) {
|
||||
synchronized (motionList) {
|
||||
motionList.add(new MotionData(System.currentTimeMillis() - start, event));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ReplayWorker extends Worker {
|
||||
protected ObjectInputStream objectInputStream;
|
||||
protected int count, i, time;
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
try {
|
||||
FileInputStream fileInputStream = new FileInputStream(String.format("tmp/motion #%d.bin", id));
|
||||
objectInputStream = new ObjectInputStream(fileInputStream);
|
||||
count = (Integer) objectInputStream.readObject();
|
||||
i = time = 0;
|
||||
wiimoteDevice.begin(action);
|
||||
super.activate();
|
||||
return;
|
||||
} catch (FileNotFoundException e) {
|
||||
log.error(e);
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void deactivate() throws DeactivateException {
|
||||
log.debug(String.format("Replay stopped (%d ms)", time));
|
||||
wiimoteDevice.end(action);
|
||||
replay = false;
|
||||
try {
|
||||
objectInputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.debug(e);
|
||||
}
|
||||
super.deactivate();
|
||||
}
|
||||
protected void work() {
|
||||
if (i++ < count) {
|
||||
try {
|
||||
Object object = objectInputStream.readObject();
|
||||
MotionData motionData = (MotionData) object;
|
||||
wiimoteDevice.onMotionSensingEvent(motionData.getEvent());
|
||||
sleep(motionData.getTime() - time);
|
||||
time = motionData.getTime();
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package mimis.device.lirc.button;
|
||||
package mimis.input.button;
|
||||
|
||||
import mimis.input.Button;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package mimis.device.lirc.button;
|
||||
package mimis.input.button;
|
||||
|
||||
import mimis.input.Button;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package mimis.value;
|
||||
|
||||
public enum Action {
|
||||
EXIT, FORWARD, MUTE, NEXT, PAUSE, PLAY, PREVIOUS, REPEAT, RESUME, REWIND, START, TEST, VOLUME_DOWN, VOLUME_UP, FULLSCREEN, TRAIN, STOP, SAVE, RECOGNIZE, LOAD, SHUFFLE, FADEOUT, QUIT, VISUALISER, LIKE, DISLIKE, ACTIVATE, SHIFT, UNSHIFT, ADD, REMOVE, RESET, CURRENT;
|
||||
EXIT, FORWARD, MUTE, NEXT, PAUSE, PLAY, PREVIOUS, REPEAT, RESUME, REWIND, START, TEST, VOLUME_DOWN, VOLUME_UP, FULLSCREEN, TRAIN, STOP, SAVE, RECOGNIZE, LOAD, SHUFFLE, FADEOUT, QUIT, VISUALISER, LIKE, DISLIKE, ACTIVATE, SHIFT, UNSHIFT, ADD, REMOVE, RESET, CURRENT, CLOSE;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package mimis.worker;
|
||||
|
||||
import mimis.input.Button;
|
||||
import mimis.input.Feedback;
|
||||
import mimis.input.Input;
|
||||
import mimis.input.Task;
|
||||
import mimis.input.state.Press;
|
||||
import mimis.input.state.Release;
|
||||
import mimis.input.state.State;
|
||||
import mimis.parser.ParserInput;
|
||||
import mimis.router.Router;
|
||||
@@ -62,14 +65,24 @@ public abstract class Component extends Listener<Input> {
|
||||
}
|
||||
|
||||
public void input(Input input) {
|
||||
if (input instanceof Task) {
|
||||
log.debug("task " + ((Task) input).getAction());
|
||||
if (input instanceof State) {
|
||||
state((State) input);
|
||||
} else if (input instanceof Task) {
|
||||
task((Task) input);
|
||||
} else if (input instanceof Feedback) {
|
||||
feedback((Feedback) input);
|
||||
}
|
||||
}
|
||||
|
||||
protected void state(State state) {
|
||||
Button button = state.getButton();
|
||||
if (state instanceof Press) {
|
||||
press(button);
|
||||
} else if (state instanceof Release) {
|
||||
release(button);
|
||||
}
|
||||
}
|
||||
|
||||
protected void task(Task task) {
|
||||
Action action = task.getAction();
|
||||
switch (task.getSignal()) {
|
||||
@@ -98,6 +111,8 @@ public abstract class Component extends Listener<Input> {
|
||||
}
|
||||
}
|
||||
|
||||
protected void press(Button button) {}
|
||||
protected void release(Button button) {}
|
||||
protected void feedback(Feedback feedback) {}
|
||||
protected void action(Action action) {}
|
||||
protected void begin(Action action) {}
|
||||
|
||||
@@ -173,7 +173,7 @@ public class Device {
|
||||
this.processingunit.saveGesture(id, filename);
|
||||
}
|
||||
|
||||
// ###### Event-Methoden
|
||||
// ###### Event-Methods
|
||||
/** Fires an acceleration event.
|
||||
* @param vector Consists of three values:
|
||||
* acceleration on X, Y and Z axis.
|
||||
|
||||
@@ -34,16 +34,15 @@ import org.wiigee.device.Device;
|
||||
* @author Benjamin 'BePo' Poppinga
|
||||
*/
|
||||
public class ButtonReleasedEvent extends ActionStopEvent {
|
||||
int button;
|
||||
|
||||
int button;
|
||||
public ButtonReleasedEvent(Device source, int button) {
|
||||
super(source);
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
public ButtonReleasedEvent(Device source, int button) {
|
||||
super(source);
|
||||
this.button = button;
|
||||
}
|
||||
public int getButton() {
|
||||
return this.button;
|
||||
}
|
||||
|
||||
public int getButton() {
|
||||
return this.button;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class TriggeredProcessingUnit extends ProcessingUnit {
|
||||
Log.write("Recognition started!");
|
||||
this.analyzing=true;
|
||||
}
|
||||
|
||||
System.err.println(analyzing + " " + learning + " " + event.isCloseGestureInitEvent());
|
||||
// CloseGestureButton = starts the training of the model with multiple
|
||||
// recognized gestures, contained in trainsequence
|
||||
if((!this.analyzing && !this.learning) &&
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
package wiiusej.values;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Represents gravity force on each axis.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class GForce {
|
||||
public class GForce implements Serializable {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
package wiiusej.values;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Class that represents the orientation of the wiimote.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class Orientation {
|
||||
public class Orientation implements Serializable {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
private float roll;
|
||||
private float pitch;
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
package wiiusej.values;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Represents raw acceleration on each axis.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public class RawAcceleration {
|
||||
public class RawAcceleration implements Serializable {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
private short x;
|
||||
private short y;
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
package wiiusej.wiiusejevents;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Abstract mother class representing an event with a wiimote id.
|
||||
*
|
||||
* @author guiguito
|
||||
*/
|
||||
public abstract class GenericEvent {
|
||||
public abstract class GenericEvent implements Serializable {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
/* ID */
|
||||
private int wiimoteId = -1;
|
||||
|
||||
@@ -27,8 +27,9 @@ import wiiusej.wiiusejevents.GenericEvent;
|
||||
* @author guiguito
|
||||
*/
|
||||
public class MotionSensingEvent extends GenericEvent {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
/* Motion Sensing */
|
||||
/* Motion Sensing */
|
||||
private Orientation orientation;
|
||||
private GForce gforce;
|
||||
private RawAcceleration acceleration;
|
||||
|
||||
Reference in New Issue
Block a user