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