somme fixes on new version. Acceleration threshold is an int.

git-svn-id: http://wiiusej.googlecode.com/svn/trunk@54 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
guilhem.duche
2008-02-15 14:26:50 +00:00
parent f2829ca27f
commit dc13f8feee
5 changed files with 96 additions and 54 deletions

View File

@@ -103,14 +103,14 @@ public class WiiUseApi {
* @param id id of the wiimote concerned * @param id id of the wiimote concerned
* @param value minimum value detected by an event * @param value minimum value detected by an event
*/ */
native void setAccelThreshold(int id, float value); native void setAccelThreshold(int id, int value);
/** /**
* Set alpha smoothing parameter for the given id. * Set alpha smoothing parameter for the given id.
* @param id id of the wiimote concerned * @param id id of the wiimote concerned
* @param value alpha smoothing value * @param value alpha smoothing value
*/ */
native void setSmoothAlpha(int id, float value); native void setAlphaSmoothing(int id, float value);
/** /**
* Try to resync with the wiimote by starting a new handshake. * Try to resync with the wiimote by starting a new handshake.

View File

@@ -1,6 +1,5 @@
package wiiusej; package wiiusej;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@@ -10,6 +9,7 @@ import wiiusej.wiiuseapievents.EventsGatherer;
import wiiusej.wiiuseapievents.WiiUseApiEvent; import wiiusej.wiiuseapievents.WiiUseApiEvent;
import wiiusej.wiiuseapievents.WiiUseApiListener; import wiiusej.wiiuseapievents.WiiUseApiListener;
import wiiusej.wiiuseapirequest.FloatValueRequest; import wiiusej.wiiuseapirequest.FloatValueRequest;
import wiiusej.wiiuseapirequest.IntValueRequest;
import wiiusej.wiiuseapirequest.LedsRequest; import wiiusej.wiiuseapirequest.LedsRequest;
import wiiusej.wiiuseapirequest.WiiUseApiRequest; import wiiusej.wiiuseapirequest.WiiUseApiRequest;
@@ -98,9 +98,9 @@ public class WiiUseApiManager extends Thread {
* @param id * @param id
* 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]); removeWiiUseApiListener(wiimotes[id]);
wiimotes[id] = null; 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 !"); System.out.println("Wiimote " + id + " disconnected !");
@@ -273,8 +273,8 @@ public class WiiUseApiManager extends Thread {
* @param th * @param th
* threshold * threshold
*/ */
public void setAccelerationThreshold(int id, float th) { public void setAccelerationThreshold(int id, int th) {
requests.add(new FloatValueRequest(id, requests.add(new IntValueRequest(id,
WiiUseApiRequest.WIIUSE_ACCEL_THRESHOLHD_REQUEST, th)); WiiUseApiRequest.WIIUSE_ACCEL_THRESHOLHD_REQUEST, th));
} }
@@ -291,6 +291,16 @@ public class WiiUseApiManager extends Thread {
WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST, th)); WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST, th));
} }
/**
* Try to resync with the wiimote by starting a new handshake.
* @TODO not used yet !!
* @param id
* id of the wiimote
*/
public void reSync(int id) {
requests.add(new WiiUseApiRequest(id, WiiUseApiRequest.WIIUSE_RESYNC));
}
/** /**
* Get Status for the wiimote for the given id. * Get Status for the wiimote for the given id.
* *
@@ -318,11 +328,12 @@ public class WiiUseApiManager extends Thread {
if (req.getRequestType() == WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST) { if (req.getRequestType() == WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST) {
/* Close connections requests */ /* Close connections requests */
wiiuse.closeConnection(id); wiiuse.closeConnection(id);
connected--; connected--;
if (connected == 0) {// stop this thread if there is if (connected == 0) {// stop this thread if there is
// no more wiimotes connected. // no more wiimotes connected.
System.out.println("No more wiimotes connected !!!"); System.out
.println("No more wiimotes connected !!!");
shutdown(); shutdown();
} }
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_STATUS_REQUEST) { } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_STATUS_REQUEST) {
@@ -369,12 +380,15 @@ public class WiiUseApiManager extends Thread {
((FloatValueRequest) req).getFloatValue()); ((FloatValueRequest) req).getFloatValue());
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ACCEL_THRESHOLHD_REQUEST) { } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ACCEL_THRESHOLHD_REQUEST) {
/* set acceleration threshold request */ /* set acceleration threshold request */
wiiuse.setOrientThreshold(req.getId(), wiiuse.setAccelThreshold(req.getId(),
((FloatValueRequest) req).getFloatValue()); ((IntValueRequest) req).getIntValue());
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST) { } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST) {
/* set alpha smoothing request */ /* set alpha smoothing request */
wiiuse.setOrientThreshold(req.getId(), wiiuse.setAlphaSmoothing(req.getId(),
((FloatValueRequest) req).getFloatValue()); ((FloatValueRequest) req).getFloatValue());
} else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_RESYNC) {
/* set resync request */
wiiuse.reSync(req.getId());
} else { } else {
System.out.println("Bad request to Wiiuse API !!!!!"); System.out.println("Bad request to Wiiuse API !!!!!");
} }
@@ -398,7 +412,7 @@ public class WiiUseApiManager extends Thread {
.println("There is an event with id == -1 ??? there is a problem !!! : " .println("There is an event with id == -1 ??? there is a problem !!! : "
+ evt); + evt);
} }
} }
gather.clearEvents(); gather.clearEvents();
} }
} else { } else {
@@ -446,7 +460,7 @@ public class WiiUseApiManager extends Thread {
*/ */
private void notifyWiiUseApiListener(WiiUseApiEvent evt) { private void notifyWiiUseApiListener(WiiUseApiEvent evt) {
for (WiiUseApiListener listener : getWiiUseApiListeners()) { for (WiiUseApiListener listener : getWiiUseApiListeners()) {
listener.wiiUseApiEvent(evt); listener.wiiUseApiEvent(evt);
} }
} }

View File

@@ -140,6 +140,24 @@ public class Wiimote implements WiiUseApiListener {
public void setOrientationThreshold(float th) { public void setOrientationThreshold(float th) {
manager.setOrientationThreshold(id,th); manager.setOrientationThreshold(id,th);
} }
/**
* Set the acceleration threshold .
* @param th
* threshold
*/
public void setAccelerationThreshold(int th) {
manager.setAccelerationThreshold(id,th);
}
/**
* Set the alpha smoothing value.
* @param th
* threshold
*/
public void setAlphaSmoothingValue(int th) {
manager.setAlphaSmoothing(id,th);
}
/** /**
* Get Status of the wiimote. * Get Status of the wiimote.

View File

@@ -1,8 +1,7 @@
package wiiusej.wiiuseapirequest; package wiiusej.wiiuseapirequest;
/** /**
* Represents a request to set orientation Threshold in Wiiuse API. * Represents a request with a float value to pass to wiiuse API.
* Orientation Threshold is the minimum angle (in degrees) between two events.
* @author gduche * @author gduche
* *
*/ */
@@ -36,6 +35,7 @@ public class FloatValueRequest extends WiiUseApiRequest {
} }
/** /**
* Get the float value.
* @return the float value * @return the float value
*/ */
public float getFloatValue() { public float getFloatValue() {
@@ -43,7 +43,8 @@ public class FloatValueRequest extends WiiUseApiRequest {
} }
/** /**
* @param val the thresholhd to set * Set the float value.
* @param val the value to set
*/ */
public void setFloatValue(float val) { public void setFloatValue(float val) {
this.floatValue = val; this.floatValue = val;

View File

@@ -2,67 +2,77 @@ package wiiusej.wiiuseapirequest;
/** /**
* Represents a request we could do to the WiiUse API. * Represents a request we could do to the WiiUse API.
*
* @author gduche * @author gduche
* *
*/ */
public class WiiUseApiRequest { public class WiiUseApiRequest {
public static int WIIUSE_STATUS_REQUEST=1; public static int WIIUSE_STATUS_REQUEST = 1;
public static int WIIUSE_ACTIVATE_SMOOTHING_REQUEST=2; public static int WIIUSE_ACTIVATE_SMOOTHING_REQUEST = 2;
public static int WIIUSE_DEACTIVATE_SMOOTHING_REQUEST=-2; public static int WIIUSE_DEACTIVATE_SMOOTHING_REQUEST = -2;
public static int WIIUSE_ACTIVATE_IR_TRACKING_REQUEST=3; public static int WIIUSE_ACTIVATE_IR_TRACKING_REQUEST = 3;
public static int WIIUSE_DEACTIVATE_IR_TRACKING_REQUEST=-3; public static int WIIUSE_DEACTIVATE_IR_TRACKING_REQUEST = -3;
public static int WIIUSE_ACTIVATE_MOTION_SENSING_REQUEST=4; public static int WIIUSE_ACTIVATE_MOTION_SENSING_REQUEST = 4;
public static int WIIUSE_DEACTIVATE_MOTION_SENSING_REQUEST=-4; public static int WIIUSE_DEACTIVATE_MOTION_SENSING_REQUEST = -4;
public static int WIIUSE_CLOSE_CONNECTION_REQUEST=5; public static int WIIUSE_CLOSE_CONNECTION_REQUEST = 5;
public static int WIIUSE_ACTIVATE_CONTINUOUS_REQUEST=6; public static int WIIUSE_ACTIVATE_CONTINUOUS_REQUEST = 6;
public static int WIIUSE_DEACTIVATE_CONTINUOUS_REQUEST=-6; public static int WIIUSE_DEACTIVATE_CONTINUOUS_REQUEST = -6;
public static int WIIUSE_ACTIVATE_RUMBLE_REQUEST=7; public static int WIIUSE_ACTIVATE_RUMBLE_REQUEST = 7;
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_ACCEL_THRESHOLHD_REQUEST = 10;
public static int WIIUSE_ALPHA_SMOOTHING_REQUEST=11; public static int WIIUSE_ALPHA_SMOOTHING_REQUEST = 11;
public static int WIIUSE_RESYNC = 12;
private int wiimoteId=0;
private int requestType=0; private int wiimoteId = 0;
private int requestType = 0;
/** /**
* Constructor setting the id of the wiimote concerned. * Constructor setting the id of the wiimote concerned.
* @param id the id of the wiimote concerned. *
* @param id
* the id of the wiimote concerned.
*/ */
public WiiUseApiRequest(int id){ public WiiUseApiRequest(int id) {
wiimoteId = id; wiimoteId = id;
} }
/** /**
* Constructor setting the id of the wiimote concerned. * Constructor setting the id of the wiimote concerned.
* @param id the id of the wiimote concerned. *
* @param id
* the id of the wiimote concerned.
* *
*/ */
public WiiUseApiRequest(int id, int type){ public WiiUseApiRequest(int id, int type) {
wiimoteId = id; wiimoteId = id;
requestType = type; requestType = type;
} }
/** /**
* Get id of the wiimote concerned by this request. * Get id of the wiimote concerned by this request.
*
* @return id of the wiimote concerned * @return id of the wiimote concerned
*/ */
public int getId(){ public int getId() {
return wiimoteId; return wiimoteId;
} }
/** /**
* Set id of the wiimote concerned by this request. * Set id of the wiimote concerned by this request.
* @param id id fh the wiimote concernet *
* @param id
* id fh the wiimote concernet
*/ */
public void setId(int id){ public void setId(int id) {
wiimoteId = id; wiimoteId = id;
} }
/** /**
* Get the request type. * Get the request type.
*
* @return the requestType * @return the requestType
*/ */
public int getRequestType() { public int getRequestType() {
@@ -71,13 +81,12 @@ public class WiiUseApiRequest {
/** /**
* Set the request type. * Set the request type.
* @param requestType the requestType to set *
* @param requestType
* the requestType to set
*/ */
public void setRequestType(int requestType) { public void setRequestType(int requestType) {
this.requestType = requestType; this.requestType = requestType;
} }
}
}