0.12 work in progress

git-svn-id: http://wiiusej.googlecode.com/svn/trunk@128 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
guilhem.duche
2008-04-27 21:01:55 +00:00
parent c09a03cc1e
commit 784707cd3b
8 changed files with 177 additions and 66 deletions

Binary file not shown.

View File

@@ -39,7 +39,28 @@ public class WiiUseApi {
static WiiUseApi getInstance() {
return instance;
}
/**
* Connect to a wiimote or wiimotes once an address is known.
* @param nbWiimotes The number of wiimotes.
* @return The number of wiimotes that successfully connected.
*/
synchronized native int connect(int nbWiimotes);
/**
* Find a wiimote or wiimotes.
* @param nbMaxWiimotes The number of wiimotes.
* @param timeout The number of seconds before the search times out.
* @return The number of wiimotes found.
*/
synchronized native int find(int nbMaxWiimotes, int timeout);
/**
* Initialize an array of wiimote structures (for the C side of the library).
* @param nbPossibleWiimotes size of the array.
*/
synchronized native void init(int nbPossibleWiimotes);
/**
* Try to connect to 2 wiimotes. Make them rumble to show they are
* connected.
@@ -52,7 +73,7 @@ public class WiiUseApi {
* wiimotes connected.
*/
synchronized native int doConnections(int nb, boolean rumble);
/**
* Close connection to the wiimote with the given id.
*
@@ -126,8 +147,8 @@ public class WiiUseApi {
* @param led4
* status of led4: True=ON, False=OFF
*/
synchronized native void setLeds(int id, boolean led1, boolean led2, boolean led3,
boolean led4);
synchronized native void setLeds(int id, boolean led1, boolean led2,
boolean led3, boolean led4);
/**
* Set how many degrees an angle must change to generate an event.
@@ -254,12 +275,40 @@ public class WiiUseApi {
*/
synchronized native void getStatus(int id);
/**
* Set the normal and expansion handshake timeouts.
*
* @param id
* the id of the wiimote concerned.
* @param nbWiimote
* Number of wiimotes connected.
* @param normalTimeout
* The timeout in milliseconds for a normal read.
* @param expansionTimeout
* The timeout in millisecondsd to wait for an expansion
* handshake.
*/
synchronized native void setTimeout(int id, int nbWiimote,
short normalTimeout, short expansionTimeout);
/**
* Set the IR sensitivity.
*
* @param id
* the id of the wiimote concerned.
* @param level
* 1-5, same as Wii system sensitivity setting. If the level is <
* 1, then level will be set to 1. If the level is > 5, then
* level will be set to 5.
*/
synchronized native void setIrSensitivity(int id, int level);
/**
* Check for new Events and Get it.
*
* @param gath
* the object where we store all the new events.
*/
native void specialPoll(EventsGatherer gath);
synchronized native void specialPoll(EventsGatherer gath);
}

View File

@@ -386,6 +386,11 @@ public class WiiUseApiManager extends Thread {
/* Polling */
wiiuse.specialPoll(gather);
try {
wiiuse.notify();
} catch (Exception e) {
// TODO: handle exception
}
/* deal with events gathered in Wiiuse API */
for (WiiUseApiEvent evt : gather.getEvents()) {

View File

@@ -18,59 +18,100 @@ package wiiusej.values;
/**
* Class that represents the orientation of the wiimote.
*
* @author guiguito
*/
public class Orientation {
private float roll;
private float pitch;
private float yaw;
/**
* Default constructor.
*/
public Orientation(){
roll = 0;
pitch = 0;
yaw = 0;
}
/**
* Contructor with raw, pitch , yaw.
* @param r raw
* @param p pitch
* @param y yaw
*/
public Orientation(float r, float p, float y){
roll = r;
pitch = p;
yaw = y;
}
/**
* @return the roll
*/
public float getRoll() {
return roll;
}
/**
* @return the pitch
*/
public float getPitch() {
return pitch;
}
private float roll;
private float pitch;
private float yaw;
private float a_roll;
private float a_pitch;
/**
* Default constructor.
*/
public Orientation() {
roll = 0;
pitch = 0;
yaw = 0;
a_roll = 0;
a_pitch = 0;
}
/**
* Contructor with raw, pitch , yaw.
*
* @param r
* roll (can be smoothed)
* @param p
* pitch (can be smoothed)
* @param y
* yaw
* @param ar
* absolute roll
* @param ap
* absolute pitch
*/
public Orientation(float r, float p, float y, float ar, float ap) {
roll = r;
pitch = p;
yaw = y;
a_roll = ar;
a_pitch = ap;
}
/**
* Get the roll (can be smoothed).
*
* @return the roll
*/
public float getRoll() {
return roll;
}
/**
* Get the pitch (can be smoothed).
*
* @return the pitch
*/
public float getPitch() {
return pitch;
}
/**
* Get the yaw.
*
* @return the yaw
*/
public float getYaw() {
return yaw;
}
/**
* Get absolute roll (can not be smoothed).
*
* @return the a_roll
*/
public float getARoll() {
return a_roll;
}
/**
* Get absolute pitch (can not be smoothed).
*
* @return the a_pitch
*/
public float getAPitch() {
return a_pitch;
}
@Override
public String toString() {
return "Orientation : (roll: " + roll + ", pitch: " + pitch + ", yaw: "
+ yaw + ", absolute roll: " + a_roll + ", absolute pitch: "
+ a_pitch + ")";
}
/**
* @return the yaw
*/
public float getYaw() {
return yaw;
}
@Override
public String toString() {
return "Orientation : (roll: "+roll+", pitch: "+pitch+", yaw: "+yaw+")";
}
}

View File

@@ -140,6 +140,10 @@ public class EventsGatherer {
* pitch
* @param ya
* yaw
* @param ar
* absolute roll
* @param ap
* absolute pitch
* @param x
* gravity force on x axis
* @param y
@@ -155,12 +159,12 @@ public class EventsGatherer {
*/
public void addMotionSensingValues(float orientationThreshold,
int accelerationThreshold, boolean smoothingState,
float alphaSmooth, float r, float p, float ya, float x, float y,
float alphaSmooth, float r, float p, float ya, float ar, float ap, float x, float y,
float z, short xx, short yy, short zz) {
if (genericEvent != null) {
genericEvent.setMotionSensingEvent(orientationThreshold,
accelerationThreshold, smoothingState, alphaSmooth, r, p,
ya, x, y, z, xx, yy, zz);
ya, ar, ap, x, y, z, xx, yy, zz);
}
}

View File

@@ -176,6 +176,10 @@ public class GenericEvent extends WiiUseApiEvent {
* pitch
* @param ya
* yaw
* @param ar
* absolute roll
* @param ap
* absolute pitch
* @param x
* gravity force on x axis
* @param y
@@ -191,11 +195,11 @@ public class GenericEvent extends WiiUseApiEvent {
*/
public void setMotionSensingEvent(float orientationThreshold,
int accelerationThreshold, boolean smoothingState,
float alphaSmooth, float r, float p, float ya, float x, float y,
float z, short xx, short yy, short zz) {
float alphaSmooth, float r, float p, float ya, float ar, float ap,
float x, float y, float z, short xx, short yy, short zz) {
motionSensingEvent = new MotionSensingEvent(getWiimoteId(),
orientationThreshold, accelerationThreshold, smoothingState,
alphaSmooth, r, p, ya, x, y, z, xx, yy, zz);
alphaSmooth, r, p, ya, ar, ap, x, y, z, xx, yy, zz);
}
@Override

View File

@@ -58,6 +58,10 @@ public class MotionSensingEvent extends WiimoteEvent {
* pitch
* @param ya
* yaw
* @param ar
* absolute roll
* @param ap
* absolute pitch
* @param x
* gravity force on x axis
* @param y
@@ -73,14 +77,14 @@ public class MotionSensingEvent extends WiimoteEvent {
*/
public MotionSensingEvent(int id, float orientationThreshold,
int accelerationThreshold, boolean smoothingState,
float alphaSmooth, float r, float p, float ya, float x, float y,
float z, short xx, short yy, short zz) {
float alphaSmooth, float r, float p, float ya, float ar, float ap,
float x, float y, float z, short xx, short yy, short zz) {
super(id);
this.orientationThreshold = orientationThreshold;
this.accelerationThreshold = accelerationThreshold;
this.isSmoothingActive = smoothingState;
this.alphaSmoothing = alphaSmooth;
setOrientationAndGforce(r, p, ya, x, y, z, xx, yy, zz);
setOrientationAndGforce(r, p, ya, ar, ap, x, y, z, xx, yy, zz);
}
/**
@@ -92,6 +96,10 @@ public class MotionSensingEvent extends WiimoteEvent {
* pitch
* @param ya
* yaw
* @param ar
* absolute roll
* @param ap
* absolute pitch
* @param x
* gravity force on x axis
* @param y
@@ -105,9 +113,9 @@ public class MotionSensingEvent extends WiimoteEvent {
* @param zz
* raw acceleration on z axis
*/
private void setOrientationAndGforce(float r, float p, float ya, float x,
float y, float z, short xx, short yy, short zz) {
this.orientation = new Orientation(r, p, ya);
private void setOrientationAndGforce(float r, float p, float ya, float ar,
float ap, float x, float y, float z, short xx, short yy, short zz) {
this.orientation = new Orientation(r, p, ya, ar, ap);
this.gforce = new GForce(x, y, z);
this.acceleration = new RawAcceleration(xx, yy, zz);
}

Binary file not shown.