reorganized files and a part of the architecture.
This version needs to be tested. Don't forget to add comments. git-svn-id: http://wiiusej.googlecode.com/svn/trunk@64 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
@@ -50,7 +50,7 @@ public class WiiUseApiManager extends Thread {
|
||||
* try to connect nb wiimotes
|
||||
* @return an array with connected wiimotes or NULL.
|
||||
*/
|
||||
public static Wiimote[] getWiimotes(int nb) {
|
||||
public synchronized static Wiimote[] getWiimotes(int nb) {
|
||||
WiiUseApiManager manager = getInstance();
|
||||
if (manager.connected < 0) {
|
||||
int nbWiimotes = manager.connectWiimotes(nb);
|
||||
@@ -80,7 +80,7 @@ public class WiiUseApiManager extends Thread {
|
||||
* try to connect nb wiimotes
|
||||
* @return 0 if nothing connected or the number of wiimotes connected.
|
||||
*/
|
||||
public int connectWiimotes(int nb) {
|
||||
private int connectWiimotes(int nb) {
|
||||
nbMaxWiimotes = nb;
|
||||
if (connected < 0) {
|
||||
connected = wiiuse.doConnections(nb);
|
||||
@@ -462,7 +462,7 @@ public class WiiUseApiManager extends Thread {
|
||||
*/
|
||||
private void notifyWiiUseApiListener(WiiUseApiEvent evt) {
|
||||
for (WiiUseApiListener listener : getWiiUseApiListeners()) {
|
||||
listener.wiiUseApiEvent(evt);
|
||||
listener.onWiiUseApiEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import javax.swing.event.EventListenerList;
|
||||
|
||||
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiuseapievents.StatusEvent;
|
||||
import wiiusej.wiiuseapievents.WiiMoteEvent;
|
||||
import wiiusej.wiiuseapievents.GenericEvent;
|
||||
import wiiusej.wiiuseapievents.WiiUseApiEvent;
|
||||
import wiiusej.wiiuseapievents.WiiUseApiListener;
|
||||
import wiiusej.wiiuseapievents.WiimoteListener;
|
||||
@@ -168,10 +168,10 @@ public class Wiimote implements WiiUseApiListener {
|
||||
manager.getStatus(id);
|
||||
}
|
||||
|
||||
public void wiiUseApiEvent(WiiUseApiEvent e) {
|
||||
public void onWiiUseApiEvent(WiiUseApiEvent e) {
|
||||
if (e.getWiimoteId() == id){
|
||||
if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT){
|
||||
notifyWiiMoteEventListeners((WiiMoteEvent)e);
|
||||
notifyWiiMoteEventListeners((GenericEvent)e);
|
||||
}else if (e.getEventType() == WiiUseApiEvent.STATUS_EVENT){
|
||||
notifyStatusEventListeners((StatusEvent)e);
|
||||
}else if (e.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT){
|
||||
@@ -205,12 +205,21 @@ public class Wiimote implements WiiUseApiListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify WiimoteListener that an event occured.
|
||||
* Notify WiimoteListeners that an event occured.
|
||||
* Notify in first the listeners for Buttons Events.
|
||||
* In second the listeners for IR Events.
|
||||
* In third the listeners for Motion sensing events.
|
||||
* @param evt WiimoteEvent occured
|
||||
*/
|
||||
private void notifyWiiMoteEventListeners(WiiMoteEvent evt) {
|
||||
private void notifyWiiMoteEventListeners(GenericEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.wiimoteEvent(evt);
|
||||
listener.onButtonsEvent(evt.getButtonsEvent());
|
||||
if (evt.isThereIrEvent()){
|
||||
listener.onIrEvent(evt.getIREvent());
|
||||
}
|
||||
if (evt.isThereMotionSensingEvent()){
|
||||
listener.onMotionSensingEvent(evt.getMotionSensingEvent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +229,7 @@ public class Wiimote implements WiiUseApiListener {
|
||||
*/
|
||||
private void notifyStatusEventListeners(StatusEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.statusEvent(evt);
|
||||
listener.onStatusEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +239,7 @@ public class Wiimote implements WiiUseApiListener {
|
||||
*/
|
||||
private void notifyDisconnectionEventListeners(DisconnectionEvent evt) {
|
||||
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||
listener.disconnectionEvent(evt);
|
||||
listener.onDisconnectionEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package tests;
|
||||
package wiiusej.test;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package tests;
|
||||
package wiiusej.test;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.InputEvent;
|
||||
|
||||
import wiiusej.Point2DInteger;
|
||||
import wiiusej.WiiUseApiManager;
|
||||
import wiiusej.Wiimote;
|
||||
import wiiusej.values.Point2DInteger;
|
||||
import wiiusej.wiiuseapievents.ButtonsEvent;
|
||||
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||
import wiiusej.wiiuseapievents.IREvent;
|
||||
import wiiusej.wiiuseapievents.MotionSensingEvent;
|
||||
import wiiusej.wiiuseapievents.StatusEvent;
|
||||
import wiiusej.wiiuseapievents.WiiMoteEvent;
|
||||
import wiiusej.wiiuseapievents.GenericEvent;
|
||||
import wiiusej.wiiuseapievents.WiimoteListener;
|
||||
|
||||
/**
|
||||
@@ -41,11 +44,10 @@ public class Tests implements WiimoteListener {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static int nb = 0;
|
||||
|
||||
public void wiimoteEvent(WiiMoteEvent e) {
|
||||
System.out.println("Number of events : "+nb++);
|
||||
|
||||
public void onButtonsEvent(ButtonsEvent e) {
|
||||
if (dump == DISPLAY_EACH_VALUE) {
|
||||
// System.out.println("*********** WIIMOTE ID : "+
|
||||
// e.getWiimoteId() + " **************");
|
||||
@@ -203,23 +205,6 @@ public class Tests implements WiimoteListener {
|
||||
if (e.isButtonMinusJustPressed()) {
|
||||
System.out.println("Motion sensing Deactivated");
|
||||
wiimote.deactivateMotionSensing();
|
||||
}
|
||||
|
||||
/* display ir points */
|
||||
if (e.isIrActive()) {
|
||||
Point2DInteger[] list = e.getIRPoints();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i] != null)
|
||||
System.out.print("Point :(" + list[i].getX() + ","
|
||||
+ list[i].getY() + ") ");
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
/* display motion sensing */
|
||||
if (e.isMotionSensingActive()) {
|
||||
System.out.println("Motion Sensing :" + e.getOrientation()
|
||||
+ " , " + e.getGforce());
|
||||
}
|
||||
|
||||
/* leave test */
|
||||
@@ -276,17 +261,6 @@ public class Tests implements WiimoteListener {
|
||||
robot.mouseRelease(InputEvent.BUTTON2_MASK);
|
||||
}
|
||||
|
||||
Point2DInteger[] list = e.getIRPoints();
|
||||
if (e.isIrActive() && list[0] != null) {
|
||||
|
||||
int x1 = (int) list[0].getX();
|
||||
int y1 = (int) list[0].getY();
|
||||
|
||||
int mousex = (int) Math.round(((double) x1 / 1024.0) * 1280.0);
|
||||
int mousey = (int) Math.round(((double) y1 / 768.0) * 1024.0);
|
||||
robot.mouseMove(mousex, mousey);
|
||||
}
|
||||
|
||||
/* leave test */
|
||||
if (e.isButtonHomeJustPressed()) {
|
||||
System.out.println("LEAVING TEST");
|
||||
@@ -318,10 +292,9 @@ public class Tests implements WiimoteListener {
|
||||
System.out.println("Threshold orientation 0.5 degrees");
|
||||
wiimote.setOrientationThreshold((float) 0.5);
|
||||
}
|
||||
|
||||
//@TODO add accelereation threshold test, add alpha smoothing test
|
||||
|
||||
|
||||
|
||||
// @TODO add accelereation threshold test, add alpha smoothing test
|
||||
|
||||
System.out.println(e);
|
||||
|
||||
/* leave test */
|
||||
@@ -350,15 +323,56 @@ public class Tests implements WiimoteListener {
|
||||
wiimote.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void statusEvent(StatusEvent e) {
|
||||
//Display status variables
|
||||
System.out.println(e);
|
||||
|
||||
public void onIrEvent(IREvent e) {
|
||||
if (dump == DISPLAY_EACH_VALUE) {
|
||||
/* display ir points */
|
||||
Point2DInteger[] list = e.getIRPoints();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i] != null)
|
||||
System.out.print("Point :(" + list[i].getX() + ","
|
||||
+ list[i].getY() + ") ");
|
||||
}
|
||||
} else if (dump == DUMP) {
|
||||
System.out.println(e);
|
||||
} else if (dump == MOVE_MOUSE) {
|
||||
Point2DInteger[] list = e.getIRPoints();
|
||||
if (list.length > 0) {
|
||||
int x1 = (int) list[0].getX();
|
||||
int y1 = (int) list[0].getY();
|
||||
|
||||
int mousex = (int) Math.round(((double) x1 / 1024.0) * 1280.0);
|
||||
int mousey = (int) Math.round(((double) y1 / 768.0) * 1024.0);
|
||||
robot.mouseMove(mousex, mousey);
|
||||
}
|
||||
} else if (dump == ORIENT_THRESH_CONT) {
|
||||
|
||||
// @TODO add acceleration threshold test, add alpha smoothing test
|
||||
} else if (dump == TEST_LEDS) {
|
||||
wiimote.activateMotionSensing();
|
||||
|
||||
}
|
||||
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
public void onMotionSensingEvent(MotionSensingEvent e) {
|
||||
/* display motion sensing */
|
||||
System.out.println("Motion Sensing :" + e.getOrientation() + " , "
|
||||
+ e.getGforce());
|
||||
|
||||
}
|
||||
|
||||
public void onStatusEvent(StatusEvent e) {
|
||||
// Display status variables
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
public void disconnectionEvent(DisconnectionEvent e) {
|
||||
System.out.println(e.getWiimoteId()+" notify it's been disconnected !!");
|
||||
public void onDisconnectionEvent(DisconnectionEvent e) {
|
||||
System.out.println(e.getWiimoteId()
|
||||
+ " notify it's been disconnected !!");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -377,5 +391,4 @@ public class Tests implements WiimoteListener {
|
||||
// timer.scheduleAtFixedRate(new LedsTask(), 0, 100);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package wiiusej;
|
||||
package wiiusej.values;
|
||||
|
||||
/**
|
||||
* Represents gravity force on each axis.
|
||||
@@ -1,4 +1,4 @@
|
||||
package wiiusej;
|
||||
package wiiusej.values;
|
||||
|
||||
/**
|
||||
* Class that represents the orientation of the wiimote.
|
||||
@@ -1,4 +1,4 @@
|
||||
package wiiusej;
|
||||
package wiiusej.values;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Point2DInteger extends Point2D {
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getY() {
|
||||
return y;
|
||||
@@ -1,9 +1,8 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
import tests.Tests;
|
||||
|
||||
/**
|
||||
* Gather events in a call to the Wiiuse API.
|
||||
* Gather events during a call to the Wiiuse API.
|
||||
*
|
||||
* @author gduche
|
||||
*
|
||||
@@ -12,7 +11,7 @@ public class EventsGatherer {
|
||||
|
||||
private WiiUseApiEvent[] events;
|
||||
private int index = 0;
|
||||
private WiiMoteEvent genericEvent = null;
|
||||
private GenericEvent genericEvent = null;
|
||||
|
||||
/**
|
||||
* Create EventsGatherer.
|
||||
@@ -49,10 +48,11 @@ public class EventsGatherer {
|
||||
*/
|
||||
public void prepareWiiMoteEvent(int id, short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
genericEvent = new WiiMoteEvent(id, buttonsJustPressed,
|
||||
genericEvent = new GenericEvent(id, buttonsJustPressed,
|
||||
buttonsJustReleased, buttonsHeld);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an IR point to the WiiMoteEvent prepared
|
||||
*
|
||||
@@ -61,8 +61,8 @@ public class EventsGatherer {
|
||||
* @param y
|
||||
* y coordinates
|
||||
*/
|
||||
public void addIRPointToPreparedWiiMoteEvent(int x, int y) {
|
||||
if (genericEvent != null) {
|
||||
public void addIRPointToPreparedWiiMoteEvent(int x, int y) {
|
||||
if (genericEvent != null) {
|
||||
genericEvent.addIRpoint(x, y);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class EventsGatherer {
|
||||
public void addMotionSensingValues(float r, float p, float ya, float x,
|
||||
float y, float z) {
|
||||
if (genericEvent != null) {
|
||||
genericEvent.setOrientationAndGforce(r, p, ya, x, y, z);
|
||||
genericEvent.setMotionSensingEvent(r, p, ya, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
150
WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java
Normal file
150
WiiUseJ/src/wiiusej/wiiuseapievents/GenericEvent.java
Normal file
@@ -0,0 +1,150 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
|
||||
/**
|
||||
* Class that is a bean to be filled by the wiiuse API.
|
||||
*
|
||||
* @author gduche
|
||||
*
|
||||
*/
|
||||
public class GenericEvent extends WiiUseApiEvent {
|
||||
|
||||
ButtonsEvent buttonsEvent = null;
|
||||
IREvent infraredEvent = null;
|
||||
MotionSensingEvent motionSensingEvent = null;
|
||||
|
||||
/**
|
||||
* Construct the Wiimote setting up the id.
|
||||
*
|
||||
* @param id
|
||||
* the Wiimote id
|
||||
*/
|
||||
public GenericEvent(int id) {
|
||||
super(id, WiiUseApiEvent.GENERIC_EVENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Wiimote setting up the id and the buttons.
|
||||
*
|
||||
* @param id
|
||||
* the Wiimote id
|
||||
* @param buttonsJustPressed
|
||||
* buttons just pressed
|
||||
* @param buttonsJustReleased
|
||||
* buttons just released
|
||||
* @param buttonsHeld
|
||||
* buttons held
|
||||
*/
|
||||
public GenericEvent(int id, short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
super(id, WiiUseApiEvent.GENERIC_EVENT);
|
||||
buttonsEvent = new ButtonsEvent(id, buttonsJustPressed,
|
||||
buttonsJustReleased, buttonsHeld);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if there is an IR Event.
|
||||
*
|
||||
* @return TRUE if there is an IR event.
|
||||
*/
|
||||
public boolean isThereIrEvent() {
|
||||
return infraredEvent == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if there is a motion sensing Event.
|
||||
*
|
||||
* @return TRUE if there is a motion sensing event.
|
||||
*/
|
||||
public boolean isThereMotionSensingEvent() {
|
||||
return motionSensingEvent == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get buttons event.
|
||||
* @return the buttons event.
|
||||
*/
|
||||
public ButtonsEvent getButtonsEvent() {
|
||||
return buttonsEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get IR event.
|
||||
* @return the IR event if there is one or null.
|
||||
*/
|
||||
public IREvent getIREvent() {
|
||||
return infraredEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get motion sensing event.
|
||||
* @return the motion sensing event if there is one or null.
|
||||
*/
|
||||
public MotionSensingEvent getMotionSensingEvent() {
|
||||
return motionSensingEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an IR point to the generic event.
|
||||
* Create an IR Event if it's not created yet.
|
||||
* @param x x coordinates.
|
||||
* @param y y coordinates
|
||||
*/
|
||||
public void addIRpoint(int x,int y){
|
||||
//@TODO add points size
|
||||
if (infraredEvent == null){
|
||||
infraredEvent = new IREvent(getWiimoteId());
|
||||
}
|
||||
infraredEvent.addIRpoint(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Motion Sensing Event.
|
||||
*
|
||||
* @param r
|
||||
* roll
|
||||
* @param p
|
||||
* pitch
|
||||
* @param ya
|
||||
* yaw
|
||||
* @param x
|
||||
* gravity force on x axis
|
||||
* @param y
|
||||
* gravity force on y axis
|
||||
* @param z
|
||||
* gravity force on z axis
|
||||
*/
|
||||
public void setMotionSensingEvent(float r, float p, float ya, float x, float y,
|
||||
float z){
|
||||
motionSensingEvent = new MotionSensingEvent(getWiimoteId(), r, p, ya, x, y, z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** GENERIC EVENT : WIIMOTE ID :"
|
||||
+ super.getWiimoteId() + " ********/\n";
|
||||
|
||||
out += buttonsEvent;
|
||||
|
||||
if (infraredEvent != null) {
|
||||
out += infraredEvent;
|
||||
}else{
|
||||
out += "/******** IR Tracking ********/\n";
|
||||
out += "--- Active : false\n";
|
||||
}
|
||||
|
||||
if (motionSensingEvent != null) {
|
||||
out += motionSensingEvent;
|
||||
}else{
|
||||
out += "/******** Motion sensing ********/\n";
|
||||
out += "--- Motion sensing : false \n";
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
65
WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java
Normal file
65
WiiUseJ/src/wiiusej/wiiuseapievents/IREvent.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
import wiiusej.values.Point2DInteger;
|
||||
|
||||
/**
|
||||
* Class which represents an IR event.
|
||||
* @author guiguito
|
||||
*
|
||||
*/
|
||||
public class IREvent extends WiimoteEvent{
|
||||
|
||||
/* IR Tracking */
|
||||
private Point2DInteger[] IRPoints;
|
||||
private short indexPoints = 0;
|
||||
|
||||
private static short NB_POINTS = 4;// number of points IR can track
|
||||
|
||||
/**
|
||||
* Constructor for an infrared event.
|
||||
* @param id id of the wiimote concerned.
|
||||
*/
|
||||
public IREvent(int id) {
|
||||
super(id);
|
||||
IRPoints = new Point2DInteger[NB_POINTS];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of IR points.
|
||||
*
|
||||
* @return the list of 2D points
|
||||
*/
|
||||
public Point2DInteger[] getIRPoints() {
|
||||
return java.util.Arrays.copyOfRange(IRPoints, 0, indexPoints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add IR Point in the list (Max 4 points)
|
||||
*
|
||||
* @param x
|
||||
* x value
|
||||
* @param y
|
||||
* y value
|
||||
*/
|
||||
public void addIRpoint(int x, int y) {
|
||||
IRPoints[indexPoints] = new Point2DInteger(x, y);
|
||||
indexPoints++;
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Display IR Tracking */
|
||||
out += "/******** IR Tracking ********/\n";
|
||||
out += "--- Active : true\n";
|
||||
out += "--- Seen points\n";
|
||||
for (int i = 0; i < IRPoints.length; i++) {
|
||||
if (IRPoints[i] != null) {
|
||||
out += IRPoints[i].toString();
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
89
WiiUseJ/src/wiiusej/wiiuseapievents/MotionSensingEvent.java
Normal file
89
WiiUseJ/src/wiiusej/wiiuseapievents/MotionSensingEvent.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
import wiiusej.values.GForce;
|
||||
import wiiusej.values.Orientation;
|
||||
|
||||
/**
|
||||
* Class which represents a motion sensing event.
|
||||
* @author guiguito
|
||||
*
|
||||
*/
|
||||
public class MotionSensingEvent extends WiimoteEvent{
|
||||
|
||||
/* Motion Sensing */
|
||||
private Orientation orientation;
|
||||
private GForce gforce;
|
||||
|
||||
/**
|
||||
* Constructor for a Motion Sensing Event.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote concerned.
|
||||
* @param r
|
||||
* roll
|
||||
* @param p
|
||||
* pitch
|
||||
* @param ya
|
||||
* yaw
|
||||
* @param x
|
||||
* gravity force on x axis
|
||||
* @param y
|
||||
* gravity force on y axis
|
||||
* @param z
|
||||
* gravity force on z axis
|
||||
*/
|
||||
public MotionSensingEvent(int id, float r, float p, float ya, float x, float y,
|
||||
float z) {
|
||||
super(id);
|
||||
setOrientationAndGforce(r, p, ya, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set orientation and gravity force.
|
||||
*
|
||||
* @param r
|
||||
* roll
|
||||
* @param p
|
||||
* pitch
|
||||
* @param ya
|
||||
* yaw
|
||||
* @param x
|
||||
* gravity force on x axis
|
||||
* @param y
|
||||
* gravity force on y axis
|
||||
* @param z
|
||||
* gravity force on z axis
|
||||
*/
|
||||
private void setOrientationAndGforce(float r, float p, float ya, float x,
|
||||
float y, float z) {
|
||||
this.orientation = new Orientation(r, p, ya);
|
||||
this.gforce = new GForce(x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the orientation
|
||||
*/
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the gravity force.
|
||||
*
|
||||
* @return the gforce
|
||||
*/
|
||||
public GForce getGforce() {
|
||||
return gforce;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Motion sensing */
|
||||
out += "/******** Motion sensing ********/\n";
|
||||
out += "--- Motion sensing : true \n";
|
||||
out += "--- " + orientation + "\n";
|
||||
out += "--- " + gforce + "\n";
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,14 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
public abstract class WiiUseApiEvent {
|
||||
public abstract class WiiUseApiEvent extends WiimoteEvent{
|
||||
|
||||
public static int GENERIC_EVENT = 1;
|
||||
public static int STATUS_EVENT = 2;
|
||||
public static int DISCONNECTION_EVENT = 3;
|
||||
|
||||
public static int DISCONNECTION_EVENT = 3;
|
||||
|
||||
/* Event Type */
|
||||
private int eventType;
|
||||
|
||||
/* ID */
|
||||
private int wiimoteId = -1;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public WiiUseApiEvent(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the WiiUseApiEvent setting up the id.
|
||||
*
|
||||
@@ -28,31 +18,9 @@ public abstract class WiiUseApiEvent {
|
||||
* type of the event
|
||||
*/
|
||||
public WiiUseApiEvent(int id, int type) {
|
||||
wiimoteId = id;
|
||||
super(id);
|
||||
eventType = type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Wiimote ID
|
||||
*
|
||||
* @return the wiimote id.
|
||||
*/
|
||||
public int getWiimoteId() {
|
||||
return wiimoteId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Wiimote ID
|
||||
*
|
||||
* @param wiimoteId
|
||||
* id of the wiimote
|
||||
*/
|
||||
void setWiimoteId(int wiimoteId) {
|
||||
this.wiimoteId = wiimoteId;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event type.
|
||||
@@ -61,8 +29,7 @@ public abstract class WiiUseApiEvent {
|
||||
public int getEventType() {
|
||||
return eventType;
|
||||
}
|
||||
|
||||
public abstract String toString();
|
||||
|
||||
public abstract String toString();
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ package wiiusej.wiiuseapievents;
|
||||
*/
|
||||
public interface WiiUseApiListener extends java.util.EventListener {
|
||||
|
||||
void wiiUseApiEvent(WiiUseApiEvent e);
|
||||
void onWiiUseApiEvent(WiiUseApiEvent e);
|
||||
|
||||
|
||||
}
|
||||
|
||||
38
WiiUseJ/src/wiiusej/wiiuseapievents/WiimoteEvent.java
Normal file
38
WiiUseJ/src/wiiusej/wiiuseapievents/WiimoteEvent.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
public abstract class WiimoteEvent {
|
||||
|
||||
/* ID */
|
||||
private int wiimoteId = -1;
|
||||
|
||||
/**
|
||||
* Construct the WiiUseApiEvent setting up the id.
|
||||
*
|
||||
* @param id
|
||||
* the Wiimote id
|
||||
*/
|
||||
public WiimoteEvent(int id) {
|
||||
wiimoteId = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Wiimote ID
|
||||
*
|
||||
* @return the wiimote id.
|
||||
*/
|
||||
public int getWiimoteId() {
|
||||
return wiimoteId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Wiimote ID
|
||||
*
|
||||
* @param wiimoteId
|
||||
* id of the wiimote
|
||||
*/
|
||||
void setWiimoteId(int wiimoteId) {
|
||||
this.wiimoteId = wiimoteId;
|
||||
}
|
||||
|
||||
public abstract String toString();
|
||||
}
|
||||
@@ -3,10 +3,14 @@ package wiiusej.wiiuseapievents;
|
||||
|
||||
public interface WiimoteListener extends java.util.EventListener {
|
||||
|
||||
void wiimoteEvent(WiiMoteEvent e);
|
||||
void onButtonsEvent(ButtonsEvent e);
|
||||
|
||||
void onIrEvent(IREvent e);
|
||||
|
||||
void onMotionSensingEvent(MotionSensingEvent e);
|
||||
|
||||
void onStatusEvent(StatusEvent e);
|
||||
|
||||
void statusEvent(StatusEvent e);
|
||||
|
||||
void disconnectionEvent(DisconnectionEvent e);
|
||||
void onDisconnectionEvent(DisconnectionEvent e);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user