Omzetten van javainput events naar buttons afgemaakt. Begonnen met ondersteuning voor macro's implementeren.
This commit is contained in:
@@ -10,8 +10,9 @@ import pm.application.voorbeeld.VoorbeeldApplication;
|
||||
import pm.device.Device;
|
||||
import pm.device.javainput.extreme3d.Extreme3DDevice;
|
||||
import pm.exception.ActionException;
|
||||
import pm.exception.NotImplementedActionException;
|
||||
import pm.exception.EventException;
|
||||
import pm.exception.action.NotImplementedActionException;
|
||||
import pm.exception.action.UnknownTargetException;
|
||||
|
||||
public class Main extends Target {
|
||||
protected static final int SLEEP = 100;
|
||||
@@ -64,7 +65,7 @@ public class Main extends Target {
|
||||
run();
|
||||
}
|
||||
|
||||
public void run() throws ActionException, EventException {
|
||||
public void run() throws ActionException {
|
||||
run = true;
|
||||
while (run) {
|
||||
//System.out.println("Print!");
|
||||
@@ -84,7 +85,7 @@ public class Main extends Target {
|
||||
target = currentApplication;
|
||||
break;
|
||||
default:
|
||||
throw new EventException("Unknown event type");
|
||||
throw new UnknownTargetException();
|
||||
}
|
||||
try {
|
||||
target.invoke(action);
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import pm.action.Action;
|
||||
import pm.exception.ActionException;
|
||||
import pm.exception.InvokeActionException;
|
||||
import pm.exception.action.InvokeActionException;
|
||||
|
||||
public abstract class Target {
|
||||
public void invoke(Action action) throws ActionException {
|
||||
|
||||
@@ -3,7 +3,7 @@ package pm.action;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import pm.event.Target;
|
||||
import pm.exception.NotImplementedActionException;
|
||||
import pm.exception.action.NotImplementedActionException;
|
||||
|
||||
public enum Action {
|
||||
START ("start"),
|
||||
|
||||
@@ -8,7 +8,9 @@ import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
import pm.device.Device;
|
||||
import pm.exception.DeviceException;
|
||||
import pm.exception.JavaInputDeviceNotFoundException;
|
||||
import pm.exception.EventException;
|
||||
import pm.exception.device.JavaInputDeviceNotFoundException;
|
||||
import pm.exception.event.UnknownDirectionException;
|
||||
|
||||
public abstract class JavaInputDevice extends Device {
|
||||
protected JavaInputListener javaInputListener;
|
||||
@@ -35,6 +37,6 @@ public abstract class JavaInputDevice extends Device {
|
||||
}
|
||||
|
||||
public void processEvent(JXInputAxisEvent event) {}
|
||||
public void processEvent(JXInputButtonEvent event) {}
|
||||
public void processEvent(JXInputDirectionalEvent event) {}
|
||||
public void processEvent(JXInputButtonEvent event) throws EventException {}
|
||||
public void processEvent(JXInputDirectionalEvent event) throws EventException {}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package pm.device.javainput;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import pm.exception.EventException;
|
||||
|
||||
import de.hardcode.jxinput.Axis;
|
||||
import de.hardcode.jxinput.Button;
|
||||
import de.hardcode.jxinput.Directional;
|
||||
@@ -70,7 +72,6 @@ public class JavaInputListener extends Thread implements JXInputAxisEventListene
|
||||
|
||||
public void run() {
|
||||
run = true;
|
||||
System.out.println("begonneuh");
|
||||
while (run) {
|
||||
JXInputManager.updateFeatures();
|
||||
boolean sleep = true;
|
||||
@@ -79,11 +80,15 @@ public class JavaInputListener extends Thread implements JXInputAxisEventListene
|
||||
sleep = false;
|
||||
}
|
||||
if (!buttonEventQueue.isEmpty()) {
|
||||
javaInputDevice.processEvent(buttonEventQueue.poll());
|
||||
try {
|
||||
javaInputDevice.processEvent(buttonEventQueue.poll());
|
||||
} catch (EventException e) {}
|
||||
sleep = false;
|
||||
}
|
||||
if (!directionalEventQueue.isEmpty()) {
|
||||
javaInputDevice.processEvent(directionalEventQueue.poll());
|
||||
try {
|
||||
javaInputDevice.processEvent(directionalEventQueue.poll());
|
||||
} catch (EventException e) {e.printStackTrace();}
|
||||
sleep = false;
|
||||
}
|
||||
if (sleep) {
|
||||
@@ -92,6 +97,5 @@ public class JavaInputListener extends Thread implements JXInputAxisEventListene
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
System.out.println("klaaaur");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package pm.device.javainput;
|
||||
|
||||
import pm.exception.ServiceJavaInputException;
|
||||
|
||||
public class RumblepadDevice extends JavaInputDevice {
|
||||
|
||||
protected static final String NAME = "Logitech RumblePad 2 USB";
|
||||
|
||||
public RumblepadDevice() throws ServiceJavaInputException {
|
||||
super(NAME);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
package pm.device.javainput.extreme3d;
|
||||
|
||||
public enum Extreme3DButton {
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import pm.device.macro.Button;
|
||||
import pm.exception.event.UnknownButtonException;
|
||||
|
||||
public enum Extreme3DButton implements Button {
|
||||
ONE ("Button 0"),
|
||||
TWO ("Button 1"),
|
||||
THREE ("Button 2"),
|
||||
@@ -14,34 +18,26 @@ public enum Extreme3DButton {
|
||||
ELEVEN ("Button 10"),
|
||||
TWELVE ("Button 11");
|
||||
|
||||
/*TWO (0x0001),
|
||||
ONE (0x0002),
|
||||
B (0x0004),
|
||||
A (0x0008),
|
||||
MINUS (0x0010),
|
||||
HOME (0x0080),
|
||||
LEFT (0x0100),
|
||||
RIGHT (0x0200),
|
||||
DOWN (0x0400),
|
||||
UP (0x0800),
|
||||
PLUS (0x1000),
|
||||
ALL (0x1F9F);*/
|
||||
|
||||
protected String code;
|
||||
|
||||
Extreme3DButton(String code) {
|
||||
private Extreme3DButton(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/*int getCode() {
|
||||
public String getCode() {
|
||||
return code;
|
||||
}*/
|
||||
}
|
||||
|
||||
static Extreme3DButton create(String name) throws Exception {
|
||||
try {
|
||||
return Extreme3DButton.valueOf(name);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new Exception("Moet ik nou heeel boos worden?? " + name);
|
||||
public static Extreme3DButton create(String code) throws UnknownButtonException {
|
||||
for (Extreme3DButton button : Extreme3DButton.values()) {
|
||||
if (button.getCode().equals(code)) {
|
||||
return button;
|
||||
}
|
||||
}
|
||||
throw new UnknownButtonException();
|
||||
}
|
||||
|
||||
public static Extreme3DButton create(JXInputButtonEvent event) throws UnknownButtonException {
|
||||
return create(event.getButton().getName());
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,10 @@ import de.hardcode.jxinput.event.JXInputAxisEvent;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
import pm.action.Action;
|
||||
import pm.device.javainput.JavaInputDevice;
|
||||
import pm.device.macro.Macro;
|
||||
import pm.event.Target;
|
||||
import pm.exception.DeviceException;
|
||||
import pm.exception.EventException;
|
||||
import pm.exception.event.UnknownDirectionException;
|
||||
|
||||
public class Extreme3DDevice extends JavaInputDevice {
|
||||
|
||||
@@ -36,25 +35,28 @@ public class Extreme3DDevice extends JavaInputDevice {
|
||||
//System.out.println(event);
|
||||
}
|
||||
|
||||
public void processEvent(JXInputButtonEvent event) {
|
||||
public void processEvent(JXInputButtonEvent event) throws EventException {
|
||||
//addAction(Action.TEST, Target.APPLICATION);
|
||||
Button button = event.getButton();
|
||||
Extreme3DButton x = null;
|
||||
try {
|
||||
x = Extreme3DButton.create(button.getName());
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
if (event.getButton().getState()) {
|
||||
// press
|
||||
} else {
|
||||
// release
|
||||
}
|
||||
System.out.println(x);
|
||||
//System.out.println(button.getType() + " " + button.getName() +" " + event.getButton().getState());
|
||||
System.out.println(Extreme3DButton.create(event));
|
||||
//System.out.println(button.getType() + " " + button.getName() +" " + );
|
||||
}
|
||||
|
||||
public void processEvent(JXInputDirectionalEvent event) {
|
||||
public void processEvent(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
||||
//addAction(Action.EXIT, Target.APPLICATION);
|
||||
Directional directional = event.getDirectional();
|
||||
|
||||
System.out.println(directional.getValue() + " [" + directional.getName() + "] " + directional.getResolution() + " " + directional.getDirection());
|
||||
//Directional directional = event.getDirectional();
|
||||
if (event.getDirectional().isCentered()) {
|
||||
// release
|
||||
} else {
|
||||
// press
|
||||
}
|
||||
System.out.println(Extreme3DDirection.create(event));
|
||||
//System.out.println(Extreme3DButton.create(event));
|
||||
//System.out.println(directional.isCentered() + " " + directional.getValue() + " [" + directional.getName() + "] " + directional.getResolution() + " " + directional.getDirection());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package pm.device.javainput.extreme3d;
|
||||
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
import pm.device.macro.Button;
|
||||
import pm.exception.event.UnknownDirectionException;
|
||||
|
||||
public enum Extreme3DDirection implements Button {
|
||||
NORTH (0),
|
||||
NORTHEAST (45),
|
||||
EAST (90),
|
||||
SOUTHEAST (135),
|
||||
SOUTH (180),
|
||||
SOUTHWEST (225),
|
||||
WEST (270),
|
||||
NORTHWEST (315);
|
||||
|
||||
protected int code;
|
||||
|
||||
private Extreme3DDirection(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static Extreme3DDirection create(int angle) throws UnknownDirectionException {
|
||||
for (Extreme3DDirection button : Extreme3DDirection.values()) {
|
||||
if (button.getCode() == angle) {
|
||||
return button;
|
||||
}
|
||||
}
|
||||
throw new UnknownDirectionException();
|
||||
}
|
||||
|
||||
public static Extreme3DDirection create(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
||||
return create(event.getDirectional().getDirection() / 100);
|
||||
}
|
||||
}
|
||||
13
java/src/pm/device/javainput/rumblepad/RumblepadDevice.java
Normal file
13
java/src/pm/device/javainput/rumblepad/RumblepadDevice.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package pm.device.javainput.rumblepad;
|
||||
|
||||
import pm.device.javainput.JavaInputDevice;
|
||||
import pm.exception.DeviceException;
|
||||
|
||||
public class RumblepadDevice extends JavaInputDevice {
|
||||
|
||||
protected static final String NAME = "Logitech RumblePad 2 USB";
|
||||
|
||||
public RumblepadDevice() throws DeviceException {
|
||||
super(NAME);
|
||||
}
|
||||
}
|
||||
5
java/src/pm/device/macro/Action.java
Normal file
5
java/src/pm/device/macro/Action.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package pm.device.macro;
|
||||
|
||||
public interface Action {
|
||||
public Button button = null;
|
||||
}
|
||||
57
java/src/pm/device/macro/Actions.java
Normal file
57
java/src/pm/device/macro/Actions.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package pm.device.macro;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiitunes.interaction.macro.Action;
|
||||
import wiitunes.interaction.macro.Button;
|
||||
import wiitunes.interaction.macro.Buttons;
|
||||
import wiitunes.interaction.macro.Combination;
|
||||
import wiitunes.interaction.macro.action.Hold;
|
||||
import wiitunes.interaction.macro.action.Press;
|
||||
import wiitunes.interaction.macro.action.Release;
|
||||
|
||||
public class Actions {
|
||||
protected Combination[] combinationArray;
|
||||
|
||||
public Actions(Action... actionArray) {
|
||||
ArrayList<Combination> combinationList = new ArrayList<Combination>();
|
||||
Buttons heldButtons = new Buttons();
|
||||
for (Action action : actionArray) {
|
||||
if (action instanceof Press) {
|
||||
Button button = ((Press) action).button;
|
||||
Buttons buttons = new Buttons(button);
|
||||
combinationList.add(new Combination(buttons, null, heldButtons));
|
||||
combinationList.add(new Combination(null, buttons, heldButtons));
|
||||
} else if (action instanceof Release) {
|
||||
Button button = ((Release) action).button;
|
||||
Buttons buttons = new Buttons(button);
|
||||
heldButtons = heldButtons.clone();
|
||||
heldButtons.remove(button);
|
||||
combinationList.add(new Combination(null, buttons, heldButtons));
|
||||
} else if (action instanceof Hold) {
|
||||
Button button = ((Hold) action).button;
|
||||
Buttons buttons = new Buttons(button);
|
||||
combinationList.add(new Combination(buttons, null, heldButtons));
|
||||
heldButtons = heldButtons.clone();
|
||||
heldButtons.add(button);
|
||||
}
|
||||
}
|
||||
combinationArray = (Combination[]) combinationList.toArray(new Combination[0]);
|
||||
}
|
||||
|
||||
public Combination get(int step) {
|
||||
return combinationArray[step];
|
||||
}
|
||||
|
||||
public int count() {
|
||||
return combinationArray.length;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String string = String.format("Gesture contains %d actions:\n", combinationArray.length);;
|
||||
for (Combination combination : combinationArray) {
|
||||
string += String.format("> %s\n", combination);
|
||||
}
|
||||
return string;
|
||||
}
|
||||
}
|
||||
5
java/src/pm/device/macro/Button.java
Normal file
5
java/src/pm/device/macro/Button.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package pm.device.macro;
|
||||
|
||||
public interface Button {
|
||||
|
||||
}
|
||||
12
java/src/pm/device/macro/action/Hold.java
Normal file
12
java/src/pm/device/macro/action/Hold.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package pm.device.macro.action;
|
||||
|
||||
import pm.device.macro.Action;
|
||||
import pm.device.macro.Button;
|
||||
|
||||
public class Hold implements Action {
|
||||
public Button button;
|
||||
|
||||
public Hold(Button button) {
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
12
java/src/pm/device/macro/action/Press.java
Normal file
12
java/src/pm/device/macro/action/Press.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package pm.device.macro.action;
|
||||
|
||||
import pm.device.macro.Action;
|
||||
import pm.device.macro.Button;
|
||||
|
||||
public class Press implements Action {
|
||||
public Button button;
|
||||
|
||||
public Press(Button button) {
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
12
java/src/pm/device/macro/action/Release.java
Normal file
12
java/src/pm/device/macro/action/Release.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package pm.device.macro.action;
|
||||
|
||||
import pm.device.macro.Action;
|
||||
import pm.device.macro.Button;
|
||||
|
||||
public class Release implements Action {
|
||||
public Button button;
|
||||
|
||||
public Release(Button button) {
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
26
java/src/pm/device/wiimote/WiimoteButton.java
Normal file
26
java/src/pm/device/wiimote/WiimoteButton.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package pm.device.wiimote;
|
||||
|
||||
public enum WiimoteButton {
|
||||
TWO (0x0001),
|
||||
ONE (0x0002),
|
||||
B (0x0004),
|
||||
A (0x0008),
|
||||
MINUS (0x0010),
|
||||
HOME (0x0080),
|
||||
LEFT (0x0100),
|
||||
RIGHT (0x0200),
|
||||
DOWN (0x0400),
|
||||
UP (0x0800),
|
||||
PLUS (0x1000),
|
||||
ALL (0x1F9F);
|
||||
|
||||
protected int code;
|
||||
|
||||
private WiimoteButton(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
package pm.exception;
|
||||
|
||||
public class EventException extends Exception {
|
||||
public EventException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
package pm.exception;
|
||||
package pm.exception.action;
|
||||
|
||||
import pm.exception.ActionException;
|
||||
|
||||
public class InvokeActionException extends ActionException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
@@ -1,4 +1,6 @@
|
||||
package pm.exception;
|
||||
package pm.exception.action;
|
||||
|
||||
import pm.exception.ActionException;
|
||||
|
||||
public class NotImplementedActionException extends ActionException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
7
java/src/pm/exception/action/UnknownTargetException.java
Normal file
7
java/src/pm/exception/action/UnknownTargetException.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package pm.exception.action;
|
||||
|
||||
import pm.exception.ActionException;
|
||||
|
||||
public class UnknownTargetException extends ActionException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
package pm.exception;
|
||||
package pm.exception.device;
|
||||
|
||||
import pm.exception.DeviceException;
|
||||
|
||||
public class JavaInputDeviceNotFoundException extends DeviceException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
7
java/src/pm/exception/event/UnknownButtonException.java
Normal file
7
java/src/pm/exception/event/UnknownButtonException.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package pm.exception.event;
|
||||
|
||||
import pm.exception.EventException;
|
||||
|
||||
public class UnknownButtonException extends EventException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package pm.exception.event;
|
||||
|
||||
import pm.exception.EventException;
|
||||
|
||||
public class UnknownDirectionException extends EventException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package pm.service.javainput;
|
||||
import de.hardcode.jxinput.JXInputDevice;
|
||||
import de.hardcode.jxinput.JXInputManager;
|
||||
|
||||
import pm.exception.JavaInputDeviceNotFoundException;
|
||||
import pm.exception.ServiceJavaInputException;
|
||||
import pm.exception.device.JavaInputDeviceNotFoundException;
|
||||
import pm.service.Service;
|
||||
|
||||
public class JavaInputService extends Service {
|
||||
|
||||
Reference in New Issue
Block a user