Buttons van Wiimote geimplementeerd.

This commit is contained in:
2011-02-13 20:41:30 +00:00
parent 7fe13d454b
commit b0e2b09487
5 changed files with 66 additions and 17 deletions

View File

@@ -8,6 +8,7 @@ import pm.application.iTunes.iTunesApplication;
import pm.device.gui.GUIDevice;
import pm.device.javainput.rumblepad.RumblepadDevice;
import pm.device.jintellitype.JIntellitypeDevice;
import pm.device.wiimote.WiimoteDevice;
import pm.exception.application.ApplicationExitException;
import pm.exception.device.DeviceExitException;
import pm.exception.device.DeviceInitialiseException;
@@ -34,7 +35,8 @@ public class Main extends TaskListener {
public void initialise() throws DeviceInitialiseException {
add(new JIntellitypeDevice());
add(new RumblepadDevice());
//add(new RumblepadDevice());
add(new WiimoteDevice());
//add(new GUIDevice());
for (Device device : deviceList) {
device.initialise();
@@ -42,7 +44,7 @@ public class Main extends TaskListener {
add(new ExampleApplication());
//add(new WinampApplication());
add(new iTunesApplication());
//add(new iTunesApplication());
applicationCycle.next();
for (Application application : applicationCycle) {
application.start();

View File

@@ -0,0 +1,10 @@
package pm.device.wiimote;
import org.wiigee.event.GestureEvent;
import org.wiigee.event.GestureListener;
public class GestureService implements GestureListener {
public void gestureReceived(GestureEvent event) {
System.out.println(event);
}
}

View File

@@ -1,6 +1,7 @@
package pm.device.wiimote;
import pm.Button;
import pm.exception.event.UnknownButtonException;
public enum WiimoteButton implements Button {
TWO (0x0001),
@@ -25,4 +26,13 @@ public enum WiimoteButton implements Button {
public int getCode() {
return code;
}
public static WiimoteButton create(int code) throws UnknownButtonException {
for (WiimoteButton button : WiimoteButton.values()) {
if (button.getCode() == code) {
return button;
}
}
throw new UnknownButtonException();
}
}

View File

@@ -1,37 +1,60 @@
package pm.device.wiimote;
import pm.Action;
import pm.Button;
import pm.Device;
import pm.Target;
import pm.exception.MacroException;
import pm.Task;
import pm.exception.device.DeviceInitialiseException;
import pm.exception.event.UnknownButtonException;
import pm.macro.event.Press;
import pm.macro.event.Release;
import wiiusej.Wiimote;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
public class WiimoteDevice extends Device {
protected static final int CONNECT_MAX = 10;
protected static WiimoteService wiimoteService;
protected static GestureService gestureService;
protected Wiimote wiimote;
public WiimoteDevice() {
{
WiimoteDevice.wiimoteService = new WiimoteService();
WiimoteDevice.gestureService = new GestureService();
}
public void initialise() throws DeviceInitialiseException {
wiimote = wiimoteService.getDevice(this);
try {
add(
new Press(WiimoteButton.A),
Action.TEST.setTarget(Target.APPLICATION));
} catch (MacroException e) {
e.printStackTrace();
}
wiimote.activateMotionSensing();
add(
new Press(WiimoteButton.A),
new Task(Action.TEST, Target.APPLICATION));
}
public void exit() {
wiimoteService.exit();
}
public void onButtonsEvent(WiimoteButtonsEvent event) {
//evm.macroEvent(event, getWiimote(event));
int pressed = event.getButtonsJustPressed() - event.getButtonsHeld();
int released = event.getButtonsJustReleased();
try {
if (pressed != 0 && released == 0) {
Button button = WiimoteButton.create(pressed);
System.out.println("Press: " + button);
add(new Press(button));
} else if (pressed == 0 && released != 0) {
Button button = WiimoteButton.create(released);
System.out.println("Release: " + button);
add(new Release(button));
}
} catch (UnknownButtonException e) {}
}
public void onMotionSensingEvent(MotionSensingEvent event) {
//System.out.println(event.getRawAcceleration());
}
}

View File

@@ -22,6 +22,8 @@ import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
public class WiimoteService extends WiiUseApiManager implements WiimoteListener {
protected final boolean RUMBLE = false;
protected ArrayList<Integer> wiimoteList;
protected Wiimote[] wiimoteArray;
protected HashMap<Integer, WiimoteDevice> wiimoteDeviceMap;
@@ -32,8 +34,7 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
wiimoteDeviceMap = new HashMap<Integer, WiimoteDevice>();
}
public void finish() {
// Todo: methode bedenken om deze methode aangeroepen te krijgen, zonder de service in de main te hoeven registreren.
public void exit() {
if (wiimoteArray != null) {
for (Wiimote wiimote : wiimoteArray) {
wiimote.disconnect();
@@ -43,7 +44,7 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
}
public Wiimote getDevice(WiimoteDevice wiimoteDevice) throws DeviceNotFoundException {
Wiimote[] wiimoteArray = getWiimotes(1, false);
Wiimote[] wiimoteArray = getWiimotes(1, RUMBLE);
for (Wiimote wiimote : wiimoteArray) {
int id = wiimote.getId();
if (!wiimoteList.contains(id)) {
@@ -65,7 +66,11 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
}
public void onButtonsEvent(WiimoteButtonsEvent event) {
getWiimoteDevice(event).onButtonsEvent(event);
}
public void onMotionSensingEvent(MotionSensingEvent event) {
getWiimoteDevice(event).onMotionSensingEvent(event);
}
public void onStatusEvent(StatusEvent event) {
@@ -75,7 +80,6 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
}
public void onIrEvent(IREvent e) {}
public void onMotionSensingEvent(MotionSensingEvent event) {}
public void onExpansionEvent(ExpansionEvent event) {}
public void onDisconnectionEvent(DisconnectionEvent event) {}
public void onNunchukInsertedEvent(NunchukInsertedEvent event) {}