0.12 work in progress
git-svn-id: http://wiiusej.googlecode.com/svn/trunk@127 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
Binary file not shown.
@@ -168,7 +168,23 @@ typedef enum ir_position_t {
|
||||
* @param button The button you are interested in.
|
||||
* @return 1 if the button is pressed, 0 if not.
|
||||
*/
|
||||
#define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button))
|
||||
#define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button))
|
||||
|
||||
/**
|
||||
* @brief Return the IR sensitivity level.
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param lvl [out] Pointer to an int that will hold the level setting.
|
||||
* If no level is set 'lvl' will be set to 0.
|
||||
*/
|
||||
#define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \
|
||||
do { \
|
||||
if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \
|
||||
else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \
|
||||
else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \
|
||||
else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \
|
||||
else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \
|
||||
else *lvl = 0; \
|
||||
} while (0)
|
||||
|
||||
#define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020)
|
||||
#define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040)
|
||||
@@ -222,13 +238,14 @@ typedef void (*wiiuse_read_cb)(struct wiimote_t* wm, byte* data, unsigned short
|
||||
* @brief Data read request structure.
|
||||
*/
|
||||
struct read_req_t {
|
||||
wiiuse_read_cb cb; /**< read data callback */
|
||||
byte* buf; /**< buffer where read data is written */
|
||||
unsigned int addr; /**< the offset that the read started at */
|
||||
unsigned short size; /**< the length of the data read */
|
||||
unsigned short wait; /**< num bytes still needed to finish read */
|
||||
wiiuse_read_cb cb; /**< read data callback */
|
||||
byte* buf; /**< buffer where read data is written */
|
||||
unsigned int addr; /**< the offset that the read started at */
|
||||
unsigned short size; /**< the length of the data read */
|
||||
unsigned short wait; /**< num bytes still needed to finish read */
|
||||
byte dirty; /**< set to 1 if not using callback and needs to be cleaned up */
|
||||
|
||||
struct read_req_t* next; /**< next read request in the queue */
|
||||
struct read_req_t* next; /**< next read request in the queue */
|
||||
};
|
||||
|
||||
|
||||
@@ -495,8 +512,11 @@ typedef struct wiimote_state_t {
|
||||
typedef enum WIIUSE_EVENT_TYPE {
|
||||
WIIUSE_NONE = 0,
|
||||
WIIUSE_EVENT,
|
||||
WIIUSE_STATUS,
|
||||
WIIUSE_STATUS,
|
||||
WIIUSE_CONNECT,
|
||||
WIIUSE_DISCONNECT,
|
||||
WIIUSE_UNEXPECTED_DISCONNECT,
|
||||
WIIUSE_READ_DATA,
|
||||
WIIUSE_NUNCHUK_INSERTED,
|
||||
WIIUSE_NUNCHUK_REMOVED,
|
||||
WIIUSE_CLASSIC_CTRL_INSERTED,
|
||||
@@ -530,8 +550,8 @@ typedef struct wiimote_t {
|
||||
WCONST byte leds; /**< currently lit leds */
|
||||
WCONST float battery_level; /**< battery level */
|
||||
|
||||
WCONST int flags; /**< options flag */
|
||||
|
||||
WCONST int flags; /**< options flag */
|
||||
|
||||
WCONST byte handshake_state; /**< the state of the connection handshake */
|
||||
|
||||
WCONST struct read_req_t* read_req; /**< list of data read requests */
|
||||
@@ -592,7 +612,7 @@ WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds);
|
||||
WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int offset, unsigned short len);
|
||||
WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, unsigned short len);
|
||||
WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len);
|
||||
WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid);
|
||||
@@ -617,10 +637,11 @@ WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level);
|
||||
|
||||
/* nunchuk.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct nunchuk_t* nc, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct nunchuk_t* nc, int threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -46,6 +46,36 @@ static int nbMaxWiiMotes=0;
|
||||
|
||||
/****************** GENERAL FUNCTIONS DEFINITIONS *************************/
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_connect
|
||||
(JNIEnv *env, jobject obj, jint nbWiimotes){
|
||||
return wiiuse_connect(wiimotes, 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.
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_find
|
||||
(JNIEnv *env, jobject obj, jint nbMaxWiimotes, jint timeout){
|
||||
return wiiuse_find(wiimotes, nbMaxWiimotes, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize an array of wiimote structures (for the C side of the library).
|
||||
* @param nbPossibleWiimotes size of the array.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_init
|
||||
(JNIEnv *env, jobject obj, jint nbPossibleWiimotes){
|
||||
wiimotes = wiiuse_init(nbPossibleWiimotes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to connect to 2 wiimotes.
|
||||
* Make them rumble to show they are connected.
|
||||
@@ -227,9 +257,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAccelThreshold
|
||||
(JNIEnv *env, jobject obj, jint id, jint val) {
|
||||
/*
|
||||
wiiuse_set_accel_threshold(wiimotes[id-1], val);
|
||||
*/
|
||||
wiiuse_set_accel_threshold(wiimotes[id-1], val);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -349,6 +377,40 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus
|
||||
wiiuse_status(wiimotes[id-1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout
|
||||
(JNIEnv *env, jobject obj, jint id, jint nbWiimote, jshort normalTimeout, jshort expansionTimeout){
|
||||
wiiuse_set_timeout(wiimotes, nbWiimote, normalTimeout, 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.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setIrSensitivity
|
||||
(JNIEnv *env, jobject obj, jint id, jint level){
|
||||
wiiuse_set_ir_sensitivity(wiimotes[id-1], level);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get status and values from the wiimotes and send it through callbacks.
|
||||
* @param wim the wiimote object to fill with the datas.
|
||||
@@ -361,7 +423,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
|
||||
short leds = 0;
|
||||
jclass cls = (*env)->GetObjectClass(env, gath);
|
||||
jmethodID mid;
|
||||
|
||||
|
||||
if (wiiuse_poll(wiimotes, nbMaxWiiMotes)) {
|
||||
/*
|
||||
* This happens if something happened on any wiimote.
|
||||
@@ -427,10 +489,11 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
|
||||
wiimotes[i]->orient_threshold, wiimotes[i]->accel_threshold,
|
||||
WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING), wiimotes[i]->accel_calib.st_alpha,
|
||||
wiimotes[i]->orient.roll, wiimotes[i]->orient.pitch, wiimotes[i]->orient.yaw,
|
||||
wiimotes[i]->orient.a_roll, wiimotes[i]->orient.a_pitch,
|
||||
wiimotes[i]->gforce.x, wiimotes[i]->gforce.y, wiimotes[i]->gforce.z,
|
||||
wiimotes[i]->accel.x, wiimotes[i]->accel.y, wiimotes[i]->accel.z);
|
||||
}
|
||||
|
||||
|
||||
/* add generic event to java object used to gather events in c environment */
|
||||
mid = (*env)->GetMethodID(env, cls, "addWiimoteEvent",
|
||||
"()V");
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
EXPORTS
|
||||
Java_wiiusej_WiiUseApi_connect
|
||||
Java_wiiusej_WiiUseApi_find
|
||||
Java_wiiusej_WiiUseApi_init
|
||||
Java_wiiusej_WiiUseApi_doConnections
|
||||
Java_wiiusej_WiiUseApi_closeConnection
|
||||
Java_wiiusej_WiiUseApi_shutdownApi
|
||||
@@ -17,11 +20,12 @@ Java_wiiusej_WiiUseApi_activateSmoothing
|
||||
Java_wiiusej_WiiUseApi_deactivateSmoothing
|
||||
Java_wiiusej_WiiUseApi_activateContinuous
|
||||
Java_wiiusej_WiiUseApi_deactivateContinuous
|
||||
Java_wiiusej_WiiUseApi_deactivateMotionSensing
|
||||
Java_wiiusej_WiiUseApi_getStatus
|
||||
Java_wiiusej_WiiUseApi_specialPoll
|
||||
Java_wiiusej_WiiUseApi_setScreenRatio43
|
||||
Java_wiiusej_WiiUseApi_setScreenRatio169
|
||||
Java_wiiusej_WiiUseApi_setSensorBarAboveScreen
|
||||
Java_wiiusej_WiiUseApi_setSensorBarBelowScreen
|
||||
Java_wiiusej_WiiUseApi_setVirtualScreenResolution
|
||||
Java_wiiusej_WiiUseApi_getStatus
|
||||
Java_wiiusej_WiiUseApi_setTimeout
|
||||
Java_wiiusej_WiiUseApi_setIrSensitivity
|
||||
Java_wiiusej_WiiUseApi_specialPoll
|
||||
|
||||
@@ -7,6 +7,30 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: connect
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_connect
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: find
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_find
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: init
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_init
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: doConnections
|
||||
@@ -199,6 +223,22 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setVirtualScreenResolution
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setTimeout
|
||||
* Signature: (IISS)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout
|
||||
(JNIEnv *, jobject, jint, jint, jshort, jshort);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: setIrSensitivity
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setIrSensitivity
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: wiiusej_WiiUseApi
|
||||
* Method: specialPoll
|
||||
|
||||
Reference in New Issue
Block a user