firt working version on wiiuse 0.10

git-svn-id: http://wiiusej.googlecode.com/svn/trunk@58 ae48ae66-6a45-0410-b38e-211266189506
This commit is contained in:
guilhem.duche
2008-02-15 16:25:32 +00:00
parent 2db1da4990
commit c9ee36198e
2 changed files with 68 additions and 66 deletions

View File

@@ -339,7 +339,7 @@
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="dll" artifactName="WiiUseJ" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.mingw.so.release.809597794" name="Release" parent="cdt.managedbuild.config.gnu.mingw.so.release">
<configuration artifactExtension="dll" artifactName="WiiUseJ" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.mingw.so.release.809597794" name="Release" parent="cdt.managedbuild.config.gnu.mingw.so.release" postannouncebuildStep="" postbuildStep="" preannouncebuildStep="" prebuildStep="">
<folderInfo id="cdt.managedbuild.config.gnu.mingw.so.release.809597794." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.mingw.so.release.1990955197" name="MinGW GCC" superClass="cdt.managedbuild.toolchain.gnu.mingw.so.release">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.mingw.so.release.486933711" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.mingw.so.release"/>
@@ -368,9 +368,11 @@
<listOptionValue builtIn="false" value="wiiusej_WiiUseApi.def"/>
</option>
<option id="gnu.c.link.option.libs.1341142556" name="Libraries (-l)" superClass="gnu.c.link.option.libs" valueType="libs">
<listOptionValue builtIn="false" value="C:\temp\wiiuse.lib"/>
<listOptionValue builtIn="false" value="wiiuse"/>
</option>
<option id="gnu.c.link.option.paths.1179889356" name="Library search path (-L)" superClass="gnu.c.link.option.paths" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;C:\temp&quot;"/>
</option>
<option id="gnu.c.link.option.paths.1179889356" name="Library search path (-L)" superClass="gnu.c.link.option.paths" valueType="libPaths"/>
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1112337924" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>

View File

@@ -29,10 +29,6 @@ static wiimote** wiimotes;
static int nbMaxWiiMotes=0;
static JNIEnv *globalEnv;
static jobject globalObj;
static jobject globalWim;
/****************** GENERAL FUNCTIONS DEFINITIONS *************************/
/**
@@ -47,7 +43,8 @@ JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_doConnections
/* variables declarations */
int found, connected, i;
short leds;
nbMaxWiiMotes = nbConnects;
/* initialize wiimotes array with the maximum number of wiimotes */
@@ -80,7 +77,12 @@ JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_doConnections
* to tell which wiimotes are connected (just like the wii does).
*/
for (i=0;i<nbMaxWiiMotes;i++) {
wiiuse_set_leds(wiimotes[i], ((2^(i%4-1))*16));
leds = 0;
if (i%4==0) leds |= WIIMOTE_LED_1;
else if (i%4==1) leds |= WIIMOTE_LED_2;
else if (i%4==2) leds |= WIIMOTE_LED_3;
else if (i%4==3) leds |= WIIMOTE_LED_4;
wiiuse_set_leds(wiimotes[i], leds);
wiiuse_rumble(wiimotes[i], 1);
}
@@ -105,7 +107,7 @@ JNIEXPORT jint JNICALL Java_wiiusej_WiiUseApi_doConnections
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_closeConnection
(JNIEnv *env, jobject obj, jint id) {
wiiuse_disconnect(wiimotes[id]);
wiiuse_disconnect(wiimotes[id-1]);
}
/**
@@ -123,7 +125,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_shutdownApi
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateRumble
(JNIEnv *env, jobject obj, jint id) {
wiiuse_rumble(wiimotes[id], 1);
wiiuse_rumble(wiimotes[id-1], 1);
}
/**
@@ -132,7 +134,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateRumble
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateRumble
(JNIEnv *env, jobject obj, jint id) {
wiiuse_rumble(wiimotes[id], 0);
wiiuse_rumble(wiimotes[id-1], 0);
}
/**
@@ -141,7 +143,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateRumble
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateIRTracking
(JNIEnv *env, jobject obj, jint id) {
wiiuse_set_ir(wiimotes[id], 1);
wiiuse_set_ir(wiimotes[id-1], 1);
}
/**
@@ -150,7 +152,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateIRTracking
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateIRTracking
(JNIEnv *env, jobject obj, jint id) {
wiiuse_set_ir(wiimotes[id], 0);
wiiuse_set_ir(wiimotes[id-1], 0);
}
/**
@@ -159,7 +161,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateIRTracking
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateMotionSensing
(JNIEnv *env, jobject obj, jint id) {
wiiuse_motion_sensing(wiimotes[id], 1);
wiiuse_motion_sensing(wiimotes[id-1], 1);
}
/**
@@ -168,7 +170,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateMotionSensing
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateMotionSensing
(JNIEnv *env, jobject obj, jint id) {
wiiuse_motion_sensing(wiimotes[id], 0);
wiiuse_motion_sensing(wiimotes[id-1], 0);
}
/**
@@ -188,7 +190,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setLeds
if (led3) leds |= WIIMOTE_LED_3;
if (led4) leds |= WIIMOTE_LED_4;
wiiuse_set_leds(wiimotes[id], leds);
wiiuse_set_leds(wiimotes[id-1], leds);
}
/**
@@ -198,7 +200,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setLeds
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold
(JNIEnv *env, jobject obj, jint id, jfloat thresh) {
wiiuse_set_orient_threshold(wiimotes[id], thresh);
wiiuse_set_orient_threshold(wiimotes[id-1], thresh);
}
/**
@@ -207,8 +209,10 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setOrientThreshold
* @param value minimum value detected by an event
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAccelThreshold
(JNIEnv *env, jobject obj, jint id, jfloat thresh) {
wiiuse_set_accel_threshold(wiimotes[id], thresh);
(JNIEnv *env, jobject obj, jint id, jint val) {
/*
wiiuse_set_accel_threshold(wiimotes[id-1], val);
*/
}
/**
@@ -218,7 +222,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setAccelThreshold
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSmoothAlpha
(JNIEnv *env, jobject obj, jint id, jfloat val) {
wiiuse_set_smooth_alpha(wiimotes[id], val);
wiiuse_set_smooth_alpha(wiimotes[id-1], val);
}
/**
@@ -227,7 +231,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSmoothAlpha
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_reSync
(JNIEnv *env, jobject obj, jint id) {
wiiuse_resync(wiimotes[id]);
wiiuse_resync(wiimotes[id-1]);
}
/**
@@ -237,7 +241,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_reSync
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSmoothing
(JNIEnv *env, jobject obj, jint id) {
wiiuse_set_flags(wiimotes[id], WIIUSE_SMOOTHING, 0);
wiiuse_set_flags(wiimotes[id-1], WIIUSE_SMOOTHING, 0);
}
/**
@@ -246,7 +250,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateSmoothing
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSmoothing
(JNIEnv *env, jobject obj, jint id) {
wiiuse_set_flags(wiimotes[id], 0, WIIUSE_SMOOTHING);
wiiuse_set_flags(wiimotes[id-1], 0, WIIUSE_SMOOTHING);
}
/**
@@ -256,7 +260,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSmoothing
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateContinuous
(JNIEnv *env, jobject obj, jint id) {
wiiuse_set_flags(wiimotes[id], WIIUSE_CONTINUOUS, 0);
wiiuse_set_flags(wiimotes[id-1], WIIUSE_CONTINUOUS, 0);
}
/**
@@ -266,7 +270,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_activateContinuous
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateContinuous
(JNIEnv *env, jobject obj, jint id) {
wiiuse_set_flags(wiimotes[id], 0, WIIUSE_CONTINUOUS);
wiiuse_set_flags(wiimotes[id-1], 0, WIIUSE_CONTINUOUS);
}
/**
@@ -276,7 +280,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateContinuous
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus
(JNIEnv *env, jobject obj, jint id) {
wiiuse_status(wiimotes[id]);
wiiuse_status(wiimotes[id-1]);
}
/**
@@ -284,18 +288,14 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_getStatus
* @param wim the wiimote object to fill with the datas.
*/
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
(JNIEnv *env, jobject obj, jobject wim) {
(JNIEnv *env, jobject obj, jobject gath) {
/* Variables Declarations */
int i;
short leds = 0;
jclass cls = (*globalEnv)->GetObjectClass(globalEnv, globalWim);
jclass cls = (*env)->GetObjectClass(env, gath);
jmethodID mid;
globalEnv = env;
globalObj = obj;
globalWim = wim;
if (wiiuse_poll(wiimotes, nbMaxWiiMotes)) {
/*
* This happens if something happened on any wiimote.
@@ -305,11 +305,11 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
switch (wiimotes[i]->event) {
case WIIUSE_EVENT:
/* a generic event occured */
mid = (*globalEnv)->GetMethodID(globalEnv, cls, "prepareWiiMoteEvent", "(ISSS)V");
mid = (*env)->GetMethodID(env, cls, "prepareWiiMoteEvent", "(ISSS)V");
if (mid == 0) {
return;
}
(*globalEnv)->CallVoidMethod(globalEnv, globalWim, mid, wiimotes[i]->unid, wiimotes[i]->btns,
(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid, wiimotes[i]->btns,
wiimotes[i]->btns_released, wiimotes[i]->btns_held);
/*
* If IR tracking is enabled then print the coordinates
@@ -323,12 +323,12 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
for (; i < 4; ++i) {
/* check if the source is visible */
if (wiimotes[i]->ir.dot[i].visible) {
mid = (*globalEnv)->GetMethodID(globalEnv, cls, "addIRPointToPreparedWiiMoteEvent",
mid = (*env)->GetMethodID(env, cls, "addIRPointToPreparedWiiMoteEvent",
"(II)V");
if (mid == 0) {
return;
}
(*globalEnv)->CallVoidMethod(globalEnv, globalWim, mid,
(*env)->CallVoidMethod(env, gath, mid,
wiimotes[i]->ir.dot[i].x, wiimotes[i]->ir.dot[i].y);
}
}
@@ -337,54 +337,54 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
/* Motion Sensing */
if (WIIUSE_USING_ACC(wiimotes[i])) {
/* set orientation and gravity force */
mid = (*globalEnv)->GetMethodID(globalEnv, cls,
mid = (*env)->GetMethodID(env, cls,
"addMotionSensingValues", "(FFFFFF)V");
if (mid == 0) {
return;
}
(*globalEnv)->CallVoidMethod(globalEnv, globalWim, mid,
(*env)->CallVoidMethod(env, gath, mid,
wiimotes[i]->orient.roll, wiimotes[i]->orient.pitch, wiimotes[i]->orient.yaw,
wiimotes[i]->gforce.x, wiimotes[i]->gforce.y, wiimotes[i]->gforce.z);
}
mid = (*globalEnv)->GetMethodID(globalEnv, cls, "addWiimoteEvent",
mid = (*env)->GetMethodID(env, cls, "addWiimoteEvent",
"()V");
if (mid == 0) {
return;
}
(*globalEnv)->CallVoidMethod(globalEnv, globalWim, mid);
(*env)->CallVoidMethod(env, gath, mid);
break;
case WIIUSE_STATUS:
/* a status event occured */
mid = (*globalEnv)->GetMethodID(globalEnv, cls, "addDisconnectionEvent", "(IZFSZIZFFFZZZZ)V");
if (mid == 0) {
return;
}
/* LEDS */
if (WIIUSE_IS_LED_SET(wiimotes[i], 1)) leds += 1;
if (WIIUSE_IS_LED_SET(wiimotes[i], 2)) leds += 2;
if (WIIUSE_IS_LED_SET(wiimotes[i], 3)) leds += 4;
if (WIIUSE_IS_LED_SET(wiimotes[i], 4)) leds += 8;
(*globalEnv)->CallVoidMethod(globalEnv, globalWim, mid,
wiimotes[i]->unid, WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_CONNECTED),
wiimotes[i]->battery_level, leds, WIIUSE_USING_SPEAKER(wiimotes[i]),
wiimotes[i]->exp.type,WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_RUMBLE),
wiimotes[i]->orient_threshold, wiimotes[i]->accel_threshold,
wiimotes[i]->accel_calib.st_alpha, WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_CONTINUOUS),
WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING), WIIUSE_USING_IR(wiimotes[i]),
WIIUSE_USING_ACC(wiimotes[i]));
// /* a status event occured */
// mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(IZFSZIZFFFZZZZ)V");
// if (mid == 0) {
// return;
// }
// /* LEDS */
// if (WIIUSE_IS_LED_SET(wiimotes[i], 1)) leds += 1;
// if (WIIUSE_IS_LED_SET(wiimotes[i], 2)) leds += 2;
// if (WIIUSE_IS_LED_SET(wiimotes[i], 3)) leds += 4;
// if (WIIUSE_IS_LED_SET(wiimotes[i], 4)) leds += 8;
//
// (*env)->CallVoidMethod(env, gath, mid,
// wiimotes[i]->unid, WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_CONNECTED),
// wiimotes[i]->battery_level, leds, WIIUSE_USING_SPEAKER(wiimotes[i]),
// wiimotes[i]->exp.type,WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_RUMBLE),
// wiimotes[i]->orient_threshold, wiimotes[i]->accel_threshold,
// wiimotes[i]->accel_calib.st_alpha, WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_CONTINUOUS),
// WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING), WIIUSE_USING_IR(wiimotes[i]),
// WIIUSE_USING_ACC(wiimotes[i]));
break;
case WIIUSE_DISCONNECT:
/* the wiimote disconnected */
mid = (*globalEnv)->GetMethodID(globalEnv, cls, "addDisconnectionEvent", "(I)V");
if (mid == 0) {
return;
}
(*globalEnv)->CallVoidMethod(globalEnv, globalWim, mid, wiimotes[i]->unid);
// /* the wiimote disconnected */
// mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V");
// if (mid == 0) {
// return;
// }
// (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
break;
default: