From dc13f8feee51288197fa7a8cfea9b202e2d67da7 Mon Sep 17 00:00:00 2001 From: "guilhem.duche" Date: Fri, 15 Feb 2008 14:26:50 +0000 Subject: [PATCH] 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 --- WiiUseJ/src/wiiusej/WiiUseApi.java | 4 +- WiiUseJ/src/wiiusej/WiiUseApiManager.java | 40 ++++++--- WiiUseJ/src/wiiusej/Wiimote.java | 18 +++++ .../wiiuseapirequest/FloatValueRequest.java | 7 +- .../wiiuseapirequest/WiiUseApiRequest.java | 81 ++++++++++--------- 5 files changed, 96 insertions(+), 54 deletions(-) diff --git a/WiiUseJ/src/wiiusej/WiiUseApi.java b/WiiUseJ/src/wiiusej/WiiUseApi.java index 93042a1..d8b48c0 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApi.java +++ b/WiiUseJ/src/wiiusej/WiiUseApi.java @@ -103,14 +103,14 @@ public class WiiUseApi { * @param id id of the wiimote concerned * @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. * @param id id of the wiimote concerned * @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. diff --git a/WiiUseJ/src/wiiusej/WiiUseApiManager.java b/WiiUseJ/src/wiiusej/WiiUseApiManager.java index cc1de77..5eeac4b 100644 --- a/WiiUseJ/src/wiiusej/WiiUseApiManager.java +++ b/WiiUseJ/src/wiiusej/WiiUseApiManager.java @@ -1,6 +1,5 @@ - package wiiusej; +package wiiusej; -import java.util.ArrayList; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; @@ -10,6 +9,7 @@ import wiiusej.wiiuseapievents.EventsGatherer; import wiiusej.wiiuseapievents.WiiUseApiEvent; import wiiusej.wiiuseapievents.WiiUseApiListener; import wiiusej.wiiuseapirequest.FloatValueRequest; +import wiiusej.wiiuseapirequest.IntValueRequest; import wiiusej.wiiuseapirequest.LedsRequest; import wiiusej.wiiuseapirequest.WiiUseApiRequest; @@ -98,9 +98,9 @@ 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; + wiimotes[id] = null; requests.add(new WiiUseApiRequest(id, WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST)); System.out.println("Wiimote " + id + " disconnected !"); @@ -273,8 +273,8 @@ public class WiiUseApiManager extends Thread { * @param th * threshold */ - public void setAccelerationThreshold(int id, float th) { - requests.add(new FloatValueRequest(id, + public void setAccelerationThreshold(int id, int th) { + requests.add(new IntValueRequest(id, WiiUseApiRequest.WIIUSE_ACCEL_THRESHOLHD_REQUEST, th)); } @@ -291,6 +291,16 @@ public class WiiUseApiManager extends Thread { 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. * @@ -318,11 +328,12 @@ public class WiiUseApiManager extends Thread { if (req.getRequestType() == WiiUseApiRequest.WIIUSE_CLOSE_CONNECTION_REQUEST) { /* 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 !!!"); + System.out + .println("No more wiimotes connected !!!"); shutdown(); } } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_STATUS_REQUEST) { @@ -369,12 +380,15 @@ public class WiiUseApiManager extends Thread { ((FloatValueRequest) req).getFloatValue()); } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ACCEL_THRESHOLHD_REQUEST) { /* set acceleration threshold request */ - wiiuse.setOrientThreshold(req.getId(), - ((FloatValueRequest) req).getFloatValue()); + wiiuse.setAccelThreshold(req.getId(), + ((IntValueRequest) req).getIntValue()); } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_ALPHA_SMOOTHING_REQUEST) { /* set alpha smoothing request */ - wiiuse.setOrientThreshold(req.getId(), + wiiuse.setAlphaSmoothing(req.getId(), ((FloatValueRequest) req).getFloatValue()); + } else if (req.getRequestType() == WiiUseApiRequest.WIIUSE_RESYNC) { + /* set resync request */ + wiiuse.reSync(req.getId()); } else { 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 !!! : " + evt); } - } + } gather.clearEvents(); } } else { @@ -446,7 +460,7 @@ public class WiiUseApiManager extends Thread { */ private void notifyWiiUseApiListener(WiiUseApiEvent evt) { for (WiiUseApiListener listener : getWiiUseApiListeners()) { - listener.wiiUseApiEvent(evt); + listener.wiiUseApiEvent(evt); } } diff --git a/WiiUseJ/src/wiiusej/Wiimote.java b/WiiUseJ/src/wiiusej/Wiimote.java index 7f8b198..e85a0cc 100644 --- a/WiiUseJ/src/wiiusej/Wiimote.java +++ b/WiiUseJ/src/wiiusej/Wiimote.java @@ -140,6 +140,24 @@ public class Wiimote implements WiiUseApiListener { public void setOrientationThreshold(float 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. diff --git a/WiiUseJ/src/wiiusej/wiiuseapirequest/FloatValueRequest.java b/WiiUseJ/src/wiiusej/wiiuseapirequest/FloatValueRequest.java index ed400fa..238ca48 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapirequest/FloatValueRequest.java +++ b/WiiUseJ/src/wiiusej/wiiuseapirequest/FloatValueRequest.java @@ -1,8 +1,7 @@ package wiiusej.wiiuseapirequest; /** - * Represents a request to set orientation Threshold in Wiiuse API. - * Orientation Threshold is the minimum angle (in degrees) between two events. + * Represents a request with a float value to pass to wiiuse API. * @author gduche * */ @@ -36,6 +35,7 @@ public class FloatValueRequest extends WiiUseApiRequest { } /** + * Get the float value. * @return the float value */ 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) { this.floatValue = val; diff --git a/WiiUseJ/src/wiiusej/wiiuseapirequest/WiiUseApiRequest.java b/WiiUseJ/src/wiiusej/wiiuseapirequest/WiiUseApiRequest.java index 528adb1..59ef9c1 100644 --- a/WiiUseJ/src/wiiusej/wiiuseapirequest/WiiUseApiRequest.java +++ b/WiiUseJ/src/wiiusej/wiiuseapirequest/WiiUseApiRequest.java @@ -2,67 +2,77 @@ package wiiusej.wiiuseapirequest; /** * Represents a request we could do to the WiiUse API. + * * @author gduche - * + * */ public class WiiUseApiRequest { - public static int WIIUSE_STATUS_REQUEST=1; - public static int WIIUSE_ACTIVATE_SMOOTHING_REQUEST=2; - public static int WIIUSE_DEACTIVATE_SMOOTHING_REQUEST=-2; - public static int WIIUSE_ACTIVATE_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_DEACTIVATE_MOTION_SENSING_REQUEST=-4; - public static int WIIUSE_CLOSE_CONNECTION_REQUEST=5; - public static int WIIUSE_ACTIVATE_CONTINUOUS_REQUEST=6; - public static int WIIUSE_DEACTIVATE_CONTINUOUS_REQUEST=-6; - public static int WIIUSE_ACTIVATE_RUMBLE_REQUEST=7; - 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; - + public static int WIIUSE_STATUS_REQUEST = 1; + public static int WIIUSE_ACTIVATE_SMOOTHING_REQUEST = 2; + public static int WIIUSE_DEACTIVATE_SMOOTHING_REQUEST = -2; + public static int WIIUSE_ACTIVATE_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_DEACTIVATE_MOTION_SENSING_REQUEST = -4; + public static int WIIUSE_CLOSE_CONNECTION_REQUEST = 5; + public static int WIIUSE_ACTIVATE_CONTINUOUS_REQUEST = 6; + public static int WIIUSE_DEACTIVATE_CONTINUOUS_REQUEST = -6; + public static int WIIUSE_ACTIVATE_RUMBLE_REQUEST = 7; + 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; + public static int WIIUSE_RESYNC = 12; + + private int wiimoteId = 0; + private int requestType = 0; + /** * 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; } - + /** * 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; requestType = type; } - + /** * Get id of the wiimote concerned by this request. + * * @return id of the wiimote concerned */ - public int getId(){ + public int getId() { return wiimoteId; } - + /** * 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; } /** * Get the request type. + * * @return the requestType */ public int getRequestType() { @@ -71,13 +81,12 @@ public class WiiUseApiRequest { /** * Set the request type. - * @param requestType the requestType to set + * + * @param requestType + * the requestType to set */ public void setRequestType(int requestType) { this.requestType = requestType; } - - - -} +}