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:
@@ -3,12 +3,15 @@ package tests;
|
|||||||
import java.awt.AWTException;
|
import java.awt.AWTException;
|
||||||
import java.awt.Robot;
|
import java.awt.Robot;
|
||||||
import java.awt.event.InputEvent;
|
import java.awt.event.InputEvent;
|
||||||
|
|
||||||
import wiiusej.Point2DInteger;
|
import wiiusej.Point2DInteger;
|
||||||
import wiiusej.WiiMoteEvent;
|
|
||||||
import wiiusej.WiiUseApiListener;
|
|
||||||
import wiiusej.WiiUseApiManager;
|
import wiiusej.WiiUseApiManager;
|
||||||
import wiiusej.Wiimote;
|
import wiiusej.Wiimote;
|
||||||
import wiiusej.WiimoteListener;
|
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||||
|
import wiiusej.wiiuseapievents.StatusEvent;
|
||||||
|
import wiiusej.wiiuseapievents.WiiMoteEvent;
|
||||||
|
import wiiusej.wiiuseapievents.WiiUseApiListener;
|
||||||
|
import wiiusej.wiiuseapievents.WiimoteListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class used to test this API.
|
* This class used to test this API.
|
||||||
@@ -44,209 +47,187 @@ public class Tests implements WiimoteListener {
|
|||||||
public void wiimoteEvent(WiiMoteEvent e) {
|
public void wiimoteEvent(WiiMoteEvent e) {
|
||||||
|
|
||||||
if (dump == DISPLAY_EACH_VALUE) {
|
if (dump == DISPLAY_EACH_VALUE) {
|
||||||
if (e.isConnected()) {
|
// System.out.println("*********** WIIMOTE ID : "+
|
||||||
// System.out.println("*********** WIIMOTE ID : "+
|
// e.getWiimoteId() + " **************");
|
||||||
// e.getWiimoteId() + " **************");
|
/* button ONE */
|
||||||
/* button ONE */
|
if (e.isButtonOneJustPressed()) {
|
||||||
if (e.isButtonOneJustPressed()) {
|
System.out.println("button one pressed");
|
||||||
System.out.println("button one pressed");
|
}
|
||||||
}
|
if (e.isButtonOneHeld()) {
|
||||||
if (e.isButtonOneHeld()) {
|
System.out.println("button one held");
|
||||||
System.out.println("button one held");
|
}
|
||||||
}
|
if (e.isButtonOneJustReleased()) {
|
||||||
if (e.isButtonOneJustReleased()) {
|
System.out.println("button one released");
|
||||||
System.out.println("button one released");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* button TWO */
|
/* button TWO */
|
||||||
if (e.isButtonTwoJustPressed()) {
|
if (e.isButtonTwoJustPressed()) {
|
||||||
System.out.println("button two pressed");
|
System.out.println("button two pressed");
|
||||||
}
|
}
|
||||||
if (e.isButtonTwoHeld()) {
|
if (e.isButtonTwoHeld()) {
|
||||||
System.out.println("button two held");
|
System.out.println("button two held");
|
||||||
}
|
}
|
||||||
if (e.isButtonTwoJustReleased()) {
|
if (e.isButtonTwoJustReleased()) {
|
||||||
System.out.println("button two released");
|
System.out.println("button two released");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* button A */
|
/* button A */
|
||||||
if (e.isButtonAJustPressed()) {
|
if (e.isButtonAJustPressed()) {
|
||||||
System.out.println("button A pressed");
|
System.out.println("button A pressed");
|
||||||
}
|
}
|
||||||
if (e.isButtonAHeld()) {
|
if (e.isButtonAHeld()) {
|
||||||
System.out.println("button A held");
|
System.out.println("button A held");
|
||||||
}
|
}
|
||||||
if (e.isButtonAJustReleased()) {
|
if (e.isButtonAJustReleased()) {
|
||||||
System.out.println("button A released");
|
System.out.println("button A released");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* button B */
|
/* button B */
|
||||||
if (e.isButtonBJustPressed()) {
|
if (e.isButtonBJustPressed()) {
|
||||||
System.out.println("button B pressed");
|
System.out.println("button B pressed");
|
||||||
}
|
}
|
||||||
if (e.isButtonBHeld()) {
|
if (e.isButtonBHeld()) {
|
||||||
System.out.println("button B held");
|
System.out.println("button B held");
|
||||||
}
|
}
|
||||||
if (e.isButtonBJustReleased()) {
|
if (e.isButtonBJustReleased()) {
|
||||||
System.out.println("button B released");
|
System.out.println("button B released");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* button LEFT */
|
/* button LEFT */
|
||||||
if (e.isButtonLeftJustPressed()) {
|
if (e.isButtonLeftJustPressed()) {
|
||||||
System.out.println("button Left pressed");
|
System.out.println("button Left pressed");
|
||||||
}
|
}
|
||||||
if (e.isButtonLeftHeld()) {
|
if (e.isButtonLeftHeld()) {
|
||||||
System.out.println("button Left held");
|
System.out.println("button Left held");
|
||||||
}
|
}
|
||||||
if (e.isButtonLeftJustReleased()) {
|
if (e.isButtonLeftJustReleased()) {
|
||||||
System.out.println("button Left released");
|
System.out.println("button Left released");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* button RIGHT */
|
/* button RIGHT */
|
||||||
if (e.isButtonRightJustPressed()) {
|
if (e.isButtonRightJustPressed()) {
|
||||||
System.out.println("button Right pressed");
|
System.out.println("button Right pressed");
|
||||||
}
|
}
|
||||||
if (e.isButtonRightHeld()) {
|
if (e.isButtonRightHeld()) {
|
||||||
System.out.println("button Right held");
|
System.out.println("button Right held");
|
||||||
}
|
}
|
||||||
if (e.isButtonRightJustReleased()) {
|
if (e.isButtonRightJustReleased()) {
|
||||||
System.out.println("button Right released");
|
System.out.println("button Right released");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* button UP */
|
/* button UP */
|
||||||
if (e.isButtonUpJustPressed()) {
|
if (e.isButtonUpJustPressed()) {
|
||||||
System.out.println("button UP pressed");
|
System.out.println("button UP pressed");
|
||||||
}
|
}
|
||||||
if (e.isButtonUpHeld()) {
|
if (e.isButtonUpHeld()) {
|
||||||
System.out.println("button UP held");
|
System.out.println("button UP held");
|
||||||
}
|
}
|
||||||
if (e.isButtonUpJustReleased()) {
|
if (e.isButtonUpJustReleased()) {
|
||||||
System.out.println("button UP released");
|
System.out.println("button UP released");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* button DOWN */
|
/* button DOWN */
|
||||||
if (e.isButtonDownJustPressed()) {
|
if (e.isButtonDownJustPressed()) {
|
||||||
System.out.println("button DOWN pressed");
|
System.out.println("button DOWN pressed");
|
||||||
}
|
}
|
||||||
if (e.isButtonDownHeld()) {
|
if (e.isButtonDownHeld()) {
|
||||||
System.out.println("button DOWN held");
|
System.out.println("button DOWN held");
|
||||||
}
|
}
|
||||||
if (e.isButtonDownJustReleased()) {
|
if (e.isButtonDownJustReleased()) {
|
||||||
System.out.println("button DOWN released");
|
System.out.println("button DOWN released");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* button MINUS */
|
/* button MINUS */
|
||||||
if (e.isButtonMinusJustPressed()) {
|
if (e.isButtonMinusJustPressed()) {
|
||||||
System.out.println("button MINUS pressed");
|
System.out.println("button MINUS pressed");
|
||||||
}
|
}
|
||||||
if (e.isButtonMinusHeld()) {
|
if (e.isButtonMinusHeld()) {
|
||||||
System.out.println("button MINUS held");
|
System.out.println("button MINUS held");
|
||||||
}
|
}
|
||||||
if (e.isButtonMinusJustReleased()) {
|
if (e.isButtonMinusJustReleased()) {
|
||||||
System.out.println("button MINUS released");
|
System.out.println("button MINUS released");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* button PLUS */
|
/* button PLUS */
|
||||||
if (e.isButtonPlusJustPressed()) {
|
if (e.isButtonPlusJustPressed()) {
|
||||||
System.out.println("button PLUS pressed");
|
System.out.println("button PLUS pressed");
|
||||||
}
|
}
|
||||||
if (e.isButtonPlusHeld()) {
|
if (e.isButtonPlusHeld()) {
|
||||||
System.out.println("button PLUS held");
|
System.out.println("button PLUS held");
|
||||||
}
|
}
|
||||||
if (e.isButtonPlusJustReleased()) {
|
if (e.isButtonPlusJustReleased()) {
|
||||||
System.out.println("button PLUS released");
|
System.out.println("button PLUS released");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* button HOME */
|
/* button HOME */
|
||||||
if (e.isButtonHomeJustPressed()) {
|
if (e.isButtonHomeJustPressed()) {
|
||||||
System.out.println("button HOME pressed");
|
System.out.println("button HOME pressed");
|
||||||
}
|
}
|
||||||
if (e.isButtonHomeHeld()) {
|
if (e.isButtonHomeHeld()) {
|
||||||
System.out.println("button HOME held");
|
System.out.println("button HOME held");
|
||||||
}
|
}
|
||||||
if (e.isButtonHomeJustReleased()) {
|
if (e.isButtonHomeJustReleased()) {
|
||||||
System.out.println("button HOME released");
|
System.out.println("button HOME released");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get status */
|
/* get status */
|
||||||
if (e.isButtonMinusJustPressed() && e.isButtonPlusJustPressed()) {
|
if (e.isButtonMinusJustPressed() && e.isButtonPlusJustPressed()) {
|
||||||
wiimote.getStatus();
|
wiimote.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Activate rumble */
|
/* Activate rumble */
|
||||||
if (e.isButtonOneJustPressed()) {
|
if (e.isButtonOneJustPressed()) {
|
||||||
System.out.println("Rumble Activated");
|
System.out.println("Rumble Activated");
|
||||||
wiimote.activateRumble();
|
wiimote.activateRumble();
|
||||||
}
|
}
|
||||||
if (e.isButtonTwoJustPressed()) {
|
if (e.isButtonTwoJustPressed()) {
|
||||||
System.out.println("Rumble Deactivated");
|
System.out.println("Rumble Deactivated");
|
||||||
wiimote.deactivateRumble();
|
wiimote.deactivateRumble();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Activate IR Tracking */
|
/* Activate IR Tracking */
|
||||||
if (e.isButtonAJustPressed()) {
|
if (e.isButtonAJustPressed()) {
|
||||||
System.out.println("IR Activated");
|
System.out.println("IR Activated");
|
||||||
wiimote.activateIRTRacking();
|
wiimote.activateIRTRacking();
|
||||||
}
|
}
|
||||||
if (e.isButtonBJustPressed()) {
|
if (e.isButtonBJustPressed()) {
|
||||||
System.out.println("IR Deactivated");
|
System.out.println("IR Deactivated");
|
||||||
wiimote.deactivateIRTRacking();
|
wiimote.deactivateIRTRacking();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Activate Motion sensing */
|
/* Activate Motion sensing */
|
||||||
if (e.isButtonPlusJustPressed()) {
|
if (e.isButtonPlusJustPressed()) {
|
||||||
System.out.println("Motion sensing Activated");
|
System.out.println("Motion sensing Activated");
|
||||||
wiimote.activateMotionSensing();
|
wiimote.activateMotionSensing();
|
||||||
}
|
}
|
||||||
if (e.isButtonMinusJustPressed()) {
|
if (e.isButtonMinusJustPressed()) {
|
||||||
System.out.println("Motion sensing Deactivated");
|
System.out.println("Motion sensing Deactivated");
|
||||||
wiimote.deactivateMotionSensing();
|
wiimote.deactivateMotionSensing();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* display status */
|
/* display ir points */
|
||||||
if (e.getBatteryLevel() != -1) {
|
if (e.isIrActive()) {
|
||||||
System.out
|
Point2DInteger[] list = e.getIRPoints();
|
||||||
.println("battery level : " + e.getBatteryLevel());
|
for (int i = 0; i < list.length; i++) {
|
||||||
System.out.println("= --- Leds : " + e.getLeds() + "\n");
|
if (list[i] != null)
|
||||||
System.out.println("= --- Rumble : " + e.isRumbleActive()
|
System.out.print("Point :(" + list[i].getX() + ","
|
||||||
+ "\n");
|
+ list[i].getY() + ") ");
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
|
||||||
/* display ir points */
|
/* display motion sensing */
|
||||||
if (e.isIrActive()) {
|
if (e.isMotionSensingActive()) {
|
||||||
Point2DInteger[] list = e.getIRPoints();
|
System.out.println("Motion Sensing :" + e.getOrientation()
|
||||||
for (int i = 0; i < list.length; i++) {
|
+ " , " + e.getGforce());
|
||||||
if (list[i] != null)
|
}
|
||||||
System.out.print("Point :(" + list[i].getX() + ","
|
|
||||||
+ list[i].getY() + ") ");
|
|
||||||
}
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* display motion sensing */
|
/* leave test */
|
||||||
if (e.isMotionSensingActive()) {
|
if (e.isButtonHomeJustPressed()) {
|
||||||
System.out.println("Motion Sensing :" + e.getOrientation()
|
System.out.println("LEAVING TEST");
|
||||||
+ " , " + e.getGforce());
|
|
||||||
}
|
|
||||||
|
|
||||||
/* leave test */
|
|
||||||
if (e.isButtonHomeJustPressed()) {
|
|
||||||
System.out.println("LEAVING TEST");
|
|
||||||
wiimote.disconnect();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println(" WIIMOTE ID : " + e.getWiimoteId()
|
|
||||||
+ " DISCONNECTED !!!!!");
|
|
||||||
wiimote.disconnect();
|
wiimote.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (dump == DUMP) {
|
} else if (dump == DUMP) {
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
/* Activate all */
|
/* Activate all */
|
||||||
@@ -337,6 +318,10 @@ public class Tests implements WiimoteListener {
|
|||||||
System.out.println("Threshold orientation 0.5 degrees");
|
System.out.println("Threshold orientation 0.5 degrees");
|
||||||
wiimote.setOrientationThreshold((float) 0.5);
|
wiimote.setOrientationThreshold((float) 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@TODO add accelereation threshold test, add alpha smoothing test
|
||||||
|
|
||||||
|
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
|
|
||||||
/* leave test */
|
/* leave test */
|
||||||
@@ -347,10 +332,10 @@ public class Tests implements WiimoteListener {
|
|||||||
} else if (dump == TEST_LEDS) {
|
} else if (dump == TEST_LEDS) {
|
||||||
wiimote.activateMotionSensing();
|
wiimote.activateMotionSensing();
|
||||||
if (e.isButtonUpJustPressed()) {
|
if (e.isButtonUpJustPressed()) {
|
||||||
wiimote.setLeds(true, false, false, false);
|
wiimote.setLeds(true, false, false, false);
|
||||||
}
|
}
|
||||||
if (e.isButtonDownJustPressed()) {
|
if (e.isButtonDownJustPressed()) {
|
||||||
wiimote.setLeds(false, true, false, false);
|
wiimote.setLeds(false, true, false, false);
|
||||||
}
|
}
|
||||||
if (e.isButtonLeftJustPressed()) {
|
if (e.isButtonLeftJustPressed()) {
|
||||||
wiimote.setLeds(false, false, true, false);
|
wiimote.setLeds(false, false, true, false);
|
||||||
@@ -367,19 +352,29 @@ public class Tests implements WiimoteListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void statusEvent(StatusEvent e) {
|
||||||
|
//Display status variables
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnectionEvent(DisconnectionEvent e) {
|
||||||
|
System.out.println(e.getWiimoteId()+" notify it's been disconnected !!");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args
|
* @param args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes();
|
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(4);
|
||||||
if (wiimotes.length>0){
|
if (wiimotes.length > 0) {
|
||||||
System.out.println(wiimotes[0]);
|
System.out.println(wiimotes[0]);
|
||||||
Tests tests = new Tests(wiimotes[0]);
|
Tests tests = new Tests(wiimotes[0]);
|
||||||
}else{
|
} else {
|
||||||
System.out.println("No wiimotes found !!!");
|
System.out.println("No wiimotes found !!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// java.util.Timer timer = new java.util.Timer();
|
// java.util.Timer timer = new java.util.Timer();
|
||||||
// timer.scheduleAtFixedRate(new LedsTask(), 0, 100);
|
// timer.scheduleAtFixedRate(new LedsTask(), 0, 100);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package wiiusej;
|
package wiiusej;
|
||||||
|
|
||||||
|
import wiiusej.wiiuseapievents.EventsGatherer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton used to manipulate WiiUse Api.
|
* Singleton used to manipulate WiiUse Api.
|
||||||
* @author gduche
|
* @author gduche
|
||||||
@@ -21,21 +23,14 @@ public class WiiUseApi {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the library.
|
|
||||||
*
|
|
||||||
* @return 0 if there is an error, 1 if everything is ok.
|
|
||||||
*/
|
|
||||||
native int loadLibrary();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to connect to 2 wiimotes. Make them rumble to show they are
|
* Try to connect to 2 wiimotes. Make them rumble to show they are
|
||||||
* connected.
|
* connected.
|
||||||
*
|
* @param nb number of wiimotes to connect
|
||||||
* @return 0 if there is an error otherwise it returns the number of
|
* @return 0 if there is an error otherwise it returns the number of
|
||||||
* wiimotes connected.
|
* wiimotes connected.
|
||||||
*/
|
*/
|
||||||
native int doConnections();
|
native int doConnections(int nb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close connection to the wiimote with the given id.
|
* Close connection to the wiimote with the given id.
|
||||||
@@ -103,6 +98,26 @@ public class WiiUseApi {
|
|||||||
*/
|
*/
|
||||||
native void setOrientThreshold(int id, float angle);
|
native void setOrientThreshold(int id, float angle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set how much acceleration must change to generate an event.
|
||||||
|
* @param id id of the wiimote concerned
|
||||||
|
* @param value minimum value detected by an event
|
||||||
|
*/
|
||||||
|
native void setAccelThreshold(int id, float value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set alpha smoothing parameter for the given id.
|
||||||
|
* @param id id of the wiimote concerned
|
||||||
|
* @param value alpha smoothing value
|
||||||
|
*/
|
||||||
|
native void setSmoothAlpha(int id, float value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to resync with the wiimote by starting a new handshake.
|
||||||
|
* @param id id of the wiimote concerned
|
||||||
|
*/
|
||||||
|
native void reSync(int id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make the the accelerometers give smoother results.
|
* Make the the accelerometers give smoother results.
|
||||||
* This is set by default.
|
* This is set by default.
|
||||||
@@ -137,17 +152,18 @@ public class WiiUseApi {
|
|||||||
native void getStatus(int id);
|
native void getStatus(int id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get status and values from the wiimotes and send it through callbacks.
|
* Check for new Events and Get it.
|
||||||
*
|
*
|
||||||
* @param mote The WiimoteEvent object to fill with the datas.
|
* @param gath the object where we store all the new events.
|
||||||
*/
|
*/
|
||||||
native void specialPoll(WiiMoteEvent mote);
|
native void specialPoll(EventsGatherer gath);
|
||||||
|
|
||||||
|
|
||||||
/* Tests */
|
/* Tests */
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
/* Test JNI Side */
|
/* Test JNI Side */
|
||||||
|
/*
|
||||||
WiiUseApi manager = new WiiUseApi();
|
WiiUseApi manager = new WiiUseApi();
|
||||||
|
|
||||||
int value = manager.loadLibrary();
|
int value = manager.loadLibrary();
|
||||||
@@ -155,8 +171,8 @@ public class WiiUseApi {
|
|||||||
|
|
||||||
value = manager.doConnections();
|
value = manager.doConnections();
|
||||||
System.out.println("doConnections : " + value);
|
System.out.println("doConnections : " + value);
|
||||||
|
WiiMoteEvent mote = new WiiMoteEvent();
|
||||||
|
|
||||||
WiiMoteEvent mote = new WiiMoteEvent();
|
|
||||||
|
|
||||||
manager.getStatus(1);
|
manager.getStatus(1);
|
||||||
System.out.println("Status : \n" + mote);
|
System.out.println("Status : \n" + mote);
|
||||||
@@ -168,6 +184,7 @@ public class WiiUseApi {
|
|||||||
System.out.println(mote);
|
System.out.println(mote);
|
||||||
mote.EmptyIRPoints();
|
mote.EmptyIRPoints();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
// manager.closeConnectionsAndShutDown();
|
// manager.closeConnectionsAndShutDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package wiiusej;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public interface WiiUseApiListener extends java.util.EventListener {
|
|
||||||
|
|
||||||
void wiimoteEvent(WiiMoteEvent e);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package wiiusej;
|
package wiiusej;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
@@ -6,6 +6,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
|
|
||||||
import javax.swing.event.EventListenerList;
|
import javax.swing.event.EventListenerList;
|
||||||
|
|
||||||
|
import wiiusej.wiiuseapievents.EventsGatherer;
|
||||||
|
import wiiusej.wiiuseapievents.WiiUseApiEvent;
|
||||||
|
import wiiusej.wiiuseapievents.WiiUseApiListener;
|
||||||
|
import wiiusej.wiiuseapirequest.FloatValueRequest;
|
||||||
|
import wiiusej.wiiuseapirequest.LedsRequest;
|
||||||
|
import wiiusej.wiiuseapirequest.WiiUseApiRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that manage the use of Wiiuse API.
|
* Class that manage the use of Wiiuse API.
|
||||||
*
|
*
|
||||||
@@ -22,10 +29,10 @@ public class WiiUseApiManager extends Thread {
|
|||||||
|
|
||||||
private WiiUseApi wiiuse = WiiUseApi.getInstance();
|
private WiiUseApi wiiuse = WiiUseApi.getInstance();
|
||||||
|
|
||||||
private boolean loaded = false;
|
|
||||||
|
|
||||||
private int connected = -1;
|
private int connected = -1;
|
||||||
|
|
||||||
|
private int nbMaxWiimotes = -1;
|
||||||
|
|
||||||
private AtomicBoolean running = new AtomicBoolean(false);
|
private AtomicBoolean running = new AtomicBoolean(false);
|
||||||
|
|
||||||
private ConcurrentLinkedQueue<WiiUseApiRequest> requests = new ConcurrentLinkedQueue<WiiUseApiRequest>();
|
private ConcurrentLinkedQueue<WiiUseApiRequest> requests = new ConcurrentLinkedQueue<WiiUseApiRequest>();
|
||||||
@@ -35,68 +42,50 @@ public class WiiUseApiManager extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get wiimotes.
|
* Get wiimotes. Load library if necessary. Connect to wiimotes if
|
||||||
* Load library if necessary.
|
* necessary. Start polling if necessary. Return an array with the connected
|
||||||
* Connect to wiimotes if necessary.
|
* wiimotes.
|
||||||
* Start polling if necessary.
|
*
|
||||||
* Return an array with the connected wiimotes.
|
* @param nb
|
||||||
|
* try to connect nb wiimotes
|
||||||
* @return an array with connected wiimotes or NULL.
|
* @return an array with connected wiimotes or NULL.
|
||||||
*/
|
*/
|
||||||
public static Wiimote[] getWiimotes() {
|
public static Wiimote[] getWiimotes(int nb) {
|
||||||
WiiUseApiManager manager = getInstance();
|
WiiUseApiManager manager = getInstance();
|
||||||
if (!manager.loaded){
|
if (manager.connected < 0) {
|
||||||
manager.loadLibrary();
|
int nbWiimotes = manager.connectWiimotes(nb);
|
||||||
}
|
|
||||||
if (manager.connected<0){
|
|
||||||
int nbWiimotes = manager.connectWiimotes();
|
|
||||||
manager.wiimotes = new Wiimote[nbWiimotes];
|
manager.wiimotes = new Wiimote[nbWiimotes];
|
||||||
for (int i=0; i<nbWiimotes; i++){
|
for (int i = 0; i < nbWiimotes; i++) {
|
||||||
Wiimote wim = new Wiimote(i,manager);
|
Wiimote wim = new Wiimote(i, manager);
|
||||||
manager.wiimotes[i] = wim;
|
manager.wiimotes[i] = wim;
|
||||||
manager.addWiiUseApiListener(wim);
|
manager.addWiiUseApiListener(wim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (manager.connected == 0){
|
if (manager.connected == 0) {
|
||||||
return new Wiimote[0];
|
return new Wiimote[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!manager.isAlive()) manager.start();
|
if (!manager.isAlive())
|
||||||
|
manager.start();
|
||||||
|
|
||||||
return manager.wiimotes;
|
return manager.wiimotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the wiimote library.
|
|
||||||
*
|
|
||||||
* @return false if the library is not loaded true otherwise.
|
|
||||||
*/
|
|
||||||
public boolean loadLibrary() {
|
|
||||||
if (!loaded) {// not yet loaded try to load it
|
|
||||||
int load = wiiuse.loadLibrary();
|
|
||||||
if (load > 0) {
|
|
||||||
loaded = true;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
loaded = false;
|
|
||||||
System.out.println("Error loading the Wiimote library !!!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// already loaded
|
|
||||||
return loaded;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect wiimote and get the number of wiimotes connected. Supposed to be
|
* Connect wiimote and get the number of wiimotes connected. Supposed to be
|
||||||
* used once.
|
* used once.
|
||||||
*
|
*
|
||||||
|
* @param nb
|
||||||
|
* try to connect nb wiimotes
|
||||||
* @return 0 if nothing connected or the number of wiimotes connected.
|
* @return 0 if nothing connected or the number of wiimotes connected.
|
||||||
*/
|
*/
|
||||||
public int connectWiimotes() {
|
public int connectWiimotes(int nb) {
|
||||||
if (connected < 0 && loaded) {
|
nbMaxWiimotes = nb;
|
||||||
connected = wiiuse.doConnections();
|
if (connected < 0) {
|
||||||
// System.out.println(connected + " wiimote(s) connected !!!");
|
connected = wiiuse.doConnections(nb);
|
||||||
|
// @TODO
|
||||||
|
System.out.println(connected + " wiimote(s) connected !!!");
|
||||||
return connected;
|
return connected;
|
||||||
} else {// library not loaded, no wiimotes connected
|
} else {// library not loaded, no wiimotes connected
|
||||||
return 0;
|
return 0;
|
||||||
@@ -110,8 +99,11 @@ public class WiiUseApiManager extends Thread {
|
|||||||
* id of the wiimote to disconnect.
|
* id of the wiimote to disconnect.
|
||||||
*/
|
*/
|
||||||
public void closeConnection(int id) {
|
public void closeConnection(int id) {
|
||||||
|
removeWiiUseApiListener(wiimotes[id]);
|
||||||
|
wiimotes[id] = null;
|
||||||
requests.add(new WiiUseApiRequest(id,
|
requests.add(new WiiUseApiRequest(id,
|
||||||
WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST));
|
WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST));
|
||||||
|
System.out.println("Wiimote " + id + " disconnected !");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,7 +120,6 @@ public class WiiUseApiManager extends Thread {
|
|||||||
*/
|
*/
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
running.set(false);
|
running.set(false);
|
||||||
loaded = false;
|
|
||||||
wiiuse.shutdownApi();
|
wiiuse.shutdownApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,10 +261,36 @@ public class WiiUseApiManager extends Thread {
|
|||||||
* threshold in degrees
|
* threshold in degrees
|
||||||
*/
|
*/
|
||||||
public void setOrientationThreshold(int id, float th) {
|
public void setOrientationThreshold(int id, float th) {
|
||||||
requests.add(new OrientThresholdRequest(id,
|
requests.add(new FloatValueRequest(id,
|
||||||
WiiUseApiRequest.WIIUSE_ORIENT_THRESHOLHD_REQUEST, th));
|
WiiUseApiRequest.WIIUSE_ORIENT_THRESHOLHD_REQUEST, th));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the acceleration threshold for the given id.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* id of the wiimote
|
||||||
|
* @param th
|
||||||
|
* threshold
|
||||||
|
*/
|
||||||
|
public void setAccelerationThreshold(int id, float th) {
|
||||||
|
requests.add(new FloatValueRequest(id,
|
||||||
|
WiiUseApiRequest.WIIUSE_ACCEL_THRESHOLHD_REQUEST, th));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set alpha smoothing for the given id.
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* id of the wiimote
|
||||||
|
* @param th
|
||||||
|
* threshold
|
||||||
|
*/
|
||||||
|
public void setAlphaSmoothing(int id, float th) {
|
||||||
|
requests.add(new FloatValueRequest(id,
|
||||||
|
WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST, th));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Status for the wiimote for the given id.
|
* Get Status for the wiimote for the given id.
|
||||||
*
|
*
|
||||||
@@ -288,10 +305,10 @@ public class WiiUseApiManager extends Thread {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
if (loaded && (connected > 0)) {
|
if (connected > 0) {
|
||||||
running.set(true);
|
running.set(true);
|
||||||
|
|
||||||
WiiMoteEvent evt = new WiiMoteEvent();
|
EventsGatherer gather = new EventsGatherer(nbMaxWiimotes);
|
||||||
|
|
||||||
// Start polling and tell the observers when there Wiimote events
|
// Start polling and tell the observers when there Wiimote events
|
||||||
while (running.get()) {
|
while (running.get()) {
|
||||||
@@ -300,10 +317,14 @@ public class WiiUseApiManager extends Thread {
|
|||||||
int id = req.getId();
|
int id = req.getId();
|
||||||
if (req.getRequestType() == WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST) {
|
if (req.getRequestType() == WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST) {
|
||||||
/* Close connections requests */
|
/* Close connections requests */
|
||||||
removeWiiUseApiListener(wiimotes[id]);
|
|
||||||
wiimotes[id]=null;
|
|
||||||
wiiuse.closeConnection(id);
|
wiiuse.closeConnection(id);
|
||||||
|
|
||||||
connected--;
|
connected--;
|
||||||
|
if (connected == 0) {// stop this thread if there is
|
||||||
|
// no more wiimotes connected.
|
||||||
|
System.out.println("No more wiimotes connected !!!");
|
||||||
|
shutdown();
|
||||||
|
}
|
||||||
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_STATUS_REQUEST) {
|
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_STATUS_REQUEST) {
|
||||||
/* Status requests */
|
/* Status requests */
|
||||||
wiiuse.getStatus(id);
|
wiiuse.getStatus(id);
|
||||||
@@ -343,42 +364,44 @@ public class WiiUseApiManager extends Thread {
|
|||||||
/* Deactivate continuous requests */
|
/* Deactivate continuous requests */
|
||||||
wiiuse.deactivateContinuous(id);
|
wiiuse.deactivateContinuous(id);
|
||||||
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ORIENT_THRESHOLHD_REQUEST) {
|
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ORIENT_THRESHOLHD_REQUEST) {
|
||||||
/* set orientation request */
|
/* set orientation threshold request */
|
||||||
wiiuse.setOrientThreshold(req.getId(),
|
wiiuse.setOrientThreshold(req.getId(),
|
||||||
((OrientThresholdRequest) req).getThresholhd());
|
((FloatValueRequest) req).getFloatValue());
|
||||||
|
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ACCEL_THRESHOLHD_REQUEST) {
|
||||||
|
/* set acceleration threshold request */
|
||||||
|
wiiuse.setOrientThreshold(req.getId(),
|
||||||
|
((FloatValueRequest) req).getFloatValue());
|
||||||
|
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST) {
|
||||||
|
/* set alpha smoothing request */
|
||||||
|
wiiuse.setOrientThreshold(req.getId(),
|
||||||
|
((FloatValueRequest) req).getFloatValue());
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Bad request to Wiiuse API !!!!!");
|
System.out.println("Bad request to Wiiuse API !!!!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Polling */
|
/* Polling */
|
||||||
wiiuse.specialPoll(evt);
|
wiiuse.specialPoll(gather);
|
||||||
|
|
||||||
if (evt.getWiimoteId() != -1) {//event filled
|
/* deal with events gathered in Wiiuse API */
|
||||||
if (!evt.isConnected()) {// check if it was a
|
for (WiiUseApiEvent evt : gather.getEvents()) {
|
||||||
// disconnection
|
if (evt.getWiimoteId() != -1) {// event filled
|
||||||
connected--;
|
// there is an event notify observers
|
||||||
removeWiiUseApiListener(wiimotes[evt.getWiimoteId()]);
|
|
||||||
wiimotes[evt.getWiimoteId()]=null;
|
|
||||||
System.out.println("Wiimote " + evt.getWiimoteId()
|
|
||||||
+ " disconnected !");
|
|
||||||
} else {//there is an event notify observers
|
|
||||||
// not a disconnection notify listeners
|
|
||||||
notifyWiiUseApiListener(evt);
|
notifyWiiUseApiListener(evt);
|
||||||
// create a new event to be filled
|
if (evt.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT) {
|
||||||
evt = new WiiMoteEvent();
|
// check if it was a disconnection
|
||||||
|
// in this case disconnect the wiimote
|
||||||
|
closeConnection(evt.getWiimoteId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out
|
||||||
|
.println("There is an event with id == -1 ??? there is a problem !!! : "
|
||||||
|
+ evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (connected == 0) {// stop this thread if there is
|
gather.clearEvents();
|
||||||
//no more wiimotes connected.
|
|
||||||
System.out.println("No more wiimotes connected !!!");
|
|
||||||
shutdown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!loaded) {
|
|
||||||
System.out.println("Library not Loaded !");
|
|
||||||
}
|
|
||||||
if (connected <= 0) {
|
if (connected <= 0) {
|
||||||
System.out.println("No wiimotes connected !");
|
System.out.println("No wiimotes connected !");
|
||||||
}
|
}
|
||||||
@@ -421,9 +444,9 @@ public class WiiUseApiManager extends Thread {
|
|||||||
* @param evt
|
* @param evt
|
||||||
* WiimoteEvent occured
|
* WiimoteEvent occured
|
||||||
*/
|
*/
|
||||||
private void notifyWiiUseApiListener(WiiMoteEvent evt) {
|
private void notifyWiiUseApiListener(WiiUseApiEvent evt) {
|
||||||
for (WiiUseApiListener listener : getWiiUseApiListeners()) {
|
for (WiiUseApiListener listener : getWiiUseApiListeners()) {
|
||||||
listener.wiimoteEvent(evt);
|
listener.wiiUseApiEvent(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,13 @@ package wiiusej;
|
|||||||
|
|
||||||
import javax.swing.event.EventListenerList;
|
import javax.swing.event.EventListenerList;
|
||||||
|
|
||||||
|
import wiiusej.wiiuseapievents.DisconnectionEvent;
|
||||||
|
import wiiusej.wiiuseapievents.StatusEvent;
|
||||||
|
import wiiusej.wiiuseapievents.WiiMoteEvent;
|
||||||
|
import wiiusej.wiiuseapievents.WiiUseApiEvent;
|
||||||
|
import wiiusej.wiiuseapievents.WiiUseApiListener;
|
||||||
|
import wiiusej.wiiuseapievents.WiimoteListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that represents a wiimote.
|
* Class that represents a wiimote.
|
||||||
* You can register as an observer of this wiimote to listen events from it.
|
* You can register as an observer of this wiimote to listen events from it.
|
||||||
@@ -11,7 +18,7 @@ import javax.swing.event.EventListenerList;
|
|||||||
*/
|
*/
|
||||||
public class Wiimote implements WiiUseApiListener {
|
public class Wiimote implements WiiUseApiListener {
|
||||||
|
|
||||||
private int id;//wiimote id
|
private int id = -1;//wiimote id
|
||||||
|
|
||||||
private EventListenerList listeners = new EventListenerList();
|
private EventListenerList listeners = new EventListenerList();
|
||||||
|
|
||||||
@@ -141,11 +148,16 @@ public class Wiimote implements WiiUseApiListener {
|
|||||||
manager.getStatus(id);
|
manager.getStatus(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void wiimoteEvent(WiiMoteEvent e) {
|
public void wiiUseApiEvent(WiiUseApiEvent e) {
|
||||||
if (e.getWiimoteId() == id){
|
if (e.getWiimoteId() == id){
|
||||||
notifyWiiMoteEventListeners(e);
|
if (e.getEventType() == WiiUseApiEvent.GENERIC_EVENT){
|
||||||
|
notifyWiiMoteEventListeners((WiiMoteEvent)e);
|
||||||
|
}else if (e.getEventType() == WiiUseApiEvent.STATUS_EVENT){
|
||||||
|
notifyStatusEventListeners((StatusEvent)e);
|
||||||
|
}else if (e.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT){
|
||||||
|
notifyDisconnectionEventListeners((DisconnectionEvent)e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +195,26 @@ public class Wiimote implements WiiUseApiListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify WiimoteListener that a status event occured.
|
||||||
|
* @param evt status event occured
|
||||||
|
*/
|
||||||
|
private void notifyStatusEventListeners(StatusEvent evt) {
|
||||||
|
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||||
|
listener.statusEvent(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify WiimoteListener that a status event occured.
|
||||||
|
* @param evt status event occured
|
||||||
|
*/
|
||||||
|
private void notifyDisconnectionEventListeners(DisconnectionEvent evt) {
|
||||||
|
for (WiimoteListener listener : getWiiMoteEventListeners()) {
|
||||||
|
listener.disconnectionEvent(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Wiimote with ID : "+id;
|
return "Wiimote with ID : "+id;
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
package wiiusej;
|
|
||||||
|
|
||||||
|
|
||||||
public interface WiimoteListener extends java.util.EventListener {
|
|
||||||
|
|
||||||
void wiimoteEvent(WiiMoteEvent e);
|
|
||||||
|
|
||||||
}
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,15 +1,19 @@
|
|||||||
package wiiusej;
|
package wiiusej.wiiuseapievents;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
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.
|
* Class that is a bean to be filled by the wiiuse API.
|
||||||
*
|
*
|
||||||
* @author gduche
|
* @author gduche
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class WiiMoteEvent {
|
public class WiiMoteEvent extends WiiUseApiEvent {
|
||||||
|
|
||||||
/* Buttons MACRO */
|
/* Buttons MACRO */
|
||||||
private static short WIIMOTE_BUTTON_TWO = 0x0001;
|
private static short WIIMOTE_BUTTON_TWO = 0x0001;
|
||||||
@@ -30,34 +34,7 @@ public class WiiMoteEvent {
|
|||||||
private static int WIIMOTE_BUTTON_UNKNOWN = 0x8000;
|
private static int WIIMOTE_BUTTON_UNKNOWN = 0x8000;
|
||||||
private static short WIIMOTE_BUTTON_ALL = 0x1F9F;
|
private static short WIIMOTE_BUTTON_ALL = 0x1F9F;
|
||||||
|
|
||||||
private static short WIIMOTE_LED_1 = 1;
|
private static short NB_POINTS = 4;// number of points IR can track
|
||||||
private static short WIIMOTE_LED_2 = 2;
|
|
||||||
private static short WIIMOTE_LED_3 = 4;
|
|
||||||
private static short WIIMOTE_LED_4 = 8;
|
|
||||||
|
|
||||||
private static short NB_LEDS = 4;
|
|
||||||
|
|
||||||
/* ID */
|
|
||||||
private int wiimoteId = -1;
|
|
||||||
|
|
||||||
/* Status variables */
|
|
||||||
private boolean connected = false;
|
|
||||||
|
|
||||||
private float batteryLevel = -1;
|
|
||||||
|
|
||||||
private short leds = 0;
|
|
||||||
|
|
||||||
private boolean isSpeakerEnabled = false;
|
|
||||||
|
|
||||||
private boolean isThereAttachment = false;
|
|
||||||
|
|
||||||
private boolean isRumbleActive = false;
|
|
||||||
|
|
||||||
private float orientationThreshold = 0;
|
|
||||||
|
|
||||||
private boolean isContinuousActive = false;
|
|
||||||
|
|
||||||
private boolean isSmoothingActive = false;
|
|
||||||
|
|
||||||
/* Buttons */
|
/* Buttons */
|
||||||
private short buttonsJustPressed = 0;
|
private short buttonsJustPressed = 0;
|
||||||
@@ -73,14 +50,6 @@ public class WiiMoteEvent {
|
|||||||
private Orientation orientation;
|
private Orientation orientation;
|
||||||
private GForce gforce;
|
private GForce gforce;
|
||||||
|
|
||||||
/**
|
|
||||||
* Default constructor
|
|
||||||
*/
|
|
||||||
public WiiMoteEvent() {
|
|
||||||
// init IRPoints array
|
|
||||||
IRPoints = new Point2DInteger[NB_LEDS];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the Wiimote setting up the id.
|
* Construct the Wiimote setting up the id.
|
||||||
*
|
*
|
||||||
@@ -88,152 +57,39 @@ public class WiiMoteEvent {
|
|||||||
* the Wiimote id
|
* the Wiimote id
|
||||||
*/
|
*/
|
||||||
public WiiMoteEvent(int id) {
|
public WiiMoteEvent(int id) {
|
||||||
this();
|
super(id, WiiUseApiEvent.GENERIC_EVENT);
|
||||||
wiimoteId = id;
|
IRPoints = new Point2DInteger[NB_POINTS];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Wiimote ID
|
* Construct the Wiimote setting up the id and the buttons.
|
||||||
*
|
*
|
||||||
* @return the wiimote id.
|
* @param id
|
||||||
|
* the Wiimote id
|
||||||
|
* @param buttonsJustPressed
|
||||||
|
* buttons just pressed
|
||||||
|
* @param buttonsJustReleased
|
||||||
|
* buttons just released
|
||||||
|
* @param buttonsHeld
|
||||||
|
* buttons held
|
||||||
*/
|
*/
|
||||||
public int getWiimoteId() {
|
public WiiMoteEvent(int id, short buttonsJustPressed,
|
||||||
return wiimoteId;
|
short buttonsJustReleased, short buttonsHeld) {
|
||||||
|
super(id, WiiUseApiEvent.GENERIC_EVENT);
|
||||||
|
IRPoints = new Point2DInteger[NB_POINTS];
|
||||||
|
setAllButtons(buttonsJustPressed, buttonsJustReleased, buttonsHeld);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Wiimote ID
|
* Construct the Wiimote setting up the id, the buttons and the infared.
|
||||||
*
|
*
|
||||||
* @param wiimoteId
|
|
||||||
* id of the wiimote
|
|
||||||
*/
|
*/
|
||||||
void setWiimoteId(int wiimoteId) {
|
|
||||||
this.wiimoteId = wiimoteId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if the wiimote is connected false otherwise.
|
* Construct the Wiimote setting up the id, the buttons, the accelerometer
|
||||||
|
* and the infrared.
|
||||||
*
|
*
|
||||||
* @return return the connected status.
|
|
||||||
*/
|
*/
|
||||||
public boolean isConnected() {
|
|
||||||
return connected;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the connected value to true.
|
|
||||||
*/
|
|
||||||
void setConnected() {
|
|
||||||
this.connected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the connected value to false.
|
|
||||||
*/
|
|
||||||
void setDisconnected() {
|
|
||||||
this.connected = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tell if there is an attachment to the Wiimote
|
|
||||||
*
|
|
||||||
* @return TRUE if it there is one false otherwise
|
|
||||||
*/
|
|
||||||
public boolean isThereAttachment() {
|
|
||||||
return isThereAttachment;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 setBatteryLedsSpeakerAttachment(float batt, short led, boolean speak,
|
|
||||||
boolean attach) {
|
|
||||||
this.batteryLevel = batt;
|
|
||||||
this.leds = led;
|
|
||||||
this.isSpeakerEnabled = speak;
|
|
||||||
this.isThereAttachment = attach;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the status of rumble.
|
|
||||||
*
|
|
||||||
* @return true if the rumble is active false otherwise
|
|
||||||
*/
|
|
||||||
public boolean isRumbleActive() {
|
|
||||||
return isRumbleActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Rumble flag to Inactive.
|
|
||||||
*/
|
|
||||||
void setRumbleInactive() {
|
|
||||||
this.isRumbleActive = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get orientation threshold.
|
|
||||||
*
|
|
||||||
* @return the orientationThreshold
|
|
||||||
*/
|
|
||||||
public float getOrientationThreshold() {
|
|
||||||
return orientationThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the short storing the buttons just pressed
|
* Get the short storing the buttons just pressed
|
||||||
@@ -269,8 +125,8 @@ public class WiiMoteEvent {
|
|||||||
* @param buttonsJustReleased
|
* @param buttonsJustReleased
|
||||||
* @param buttonsHeld
|
* @param buttonsHeld
|
||||||
*/
|
*/
|
||||||
void setAllButtons(short buttonsJustPressed, short buttonsJustReleased,
|
private void setAllButtons(short buttonsJustPressed,
|
||||||
short buttonsHeld) {
|
short buttonsJustReleased, short buttonsHeld) {
|
||||||
this.buttonsJustPressed = buttonsJustPressed;
|
this.buttonsJustPressed = buttonsJustPressed;
|
||||||
this.buttonsJustReleased = buttonsJustReleased;
|
this.buttonsJustReleased = buttonsJustReleased;
|
||||||
this.buttonsHeld = buttonsHeld;
|
this.buttonsHeld = buttonsHeld;
|
||||||
@@ -302,7 +158,8 @@ public class WiiMoteEvent {
|
|||||||
* @param y
|
* @param y
|
||||||
* y value
|
* y value
|
||||||
*/
|
*/
|
||||||
void addIRpoint(int x, int y) {
|
public void addIRpoint(int x, int y) {
|
||||||
|
isIrActive = true;
|
||||||
for (int i = 0; i < IRPoints.length; i++) {
|
for (int i = 0; i < IRPoints.length; i++) {
|
||||||
if (IRPoints[i] == null) {
|
if (IRPoints[i] == null) {
|
||||||
IRPoints[i] = new Point2DInteger(x, y);
|
IRPoints[i] = new Point2DInteger(x, y);
|
||||||
@@ -312,15 +169,6 @@ public class WiiMoteEvent {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear IR points.
|
|
||||||
*/
|
|
||||||
void EmptyIRPoints() {
|
|
||||||
for (int i = 0; i < IRPoints.length; i++) {
|
|
||||||
IRPoints[i] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the flag indicating if the motion sensing is active.
|
* Get the flag indicating if the motion sensing is active.
|
||||||
*
|
*
|
||||||
@@ -330,41 +178,6 @@ public class WiiMoteEvent {
|
|||||||
return isMotionSensingActive;
|
return isMotionSensingActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 setPermanentStatus(int id, boolean connect, boolean irState,
|
|
||||||
boolean rumbleState, boolean motionSensingState,
|
|
||||||
float orientationThreshold, boolean continuousState,
|
|
||||||
boolean smoothingState) {
|
|
||||||
wiimoteId = id;
|
|
||||||
connected = connect;
|
|
||||||
isIrActive = irState;
|
|
||||||
isRumbleActive = rumbleState;
|
|
||||||
isMotionSensingActive = motionSensingState;
|
|
||||||
this.orientationThreshold = orientationThreshold;
|
|
||||||
isContinuousActive = continuousState;
|
|
||||||
isSmoothingActive = smoothingState;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the orientation
|
* @return the orientation
|
||||||
*/
|
*/
|
||||||
@@ -397,8 +210,9 @@ public class WiiMoteEvent {
|
|||||||
* @param z
|
* @param z
|
||||||
* gravity force on z axis
|
* gravity force on z axis
|
||||||
*/
|
*/
|
||||||
void setOrientationAndGforce(float r, float p, float ya, float x, float y,
|
public void setOrientationAndGforce(float r, float p, float ya, float x,
|
||||||
float z) {
|
float y, float z) {
|
||||||
|
this.isMotionSensingActive = true;
|
||||||
this.orientation = new Orientation(r, p, ya);
|
this.orientation = new Orientation(r, p, ya);
|
||||||
this.gforce = new GForce(x, y, z);
|
this.gforce = new GForce(x, y, z);
|
||||||
}
|
}
|
||||||
@@ -579,20 +393,10 @@ public class WiiMoteEvent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
super.toString();
|
|
||||||
String out = "";
|
String out = "";
|
||||||
/* Status */
|
/* Status */
|
||||||
out += "/*********** WIIMOTE ID :" + wiimoteId + " ********/\n";
|
out += "/*********** GENERIC EVENT : WIIMOTE ID :"
|
||||||
out += "--- connected : " + connected + "\n";
|
+ super.getWiimoteId() + " ********/\n";
|
||||||
out += "--- Battery level : " + batteryLevel + "\n";
|
|
||||||
out += "--- Leds : " + leds + "\n";
|
|
||||||
out += "--- Speaker enabled : " + isSpeakerEnabled + "\n";
|
|
||||||
out += "--- Attachment ? : " + isThereAttachment + "\n";
|
|
||||||
out += "--- Rumble ? : " + isRumbleActive + "\n";
|
|
||||||
out += "--- Orientation threshold value ? : " + orientationThreshold
|
|
||||||
+ "\n";
|
|
||||||
out += "--- Continuous ? : " + isContinuousActive + "\n";
|
|
||||||
out += "--- Smoothing ? : " + isSmoothingActive + "\n";
|
|
||||||
/* Display buttons */
|
/* Display buttons */
|
||||||
out += "/******** Buttons ********/\n";
|
out += "/******** Buttons ********/\n";
|
||||||
out += "--- Buttons just pressed : " + buttonsJustPressed + "\n";
|
out += "--- Buttons just pressed : " + buttonsJustPressed + "\n";
|
||||||
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);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package wiiusej;
|
package wiiusej.wiiuseapirequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a request to set orientation Threshold in Wiiuse API.
|
* Represents a request to set orientation Threshold in Wiiuse API.
|
||||||
@@ -6,9 +6,9 @@ package wiiusej;
|
|||||||
* @author gduche
|
* @author gduche
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class OrientThresholdRequest extends WiiUseApiRequest {
|
public class FloatValueRequest extends WiiUseApiRequest {
|
||||||
|
|
||||||
private float thresholhd;
|
private float floatValue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor setting the id of the wiimote concerned.
|
* Constructor setting the id of the wiimote concerned.
|
||||||
@@ -16,7 +16,7 @@ public class OrientThresholdRequest extends WiiUseApiRequest {
|
|||||||
* @param id
|
* @param id
|
||||||
* the id of the wiimote concerned.
|
* the id of the wiimote concerned.
|
||||||
*/
|
*/
|
||||||
public OrientThresholdRequest(int id, int type) {
|
public FloatValueRequest(int id, int type) {
|
||||||
super(id, type);
|
super(id, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,23 +30,23 @@ public class OrientThresholdRequest extends WiiUseApiRequest {
|
|||||||
* @param th
|
* @param th
|
||||||
* threshold in degrees
|
* threshold in degrees
|
||||||
*/
|
*/
|
||||||
public OrientThresholdRequest(int id, int type, float th) {
|
public FloatValueRequest(int id, int type, float th) {
|
||||||
super(id, type);
|
super(id, type);
|
||||||
thresholhd = th;
|
floatValue = th;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the thresholhd
|
* @return the float value
|
||||||
*/
|
*/
|
||||||
public float getThresholhd() {
|
public float getFloatValue() {
|
||||||
return thresholhd;
|
return floatValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param thresholhd the thresholhd to set
|
* @param val the thresholhd to set
|
||||||
*/
|
*/
|
||||||
public void setThresholhd(float thresholhd) {
|
public void setFloatValue(float val) {
|
||||||
this.thresholhd = thresholhd;
|
this.floatValue = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package wiiusej;
|
package wiiusej.wiiuseapirequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a request to set leds of the wiimote with WiiUse API.
|
* Represents a request to set leds of the wiimote with WiiUse API.
|
||||||
* @author gduche
|
* @author gduche
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class LedsRequest extends wiiusej.WiiUseApiRequest {
|
public class LedsRequest extends wiiusej.wiiuseapirequest.WiiUseApiRequest {
|
||||||
|
|
||||||
private boolean led1, led2, led3, led4;
|
private boolean led1, led2, led3, led4;
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package wiiusej;
|
package wiiusej.wiiuseapirequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a request we could do to the WiiUse API.
|
* Represents a request we could do to the WiiUse API.
|
||||||
@@ -21,7 +21,8 @@ public class WiiUseApiRequest {
|
|||||||
public static int WIIUSE_DEACTIVATE_RUMBLE_REQUEST=-7;
|
public static int WIIUSE_DEACTIVATE_RUMBLE_REQUEST=-7;
|
||||||
public static int WIIUSE_LEDS_REQUEST=8;
|
public static int WIIUSE_LEDS_REQUEST=8;
|
||||||
public static int WIIUSE_ORIENT_THRESHOLHD_REQUEST=9;
|
public static int WIIUSE_ORIENT_THRESHOLHD_REQUEST=9;
|
||||||
|
public static int WIIUSE_ACCEL_THRESHOLHD_REQUEST=10;
|
||||||
|
public static int WIIUSE_ALPHA_SMOOTHING_REQUEST=11;
|
||||||
|
|
||||||
private int wiimoteId=0;
|
private int wiimoteId=0;
|
||||||
private int requestType=0;
|
private int requestType=0;
|
||||||
Binary file not shown.
Reference in New Issue
Block a user