Ant buildfile aan Mimis toegevoegd om uitvoerbare jar te maken. Begonnen aan implementatie van Wii Balance Board in WiiuseJ.

This commit is contained in:
2011-10-22 09:15:01 +00:00
parent 80f639474b
commit 8e485256b2
39 changed files with 385 additions and 186 deletions

View File

@@ -77,7 +77,6 @@ public class WiimoteDevice extends Device implements GestureListener {
}
if (!connected) {
try {
log.debug("!");
connect();
} catch (DeviceNotFoundException e) {
disconnect = true;
@@ -98,7 +97,6 @@ public class WiimoteDevice extends Device implements GestureListener {
}
wiimoteDiscovery.disconnect();
disconnect = false;
//start();
}
}
@@ -168,11 +166,12 @@ public class WiimoteDevice extends Device implements GestureListener {
}
/* Connectivity */
public void connect() throws DeviceNotFoundException {
public synchronized void connect() throws DeviceNotFoundException {
wiimote = wiimoteService.getDevice(this);
log.debug("Connected");
//wiimote.activateContinuous();
wiimoteDiscovery.stop();
ledWorker.start();
//ledWorker.start();
sleep(10000);
}
/* Listeners */

View File

@@ -9,6 +9,7 @@ import mimis.exception.worker.ActivateException;
import mimis.exception.worker.DeactivateException;
public class WiimoteDiscovery extends Worker {
protected static final String WIISCAN = "wiiscan-bb.exe";
protected static final int TIMEOUT = 1000;
protected WiimoteDevice wiimoteDevice;
protected Process process;
@@ -29,7 +30,7 @@ public class WiimoteDiscovery extends Worker {
}
public boolean execute(String parameters) {
String command = "wiiscan.exe -l none " + parameters;
String command = WIISCAN + " -l none " + parameters;
try {
process = Runtime.getRuntime().exec(command);
Scanner scanner = new Scanner(process.getInputStream());

View File

@@ -16,6 +16,8 @@ import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
import wiiusej.wiiusejevents.utils.WiimoteListener;
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
@@ -30,8 +32,7 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
public static void main(String[] args) {
Log log = LogFactory.getLog(WiimoteService.class);
WiimoteService wiimoteService = new WiimoteService();
for (Wiimote wm : wiimoteService.getWiimotes(1, false)) {
for (Wiimote wm : WiiUseApiManager.getWiimotes(1, false)) {
log.debug(wm);
}
}
@@ -88,6 +89,7 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
}
public void onStatusEvent(StatusEvent event) {
log.debug(event);
if (event.isConnected()) {
WiimoteDevice wiimoteDevice = getWiimoteDevice(event);
wiimoteDevice.connected = true;
@@ -106,4 +108,12 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent event) {}
public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent event) {}
public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent event) {}
public void onBalanceBoardInsertedEvent(BalanceBoardInsertedEvent e) {
log.debug(e);
}
public void onBalanceBoardRemovedEvent(BalanceBoardRemovedEvent e) {
}
}

View File

@@ -20,6 +20,8 @@ import javax.swing.event.EventListenerList;
import wiiusej.wiiusejevents.utils.WiiUseApiListener;
import wiiusej.wiiusejevents.utils.WiimoteListener;
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
@@ -327,7 +329,11 @@ public class Wiimote implements WiiUseApiListener {
notifyClassicControllerInsertedEventListeners((ClassicControllerInsertedEvent) e);
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_REMOVED) {
notifyClassicControllerRemovedEventListeners((ClassicControllerRemovedEvent) e);
}
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_BALANCE_BOARD_CTRL_INSERTED) {
notifyBalanceBoardInsertedEventListeners((BalanceBoardInsertedEvent) e);
} else if (e.getEventType() == WiiUseApiEvent.WIIUSE_BALANCE_BOARD_CTRL_REMOVED) {
notifyBalanceBoardRemovedEventListeners((BalanceBoardRemovedEvent) e);
}
/*
* events not managed yet || e.getEventType() == WIIUSE_READ_DATA
* WiiUseApiEvent.WIIUSE_CLASSIC_CTRL_INSERTED || e.getEventType() ==
@@ -486,6 +492,18 @@ public class Wiimote implements WiiUseApiListener {
listener.onClassicControllerRemovedEvent(evt);
}
}
protected void notifyBalanceBoardInsertedEventListeners(BalanceBoardInsertedEvent evt) {
for (WiimoteListener listener : getWiiMoteEventListeners()) {
listener.onBalanceBoardInsertedEvent(evt);
}
}
protected void notifyBalanceBoardRemovedEventListeners(BalanceBoardRemovedEvent evt) {
for (WiimoteListener listener : getWiiMoteEventListeners()) {
listener.onBalanceBoardRemovedEvent(evt);
}
}
@Override
public String toString() {

View File

@@ -12,11 +12,6 @@ public class Calibration {
(short) (gAcceleration.getX() - zeroAcceleration.getX()),
(short) (gAcceleration.getY() - zeroAcceleration.getY()),
(short) (gAcceleration.getZ() - zeroAcceleration.getZ()));
System.out.println(zeroAcceleration);
System.out.println(gAcceleration);
System.out.println(differenceAcceleration);
System.out.println("<");
//System.exit(0);
}
public RawAcceleration getZeroAcceleration() {

View File

@@ -0,0 +1,11 @@
package wiiusej.wiiusejevents.physicalevents;
public class BalanceBoardButtonsEvent extends ButtonsEvent {
protected static short BALANCE_BOARD_BUTTON = 0x0001;
public BalanceBoardButtonsEvent(int id, short buttonsJustPressed,
short buttonsJustReleased, short buttonsHeld) {
super(id, buttonsJustPressed, buttonsJustReleased, buttonsHeld);
}
}

View File

@@ -0,0 +1,33 @@
package wiiusej.wiiusejevents.physicalevents;
public class BalanceBoardEvent extends ExpansionEvent {
protected BalanceBoardButtonsEvent buttonsEvent;
protected JoystickEvent balanceBoardJoystickEvent;
public BalanceBoardEvent(int id, float topRight, float bottomRight,
float bottomLeft, float topLeft) {
super(id);
System.out.println(String.format("%f %f %f %f", topRight, bottomRight, bottomLeft, topLeft));
/*balanceBoardJoystickEvent = new JoystickEvent(id, angle,
magnitude, max1, max2, min1, min2, center1, center2);*/
}
public boolean isThereBalanceBoardJoystickEvent() {
return balanceBoardJoystickEvent != null;
}
public JoystickEvent getBalanceBoardJoystickEvent() {
return balanceBoardJoystickEvent;
}
public String toString() {
String out = "";
/* Status */
out += "/*********** Balance Board EVENT : WIIMOTE ID :" + getWiimoteId()
+ " ********/\n";
out += balanceBoardJoystickEvent;
return out;
}
}

View File

@@ -16,6 +16,8 @@
*/
package wiiusej.wiiusejevents.utils;
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
@@ -362,6 +364,14 @@ public class EventsGatherer {
}
}
public void addBalanceBoardEventToPreparedWiimoteEvent(float topRight,
float bottomRight, float bottomLeft, float topLeft) {
if (genericEvent != null) {
genericEvent.setBalanceBoardEvent(topRight, bottomRight,
bottomLeft, topLeft);
}
}
/**
* Add the prepared WiimoteEvent to the gatherer.
*/
@@ -484,6 +494,16 @@ public class EventsGatherer {
addEvent(evt);
}
public void addBalanceBoardInsertedEvent(int id) {
BalanceBoardInsertedEvent evt = new BalanceBoardInsertedEvent(id);
addEvent(evt);
}
public void addBalanceBoardRemovedEvent(int id) {
BalanceBoardRemovedEvent evt = new BalanceBoardRemovedEvent(id);
addEvent(evt);
}
/**
* Return an array containing the events.
*

View File

@@ -20,6 +20,8 @@ import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.IREvent;
import wiiusej.wiiusejevents.physicalevents.MotionSensingEvent;
import wiiusej.wiiusejevents.physicalevents.WiimoteButtonsEvent;
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.BalanceBoardRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerInsertedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.ClassicControllerRemovedEvent;
import wiiusej.wiiusejevents.wiiuseapievents.DisconnectionEvent;
@@ -142,4 +144,6 @@ public interface WiimoteListener extends java.util.EventListener {
*/
void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent e);
void onBalanceBoardInsertedEvent(BalanceBoardInsertedEvent e);
void onBalanceBoardRemovedEvent(BalanceBoardRemovedEvent e);
}

View File

@@ -0,0 +1,15 @@
package wiiusej.wiiusejevents.wiiuseapievents;
public class BalanceBoardInsertedEvent extends WiiUseApiEvent {
public BalanceBoardInsertedEvent(int id) {
super(id, WIIUSE_BALANCE_BOARD_CTRL_INSERTED);
}
public String toString() {
String out = "";
/* Status */
out += "/*********** BALANCE BOARD INSERTED EVENT : WIIMOTE ID :"
+ super.getWiimoteId() + " ********/\n";
return out;
}
}

View File

@@ -0,0 +1,17 @@
package wiiusej.wiiusejevents.wiiuseapievents;
import wiiusej.wiiusejevents.wiiuseapievents.WiiUseApiEvent;
public class BalanceBoardRemovedEvent extends WiiUseApiEvent {
public BalanceBoardRemovedEvent(int id) {
super(id, WIIUSE_BALANCE_BOARD_CTRL_REMOVED);
}
public String toString() {
String out = "";
/* Status */
out += "/*********** BALANCE BOARD INSERTED EVENT : WIIMOTE ID :"
+ super.getWiimoteId() + " ********/\n";
return out;
}
}

View File

@@ -24,7 +24,6 @@ import wiiusej.wiiusejevents.GenericEvent;
* @author guiguito
*/
public abstract class WiiUseApiEvent extends GenericEvent{
public static int NONE_EVENT = 0;
public static int GENERIC_EVENT = 1;
public static int STATUS_EVENT = 2;
@@ -36,7 +35,9 @@ public abstract class WiiUseApiEvent extends GenericEvent{
public static int WIIUSE_CLASSIC_CTRL_REMOVED = 8;
public static int WIIUSE_GUITAR_HERO_3_CTRL_INSERTED = 9;
public static int WIIUSE_GUITAR_HERO_3_CTRL_REMOVED = 10;
public static int WIIUSE_BALANCE_BOARD_CTRL_INSERTED = 11;
public static int WIIUSE_BALANCE_BOARD_CTRL_REMOVED = 12;
/* Event Type */
private int eventType;

View File

@@ -16,6 +16,7 @@
*/
package wiiusej.wiiusejevents.wiiuseapievents;
import wiiusej.wiiusejevents.physicalevents.BalanceBoardEvent;
import wiiusej.wiiusejevents.physicalevents.ClassicControllerEvent;
import wiiusej.wiiusejevents.physicalevents.ExpansionEvent;
import wiiusej.wiiusejevents.physicalevents.GuitarHeroEvent;
@@ -405,6 +406,12 @@ public class WiimoteEvent extends WiiUseApiEvent {
center2);
}
public void setBalanceBoardEvent(float topRight, float bottomRight,
float bottomLeft, float topLeft) {
expansionEvent = new BalanceBoardEvent(getWiimoteId(), topRight,
bottomRight, bottomLeft, topLeft);
}
@Override
public String toString() {
String out = "";
@@ -437,5 +444,4 @@ public class WiimoteEvent extends WiiUseApiEvent {
return out;
}
}