From e9c0216ad93234c8649a249c82636feb2df95582 Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Tue, 8 Feb 2011 19:06:16 +0000 Subject: [PATCH] Verder gewerkt aan implementatie wiimote. --- java/src/pm/device/wiimote/WiimoteDevice.java | 5 +++ .../src/pm/device/wiimote/WiimoteService.java | 35 +++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/java/src/pm/device/wiimote/WiimoteDevice.java b/java/src/pm/device/wiimote/WiimoteDevice.java index e4b43fc..d59ca02 100644 --- a/java/src/pm/device/wiimote/WiimoteDevice.java +++ b/java/src/pm/device/wiimote/WiimoteDevice.java @@ -7,6 +7,7 @@ import pm.exception.DeviceException; import pm.exception.MacroException; import pm.macro.event.Press; import wiiusej.Wiimote; +import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; public class WiimoteDevice extends Device { protected static final int CONNECT_MAX = 10; @@ -33,4 +34,8 @@ public class WiimoteDevice extends Device { e.printStackTrace(); } } + + public void onButtonsEvent(WiimoteButtonsEvent event) { + //evm.macroEvent(event, getWiimote(event)); + } } diff --git a/java/src/pm/device/wiimote/WiimoteService.java b/java/src/pm/device/wiimote/WiimoteService.java index 0aa1ab2..196c173 100644 --- a/java/src/pm/device/wiimote/WiimoteService.java +++ b/java/src/pm/device/wiimote/WiimoteService.java @@ -7,6 +7,7 @@ import pm.exception.DeviceException; import pm.exception.device.JavaInputDeviceNotFoundException; import wiiusej.WiiUseApiManager; import wiiusej.Wiimote; +import wiiusej.wiiusejevents.GenericEvent; import wiiusej.wiiusejevents.physicalevents.ExpansionEvent; import wiiusej.wiiusejevents.physicalevents.IREvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; @@ -23,11 +24,23 @@ import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; public class WiimoteService extends WiiUseApiManager implements WiimoteListener { protected ArrayList wiimoteList; - protected HashMap wiimoteMap; + protected Wiimote[] wiimoteArray; + protected HashMap wiimoteDeviceMap; WiimoteService() { wiimoteList = new ArrayList(); - wiimoteMap = new HashMap(); + wiimoteArray = new Wiimote[0]; + wiimoteDeviceMap = new HashMap(); + } + + public void finish() { + // Todo: methode bedenken om deze methode aangeroepen te krijgen, zonder de service in de main te hoeven registreren. + if (wiimoteArray != null) { + for (Wiimote wiimote : wiimoteArray) { + wiimote.disconnect(); + } + } + definitiveShutdown(); } public Wiimote getDevice(WiimoteDevice wiimoteDevice) throws DeviceException { @@ -37,21 +50,29 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener if (!wiimoteList.contains(id)) { wiimote.addWiiMoteEventListeners(this); wiimoteList.add(id); - wiimoteMap.put(wiimote, wiimoteDevice); + wiimoteDeviceMap.put(id, wiimoteDevice); // Todo: controleren of dit nodig is. Ligt aan hoe uniek het id is na bijvoorbeeld een reconnect. Wellicht voldoet een arrayList ook. return wiimote; } } throw new JavaInputDeviceNotFoundException(); } + public Wiimote getWiimote(GenericEvent event) { + return wiimoteArray[event.getWiimoteId() - 1]; + } + + public WiimoteDevice getWiimoteDevice(GenericEvent event){ + return wiimoteDeviceMap.get(event.getWiimoteId()); + } + public void onButtonsEvent(WiimoteButtonsEvent event) { - //evm.macroEvent(event, getWiimote(event)); + } public void onStatusEvent(StatusEvent event) { - /*if (event.isConnected()) { - evm.event(WiimoteEvent.CONNECT, getWiimote(event)); - }*/ + if (event.isConnected()) { + + } } public void onIrEvent(IREvent e) {}