Buttons van Wiimote geimplementeerd.
This commit is contained in:
@@ -8,6 +8,7 @@ import pm.application.iTunes.iTunesApplication;
|
|||||||
import pm.device.gui.GUIDevice;
|
import pm.device.gui.GUIDevice;
|
||||||
import pm.device.javainput.rumblepad.RumblepadDevice;
|
import pm.device.javainput.rumblepad.RumblepadDevice;
|
||||||
import pm.device.jintellitype.JIntellitypeDevice;
|
import pm.device.jintellitype.JIntellitypeDevice;
|
||||||
|
import pm.device.wiimote.WiimoteDevice;
|
||||||
import pm.exception.application.ApplicationExitException;
|
import pm.exception.application.ApplicationExitException;
|
||||||
import pm.exception.device.DeviceExitException;
|
import pm.exception.device.DeviceExitException;
|
||||||
import pm.exception.device.DeviceInitialiseException;
|
import pm.exception.device.DeviceInitialiseException;
|
||||||
@@ -34,7 +35,8 @@ public class Main extends TaskListener {
|
|||||||
|
|
||||||
public void initialise() throws DeviceInitialiseException {
|
public void initialise() throws DeviceInitialiseException {
|
||||||
add(new JIntellitypeDevice());
|
add(new JIntellitypeDevice());
|
||||||
add(new RumblepadDevice());
|
//add(new RumblepadDevice());
|
||||||
|
add(new WiimoteDevice());
|
||||||
//add(new GUIDevice());
|
//add(new GUIDevice());
|
||||||
for (Device device : deviceList) {
|
for (Device device : deviceList) {
|
||||||
device.initialise();
|
device.initialise();
|
||||||
@@ -42,7 +44,7 @@ public class Main extends TaskListener {
|
|||||||
|
|
||||||
add(new ExampleApplication());
|
add(new ExampleApplication());
|
||||||
//add(new WinampApplication());
|
//add(new WinampApplication());
|
||||||
add(new iTunesApplication());
|
//add(new iTunesApplication());
|
||||||
applicationCycle.next();
|
applicationCycle.next();
|
||||||
for (Application application : applicationCycle) {
|
for (Application application : applicationCycle) {
|
||||||
application.start();
|
application.start();
|
||||||
|
|||||||
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;
|
package pm.device.wiimote;
|
||||||
|
|
||||||
import pm.Button;
|
import pm.Button;
|
||||||
|
import pm.exception.event.UnknownButtonException;
|
||||||
|
|
||||||
public enum WiimoteButton implements Button {
|
public enum WiimoteButton implements Button {
|
||||||
TWO (0x0001),
|
TWO (0x0001),
|
||||||
@@ -25,4 +26,13 @@ public enum WiimoteButton implements Button {
|
|||||||
public int getCode() {
|
public int getCode() {
|
||||||
return code;
|
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;
|
package pm.device.wiimote;
|
||||||
|
|
||||||
import pm.Action;
|
import pm.Action;
|
||||||
|
import pm.Button;
|
||||||
import pm.Device;
|
import pm.Device;
|
||||||
import pm.Target;
|
import pm.Target;
|
||||||
import pm.exception.MacroException;
|
import pm.Task;
|
||||||
import pm.exception.device.DeviceInitialiseException;
|
import pm.exception.device.DeviceInitialiseException;
|
||||||
|
import pm.exception.event.UnknownButtonException;
|
||||||
import pm.macro.event.Press;
|
import pm.macro.event.Press;
|
||||||
|
import pm.macro.event.Release;
|
||||||
import wiiusej.Wiimote;
|
import wiiusej.Wiimote;
|
||||||
|
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||||
|
|
||||||
public class WiimoteDevice extends Device {
|
public class WiimoteDevice extends Device {
|
||||||
protected static final int CONNECT_MAX = 10;
|
protected static final int CONNECT_MAX = 10;
|
||||||
|
|
||||||
protected static WiimoteService wiimoteService;
|
protected static WiimoteService wiimoteService;
|
||||||
|
protected static GestureService gestureService;
|
||||||
|
|
||||||
protected Wiimote wiimote;
|
protected Wiimote wiimote;
|
||||||
|
|
||||||
public WiimoteDevice() {
|
{
|
||||||
WiimoteDevice.wiimoteService = new WiimoteService();
|
WiimoteDevice.wiimoteService = new WiimoteService();
|
||||||
|
WiimoteDevice.gestureService = new GestureService();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialise() throws DeviceInitialiseException {
|
public void initialise() throws DeviceInitialiseException {
|
||||||
wiimote = wiimoteService.getDevice(this);
|
wiimote = wiimoteService.getDevice(this);
|
||||||
try {
|
wiimote.activateMotionSensing();
|
||||||
add(
|
add(
|
||||||
new Press(WiimoteButton.A),
|
new Press(WiimoteButton.A),
|
||||||
Action.TEST.setTarget(Target.APPLICATION));
|
new Task(Action.TEST, Target.APPLICATION));
|
||||||
} catch (MacroException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void exit() {
|
||||||
|
wiimoteService.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onButtonsEvent(WiimoteButtonsEvent event) {
|
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;
|
import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent;
|
||||||
|
|
||||||
public class WiimoteService extends WiiUseApiManager implements WiimoteListener {
|
public class WiimoteService extends WiiUseApiManager implements WiimoteListener {
|
||||||
|
protected final boolean RUMBLE = false;
|
||||||
|
|
||||||
protected ArrayList<Integer> wiimoteList;
|
protected ArrayList<Integer> wiimoteList;
|
||||||
protected Wiimote[] wiimoteArray;
|
protected Wiimote[] wiimoteArray;
|
||||||
protected HashMap<Integer, WiimoteDevice> wiimoteDeviceMap;
|
protected HashMap<Integer, WiimoteDevice> wiimoteDeviceMap;
|
||||||
@@ -32,8 +34,7 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
|
|||||||
wiimoteDeviceMap = new HashMap<Integer, WiimoteDevice>();
|
wiimoteDeviceMap = new HashMap<Integer, WiimoteDevice>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish() {
|
public void exit() {
|
||||||
// Todo: methode bedenken om deze methode aangeroepen te krijgen, zonder de service in de main te hoeven registreren.
|
|
||||||
if (wiimoteArray != null) {
|
if (wiimoteArray != null) {
|
||||||
for (Wiimote wiimote : wiimoteArray) {
|
for (Wiimote wiimote : wiimoteArray) {
|
||||||
wiimote.disconnect();
|
wiimote.disconnect();
|
||||||
@@ -43,7 +44,7 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Wiimote getDevice(WiimoteDevice wiimoteDevice) throws DeviceNotFoundException {
|
public Wiimote getDevice(WiimoteDevice wiimoteDevice) throws DeviceNotFoundException {
|
||||||
Wiimote[] wiimoteArray = getWiimotes(1, false);
|
Wiimote[] wiimoteArray = getWiimotes(1, RUMBLE);
|
||||||
for (Wiimote wiimote : wiimoteArray) {
|
for (Wiimote wiimote : wiimoteArray) {
|
||||||
int id = wiimote.getId();
|
int id = wiimote.getId();
|
||||||
if (!wiimoteList.contains(id)) {
|
if (!wiimoteList.contains(id)) {
|
||||||
@@ -65,7 +66,11 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onButtonsEvent(WiimoteButtonsEvent event) {
|
public void onButtonsEvent(WiimoteButtonsEvent event) {
|
||||||
|
getWiimoteDevice(event).onButtonsEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onMotionSensingEvent(MotionSensingEvent event) {
|
||||||
|
getWiimoteDevice(event).onMotionSensingEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStatusEvent(StatusEvent event) {
|
public void onStatusEvent(StatusEvent event) {
|
||||||
@@ -75,7 +80,6 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onIrEvent(IREvent e) {}
|
public void onIrEvent(IREvent e) {}
|
||||||
public void onMotionSensingEvent(MotionSensingEvent event) {}
|
|
||||||
public void onExpansionEvent(ExpansionEvent event) {}
|
public void onExpansionEvent(ExpansionEvent event) {}
|
||||||
public void onDisconnectionEvent(DisconnectionEvent event) {}
|
public void onDisconnectionEvent(DisconnectionEvent event) {}
|
||||||
public void onNunchukInsertedEvent(NunchukInsertedEvent event) {}
|
public void onNunchukInsertedEvent(NunchukInsertedEvent event) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user