simplified callbacks and filling of WiimoteEvent objects.
git-svn-id: http://wiiusej.googlecode.com/svn/trunk@16 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
@@ -10,6 +10,7 @@ import wiiusej.WiiUseApiManager;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This class used to test this API.
|
* This class used to test this API.
|
||||||
|
*
|
||||||
* @author gduche
|
* @author gduche
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -206,7 +207,16 @@ public class Tests implements WiiUseApiListener {
|
|||||||
System.out
|
System.out
|
||||||
.println("battery level : " + e.getBatteryLevel());
|
.println("battery level : " + e.getBatteryLevel());
|
||||||
System.out.println("= --- Leds : " + e.getLeds() + "\n");
|
System.out.println("= --- Leds : " + e.getLeds() + "\n");
|
||||||
System.out.println("= --- Rumble : " + e.isRumbleActive() + "\n");
|
System.out.println("= --- Rumble : " + e.isRumbleActive()
|
||||||
|
+ "\n");
|
||||||
|
System.out.println("= --- Continous : "
|
||||||
|
+ e.isContinuousActive() + "\n");
|
||||||
|
System.out.println("= --- Smoothing : "
|
||||||
|
+ e.isSmoothingActive() + "\n");
|
||||||
|
System.out.println("= --- Speaker : "
|
||||||
|
+ e.isSpeakerEnabled() + "\n");
|
||||||
|
System.out.println("= --- Attachment : "
|
||||||
|
+ e.isThereAttachment() + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* display ir points */
|
/* display ir points */
|
||||||
@@ -222,7 +232,8 @@ public class Tests implements WiiUseApiListener {
|
|||||||
|
|
||||||
/* display motion sensing */
|
/* display motion sensing */
|
||||||
if (e.isMotionSensingActive()) {
|
if (e.isMotionSensingActive()) {
|
||||||
System.out.println("Motion Sensing :"+e.getOrientation()+" , "+e.getGforce());
|
System.out.println("Motion Sensing :" + e.getOrientation()
|
||||||
|
+ " , " + e.getGforce());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* leave test */
|
/* leave test */
|
||||||
@@ -326,11 +337,11 @@ public class Tests implements WiiUseApiListener {
|
|||||||
}
|
}
|
||||||
if (e.isButtonMinusJustPressed()) {
|
if (e.isButtonMinusJustPressed()) {
|
||||||
System.out.println("Threshold orientation 0.5 degrees");
|
System.out.println("Threshold orientation 0.5 degrees");
|
||||||
WiiUseApiManager.getInstance().setOrientationThreshold(1, (float)0.5);
|
WiiUseApiManager.getInstance().setOrientationThreshold(1,
|
||||||
|
(float) 0.5);
|
||||||
}
|
}
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
|
|
||||||
|
|
||||||
/* leave test */
|
/* leave test */
|
||||||
if (e.isButtonHomeJustPressed()) {
|
if (e.isButtonHomeJustPressed()) {
|
||||||
System.out.println("LEAVING TEST");
|
System.out.println("LEAVING TEST");
|
||||||
@@ -339,16 +350,20 @@ public class Tests implements WiiUseApiListener {
|
|||||||
} else if (dump == TEST_LEDS) {
|
} else if (dump == TEST_LEDS) {
|
||||||
WiiUseApiManager.getInstance().activateMotionSensing(1);
|
WiiUseApiManager.getInstance().activateMotionSensing(1);
|
||||||
if (e.isButtonUpJustPressed()) {
|
if (e.isButtonUpJustPressed()) {
|
||||||
WiiUseApiManager.getInstance().setLeds(1, true, false, false, false);
|
WiiUseApiManager.getInstance().setLeds(1, true, false, false,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
if (e.isButtonDownJustPressed()) {
|
if (e.isButtonDownJustPressed()) {
|
||||||
WiiUseApiManager.getInstance().setLeds(1, false, true, false, false);
|
WiiUseApiManager.getInstance().setLeds(1, false, true, false,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
if (e.isButtonLeftJustPressed()) {
|
if (e.isButtonLeftJustPressed()) {
|
||||||
WiiUseApiManager.getInstance().setLeds(1, false, false, true, false);
|
WiiUseApiManager.getInstance().setLeds(1, false, false, true,
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
if (e.isButtonRightJustPressed()) {
|
if (e.isButtonRightJustPressed()) {
|
||||||
WiiUseApiManager.getInstance().setLeds(1, false, false, false, true);
|
WiiUseApiManager.getInstance().setLeds(1, false, false, false,
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* leave test */
|
/* leave test */
|
||||||
|
|||||||
@@ -143,16 +143,6 @@ public class WiiMoteEvent {
|
|||||||
return batteryLevel;
|
return batteryLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set level battery.
|
|
||||||
*
|
|
||||||
* @param batteryLevel
|
|
||||||
* must be between 0 and 1
|
|
||||||
*/
|
|
||||||
void setBatteryLevel(float batteryLevel) {
|
|
||||||
this.batteryLevel = batteryLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get status of the leds .
|
* Get status of the leds .
|
||||||
*
|
*
|
||||||
@@ -162,15 +152,6 @@ public class WiiMoteEvent {
|
|||||||
return leds;
|
return leds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Status of the leds.
|
|
||||||
*
|
|
||||||
* @param leds
|
|
||||||
*/
|
|
||||||
void setLeds(short leds) {
|
|
||||||
this.leds = leds;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell if the speaker is enable for this wiimote
|
* Tell if the speaker is enable for this wiimote
|
||||||
*
|
*
|
||||||
@@ -180,20 +161,6 @@ public class WiiMoteEvent {
|
|||||||
return isSpeakerEnabled;
|
return isSpeakerEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the flag for the speaker to "enabled"
|
|
||||||
*/
|
|
||||||
void setSpeakerEnabled() {
|
|
||||||
this.isSpeakerEnabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the flag for the speaker to "disabled"
|
|
||||||
*/
|
|
||||||
void setSpeakerDisabled() {
|
|
||||||
this.isSpeakerEnabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell if there is an attachment to the Wiimote
|
* Tell if there is an attachment to the Wiimote
|
||||||
*
|
*
|
||||||
@@ -204,17 +171,25 @@ public class WiiMoteEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the flag for the attachment to true
|
* Set battery level, leds, speaker state and attachment in one method.
|
||||||
|
* These method is called (and those variables are filled) only when a
|
||||||
|
* status has been requested on this wiimote.
|
||||||
|
*
|
||||||
|
* @param batt
|
||||||
|
* battery level
|
||||||
|
* @param led
|
||||||
|
* status of leds
|
||||||
|
* @param speak
|
||||||
|
* speakers status
|
||||||
|
* @param attach
|
||||||
|
* attachment status
|
||||||
*/
|
*/
|
||||||
void setThereIsAnAttachment() {
|
void setBatteryLedsSpeakerAttachment(float batt, short led, boolean speak,
|
||||||
this.isThereAttachment = true;
|
boolean attach) {
|
||||||
}
|
this.batteryLevel = batt;
|
||||||
|
this.leds = led;
|
||||||
/**
|
this.isSpeakerEnabled = speak;
|
||||||
* Set the flag for the attachment to false
|
this.isThereAttachment = attach;
|
||||||
*/
|
|
||||||
void setThereIsNoAttachment() {
|
|
||||||
this.isThereAttachment = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -226,13 +201,6 @@ public class WiiMoteEvent {
|
|||||||
return isRumbleActive;
|
return isRumbleActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Rumble flag to Active.
|
|
||||||
*/
|
|
||||||
void setRumbleActive() {
|
|
||||||
this.isRumbleActive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Rumble flag to Inactive.
|
* Set Rumble flag to Inactive.
|
||||||
*/
|
*/
|
||||||
@@ -249,16 +217,6 @@ public class WiiMoteEvent {
|
|||||||
return orientationThreshold;
|
return orientationThreshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the orientation threshold.
|
|
||||||
*
|
|
||||||
* @param orientationThreshold
|
|
||||||
* the orientationThreshold to set
|
|
||||||
*/
|
|
||||||
void setOrientationThreshold(float orientationThreshold) {
|
|
||||||
this.orientationThreshold = orientationThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell if the CONTINUOUS option is activated.
|
* Tell if the CONTINUOUS option is activated.
|
||||||
*
|
*
|
||||||
@@ -268,20 +226,6 @@ public class WiiMoteEvent {
|
|||||||
return isContinuousActive;
|
return isContinuousActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the CONTINUOUS option active.
|
|
||||||
*/
|
|
||||||
void setContinuousActive() {
|
|
||||||
this.isContinuousActive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the CONTINUOUS option inactive.
|
|
||||||
*/
|
|
||||||
void setContinuousInactive() {
|
|
||||||
this.isContinuousActive = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell if the option SMOOTHING is activated.
|
* Tell if the option SMOOTHING is activated.
|
||||||
*
|
*
|
||||||
@@ -291,20 +235,6 @@ public class WiiMoteEvent {
|
|||||||
return isSmoothingActive;
|
return isSmoothingActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set SMOOTHING option to active.
|
|
||||||
*/
|
|
||||||
void setSmoothingActive() {
|
|
||||||
this.isSmoothingActive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set SMOOTHING option to inactive.
|
|
||||||
*/
|
|
||||||
void setSmoothingInactive() {
|
|
||||||
this.isSmoothingActive = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the short storing the buttons just pressed
|
* Get the short storing the buttons just pressed
|
||||||
*
|
*
|
||||||
@@ -314,15 +244,6 @@ public class WiiMoteEvent {
|
|||||||
return buttonsJustPressed;
|
return buttonsJustPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* set the short storing the buttons just pressed
|
|
||||||
*
|
|
||||||
* @param buttonsJustPressed
|
|
||||||
*/
|
|
||||||
void setButtonsJustPressed(short buttonsJustPressed) {
|
|
||||||
this.buttonsJustPressed = buttonsJustPressed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the short storing the buttons just released
|
* Get the short storing the buttons just released
|
||||||
*
|
*
|
||||||
@@ -332,15 +253,6 @@ public class WiiMoteEvent {
|
|||||||
return buttonsJustReleased;
|
return buttonsJustReleased;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* set the short storing the buttons just released
|
|
||||||
*
|
|
||||||
* @param buttonsJustReleased
|
|
||||||
*/
|
|
||||||
void setButtonsJustReleased(short buttonsJustReleased) {
|
|
||||||
this.buttonsJustReleased = buttonsJustReleased;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the short storing the buttons held
|
* get the short storing the buttons held
|
||||||
*
|
*
|
||||||
@@ -351,11 +263,16 @@ public class WiiMoteEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the short storing the buttons held
|
* Set all buttons in one method.
|
||||||
*
|
*
|
||||||
|
* @param buttonsJustPressed
|
||||||
|
* @param buttonsJustReleased
|
||||||
* @param buttonsHeld
|
* @param buttonsHeld
|
||||||
*/
|
*/
|
||||||
void setButtonsHeld(short buttonsHeld) {
|
void setAllButtons(short buttonsJustPressed, short buttonsJustReleased,
|
||||||
|
short buttonsHeld) {
|
||||||
|
this.buttonsJustPressed = buttonsJustPressed;
|
||||||
|
this.buttonsJustReleased = buttonsJustReleased;
|
||||||
this.buttonsHeld = buttonsHeld;
|
this.buttonsHeld = buttonsHeld;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,20 +285,6 @@ public class WiiMoteEvent {
|
|||||||
return isIrActive;
|
return isIrActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the value isIrActive to true
|
|
||||||
*/
|
|
||||||
void setIrActive() {
|
|
||||||
this.isIrActive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the value isIrActive to true
|
|
||||||
*/
|
|
||||||
void setIrInactive() {
|
|
||||||
this.isIrActive = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list of IR points.
|
* Get list of IR points.
|
||||||
*
|
*
|
||||||
@@ -428,17 +331,38 @@ public class WiiMoteEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the motion sensing flag to active.
|
* Set status variables always filled during an event.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* id of the wiimote
|
||||||
|
* @param connect
|
||||||
|
* true if the wiimote is connected
|
||||||
|
* @param irState
|
||||||
|
* true if ir is active
|
||||||
|
* @param rumbleState
|
||||||
|
* true if rumble is active
|
||||||
|
* @param motionSensingState
|
||||||
|
* true if accelerometer is active
|
||||||
|
* @param orientationThreshold
|
||||||
|
* value of the minimum angle between two events with the
|
||||||
|
* accelerometer
|
||||||
|
* @param continuousState
|
||||||
|
* true if continuous flag is activated
|
||||||
|
* @param smoothingState
|
||||||
|
* true if smoothing flag is activated
|
||||||
*/
|
*/
|
||||||
void setMotionSensingActive() {
|
void setPermanentStatus(int id, boolean connect, boolean irState,
|
||||||
this.isMotionSensingActive = true;
|
boolean rumbleState, boolean motionSensingState,
|
||||||
}
|
float orientationThreshold, boolean continuousState,
|
||||||
|
boolean smoothingState) {
|
||||||
/**
|
wiimoteId = id;
|
||||||
* Set the motion sensing flag to inactive.
|
connected = connect;
|
||||||
*/
|
isIrActive = irState;
|
||||||
void setMotionSensingInactive() {
|
isRumbleActive = rumbleState;
|
||||||
this.isMotionSensingActive = false;
|
isMotionSensingActive = motionSensingState;
|
||||||
|
this.orientationThreshold = orientationThreshold;
|
||||||
|
isContinuousActive = continuousState;
|
||||||
|
isSmoothingActive = smoothingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -448,20 +372,6 @@ public class WiiMoteEvent {
|
|||||||
return orientation;
|
return orientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set orientation of the wiimote.
|
|
||||||
*
|
|
||||||
* @param r
|
|
||||||
* roll
|
|
||||||
* @param p
|
|
||||||
* pitch
|
|
||||||
* @param y
|
|
||||||
* yaw
|
|
||||||
*/
|
|
||||||
void setOrientation(float r, float p, float y) {
|
|
||||||
this.orientation = new Orientation(r, p, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the gravity force.
|
* Get the gravity force.
|
||||||
*
|
*
|
||||||
@@ -472,8 +382,14 @@ public class WiiMoteEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the gravity force.
|
* Set orientation and gravity force.
|
||||||
*
|
*
|
||||||
|
* @param r
|
||||||
|
* roll
|
||||||
|
* @param p
|
||||||
|
* pitch
|
||||||
|
* @param ya
|
||||||
|
* yaw
|
||||||
* @param x
|
* @param x
|
||||||
* gravity force on x axis
|
* gravity force on x axis
|
||||||
* @param y
|
* @param y
|
||||||
@@ -481,7 +397,9 @@ public class WiiMoteEvent {
|
|||||||
* @param z
|
* @param z
|
||||||
* gravity force on z axis
|
* gravity force on z axis
|
||||||
*/
|
*/
|
||||||
void setGforce(float x, float y, float z) {
|
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);
|
this.gforce = new GForce(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -667,7 +585,7 @@ public class WiiMoteEvent {
|
|||||||
out += "/*********** WIIMOTE ID :" + wiimoteId + " ********/\n";
|
out += "/*********** WIIMOTE ID :" + wiimoteId + " ********/\n";
|
||||||
out += "--- connected : " + connected + "\n";
|
out += "--- connected : " + connected + "\n";
|
||||||
out += "--- Battery level : " + batteryLevel + "\n";
|
out += "--- Battery level : " + batteryLevel + "\n";
|
||||||
out += "= --- Leds : " + leds + "\n";
|
out += "--- Leds : " + leds + "\n";
|
||||||
out += "--- Speaker enabled : " + isSpeakerEnabled + "\n";
|
out += "--- Speaker enabled : " + isSpeakerEnabled + "\n";
|
||||||
out += "--- Attachment ? : " + isThereAttachment + "\n";
|
out += "--- Attachment ? : " + isThereAttachment + "\n";
|
||||||
out += "--- Rumble ? : " + isRumbleActive + "\n";
|
out += "--- Rumble ? : " + isRumbleActive + "\n";
|
||||||
|
|||||||
@@ -338,32 +338,32 @@ public class WiiUseApiManager extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Add WiiUseApiListener to the listeners list.
|
||||||
* @param listener
|
* @param listener a WiiUseApiListener
|
||||||
*/
|
*/
|
||||||
public void addWiiUseApiListener(WiiUseApiListener listener) {
|
public void addWiiUseApiListener(WiiUseApiListener listener) {
|
||||||
listeners.add(WiiUseApiListener.class, listener);
|
listeners.add(WiiUseApiListener.class, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Remove WiiUseApiListener from the listeners list.
|
||||||
* @param listener
|
* @param listener a WiiUseApiListener
|
||||||
*/
|
*/
|
||||||
public void removeWiiUseApiListener(WiiUseApiListener listener) {
|
public void removeWiiUseApiListener(WiiUseApiListener listener) {
|
||||||
listeners.remove(WiiUseApiListener.class, listener);
|
listeners.remove(WiiUseApiListener.class, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Get the list of WiiUseApiListeners.
|
||||||
* @return
|
* @return the list of WiiUseApiListeners.
|
||||||
*/
|
*/
|
||||||
public WiiUseApiListener[] getWiiUseApiListeners() {
|
public WiiUseApiListener[] getWiiUseApiListeners() {
|
||||||
return listeners.getListeners(WiiUseApiListener.class);
|
return listeners.getListeners(WiiUseApiListener.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Notify WiiUseApiListeners that an event occured.
|
||||||
* @param evt
|
* @param evt WiimoteEvent occured
|
||||||
*/
|
*/
|
||||||
public void notifyWiiUseApiListener(WiiMoteEvent evt) {
|
public void notifyWiiUseApiListener(WiiMoteEvent evt) {
|
||||||
for (WiiUseApiListener listener : getWiiUseApiListeners()) {
|
for (WiiUseApiListener listener : getWiiUseApiListeners()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user