Kleine aanpassingen. Lirc kan nu gestart worden via de GUI.
This commit is contained in:
@@ -16,39 +16,47 @@ public abstract class CMDApplication extends Component {
|
||||
protected String program;
|
||||
protected String title;
|
||||
protected Process process;
|
||||
protected boolean detect, running;
|
||||
|
||||
public CMDApplication(String program, String title) {
|
||||
super(title);
|
||||
this.program = program;
|
||||
this.title = title;
|
||||
detect = true;
|
||||
}
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
detect = true;
|
||||
if (!running) {
|
||||
String path = getPath();
|
||||
if (path == null) {
|
||||
throw new ActivateException();
|
||||
}
|
||||
try {
|
||||
String command = path.startsWith("\"") ? path : String.format("\"%s\"", path);
|
||||
command = replaceVariables(command);
|
||||
process = Runtime.getRuntime().exec(command);
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
throw new ActivateException();
|
||||
}
|
||||
}
|
||||
super.activate();
|
||||
String path = getPath();
|
||||
if (path == null) {
|
||||
throw new ActivateException();
|
||||
}
|
||||
try {
|
||||
String command = path.startsWith("\"") ? path : String.format("\"%s\"", path);
|
||||
command = replaceVariables(command);
|
||||
process = Runtime.getRuntime().exec(command);
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
throw new ActivateException();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
boolean running = Native.isRunning(program);
|
||||
if (!active && running) {
|
||||
active = true;
|
||||
start();
|
||||
if (detect) {
|
||||
running = Native.isRunning(program);
|
||||
if (!active && running) {
|
||||
active = true;
|
||||
start();
|
||||
}
|
||||
}
|
||||
return active = running;
|
||||
return active;
|
||||
}
|
||||
|
||||
protected synchronized void deactivate() throws DeactivateException {
|
||||
protected synchronized void deactivate() throws DeactivateException {
|
||||
detect = false;
|
||||
super.deactivate();
|
||||
if (process != null) {
|
||||
process.destroy();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mimis.application.itunes;
|
||||
|
||||
import mimis.application.Application;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.value.Action;
|
||||
@@ -11,7 +12,7 @@ import com.dt.iTunesController.ITTrack;
|
||||
import com.dt.iTunesController.iTunes;
|
||||
import com.dt.iTunesController.iTunesEventsInterface;
|
||||
|
||||
public class iTunesApplication extends Component implements iTunesEventsInterface {
|
||||
public class iTunesApplication extends Component implements Application, iTunesEventsInterface {
|
||||
protected static final String TITLE = "iTunes";
|
||||
protected static final boolean EVENTS = false;
|
||||
|
||||
@@ -22,7 +23,7 @@ public class iTunesApplication extends Component implements iTunesEventsInterfac
|
||||
|
||||
protected iTunes iTunes;
|
||||
protected VolumeWorker volumeWorker;
|
||||
protected boolean events, handle;
|
||||
protected boolean events;
|
||||
|
||||
public iTunesApplication() {
|
||||
this(EVENTS);
|
||||
@@ -32,7 +33,6 @@ public class iTunesApplication extends Component implements iTunesEventsInterfac
|
||||
super(TITLE);
|
||||
this.events = events;
|
||||
volumeWorker = new VolumeWorker();
|
||||
handle = false;
|
||||
}
|
||||
|
||||
protected synchronized void activate() throws ActivateException {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mimis.device.javainput;
|
||||
|
||||
import mimis.Button;
|
||||
import mimis.device.Device;
|
||||
import mimis.exception.ButtonException;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.button.UnknownDirectionException;
|
||||
@@ -16,7 +17,7 @@ import de.hardcode.jxinput.event.JXInputAxisEvent;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public abstract class JavaInputDevice extends Component {
|
||||
public abstract class JavaInputDevice extends Component implements Device {
|
||||
protected String name;
|
||||
|
||||
public JavaInputDevice(String title, String name) {
|
||||
@@ -50,9 +51,9 @@ public abstract class JavaInputDevice extends Component {
|
||||
public void processEvent(JXInputButtonEvent event) throws ButtonException {
|
||||
Button button = getButton(event);
|
||||
if (event.getButton().getState()) {
|
||||
add(new Press(button));
|
||||
route(new Press(button));
|
||||
} else {
|
||||
add(new Release(button));
|
||||
route(new Release(button));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,10 +61,10 @@ public abstract class JavaInputDevice extends Component {
|
||||
Button button = getButton(event);
|
||||
if (event.getDirectional().isCentered()) {
|
||||
if (previousDirectionalButton != null) {
|
||||
add(new Release(previousDirectionalButton));
|
||||
route(new Release(previousDirectionalButton));
|
||||
}
|
||||
} else {
|
||||
add(new Press(button));
|
||||
route(new Press(button));
|
||||
previousDirectionalButton = button;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import mimis.device.javainput.JavaInputDevice;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.button.UnknownDirectionException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.value.Action;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
@@ -22,9 +23,9 @@ public class Extreme3DDevice extends JavaInputDevice {
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
super.activate();
|
||||
add(taskMapCycle.mimis);
|
||||
add(taskMapCycle.player);
|
||||
add(taskMapCycle.like);
|
||||
parser(Action.ADD, taskMapCycle.mimis);
|
||||
parser(Action.ADD, taskMapCycle.player);
|
||||
parser(Action.ADD, taskMapCycle.like);
|
||||
}
|
||||
|
||||
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {
|
||||
|
||||
@@ -6,6 +6,7 @@ import mimis.device.javainput.JavaInputDevice;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.button.UnknownDirectionException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.value.Action;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
@@ -22,9 +23,9 @@ public class RumblepadDevice extends JavaInputDevice {
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
super.activate();
|
||||
add(taskMapCycle.mimis);
|
||||
add(taskMapCycle.player);
|
||||
add(taskMapCycle.like);
|
||||
parser(Action.ADD, taskMapCycle.mimis);
|
||||
parser(Action.ADD, taskMapCycle.player);
|
||||
parser(Action.ADD, taskMapCycle.like);
|
||||
}
|
||||
|
||||
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {
|
||||
|
||||
@@ -2,18 +2,20 @@ package mimis.device.jintellitype;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mimis.device.Device;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.state.Press;
|
||||
import mimis.input.state.Release;
|
||||
import mimis.value.Action;
|
||||
import mimis.worker.Component;
|
||||
|
||||
import com.melloware.jintellitype.HotkeyListener;
|
||||
import com.melloware.jintellitype.IntellitypeListener;
|
||||
import com.melloware.jintellitype.JIntellitype;
|
||||
|
||||
public class JIntellitypeDevice extends Component implements HotkeyListener, IntellitypeListener {
|
||||
public class JIntellitypeDevice extends Component implements Device, HotkeyListener, IntellitypeListener {
|
||||
protected static final String TITLE = "Keyboard";
|
||||
|
||||
protected JIntellitypeTaskMapCycle taskMapCycle;
|
||||
@@ -32,16 +34,16 @@ public class JIntellitypeDevice extends Component implements HotkeyListener, Int
|
||||
super.activate();
|
||||
jit.addHotKeyListener(this);
|
||||
jit.addIntellitypeListener(this);
|
||||
add(taskMapCycle.mimis);
|
||||
add(taskMapCycle.player);
|
||||
parser(Action.ADD, taskMapCycle.mimis);
|
||||
parser(Action.ADD, taskMapCycle.player);
|
||||
}
|
||||
|
||||
public void onIntellitype(int command) {
|
||||
if (active) {
|
||||
try {
|
||||
CommandButton commandButton = CommandButton.create(command);
|
||||
add(new Press(commandButton));
|
||||
add(new Release(commandButton));
|
||||
route(new Press(commandButton));
|
||||
route(new Release(commandButton));
|
||||
} catch (UnknownButtonException e) {
|
||||
log.error(e);
|
||||
}
|
||||
@@ -51,8 +53,8 @@ public class JIntellitypeDevice extends Component implements HotkeyListener, Int
|
||||
public void onHotKey(int id) {
|
||||
if (active) {
|
||||
Hotkey hotkey = hotkeyList.get(id);
|
||||
add(new Press(hotkey));
|
||||
add(new Release(hotkey));
|
||||
route(new Press(hotkey));
|
||||
route(new Release(hotkey));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package mimis.device.lirc;
|
||||
|
||||
import mimis.Button;
|
||||
import mimis.application.cmd.CMDApplication;
|
||||
import mimis.device.Device;
|
||||
import mimis.device.lirc.button.ColorButton;
|
||||
import mimis.device.lirc.button.NumberButton;
|
||||
import mimis.device.lirc.remote.DenonRC176Button;
|
||||
@@ -10,24 +12,22 @@ import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.state.Press;
|
||||
import mimis.input.state.Release;
|
||||
import mimis.parser.ParserInput;
|
||||
import mimis.util.Multiplexer;
|
||||
import mimis.util.Native;
|
||||
import mimis.util.multiplexer.SignalListener;
|
||||
import mimis.value.Action;
|
||||
import mimis.value.Signal;
|
||||
import mimis.worker.Component;
|
||||
|
||||
public class LircDevice extends Component implements LircButtonListener, SignalListener<Button> {
|
||||
protected static final String TITLE = "Lirc";
|
||||
public class LircDevice extends CMDApplication implements Device, LircButtonListener, SignalListener<Button> {
|
||||
protected final static String PROGRAM = "winlirc.exe";
|
||||
protected static final String TITLE = "Lirc";
|
||||
|
||||
protected Multiplexer<Button> multiplexer;
|
||||
protected LircService lircService;
|
||||
protected LircTaskMapCycle taskMapCycle;
|
||||
|
||||
public LircDevice() {
|
||||
super(TITLE);
|
||||
super(PROGRAM, TITLE);
|
||||
multiplexer = new Multiplexer<Button>(this);
|
||||
lircService = new LircService();
|
||||
lircService.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values());
|
||||
@@ -38,19 +38,22 @@ public class LircDevice extends Component implements LircButtonListener, SignalL
|
||||
}
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
lircService.start();
|
||||
route(new ParserInput(Action.ADD, taskMapCycle.denonRC176));
|
||||
route(new ParserInput(Action.ADD, taskMapCycle.philiphsRCLE011));
|
||||
route(new ParserInput(Action.ADD, taskMapCycle.samsungBN5901015A));
|
||||
super.activate();
|
||||
lircService.start();
|
||||
parser(Action.ADD, taskMapCycle.denonRC176);
|
||||
parser(Action.ADD, taskMapCycle.philiphsRCLE011);
|
||||
parser(Action.ADD, taskMapCycle.samsungBN5901015A);
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
if (active && !lircService.active()) {
|
||||
stop();
|
||||
} else if (!active) {
|
||||
if (Native.isRunning(PROGRAM)) {
|
||||
start();
|
||||
if (detect) {
|
||||
if (active && !lircService.active()) {
|
||||
stop();
|
||||
} else if (!active) {
|
||||
running = Native.isRunning(PROGRAM);
|
||||
if (running) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
}
|
||||
return active;
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import mimis.device.Device;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.Feedback;
|
||||
@@ -22,7 +23,7 @@ import mimis.worker.Worker;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class NetworkDevice extends Component {
|
||||
public class NetworkDevice extends Component implements Device {
|
||||
protected static final String TITLE = "Network";
|
||||
public static final int PORT = 6789;
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package mimis.device.panel;
|
||||
|
||||
import mimis.device.Device;
|
||||
import mimis.exception.worker.ActivateException;
|
||||
import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.state.Press;
|
||||
import mimis.input.state.Release;
|
||||
import mimis.parser.ParserInput;
|
||||
import mimis.value.Action;
|
||||
import mimis.worker.Component;
|
||||
|
||||
public class PanelDevice extends Component {
|
||||
public class PanelDevice extends Component implements Device {
|
||||
protected static final String TITLE = "Panel";
|
||||
protected Panel panel;
|
||||
protected PanelTaskMapCycle taskMapCycle;
|
||||
@@ -20,7 +20,7 @@ public class PanelDevice extends Component {
|
||||
|
||||
protected void activate() throws ActivateException {
|
||||
panel = new Panel(this);
|
||||
route(new ParserInput(Action.ADD, taskMapCycle.player));
|
||||
parser(Action.ADD, taskMapCycle.player);
|
||||
super.activate();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mimis.device.wiimote;
|
||||
|
||||
import mimis.Button;
|
||||
import mimis.device.Device;
|
||||
import mimis.device.wiimote.gesture.GestureDevice;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
import mimis.exception.device.DeviceNotFoundException;
|
||||
@@ -9,7 +10,6 @@ import mimis.exception.worker.DeactivateException;
|
||||
import mimis.input.Feedback;
|
||||
import mimis.input.state.Press;
|
||||
import mimis.input.state.Release;
|
||||
import mimis.parser.ParserInput;
|
||||
import mimis.util.ArrayCycle;
|
||||
import mimis.value.Action;
|
||||
import mimis.worker.Component;
|
||||
@@ -24,7 +24,7 @@ import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
|
||||
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
|
||||
|
||||
public class WiimoteDevice extends Component implements GestureListener {
|
||||
public class WiimoteDevice extends Component implements Device, GestureListener {
|
||||
protected static final String TITLE = "Wiimote";
|
||||
protected static final int RUMBLE = 50;
|
||||
protected static final int CONNECTED_TIMEOUT = 500;
|
||||
@@ -58,7 +58,7 @@ public class WiimoteDevice extends Component implements GestureListener {
|
||||
|
||||
/* Worker */
|
||||
protected void activate() throws ActivateException {
|
||||
add(taskMapCycle.player);
|
||||
parser(Action.ADD, taskMapCycle.player);
|
||||
wiimote = null;
|
||||
try {
|
||||
connect();
|
||||
@@ -118,15 +118,15 @@ public class WiimoteDevice extends Component implements GestureListener {
|
||||
switch (action) {
|
||||
case SHIFT:
|
||||
log.debug("Shift");
|
||||
route(new ParserInput(Action.RESET, taskMapCycle.player));
|
||||
add(taskMapCycle.mimis);
|
||||
add(taskMapCycle.like);
|
||||
parser(Action.RESET, taskMapCycle.player);
|
||||
parser(Action.ADD, taskMapCycle.mimis);
|
||||
parser(Action.ADD, taskMapCycle.like);
|
||||
break;
|
||||
case UNSHIFT:
|
||||
log.debug("Unshift");
|
||||
route(new ParserInput(Action.RESET, taskMapCycle.mimis));
|
||||
route(new ParserInput(Action.RESET, taskMapCycle.like));
|
||||
add(taskMapCycle.player);
|
||||
parser(Action.RESET, taskMapCycle.mimis);
|
||||
parser(Action.RESET, taskMapCycle.like);
|
||||
parser(Action.ADD, taskMapCycle.player);
|
||||
break;
|
||||
case TRAIN:
|
||||
log.debug("Gesture train");
|
||||
@@ -185,11 +185,11 @@ public class WiimoteDevice extends Component implements GestureListener {
|
||||
if (pressed != 0 && released == 0) {
|
||||
Button button = WiimoteButton.create(pressed);
|
||||
log.trace("Press: " + button);
|
||||
add(new Press(button));
|
||||
route(new Press(button));
|
||||
} else if (pressed == 0 && released != 0) {
|
||||
Button button = WiimoteButton.create(released);
|
||||
log.trace("Release: " + button);
|
||||
add(new Release(button));
|
||||
route(new Release(button));
|
||||
}
|
||||
} catch (UnknownButtonException e) {}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import mimis.value.Target;
|
||||
public class WiimoteTaskMapCycle extends TaskMapCycle {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
public TaskMap mimis, player, gesture, like, shift;
|
||||
public TaskMap mimis, player, gesture, like;
|
||||
|
||||
public WiimoteTaskMapCycle() {
|
||||
/* Mimis */
|
||||
|
||||
@@ -4,7 +4,9 @@ import mimis.input.Feedback;
|
||||
import mimis.input.Input;
|
||||
import mimis.input.Task;
|
||||
import mimis.input.state.State;
|
||||
import mimis.parser.ParserInput;
|
||||
import mimis.router.Router;
|
||||
import mimis.state.TaskMap;
|
||||
import mimis.value.Action;
|
||||
|
||||
public abstract class Component extends Listener<Input> {
|
||||
@@ -100,4 +102,8 @@ public abstract class Component extends Listener<Input> {
|
||||
protected void action(Action action) {}
|
||||
protected void begin(Action action) {}
|
||||
protected void end(Action action) {}
|
||||
|
||||
protected void parser(Action action, TaskMap taskMap) {
|
||||
route(new ParserInput(action, taskMap));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ public abstract class Worker implements Runnable {
|
||||
protected Log log = LogFactory.getLog(getClass());
|
||||
|
||||
protected static final boolean THREAD = false;
|
||||
protected static final boolean INTERRUPT = false;
|
||||
protected static final int SLEEP = 100;
|
||||
|
||||
protected boolean interrupt;
|
||||
|
||||
Reference in New Issue
Block a user