iPod applicatie omgeschreven naar lircdevice. Wiimote verbindt niet altijd goed. Procedure nakijken!
This commit is contained in:
@@ -3,8 +3,8 @@ package mimis;
|
|||||||
import mimis.application.cmd.windows.gomplayer.GomPlayerApplication;
|
import mimis.application.cmd.windows.gomplayer.GomPlayerApplication;
|
||||||
import mimis.application.cmd.windows.winamp.WinampApplication;
|
import mimis.application.cmd.windows.winamp.WinampApplication;
|
||||||
import mimis.application.cmd.windows.wmp.WMPApplication;
|
import mimis.application.cmd.windows.wmp.WMPApplication;
|
||||||
import mimis.application.irtoy.ipod.iPodApplication;
|
|
||||||
import mimis.application.itunes.iTunesApplication;
|
import mimis.application.itunes.iTunesApplication;
|
||||||
|
import mimis.application.lirc.ipod.iPodApplication;
|
||||||
import mimis.application.mpc.MPCApplication;
|
import mimis.application.mpc.MPCApplication;
|
||||||
import mimis.application.vlc.VLCApplication;
|
import mimis.application.vlc.VLCApplication;
|
||||||
import mimis.device.javainput.extreme3d.Extreme3DDevice;
|
import mimis.device.javainput.extreme3d.Extreme3DDevice;
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
package mimis.application.irtoy;
|
|
||||||
|
|
||||||
public class Command {
|
|
||||||
protected String name;
|
|
||||||
protected String data;
|
|
||||||
|
|
||||||
public Command(String name, String data) {
|
|
||||||
this.name = name;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
package mimis.application.irtoy;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import mimis.util.Reader;
|
|
||||||
|
|
||||||
public class Config {
|
|
||||||
public static final String FILE = "C:\\Users\\Rik\\Dropbox\\Gedeeld\\Mimis\\IRToy\\WinLIRC\\remote.txt";
|
|
||||||
|
|
||||||
protected Log log = LogFactory.getLog(getClass());
|
|
||||||
protected static Config config;
|
|
||||||
protected File file;
|
|
||||||
protected ArrayList<Remote> remoteList;
|
|
||||||
|
|
||||||
private Config() {
|
|
||||||
file = new File(FILE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Config getInstance() {
|
|
||||||
if (config == null) {
|
|
||||||
config = new Config();
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Remote getRemote(String name) {
|
|
||||||
if (remoteList == null) {
|
|
||||||
remoteList = new ArrayList<Remote>();
|
|
||||||
try {
|
|
||||||
parse();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error(e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Remote remote : remoteList) {
|
|
||||||
if (remote.getName().equals(name)) {
|
|
||||||
return remote;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void parse() throws IOException {
|
|
||||||
String contents = Reader.getContents(file);
|
|
||||||
Pattern pattern = Pattern.compile("begin remote(.+?)end remote", Pattern.DOTALL);
|
|
||||||
Matcher remoteMatcher = pattern.matcher(contents);
|
|
||||||
while (remoteMatcher.find()) {
|
|
||||||
pattern = Pattern.compile("begin raw_codes(.+)end raw_codes", Pattern.DOTALL);
|
|
||||||
Matcher rawMatcher = pattern.matcher(remoteMatcher.group(1));
|
|
||||||
if (rawMatcher.find()) {
|
|
||||||
String raw = rawMatcher.group(1);
|
|
||||||
pattern = Pattern.compile("name[ ]+(.+)");
|
|
||||||
Matcher nameMatcher = pattern.matcher(remoteMatcher.group(1));
|
|
||||||
if (nameMatcher.find()) {
|
|
||||||
String name = nameMatcher.group(1);
|
|
||||||
pattern = Pattern.compile("name[ ]+([^\n]+)(.*?)(?=name)", Pattern.DOTALL);
|
|
||||||
Remote remote = new Remote(name);
|
|
||||||
Matcher commandMatcher = pattern.matcher(raw);
|
|
||||||
while (commandMatcher.find()) {
|
|
||||||
String data = commandMatcher.group(2);
|
|
||||||
pattern = Pattern.compile("([0-9]+)");
|
|
||||||
Matcher dataMatcher = pattern.matcher(data);
|
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
|
||||||
while (dataMatcher.find()) {
|
|
||||||
stringBuffer.append((char) Math.round(Double.valueOf(dataMatcher.group(1)) / 21.3333));
|
|
||||||
}
|
|
||||||
stringBuffer.append(0xffff);
|
|
||||||
Command command = new Command(commandMatcher.group(1), stringBuffer.toString());
|
|
||||||
remote.add(command);
|
|
||||||
}
|
|
||||||
remoteList.add(remote);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package mimis.application.irtoy;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class Remote {
|
|
||||||
protected String name;
|
|
||||||
protected ArrayList<Command> commandList;
|
|
||||||
|
|
||||||
public Remote(String name) {
|
|
||||||
this.name = name;
|
|
||||||
commandList = new ArrayList<Command>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Command command) {
|
|
||||||
commandList.add(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Command getCommand(String name) {
|
|
||||||
for (Command command : commandList) {
|
|
||||||
if (command.getName().equals(name)) {
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
package mimis.application.irtoy.ipod;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
|
|
||||||
import mimis.Application;
|
|
||||||
import mimis.Worker;
|
|
||||||
import mimis.application.irtoy.Command;
|
|
||||||
import mimis.application.irtoy.Config;
|
|
||||||
import mimis.application.irtoy.Remote;
|
|
||||||
import mimis.device.lirc.LircService;
|
|
||||||
import mimis.device.lirc.remote.WC02IPOButton;
|
|
||||||
import mimis.exception.worker.ActivateException;
|
|
||||||
import mimis.exception.worker.DeactivateException;
|
|
||||||
import mimis.value.Action;
|
|
||||||
|
|
||||||
public class iPodApplication extends Application {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Config config = Config.getInstance();
|
|
||||||
Remote remote = config.getRemote("WC02-IPO");
|
|
||||||
if (remote != null) {
|
|
||||||
Command command = remote.getCommand("PLAY");
|
|
||||||
if (command != null) {
|
|
||||||
try {
|
|
||||||
File file = File.createTempFile("irtoy", ".bin");
|
|
||||||
file.deleteOnExit();
|
|
||||||
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
|
|
||||||
bufferedWriter.write(command.getData());
|
|
||||||
bufferedWriter.close();
|
|
||||||
String cmd = String.format("irtoy -d COM3 -f %s -p -a 0", file.getAbsoluteFile());
|
|
||||||
System.out.println(cmd);
|
|
||||||
Process process = Runtime.getRuntime().exec(cmd);
|
|
||||||
process.waitFor();
|
|
||||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
||||||
process.getOutputStream().write(byteArrayOutputStream.toByteArray());
|
|
||||||
System.out.println(byteArrayOutputStream.toString());
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static final String TITLE = "iPod";
|
|
||||||
protected static final boolean QUIT = true;
|
|
||||||
|
|
||||||
protected static final int VOLUME_SLEEP = 100;
|
|
||||||
|
|
||||||
protected LircService lircService;
|
|
||||||
protected VolumeWorker volumeWorker;
|
|
||||||
|
|
||||||
public iPodApplication() {
|
|
||||||
super(TITLE);
|
|
||||||
lircService = new LircService();
|
|
||||||
lircService.put(WC02IPOButton.NAME, WC02IPOButton.values());
|
|
||||||
volumeWorker = new VolumeWorker();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void activate() throws ActivateException {
|
|
||||||
lircService.activate();
|
|
||||||
super.activate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean active() {
|
|
||||||
return active = lircService.active();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deactivate() throws DeactivateException {
|
|
||||||
super.deactivate();
|
|
||||||
lircService.deactivate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
|
||||||
super.stop();
|
|
||||||
volumeWorker.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void begin(Action action) {
|
|
||||||
log.trace("iPodApplication begin: " + action);
|
|
||||||
if (!active) return;
|
|
||||||
switch (action) {
|
|
||||||
case VOLUME_UP:
|
|
||||||
try {
|
|
||||||
volumeWorker.activate(1);
|
|
||||||
} catch (ActivateException e) {
|
|
||||||
log.error(e);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VOLUME_DOWN:
|
|
||||||
try {
|
|
||||||
volumeWorker.activate(-1);
|
|
||||||
} catch (ActivateException e) {
|
|
||||||
log.error(e);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void end(Action action) {
|
|
||||||
log.trace("iPodApplication end: " + action);
|
|
||||||
if (!active) return;
|
|
||||||
switch (action) {
|
|
||||||
case PLAY:
|
|
||||||
lircService.send(WC02IPOButton.PLAY);
|
|
||||||
break;
|
|
||||||
case NEXT:
|
|
||||||
lircService.send(WC02IPOButton.NEXT);
|
|
||||||
break;
|
|
||||||
case PREVIOUS:
|
|
||||||
lircService.send(WC02IPOButton.PREVIOUS);
|
|
||||||
break;
|
|
||||||
case VOLUME_UP:
|
|
||||||
case VOLUME_DOWN:
|
|
||||||
try {
|
|
||||||
volumeWorker.deactivate();
|
|
||||||
} catch (DeactivateException e) {
|
|
||||||
log.error(e);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class VolumeWorker extends Worker {
|
|
||||||
protected int volumeChangeRate;
|
|
||||||
|
|
||||||
public void activate(int volumeChangeRate) throws ActivateException {
|
|
||||||
super.activate();
|
|
||||||
this.volumeChangeRate = volumeChangeRate;
|
|
||||||
lircService.send(volumeChangeRate > 0 ? WC02IPOButton.PLUS : WC02IPOButton.MINUS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void work() {
|
|
||||||
lircService.send(WC02IPOButton.HOLD);
|
|
||||||
sleep(VOLUME_SLEEP);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
36
java/src/mimis/application/lirc/LircApplication.java
Normal file
36
java/src/mimis/application/lirc/LircApplication.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package mimis.application.lirc;
|
||||||
|
|
||||||
|
import mimis.Application;
|
||||||
|
import mimis.device.lirc.LircButton;
|
||||||
|
import mimis.device.lirc.LircService;
|
||||||
|
import mimis.device.lirc.remote.WC02IPOButton;
|
||||||
|
import mimis.exception.worker.ActivateException;
|
||||||
|
import mimis.exception.worker.DeactivateException;
|
||||||
|
|
||||||
|
public class LircApplication extends Application {
|
||||||
|
protected LircService lircService;
|
||||||
|
|
||||||
|
public LircApplication(String title) {
|
||||||
|
super(title);
|
||||||
|
lircService = new LircService();
|
||||||
|
lircService.put(WC02IPOButton.NAME, WC02IPOButton.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void activate() throws ActivateException {
|
||||||
|
lircService.activate();
|
||||||
|
super.activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean active() {
|
||||||
|
return active = lircService.active();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deactivate() throws DeactivateException {
|
||||||
|
super.deactivate();
|
||||||
|
lircService.deactivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(LircButton button) {
|
||||||
|
lircService.send(button);
|
||||||
|
}
|
||||||
|
}
|
||||||
85
java/src/mimis/application/lirc/ipod/iPodApplication.java
Normal file
85
java/src/mimis/application/lirc/ipod/iPodApplication.java
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package mimis.application.lirc.ipod;
|
||||||
|
|
||||||
|
import mimis.Worker;
|
||||||
|
import mimis.application.lirc.LircApplication;
|
||||||
|
import mimis.device.lirc.remote.WC02IPOButton;
|
||||||
|
import mimis.exception.worker.ActivateException;
|
||||||
|
import mimis.exception.worker.DeactivateException;
|
||||||
|
import mimis.value.Action;
|
||||||
|
|
||||||
|
public class iPodApplication extends LircApplication {
|
||||||
|
protected static final String TITLE = "iPod";
|
||||||
|
protected static final int VOLUME_SLEEP = 100;
|
||||||
|
|
||||||
|
protected VolumeWorker volumeWorker;
|
||||||
|
|
||||||
|
public iPodApplication() {
|
||||||
|
super(TITLE);
|
||||||
|
volumeWorker = new VolumeWorker();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
super.stop();
|
||||||
|
volumeWorker.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void begin(Action action) {
|
||||||
|
log.trace("iPodApplication begin: " + action);
|
||||||
|
if (!active) return;
|
||||||
|
switch (action) {
|
||||||
|
case VOLUME_UP:
|
||||||
|
try {
|
||||||
|
volumeWorker.activate(1);
|
||||||
|
} catch (ActivateException e) {
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VOLUME_DOWN:
|
||||||
|
try {
|
||||||
|
volumeWorker.activate(-1);
|
||||||
|
} catch (ActivateException e) {
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void end(Action action) {
|
||||||
|
log.trace("iPodApplication end: " + action);
|
||||||
|
if (!active) return;
|
||||||
|
switch (action) {
|
||||||
|
case PLAY:
|
||||||
|
send(WC02IPOButton.PLAY);
|
||||||
|
break;
|
||||||
|
case NEXT:
|
||||||
|
send(WC02IPOButton.NEXT);
|
||||||
|
break;
|
||||||
|
case PREVIOUS:
|
||||||
|
send(WC02IPOButton.PREVIOUS);
|
||||||
|
break;
|
||||||
|
case VOLUME_UP:
|
||||||
|
case VOLUME_DOWN:
|
||||||
|
try {
|
||||||
|
volumeWorker.deactivate();
|
||||||
|
} catch (DeactivateException e) {
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected class VolumeWorker extends Worker {
|
||||||
|
protected int volumeChangeRate;
|
||||||
|
|
||||||
|
public void activate(int volumeChangeRate) throws ActivateException {
|
||||||
|
super.activate();
|
||||||
|
this.volumeChangeRate = volumeChangeRate;
|
||||||
|
send(volumeChangeRate > 0 ? WC02IPOButton.PLUS : WC02IPOButton.MINUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void work() {
|
||||||
|
lircService.send(WC02IPOButton.HOLD);
|
||||||
|
sleep(VOLUME_SLEEP);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -53,6 +53,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
|
|
||||||
/* Worker */
|
/* Worker */
|
||||||
public void activate() throws ActivateException {
|
public void activate() throws ActivateException {
|
||||||
|
add(eventMapCycle.player);
|
||||||
connect();
|
connect();
|
||||||
try {
|
try {
|
||||||
wiimote = wiimoteService.getDevice(this);
|
wiimote = wiimoteService.getDevice(this);
|
||||||
@@ -61,7 +62,7 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
log.error(e);
|
log.error(e);
|
||||||
throw new ActivateException();
|
throw new ActivateException();
|
||||||
}
|
}
|
||||||
add(eventMapCycle.player);
|
|
||||||
super.activate();
|
super.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,13 +111,13 @@ public class WiimoteDevice extends Device implements GestureListener {
|
|||||||
switch (action) {
|
switch (action) {
|
||||||
case SHIFT:
|
case SHIFT:
|
||||||
log.debug("Shift");
|
log.debug("Shift");
|
||||||
reset();
|
/*reset();
|
||||||
add(eventMapCycle.mimis);
|
add(eventMapCycle.mimis);
|
||||||
add(eventMapCycle.like);
|
add(eventMapCycle.like);*/
|
||||||
break;
|
break;
|
||||||
case UNSHIFT:
|
case UNSHIFT:
|
||||||
log.debug("Unshift");
|
log.debug("Unshift");
|
||||||
reset();
|
//reset();
|
||||||
add(eventMapCycle.player);
|
add(eventMapCycle.player);
|
||||||
break;
|
break;
|
||||||
case TRAIN:
|
case TRAIN:
|
||||||
|
|||||||
Reference in New Issue
Block a user