Herstructuratie alom:
- EventMaps in plaats van event+task steeds handmatig toevoegen - EventMapCycles om eenvoudig te kunnen cyclen in geval van bvb een shift button - JIntellitype en Wiimote device hiernaar omgeschreven - wat overbodige logging verwijderd
This commit is contained in:
@@ -1,58 +1,37 @@
|
|||||||
package mimis;
|
package mimis;
|
||||||
|
|
||||||
|
import mimis.device.EventMapCycle;
|
||||||
import mimis.event.EventHandler;
|
import mimis.event.EventHandler;
|
||||||
import mimis.event.Task;
|
|
||||||
import mimis.exception.worker.ActivateException;
|
import mimis.exception.worker.ActivateException;
|
||||||
import mimis.exception.worker.DeactivateException;
|
import mimis.exception.worker.DeactivateException;
|
||||||
import mimis.manager.Exitable;
|
import mimis.manager.Exitable;
|
||||||
import mimis.manager.Titled;
|
import mimis.manager.Titled;
|
||||||
import mimis.sequence.Sequence;
|
import mimis.sequence.EventMap;
|
||||||
import mimis.sequence.SequenceListener;
|
import mimis.sequence.SequenceListener;
|
||||||
import mimis.sequence.State;
|
import mimis.sequence.State;
|
||||||
import mimis.sequence.state.Press;
|
|
||||||
|
|
||||||
public abstract class Device extends EventHandler implements Titled, Exitable {
|
public abstract class Device extends EventHandler implements Titled, Exitable {
|
||||||
protected String title;
|
protected String title;
|
||||||
|
protected EventMapCycle eventMapCycle;
|
||||||
protected SequenceListener sequenceListener;
|
protected SequenceListener sequenceListener;
|
||||||
|
|
||||||
public Device(String title) {
|
public Device(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String title() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Worker */
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
super.activate();
|
super.activate();
|
||||||
sequenceListener = new SequenceListener(this);
|
sequenceListener = new SequenceListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register macro's */
|
public void deactivate() throws DeactivateException {
|
||||||
protected void add(Sequence sequence, Task task) {
|
super.deactivate();
|
||||||
sequenceListener.add(sequence, task);
|
sequenceListener.reset();
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(State state, Task task) {
|
|
||||||
add(new Sequence(state), task);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(Press press, Task task, boolean macro) {
|
|
||||||
if (macro) {
|
|
||||||
add(new Macro(press), task);
|
|
||||||
} else {
|
|
||||||
add((State) press, task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(Press press, Task task) {
|
|
||||||
add(press, task, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Recognize events */
|
|
||||||
protected void add(State state) {
|
|
||||||
log.debug(state.toString() + " " + state.getButton());
|
|
||||||
sequenceListener.add(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String title() {
|
|
||||||
return title;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
@@ -65,4 +44,21 @@ public abstract class Device extends EventHandler implements Titled, Exitable {
|
|||||||
}
|
}
|
||||||
super.stop();
|
super.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* SequenceListener */
|
||||||
|
protected void add(EventMap eventMap) {
|
||||||
|
sequenceListener.add(eventMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void remove(EventMap eventMap) {
|
||||||
|
sequenceListener.remove(eventMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void add(State state) {
|
||||||
|
sequenceListener.add(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void reset() {
|
||||||
|
sequenceListener.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ public class Mimis extends EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void end(Action action) {
|
protected void end(Action action) {
|
||||||
log.debug(String.format("action(%s)", action));
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case NEXT:
|
case NEXT:
|
||||||
eventRouter.set(applicationCycle.next());
|
eventRouter.set(applicationCycle.next());
|
||||||
|
|||||||
13
java/src/mimis/device/EventMapCycle.java
Normal file
13
java/src/mimis/device/EventMapCycle.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package mimis.device;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import mimis.sequence.EventMap;
|
||||||
|
import mimis.util.ArrayCycle;
|
||||||
|
|
||||||
|
public class EventMapCycle extends ArrayCycle<EventMap> {
|
||||||
|
protected static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
protected Log log = LogFactory.getLog(getClass());
|
||||||
|
}
|
||||||
@@ -3,23 +3,19 @@ package mimis.device.jintellitype;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import mimis.Device;
|
import mimis.Device;
|
||||||
import mimis.event.Task;
|
|
||||||
import mimis.exception.button.UnknownButtonException;
|
import mimis.exception.button.UnknownButtonException;
|
||||||
import mimis.exception.worker.ActivateException;
|
import mimis.exception.worker.ActivateException;
|
||||||
|
import mimis.exception.worker.DeactivateException;
|
||||||
import mimis.sequence.state.Press;
|
import mimis.sequence.state.Press;
|
||||||
import mimis.sequence.state.Release;
|
import mimis.sequence.state.Release;
|
||||||
import mimis.value.Action;
|
|
||||||
import mimis.value.Key;
|
|
||||||
import mimis.value.Target;
|
|
||||||
|
|
||||||
import com.melloware.jintellitype.HotkeyListener;
|
import com.melloware.jintellitype.HotkeyListener;
|
||||||
import com.melloware.jintellitype.IntellitypeListener;
|
import com.melloware.jintellitype.IntellitypeListener;
|
||||||
import com.melloware.jintellitype.JIntellitype;
|
import com.melloware.jintellitype.JIntellitype;
|
||||||
|
|
||||||
|
|
||||||
public class JIntellitypeDevice extends Device implements HotkeyListener, IntellitypeListener {
|
public class JIntellitypeDevice extends Device implements HotkeyListener, IntellitypeListener {
|
||||||
protected static final String TITLE = "JIntellitype";
|
protected static final String TITLE = "JIntellitype";
|
||||||
|
|
||||||
|
protected JIntellitypeEventMapCycle eventMapCycle;
|
||||||
protected ArrayList<Hotkey> hotkeyList;
|
protected ArrayList<Hotkey> hotkeyList;
|
||||||
protected JIntellitype jit;
|
protected JIntellitype jit;
|
||||||
|
|
||||||
@@ -28,45 +24,15 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
|||||||
hotkeyList = new ArrayList<Hotkey>();
|
hotkeyList = new ArrayList<Hotkey>();
|
||||||
jit = JIntellitype.getInstance();
|
jit = JIntellitype.getInstance();
|
||||||
Hotkey.initialise(hotkeyList, jit);
|
Hotkey.initialise(hotkeyList, jit);
|
||||||
|
eventMapCycle = new JIntellitypeEventMapCycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
super.activate();
|
super.activate();
|
||||||
jit.addHotKeyListener(this);
|
jit.addHotKeyListener(this);
|
||||||
jit.addIntellitypeListener(this);
|
jit.addIntellitypeListener(this);
|
||||||
add(
|
add(eventMapCycle.mimis);
|
||||||
new Hotkey(Key.PRIOR),
|
add(eventMapCycle.player);
|
||||||
new Task(Target.MIMIS, Action.PREVIOUS));
|
|
||||||
add(
|
|
||||||
new Hotkey(Key.NEXT),
|
|
||||||
new Task(Target.MIMIS, Action.NEXT));
|
|
||||||
add(
|
|
||||||
new Press(CommandButton.VOLUME_DOWN),
|
|
||||||
new Task(Target.APPLICATIONS, Action.VOLUME_DOWN));
|
|
||||||
add(
|
|
||||||
new Press(CommandButton.VOLUME_UP),
|
|
||||||
new Task(Target.APPLICATIONS, Action.VOLUME_UP));
|
|
||||||
add(
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),
|
|
||||||
new Task(Target.MIMIS, Action.EXIT));
|
|
||||||
add(
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'n'),
|
|
||||||
new Task(Target.APPLICATION, Action.NEXT));
|
|
||||||
add(
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'p'),
|
|
||||||
new Task(Target.APPLICATION, Action.PREVIOUS));
|
|
||||||
/*add(
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 't'),
|
|
||||||
new Task(Action.TEST, Target.MAIN));
|
|
||||||
add(
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 'r'),
|
|
||||||
new Hotkey(Modifier.CTRL | Modifier.WIN, 's'),
|
|
||||||
new Continuous(Action.REPEAT, Target.APPLICATIONS, 500));*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void add(Hotkey hotkey, Task task) {
|
|
||||||
add(new Press(hotkey), task);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onIntellitype(int command) {
|
public void onIntellitype(int command) {
|
||||||
@@ -89,8 +55,8 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void deactivate() throws DeactivateException {
|
||||||
super.stop();
|
super.deactivate();
|
||||||
jit.removeHotKeyListener(this);
|
jit.removeHotKeyListener(this);
|
||||||
jit.removeIntellitypeListener(this);
|
jit.removeIntellitypeListener(this);
|
||||||
jit.cleanUp();
|
jit.cleanUp();
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package mimis.device.jintellitype;
|
||||||
|
|
||||||
|
import mimis.device.EventMapCycle;
|
||||||
|
import mimis.event.Task;
|
||||||
|
import mimis.sequence.EventMap;
|
||||||
|
import mimis.sequence.state.Press;
|
||||||
|
import mimis.value.Action;
|
||||||
|
import mimis.value.Key;
|
||||||
|
import mimis.value.Target;
|
||||||
|
|
||||||
|
public class JIntellitypeEventMapCycle extends EventMapCycle {
|
||||||
|
protected static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public EventMap mimis, player;
|
||||||
|
|
||||||
|
public JIntellitypeEventMapCycle() {
|
||||||
|
/* Mimis */
|
||||||
|
mimis = new EventMap();
|
||||||
|
mimis.add(
|
||||||
|
new Hotkey(Key.PRIOR),
|
||||||
|
new Task(Target.MIMIS, Action.PREVIOUS));
|
||||||
|
mimis.add(
|
||||||
|
new Hotkey(Key.NEXT),
|
||||||
|
new Task(Target.MIMIS, Action.NEXT));
|
||||||
|
|
||||||
|
/* Player */
|
||||||
|
player = new EventMap();
|
||||||
|
player.add(
|
||||||
|
new Press(CommandButton.VOLUME_DOWN),
|
||||||
|
new Task(Target.APPLICATIONS, Action.VOLUME_DOWN));
|
||||||
|
player.add(
|
||||||
|
new Press(CommandButton.VOLUME_UP),
|
||||||
|
new Task(Target.APPLICATIONS, Action.VOLUME_UP));
|
||||||
|
player.add(
|
||||||
|
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),
|
||||||
|
new Task(Target.MIMIS, Action.EXIT));
|
||||||
|
player.add(
|
||||||
|
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'n'),
|
||||||
|
new Task(Target.APPLICATION, Action.NEXT));
|
||||||
|
player.add(
|
||||||
|
new Hotkey(Modifier.CTRL | Modifier.SHIFT | Modifier.WIN, 'p'),
|
||||||
|
new Task(Target.APPLICATION, Action.PREVIOUS));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import mimis.Button;
|
|||||||
import mimis.Device;
|
import mimis.Device;
|
||||||
import mimis.device.wiimote.gesture.GestureDevice;
|
import mimis.device.wiimote.gesture.GestureDevice;
|
||||||
import mimis.event.Feedback;
|
import mimis.event.Feedback;
|
||||||
import mimis.event.Task;
|
|
||||||
import mimis.exception.button.UnknownButtonException;
|
import mimis.exception.button.UnknownButtonException;
|
||||||
import mimis.exception.device.DeviceNotFoundException;
|
import mimis.exception.device.DeviceNotFoundException;
|
||||||
import mimis.exception.worker.ActivateException;
|
import mimis.exception.worker.ActivateException;
|
||||||
@@ -12,31 +11,26 @@ import mimis.exception.worker.DeactivateException;
|
|||||||
import mimis.sequence.state.Press;
|
import mimis.sequence.state.Press;
|
||||||
import mimis.sequence.state.Release;
|
import mimis.sequence.state.Release;
|
||||||
import mimis.value.Action;
|
import mimis.value.Action;
|
||||||
|
|
||||||
import org.wiigee.event.GestureEvent;
|
import org.wiigee.event.GestureEvent;
|
||||||
import org.wiigee.event.GestureListener;
|
import org.wiigee.event.GestureListener;
|
||||||
import org.wiigee.util.Log;
|
import org.wiigee.util.Log;
|
||||||
|
|
||||||
import wiiusej.Wiimote;
|
import wiiusej.Wiimote;
|
||||||
import wiiusej.values.Calibration;
|
|
||||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||||
|
|
||||||
public class WiimoteDevice extends Device implements GestureListener {
|
public class WiimoteDevice extends Device implements GestureListener {
|
||||||
protected static final String TITLE = "Wiimote";
|
protected static final String TITLE = "Wiimote";
|
||||||
|
|
||||||
protected static final int CONNECT_MAX = 10;
|
|
||||||
protected static final int RUMBLE = 150;
|
protected static final int RUMBLE = 150;
|
||||||
public static final int TIMEOUT = 200;
|
protected static final int TIMEOUT = 200;
|
||||||
|
|
||||||
protected static WiimoteService wiimoteService;
|
protected static WiimoteService wiimoteService;
|
||||||
|
protected WiimoteEventMapCycle eventMapCycle;
|
||||||
protected Wiimote wiimote;
|
|
||||||
protected Calibration calibration;
|
|
||||||
protected GestureDevice gestureDevice;
|
|
||||||
protected int gestureId;
|
|
||||||
protected WiimoteDiscovery wiimoteDiscovery;
|
protected WiimoteDiscovery wiimoteDiscovery;
|
||||||
protected boolean connected;
|
protected boolean connected;
|
||||||
|
protected Wiimote wiimote;
|
||||||
|
protected GestureDevice gestureDevice;
|
||||||
|
protected int gestureId;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
WiimoteDevice.wiimoteService = new WiimoteService();
|
WiimoteDevice.wiimoteService = new WiimoteService();
|
||||||
@@ -45,6 +39,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
|
|
||||||
public WiimoteDevice() {
|
public WiimoteDevice() {
|
||||||
super(TITLE);
|
super(TITLE);
|
||||||
|
eventMapCycle = new WiimoteEventMapCycle();
|
||||||
wiimoteDiscovery = new WiimoteDiscovery(this);
|
wiimoteDiscovery = new WiimoteDiscovery(this);
|
||||||
gestureDevice = new GestureDevice();
|
gestureDevice = new GestureDevice();
|
||||||
gestureDevice.add(this);
|
gestureDevice.add(this);
|
||||||
@@ -55,67 +50,9 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
super.activate();
|
super.activate();
|
||||||
connect();
|
connect();
|
||||||
/*add(
|
add(eventMapCycle.mimis);
|
||||||
new Hold(WiimoteButton.A),
|
add(eventMapCycle.player);
|
||||||
new Task(Action.TRAIN),
|
add(eventMapCycle.like);
|
||||||
new Task(Action.STOP));*/
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.B),
|
|
||||||
new Task(Action.SAVE));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.DOWN),
|
|
||||||
new Task(Action.LOAD));
|
|
||||||
/*add(
|
|
||||||
new Hold(WiimoteButton.HOME),
|
|
||||||
new Task(Action.RECOGNIZE),
|
|
||||||
new Task(Action.STOP));/*
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.A),
|
|
||||||
new Task(Target.APPLICATION, Action.PLAY));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.B),
|
|
||||||
new Task(Target.APPLICATION, Action.MUTE));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.ONE),
|
|
||||||
new Task(Target.APPLICATION, Action.SHUFFLE));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.TWO),
|
|
||||||
new Task(Target.APPLICATION, Action.REPEAT));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.UP),
|
|
||||||
new Task(Target.APPLICATION, Action.NEXT));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.DOWN),
|
|
||||||
new Task(Target.APPLICATION, Action.PREVIOUS));
|
|
||||||
add(
|
|
||||||
new Hold(WiimoteButton.RIGHT),
|
|
||||||
new Dynamic(Action.FORWARD, Target.APPLICATION, 200, -30));
|
|
||||||
add(
|
|
||||||
new Hold(WiimoteButton.LEFT),
|
|
||||||
new Dynamic(Action.REWIND, Target.APPLICATION, 200, -30));
|
|
||||||
add(
|
|
||||||
new Hold(WiimoteButton.MINUS),
|
|
||||||
new Continuous(Action.VOLUME_DOWN, Target.APPLICATION, 100));
|
|
||||||
add(
|
|
||||||
new Hold(WiimoteButton.PLUS),
|
|
||||||
new Continuous(Action.VOLUME_UP, Target.APPLICATION, 100));
|
|
||||||
add(
|
|
||||||
new Press(WiimoteButton.HOME),
|
|
||||||
new Task(Target.MANAGER, Action.NEXT));
|
|
||||||
try {
|
|
||||||
add(
|
|
||||||
new Macro(
|
|
||||||
new Hold(WiimoteButton.TWO),
|
|
||||||
new Press(WiimoteButton.PLUS),
|
|
||||||
new Release(WiimoteButton.TWO)),
|
|
||||||
new Task(Target.APPLICATION, Action.LIKE));
|
|
||||||
add(
|
|
||||||
new Macro(
|
|
||||||
new Hold(WiimoteButton.TWO),
|
|
||||||
new Press(WiimoteButton.MINUS),
|
|
||||||
new Release(WiimoteButton.TWO)),
|
|
||||||
new Task(Target.APPLICATION, Action.DISLIKE));
|
|
||||||
} catch (StateOrderException e) {}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
public void deactivate() throws DeactivateException {
|
||||||
@@ -132,33 +69,41 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Events */
|
/* Events */
|
||||||
public void action(Action action) {
|
public void begin(Action action) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case TRAIN:
|
case TRAIN:
|
||||||
System.out.println("Wiimote Train");
|
log.debug("Gesture train");
|
||||||
gestureDevice.train();
|
gestureDevice.train();
|
||||||
break;
|
break;
|
||||||
case STOP:
|
|
||||||
System.out.println("Wiimote Stop");
|
|
||||||
gestureDevice.stop();
|
|
||||||
break;
|
|
||||||
case SAVE:
|
case SAVE:
|
||||||
System.out.println("Wiimote Save");
|
log.debug("Gesture save");
|
||||||
gestureDevice.close();
|
gestureDevice.close();
|
||||||
gestureDevice.saveGesture(gestureId, "C:\\gesture-" + gestureId);
|
gestureDevice.saveGesture(gestureId, "C:\\gesture-" + gestureId);
|
||||||
++gestureId;
|
++gestureId;
|
||||||
break;
|
break;
|
||||||
case LOAD:
|
case LOAD:
|
||||||
|
log.debug("Gesture load");
|
||||||
for (int i = 0; i < gestureId; ++i) {
|
for (int i = 0; i < gestureId; ++i) {
|
||||||
gestureDevice.loadGesture("C:\\gesture-" + i);
|
gestureDevice.loadGesture("C:\\gesture-" + i);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RECOGNIZE:
|
case RECOGNIZE:
|
||||||
|
log.debug("Gesture recognize");
|
||||||
gestureDevice.recognize();
|
gestureDevice.recognize();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void end(Action action) {
|
||||||
|
switch (action) {
|
||||||
|
case TRAIN:
|
||||||
|
case RECOGNIZE:
|
||||||
|
log.debug("Gesture stop");
|
||||||
|
gestureDevice.stop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void feedback(Feedback feedback) {
|
public void feedback(Feedback feedback) {
|
||||||
System.out.println("Wiimote feedback");
|
System.out.println("Wiimote feedback");
|
||||||
wiimote.rumble(RUMBLE);
|
wiimote.rumble(RUMBLE);
|
||||||
|
|||||||
96
java/src/mimis/device/wiimote/WiimoteEventMapCycle.java
Normal file
96
java/src/mimis/device/wiimote/WiimoteEventMapCycle.java
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
package mimis.device.wiimote;
|
||||||
|
|
||||||
|
import mimis.Macro;
|
||||||
|
import mimis.device.EventMapCycle;
|
||||||
|
import mimis.event.Task;
|
||||||
|
import mimis.exception.macro.StateOrderException;
|
||||||
|
import mimis.sequence.EventMap;
|
||||||
|
import mimis.sequence.state.Hold;
|
||||||
|
import mimis.sequence.state.Press;
|
||||||
|
import mimis.sequence.state.Release;
|
||||||
|
import mimis.value.Action;
|
||||||
|
import mimis.value.Target;
|
||||||
|
|
||||||
|
public class WiimoteEventMapCycle extends EventMapCycle {
|
||||||
|
protected static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public EventMap mimis, player, gesture, like;
|
||||||
|
|
||||||
|
public WiimoteEventMapCycle() {
|
||||||
|
/* Mimis */
|
||||||
|
mimis = new EventMap();
|
||||||
|
mimis.add(
|
||||||
|
new Press(WiimoteButton.HOME),
|
||||||
|
new Task(Target.MIMIS, Action.NEXT));
|
||||||
|
|
||||||
|
/* Gesture */
|
||||||
|
gesture = new EventMap();
|
||||||
|
gesture.add(
|
||||||
|
new Press(WiimoteButton.A),
|
||||||
|
new Task(Action.TRAIN));
|
||||||
|
gesture.add(
|
||||||
|
new Press(WiimoteButton.B),
|
||||||
|
new Task(Action.SAVE));
|
||||||
|
gesture.add(
|
||||||
|
new Press(WiimoteButton.DOWN),
|
||||||
|
new Task(Action.LOAD));
|
||||||
|
gesture.add(
|
||||||
|
new Press(WiimoteButton.HOME),
|
||||||
|
new Task(Action.RECOGNIZE));
|
||||||
|
add(gesture);
|
||||||
|
|
||||||
|
/* Player */
|
||||||
|
player = new EventMap();
|
||||||
|
player.add(
|
||||||
|
new Press(WiimoteButton.A),
|
||||||
|
new Task(Target.APPLICATION, Action.PLAY));
|
||||||
|
player.add(
|
||||||
|
new Press(WiimoteButton.B),
|
||||||
|
new Task(Target.APPLICATION, Action.MUTE));
|
||||||
|
player.add(
|
||||||
|
new Press(WiimoteButton.ONE),
|
||||||
|
new Task(Target.APPLICATION, Action.SHUFFLE));
|
||||||
|
player.add(
|
||||||
|
new Press(WiimoteButton.TWO),
|
||||||
|
new Task(Target.APPLICATION, Action.REPEAT));
|
||||||
|
player.add(
|
||||||
|
new Press(WiimoteButton.UP),
|
||||||
|
new Task(Target.APPLICATION, Action.NEXT));
|
||||||
|
player.add(
|
||||||
|
new Press(WiimoteButton.DOWN),
|
||||||
|
new Task(Target.APPLICATION, Action.PREVIOUS));
|
||||||
|
player.add(
|
||||||
|
new Press(WiimoteButton.RIGHT),
|
||||||
|
new Task(Target.APPLICATION, Action.FORWARD));
|
||||||
|
player.add(
|
||||||
|
new Press(WiimoteButton.LEFT),
|
||||||
|
new Task(Target.APPLICATION, Action.REWIND));
|
||||||
|
player.add(
|
||||||
|
new Press(WiimoteButton.MINUS),
|
||||||
|
new Task(Target.APPLICATION, Action.VOLUME_DOWN));
|
||||||
|
player.add(
|
||||||
|
new Press(WiimoteButton.PLUS),
|
||||||
|
new Task(Target.APPLICATION, Action.VOLUME_UP));
|
||||||
|
add(player);
|
||||||
|
|
||||||
|
/* Like */
|
||||||
|
try {
|
||||||
|
like = new EventMap();
|
||||||
|
like.add(
|
||||||
|
new Macro(
|
||||||
|
new Hold(WiimoteButton.TWO),
|
||||||
|
new Press(WiimoteButton.PLUS),
|
||||||
|
new Release(WiimoteButton.TWO)),
|
||||||
|
new Task(Target.APPLICATION, Action.LIKE));
|
||||||
|
like.add(
|
||||||
|
new Macro(
|
||||||
|
new Hold(WiimoteButton.TWO),
|
||||||
|
new Press(WiimoteButton.MINUS),
|
||||||
|
new Release(WiimoteButton.TWO)),
|
||||||
|
new Task(Target.APPLICATION, Action.DISLIKE));
|
||||||
|
add(like);
|
||||||
|
} catch (StateOrderException e) {
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,6 @@ public abstract class EventHandler extends EventListener {
|
|||||||
protected void feedback(Feedback feedback) {}
|
protected void feedback(Feedback feedback) {}
|
||||||
|
|
||||||
protected final void task(Task task) {
|
protected final void task(Task task) {
|
||||||
log.debug("Signal: " + task.signal);
|
|
||||||
Action action = task.getAction();
|
Action action = task.getAction();
|
||||||
switch (task.getSignal()) {
|
switch (task.getSignal()) {
|
||||||
case BEGIN:
|
case BEGIN:
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ public abstract class EventListener extends Worker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void add(Event event) {
|
public void add(Event event) {
|
||||||
log.info("event " + event + " " + active);
|
|
||||||
eventQueue.add(event);
|
eventQueue.add(event);
|
||||||
synchronized (work) {
|
synchronized (work) {
|
||||||
work.notifyAll();
|
work.notifyAll();
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ public class LocalRouter extends EventRouter {
|
|||||||
default:
|
default:
|
||||||
for (EventListener eventListener : eventListenerList) {
|
for (EventListener eventListener : eventListenerList) {
|
||||||
if (event.compatible(eventListener)) {
|
if (event.compatible(eventListener)) {
|
||||||
log.trace(eventListener);
|
|
||||||
eventListener.add(event);
|
eventListener.add(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
java/src/mimis/sequence/EventMap.java
Normal file
37
java/src/mimis/sequence/EventMap.java
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
package mimis.sequence;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import mimis.Button;
|
||||||
|
import mimis.Event;
|
||||||
|
import mimis.Macro;
|
||||||
|
import mimis.event.Task;
|
||||||
|
import mimis.sequence.state.Press;
|
||||||
|
|
||||||
|
public class EventMap extends HashMap<Sequence, Event> {
|
||||||
|
protected static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public void add(Button button, Task task) {
|
||||||
|
add(new Press(button), task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Press press, Task task) {
|
||||||
|
add(press, task, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void add(Press press, Task task, boolean macro) {
|
||||||
|
if (macro) {
|
||||||
|
add(new Macro(press), task);
|
||||||
|
} else {
|
||||||
|
add((State) press, task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void add(State state, Task task) {
|
||||||
|
add(new Sequence(state), task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Sequence sequence, Task task) {
|
||||||
|
put(sequence, task);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package mimis.sequence;
|
package mimis.sequence;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@@ -17,16 +17,16 @@ public class SequenceListener {
|
|||||||
protected Log log = LogFactory.getLog(getClass());
|
protected Log log = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
protected EventHandler self;
|
protected EventHandler self;
|
||||||
|
protected EventMap eventMap;
|
||||||
protected ArrayList<Sequence> sequenceList;
|
protected ArrayList<Sequence> sequenceList;
|
||||||
protected HashMap<Sequence, Event> eventMap;
|
|
||||||
protected ArrayList<Active> activeList;
|
protected ArrayList<Active> activeList;
|
||||||
|
|
||||||
protected static EventListener eventListener;
|
protected static EventListener eventListener;
|
||||||
|
|
||||||
public SequenceListener(EventHandler self) {
|
public SequenceListener(EventHandler self) {
|
||||||
this.self = self;
|
this.self = self;
|
||||||
|
eventMap = new EventMap();
|
||||||
sequenceList = new ArrayList<Sequence>();
|
sequenceList = new ArrayList<Sequence>();
|
||||||
eventMap = new HashMap<Sequence, Event>();
|
|
||||||
activeList = new ArrayList<Active>();
|
activeList = new ArrayList<Active>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,14 +34,27 @@ public class SequenceListener {
|
|||||||
SequenceListener.eventListener = eventListener;
|
SequenceListener.eventListener = eventListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int add(Sequence sequence, Task task) {
|
public synchronized void add(EventMap eventMap) {
|
||||||
int id = sequenceList.size();
|
this.eventMap.putAll(eventMap);
|
||||||
sequenceList.add(sequence);
|
sequenceList.addAll(eventMap.keySet());
|
||||||
eventMap.put(sequence, task);
|
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(State state) {
|
public void remove(EventMap eventMap) {
|
||||||
|
for (Entry<Sequence, Event> entry : eventMap.entrySet()) {
|
||||||
|
Sequence sequence = entry.getKey();
|
||||||
|
this.eventMap.remove(sequence);
|
||||||
|
sequenceList.remove(sequence);
|
||||||
|
activeList.remove(sequence);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void reset() {
|
||||||
|
eventMap.clear();
|
||||||
|
sequenceList.clear();
|
||||||
|
activeList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void add(State state) {
|
||||||
for (Sequence sequence : sequenceList) {
|
for (Sequence sequence : sequenceList) {
|
||||||
activeList.add(new Active(sequence));
|
activeList.add(new Active(sequence));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user