Buttons van Wiimote geimplementeerd.
This commit is contained in:
10
java/src/pm/device/wiimote/GestureService.java
Normal file
10
java/src/pm/device/wiimote/GestureService.java
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
Reference in New Issue
Block a user