Begonnen met implementatie wiimote. Nu even de wiiuse dll op de goede plaats zetten.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
36
java/src/pm/device/wiimote/WiimoteDevice.java
Normal file
36
java/src/pm/device/wiimote/WiimoteDevice.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
67
java/src/pm/device/wiimote/WiimoteService.java
Normal file
67
java/src/pm/device/wiimote/WiimoteService.java
Normal file
@@ -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<Integer> wiimoteList;
|
||||
protected HashMap<Wiimote, WiimoteDevice> wiimoteMap;
|
||||
|
||||
WiimoteService() {
|
||||
wiimoteList = new ArrayList<Integer>();
|
||||
wiimoteMap = new HashMap<Wiimote, WiimoteDevice>();
|
||||
}
|
||||
|
||||
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) {}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import pm.Button;
|
||||
|
||||
public abstract class Event {
|
||||
protected Button button;
|
||||
|
||||
|
||||
public Event(Button button) {
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
@@ -2,30 +2,30 @@ package pm.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ArrayCycle<T> extends ArrayList<T> {
|
||||
public class ArrayCycle<E> extends ArrayList<E> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user