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.Robot;
|
||||
import java.awt.event.InputEvent;
|
||||
|
||||
import wiiusej.Point2DInteger;
|
||||
import wiiusej.WiiMoteEvent;
|
||||
import wiiusej.WiiUseApiListener;
|
||||
import wiiusej.WiiUseApiManager;
|
||||
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.
|
||||
@@ -25,7 +28,7 @@ public class Tests implements WiimoteListener {
|
||||
private static int MOVE_MOUSE = 3;
|
||||
private static int ORIENT_THRESH_CONT = 4;
|
||||
private static int TEST_LEDS = 5;
|
||||
|
||||
|
||||
private Wiimote wiimote;
|
||||
|
||||
int dump = DISPLAY_EACH_VALUE;
|
||||
@@ -44,209 +47,187 @@ public class Tests implements WiimoteListener {
|
||||
public void wiimoteEvent(WiiMoteEvent e) {
|
||||
|
||||
if (dump == DISPLAY_EACH_VALUE) {
|
||||
if (e.isConnected()) {
|
||||
// System.out.println("*********** WIIMOTE ID : "+
|
||||
// e.getWiimoteId() + " **************");
|
||||
/* button ONE */
|
||||
if (e.isButtonOneJustPressed()) {
|
||||
System.out.println("button one pressed");
|
||||
}
|
||||
if (e.isButtonOneHeld()) {
|
||||
System.out.println("button one held");
|
||||
}
|
||||
if (e.isButtonOneJustReleased()) {
|
||||
System.out.println("button one released");
|
||||
}
|
||||
// System.out.println("*********** WIIMOTE ID : "+
|
||||
// e.getWiimoteId() + " **************");
|
||||
/* button ONE */
|
||||
if (e.isButtonOneJustPressed()) {
|
||||
System.out.println("button one pressed");
|
||||
}
|
||||
if (e.isButtonOneHeld()) {
|
||||
System.out.println("button one held");
|
||||
}
|
||||
if (e.isButtonOneJustReleased()) {
|
||||
System.out.println("button one released");
|
||||
}
|
||||
|
||||
/* button TWO */
|
||||
if (e.isButtonTwoJustPressed()) {
|
||||
System.out.println("button two pressed");
|
||||
}
|
||||
if (e.isButtonTwoHeld()) {
|
||||
System.out.println("button two held");
|
||||
}
|
||||
if (e.isButtonTwoJustReleased()) {
|
||||
System.out.println("button two released");
|
||||
}
|
||||
/* button TWO */
|
||||
if (e.isButtonTwoJustPressed()) {
|
||||
System.out.println("button two pressed");
|
||||
}
|
||||
if (e.isButtonTwoHeld()) {
|
||||
System.out.println("button two held");
|
||||
}
|
||||
if (e.isButtonTwoJustReleased()) {
|
||||
System.out.println("button two released");
|
||||
}
|
||||
|
||||
/* button A */
|
||||
if (e.isButtonAJustPressed()) {
|
||||
System.out.println("button A pressed");
|
||||
}
|
||||
if (e.isButtonAHeld()) {
|
||||
System.out.println("button A held");
|
||||
}
|
||||
if (e.isButtonAJustReleased()) {
|
||||
System.out.println("button A released");
|
||||
}
|
||||
/* button A */
|
||||
if (e.isButtonAJustPressed()) {
|
||||
System.out.println("button A pressed");
|
||||
}
|
||||
if (e.isButtonAHeld()) {
|
||||
System.out.println("button A held");
|
||||
}
|
||||
if (e.isButtonAJustReleased()) {
|
||||
System.out.println("button A released");
|
||||
}
|
||||
|
||||
/* button B */
|
||||
if (e.isButtonBJustPressed()) {
|
||||
System.out.println("button B pressed");
|
||||
}
|
||||
if (e.isButtonBHeld()) {
|
||||
System.out.println("button B held");
|
||||
}
|
||||
if (e.isButtonBJustReleased()) {
|
||||
System.out.println("button B released");
|
||||
}
|
||||
/* button B */
|
||||
if (e.isButtonBJustPressed()) {
|
||||
System.out.println("button B pressed");
|
||||
}
|
||||
if (e.isButtonBHeld()) {
|
||||
System.out.println("button B held");
|
||||
}
|
||||
if (e.isButtonBJustReleased()) {
|
||||
System.out.println("button B released");
|
||||
}
|
||||
|
||||
/* button LEFT */
|
||||
if (e.isButtonLeftJustPressed()) {
|
||||
System.out.println("button Left pressed");
|
||||
}
|
||||
if (e.isButtonLeftHeld()) {
|
||||
System.out.println("button Left held");
|
||||
}
|
||||
if (e.isButtonLeftJustReleased()) {
|
||||
System.out.println("button Left released");
|
||||
}
|
||||
/* button LEFT */
|
||||
if (e.isButtonLeftJustPressed()) {
|
||||
System.out.println("button Left pressed");
|
||||
}
|
||||
if (e.isButtonLeftHeld()) {
|
||||
System.out.println("button Left held");
|
||||
}
|
||||
if (e.isButtonLeftJustReleased()) {
|
||||
System.out.println("button Left released");
|
||||
}
|
||||
|
||||
/* button RIGHT */
|
||||
if (e.isButtonRightJustPressed()) {
|
||||
System.out.println("button Right pressed");
|
||||
}
|
||||
if (e.isButtonRightHeld()) {
|
||||
System.out.println("button Right held");
|
||||
}
|
||||
if (e.isButtonRightJustReleased()) {
|
||||
System.out.println("button Right released");
|
||||
}
|
||||
/* button RIGHT */
|
||||
if (e.isButtonRightJustPressed()) {
|
||||
System.out.println("button Right pressed");
|
||||
}
|
||||
if (e.isButtonRightHeld()) {
|
||||
System.out.println("button Right held");
|
||||
}
|
||||
if (e.isButtonRightJustReleased()) {
|
||||
System.out.println("button Right released");
|
||||
}
|
||||
|
||||
/* button UP */
|
||||
if (e.isButtonUpJustPressed()) {
|
||||
System.out.println("button UP pressed");
|
||||
}
|
||||
if (e.isButtonUpHeld()) {
|
||||
System.out.println("button UP held");
|
||||
}
|
||||
if (e.isButtonUpJustReleased()) {
|
||||
System.out.println("button UP released");
|
||||
}
|
||||
/* button UP */
|
||||
if (e.isButtonUpJustPressed()) {
|
||||
System.out.println("button UP pressed");
|
||||
}
|
||||
if (e.isButtonUpHeld()) {
|
||||
System.out.println("button UP held");
|
||||
}
|
||||
if (e.isButtonUpJustReleased()) {
|
||||
System.out.println("button UP released");
|
||||
}
|
||||
|
||||
/* button DOWN */
|
||||
if (e.isButtonDownJustPressed()) {
|
||||
System.out.println("button DOWN pressed");
|
||||
}
|
||||
if (e.isButtonDownHeld()) {
|
||||
System.out.println("button DOWN held");
|
||||
}
|
||||
if (e.isButtonDownJustReleased()) {
|
||||
System.out.println("button DOWN released");
|
||||
}
|
||||
/* button DOWN */
|
||||
if (e.isButtonDownJustPressed()) {
|
||||
System.out.println("button DOWN pressed");
|
||||
}
|
||||
if (e.isButtonDownHeld()) {
|
||||
System.out.println("button DOWN held");
|
||||
}
|
||||
if (e.isButtonDownJustReleased()) {
|
||||
System.out.println("button DOWN released");
|
||||
}
|
||||
|
||||
/* button MINUS */
|
||||
if (e.isButtonMinusJustPressed()) {
|
||||
System.out.println("button MINUS pressed");
|
||||
}
|
||||
if (e.isButtonMinusHeld()) {
|
||||
System.out.println("button MINUS held");
|
||||
}
|
||||
if (e.isButtonMinusJustReleased()) {
|
||||
System.out.println("button MINUS released");
|
||||
}
|
||||
/* button MINUS */
|
||||
if (e.isButtonMinusJustPressed()) {
|
||||
System.out.println("button MINUS pressed");
|
||||
}
|
||||
if (e.isButtonMinusHeld()) {
|
||||
System.out.println("button MINUS held");
|
||||
}
|
||||
if (e.isButtonMinusJustReleased()) {
|
||||
System.out.println("button MINUS released");
|
||||
}
|
||||
|
||||
/* button PLUS */
|
||||
if (e.isButtonPlusJustPressed()) {
|
||||
System.out.println("button PLUS pressed");
|
||||
}
|
||||
if (e.isButtonPlusHeld()) {
|
||||
System.out.println("button PLUS held");
|
||||
}
|
||||
if (e.isButtonPlusJustReleased()) {
|
||||
System.out.println("button PLUS released");
|
||||
}
|
||||
/* button PLUS */
|
||||
if (e.isButtonPlusJustPressed()) {
|
||||
System.out.println("button PLUS pressed");
|
||||
}
|
||||
if (e.isButtonPlusHeld()) {
|
||||
System.out.println("button PLUS held");
|
||||
}
|
||||
if (e.isButtonPlusJustReleased()) {
|
||||
System.out.println("button PLUS released");
|
||||
}
|
||||
|
||||
/* button HOME */
|
||||
if (e.isButtonHomeJustPressed()) {
|
||||
System.out.println("button HOME pressed");
|
||||
}
|
||||
if (e.isButtonHomeHeld()) {
|
||||
System.out.println("button HOME held");
|
||||
}
|
||||
if (e.isButtonHomeJustReleased()) {
|
||||
System.out.println("button HOME released");
|
||||
}
|
||||
/* button HOME */
|
||||
if (e.isButtonHomeJustPressed()) {
|
||||
System.out.println("button HOME pressed");
|
||||
}
|
||||
if (e.isButtonHomeHeld()) {
|
||||
System.out.println("button HOME held");
|
||||
}
|
||||
if (e.isButtonHomeJustReleased()) {
|
||||
System.out.println("button HOME released");
|
||||
}
|
||||
|
||||
/* get status */
|
||||
if (e.isButtonMinusJustPressed() && e.isButtonPlusJustPressed()) {
|
||||
wiimote.getStatus();
|
||||
}
|
||||
/* get status */
|
||||
if (e.isButtonMinusJustPressed() && e.isButtonPlusJustPressed()) {
|
||||
wiimote.getStatus();
|
||||
}
|
||||
|
||||
/* Activate rumble */
|
||||
if (e.isButtonOneJustPressed()) {
|
||||
System.out.println("Rumble Activated");
|
||||
wiimote.activateRumble();
|
||||
}
|
||||
if (e.isButtonTwoJustPressed()) {
|
||||
System.out.println("Rumble Deactivated");
|
||||
wiimote.deactivateRumble();
|
||||
}
|
||||
/* Activate rumble */
|
||||
if (e.isButtonOneJustPressed()) {
|
||||
System.out.println("Rumble Activated");
|
||||
wiimote.activateRumble();
|
||||
}
|
||||
if (e.isButtonTwoJustPressed()) {
|
||||
System.out.println("Rumble Deactivated");
|
||||
wiimote.deactivateRumble();
|
||||
}
|
||||
|
||||
/* Activate IR Tracking */
|
||||
if (e.isButtonAJustPressed()) {
|
||||
System.out.println("IR Activated");
|
||||
wiimote.activateIRTRacking();
|
||||
}
|
||||
if (e.isButtonBJustPressed()) {
|
||||
System.out.println("IR Deactivated");
|
||||
wiimote.deactivateIRTRacking();
|
||||
}
|
||||
/* Activate IR Tracking */
|
||||
if (e.isButtonAJustPressed()) {
|
||||
System.out.println("IR Activated");
|
||||
wiimote.activateIRTRacking();
|
||||
}
|
||||
if (e.isButtonBJustPressed()) {
|
||||
System.out.println("IR Deactivated");
|
||||
wiimote.deactivateIRTRacking();
|
||||
}
|
||||
|
||||
/* Activate Motion sensing */
|
||||
if (e.isButtonPlusJustPressed()) {
|
||||
System.out.println("Motion sensing Activated");
|
||||
wiimote.activateMotionSensing();
|
||||
}
|
||||
if (e.isButtonMinusJustPressed()) {
|
||||
System.out.println("Motion sensing Deactivated");
|
||||
wiimote.deactivateMotionSensing();
|
||||
}
|
||||
/* Activate Motion sensing */
|
||||
if (e.isButtonPlusJustPressed()) {
|
||||
System.out.println("Motion sensing Activated");
|
||||
wiimote.activateMotionSensing();
|
||||
}
|
||||
if (e.isButtonMinusJustPressed()) {
|
||||
System.out.println("Motion sensing Deactivated");
|
||||
wiimote.deactivateMotionSensing();
|
||||
}
|
||||
|
||||
/* display status */
|
||||
if (e.getBatteryLevel() != -1) {
|
||||
System.out
|
||||
.println("battery level : " + e.getBatteryLevel());
|
||||
System.out.println("= --- Leds : " + e.getLeds() + "\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 */
|
||||
if (e.isIrActive()) {
|
||||
Point2DInteger[] list = e.getIRPoints();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i] != null)
|
||||
System.out.print("Point :(" + list[i].getX() + ","
|
||||
+ list[i].getY() + ") ");
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
/* display ir points */
|
||||
if (e.isIrActive()) {
|
||||
Point2DInteger[] list = e.getIRPoints();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i] != null)
|
||||
System.out.print("Point :(" + list[i].getX() + ","
|
||||
+ list[i].getY() + ") ");
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
/* display motion sensing */
|
||||
if (e.isMotionSensingActive()) {
|
||||
System.out.println("Motion Sensing :" + e.getOrientation()
|
||||
+ " , " + e.getGforce());
|
||||
}
|
||||
|
||||
/* display motion sensing */
|
||||
if (e.isMotionSensingActive()) {
|
||||
System.out.println("Motion Sensing :" + e.getOrientation()
|
||||
+ " , " + e.getGforce());
|
||||
}
|
||||
|
||||
/* leave test */
|
||||
if (e.isButtonHomeJustPressed()) {
|
||||
System.out.println("LEAVING TEST");
|
||||
wiimote.disconnect();
|
||||
}
|
||||
} else {
|
||||
System.out.println(" WIIMOTE ID : " + e.getWiimoteId()
|
||||
+ " DISCONNECTED !!!!!");
|
||||
/* leave test */
|
||||
if (e.isButtonHomeJustPressed()) {
|
||||
System.out.println("LEAVING TEST");
|
||||
wiimote.disconnect();
|
||||
}
|
||||
|
||||
} else if (dump == DUMP) {
|
||||
System.out.println(e);
|
||||
/* Activate all */
|
||||
@@ -337,6 +318,10 @@ public class Tests implements WiimoteListener {
|
||||
System.out.println("Threshold orientation 0.5 degrees");
|
||||
wiimote.setOrientationThreshold((float) 0.5);
|
||||
}
|
||||
|
||||
//@TODO add accelereation threshold test, add alpha smoothing test
|
||||
|
||||
|
||||
System.out.println(e);
|
||||
|
||||
/* leave test */
|
||||
@@ -347,10 +332,10 @@ public class Tests implements WiimoteListener {
|
||||
} else if (dump == TEST_LEDS) {
|
||||
wiimote.activateMotionSensing();
|
||||
if (e.isButtonUpJustPressed()) {
|
||||
wiimote.setLeds(true, false, false, false);
|
||||
wiimote.setLeds(true, false, false, false);
|
||||
}
|
||||
if (e.isButtonDownJustPressed()) {
|
||||
wiimote.setLeds(false, true, false, false);
|
||||
wiimote.setLeds(false, true, false, false);
|
||||
}
|
||||
if (e.isButtonLeftJustPressed()) {
|
||||
wiimote.setLeds(false, false, true, false);
|
||||
@@ -366,20 +351,30 @@ 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
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes();
|
||||
if (wiimotes.length>0){
|
||||
Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(4);
|
||||
if (wiimotes.length > 0) {
|
||||
System.out.println(wiimotes[0]);
|
||||
Tests tests = new Tests(wiimotes[0]);
|
||||
}else{
|
||||
} else {
|
||||
System.out.println("No wiimotes found !!!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// java.util.Timer timer = new java.util.Timer();
|
||||
// timer.scheduleAtFixedRate(new LedsTask(), 0, 100);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package wiiusej;
|
||||
|
||||
import wiiusej.wiiuseapievents.EventsGatherer;
|
||||
|
||||
/**
|
||||
* Singleton used to manipulate WiiUse Api.
|
||||
* @author gduche
|
||||
@@ -19,23 +21,16 @@ public class WiiUseApi {
|
||||
*/
|
||||
static WiiUseApi getInstance(){
|
||||
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
|
||||
* connected.
|
||||
*
|
||||
* @param nb number of wiimotes to connect
|
||||
* @return 0 if there is an error otherwise it returns the number of
|
||||
* wiimotes connected.
|
||||
*/
|
||||
native int doConnections();
|
||||
native int doConnections(int nb);
|
||||
|
||||
/**
|
||||
* Close connection to the wiimote with the given id.
|
||||
@@ -103,6 +98,26 @@ public class WiiUseApi {
|
||||
*/
|
||||
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.
|
||||
* This is set by default.
|
||||
@@ -137,26 +152,27 @@ public class WiiUseApi {
|
||||
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 */
|
||||
public static void main(String[] args) {
|
||||
|
||||
/* Test JNI Side */
|
||||
/*
|
||||
WiiUseApi manager = new WiiUseApi();
|
||||
|
||||
int value = manager.loadLibrary();
|
||||
System.out.println("loadLibrary : " + value);
|
||||
|
||||
value = manager.doConnections();
|
||||
System.out.println("doConnections : " + value);
|
||||
|
||||
WiiMoteEvent mote = new WiiMoteEvent();
|
||||
System.out.println("doConnections : " + value);
|
||||
WiiMoteEvent mote = new WiiMoteEvent();
|
||||
|
||||
|
||||
manager.getStatus(1);
|
||||
System.out.println("Status : \n" + mote);
|
||||
@@ -168,6 +184,7 @@ public class WiiUseApi {
|
||||
System.out.println(mote);
|
||||
mote.EmptyIRPoints();
|
||||
}
|
||||
*/
|
||||
// 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.concurrent.ConcurrentLinkedQueue;
|
||||
@@ -6,6 +6,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
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.
|
||||
*
|
||||
@@ -19,84 +26,66 @@ public class WiiUseApiManager extends Thread {
|
||||
private final EventListenerList listeners = new EventListenerList();
|
||||
|
||||
private Wiimote[] wiimotes;
|
||||
|
||||
private WiiUseApi wiiuse = WiiUseApi.getInstance();
|
||||
|
||||
private boolean loaded = false;
|
||||
private WiiUseApi wiiuse = WiiUseApi.getInstance();
|
||||
|
||||
private int connected = -1;
|
||||
|
||||
private int nbMaxWiimotes = -1;
|
||||
|
||||
private AtomicBoolean running = new AtomicBoolean(false);
|
||||
|
||||
private ConcurrentLinkedQueue<WiiUseApiRequest> requests = new ConcurrentLinkedQueue<WiiUseApiRequest>();
|
||||
private ConcurrentLinkedQueue<WiiUseApiRequest> requests = new ConcurrentLinkedQueue<WiiUseApiRequest>();
|
||||
|
||||
public static WiiUseApiManager getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get wiimotes.
|
||||
* Load library if necessary.
|
||||
* Connect to wiimotes if necessary.
|
||||
* Start polling if necessary.
|
||||
* Return an array with the connected wiimotes.
|
||||
* @return an array with connected wiimotes or NULL.
|
||||
*/
|
||||
public static Wiimote[] getWiimotes() {
|
||||
WiiUseApiManager manager = getInstance();
|
||||
if (!manager.loaded){
|
||||
manager.loadLibrary();
|
||||
}
|
||||
if (manager.connected<0){
|
||||
int nbWiimotes = manager.connectWiimotes();
|
||||
manager.wiimotes = new Wiimote[nbWiimotes];
|
||||
for (int i=0; i<nbWiimotes; i++){
|
||||
Wiimote wim = new Wiimote(i,manager);
|
||||
manager.wiimotes[i] = wim;
|
||||
manager.addWiiUseApiListener(wim);
|
||||
}
|
||||
}
|
||||
|
||||
if (manager.connected == 0){
|
||||
return new Wiimote[0];
|
||||
}
|
||||
|
||||
if (!manager.isAlive()) manager.start();
|
||||
|
||||
return manager.wiimotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the wiimote library.
|
||||
* Get wiimotes. Load library if necessary. Connect to wiimotes if
|
||||
* necessary. Start polling if necessary. Return an array with the connected
|
||||
* wiimotes.
|
||||
*
|
||||
* @return false if the library is not loaded true otherwise.
|
||||
* @param nb
|
||||
* try to connect nb wiimotes
|
||||
* @return an array with connected wiimotes or NULL.
|
||||
*/
|
||||
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;
|
||||
public static Wiimote[] getWiimotes(int nb) {
|
||||
WiiUseApiManager manager = getInstance();
|
||||
if (manager.connected < 0) {
|
||||
int nbWiimotes = manager.connectWiimotes(nb);
|
||||
manager.wiimotes = new Wiimote[nbWiimotes];
|
||||
for (int i = 0; i < nbWiimotes; i++) {
|
||||
Wiimote wim = new Wiimote(i, manager);
|
||||
manager.wiimotes[i] = wim;
|
||||
manager.addWiiUseApiListener(wim);
|
||||
}
|
||||
}
|
||||
// already loaded
|
||||
return loaded;
|
||||
|
||||
if (manager.connected == 0) {
|
||||
return new Wiimote[0];
|
||||
}
|
||||
|
||||
if (!manager.isAlive())
|
||||
manager.start();
|
||||
|
||||
return manager.wiimotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect wiimote and get the number of wiimotes connected. Supposed to be
|
||||
* used once.
|
||||
*
|
||||
* @param nb
|
||||
* try to connect nb wiimotes
|
||||
* @return 0 if nothing connected or the number of wiimotes connected.
|
||||
*/
|
||||
public int connectWiimotes() {
|
||||
if (connected < 0 && loaded) {
|
||||
connected = wiiuse.doConnections();
|
||||
// System.out.println(connected + " wiimote(s) connected !!!");
|
||||
public int connectWiimotes(int nb) {
|
||||
nbMaxWiimotes = nb;
|
||||
if (connected < 0) {
|
||||
connected = wiiuse.doConnections(nb);
|
||||
// @TODO
|
||||
System.out.println(connected + " wiimote(s) connected !!!");
|
||||
return connected;
|
||||
} else {// library not loaded, no wiimotes connected
|
||||
return 0;
|
||||
@@ -109,9 +98,12 @@ public class WiiUseApiManager extends Thread {
|
||||
* @param id
|
||||
* 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,
|
||||
WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST));
|
||||
System.out.println("Wiimote " + id + " disconnected !");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +120,6 @@ public class WiiUseApiManager extends Thread {
|
||||
*/
|
||||
public void shutdown() {
|
||||
running.set(false);
|
||||
loaded = false;
|
||||
wiiuse.shutdownApi();
|
||||
}
|
||||
|
||||
@@ -270,10 +261,36 @@ public class WiiUseApiManager extends Thread {
|
||||
* threshold in degrees
|
||||
*/
|
||||
public void setOrientationThreshold(int id, float th) {
|
||||
requests.add(new OrientThresholdRequest(id,
|
||||
requests.add(new FloatValueRequest(id,
|
||||
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.
|
||||
*
|
||||
@@ -288,10 +305,10 @@ public class WiiUseApiManager extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (loaded && (connected > 0)) {
|
||||
if (connected > 0) {
|
||||
running.set(true);
|
||||
|
||||
WiiMoteEvent evt = new WiiMoteEvent();
|
||||
EventsGatherer gather = new EventsGatherer(nbMaxWiimotes);
|
||||
|
||||
// Start polling and tell the observers when there Wiimote events
|
||||
while (running.get()) {
|
||||
@@ -299,11 +316,15 @@ public class WiiUseApiManager extends Thread {
|
||||
if (req != null) {// there is a request for the wiiuse api
|
||||
int id = req.getId();
|
||||
if (req.getRequestType() == WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST) {
|
||||
/* Close connections requests */
|
||||
removeWiiUseApiListener(wiimotes[id]);
|
||||
wiimotes[id]=null;
|
||||
/* Close connections requests */
|
||||
wiiuse.closeConnection(id);
|
||||
|
||||
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) {
|
||||
/* Status requests */
|
||||
wiiuse.getStatus(id);
|
||||
@@ -343,42 +364,44 @@ public class WiiUseApiManager extends Thread {
|
||||
/* Deactivate continuous requests */
|
||||
wiiuse.deactivateContinuous(id);
|
||||
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ORIENT_THRESHOLHD_REQUEST) {
|
||||
/* set orientation request */
|
||||
/* set orientation threshold request */
|
||||
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 {
|
||||
System.out.println("Bad request to Wiiuse API !!!!!");
|
||||
}
|
||||
}
|
||||
|
||||
/* Polling */
|
||||
wiiuse.specialPoll(evt);
|
||||
wiiuse.specialPoll(gather);
|
||||
|
||||
if (evt.getWiimoteId() != -1) {//event filled
|
||||
if (!evt.isConnected()) {// check if it was a
|
||||
// disconnection
|
||||
connected--;
|
||||
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
|
||||
/* deal with events gathered in Wiiuse API */
|
||||
for (WiiUseApiEvent evt : gather.getEvents()) {
|
||||
if (evt.getWiimoteId() != -1) {// event filled
|
||||
// there is an event notify observers
|
||||
notifyWiiUseApiListener(evt);
|
||||
// create a new event to be filled
|
||||
evt = new WiiMoteEvent();
|
||||
}
|
||||
}
|
||||
if (connected == 0) {// stop this thread if there is
|
||||
//no more wiimotes connected.
|
||||
System.out.println("No more wiimotes connected !!!");
|
||||
shutdown();
|
||||
}
|
||||
if (evt.getEventType() == WiiUseApiEvent.DISCONNECTION_EVENT) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
gather.clearEvents();
|
||||
}
|
||||
} else {
|
||||
if (!loaded) {
|
||||
System.out.println("Library not Loaded !");
|
||||
}
|
||||
if (connected <= 0) {
|
||||
System.out.println("No wiimotes connected !");
|
||||
}
|
||||
@@ -421,9 +444,9 @@ public class WiiUseApiManager extends Thread {
|
||||
* @param evt
|
||||
* WiimoteEvent occured
|
||||
*/
|
||||
private void notifyWiiUseApiListener(WiiMoteEvent evt) {
|
||||
private void notifyWiiUseApiListener(WiiUseApiEvent evt) {
|
||||
for (WiiUseApiListener listener : getWiiUseApiListeners()) {
|
||||
listener.wiimoteEvent(evt);
|
||||
listener.wiiUseApiEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,13 @@ package wiiusej;
|
||||
|
||||
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.
|
||||
* 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 {
|
||||
|
||||
private int id;//wiimote id
|
||||
private int id = -1;//wiimote id
|
||||
|
||||
private EventListenerList listeners = new EventListenerList();
|
||||
|
||||
@@ -140,15 +147,20 @@ public class Wiimote implements WiiUseApiListener {
|
||||
public void getStatus() {
|
||||
manager.getStatus(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void wiimoteEvent(WiiMoteEvent e) {
|
||||
if (e.getWiimoteId() == id){
|
||||
notifyWiiMoteEventListeners(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wiiUseApiEvent(WiiUseApiEvent e) {
|
||||
if (e.getWiimoteId() == id){
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a WiimoteListener to the listeners list.
|
||||
* @param listener a WiimoteListener
|
||||
@@ -183,9 +195,29 @@ 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
|
||||
public String toString() {
|
||||
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.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 {
|
||||
public class WiiMoteEvent extends WiiUseApiEvent {
|
||||
|
||||
/* Buttons MACRO */
|
||||
private static short WIIMOTE_BUTTON_TWO = 0x0001;
|
||||
@@ -30,34 +34,7 @@ public class WiiMoteEvent {
|
||||
private static int WIIMOTE_BUTTON_UNKNOWN = 0x8000;
|
||||
private static short WIIMOTE_BUTTON_ALL = 0x1F9F;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
private static short NB_POINTS = 4;// number of points IR can track
|
||||
|
||||
/* Buttons */
|
||||
private short buttonsJustPressed = 0;
|
||||
@@ -73,14 +50,6 @@ public class WiiMoteEvent {
|
||||
private Orientation orientation;
|
||||
private GForce gforce;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public WiiMoteEvent() {
|
||||
// init IRPoints array
|
||||
IRPoints = new Point2DInteger[NB_LEDS];
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Wiimote setting up the id.
|
||||
*
|
||||
@@ -88,153 +57,40 @@ public class WiiMoteEvent {
|
||||
* the Wiimote id
|
||||
*/
|
||||
public WiiMoteEvent(int id) {
|
||||
this();
|
||||
wiimoteId = id;
|
||||
super(id, WiiUseApiEvent.GENERIC_EVENT);
|
||||
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() {
|
||||
return wiimoteId;
|
||||
public WiiMoteEvent(int id, short buttonsJustPressed,
|
||||
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
|
||||
*
|
||||
@@ -269,8 +125,8 @@ public class WiiMoteEvent {
|
||||
* @param buttonsJustReleased
|
||||
* @param buttonsHeld
|
||||
*/
|
||||
void setAllButtons(short buttonsJustPressed, short buttonsJustReleased,
|
||||
short buttonsHeld) {
|
||||
private void setAllButtons(short buttonsJustPressed,
|
||||
short buttonsJustReleased, short buttonsHeld) {
|
||||
this.buttonsJustPressed = buttonsJustPressed;
|
||||
this.buttonsJustReleased = buttonsJustReleased;
|
||||
this.buttonsHeld = buttonsHeld;
|
||||
@@ -302,7 +158,8 @@ public class WiiMoteEvent {
|
||||
* @param y
|
||||
* 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++) {
|
||||
if (IRPoints[i] == null) {
|
||||
IRPoints[i] = new Point2DInteger(x, y);
|
||||
@@ -312,15 +169,6 @@ public class WiiMoteEvent {
|
||||
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.
|
||||
*
|
||||
@@ -330,41 +178,6 @@ public class WiiMoteEvent {
|
||||
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
|
||||
*/
|
||||
@@ -397,8 +210,9 @@ public class WiiMoteEvent {
|
||||
* @param z
|
||||
* gravity force on z axis
|
||||
*/
|
||||
void setOrientationAndGforce(float r, float p, float ya, float x, float y,
|
||||
float z) {
|
||||
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);
|
||||
}
|
||||
@@ -579,20 +393,10 @@ public class WiiMoteEvent {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
super.toString();
|
||||
String out = "";
|
||||
/* Status */
|
||||
out += "/*********** WIIMOTE ID :" + wiimoteId + " ********/\n";
|
||||
out += "--- connected : " + connected + "\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";
|
||||
out += "/*********** GENERIC EVENT : WIIMOTE ID :"
|
||||
+ super.getWiimoteId() + " ********/\n";
|
||||
/* Display buttons */
|
||||
out += "/******** Buttons ********/\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.
|
||||
@@ -6,9 +6,9 @@ package wiiusej;
|
||||
* @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.
|
||||
@@ -16,7 +16,7 @@ public class OrientThresholdRequest extends WiiUseApiRequest {
|
||||
* @param id
|
||||
* the id of the wiimote concerned.
|
||||
*/
|
||||
public OrientThresholdRequest(int id, int type) {
|
||||
public FloatValueRequest(int id, int type) {
|
||||
super(id, type);
|
||||
}
|
||||
|
||||
@@ -30,23 +30,23 @@ public class OrientThresholdRequest extends WiiUseApiRequest {
|
||||
* @param th
|
||||
* threshold in degrees
|
||||
*/
|
||||
public OrientThresholdRequest(int id, int type, float th) {
|
||||
public FloatValueRequest(int id, int type, float th) {
|
||||
super(id, type);
|
||||
thresholhd = th;
|
||||
floatValue = th;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the thresholhd
|
||||
* @return the float value
|
||||
*/
|
||||
public float getThresholhd() {
|
||||
return thresholhd;
|
||||
public float getFloatValue() {
|
||||
return floatValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param thresholhd the thresholhd to set
|
||||
* @param val the thresholhd to set
|
||||
*/
|
||||
public void setThresholhd(float thresholhd) {
|
||||
this.thresholhd = thresholhd;
|
||||
public void setFloatValue(float val) {
|
||||
this.floatValue = val;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package wiiusej;
|
||||
package wiiusej.wiiuseapirequest;
|
||||
|
||||
/**
|
||||
* Represents a request to set leds of the wiimote with WiiUse API.
|
||||
* @author gduche
|
||||
*
|
||||
*/
|
||||
public class LedsRequest extends wiiusej.WiiUseApiRequest {
|
||||
public class LedsRequest extends wiiusej.wiiuseapirequest.WiiUseApiRequest {
|
||||
|
||||
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.
|
||||
@@ -21,7 +21,8 @@ public class WiiUseApiRequest {
|
||||
public static int WIIUSE_DEACTIVATE_RUMBLE_REQUEST=-7;
|
||||
public static int WIIUSE_LEDS_REQUEST=8;
|
||||
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 requestType=0;
|
||||
Binary file not shown.
Reference in New Issue
Block a user