From 732154a82ff08bd0473ac1f13c12578d6dbc0db4 Mon Sep 17 00:00:00 2001 From: "guilhem.duche" Date: Fri, 9 May 2008 22:19:58 +0000 Subject: [PATCH] 0.12 going well. Added everything for the nunchuk. Need more testing. git-svn-id: http://wiiusej.googlecode.com/svn/trunk@140 ae48ae66-6a45-0410-b38e-211266189506 --- WiiUseJC/wiiusej_WiiUseApi.c | 54 ++++++++++++++++++++++++++++++++-- WiiUseJC/wiiusej_WiiUseApi.def | 2 ++ WiiUseJC/wiiusej_WiiUseApi.h | 20 +++++++++++-- 3 files changed, 72 insertions(+), 4 deletions(-) diff --git a/WiiUseJC/wiiusej_WiiUseApi.c b/WiiUseJC/wiiusej_WiiUseApi.c index 905b1c4..4fad079 100644 --- a/WiiUseJC/wiiusej_WiiUseApi.c +++ b/WiiUseJC/wiiusej_WiiUseApi.c @@ -192,7 +192,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setLeds /** * Set how many degrees an angle must change to generate an event. * @param id id of the wiimote concerned - * @param angle minimum angle detected by an event + * @param thresh minimum angle detected by an event */ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold (JNIEnv *env, jobject obj, jint id, jfloat thresh) { @@ -202,7 +202,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold /** * 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 + * @param val minimum value detected by an event */ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAccelThreshold (JNIEnv *env, jobject obj, jint id, jint val) { @@ -357,6 +357,26 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setIrSensitivity wiiuse_set_ir_sensitivity(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), level); } +/** + * Set how many degrees an angle must change to generate an event for the nunchuk. + * @param id id of the wiimote concerned + * @param thresh minimum angle detected by an event + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold +(JNIEnv *env, jobject obj, jint id, jfloat thresh) { + wiiuse_set_nunchuk_orient_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), thresh); +} + +/** + * Set how much acceleration must change to generate an event for the nunchuk. + * @param id id of the wiimote concerned + * @param val minimum value detected by an event + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold +(JNIEnv *env, jobject obj, jint id, jint val) { + wiiuse_set_nunchuk_accel_threshold(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), val); +} + /** * Get status and values from the wiimotes and send it through callbacks. * @param wim the wiimote object to fill with the datas. @@ -442,6 +462,36 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll wiimotes[i]->accel.x, wiimotes[i]->accel.y, wiimotes[i]->accel.z); } + /* Expansions support support*/ + if (WIIUSE_USING_EXP(wiimotes[i])) { + /* Nunchuk support */ + if (wiimotes[i]->exp.type == EXP_NUNCHUK) { + /* put nunchuk values to wiimote generic event */ + mid = (*env)->GetMethodID(env, cls, + "addNunchunkEventToPreparedWiimoteEvent", "(SSSFIZFFFFFFFFFSSSIISSSSSS)V"); + if (mid == 0) { + return; + } + struct nunchuk_t* nc = (nunchuk_t*)&wiimotes[i]->exp.nunchuk; + + (*env)->CallVoidMethod(env, gath, mid, + /* buttons */ + nc->btns,nc->btns_released,nc->btns_held, + /* motion sensing */ + nc->orient_threshold,nc->accel_threshold, + WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING),nc->accel_calib.st_alpha, + nc->orient.roll, nc->orient.pitch, nc->orient.yaw, + nc->orient.a_roll, nc->orient.a_pitch, + nc->gforce.x, nc->gforce.y, nc->gforce.z, + nc->accel.x, nc->accel.y, nc->accel.z, + /* joystick */ + nc->js.ang,nc->js.mag, + nc->js.max.x,nc->js.max.y, + nc->js.min.x,nc->js.min.y, + nc->js.center.x,nc->js.center.y); + } + } + /* add generic event to java object used to gather events in c environment */ mid = (*env)->GetMethodID(env, cls, "addWiimoteEvent", "()V"); diff --git a/WiiUseJC/wiiusej_WiiUseApi.def b/WiiUseJC/wiiusej_WiiUseApi.def index 54b4857..3b6de9c 100644 --- a/WiiUseJC/wiiusej_WiiUseApi.def +++ b/WiiUseJC/wiiusej_WiiUseApi.def @@ -28,4 +28,6 @@ Java_wiiusej_WiiUseApi_setVirtualScreenResolution Java_wiiusej_WiiUseApi_getStatus Java_wiiusej_WiiUseApi_setTimeout Java_wiiusej_WiiUseApi_setIrSensitivity +Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold +Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold Java_wiiusej_WiiUseApi_specialPoll diff --git a/WiiUseJC/wiiusej_WiiUseApi.h b/WiiUseJC/wiiusej_WiiUseApi.h index 10af29a..bdc289a 100644 --- a/WiiUseJC/wiiusej_WiiUseApi.h +++ b/WiiUseJC/wiiusej_WiiUseApi.h @@ -226,7 +226,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus /* * Class: wiiusej_WiiUseApi * Method: setTimeout - * Signature: (IISS)V + * Signature: (ISS)V */ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout (JNIEnv *, jobject, jint, jshort, jshort); @@ -239,10 +239,26 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setTimeout JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setIrSensitivity (JNIEnv *, jobject, jint, jint); +/* + * Class: wiiusej_WiiUseApi + * Method: setNunchukOrientationThreshold + * Signature: (IF)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukOrientationThreshold + (JNIEnv *, jobject, jint, jfloat); + +/* + * Class: wiiusej_WiiUseApi + * Method: setNunchukAccelerationThreshold + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setNunchukAccelerationThreshold + (JNIEnv *, jobject, jint, jint); + /* * Class: wiiusej_WiiUseApi * Method: specialPoll - * Signature: (Lwiiusej/wiiuseapievents/EventsGatherer;)V + * Signature: (Lwiiusej/wiiusejevents/utils/EventsGatherer;)V */ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll (JNIEnv *, jobject, jobject);