diff --git a/java/src/pm/Main.java b/java/src/pm/Main.java index 550f14a..5fe0c24 100644 --- a/java/src/pm/Main.java +++ b/java/src/pm/Main.java @@ -9,6 +9,7 @@ import pm.application.voorbeeld.VoorbeeldApplication; import pm.device.Device; import pm.device.javainput.extreme3d.Extreme3DDevice; import pm.device.jintellitype.JIntellitypeDevice; +import pm.device.wiimote.WiimoteDevice; import pm.exception.ActionException; import pm.exception.action.NotImplementedActionException; import pm.exception.action.UnknownTargetException; @@ -52,6 +53,7 @@ public class Main { //add(new RumblepadDevice()); add(new Extreme3DDevice()); add(new JIntellitypeDevice()); + add(new WiimoteDevice()); Application application = new VoorbeeldApplication(); add(application); diff --git a/java/src/pm/device/javainput/JavaInputDevice.java b/java/src/pm/device/javainput/JavaInputDevice.java index 778f6ff..9d65079 100644 --- a/java/src/pm/device/javainput/JavaInputDevice.java +++ b/java/src/pm/device/javainput/JavaInputDevice.java @@ -19,7 +19,6 @@ import pm.macro.event.Release; public abstract class JavaInputDevice extends Device { protected JavaInputListener javaInputListener; - //protected JXInputDevice jxinputDevice; protected Button previousDirectionalButton; protected JavaInputDevice(String name) throws DeviceException { @@ -47,12 +46,10 @@ public abstract class JavaInputDevice extends Device { } public void processEvent(JXInputAxisEvent event) { - //addAction(Action.START, Target.APPLICATION); //System.out.println(event); } public void processEvent(JXInputButtonEvent event) throws EventException { - //addAction(Action.TEST, Target.APPLICATION); Button button = Extreme3DButton.create(event); if (event.getButton().getState()) { System.out.println("Press: " + button); @@ -61,13 +58,9 @@ public abstract class JavaInputDevice extends Device { System.out.println("Release: " + button); add(new Release(button)); } - //System.out.println(button); - //System.out.println(button.getType() + " " + button.getName() +" " + ); } public void processEvent(JXInputDirectionalEvent event) throws UnknownDirectionException { - //addAction(Action.EXIT, Target.APPLICATION); - //Directional directional = event.getDirectional(); Button button = Extreme3DDirection.create(event); if (event.getDirectional().isCentered()) { if (previousDirectionalButton != null) { @@ -79,8 +72,5 @@ public abstract class JavaInputDevice extends Device { add(new Press(button)); previousDirectionalButton = button; } - //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()); } } diff --git a/java/src/pm/device/javainput/JavaInputListener.java b/java/src/pm/device/javainput/JavaInputListener.java index e260e0d..f02c22c 100644 --- a/java/src/pm/device/javainput/JavaInputListener.java +++ b/java/src/pm/device/javainput/JavaInputListener.java @@ -19,7 +19,7 @@ import de.hardcode.jxinput.event.JXInputDirectionalEventListener; import de.hardcode.jxinput.event.JXInputEventManager; public class JavaInputListener extends Thread implements JXInputAxisEventListener, JXInputButtonEventListener, JXInputDirectionalEventListener { - protected static int SLEEP = 100; + protected static final int SLEEP = 100; protected boolean run; protected JavaInputDevice javaInputDevice; diff --git a/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java b/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java index 411bc5a..e126b3f 100644 --- a/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java +++ b/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java @@ -20,7 +20,9 @@ public class Extreme3DDevice extends JavaInputDevice { public void start() { super.start(); try { - add(new Macro(new Press(Extreme3DButton.TWELVE)), Action.TEST.setTarget(Target.APPLICATION)); + add( + new Press(Extreme3DButton.TWELVE), + Action.TEST.setTarget(Target.APPLICATION)); add( new Macro( new Hold(Extreme3DButton.ONE), diff --git a/java/src/pm/device/jintellitype/CommandButton.java b/java/src/pm/device/jintellitype/CommandButton.java index 875f764..61f13c2 100644 --- a/java/src/pm/device/jintellitype/CommandButton.java +++ b/java/src/pm/device/jintellitype/CommandButton.java @@ -51,7 +51,7 @@ public enum CommandButton implements Button { DICTATE_OR_COMMAND_CONTROL_TOGGLE (JIntellitype.APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE), MIC_ON_OFF_TOGGLE (JIntellitype.APPCOMMAND_MIC_ON_OFF_TOGGLE), CORRECTION_LIST (JIntellitype.APPCOMMAND_CORRECTION_LIST); - + protected int code; private CommandButton(int code) { diff --git a/java/src/pm/device/jintellitype/Hotkey.java b/java/src/pm/device/jintellitype/Hotkey.java index ed1c340..a5635e3 100644 --- a/java/src/pm/device/jintellitype/Hotkey.java +++ b/java/src/pm/device/jintellitype/Hotkey.java @@ -11,19 +11,19 @@ public class Hotkey extends Press { protected static JIntellitype jit; public Hotkey(int modifier, int keycode) { - super(null); + super(null); // Todo: nettere oplossing zoeken / controleren op null int id = hotkeyList.size(); button = new HotkeyButton(id); jit.registerHotKey(id, modifier, keycode); hotkeyList.add(this); } - public Hotkey(int modifier, char keycode) { - this(modifier, (int) keycode); + public Hotkey(int modifier, char key) { + this(modifier, (int) Character.toUpperCase(key)); } - public Hotkey(char keycode) { - this(0, (int) keycode); + public Hotkey(char key) { + this(0, (int) Character.toUpperCase(key)); } public Hotkey(int keycode) { diff --git a/java/src/pm/device/jintellitype/HotkeyButton.java b/java/src/pm/device/jintellitype/HotkeyButton.java index 0fd4fda..ca91592 100644 --- a/java/src/pm/device/jintellitype/HotkeyButton.java +++ b/java/src/pm/device/jintellitype/HotkeyButton.java @@ -6,14 +6,14 @@ import pm.Button; public class HotkeyButton implements Button { public static final int - MOD_ALT = JIntellitype.MOD_ALT, - MOD_CTRL = JIntellitype.MOD_CONTROL, - MOD_SHIFT = JIntellitype.MOD_SHIFT, - MOD_WIN = JIntellitype.MOD_WIN; + ALT = JIntellitype.MOD_ALT, + CTRL = JIntellitype.MOD_CONTROL, + SHIFT = JIntellitype.MOD_SHIFT, + WIN = JIntellitype.MOD_WIN; protected int code; - public HotkeyButton(int code) { + protected HotkeyButton(int code) { this.code = code; } diff --git a/java/src/pm/device/jintellitype/JIntellitypeDevice.java b/java/src/pm/device/jintellitype/JIntellitypeDevice.java index a5b3f43..777b5e6 100644 --- a/java/src/pm/device/jintellitype/JIntellitypeDevice.java +++ b/java/src/pm/device/jintellitype/JIntellitypeDevice.java @@ -7,6 +7,7 @@ import com.melloware.jintellitype.IntellitypeListener; import com.melloware.jintellitype.JIntellitype; import pm.Action; +import pm.Macro; import pm.Target; import pm.device.Device; import pm.exception.EventException; @@ -30,7 +31,10 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell jit.addIntellitypeListener(this); try { add( - new Hotkey(HotkeyButton.MOD_CTRL | HotkeyButton.MOD_WIN, 'I'), + new Macro( + new Hotkey('r'), + new Hotkey('i'), + new Hotkey('k')), Action.EXIT.setTarget(Target.MAIN)); add( new Press(CommandButton.VOLUME_UP), @@ -48,8 +52,7 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell add(new Press(commandButton)); add(new Release(commandButton)); } catch (EventException e) { - // Todo: deze exception verder omhoog gooien - e.printStackTrace(); + e.printStackTrace(); // Todo: deze exception verder omhoog gooien } } diff --git a/java/src/pm/device/wiimote/WiimoteButton.java b/java/src/pm/device/wiimote/WiimoteButton.java index 4e69844..88e95a4 100644 --- a/java/src/pm/device/wiimote/WiimoteButton.java +++ b/java/src/pm/device/wiimote/WiimoteButton.java @@ -1,6 +1,8 @@ package pm.device.wiimote; -public enum WiimoteButton { +import pm.Button; + +public enum WiimoteButton implements Button { TWO (0x0001), ONE (0x0002), B (0x0004), @@ -13,7 +15,7 @@ public enum WiimoteButton { UP (0x0800), PLUS (0x1000), ALL (0x1F9F); - + protected int code; private WiimoteButton(int code) { diff --git a/java/src/pm/device/wiimote/WiimoteDevice.java b/java/src/pm/device/wiimote/WiimoteDevice.java new file mode 100644 index 0000000..e4b43fc --- /dev/null +++ b/java/src/pm/device/wiimote/WiimoteDevice.java @@ -0,0 +1,36 @@ +package pm.device.wiimote; + +import pm.Action; +import pm.Target; +import pm.device.Device; +import pm.exception.DeviceException; +import pm.exception.MacroException; +import pm.macro.event.Press; +import wiiusej.Wiimote; + +public class WiimoteDevice extends Device { + protected static final int CONNECT_MAX = 10; + + protected static WiimoteService wiimoteService; + + protected Wiimote wiimote; + + { + WiimoteDevice.wiimoteService = new WiimoteService(); + } + + public WiimoteDevice() throws DeviceException { + wiimote = wiimoteService.getDevice(this); + } + + public void start() { + super.start(); + try { + add( + new Press(WiimoteButton.A), + Action.TEST.setTarget(Target.APPLICATION)); + } catch (MacroException e) { + e.printStackTrace(); + } + } +} diff --git a/java/src/pm/device/wiimote/WiimoteService.java b/java/src/pm/device/wiimote/WiimoteService.java new file mode 100644 index 0000000..0aa1ab2 --- /dev/null +++ b/java/src/pm/device/wiimote/WiimoteService.java @@ -0,0 +1,67 @@ +package pm.device.wiimote; + +import java.util.ArrayList; +import java.util.HashMap; + +import pm.exception.DeviceException; +import pm.exception.device.JavaInputDeviceNotFoundException; +import wiiusej.WiiUseApiManager; +import wiiusej.Wiimote; +import wiiusej.wiiusejevents.physicalevents.ExpansionEvent; +import wiiusej.wiiusejevents.physicalevents.IREvent; +import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; +import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; +import wiiusej.wiiusejevents.utils.WiimoteListener; +import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent; +import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.GuitarHeroRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.NunchukInsertedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.NunchukRemovedEvent; +import wiiusej.wiiusejevents.wiiuseapievents.StatusEvent; + +public class WiimoteService extends WiiUseApiManager implements WiimoteListener { + protected ArrayList wiimoteList; + protected HashMap wiimoteMap; + + WiimoteService() { + wiimoteList = new ArrayList(); + wiimoteMap = new HashMap(); + } + + public Wiimote getDevice(WiimoteDevice wiimoteDevice) throws DeviceException { + Wiimote[] wiimoteArray = getWiimotes(1, false); + for (Wiimote wiimote : wiimoteArray) { + int id = wiimote.getId(); + if (!wiimoteList.contains(id)) { + wiimote.addWiiMoteEventListeners(this); + wiimoteList.add(id); + wiimoteMap.put(wiimote, wiimoteDevice); + return wiimote; + } + } + throw new JavaInputDeviceNotFoundException(); + } + + public void onButtonsEvent(WiimoteButtonsEvent event) { + //evm.macroEvent(event, getWiimote(event)); + } + + public void onStatusEvent(StatusEvent event) { + /*if (event.isConnected()) { + evm.event(WiimoteEvent.CONNECT, getWiimote(event)); + }*/ + } + + 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) {} + public void onNunchukRemovedEvent(NunchukRemovedEvent event) {} + public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent event) {} + public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent event) {} + public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent event) {} + public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent event) {} +} diff --git a/java/src/pm/macro/Event.java b/java/src/pm/macro/Event.java index 7bdec66..c27745b 100644 --- a/java/src/pm/macro/Event.java +++ b/java/src/pm/macro/Event.java @@ -4,7 +4,7 @@ import pm.Button; public abstract class Event { protected Button button; - + public Event(Button button) { this.button = button; } diff --git a/java/src/pm/util/ArrayCycle.java b/java/src/pm/util/ArrayCycle.java index f562ebd..cde2d16 100644 --- a/java/src/pm/util/ArrayCycle.java +++ b/java/src/pm/util/ArrayCycle.java @@ -2,30 +2,30 @@ package pm.util; import java.util.ArrayList; -public class ArrayCycle extends ArrayList { +public class ArrayCycle extends ArrayList { protected static final long serialVersionUID = 1L; protected int index = 0; - public T current() { + public E current() { return this.get(index); } - public T previous() { + public E previous() { if (--index < 0) { index = Math.max(0, size() - 1); } return get(index); } - public T next() { + public E next() { if (++index >= size()) { index = 0; } return get(index); } - public T reset() { + public E reset() { return get(index = 0); } }