Enkele hele kleine wijzigingen aangebracht.
This commit is contained in:
@@ -7,13 +7,13 @@ import mimis.exception.worker.DeactivateException;
|
||||
import mimis.manager.Exitable;
|
||||
import mimis.manager.Titled;
|
||||
import mimis.sequence.EventMap;
|
||||
import mimis.sequence.SequenceListener;
|
||||
import mimis.sequence.EventParser;
|
||||
import mimis.sequence.State;
|
||||
|
||||
public abstract class Device extends EventHandler implements Titled, Exitable {
|
||||
protected String title;
|
||||
protected EventMapCycle eventMapCycle;
|
||||
protected SequenceListener sequenceListener;
|
||||
protected EventParser eventParser;
|
||||
|
||||
public Device(String title) {
|
||||
this.title = title;
|
||||
@@ -26,12 +26,12 @@ public abstract class Device extends EventHandler implements Titled, Exitable {
|
||||
/* Worker */
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
sequenceListener = new SequenceListener(this);
|
||||
eventParser = new EventParser(this);
|
||||
}
|
||||
|
||||
public void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
sequenceListener.reset();
|
||||
eventParser.reset();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
@@ -45,20 +45,20 @@ public abstract class Device extends EventHandler implements Titled, Exitable {
|
||||
super.stop();
|
||||
}
|
||||
|
||||
/* SequenceListener */
|
||||
/* EventParser */
|
||||
protected void add(EventMap eventMap) {
|
||||
sequenceListener.add(eventMap);
|
||||
eventParser.add(eventMap);
|
||||
}
|
||||
|
||||
protected void remove(EventMap eventMap) {
|
||||
sequenceListener.remove(eventMap);
|
||||
eventParser.remove(eventMap);
|
||||
}
|
||||
|
||||
protected void add(State state) {
|
||||
sequenceListener.add(state);
|
||||
protected void reset() {
|
||||
eventParser.reset();
|
||||
}
|
||||
|
||||
protected void reset() {
|
||||
sequenceListener.reset();
|
||||
protected void add(State state) {
|
||||
eventParser.add(state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import mimis.event.EventRouter;
|
||||
import mimis.event.Feedback;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.feedback.TextFeedback;
|
||||
import mimis.sequence.SequenceListener;
|
||||
import mimis.sequence.EventParser;
|
||||
import mimis.util.ArrayCycle;
|
||||
import mimis.value.Action;
|
||||
|
||||
@@ -40,9 +40,9 @@ public class Mimis extends EventHandler {
|
||||
this.deviceArray = deviceArray;
|
||||
applicationCycle = new ArrayCycle<Application>(applicationArray);
|
||||
|
||||
log.debug("Initialise EventHandler and SequenceListener");
|
||||
log.debug("Initialise EventHandler and EventParser");
|
||||
EventHandler.initialise(eventRouter);
|
||||
SequenceListener.initialise(eventRouter);
|
||||
EventParser.initialise(eventRouter);
|
||||
|
||||
log.debug("Add EventListeners to EventRouter");
|
||||
eventRouter.add(this);
|
||||
|
||||
@@ -27,8 +27,8 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
protected static WiimoteService wiimoteService;
|
||||
protected WiimoteEventMapCycle eventMapCycle;
|
||||
protected WiimoteDiscovery wiimoteDiscovery;
|
||||
protected boolean connected;
|
||||
protected Wiimote wiimote;
|
||||
protected boolean connected;
|
||||
protected GestureDevice gestureDevice;
|
||||
protected int gestureId;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
gestureId = 0;
|
||||
}
|
||||
|
||||
/* Activation */
|
||||
/* Worker */
|
||||
public void activate() throws ActivateException {
|
||||
super.activate();
|
||||
connect();
|
||||
@@ -54,6 +54,25 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
add(eventMapCycle.player);
|
||||
add(eventMapCycle.like);
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
if (wiimote != null) {
|
||||
connected = false;
|
||||
wiimote.getStatus();
|
||||
synchronized (this) {
|
||||
try {
|
||||
wait(TIMEOUT);
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
if (!connected) {
|
||||
disconnect();
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
return active;
|
||||
}
|
||||
|
||||
public void deactivate() throws DeactivateException {
|
||||
super.deactivate();
|
||||
@@ -110,22 +129,12 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
}
|
||||
|
||||
/* Connectivity */
|
||||
public void connect() {
|
||||
public void connect() throws ActivateException {
|
||||
wiimote = null;
|
||||
try {
|
||||
wiimote = wiimoteService.getDevice(this);
|
||||
super.activate();
|
||||
} catch (DeviceNotFoundException e) {
|
||||
log.error(e);
|
||||
} catch (ActivateException e) {
|
||||
log.error(e);
|
||||
}
|
||||
if (wiimote == null) {
|
||||
try {
|
||||
wiimoteDiscovery.activate();
|
||||
} catch (ActivateException e) {
|
||||
log.error(e);
|
||||
}
|
||||
wiimoteDiscovery.activate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,25 +166,6 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
if (wiimote != null) {
|
||||
connected = false;
|
||||
wiimote.getStatus();
|
||||
synchronized (this) {
|
||||
try {
|
||||
wait(TIMEOUT);
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
if (!connected) {
|
||||
disconnect();
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
return active;
|
||||
}
|
||||
|
||||
/* Listeners */
|
||||
public void onButtonsEvent(WiimoteButtonsEvent event) {
|
||||
int pressed = event.getButtonsJustPressed() - event.getButtonsHeld();
|
||||
|
||||
@@ -37,7 +37,7 @@ public class WiimoteDiscovery extends Worker {
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
} finally {
|
||||
process =null;
|
||||
process = null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -89,12 +89,9 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
|
||||
}
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent e) {}
|
||||
public void onIrEvent(IREvent event) {}
|
||||
public void onExpansionEvent(ExpansionEvent event) {}
|
||||
public void onDisconnectionEvent(DisconnectionEvent event) {
|
||||
log.debug("disconnect!");
|
||||
|
||||
}
|
||||
public void onDisconnectionEvent(DisconnectionEvent event) {}
|
||||
public void onNunchukInsertedEvent(NunchukInsertedEvent event) {}
|
||||
public void onNunchukRemovedEvent(NunchukRemovedEvent event) {}
|
||||
public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent event) {}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package mimis.sequence;
|
||||
|
||||
|
||||
public class Active {
|
||||
protected Sequence sequence;
|
||||
protected int step;
|
||||
|
||||
@@ -13,7 +13,7 @@ import mimis.event.Task;
|
||||
import mimis.value.Signal;
|
||||
import mimis.value.Target;
|
||||
|
||||
public class SequenceListener {
|
||||
public class EventParser {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
|
||||
protected EventHandler self;
|
||||
@@ -23,7 +23,7 @@ public class SequenceListener {
|
||||
|
||||
protected static EventListener eventListener;
|
||||
|
||||
public SequenceListener(EventHandler self) {
|
||||
public EventParser(EventHandler self) {
|
||||
this.self = self;
|
||||
eventMap = new EventMap();
|
||||
sequenceList = new ArrayList<Sequence>();
|
||||
@@ -31,7 +31,7 @@ public class SequenceListener {
|
||||
}
|
||||
|
||||
public static void initialise(EventListener eventListener) {
|
||||
SequenceListener.eventListener = eventListener;
|
||||
EventParser.eventListener = eventListener;
|
||||
}
|
||||
|
||||
public synchronized void add(EventMap eventMap) {
|
||||
@@ -39,7 +39,7 @@ public class SequenceListener {
|
||||
sequenceList.addAll(eventMap.keySet());
|
||||
}
|
||||
|
||||
public void remove(EventMap eventMap) {
|
||||
public synchronized void remove(EventMap eventMap) {
|
||||
for (Entry<Sequence, Event> entry : eventMap.entrySet()) {
|
||||
Sequence sequence = entry.getKey();
|
||||
this.eventMap.remove(sequence);
|
||||
@@ -493,10 +493,6 @@ public class Wiimote implements WiiUseApiListener {
|
||||
return "Wiimote with ID : " + id;
|
||||
}
|
||||
|
||||
public Calibration getCalibration() {
|
||||
return manager.getCalibration(id);
|
||||
}
|
||||
|
||||
public void rumble(int milliseconds) {
|
||||
activateRumble();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user