Multiplexer ten behoeve van Lirc toegevoegd.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
log4j.rootLogger=TRACE, CA
|
||||
log4j.rootLogger=DEBUG, CA
|
||||
log4j.appender.CA=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
|
||||
|
||||
@@ -76,6 +76,7 @@ public abstract class Device extends EventHandler implements Titled, Exitable {
|
||||
|
||||
/* Recognize events */
|
||||
protected void add(State state) {
|
||||
log.debug(state.toString() + " " + state.getButton());
|
||||
sequenceListener.add(state);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public abstract class Worker implements Runnable {
|
||||
protected boolean active = false;
|
||||
|
||||
public void start(boolean thread) {
|
||||
log.debug("Start");
|
||||
log.trace("Start");
|
||||
running = true;
|
||||
if (thread) {
|
||||
log.debug("Start thread");
|
||||
@@ -29,7 +29,7 @@ public abstract class Worker implements Runnable {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
log.debug("Stop");
|
||||
log.trace("Stop");
|
||||
if (active()) {
|
||||
deactivate();
|
||||
}
|
||||
@@ -66,6 +66,9 @@ public abstract class Worker implements Runnable {
|
||||
start(thread);
|
||||
}
|
||||
active = true;
|
||||
synchronized (this) {
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
@@ -79,7 +82,7 @@ public abstract class Worker implements Runnable {
|
||||
} else {
|
||||
try {
|
||||
synchronized (this) {
|
||||
log.debug("Wait");
|
||||
log.trace("Wait");
|
||||
wait();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
@@ -2,13 +2,17 @@ package mimis.device.lirc;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import mimis.Button;
|
||||
import mimis.Device;
|
||||
import mimis.device.lirc.button.DenonRC176;
|
||||
import mimis.device.lirc.button.PhiliphsRCLE011Button;
|
||||
import mimis.macro.state.Press;
|
||||
import mimis.macro.state.Release;
|
||||
import mimis.util.Multiplexer;
|
||||
import mimis.util.multiplexer.SignalListener;
|
||||
import mimis.value.Signal;
|
||||
|
||||
|
||||
public class LircDevice extends Device implements LircButtonListener {
|
||||
public class LircDevice extends Device implements LircButtonListener, SignalListener {
|
||||
protected static final String TITLE = "Lirc";
|
||||
|
||||
protected Multiplexer multiplexer;
|
||||
@@ -21,23 +25,36 @@ public class LircDevice extends Device implements LircButtonListener {
|
||||
buttonMap.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values());
|
||||
buttonMap.put(DenonRC176.NAME, DenonRC176.values());
|
||||
|
||||
multiplexer = new Multiplexer();
|
||||
|
||||
multiplexer = new Multiplexer(this);
|
||||
|
||||
lircService = new LircService(buttonMap);
|
||||
lircService.add(this);
|
||||
}
|
||||
|
||||
public void activate() {
|
||||
lircService.start();
|
||||
multiplexer.start();
|
||||
lircService.activate();
|
||||
super.activate();
|
||||
}
|
||||
|
||||
public void deactivate() {
|
||||
multiplexer.deactivate();
|
||||
lircService.deactivate();
|
||||
super.deactivate();
|
||||
}
|
||||
|
||||
public void add(LircButton lircButton) {
|
||||
|
||||
multiplexer.add(lircButton);
|
||||
}
|
||||
|
||||
public void add(Signal signal, Object object) {
|
||||
switch (signal) {
|
||||
case BEGIN:
|
||||
add(new Press((Button) object));
|
||||
break;
|
||||
case END:
|
||||
add(new Release((Button) object));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.Scanner;
|
||||
import mimis.Worker;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
|
||||
|
||||
public class LircService extends Worker {
|
||||
public static final String IP = "127.0.0.1";
|
||||
public static final int PORT = 8765;
|
||||
@@ -33,6 +32,7 @@ public class LircService extends Worker {
|
||||
|
||||
public LircService(HashMap<String, LircButton[]> buttonMap) {
|
||||
this(buttonMap, IP, PORT);
|
||||
//String send = Native.getValue("HKEY_CURRENT_USER\\Software\\LIRC", "password");
|
||||
}
|
||||
|
||||
public LircService(HashMap<String, LircButton[]> buttonMap, String ip, int port) {
|
||||
@@ -83,7 +83,7 @@ public class LircService extends Worker {
|
||||
String string = bufferedReader.readLine();
|
||||
try {
|
||||
LircButton lircButton = parseButton(new Scanner(string));
|
||||
log.debug(String.format("Lirc button: %s", lircButton));
|
||||
//log.debug(String.format("Lirc button: %s", lircButton));
|
||||
for (LircButtonListener lircbuttonListener : lircButtonListenerList) {
|
||||
lircbuttonListener.add(lircButton);
|
||||
}
|
||||
@@ -112,10 +112,8 @@ public class LircService extends Worker {
|
||||
throw new UnknownButtonException();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("hey");
|
||||
//String send = Native.getValue("HKEY_CURRENT_USER\\Software\\LIRC", "password");
|
||||
new LircDevice().start();
|
||||
public static void main(String[] args) {
|
||||
new LircDevice().activate();
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package mimis.device.lirc.button;
|
||||
|
||||
import mimis.device.lirc.LircButton;
|
||||
import mimis.exception.button.UnknownButtonException;
|
||||
|
||||
public enum PhiliphsRCLE011Button implements LircButton {
|
||||
POWER ("Standby"),
|
||||
@@ -43,7 +42,7 @@ public enum PhiliphsRCLE011Button implements LircButton {
|
||||
public static final String NAME = "Philips_RCLE011";
|
||||
|
||||
protected String code;
|
||||
|
||||
|
||||
private PhiliphsRCLE011Button(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
@@ -51,13 +50,4 @@ public enum PhiliphsRCLE011Button implements LircButton {
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static PhiliphsRCLE011Button create(String code) throws UnknownButtonException {
|
||||
for (PhiliphsRCLE011Button button : PhiliphsRCLE011Button.values()) {
|
||||
if (button.getCode().equals(code)) {
|
||||
return button;
|
||||
}
|
||||
}
|
||||
throw new UnknownButtonException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,56 @@
|
||||
package mimis.util;
|
||||
|
||||
import mimis.Worker;
|
||||
import mimis.util.multiplexer.SignalListener;
|
||||
import mimis.value.Signal;
|
||||
|
||||
public class Multiplexer extends Worker {
|
||||
public static final int THRESHOLD = 500;
|
||||
public static final int TIMEOUT = 150;
|
||||
|
||||
protected int threshold;
|
||||
protected Object object;
|
||||
protected SignalListener signalListener;
|
||||
protected boolean end;
|
||||
|
||||
public Multiplexer(SignalListener signalListener) {
|
||||
this(signalListener, TIMEOUT);
|
||||
}
|
||||
|
||||
public Multiplexer(SignalListener signalListener, int treshold) {
|
||||
this.signalListener = signalListener;
|
||||
}
|
||||
|
||||
public void add(Object object) {
|
||||
if (this.object == null) {
|
||||
signalListener.add(Signal.BEGIN, object);
|
||||
this.object = object;
|
||||
end = true;
|
||||
activate();
|
||||
} else if (this.object.equals(object)) {
|
||||
end = false;
|
||||
synchronized (this) {
|
||||
notifyAll();
|
||||
}
|
||||
} else {
|
||||
end = true;
|
||||
synchronized (this) {
|
||||
notifyAll();
|
||||
}
|
||||
add(object);
|
||||
}
|
||||
}
|
||||
|
||||
protected void work() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
try {
|
||||
synchronized (this) {
|
||||
wait(TIMEOUT);
|
||||
}
|
||||
} catch (InterruptedException e) {}
|
||||
if (end) {
|
||||
signalListener.add(Signal.END, object);
|
||||
object = null;
|
||||
deactivate();
|
||||
}
|
||||
end = !end;
|
||||
}
|
||||
}
|
||||
|
||||
7
java/src/mimis/util/multiplexer/SignalListener.java
Normal file
7
java/src/mimis/util/multiplexer/SignalListener.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package mimis.util.multiplexer;
|
||||
|
||||
import mimis.value.Signal;
|
||||
|
||||
public interface SignalListener {
|
||||
public void add(Signal signal, Object object);
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package mimis.value;
|
||||
|
||||
import mimis.exception.task.action.ActionDeserializeException;
|
||||
|
||||
public enum Action {
|
||||
EXIT,
|
||||
FORWARD,
|
||||
@@ -19,16 +17,4 @@ public enum Action {
|
||||
VOLUME_UP,
|
||||
FULLSCREEN,
|
||||
TRAIN, STOP, SAVE, RECOGNIZE, LOAD, SHUFFLE, FADEOUT, QUIT, VISUALISER, LIKE, DISLIKE;
|
||||
|
||||
public String serialze() {
|
||||
return name();
|
||||
}
|
||||
|
||||
public static Action deserialise(String value) throws ActionDeserializeException {
|
||||
try {
|
||||
return Action.valueOf(value);
|
||||
} catch (NullPointerException e) {
|
||||
throw new ActionDeserializeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
java/src/mimis/value/Signal.java
Normal file
5
java/src/mimis/value/Signal.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package mimis.value;
|
||||
|
||||
public enum Signal {
|
||||
BEGIN, END;
|
||||
}
|
||||
Reference in New Issue
Block a user