EventMaps van LircDevice gedeeltelijk toegevoegd. In WiimoteDevice SHIFT mechanisme toegepast. iTunes uitgeprobeerd: mechanisme verzinnen om in thread bepaalde taak te draaien!

This commit is contained in:
2011-06-08 14:19:55 +00:00
parent 7589708783
commit 3bebd1897d
32 changed files with 305 additions and 238 deletions

View File

@@ -4,7 +4,6 @@ import java.awt.GridLayout;
import java.awt.TextArea;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

View File

@@ -7,7 +7,7 @@ import java.util.Map;
import javax.swing.JToggleButton;
import mimis.manager.Exitable;
import mimis.manager.SelectButton;
import mimis.manager.ManageButton;
import mimis.manager.Titled;
import org.apache.commons.logging.Log;
@@ -19,7 +19,7 @@ public class Manager<T extends Worker & Titled & Exitable> extends Worker {
protected static final int INTERVAL = 500;
protected T[] manageableArray;
protected Map<T, SelectButton<T>> buttonMap;
protected Map<T, ManageButton<T>> buttonMap;
public Manager(T[] manageableArray) {
this.manageableArray = manageableArray;
@@ -34,9 +34,9 @@ public class Manager<T extends Worker & Titled & Exitable> extends Worker {
}
protected void createButtons() {
buttonMap = new HashMap<T, SelectButton<T>>();
buttonMap = new HashMap<T, ManageButton<T>>();
for (T manageable : manageableArray) {
SelectButton<T> button = new SelectButton<T>(manageable);
ManageButton<T> button = new ManageButton<T>(manageable);
buttonMap.put(manageable, button);
}
}
@@ -49,7 +49,7 @@ public class Manager<T extends Worker & Titled & Exitable> extends Worker {
long before = Calendar.getInstance().getTimeInMillis();
for (T manageable : manageableArray) {
boolean active = manageable.active();
SelectButton<T> button = buttonMap.get(manageable);
ManageButton<T> button = buttonMap.get(manageable);
button.setPressed(active);
}
long after = Calendar.getInstance().getTimeInMillis();

View File

@@ -13,12 +13,14 @@ import com.dt.iTunesController.iTunesEventsInterface;
public class iTunesApplication extends Application implements iTunesEventsInterface {
protected static final String TITLE = "iTunes";
protected static final int POSTION_CHANGE_RATE = 1;
protected static final boolean QUIT = false;
protected static final int VOLUME_CHANGE_RATE = 5;
protected static final int VOLUME_SLEEP = 500;
protected static final String PLAYLIST_LIKE = "Like";
protected static final String PLAYLIST_DISLIKE = "Dislike";
protected iTunes iTunes;
protected boolean volume;
public iTunesApplication() {
super(TITLE);
@@ -45,8 +47,10 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
public void deactivate() throws DeactivateException {
try {
synchronized (iTunes) {
iTunes.quit();
if (QUIT) {
synchronized (iTunes) {
iTunes.quit();
}
}
} catch (Exception e) {
throw new DeactivateException();
@@ -56,7 +60,7 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
}
protected void begin(Action action) {
log.trace("iTunesApplication: " + action);
log.trace("iTunesApplication begin: " + action);
if (!active) return;
switch (action) {
case FORWARD:
@@ -65,11 +69,17 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
case REWIND:
iTunes.rewind();
break;
case VOLUME_UP:
volume(true);
break;
case VOLUME_DOWN:
volume(false);
break;
}
}
protected void end(Action action) {
log.trace("iTunesApplication: " + action);
log.trace("iTunesApplication end: " + action);
if (!active) return;
switch (action) {
case PLAY:
@@ -82,27 +92,23 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
iTunes.previousTrack();
break;
case FORWARD:
iTunes.play();
iTunes.resume();
break;
case REWIND:
iTunes.play();
iTunes.resume();
break;
case MUTE:
iTunes.toggleMute();
break;
case VOLUME_UP:
iTunes.setSoundVolume(getVolume() + VOLUME_CHANGE_RATE);
break;
case VOLUME_DOWN:
iTunes.setSoundVolume(getVolume() - VOLUME_CHANGE_RATE);
volume = false;
break;
case SHUFFLE:
iTunes.toggleShuffle();
//iTunes.fastForward();
break;
case REPEAT:
iTunes.cycleSongRepeat();
//iTunes.resume();
break;
case LIKE:
iTunes.playlistAddCurrentTrack(PLAYLIST_LIKE);
@@ -113,6 +119,15 @@ public class iTunesApplication extends Application implements iTunesEventsInterf
}
}
protected void volume(boolean up) {
volume = true;
while (volume) {
int change = (up ? 1 : -1) * VOLUME_CHANGE_RATE;
iTunes.setSoundVolume(getVolume() + change);
sleep(VOLUME_SLEEP);
}
}
protected int getVolume() {
return iTunes.getSoundVolume();
}

View File

@@ -5,18 +5,18 @@ import mimis.exception.button.UnknownButtonException;
import de.hardcode.jxinput.event.JXInputButtonEvent;
public enum Extreme3DButton implements Button {
ONE ("SelectButton 0"),
TWO ("SelectButton 1"),
THREE ("SelectButton 2"),
FOUR ("SelectButton 3"),
FIVE ("SelectButton 4"),
SIX ("SelectButton 5"),
SEVEN ("SelectButton 6"),
EIGHT ("SelectButton 7"),
NINE ("SelectButton 8"),
TEN ("SelectButton 9"),
ELEVEN ("SelectButton 10"),
TWELVE ("SelectButton 11");
ONE ("ManageButton 0"),
TWO ("ManageButton 1"),
THREE ("ManageButton 2"),
FOUR ("ManageButton 3"),
FIVE ("ManageButton 4"),
SIX ("ManageButton 5"),
SEVEN ("ManageButton 6"),
EIGHT ("ManageButton 7"),
NINE ("ManageButton 8"),
TEN ("ManageButton 9"),
ELEVEN ("ManageButton 10"),
TWELVE ("ManageButton 11");
protected String code;

View File

@@ -3,7 +3,6 @@ package mimis.device.jintellitype;
import mimis.device.EventMapCycle;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.sequence.state.Press;
import mimis.value.Action;
import mimis.value.Key;
import mimis.value.Target;
@@ -26,10 +25,10 @@ public class JIntellitypeEventMapCycle extends EventMapCycle {
/* Player */
player = new EventMap();
player.add(
new Press(CommandButton.VOLUME_DOWN),
CommandButton.VOLUME_DOWN,
new Task(Target.APPLICATIONS, Action.VOLUME_DOWN));
player.add(
new Press(CommandButton.VOLUME_UP),
CommandButton.VOLUME_UP,
new Task(Target.APPLICATIONS, Action.VOLUME_UP));
player.add(
new Hotkey(Modifier.CTRL | Modifier.WIN, 'x'),

View File

@@ -4,8 +4,8 @@ import java.util.HashMap;
import mimis.Button;
import mimis.Device;
import mimis.device.lirc.button.DenonRC176;
import mimis.device.lirc.button.PhiliphsRCLE011Button;
import mimis.device.lirc.remote.DenonRC176Button;
import mimis.device.lirc.remote.PhiliphsRCLE011Button;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
import mimis.sequence.state.Press;
@@ -19,30 +19,37 @@ public class LircDevice extends Device implements LircButtonListener, SignalList
protected Multiplexer multiplexer;
protected LircService lircService;
protected LircEventMapCycle eventMapCycle;
public LircDevice() {
super(TITLE);
/* Initialise remotes */
HashMap<String, LircButton[]> buttonMap = new HashMap<String, LircButton[]>();
buttonMap.put(PhiliphsRCLE011Button.NAME, PhiliphsRCLE011Button.values());
buttonMap.put(DenonRC176.NAME, DenonRC176.values());
buttonMap.put(DenonRC176Button.NAME, DenonRC176Button.values());
buttonMap.put(DenonRC176Button.NAME, DenonRC176Button.values());
multiplexer = new Multiplexer(this);
lircService = new LircService(buttonMap);
lircService.add(this);
eventMapCycle = new LircEventMapCycle();
}
public void activate() throws ActivateException {
super.activate();
multiplexer.start();
lircService.activate();
super.activate();
add(eventMapCycle.denonRC176);
add(eventMapCycle.philiphsRCLE011);
add(eventMapCycle.samsungBN5901015A);
}
public void deactivate() throws DeactivateException {
super.deactivate();
multiplexer.deactivate();
lircService.deactivate();
super.deactivate();
}
public void add(LircButton lircButton) {

View File

@@ -0,0 +1,33 @@
package mimis.device.lirc;
import mimis.device.EventMapCycle;
import mimis.device.lirc.remote.DenonRC176EventMap;
import mimis.device.lirc.remote.PhiliphsRCLE011EventMap;
import mimis.device.lirc.remote.SamsungBN5901015AEventMap;
import mimis.sequence.EventMap;
public class LircEventMapCycle extends EventMapCycle {
protected static final long serialVersionUID = 1L;
public EventMap denonRC176, philiphsRCLE011, samsungBN5901015A;
public LircEventMapCycle() {
add(denonRC176 = new DenonRC176EventMap());
add(philiphsRCLE011 = new PhiliphsRCLE011EventMap());
add(samsungBN5901015A = new SamsungBN5901015AEventMap());
/*
player = new EventMap();
player.add(PanelButton.PREVIOUS, new Task(Target.APPLICATION, Action.PREVIOUS));
player.add(PanelButton.REWIND, new Task(Target.APPLICATION, Action.REWIND));
player.add(PanelButton.STOP, new Task(Target.APPLICATION, Action.STOP));
player.add(PanelButton.PAUSE, new Task(Target.APPLICATION, Action.PAUSE));
player.add(PanelButton.PLAY, new Task(Target.APPLICATION, Action.PLAY));
player.add(PanelButton.FORWARD, new Task(Target.APPLICATION, Action.FORWARD));
player.add(PanelButton.NEXT, new Task(Target.APPLICATION, Action.NEXT));
player.add(PanelButton.VOLUME_DOWN, new Task(Target.APPLICATION, Action.VOLUME_DOWN));
player.add(PanelButton.MUTE, new Task(Target.APPLICATION, Action.MUTE));
player.add(PanelButton.VOLUME_UP, new Task(Target.APPLICATION, Action.VOLUME_UP));
player.add(PanelButton.REPEAT, new Task(Target.APPLICATION, Action.REPEAT));
player.add(PanelButton.SHUFFLE, new Task(Target.APPLICATION, Action.SHUFFLE));
add(player);*/
}
}

View File

@@ -11,9 +11,10 @@ import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Scanner;
import mimis.Worker;
import mimis.device.lirc.button.PhiliphsRCLE011Button;
import mimis.exception.button.UnknownButtonException;
import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
@@ -64,10 +65,10 @@ public class LircService extends Worker {
outputStream = socket.getOutputStream();
printWriter = new PrintWriter(outputStream);
} catch (UnknownHostException e) {
log.info(e);
log.error(e);
throw new ActivateException();
} catch (IOException e) {
log.info(e);
log.error(e);
throw new ActivateException();
}
super.activate();
@@ -87,20 +88,13 @@ public class LircService extends Worker {
}
public void work() {
log.debug("wrk");
try {
String string;
//synchronized (this) {
string = bufferedReader.readLine();
//}
String string = bufferedReader.readLine();
try {
System.out.println(string);
LircButton lircButton = parseButton(new Scanner(string));
log.trace("LircButton: " + lircButton);
for (LircButtonListener lircbuttonListener : lircButtonListenerList) {
lircbuttonListener.add(lircButton);
}
log.info(send(PhiliphsRCLE011Button.MUTE));
} catch (UnknownButtonException e) {
log.error(e);
}
@@ -126,6 +120,8 @@ public class LircService extends Worker {
}
} catch (InputMismatchException e) {
log.error(e);
} catch (NoSuchElementException e) {
log.error(e);
}
throw new UnknownButtonException();
}
@@ -142,17 +138,15 @@ public class LircService extends Worker {
log.debug(command);
printWriter.append(command);
printWriter.flush();
//synchronized (this) {
try {
bufferedReader.readLine();
bufferedReader.readLine();
String result = bufferedReader.readLine();
bufferedReader.readLine();
return result.equals("SUCCESS");
} catch (IOException e) {
log.error(e);
}
return false;
//}
try {
bufferedReader.readLine();
bufferedReader.readLine();
String result = bufferedReader.readLine();
bufferedReader.readLine();
return result.equals("SUCCESS");
} catch (IOException e) {
log.error(e);
}
return false;
}
}

View File

@@ -1,8 +1,8 @@
package mimis.device.lirc.button;
package mimis.device.lirc.remote;
import mimis.device.lirc.LircButton;
public enum DenonRC176 implements LircButton {
public enum DenonRC176Button implements LircButton {
TAPE_AB ("TAPE_AB"),
TAPE_REC ("TAPE_REC"),
TAPE_PAUSE ("TAPE_PAUSE"),
@@ -36,7 +36,7 @@ public enum DenonRC176 implements LircButton {
protected String code;
private DenonRC176(String code) {
private DenonRC176Button(String code) {
this.code = code;
}

View File

@@ -0,0 +1,14 @@
package mimis.device.lirc.remote;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.value.Action;
import mimis.value.Target;
public class DenonRC176EventMap extends EventMap {
protected static final long serialVersionUID = 1L;
public DenonRC176EventMap() {
add(DenonRC176Button.AMP_VOLUME_UP, new Task(Target.APPLICATION, Action.VOLUME_UP));
}
}

View File

@@ -1,4 +1,4 @@
package mimis.device.lirc.button;
package mimis.device.lirc.remote;
import mimis.device.lirc.LircButton;
@@ -21,7 +21,7 @@ public enum PhiliphsRCLE011Button implements LircButton {
VOLUME_DOWN ("Volume-"),
MUTE ("Mute"),
PROGRAM_UP ("Program+"),
PROGRUM_DOWN ("Program-"),
PROGRAM_DOWN ("Program-"),
ONE ("1"),
TWO ("2"),
THREE ("3"),

View File

@@ -0,0 +1,30 @@
package mimis.device.lirc.remote;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.value.Action;
import mimis.value.Target;
public class PhiliphsRCLE011EventMap extends EventMap {
protected static final long serialVersionUID = 1L;
public PhiliphsRCLE011EventMap() {
/* Mimis */
add(PhiliphsRCLE011Button.UP, new Task(Target.MIMIS, Action.NEXT));
add(PhiliphsRCLE011Button.DOWN, new Task(Target.MIMIS, Action.PREVIOUS));
/* Application */
add(PhiliphsRCLE011Button.POWER, new Task(Target.APPLICATION, Action.ACTIVATE));
add(PhiliphsRCLE011Button.PROGRAM_UP, new Task(Target.APPLICATION, Action.NEXT));
add(PhiliphsRCLE011Button.PROGRAM_DOWN, new Task(Target.APPLICATION, Action.PREVIOUS));
add(PhiliphsRCLE011Button.LEFT, new Task(Target.APPLICATION, Action.REWIND));
add(PhiliphsRCLE011Button.TUNE, new Task(Target.APPLICATION, Action.PAUSE));
add(PhiliphsRCLE011Button.RIGHT, new Task(Target.APPLICATION, Action.FORWARD));
add(PhiliphsRCLE011Button.VOLUME_DOWN, new Task(Target.APPLICATION, Action.VOLUME_DOWN));
add(PhiliphsRCLE011Button.MUTE, new Task(Target.APPLICATION, Action.MUTE));
add(PhiliphsRCLE011Button.VOLUME_UP, new Task(Target.APPLICATION, Action.VOLUME_UP));
add(PhiliphsRCLE011Button.VOLUME_UP, new Task(Target.APPLICATION, Action.VOLUME_UP));
add(PhiliphsRCLE011Button.CLOCK, new Task(Target.APPLICATION, Action.REPEAT));
add(PhiliphsRCLE011Button.OUT, new Task(Target.APPLICATION, Action.SHUFFLE));
}
}

View File

@@ -1,4 +1,4 @@
package mimis.device.lirc.button;
package mimis.device.lirc.remote;
import mimis.device.lirc.LircButton;

View File

@@ -0,0 +1,14 @@
package mimis.device.lirc.remote;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.value.Action;
import mimis.value.Target;
public class SamsungBN5901015AEventMap extends EventMap {
protected static final long serialVersionUID = 1L;
public SamsungBN5901015AEventMap() {
add(SamsungBN5901015AButton.VOLUME_UP, new Task(Target.APPLICATION, Action.VOLUME_UP));
}
}

View File

@@ -17,10 +17,6 @@ public class Panel extends JFrame implements HoldButtonListener {
protected PanelButtonListener panelButtonListener;
protected ClassLoader classLoader;
//protected JTextArea feedbackArea;
//protected JScrollPane scrollPane;
protected HoldButton previousButton;
protected HoldButton rewindButton;
protected HoldButton stopButton;
@@ -72,7 +68,7 @@ public class Panel extends JFrame implements HoldButtonListener {
protected void createControls() {
previousButton = getButton("icons/previous.png", "Go to previous track");
rewindButton = getButton("icons/rewind.png", "Skip backward");
playPauseToggleButton = getToggleButton("icons/play.png", "icons/pause.png", "Play/pause");//getButton("icons/play.png", "Play/pause");
playPauseToggleButton = getToggleButton("icons/play.png", "icons/pause.png", "Play/pause");
forwardButton = getButton("icons/forward.png", "Skip forward");
nextButton = getButton("icons/next.png", "Go to next track");
volumeDownButton = getButton("icons/volumeDown.png", "Decrease volume");
@@ -160,15 +156,4 @@ public class Panel extends JFrame implements HoldButtonListener {
panelButtonListener.buttonReleased(PanelButton.SHUFFLE);
}
}
/* Feedback */
/*public void addFeedback(String format, Object... args) {
feedbackArea.append(String.format(format, args));
JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
scrollBar.setValue(scrollBar.getMaximum());
}
public void clearFeedback() {
feedbackArea.setText("");
}*/
}

View File

@@ -5,20 +5,18 @@ import java.awt.event.WindowEvent;
import javax.swing.WindowConstants;
import mimis.Device;
import mimis.event.Task;
import mimis.exception.worker.ActivateException;
import mimis.sequence.state.Press;
import mimis.sequence.state.Release;
import mimis.value.Action;
import mimis.value.Target;
public class PanelDevice extends Device implements PanelButtonListener {
protected static final String TITLE = "Panel";
protected Panel panel;
protected PanelEventMapCycle eventMapCycle;
public PanelDevice() {
super(TITLE);
eventMapCycle = new PanelEventMapCycle();
}
public void activate() throws ActivateException {
@@ -33,20 +31,7 @@ public class PanelDevice extends Device implements PanelButtonListener {
}
};
panel.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
//panel.updateTime(12342398);
//panel.updatePosition(43);
add(new Press(PanelButton.PREVIOUS), new Task(Target.APPLICATION, Action.PREVIOUS));
add(new Press(PanelButton.REWIND), new Task(Target.APPLICATION, Action.REWIND));
add(new Press(PanelButton.STOP), new Task(Target.APPLICATION, Action.STOP));
add(new Press(PanelButton.PAUSE), new Task(Target.APPLICATION, Action.PAUSE));
add(new Press(PanelButton.PLAY), new Task(Target.APPLICATION, Action.PLAY));
add(new Press(PanelButton.FORWARD), new Task(Target.APPLICATION, Action.FORWARD));
add(new Press(PanelButton.NEXT), new Task(Target.APPLICATION, Action.NEXT));
add(new Press(PanelButton.VOLUME_DOWN), new Task(Target.APPLICATION, Action.VOLUME_DOWN));
add(new Press(PanelButton.MUTE), new Task(Target.APPLICATION, Action.MUTE));
add(new Press(PanelButton.VOLUME_UP), new Task(Target.APPLICATION, Action.VOLUME_UP));
add(new Press(PanelButton.REPEAT), new Task(Target.APPLICATION, Action.REPEAT));
add(new Press(PanelButton.SHUFFLE), new Task(Target.APPLICATION, Action.SHUFFLE));
add(eventMapCycle.player);
}
public boolean active() {
@@ -65,7 +50,6 @@ public class PanelDevice extends Device implements PanelButtonListener {
}
public void buttonPressed(PanelButton panelButton) {
//Vang hier toggles af om bijvoorbeeld de play/pause en mute knop en veranderen
add(new Press(panelButton));
}

View File

@@ -0,0 +1,31 @@
package mimis.device.panel;
import mimis.device.EventMapCycle;
import mimis.event.Task;
import mimis.sequence.EventMap;
import mimis.sequence.state.Press;
import mimis.value.Action;
import mimis.value.Target;
public class PanelEventMapCycle extends EventMapCycle {
protected static final long serialVersionUID = 1L;
public EventMap player;
public PanelEventMapCycle() {
/* Player */
player = new EventMap();
player.add(new Press(PanelButton.PREVIOUS), new Task(Target.APPLICATION, Action.PREVIOUS));
player.add(new Press(PanelButton.REWIND), new Task(Target.APPLICATION, Action.REWIND));
player.add(new Press(PanelButton.STOP), new Task(Target.APPLICATION, Action.STOP));
player.add(new Press(PanelButton.PAUSE), new Task(Target.APPLICATION, Action.PAUSE));
player.add(new Press(PanelButton.PLAY), new Task(Target.APPLICATION, Action.PLAY));
player.add(new Press(PanelButton.FORWARD), new Task(Target.APPLICATION, Action.FORWARD));
player.add(new Press(PanelButton.NEXT), new Task(Target.APPLICATION, Action.NEXT));
player.add(new Press(PanelButton.VOLUME_DOWN), new Task(Target.APPLICATION, Action.VOLUME_DOWN));
player.add(new Press(PanelButton.MUTE), new Task(Target.APPLICATION, Action.MUTE));
player.add(new Press(PanelButton.VOLUME_UP), new Task(Target.APPLICATION, Action.VOLUME_UP));
player.add(new Press(PanelButton.REPEAT), new Task(Target.APPLICATION, Action.REPEAT));
player.add(new Press(PanelButton.SHUFFLE), new Task(Target.APPLICATION, Action.SHUFFLE));
add(player);
}
}

View File

@@ -21,7 +21,7 @@ import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
public class WiimoteDevice extends Device implements GestureListener {
protected static final String TITLE = "Wiimote";
protected static final int RUMBLE = 150;
protected static final int RUMBLE = 50;
protected static final int TIMEOUT = 200;
protected static WiimoteService wiimoteService;
@@ -50,11 +50,9 @@ public class WiimoteDevice extends Device implements GestureListener {
public void activate() throws ActivateException {
super.activate();
connect();
add(eventMapCycle.mimis);
add(eventMapCycle.player);
add(eventMapCycle.like);
}
public boolean active() {
if (wiimote != null) {
connected = false;
@@ -90,6 +88,17 @@ public class WiimoteDevice extends Device implements GestureListener {
/* Events */
public void begin(Action action) {
switch (action) {
case SHIFT:
log.debug("Shift");
reset();
add(eventMapCycle.mimis);
add(eventMapCycle.like);
break;
case UNSHIFT:
log.debug("Unshift");
reset();
add(eventMapCycle.player);
break;
case TRAIN:
log.debug("Gesture train");
gestureDevice.train();
@@ -112,7 +121,7 @@ public class WiimoteDevice extends Device implements GestureListener {
break;
}
}
public void end(Action action) {
switch (action) {
case TRAIN:
@@ -141,7 +150,6 @@ public class WiimoteDevice extends Device implements GestureListener {
public void connected() {
try {
wiimote = wiimoteService.getDevice(this);
//wiimote.activateMotionSensing();
try {
wiimoteDiscovery.deactivate();
} catch (DeactivateException e) {

View File

@@ -1,96 +1,50 @@
package mimis.device.wiimote;
import mimis.Macro;
import mimis.device.EventMapCycle;
import mimis.event.Task;
import mimis.exception.macro.StateOrderException;
import mimis.sequence.EventMap;
import mimis.sequence.state.Hold;
import mimis.sequence.state.Press;
import mimis.sequence.state.Release;
import mimis.value.Action;
import mimis.value.Target;
import mimis.sequence.state.Release;
public class WiimoteEventMapCycle extends EventMapCycle {
protected static final long serialVersionUID = 1L;
public EventMap mimis, player, gesture, like;
public EventMap mimis, player, gesture, like, shift;
public WiimoteEventMapCycle() {
/* Mimis */
mimis = new EventMap();
mimis.add(
new Press(WiimoteButton.HOME),
new Task(Target.MIMIS, Action.NEXT));
mimis.add(WiimoteButton.HOME, new Task(Target.MIMIS, Action.NEXT));
mimis.add(new Release(WiimoteButton.B), new Task(Target.SELF, Action.UNSHIFT));
/* Gesture */
gesture = new EventMap();
gesture.add(
new Press(WiimoteButton.A),
new Task(Action.TRAIN));
gesture.add(
new Press(WiimoteButton.B),
new Task(Action.SAVE));
gesture.add(
new Press(WiimoteButton.DOWN),
new Task(Action.LOAD));
gesture.add(
new Press(WiimoteButton.HOME),
new Task(Action.RECOGNIZE));
gesture.add(WiimoteButton.A, new Task(Action.TRAIN));
gesture.add(WiimoteButton.B, new Task(Action.SAVE));
gesture.add(WiimoteButton.DOWN, new Task(Action.LOAD));
gesture.add(WiimoteButton.HOME, new Task(Action.RECOGNIZE));
add(gesture);
/* Player */
player = new EventMap();
player.add(
new Press(WiimoteButton.A),
new Task(Target.APPLICATION, Action.PLAY));
player.add(
new Press(WiimoteButton.B),
new Task(Target.APPLICATION, Action.MUTE));
player.add(
new Press(WiimoteButton.ONE),
new Task(Target.APPLICATION, Action.SHUFFLE));
player.add(
new Press(WiimoteButton.TWO),
new Task(Target.APPLICATION, Action.REPEAT));
player.add(
new Press(WiimoteButton.UP),
new Task(Target.APPLICATION, Action.NEXT));
player.add(
new Press(WiimoteButton.DOWN),
new Task(Target.APPLICATION, Action.PREVIOUS));
player.add(
new Press(WiimoteButton.RIGHT),
new Task(Target.APPLICATION, Action.FORWARD));
player.add(
new Press(WiimoteButton.LEFT),
new Task(Target.APPLICATION, Action.REWIND));
player.add(
new Press(WiimoteButton.MINUS),
new Task(Target.APPLICATION, Action.VOLUME_DOWN));
player.add(
new Press(WiimoteButton.PLUS),
new Task(Target.APPLICATION, Action.VOLUME_UP));
player.add(WiimoteButton.A, new Task(Target.APPLICATION, Action.PLAY));
player.add(WiimoteButton.B, new Task(Target.SELF, Action.SHIFT));
player.add(WiimoteButton.HOME, new Task(Target.APPLICATION, Action.MUTE));
player.add(WiimoteButton.ONE, new Task(Target.APPLICATION, Action.SHUFFLE));
player.add(WiimoteButton.TWO, new Task(Target.APPLICATION, Action.REPEAT));
player.add(WiimoteButton.UP, new Task(Target.APPLICATION, Action.NEXT));
player.add(WiimoteButton.DOWN, new Task(Target.APPLICATION, Action.PREVIOUS));
player.add(WiimoteButton.RIGHT, new Task(Target.APPLICATION, Action.FORWARD));
player.add(WiimoteButton.LEFT, new Task(Target.APPLICATION, Action.REWIND));
player.add(WiimoteButton.MINUS, new Task(Target.APPLICATION, Action.VOLUME_DOWN));
player.add(WiimoteButton.PLUS, new Task(Target.APPLICATION, Action.VOLUME_UP));
add(player);
/* Like */
try {
like = new EventMap();
like.add(
new Macro(
new Hold(WiimoteButton.TWO),
new Press(WiimoteButton.PLUS),
new Release(WiimoteButton.TWO)),
new Task(Target.APPLICATION, Action.LIKE));
like.add(
new Macro(
new Hold(WiimoteButton.TWO),
new Press(WiimoteButton.MINUS),
new Release(WiimoteButton.TWO)),
new Task(Target.APPLICATION, Action.DISLIKE));
add(like);
} catch (StateOrderException e) {
log.error(e);
}
like = new EventMap();
like.add(WiimoteButton.PLUS, new Task(Target.APPLICATION, Action.LIKE));
like.add(WiimoteButton.MINUS, new Task(Target.APPLICATION, Action.DISLIKE));
add(like);
}
}

View File

@@ -17,8 +17,7 @@ public class LocalRouter extends EventRouter {
}
if (event instanceof Task) {
Task task = (Task) event;
add(new TextFeedback("Action: " + task.getAction()));
add(new TextFeedback(String.format("Action (%s): %s", task.getSignal(), task.getAction())));
}
break;
default:

View File

@@ -13,32 +13,32 @@ import mimis.exception.worker.DeactivateException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class SelectButton<T extends Worker & Titled> extends JToggleButton implements MouseListener {
public class ManageButton<T extends Worker & Titled> extends JToggleButton implements MouseListener {
protected Log log = LogFactory.getLog(getClass());
protected static final long serialVersionUID = 1L;
protected T activatable;
protected T manageable;
protected Action action;
public SelectButton(T activatable) {
this.activatable = activatable;
setText(activatable.title());
public ManageButton(T manageable) {
this.manageable = manageable;
setText(manageable.title());
setFocusable(false);
addMouseListener(this);
}
public void mouseClicked(MouseEvent event) {
if (activatable.active()) {
if (manageable.active()) {
try {
log.trace("Uit");
activatable.deactivate();
manageable.deactivate();
} catch (DeactivateException e) {
log.error(e);
}
} else {
try {
log.trace("Aan");
activatable.activate();
manageable.activate();
} catch (ActivateException e) {
log.error(e);
}
@@ -49,7 +49,7 @@ public class SelectButton<T extends Worker & Titled> extends JToggleButton imple
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void setPressed(boolean pressed) {
if (!isSelected() && pressed || isSelected() && !pressed) {
doClick();

View File

@@ -27,7 +27,7 @@ public class EventMap extends HashMap<Sequence, Event> {
}
}
protected void add(State state, Task task) {
public void add(State state, Task task) {
add(new Sequence(state), task);
}

View File

@@ -77,9 +77,10 @@ public class SequenceParser {
}
}
protected void add(Event event, Signal signal) {
protected synchronized void add(Event event, Signal signal) {
if (event instanceof Task) {
event = ((Task) event).setSignal(signal);
}
if (event.getTarget().equals(Target.SELF)) {
self.add(event);

View File

@@ -16,5 +16,5 @@ public enum Action {
VOLUME_DOWN,
VOLUME_UP,
FULLSCREEN,
TRAIN, STOP, SAVE, RECOGNIZE, LOAD, SHUFFLE, FADEOUT, QUIT, VISUALISER, LIKE, DISLIKE, ACTIVATE;
TRAIN, STOP, SAVE, RECOGNIZE, LOAD, SHUFFLE, FADEOUT, QUIT, VISUALISER, LIKE, DISLIKE, ACTIVATE, SHIFT, UNSHIFT;
}

View File

@@ -160,7 +160,7 @@ public class WiimoteWiigee extends Wiigee {
/**
* Sets the Trainbutton for all wiimotes;
*
* @param b SelectButton encoding, see static Wiimote values
* @param b ManageButton encoding, see static Wiimote values
*/
public void setTrainButton(int b) {
for (int i = 0; i < this.devices.size(); i++) {
@@ -171,7 +171,7 @@ public class WiimoteWiigee extends Wiigee {
/**
* Sets the Recognitionbutton for all wiimotes;
*
* @param b SelectButton encoding, see static Wiimote values
* @param b ManageButton encoding, see static Wiimote values
*/
public void setRecognitionButton(int b) {
for (int i = 0; i < this.devices.size(); i++) {
@@ -182,7 +182,7 @@ public class WiimoteWiigee extends Wiigee {
/**
* Sets the CloseGesturebutton for all wiimotes;
*
* @param b SelectButton encoding, see static Wiimote values
* @param b ManageButton encoding, see static Wiimote values
*/
public void setCloseGestureButton(int b) {
for (int i = 0; i < this.devices.size(); i++) {

View File

@@ -101,7 +101,7 @@ public class Device {
}
/**
* Adds a ButtonListener to the Device. Everytime a SelectButton has been
* Adds a ButtonListener to the Device. Everytime a ManageButton has been
* pressed or released, the Listener would be notified about this via
* the corresponding Events.
*

View File

@@ -81,7 +81,7 @@ public class WiimoteStreamer extends Thread {
if((b[1] & 0xFF) == 0x31) {
this.handleButtonData(new byte[] { b[2], b[3] });
this.handleAccelerationData(new byte[] { b[4], b[5], b[6] });
//Log.write("0x31: SelectButton + Acc");
//Log.write("0x31: ManageButton + Acc");
}
else if ((b[1] & 0xFF) == 0x33) {
this.handleButtonData(new byte[] { b[2], b[3] });
@@ -90,7 +90,7 @@ public class WiimoteStreamer extends Thread {
b[10], b[11], b[12],
b[13], b[14], b[15],
b[16], b[17], b[18]});
//Log.write("0x33: SelectButton + Acc + Irda");
//Log.write("0x33: ManageButton + Acc + Irda");
}
else if ((b[1] & 0xFF) == 0x37) {
this.handleButtonData(new byte[] { b[2], b[3] });
@@ -100,7 +100,7 @@ public class WiimoteStreamer extends Thread {
b[13], b[14], b[15], b[16]});
this.handleWiiMotionPlusData(
new byte[]{b[17], b[18], b[19], b[20], b[21], b[22]});
//Log.write("0x37: SelectButton + Acc + Ext");
//Log.write("0x37: ManageButton + Acc + Ext");
}
else if ((b[1] & 0xFF) == 0x21) {
this.handleButtonData(new byte[] { b[2], b[3] });

View File

@@ -55,7 +55,7 @@ public class ButtonPressedEvent extends ActionStartEvent {
/**
* Create a WiimoteButtonPressedEvent with the Wiimote source whose
* SelectButton has been pressed and the integer representation of the button.
* ManageButton has been pressed and the integer representation of the button.
*
* @param source
* @param button

View File

@@ -56,7 +56,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
super(id, buttonsJustPressed, buttonsJustReleased, buttonsHeld);
}
/* SelectButton LEFT */
/* ManageButton LEFT */
public boolean isButtonLeftJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_LEFT);
@@ -74,7 +74,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_LEFT);
}
/* SelectButton RIGHT */
/* ManageButton RIGHT */
public boolean isButtonRightJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_RIGHT);
@@ -92,7 +92,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_RIGHT);
}
/* SelectButton UP */
/* ManageButton UP */
public boolean isButtonUpJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_UP);
@@ -110,7 +110,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_UP);
}
/* SelectButton DOWN */
/* ManageButton DOWN */
public boolean isButtonDownJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_DOWN);
@@ -128,7 +128,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_DOWN);
}
/* SelectButton A */
/* ManageButton A */
public boolean isButtonAJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_A);
@@ -146,7 +146,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_A);
}
/* SelectButton B */
/* ManageButton B */
public boolean isButtonBJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_B);
@@ -164,7 +164,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_B);
}
/* SelectButton X */
/* ManageButton X */
public boolean isButtonXJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_X);
@@ -182,7 +182,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_X);
}
/* SelectButton Y */
/* ManageButton Y */
public boolean isButtonYJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_Y);
@@ -200,7 +200,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_Y);
}
/* SelectButton FullLeft */
/* ManageButton FullLeft */
public boolean isButtonFullLeftJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_FULL_L);
@@ -218,7 +218,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_FULL_L);
}
/* SelectButton FullRight */
/* ManageButton FullRight */
public boolean isButtonFullRightJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_FULL_R);
@@ -236,7 +236,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_FULL_R);
}
/* SelectButton Home */
/* ManageButton Home */
public boolean isButtonHomeJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_HOME);
@@ -254,7 +254,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_HOME);
}
/* SelectButton Minus */
/* ManageButton Minus */
public boolean isButtonMinusJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_MINUS);
@@ -272,7 +272,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_MINUS);
}
/* SelectButton Plus */
/* ManageButton Plus */
public boolean isButtonPlusJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_PLUS);
@@ -290,7 +290,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_PLUS);
}
/* SelectButton ZL */
/* ManageButton ZL */
public boolean isButtonZLJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_ZL);
@@ -308,7 +308,7 @@ public class ClassicControllerButtonsEvent extends ButtonsEvent{
return isButtonPressed(CLASSIC_CTRL_BUTTON_ZL);
}
/* SelectButton ZR */
/* ManageButton ZR */
public boolean isButtonZRJustPressed() {
return isButtonJustPressed(CLASSIC_CTRL_BUTTON_ZR);

View File

@@ -50,7 +50,7 @@ public class GuitarHeroButtonsEvent extends ButtonsEvent {
super(id, buttonsJustPressed, buttonsJustReleased, buttonsHeld);
}
/* SelectButton Strum Up */
/* ManageButton Strum Up */
public boolean isButtonStrumUpJustPressed() {
return isButtonJustPressed(GUITAR_HERO_3_BUTTON_STRUM_UP);
@@ -68,7 +68,7 @@ public class GuitarHeroButtonsEvent extends ButtonsEvent {
return isButtonPressed(GUITAR_HERO_3_BUTTON_STRUM_UP);
}
/* SelectButton Strum Down */
/* ManageButton Strum Down */
public boolean isButtonStrumDownJustPressed() {
return isButtonJustPressed(GUITAR_HERO_3_BUTTON_STRUM_DOWN);
@@ -86,7 +86,7 @@ public class GuitarHeroButtonsEvent extends ButtonsEvent {
return isButtonPressed(GUITAR_HERO_3_BUTTON_STRUM_DOWN);
}
/* SelectButton blue */
/* ManageButton blue */
public boolean isButtonBlueJustPressed() {
return isButtonJustPressed(GUITAR_HERO_3_BUTTON_BLUE);
@@ -104,7 +104,7 @@ public class GuitarHeroButtonsEvent extends ButtonsEvent {
return isButtonPressed(GUITAR_HERO_3_BUTTON_BLUE);
}
/* SelectButton Green */
/* ManageButton Green */
public boolean isButtonGreenJustPressed() {
return isButtonJustPressed(GUITAR_HERO_3_BUTTON_GREEN);
@@ -122,7 +122,7 @@ public class GuitarHeroButtonsEvent extends ButtonsEvent {
return isButtonPressed(GUITAR_HERO_3_BUTTON_GREEN);
}
/* SelectButton Minus */
/* ManageButton Minus */
public boolean isButtonMinusJustPressed() {
return isButtonJustPressed(GUITAR_HERO_3_BUTTON_MINUS);
@@ -140,7 +140,7 @@ public class GuitarHeroButtonsEvent extends ButtonsEvent {
return isButtonPressed(GUITAR_HERO_3_BUTTON_MINUS);
}
/* SelectButton Orange */
/* ManageButton Orange */
public boolean isButtonOrangeJustPressed() {
return isButtonJustPressed(GUITAR_HERO_3_BUTTON_ORANGE);
@@ -158,7 +158,7 @@ public class GuitarHeroButtonsEvent extends ButtonsEvent {
return isButtonPressed(GUITAR_HERO_3_BUTTON_ORANGE);
}
/* SelectButton Plus */
/* ManageButton Plus */
public boolean isButtonPlusJustPressed() {
return isButtonJustPressed(GUITAR_HERO_3_BUTTON_PLUS);
@@ -176,7 +176,7 @@ public class GuitarHeroButtonsEvent extends ButtonsEvent {
return isButtonPressed(GUITAR_HERO_3_BUTTON_PLUS);
}
/* SelectButton Red */
/* ManageButton Red */
public boolean isButtonRedJustPressed() {
return isButtonJustPressed(GUITAR_HERO_3_BUTTON_RED);
@@ -194,7 +194,7 @@ public class GuitarHeroButtonsEvent extends ButtonsEvent {
return isButtonPressed(GUITAR_HERO_3_BUTTON_RED);
}
/* SelectButton Yellow */
/* ManageButton Yellow */
public boolean isButtonYellowJustPressed() {
return isButtonJustPressed(GUITAR_HERO_3_BUTTON_YELLOW);

View File

@@ -44,7 +44,7 @@ public class NunchukButtonsEvent extends ButtonsEvent {
super(id, buttonsJustPressed, buttonsJustReleased, buttonsHeld);
}
/* SelectButton Z */
/* ManageButton Z */
public boolean isButtonZJustPressed() {
return isButtonJustPressed(NUNCHUK_BUTTON_Z);
@@ -62,7 +62,7 @@ public class NunchukButtonsEvent extends ButtonsEvent {
return isButtonPressed(NUNCHUK_BUTTON_Z);
}
/* SelectButton Z */
/* ManageButton Z */
public boolean isButtonCJustPressed() {
return isButtonJustPressed(NUNCHUK_BUTTON_C);

View File

@@ -60,7 +60,7 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
super(id, buttonsJustPressed, buttonsJustReleased, buttonsHeld);
}
/* SelectButton ONE */
/* ManageButton ONE */
public boolean isButtonOneJustPressed() {
return isButtonJustPressed(WIIMOTE_BUTTON_ONE);
@@ -78,7 +78,7 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
return isButtonPressed(WIIMOTE_BUTTON_ONE);
}
/* SelectButton TWO */
/* ManageButton TWO */
public boolean isButtonTwoJustPressed() {
return isButtonJustPressed(WIIMOTE_BUTTON_TWO);
@@ -96,7 +96,7 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
return isButtonPressed(WIIMOTE_BUTTON_TWO);
}
/* SelectButton A */
/* ManageButton A */
public boolean isButtonAJustPressed() {
return isButtonJustPressed(WIIMOTE_BUTTON_A);
@@ -114,7 +114,7 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
return isButtonPressed(WIIMOTE_BUTTON_A);
}
/* SelectButton B */
/* ManageButton B */
public boolean isButtonBJustPressed() {
return isButtonJustPressed(WIIMOTE_BUTTON_B);
@@ -132,7 +132,7 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
return isButtonPressed(WIIMOTE_BUTTON_B);
}
/* SelectButton LEFT */
/* ManageButton LEFT */
public boolean isButtonLeftJustPressed() {
return isButtonJustPressed(WIIMOTE_BUTTON_LEFT);
@@ -150,7 +150,7 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
return isButtonPressed(WIIMOTE_BUTTON_LEFT);
}
/* SelectButton RIGHT */
/* ManageButton RIGHT */
public boolean isButtonRightJustPressed() {
return isButtonJustPressed(WIIMOTE_BUTTON_RIGHT);
@@ -168,7 +168,7 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
return isButtonPressed(WIIMOTE_BUTTON_RIGHT);
}
/* SelectButton UP */
/* ManageButton UP */
public boolean isButtonUpJustPressed() {
return isButtonJustPressed(WIIMOTE_BUTTON_UP);
@@ -186,7 +186,7 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
return isButtonPressed(WIIMOTE_BUTTON_UP);
}
/* SelectButton DOWN */
/* ManageButton DOWN */
public boolean isButtonDownJustPressed() {
return isButtonJustPressed(WIIMOTE_BUTTON_DOWN);
@@ -204,7 +204,7 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
return isButtonPressed(WIIMOTE_BUTTON_DOWN);
}
/* SelectButton - */
/* ManageButton - */
public boolean isButtonMinusJustPressed() {
return isButtonJustPressed(WIIMOTE_BUTTON_MINUS);
@@ -222,7 +222,7 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
return isButtonPressed(WIIMOTE_BUTTON_MINUS);
}
/* SelectButton + */
/* ManageButton + */
public boolean isButtonPlusJustPressed() {
return isButtonJustPressed(WIIMOTE_BUTTON_PLUS);
@@ -240,7 +240,7 @@ public class WiimoteButtonsEvent extends ButtonsEvent {
return isButtonPressed(WIIMOTE_BUTTON_PLUS);
}
/* SelectButton HOME */
/* ManageButton HOME */
public boolean isButtonHomeJustPressed() {
return isButtonJustPressed(WIIMOTE_BUTTON_HOME);