Kleine aanpassingen. Lirc kan nu gestart worden via de GUI.

This commit is contained in:
2012-03-04 11:38:04 +00:00
parent 601e4a2464
commit 56967b97a7
13 changed files with 92 additions and 70 deletions

View File

@@ -16,15 +16,18 @@ public abstract class CMDApplication extends Component {
protected String program; protected String program;
protected String title; protected String title;
protected Process process; protected Process process;
protected boolean detect, running;
public CMDApplication(String program, String title) { public CMDApplication(String program, String title) {
super(title); super(title);
this.program = program; this.program = program;
this.title = title; this.title = title;
detect = true;
} }
protected void activate() throws ActivateException { protected void activate() throws ActivateException {
super.activate(); detect = true;
if (!running) {
String path = getPath(); String path = getPath();
if (path == null) { if (path == null) {
throw new ActivateException(); throw new ActivateException();
@@ -38,17 +41,22 @@ public abstract class CMDApplication extends Component {
throw new ActivateException(); throw new ActivateException();
} }
} }
super.activate();
}
public boolean active() { public boolean active() {
boolean running = Native.isRunning(program); if (detect) {
running = Native.isRunning(program);
if (!active && running) { if (!active && running) {
active = true; active = true;
start(); start();
} }
return active = running; }
return active;
} }
protected synchronized void deactivate() throws DeactivateException { protected synchronized void deactivate() throws DeactivateException {
detect = false;
super.deactivate(); super.deactivate();
if (process != null) { if (process != null) {
process.destroy(); process.destroy();

View File

@@ -1,5 +1,6 @@
package mimis.application.itunes; package mimis.application.itunes;
import mimis.application.Application;
import mimis.exception.worker.ActivateException; import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException; import mimis.exception.worker.DeactivateException;
import mimis.value.Action; import mimis.value.Action;
@@ -11,7 +12,7 @@ import com.dt.iTunesController.ITTrack;
import com.dt.iTunesController.iTunes; import com.dt.iTunesController.iTunes;
import com.dt.iTunesController.iTunesEventsInterface; 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 String TITLE = "iTunes";
protected static final boolean EVENTS = false; protected static final boolean EVENTS = false;
@@ -22,7 +23,7 @@ public class iTunesApplication extends Component implements iTunesEventsInterfac
protected iTunes iTunes; protected iTunes iTunes;
protected VolumeWorker volumeWorker; protected VolumeWorker volumeWorker;
protected boolean events, handle; protected boolean events;
public iTunesApplication() { public iTunesApplication() {
this(EVENTS); this(EVENTS);
@@ -32,7 +33,6 @@ public class iTunesApplication extends Component implements iTunesEventsInterfac
super(TITLE); super(TITLE);
this.events = events; this.events = events;
volumeWorker = new VolumeWorker(); volumeWorker = new VolumeWorker();
handle = false;
} }
protected synchronized void activate() throws ActivateException { protected synchronized void activate() throws ActivateException {

View File

@@ -1,6 +1,7 @@
package mimis.device.javainput; package mimis.device.javainput;
import mimis.Button; import mimis.Button;
import mimis.device.Device;
import mimis.exception.ButtonException; import mimis.exception.ButtonException;
import mimis.exception.button.UnknownButtonException; import mimis.exception.button.UnknownButtonException;
import mimis.exception.button.UnknownDirectionException; 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.JXInputButtonEvent;
import de.hardcode.jxinput.event.JXInputDirectionalEvent; import de.hardcode.jxinput.event.JXInputDirectionalEvent;
public abstract class JavaInputDevice extends Component { public abstract class JavaInputDevice extends Component implements Device {
protected String name; protected String name;
public JavaInputDevice(String title, 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 { public void processEvent(JXInputButtonEvent event) throws ButtonException {
Button button = getButton(event); Button button = getButton(event);
if (event.getButton().getState()) { if (event.getButton().getState()) {
add(new Press(button)); route(new Press(button));
} else { } else {
add(new Release(button)); route(new Release(button));
} }
} }
@@ -60,10 +61,10 @@ public abstract class JavaInputDevice extends Component {
Button button = getButton(event); Button button = getButton(event);
if (event.getDirectional().isCentered()) { if (event.getDirectional().isCentered()) {
if (previousDirectionalButton != null) { if (previousDirectionalButton != null) {
add(new Release(previousDirectionalButton)); route(new Release(previousDirectionalButton));
} }
} else { } else {
add(new Press(button)); route(new Press(button));
previousDirectionalButton = button; previousDirectionalButton = button;
} }
} }

View File

@@ -6,6 +6,7 @@ import mimis.device.javainput.JavaInputDevice;
import mimis.exception.button.UnknownButtonException; import mimis.exception.button.UnknownButtonException;
import mimis.exception.button.UnknownDirectionException; import mimis.exception.button.UnknownDirectionException;
import mimis.exception.worker.ActivateException; import mimis.exception.worker.ActivateException;
import mimis.value.Action;
import de.hardcode.jxinput.event.JXInputButtonEvent; import de.hardcode.jxinput.event.JXInputButtonEvent;
import de.hardcode.jxinput.event.JXInputDirectionalEvent; import de.hardcode.jxinput.event.JXInputDirectionalEvent;
@@ -22,9 +23,9 @@ public class Extreme3DDevice extends JavaInputDevice {
protected void activate() throws ActivateException { protected void activate() throws ActivateException {
super.activate(); super.activate();
add(taskMapCycle.mimis); parser(Action.ADD, taskMapCycle.mimis);
add(taskMapCycle.player); parser(Action.ADD, taskMapCycle.player);
add(taskMapCycle.like); parser(Action.ADD, taskMapCycle.like);
} }
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException { protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {

View File

@@ -6,6 +6,7 @@ import mimis.device.javainput.JavaInputDevice;
import mimis.exception.button.UnknownButtonException; import mimis.exception.button.UnknownButtonException;
import mimis.exception.button.UnknownDirectionException; import mimis.exception.button.UnknownDirectionException;
import mimis.exception.worker.ActivateException; import mimis.exception.worker.ActivateException;
import mimis.value.Action;
import de.hardcode.jxinput.event.JXInputButtonEvent; import de.hardcode.jxinput.event.JXInputButtonEvent;
import de.hardcode.jxinput.event.JXInputDirectionalEvent; import de.hardcode.jxinput.event.JXInputDirectionalEvent;
@@ -22,9 +23,9 @@ public class RumblepadDevice extends JavaInputDevice {
protected void activate() throws ActivateException { protected void activate() throws ActivateException {
super.activate(); super.activate();
add(taskMapCycle.mimis); parser(Action.ADD, taskMapCycle.mimis);
add(taskMapCycle.player); parser(Action.ADD, taskMapCycle.player);
add(taskMapCycle.like); parser(Action.ADD, taskMapCycle.like);
} }
protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException { protected Button getButton(JXInputButtonEvent event) throws UnknownButtonException {

View File

@@ -2,18 +2,20 @@ package mimis.device.jintellitype;
import java.util.ArrayList; import java.util.ArrayList;
import mimis.device.Device;
import mimis.exception.button.UnknownButtonException; import mimis.exception.button.UnknownButtonException;
import mimis.exception.worker.ActivateException; import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException; import mimis.exception.worker.DeactivateException;
import mimis.input.state.Press; import mimis.input.state.Press;
import mimis.input.state.Release; import mimis.input.state.Release;
import mimis.value.Action;
import mimis.worker.Component; import mimis.worker.Component;
import com.melloware.jintellitype.HotkeyListener; import com.melloware.jintellitype.HotkeyListener;
import com.melloware.jintellitype.IntellitypeListener; import com.melloware.jintellitype.IntellitypeListener;
import com.melloware.jintellitype.JIntellitype; 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 static final String TITLE = "Keyboard";
protected JIntellitypeTaskMapCycle taskMapCycle; protected JIntellitypeTaskMapCycle taskMapCycle;
@@ -32,16 +34,16 @@ public class JIntellitypeDevice extends Component implements HotkeyListener, Int
super.activate(); super.activate();
jit.addHotKeyListener(this); jit.addHotKeyListener(this);
jit.addIntellitypeListener(this); jit.addIntellitypeListener(this);
add(taskMapCycle.mimis); parser(Action.ADD, taskMapCycle.mimis);
add(taskMapCycle.player); parser(Action.ADD, taskMapCycle.player);
} }
public void onIntellitype(int command) { public void onIntellitype(int command) {
if (active) { if (active) {
try { try {
CommandButton commandButton = CommandButton.create(command); CommandButton commandButton = CommandButton.create(command);
add(new Press(commandButton)); route(new Press(commandButton));
add(new Release(commandButton)); route(new Release(commandButton));
} catch (UnknownButtonException e) { } catch (UnknownButtonException e) {
log.error(e); log.error(e);
} }
@@ -51,8 +53,8 @@ public class JIntellitypeDevice extends Component implements HotkeyListener, Int
public void onHotKey(int id) { public void onHotKey(int id) {
if (active) { if (active) {
Hotkey hotkey = hotkeyList.get(id); Hotkey hotkey = hotkeyList.get(id);
add(new Press(hotkey)); route(new Press(hotkey));
add(new Release(hotkey)); route(new Release(hotkey));
} }
} }

View File

@@ -1,6 +1,8 @@
package mimis.device.lirc; package mimis.device.lirc;
import mimis.Button; import mimis.Button;
import mimis.application.cmd.CMDApplication;
import mimis.device.Device;
import mimis.device.lirc.button.ColorButton; import mimis.device.lirc.button.ColorButton;
import mimis.device.lirc.button.NumberButton; import mimis.device.lirc.button.NumberButton;
import mimis.device.lirc.remote.DenonRC176Button; import mimis.device.lirc.remote.DenonRC176Button;
@@ -10,24 +12,22 @@ import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException; import mimis.exception.worker.DeactivateException;
import mimis.input.state.Press; import mimis.input.state.Press;
import mimis.input.state.Release; import mimis.input.state.Release;
import mimis.parser.ParserInput;
import mimis.util.Multiplexer; import mimis.util.Multiplexer;
import mimis.util.Native; import mimis.util.Native;
import mimis.util.multiplexer.SignalListener; import mimis.util.multiplexer.SignalListener;
import mimis.value.Action; import mimis.value.Action;
import mimis.value.Signal; import mimis.value.Signal;
import mimis.worker.Component;
public class LircDevice extends Component implements LircButtonListener, SignalListener<Button> { public class LircDevice extends CMDApplication implements Device, LircButtonListener, SignalListener<Button> {
protected static final String TITLE = "Lirc";
protected final static String PROGRAM = "winlirc.exe"; protected final static String PROGRAM = "winlirc.exe";
protected static final String TITLE = "Lirc";
protected Multiplexer<Button> multiplexer; protected Multiplexer<Button> multiplexer;
protected LircService lircService; protected LircService lircService;
protected LircTaskMapCycle taskMapCycle; protected LircTaskMapCycle taskMapCycle;
public LircDevice() { public LircDevice() {
super(TITLE); super(PROGRAM, TITLE);
multiplexer = new Multiplexer<Button>(this); multiplexer = new Multiplexer<Button>(this);
lircService = new LircService(); lircService = new LircService();
lircService.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values()); lircService.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values());
@@ -38,21 +38,24 @@ public class LircDevice extends Component implements LircButtonListener, SignalL
} }
protected void activate() throws ActivateException { 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(); super.activate();
lircService.start();
parser(Action.ADD, taskMapCycle.denonRC176);
parser(Action.ADD, taskMapCycle.philiphsRCLE011);
parser(Action.ADD, taskMapCycle.samsungBN5901015A);
} }
public boolean active() { public boolean active() {
if (detect) {
if (active && !lircService.active()) { if (active && !lircService.active()) {
stop(); stop();
} else if (!active) { } else if (!active) {
if (Native.isRunning(PROGRAM)) { running = Native.isRunning(PROGRAM);
if (running) {
start(); start();
} }
} }
}
return active; return active;
} }

View File

@@ -9,6 +9,7 @@ import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import mimis.device.Device;
import mimis.exception.worker.ActivateException; import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException; import mimis.exception.worker.DeactivateException;
import mimis.input.Feedback; import mimis.input.Feedback;
@@ -22,7 +23,7 @@ import mimis.worker.Worker;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
public class NetworkDevice extends Component { public class NetworkDevice extends Component implements Device {
protected static final String TITLE = "Network"; protected static final String TITLE = "Network";
public static final int PORT = 6789; public static final int PORT = 6789;

View File

@@ -1,14 +1,14 @@
package mimis.device.panel; package mimis.device.panel;
import mimis.device.Device;
import mimis.exception.worker.ActivateException; import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException; import mimis.exception.worker.DeactivateException;
import mimis.input.state.Press; import mimis.input.state.Press;
import mimis.input.state.Release; import mimis.input.state.Release;
import mimis.parser.ParserInput;
import mimis.value.Action; import mimis.value.Action;
import mimis.worker.Component; import mimis.worker.Component;
public class PanelDevice extends Component { public class PanelDevice extends Component implements Device {
protected static final String TITLE = "Panel"; protected static final String TITLE = "Panel";
protected Panel panel; protected Panel panel;
protected PanelTaskMapCycle taskMapCycle; protected PanelTaskMapCycle taskMapCycle;
@@ -20,7 +20,7 @@ public class PanelDevice extends Component {
protected void activate() throws ActivateException { protected void activate() throws ActivateException {
panel = new Panel(this); panel = new Panel(this);
route(new ParserInput(Action.ADD, taskMapCycle.player)); parser(Action.ADD, taskMapCycle.player);
super.activate(); super.activate();
} }

View File

@@ -1,6 +1,7 @@
package mimis.device.wiimote; package mimis.device.wiimote;
import mimis.Button; import mimis.Button;
import mimis.device.Device;
import mimis.device.wiimote.gesture.GestureDevice; import mimis.device.wiimote.gesture.GestureDevice;
import mimis.exception.button.UnknownButtonException; import mimis.exception.button.UnknownButtonException;
import mimis.exception.device.DeviceNotFoundException; import mimis.exception.device.DeviceNotFoundException;
@@ -9,7 +10,6 @@ import mimis.exception.worker.DeactivateException;
import mimis.input.Feedback; import mimis.input.Feedback;
import mimis.input.state.Press; import mimis.input.state.Press;
import mimis.input.state.Release; import mimis.input.state.Release;
import mimis.parser.ParserInput;
import mimis.util.ArrayCycle; import mimis.util.ArrayCycle;
import mimis.value.Action; import mimis.value.Action;
import mimis.worker.Component; import mimis.worker.Component;
@@ -24,7 +24,7 @@ import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent; import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent; 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 String TITLE = "Wiimote";
protected static final int RUMBLE = 50; protected static final int RUMBLE = 50;
protected static final int CONNECTED_TIMEOUT = 500; protected static final int CONNECTED_TIMEOUT = 500;
@@ -58,7 +58,7 @@ public class WiimoteDevice extends Component implements GestureListener {
/* Worker */ /* Worker */
protected void activate() throws ActivateException { protected void activate() throws ActivateException {
add(taskMapCycle.player); parser(Action.ADD, taskMapCycle.player);
wiimote = null; wiimote = null;
try { try {
connect(); connect();
@@ -118,15 +118,15 @@ public class WiimoteDevice extends Component implements GestureListener {
switch (action) { switch (action) {
case SHIFT: case SHIFT:
log.debug("Shift"); log.debug("Shift");
route(new ParserInput(Action.RESET, taskMapCycle.player)); parser(Action.RESET, taskMapCycle.player);
add(taskMapCycle.mimis); parser(Action.ADD, taskMapCycle.mimis);
add(taskMapCycle.like); parser(Action.ADD, taskMapCycle.like);
break; break;
case UNSHIFT: case UNSHIFT:
log.debug("Unshift"); log.debug("Unshift");
route(new ParserInput(Action.RESET, taskMapCycle.mimis)); parser(Action.RESET, taskMapCycle.mimis);
route(new ParserInput(Action.RESET, taskMapCycle.like)); parser(Action.RESET, taskMapCycle.like);
add(taskMapCycle.player); parser(Action.ADD, taskMapCycle.player);
break; break;
case TRAIN: case TRAIN:
log.debug("Gesture train"); log.debug("Gesture train");
@@ -185,11 +185,11 @@ public class WiimoteDevice extends Component implements GestureListener {
if (pressed != 0 && released == 0) { if (pressed != 0 && released == 0) {
Button button = WiimoteButton.create(pressed); Button button = WiimoteButton.create(pressed);
log.trace("Press: " + button); log.trace("Press: " + button);
add(new Press(button)); route(new Press(button));
} else if (pressed == 0 && released != 0) { } else if (pressed == 0 && released != 0) {
Button button = WiimoteButton.create(released); Button button = WiimoteButton.create(released);
log.trace("Release: " + button); log.trace("Release: " + button);
add(new Release(button)); route(new Release(button));
} }
} catch (UnknownButtonException e) {} } catch (UnknownButtonException e) {}
} }

View File

@@ -10,7 +10,7 @@ import mimis.value.Target;
public class WiimoteTaskMapCycle extends TaskMapCycle { public class WiimoteTaskMapCycle extends TaskMapCycle {
protected static final long serialVersionUID = 1L; protected static final long serialVersionUID = 1L;
public TaskMap mimis, player, gesture, like, shift; public TaskMap mimis, player, gesture, like;
public WiimoteTaskMapCycle() { public WiimoteTaskMapCycle() {
/* Mimis */ /* Mimis */

View File

@@ -4,7 +4,9 @@ import mimis.input.Feedback;
import mimis.input.Input; import mimis.input.Input;
import mimis.input.Task; import mimis.input.Task;
import mimis.input.state.State; import mimis.input.state.State;
import mimis.parser.ParserInput;
import mimis.router.Router; import mimis.router.Router;
import mimis.state.TaskMap;
import mimis.value.Action; import mimis.value.Action;
public abstract class Component extends Listener<Input> { 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 action(Action action) {}
protected void begin(Action action) {} protected void begin(Action action) {}
protected void end(Action action) {} protected void end(Action action) {}
protected void parser(Action action, TaskMap taskMap) {
route(new ParserInput(action, taskMap));
}
} }

View File

@@ -10,7 +10,6 @@ public abstract class Worker implements Runnable {
protected Log log = LogFactory.getLog(getClass()); protected Log log = LogFactory.getLog(getClass());
protected static final boolean THREAD = false; protected static final boolean THREAD = false;
protected static final boolean INTERRUPT = false;
protected static final int SLEEP = 100; protected static final int SLEEP = 100;
protected boolean interrupt; protected boolean interrupt;