first draft with new version working on wiiuse 0.10.
New system to get events. git-svn-id: http://wiiusej.googlecode.com/svn/trunk@52 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
24
WiiUseJ/src/wiiusej/wiiuseapievents/DisconnectionEvent.java
Normal file
24
WiiUseJ/src/wiiusej/wiiuseapievents/DisconnectionEvent.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
public class DisconnectionEvent extends WiiUseApiEvent {
|
||||
|
||||
/**
|
||||
* Construct the DisconnectionEvent setting up the id.
|
||||
*
|
||||
* @param id
|
||||
* the Wiimote id
|
||||
*/
|
||||
public DisconnectionEvent(int id) {
|
||||
super(id,WiiUseApiEvent.DISCONNECTION_EVENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** DISCONNECTION EVENT : WIIMOTE ID :" + super.getWiimoteId() + " ********/\n";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
180
WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java
Normal file
180
WiiUseJ/src/wiiusej/wiiuseapievents/EventsGatherer.java
Normal file
@@ -0,0 +1,180 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
import tests.Tests;
|
||||
|
||||
/**
|
||||
* Gather events in a call to the Wiiuse API.
|
||||
*
|
||||
* @author gduche
|
||||
*
|
||||
*/
|
||||
public class EventsGatherer {
|
||||
|
||||
private WiiUseApiEvent[] events;
|
||||
private int index = 0;
|
||||
private WiiMoteEvent genericEvent = null;
|
||||
|
||||
/**
|
||||
* Create EventsGatherer.
|
||||
*
|
||||
* @param nbWiimotes
|
||||
* nb wiimotes (nb a of events possible in a call to Wiiuse API)
|
||||
*/
|
||||
public EventsGatherer(int nbWiimotes) {
|
||||
events = new WiiUseApiEvent[nbWiimotes];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an event to the array.
|
||||
*
|
||||
* @param e
|
||||
* the event to add.
|
||||
*/
|
||||
private void addEvent(WiiUseApiEvent e) {
|
||||
events[index] = e;
|
||||
index++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare a wiimote event to add.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote.
|
||||
* @param buttonsJustPressed
|
||||
* buttons just pressed
|
||||
* @param buttonsJustReleased
|
||||
* buttons just released
|
||||
* @param buttonsHeld
|
||||
* buttons held
|
||||
*/
|
||||
public void prepareWiiMoteEvent(int id, short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
genericEvent = new WiiMoteEvent(id, buttonsJustPressed,
|
||||
buttonsJustReleased, buttonsHeld);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an IR point to the WiiMoteEvent prepared
|
||||
*
|
||||
* @param x
|
||||
* x coordinates
|
||||
* @param y
|
||||
* y coordinates
|
||||
*/
|
||||
public void addIRPointToPreparedWiiMoteEvent(int x, int y) {
|
||||
if (genericEvent != null) {
|
||||
genericEvent.addIRpoint(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set orientation and gravity force of the prepared 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 addMotionSensingValues(float r, float p, float ya, float x,
|
||||
float y, float z) {
|
||||
if (genericEvent != null) {
|
||||
genericEvent.setOrientationAndGforce(r, p, ya, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the prepared WiimoteEvent to the gatherer.
|
||||
*/
|
||||
public void addWiimoteEvent() {
|
||||
if (genericEvent != null) {
|
||||
addEvent(genericEvent);
|
||||
genericEvent = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a StatusEvent to the gatherer.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* @param connect
|
||||
* true if the wiimote is connected
|
||||
* @param batt
|
||||
* battery level
|
||||
* @param led
|
||||
* status of leds
|
||||
* @param speak
|
||||
* speakers status
|
||||
* @param attach
|
||||
* attachment status
|
||||
* @param rumbleState
|
||||
* true if rumble is active
|
||||
* @param orientationThreshold
|
||||
* value of the minimum angle between two events with the
|
||||
* accelerometer
|
||||
* @param accelerationThreshold
|
||||
* value of the value variation between two events with the
|
||||
* accelerometer
|
||||
* @param alphaSmooth
|
||||
* value of the alpha smoothing parameter
|
||||
* @param continuousState
|
||||
* true if continuous flag is activated
|
||||
* @param smoothingState
|
||||
* true if smoothing flag is activated
|
||||
* @param irState
|
||||
* true if ir is active
|
||||
* @param motionSensingState
|
||||
* true if accelerometer is active
|
||||
*/
|
||||
public void addStatusEvent(int id, boolean connect, float batt, short led,
|
||||
boolean speak, int attach, boolean rumbleState,
|
||||
float orientationThreshold, float accelerationThreshold,
|
||||
float alphaSmooth, boolean continuousState, boolean smoothingState,
|
||||
boolean irState, boolean motionSensingState) {
|
||||
StatusEvent evt = new StatusEvent(id, connect, batt, led, speak,
|
||||
attach, rumbleState, orientationThreshold,
|
||||
accelerationThreshold, alphaSmooth, continuousState,
|
||||
smoothingState, irState, motionSensingState);
|
||||
addEvent(evt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a DisconnectionEvent to the gatherer.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
*/
|
||||
public void addDisconnectionEvent(int id) {
|
||||
DisconnectionEvent evt = new DisconnectionEvent(id);
|
||||
addEvent(evt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array containing the events.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WiiUseApiEvent[] getEvents() {
|
||||
return java.util.Arrays.copyOfRange(events, 0, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the gatherer and remove objects.
|
||||
*/
|
||||
public void clearEvents() {
|
||||
for (int i = 0; i < events.length; i++) {
|
||||
events[i] = null;
|
||||
}
|
||||
genericEvent = null;
|
||||
index = 0;
|
||||
}
|
||||
|
||||
}
|
||||
251
WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java
Normal file
251
WiiUseJ/src/wiiusej/wiiuseapievents/StatusEvent.java
Normal file
@@ -0,0 +1,251 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
public class StatusEvent extends WiiUseApiEvent {
|
||||
|
||||
private static short WIIMOTE_LED_1 = 1;
|
||||
private static short WIIMOTE_LED_2 = 2;
|
||||
private static short WIIMOTE_LED_3 = 4;
|
||||
private static short WIIMOTE_LED_4 = 8;
|
||||
|
||||
/* ATTACHMENT CONSTANTS */
|
||||
|
||||
private static short EXP_NONE = 0;
|
||||
private static short EXP_NUNCHUK = 1;
|
||||
private static short EXP_CLASSIC = 2;
|
||||
private static short EXP_GUITAR_HERO_3 = 3;
|
||||
|
||||
/* Status variables */
|
||||
private boolean connected = false;
|
||||
|
||||
private float batteryLevel = -1;
|
||||
|
||||
private short leds = 0;
|
||||
|
||||
private boolean isSpeakerEnabled = false;
|
||||
|
||||
private int attachment = 0;
|
||||
|
||||
private boolean isRumbleActive = false;
|
||||
|
||||
private float orientationThreshold = 0;
|
||||
|
||||
private float accelerationThreshold = 0;
|
||||
|
||||
private float alphaSmoothing = 0;
|
||||
|
||||
private boolean isContinuousActive = false;
|
||||
|
||||
private boolean isSmoothingActive = false;
|
||||
|
||||
private boolean isIrActive = false;
|
||||
|
||||
private boolean isMotionSensingActive = false;
|
||||
|
||||
/**
|
||||
* Construct the StatusEvent setting up the id.
|
||||
*
|
||||
* @param id
|
||||
* the Wiimote id
|
||||
*/
|
||||
public StatusEvent(int id) {
|
||||
super(id, WiiUseApiEvent.STATUS_EVENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a StatusEvent with all fields set.
|
||||
*
|
||||
* @param id
|
||||
* id of the wiimote
|
||||
* @param connect
|
||||
* true if the wiimote is connected
|
||||
* @param batt
|
||||
* battery level
|
||||
* @param led
|
||||
* status of leds
|
||||
* @param speak
|
||||
* speakers status
|
||||
* @param attach
|
||||
* attachment status
|
||||
* @param rumbleState
|
||||
* true if rumble is active
|
||||
* @param orientationThreshold
|
||||
* value of the minimum angle between two events with the
|
||||
* accelerometer
|
||||
* @param accelerationThreshold
|
||||
* value of the value variation between two events with the
|
||||
* accelerometer
|
||||
* @param alphaSmooth
|
||||
* value of the alpha smoothing parameter
|
||||
* @param continuousState
|
||||
* true if continuous flag is activated
|
||||
* @param smoothingState
|
||||
* true if smoothing flag is activated
|
||||
* @param irState
|
||||
* true if ir is active
|
||||
* @param motionSensingState
|
||||
* true if accelerometer is active
|
||||
*/
|
||||
public StatusEvent(int id, boolean connect, float batt, short led,
|
||||
boolean speak, int attach, boolean rumbleState,
|
||||
float orientationThreshold, float accelerationThreshold,
|
||||
float alphaSmooth, boolean continuousState, boolean smoothingState,
|
||||
boolean irState, boolean motionSensingState) {
|
||||
super(id, WiiUseApiEvent.STATUS_EVENT);
|
||||
connected = connect;
|
||||
this.batteryLevel = batt;
|
||||
this.leds = led;
|
||||
this.isSpeakerEnabled = speak;
|
||||
this.attachment = attach;
|
||||
isRumbleActive = rumbleState;
|
||||
this.orientationThreshold = orientationThreshold;
|
||||
this.accelerationThreshold = accelerationThreshold;
|
||||
alphaSmoothing = alphaSmooth;
|
||||
isContinuousActive = continuousState;
|
||||
isSmoothingActive = smoothingState;
|
||||
isIrActive = irState;
|
||||
isMotionSensingActive = motionSensingState;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the wiimote is connected false otherwise.
|
||||
*
|
||||
* @return return the connected status.
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get battery level.
|
||||
*
|
||||
* @return battery level. 1 = 100%
|
||||
*/
|
||||
public float getBatteryLevel() {
|
||||
return batteryLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status of the leds .
|
||||
*
|
||||
* @return a short representing LEDS turned on.
|
||||
*/
|
||||
public short getLeds() {
|
||||
return leds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if the speaker is enable for this wiimote
|
||||
*
|
||||
* @return TRUE if it enabled false otherwise
|
||||
*/
|
||||
public boolean isSpeakerEnabled() {
|
||||
return isSpeakerEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the int representing the attachment type.
|
||||
*
|
||||
* @return value of the Attachment Type
|
||||
*/
|
||||
public int getAttachment() {
|
||||
return attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status of rumble.
|
||||
*
|
||||
* @return true if the rumble is active false otherwise
|
||||
*/
|
||||
public boolean isRumbleActive() {
|
||||
return isRumbleActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get orientation threshold.
|
||||
*
|
||||
* @return the orientationThreshold
|
||||
*/
|
||||
public float getOrientationThreshold() {
|
||||
return orientationThreshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get acceleration threshold.
|
||||
*
|
||||
* @return the accelerationThreshold
|
||||
*/
|
||||
public float getAccelerationThreshold() {
|
||||
return accelerationThreshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get alpha smoothing.
|
||||
*
|
||||
* @return the alphaSmoothing
|
||||
*/
|
||||
public float getAlphaSmoothing() {
|
||||
return alphaSmoothing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if the CONTINUOUS option is activated.
|
||||
*
|
||||
* @return the isContinuousActive
|
||||
*/
|
||||
public boolean isContinuousActive() {
|
||||
return isContinuousActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if the option SMOOTHING is activated.
|
||||
*
|
||||
* @return the isSmoothingActive
|
||||
*/
|
||||
public boolean isSmoothingActive() {
|
||||
return isSmoothingActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if the IR Tracking is active.
|
||||
*
|
||||
* @return TRUE if it is active or false otherwise.
|
||||
*/
|
||||
public boolean isIrActive() {
|
||||
return isIrActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag indicating if the motion sensing is active.
|
||||
*
|
||||
* @return true if the motion sensing is active false otherwise
|
||||
*/
|
||||
public boolean isMotionSensingActive() {
|
||||
return isMotionSensingActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** STATUS EVENT : WIIMOTE ID :"
|
||||
+ super.getWiimoteId() + " ********/\n";
|
||||
out += "--- connected : " + connected + "\n";
|
||||
out += "--- Battery level : " + batteryLevel + "\n";
|
||||
out += "--- Leds : " + leds + "\n";
|
||||
out += "--- Speaker enabled : " + isSpeakerEnabled + "\n";
|
||||
out += "--- Attachment ? : " + attachment + "\n";
|
||||
out += "--- Rumble ? : " + isRumbleActive + "\n";
|
||||
out += "--- Orientation threshold value ? : " + orientationThreshold
|
||||
+ "\n";
|
||||
out += "--- Acceleration threshold value ? : " + accelerationThreshold
|
||||
+ "\n";
|
||||
out += "--- Alpha smoothing threshold value ? : " + alphaSmoothing
|
||||
+ "\n";
|
||||
out += "--- Continuous ? : " + isContinuousActive + "\n";
|
||||
out += "--- Smoothing ? : " + isSmoothingActive + "\n";
|
||||
out += "--- IR active ? : " + isIrActive + "\n";
|
||||
out += "--- Motion sensing active ? : " + isMotionSensingActive + "\n";
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
428
WiiUseJ/src/wiiusej/wiiuseapievents/WiiMoteEvent.java
Normal file
428
WiiUseJ/src/wiiusej/wiiuseapievents/WiiMoteEvent.java
Normal file
@@ -0,0 +1,428 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import wiiusej.GForce;
|
||||
import wiiusej.Orientation;
|
||||
import wiiusej.Point2DInteger;
|
||||
|
||||
/**
|
||||
* Class that is a bean to be filled by the wiiuse API.
|
||||
*
|
||||
* @author gduche
|
||||
*
|
||||
*/
|
||||
public class WiiMoteEvent extends WiiUseApiEvent {
|
||||
|
||||
/* Buttons MACRO */
|
||||
private static short WIIMOTE_BUTTON_TWO = 0x0001;
|
||||
private static short WIIMOTE_BUTTON_ONE = 0x0002;
|
||||
private static short WIIMOTE_BUTTON_B = 0x0004;
|
||||
private static short WIIMOTE_BUTTON_A = 0x0008;
|
||||
private static short WIIMOTE_BUTTON_MINUS = 0x0010;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT6 = 0x0020;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT7 = 0x0040;
|
||||
private static short WIIMOTE_BUTTON_HOME = 0x0080;
|
||||
private static short WIIMOTE_BUTTON_LEFT = 0x0100;
|
||||
private static short WIIMOTE_BUTTON_RIGHT = 0x0200;
|
||||
private static short WIIMOTE_BUTTON_DOWN = 0x0400;
|
||||
private static short WIIMOTE_BUTTON_UP = 0x0800;
|
||||
private static short WIIMOTE_BUTTON_PLUS = 0x1000;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT4 = 0x2000;
|
||||
private static short WIIMOTE_BUTTON_ZACCEL_BIT5 = 0x4000;
|
||||
private static int WIIMOTE_BUTTON_UNKNOWN = 0x8000;
|
||||
private static short WIIMOTE_BUTTON_ALL = 0x1F9F;
|
||||
|
||||
private static short NB_POINTS = 4;// number of points IR can track
|
||||
|
||||
/* Buttons */
|
||||
private short buttonsJustPressed = 0;
|
||||
private short buttonsJustReleased = 0;
|
||||
private short buttonsHeld = 0;
|
||||
|
||||
/* IR Tracking */
|
||||
private boolean isIrActive = false;
|
||||
private Point2DInteger[] IRPoints;
|
||||
|
||||
/* Motion Sensing */
|
||||
private boolean isMotionSensingActive = false;
|
||||
private Orientation orientation;
|
||||
private GForce gforce;
|
||||
|
||||
/**
|
||||
* Construct the Wiimote setting up the id.
|
||||
*
|
||||
* @param id
|
||||
* the Wiimote id
|
||||
*/
|
||||
public WiiMoteEvent(int id) {
|
||||
super(id, WiiUseApiEvent.GENERIC_EVENT);
|
||||
IRPoints = new Point2DInteger[NB_POINTS];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 WiiMoteEvent(int id, short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
super(id, WiiUseApiEvent.GENERIC_EVENT);
|
||||
IRPoints = new Point2DInteger[NB_POINTS];
|
||||
setAllButtons(buttonsJustPressed, buttonsJustReleased, buttonsHeld);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Wiimote setting up the id, the buttons and the infared.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Construct the Wiimote setting up the id, the buttons, the accelerometer
|
||||
* and the infrared.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the short storing the buttons just pressed
|
||||
*
|
||||
* @return the short storing the buttons just pressed
|
||||
*/
|
||||
public short getButtonsJustPressed() {
|
||||
return buttonsJustPressed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the short storing the buttons just released
|
||||
*
|
||||
* @return the short storing the buttons just released
|
||||
*/
|
||||
public short getButtonsJustReleased() {
|
||||
return buttonsJustReleased;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the short storing the buttons held
|
||||
*
|
||||
* @return the short storing the buttons held
|
||||
*/
|
||||
public short getButtonsHeld() {
|
||||
return buttonsHeld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all buttons in one method.
|
||||
*
|
||||
* @param buttonsJustPressed
|
||||
* @param buttonsJustReleased
|
||||
* @param buttonsHeld
|
||||
*/
|
||||
private void setAllButtons(short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
this.buttonsJustPressed = buttonsJustPressed;
|
||||
this.buttonsJustReleased = buttonsJustReleased;
|
||||
this.buttonsHeld = buttonsHeld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if the IR Tracking is active.
|
||||
*
|
||||
* @return TRUE if it is active or false otherwise.
|
||||
*/
|
||||
public boolean isIrActive() {
|
||||
return isIrActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of IR points.
|
||||
*
|
||||
* @return the list of 2D points
|
||||
*/
|
||||
public Point2DInteger[] getIRPoints() {
|
||||
return IRPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add IR Point in the list (Max 4 points)
|
||||
*
|
||||
* @param x
|
||||
* x value
|
||||
* @param y
|
||||
* y value
|
||||
*/
|
||||
public void addIRpoint(int x, int y) {
|
||||
isIrActive = true;
|
||||
for (int i = 0; i < IRPoints.length; i++) {
|
||||
if (IRPoints[i] == null) {
|
||||
IRPoints[i] = new Point2DInteger(x, y);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the flag indicating if the motion sensing is active.
|
||||
*
|
||||
* @return true if the motion sensing is active false otherwise
|
||||
*/
|
||||
public boolean isMotionSensingActive() {
|
||||
return isMotionSensingActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the orientation
|
||||
*/
|
||||
public Orientation getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the gravity force.
|
||||
*
|
||||
* @return the gforce
|
||||
*/
|
||||
public GForce getGforce() {
|
||||
return gforce;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public void setOrientationAndGforce(float r, float p, float ya, float x,
|
||||
float y, float z) {
|
||||
this.isMotionSensingActive = true;
|
||||
this.orientation = new Orientation(r, p, ya);
|
||||
this.gforce = new GForce(x, y, z);
|
||||
}
|
||||
|
||||
/** **************** BUTTONS Methods ***************** */
|
||||
/* generic button functions */
|
||||
|
||||
private boolean buttonTest(short buttonBitsDefinition, short buttons) {
|
||||
return (buttons & buttonBitsDefinition) == buttonBitsDefinition;
|
||||
}
|
||||
|
||||
private boolean isButtonJustPressed(short buttonBitsDefinition) {
|
||||
return buttonTest(buttonBitsDefinition, buttonsJustPressed)
|
||||
&& !isButtonHeld(buttonBitsDefinition);
|
||||
}
|
||||
|
||||
private boolean isButtonJustReleased(short buttonBitsDefinition) {
|
||||
return buttonTest(buttonBitsDefinition, buttonsJustReleased);
|
||||
}
|
||||
|
||||
private boolean isButtonHeld(short buttonBitsDefinition) {
|
||||
return buttonTest(buttonBitsDefinition, buttonsHeld);
|
||||
}
|
||||
|
||||
/* Button ONE */
|
||||
|
||||
public boolean isButtonOneJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_ONE);
|
||||
}
|
||||
|
||||
public boolean isButtonOneJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_ONE);
|
||||
}
|
||||
|
||||
public boolean isButtonOneHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_ONE);
|
||||
}
|
||||
|
||||
/* Button TWO */
|
||||
|
||||
public boolean isButtonTwoJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_TWO);
|
||||
}
|
||||
|
||||
public boolean isButtonTwoJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_TWO);
|
||||
}
|
||||
|
||||
public boolean isButtonTwoHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_TWO);
|
||||
}
|
||||
|
||||
/* Button A */
|
||||
|
||||
public boolean isButtonAJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_A);
|
||||
}
|
||||
|
||||
public boolean isButtonAJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_A);
|
||||
}
|
||||
|
||||
public boolean isButtonAHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_A);
|
||||
}
|
||||
|
||||
/* Button B */
|
||||
|
||||
public boolean isButtonBJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_B);
|
||||
}
|
||||
|
||||
public boolean isButtonBJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_B);
|
||||
}
|
||||
|
||||
public boolean isButtonBHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_B);
|
||||
}
|
||||
|
||||
/* Button LEFT */
|
||||
|
||||
public boolean isButtonLeftJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_LEFT);
|
||||
}
|
||||
|
||||
public boolean isButtonLeftJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_LEFT);
|
||||
}
|
||||
|
||||
public boolean isButtonLeftHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_LEFT);
|
||||
}
|
||||
|
||||
/* Button RIGHT */
|
||||
|
||||
public boolean isButtonRightJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
public boolean isButtonRightJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
public boolean isButtonRightHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
/* Button UP */
|
||||
|
||||
public boolean isButtonUpJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_UP);
|
||||
}
|
||||
|
||||
public boolean isButtonUpJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_UP);
|
||||
}
|
||||
|
||||
public boolean isButtonUpHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_UP);
|
||||
}
|
||||
|
||||
/* Button DOWN */
|
||||
|
||||
public boolean isButtonDownJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
public boolean isButtonDownJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
public boolean isButtonDownHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_DOWN);
|
||||
}
|
||||
|
||||
/* Button - */
|
||||
|
||||
public boolean isButtonMinusJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_MINUS);
|
||||
}
|
||||
|
||||
public boolean isButtonMinusJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_MINUS);
|
||||
}
|
||||
|
||||
public boolean isButtonMinusHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_MINUS);
|
||||
}
|
||||
|
||||
/* Button + */
|
||||
|
||||
public boolean isButtonPlusJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_PLUS);
|
||||
}
|
||||
|
||||
public boolean isButtonPlusJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_PLUS);
|
||||
}
|
||||
|
||||
public boolean isButtonPlusHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_PLUS);
|
||||
}
|
||||
|
||||
/* Button HOME */
|
||||
|
||||
public boolean isButtonHomeJustPressed() {
|
||||
return isButtonJustPressed(WIIMOTE_BUTTON_HOME);
|
||||
}
|
||||
|
||||
public boolean isButtonHomeJustReleased() {
|
||||
return isButtonJustReleased(WIIMOTE_BUTTON_HOME);
|
||||
}
|
||||
|
||||
public boolean isButtonHomeHeld() {
|
||||
return isButtonHeld(WIIMOTE_BUTTON_HOME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** GENERIC EVENT : WIIMOTE ID :"
|
||||
+ super.getWiimoteId() + " ********/\n";
|
||||
/* Display buttons */
|
||||
out += "/******** Buttons ********/\n";
|
||||
out += "--- Buttons just pressed : " + buttonsJustPressed + "\n";
|
||||
out += "--- Buttons just released : " + buttonsJustReleased + "\n";
|
||||
out += "--- Buttons held : " + buttonsHeld + "\n";
|
||||
|
||||
/* Display IR Tracking */
|
||||
out += "/******** IR Tracking ********/\n";
|
||||
out += "--- Active : " + isIrActive + "\n";
|
||||
if (isIrActive) {
|
||||
out += "--- Seen points\n";
|
||||
for (int i = 0; i < IRPoints.length; i++) {
|
||||
if (IRPoints[i] != null) {
|
||||
out += IRPoints[i].toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Motion sensing */
|
||||
out += "/******** Motion sensing ********/\n";
|
||||
out += "--- Motion sensing : " + isMotionSensingActive + "\n";
|
||||
if (isMotionSensingActive) {
|
||||
out += "--- " + orientation + "\n";
|
||||
out += "--- " + gforce + "\n";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
68
WiiUseJ/src/wiiusej/wiiuseapievents/WiiUseApiEvent.java
Normal file
68
WiiUseJ/src/wiiusej/wiiuseapievents/WiiUseApiEvent.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
public abstract class WiiUseApiEvent {
|
||||
|
||||
public static int GENERIC_EVENT = 1;
|
||||
public static int STATUS_EVENT = 2;
|
||||
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.
|
||||
*
|
||||
* @param id
|
||||
* the Wiimote id
|
||||
* @param type
|
||||
* type of the event
|
||||
*/
|
||||
public WiiUseApiEvent(int id, int type) {
|
||||
wiimoteId = 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.
|
||||
* @return the eventType
|
||||
*/
|
||||
public int getEventType() {
|
||||
return eventType;
|
||||
}
|
||||
|
||||
public abstract String toString();
|
||||
|
||||
|
||||
}
|
||||
15
WiiUseJ/src/wiiusej/wiiuseapievents/WiiUseApiListener.java
Normal file
15
WiiUseJ/src/wiiusej/wiiuseapievents/WiiUseApiListener.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Interface defining the methods a WiiUseApiListener must have
|
||||
* @author gduche
|
||||
*
|
||||
*/
|
||||
public interface WiiUseApiListener extends java.util.EventListener {
|
||||
|
||||
void wiiUseApiEvent(WiiUseApiEvent e);
|
||||
|
||||
|
||||
}
|
||||
12
WiiUseJ/src/wiiusej/wiiuseapievents/WiimoteListener.java
Normal file
12
WiiUseJ/src/wiiusej/wiiuseapievents/WiimoteListener.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package wiiusej.wiiuseapievents;
|
||||
|
||||
|
||||
public interface WiimoteListener extends java.util.EventListener {
|
||||
|
||||
void wiimoteEvent(WiiMoteEvent e);
|
||||
|
||||
void statusEvent(StatusEvent e);
|
||||
|
||||
void disconnectionEvent(DisconnectionEvent e);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user