This commit is contained in:
@@ -6,6 +6,8 @@ import pm.event.task.Continuous;
|
||||
import pm.event.task.Stopper;
|
||||
import pm.exception.device.DeviceExitException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.interrupt.InterruptListener;
|
||||
import pm.interrupt.Interruptible;
|
||||
import pm.macro.Sequence;
|
||||
import pm.macro.SequenceListener;
|
||||
import pm.macro.State;
|
||||
@@ -15,10 +17,12 @@ import pm.macro.state.Release;
|
||||
|
||||
public abstract class Device extends EventListener {
|
||||
protected SequenceListener sequenceListener;
|
||||
protected InterruptListener interruptListener;
|
||||
|
||||
public Device() {
|
||||
super();
|
||||
sequenceListener = new SequenceListener(this);
|
||||
interruptListener = new InterruptListener(this);
|
||||
}
|
||||
|
||||
/* Register macro's */
|
||||
@@ -67,6 +71,11 @@ public abstract class Device extends EventListener {
|
||||
Button button = hold.getButton();
|
||||
add(new Press(button), new Release(button), continuous);
|
||||
}
|
||||
|
||||
/* Register interruptibles */
|
||||
protected void add(Interruptible interruptible) {
|
||||
interruptListener.add(interruptible);
|
||||
}
|
||||
|
||||
/* Recognize events */
|
||||
protected void add(State state) {
|
||||
|
||||
@@ -8,10 +8,13 @@ import org.apache.commons.logging.LogFactory;
|
||||
import pm.application.ApplicationCycle;
|
||||
import pm.application.example.ExampleApplication;
|
||||
import pm.application.itunes.iTunesApplication;
|
||||
import pm.application.mpc.MPCApplication;
|
||||
import pm.application.vlc.VLCApplication;
|
||||
import pm.application.winamp.WinampApplication;
|
||||
import pm.application.windows.gomplayer.GomPlayerApplication;
|
||||
import pm.application.windows.wmp.WMPApplication;
|
||||
import pm.device.gui.GUIDevice;
|
||||
import pm.device.javainput.extreme3d.Extreme3DDevice;
|
||||
import pm.device.javainput.rumblepad.RumblepadDevice;
|
||||
import pm.device.jintellitype.JIntellitypeDevice;
|
||||
import pm.device.player.PlayerDevice;
|
||||
@@ -48,20 +51,23 @@ public class Main extends EventListener {
|
||||
}
|
||||
|
||||
public void initialise() throws DeviceInitialiseException {
|
||||
add(new JIntellitypeDevice());
|
||||
//add(new JIntellitypeDevice());
|
||||
//add(new PlayerDevice());
|
||||
//add(new RumblepadDevice());
|
||||
add(new WiimoteDevice());
|
||||
//add(new WiimoteDevice());
|
||||
//add(new GUIDevice());
|
||||
//add(new TextDevice());
|
||||
//add(new LanTextDevice());
|
||||
add(new Extreme3DDevice());
|
||||
startDevices();
|
||||
|
||||
//add(new ExampleApplication());
|
||||
//add(new WMPApplication());
|
||||
add(new WMPApplication());
|
||||
//add(new GomPlayerApplication());
|
||||
//add(new WinampApplication());
|
||||
add(new iTunesApplication());
|
||||
//add(new iTunesApplication());
|
||||
//add(new VLCApplication());
|
||||
//add(new MPCApplication());
|
||||
startApplications();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,12 @@ abstract public class WindowsApplication extends Application {
|
||||
if (handle < 1) {
|
||||
String key = String.format("%s\\%s", REGISTRY, program);
|
||||
String path = Native.getValue(key);
|
||||
System.out.println("PATH=" + path);
|
||||
try {
|
||||
String command = String.format("\"%s\"", path);
|
||||
String command = path.startsWith("\"") ? path : String.format("\"%s\"", path);
|
||||
System.out.println("COMMAND=" + command);
|
||||
command = Native.replaceVariables(command);
|
||||
System.out.println("COMMAND=" + command);
|
||||
process = Runtime.getRuntime().exec(command);
|
||||
sleep(START_SLEEP);
|
||||
handle = Windows.findWindow(name, null);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class WMPApplication extends WindowsApplication {
|
||||
command(18813);
|
||||
break;
|
||||
case REWIND:
|
||||
command(18814);
|
||||
command(18812);
|
||||
break;
|
||||
case MUTE:
|
||||
command(18817);
|
||||
|
||||
@@ -9,6 +9,7 @@ import pm.exception.MacroException;
|
||||
import pm.exception.button.UnknownButtonException;
|
||||
import pm.exception.button.UnknownDirectionException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.interrupt.Interruptible;
|
||||
import pm.macro.state.Hold;
|
||||
import pm.macro.state.Press;
|
||||
import pm.macro.state.Release;
|
||||
@@ -33,6 +34,12 @@ public class Extreme3DDevice extends JavaInputDevice {
|
||||
new Press(Extreme3DButton.ELEVEN),
|
||||
new Release(Extreme3DButton.ONE)),
|
||||
new Task(Action.EXIT, Target.MAIN));
|
||||
add(
|
||||
new Interruptible(
|
||||
new Press(Extreme3DButton.NINE),
|
||||
new Task(Action.FORWARD),
|
||||
new Press(Extreme3DButton.TEN),
|
||||
new Task(Action.PLAY)));
|
||||
} catch (MacroException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
34
java/src/pm/interrupt/InterruptListener.java
Normal file
34
java/src/pm/interrupt/InterruptListener.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package pm.interrupt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import pm.event.EventListener;
|
||||
import pm.event.EventManager;
|
||||
import pm.macro.State;
|
||||
|
||||
public class InterruptListener {
|
||||
protected EventListener eventListener;
|
||||
protected ArrayList<Interruptible> interruptibleList;
|
||||
|
||||
public InterruptListener(EventListener eventListener) {
|
||||
this.eventListener = eventListener;
|
||||
interruptibleList = new ArrayList<Interruptible>();
|
||||
}
|
||||
|
||||
public void add(Interruptible interruptible) {
|
||||
interruptibleList.add(interruptible);
|
||||
}
|
||||
|
||||
public void add(State state) {
|
||||
for (Interruptible interruptible : interruptibleList) {
|
||||
if(interruptible.triggerPress.equals(state)) {
|
||||
EventManager.add(interruptible.triggerTask);
|
||||
interruptible.triggered = true;
|
||||
} else if(interruptible.interruptPress.equals(state) && interruptible.triggered) {
|
||||
EventManager.add(interruptible.interruptTask);
|
||||
interruptible.interrupted = true;
|
||||
interruptibleList.remove(interruptible);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
java/src/pm/interrupt/Interruptible.java
Normal file
26
java/src/pm/interrupt/Interruptible.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package pm.interrupt;
|
||||
|
||||
import pm.event.Task;
|
||||
import pm.macro.state.Press;
|
||||
|
||||
public class Interruptible extends Task {
|
||||
protected static final int SLEEP = 0;
|
||||
|
||||
protected boolean triggered;
|
||||
protected boolean interrupted;
|
||||
protected Press triggerPress;
|
||||
protected Task triggerTask;
|
||||
protected Press interruptPress;
|
||||
protected Task interruptTask;
|
||||
|
||||
|
||||
public Interruptible(Press triggerPress, Task triggerTask, Press interruptPress, Task interruptTask) {
|
||||
super(null, null);
|
||||
triggered = false;
|
||||
interrupted = false;
|
||||
this.triggerPress = triggerPress;
|
||||
this.triggerTask = triggerTask;
|
||||
this.interruptPress = interruptPress;
|
||||
this.interruptTask = interruptTask;
|
||||
}
|
||||
}
|
||||
@@ -15,5 +15,6 @@ public enum Action {
|
||||
TEST,
|
||||
VOLUME_DOWN,
|
||||
VOLUME_UP,
|
||||
FULLSCREEN,
|
||||
TRAIN, STOP, SAVE, RECOGNIZE, LOAD, SHUFFLE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user