void IRThread::run() { int visiblePointCount = 0; while(!isConnected) initialize(); int poll_res = 0; while(1) { poll_res = wiiuse_poll(wiimotes, MAX_WIIMOTES); //qWarning() << "poll result" << poll_res; if (poll_res) { //qWarning() << "wii event: " << wiimotes[0]->event; if(wiimotes[0]->event == WIIUSE_EVENT) { if (WIIUSE_USING_IR(wiimotes[0])) { int i = 0; //count number of visible points visiblePointCount = 0; for(int i = 0; i < 4; i++) { if(wiimotes[0]->ir.dot[i].visible) { irpoints[i].setX(wiimotes[0]->ir.dot[i].rx); irpoints[i].setY(wiimotes[0]->ir.dot[i].ry); visiblePointCount++; } else { //qWarning() << "else"; irpoints[i].setX(-1); irpoints[i].setY(-1); } } //qWarning() << "visible points:" << visiblePointCount; // process ir dot #0 if (wiimotes[0]->ir.dot[0].visible) { if(previous[0] == false) { previous[0] = true; emit IRInputReceived(irpoints,0,MOUSE_PRESSED,visiblePointCount); copyPoints(irpoints,previousPoints); } else if(previous[0] == true) { emit IRInputReceived(irpoints,0,MOUSE_MOVE,visiblePointCount); copyPoints(irpoints,previousPoints); } } else if(previous[0] == true) { previous[0] = false; //emit IRInputReceived(wiimotes[0]->ir.dot[0].rx, wiimotes[0]->ir.dot[0].ry,0,MOUSE_RELEASED,visiblePointCount); //previousPoint = QPoint(wiimotes[0]->ir.dot[0].rx,wiimotes[0]->ir.dot[0].ry); emit IRInputReceived(previousPoints, 0, MOUSE_RELEASED, visiblePointCount); } else if(previous[0] == false) { // do nothing } } } } } exec(); }
/** * @brief Callback that handles a controller status event. * * @param wm Pointer to a wiimote_t structure. * @param attachment Is there an attachment? (1 for yes, 0 for no) * @param speaker Is the speaker enabled? (1 for yes, 0 for no) * @param ir Is the IR support enabled? (1 for yes, 0 for no) * @param led What LEDs are lit. * @param battery_level Battery level, between 0.0 (0%) and 1.0 (100%). * * This occurs when either the controller status changed * or the controller status was requested explicitly by * wiiuse_status(). * * One reason the status can change is if the nunchuk was * inserted or removed from the expansion port. */ void handle_ctrl_status(struct wiimote_t* wm) { printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", wm->unid); printf("attachment: %i\n", wm->exp.type); printf("speaker: %i\n", WIIUSE_USING_SPEAKER(wm)); printf("ir: %i\n", WIIUSE_USING_IR(wm)); printf("leds: %i %i %i %i\n", WIIUSE_IS_LED_SET(wm, 1), WIIUSE_IS_LED_SET(wm, 2), WIIUSE_IS_LED_SET(wm, 3), WIIUSE_IS_LED_SET(wm, 4)); printf("battery: %f %%\n", wm->battery_level); }
void CryVR_WiimoteManagerPlugin::Status( struct wiimote_t* wm ) { CryLogAlways( "\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", wm->unid ); CryLogAlways( "attachment: %i\n", wm->exp.type ); CryLogAlways( "speaker: %i\n", WIIUSE_USING_SPEAKER( wm ) ); CryLogAlways( "ir: %i\n", WIIUSE_USING_IR( wm ) ); CryLogAlways( "leds: %i %i %i %i\n", WIIUSE_IS_LED_SET( wm, 1 ), WIIUSE_IS_LED_SET( wm, 2 ), WIIUSE_IS_LED_SET( wm, 3 ), WIIUSE_IS_LED_SET( wm, 4 ) ); CryLogAlways( "battery: %f %%\n", wm->battery_level ); }
bool CryVR_WiimoteManagerPlugin::GetIr( int id ) { if ( init && id < found && id >= 0 ) { return WIIUSE_USING_IR( wiimotes[id] ); } return false; }
/** * @brief Callback that handles an event. * * @param wm Pointer to a wiimote_t structure. * * This function is called automatically by the wiiuse library when an * event occurs on the specified wiimote. */ static void handle_event(struct wiimote_t* wm) { /* Variables Declarations */ jclass cls = (*globalEnv)->GetObjectClass(globalEnv, globalWim); jmethodID mid; /* fill java class */ copy_common_status(wm); /* Set all buttons */ mid = (*globalEnv)->GetMethodID(globalEnv, cls, "setAllButtons", "(SSS)V"); if (mid == 0) { return; } (*globalEnv)->CallVoidMethod(globalEnv, globalWim, mid, wm->btns, wm->btns_released, wm->btns_held); /* * If IR tracking is enabled then print the coordinates * on the virtual screen that the wiimote is pointing to. * * Also make sure that we see at least 1 dot. */ if (WIIUSE_USING_IR(wm)) { int i = 0; /* go through each of the 4 possible IR sources */ for (; i < 4; ++i) { /* check if the source is visible */ if (wm->ir.dot[i].visible) { cls = (*globalEnv)->GetObjectClass(globalEnv, globalWim); mid = (*globalEnv)->GetMethodID(globalEnv, cls, "addIRpoint", "(II)V"); if (mid == 0) { return; } (*globalEnv)->CallVoidMethod(globalEnv, globalWim, mid, wm->ir.dot[i].x, wm->ir.dot[i].y); } } //printf("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y); //printf("IR z distance: %f\n", wm->ir.z); } /* Motion Sensing */ if (WIIUSE_USING_ACC(wm)) { /* set orientation and gravity force */ cls = (*globalEnv)->GetObjectClass(globalEnv, globalWim); mid = (*globalEnv)->GetMethodID(globalEnv, cls, "setOrientationAndGforce", "(FFFFFF)V"); if (mid == 0) { return; } (*globalEnv)->CallVoidMethod(globalEnv, globalWim, mid, wm->orient.roll, wm->orient.pitch, wm->orient.yaw, wm->gforce.x, wm->gforce.y, wm->gforce.z); } }
void FWiimoteInputDevice::handle_ctrl_status(struct wiimote_t* wm, int id) { UE_LOG(LogWiimote, Log, TEXT("\n\n--- CONTROLLER STATUS [wiimote id %i] ---"), wm->unid); UE_LOG(LogWiimote, Log, TEXT("attachment: %i"), wm->exp.type); UE_LOG(LogWiimote, Log, TEXT("speaker: %i"), WIIUSE_USING_SPEAKER(wm)); UE_LOG(LogWiimote, Log, TEXT("ir: %i"), WIIUSE_USING_IR(wm)); UE_LOG(LogWiimote, Log, TEXT("leds: %i %i %i %i"), WIIUSE_IS_LED_SET(wm, 1), WIIUSE_IS_LED_SET(wm, 2), WIIUSE_IS_LED_SET(wm, 3), WIIUSE_IS_LED_SET(wm, 4)); UE_LOG(LogWiimote, Log, TEXT("battery: %f %%"), wm->battery_level); }
/** * Fills status variables. This method fills some status variables always filled in a WiiMoteEvent object. * This function is called in every callback function. */ static void copy_common_status(struct wiimote_t* wm) { /* Variables Declarations */ jmethodID mid; jclass cls = (*globalEnv)->GetObjectClass(globalEnv, globalWim); /* set statuses */ mid = (*globalEnv)->GetMethodID(globalEnv, cls, "setPermanentStatus", "(IZZZZFZZ)V"); if (mid == 0) { return; } (*globalEnv)->CallVoidMethod(globalEnv, globalWim, mid, wm->unid, WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED), WIIUSE_USING_IR(wm), WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE), WIIUSE_USING_ACC(wm), wm->orient_threshold, WIIMOTE_IS_FLAG_SET(wm,WIIUSE_CONTINUOUS), WIIMOTE_IS_FLAG_SET(wm,WIIUSE_SMOOTHING)); }
/** * @brief Callback that handles an event. * * @param wm Pointer to a wiimote_t structure. * * This function is called automatically by the wiiuse library when an * event occurs on the specified wiimote. */ void handle_event(struct wiimote_t* wm) { printf("\n\n--- EVENT [id %i] ---\n", wm->unid); /* if a button is pressed, report it */ if (IS_PRESSED(wm, WIIMOTE_BUTTON_A)) printf("A pressed\n"); if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) printf("B pressed\n"); if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP)) printf("UP pressed\n"); if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) printf("DOWN pressed\n"); if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) printf("LEFT pressed\n"); if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) printf("RIGHT pressed\n"); if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) printf("MINUS pressed\n"); if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) printf("PLUS pressed\n"); if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) printf("ONE pressed\n"); if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) printf("TWO pressed\n"); if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) printf("HOME pressed\n"); /* * Pressing minus will tell the wiimote we are no longer interested in movement. * This is useful because it saves battery power. */ if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) wiiuse_motion_sensing(wm, 0); /* * Pressing plus will tell the wiimote we are interested in movement. */ if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) wiiuse_motion_sensing(wm, 1); /* * Pressing B will toggle the rumble * * if B is pressed but is not held, toggle the rumble */ if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B)) wiiuse_toggle_rumble(wm); if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP)) wiiuse_set_ir(wm, 1); if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) wiiuse_set_ir(wm, 0); /* if the accelerometer is turned on then print angles */ if (WIIUSE_USING_ACC(wm)) { printf("wiimote roll = %f [%f]\n", wm->orient.roll, wm->orient.a_roll); printf("wiimote pitch = %f [%f]\n", wm->orient.pitch, wm->orient.a_pitch); printf("wiimote yaw = %f\n", wm->orient.yaw); } /* * If IR tracking is enabled then print the coordinates * on the virtual screen that the wiimote is pointing to. * * Also make sure that we see at least 1 dot. */ if (WIIUSE_USING_IR(wm)) { int i = 0; /* go through each of the 4 possible IR sources */ for (; i < 4; ++i) { /* check if the source is visible */ if (wm->ir.dot[i].visible) printf("IR source %i: (%u, %u)\n", i, wm->ir.dot[i].x, wm->ir.dot[i].y); } printf("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y); printf("IR z distance: %f\n", wm->ir.z); } /* show events specific to supported expansions */ if (wm->exp.type == EXP_NUNCHUK) { /* nunchuk */ struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk; if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) printf("Nunchuk: C pressed\n"); if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) printf("Nunchuk: Z pressed\n"); printf("nunchuk roll = %f\n", nc->orient.roll); printf("nunchuk pitch = %f\n", nc->orient.pitch); printf("nunchuk yaw = %f\n", nc->orient.yaw); printf("nunchuk joystick angle: %f\n", nc->js.ang); printf("nunchuk joystick magnitude: %f\n", nc->js.mag); } else if (wm->exp.type == EXP_CLASSIC) { /* classic controller */ struct classic_ctrl_t* cc = (classic_ctrl_t*)&wm->exp.classic; if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZL)) printf("Classic: ZL pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_B)) printf("Classic: B pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_Y)) printf("Classic: Y pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_A)) printf("Classic: A pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_X)) printf("Classic: X pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZR)) printf("Classic: ZR pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_LEFT)) printf("Classic: LEFT pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_UP)) printf("Classic: UP pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_RIGHT)) printf("Classic: RIGHT pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_DOWN)) printf("Classic: DOWN pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_L)) printf("Classic: FULL L pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_MINUS)) printf("Classic: MINUS pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_HOME)) printf("Classic: HOME pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_PLUS)) printf("Classic: PLUS pressed\n"); if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_R)) printf("Classic: FULL R pressed\n"); printf("classic L button pressed: %f\n", cc->l_shoulder); printf("classic R button pressed: %f\n", cc->r_shoulder); printf("classic left joystick angle: %f\n", cc->ljs.ang); printf("classic left joystick magnitude: %f\n", cc->ljs.mag); printf("classic right joystick angle: %f\n", cc->rjs.ang); printf("classic right joystick magnitude: %f\n", cc->rjs.mag); } else if (wm->exp.type == EXP_GUITAR_HERO_3) { /* guitar hero 3 guitar */ struct guitar_hero_3_t* gh3 = (guitar_hero_3_t*)&wm->exp.gh3; if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP)) printf("Guitar: Strum Up pressed\n"); if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN)) printf("Guitar: Strum Down pressed\n"); if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_YELLOW)) printf("Guitar: Yellow pressed\n"); if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_GREEN)) printf("Guitar: Green pressed\n"); if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_BLUE)) printf("Guitar: Blue pressed\n"); if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_RED)) printf("Guitar: Red pressed\n"); if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE)) printf("Guitar: Orange pressed\n"); if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_PLUS)) printf("Guitar: Plus pressed\n"); if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_MINUS)) printf("Guitar: Minus pressed\n"); printf("Guitar whammy bar: %f\n", gh3->whammy_bar); printf("Guitar joystick angle: %f\n", gh3->js.ang); printf("Guitar joystick magnitude: %f\n", gh3->js.mag); } }
/** * Get status and values from the wiimotes and send it through callbacks. * @param wim the wiimote object to fill with the datas. */ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll (JNIEnv *env, jobject obj, jobject gath) { /* Variables Declarations */ int i; short leds = 0; jclass cls = (*env)->GetObjectClass(env, gath); jmethodID mid; if (wiiuse_poll(wiimotes, nbMaxWiimotes)) { /* * This happens if something happened on any wiimote. * So go through each one and check if anything happened. */ for (i=0; i < nbMaxWiimotes; ++i) { switch (wiimotes[i]->event) { case WIIUSE_EVENT: /* a generic event occured */ mid = (*env)->GetMethodID(env, cls, "prepareWiiMoteEvent", "(ISSS)V"); if (mid == 0) { return; } (*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 * on the virtual screen that the wiimote is pointing to. * * Also make sure that we see at least 1 dot. */ if (WIIUSE_USING_IR(wiimotes[i])) { int a; WIIUSE_GET_IR_SENSITIVITY_CORRECTED(wiimotes[i], &a); mid = (*env)->GetMethodID(env, cls, "prepareIRevent", "(IIFIIIIIISSSF)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->ir.x, wiimotes[i]->ir.y, wiimotes[i]->ir.z, wiimotes[i]->ir.ax, wiimotes[i]->ir.ay, wiimotes[i]->ir.vres[0], wiimotes[i]->ir.vres[1], wiimotes[i]->ir.offset[0], wiimotes[i]->ir.offset[1], wiimotes[i]->ir.pos, wiimotes[i]->ir.aspect, a , wiimotes[i]->ir.distance); mid = (*env)->GetMethodID(env, cls, "addIRPointToPreparedWiiMoteEvent", "(IISSS)V"); if (mid == 0) { return; } /* go through each of the 4 possible IR sources */ for (a=0; a < 4; a++) { /* check if the source is visible */ if (wiimotes[i]->ir.dot[a].visible) { (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->ir.dot[a].x, wiimotes[i]->ir.dot[a].y, wiimotes[i]->ir.dot[a].rx, wiimotes[i]->ir.dot[a].ry, wiimotes[i]->ir.dot[a].size); } } } /* Motion Sensing */ if (WIIUSE_USING_ACC(wiimotes[i])) { /* set orientation and gravity force */ mid = (*env)->GetMethodID(env, cls, "addMotionSensingValues", "(FIZFFFFFFFFFSSS)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, 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); } /* Expansions support support*/ if (WIIUSE_USING_EXP(wiimotes[i])) { /* Nunchuk support */ if (wiimotes[i]->exp.type == EXP_NUNCHUK) { /* put nunchuk values in wiimote generic event */ mid = (*env)->GetMethodID(env, cls, "addNunchunkEventToPreparedWiimoteEvent", "(SSSFIZFFFFFFFFFSSSFFSSSSSS)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); } else if (wiimotes[i]->exp.type == EXP_GUITAR_HERO_3) { /* put guitar hero values in wiimote generic event */ mid = (*env)->GetMethodID(env, cls, "addGuitarHeroEventToPreparedWiimoteEvent", "(SSSFFFSSSSSS)V"); if (mid == 0) { return; } struct guitar_hero_3_t* gh = (guitar_hero_3_t*)&wiimotes[i]->exp.gh3; (*env)->CallVoidMethod(env, gath, mid, /* buttons */ gh->btns,gh->btns_released,gh->btns_held, /* whammy bar */ gh->whammy_bar, /* joystick */ gh->js.ang,gh->js.mag, gh->js.max.x,gh->js.max.y, gh->js.min.x,gh->js.min.y, gh->js.center.x,gh->js.center.y); }if (wiimotes[i]->exp.type == EXP_CLASSIC) { /* put classic controller values in wiimote generic event */ mid = (*env)->GetMethodID(env, cls, "addClassicControllerEventToPreparedWiimoteEvent", "(SSSFFFFSSSSSSFFSSSSSS)V"); if (mid == 0) { return; } struct classic_ctrl_t* cl = (classic_ctrl_t*)&wiimotes[i]->exp.classic; (*env)->CallVoidMethod(env, gath, mid, /* buttons */ cl->btns,cl->btns_released,cl->btns_held, /* shoulder buttons */ cl->r_shoulder,cl->l_shoulder, /* joystick left*/ cl->ljs.ang,cl->ljs.mag, cl->ljs.max.x,cl->ljs.max.y, cl->ljs.min.x,cl->ljs.min.y, cl->ljs.center.x,cl->ljs.center.y, /* joystick right */ cl->rjs.ang,cl->rjs.mag, cl->rjs.max.x,cl->rjs.max.y, cl->rjs.min.x,cl->rjs.min.y, cl->rjs.center.x,cl->rjs.center.y); } } /* add generic event to java object used to gather events in c environment */ mid = (*env)->GetMethodID(env, cls, "addWiimoteEvent", "()V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid); break; case WIIUSE_DISCONNECT: /* the wiimote disconnected */ mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); break; case WIIUSE_UNEXPECTED_DISCONNECT: /* the wimote disconnected */ mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); break; case WIIUSE_NUNCHUK_INSERTED: /* the nunchuk was just connected */ mid = (*env)->GetMethodID(env, cls, "addNunchukInsertedEvent", "(I)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); break; case WIIUSE_NUNCHUK_REMOVED: /* the nunchuk disconnected */ mid = (*env)->GetMethodID(env, cls, "addNunchukRemovedEvent", "(I)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); break; case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED: /* the guitar hero was just connected */ mid = (*env)->GetMethodID(env, cls, "addGuitarHeroInsertedEvent", "(I)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); break; case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED: /* the guitar hero disconnected */ mid = (*env)->GetMethodID(env, cls, "addGuitarHeroRemovedEvent", "(I)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); break; case WIIUSE_CLASSIC_CTRL_INSERTED: /* the classic controller was just connected */ mid = (*env)->GetMethodID(env, cls, "addClassicControllerInsertedEvent", "(I)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); break; case WIIUSE_CLASSIC_CTRL_REMOVED: /* the classic controller disconnected */ mid = (*env)->GetMethodID(env, cls, "addClassicControllerRemovedEvent", "(I)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid); break; case WIIUSE_STATUS: /* a status event occured */ mid = (*env)->GetMethodID(env, cls, "addStatusEvent", "(IZFSZIZZZZ)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), WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_CONTINUOUS), WIIUSE_USING_IR(wiimotes[i]),WIIUSE_USING_ACC(wiimotes[i])); break; default: break; } } } }
void vrpn_WiiMote::handle_event() { //------------------------------------------------------------------------- // Set the status of the buttons. The first 16 buttons come from // the main contoller. If there is an expansion controller plugged in, // then there is a second set of up to 16 buttons that can be read from it. unsigned i; for (i = 0; i < 16; i++) { buttons[i] = ( wiimote->device->btns & (1 << i) ) != 0; } if (wiimote->device->exp.type == EXP_NUNCHUK) { for (i = 0; i < 16; i++) { buttons[16+i] = ( wiimote->device->exp.nunchuk.btns & (1 << i) ) != 0; } } if (wiimote->device->exp.type == EXP_CLASSIC) { for (i = 0; i < 16; i++) { buttons[32+i] = ( wiimote->device->exp.classic.btns & (1 << i) ) != 0; } } if (wiimote->device->exp.type == EXP_GUITAR_HERO_3) { for (i = 0; i < 16; i++) { buttons[48+i] = ( wiimote->device->exp.gh3.btns & (1 << i) ) != 0; } } //------------------------------------------------------------------------- // Read the status of the analog values. There are six of them for the // base unit and extras for expansion units. channel[0] = wiimote->device->battery_level; if (WIIUSE_USING_ACC(wiimote->device)) { channel[1] = wiimote->device->gforce.x; channel[2] = wiimote->device->gforce.y; channel[3] = wiimote->device->gforce.z; } if (WIIUSE_USING_IR(wiimote->device)) { unsigned dot; for (dot = 0; dot < 3; dot++) { if (wiimote->device->ir.dot[dot].visible) { channel[4 + 3*dot + 0] = wiimote->device->ir.dot[dot].rx; channel[4 + 3*dot + 1] = wiimote->device->ir.dot[dot].ry; channel[4 + 3*dot + 2] = wiimote->device->ir.dot[dot].size; } else { channel[4 + 3*dot + 0] = -1; channel[4 + 3*dot + 1] = -1; channel[4 + 3*dot + 2] = -1; } } } // See which secondary controller is installed and report if (wiimote->device->exp.type == EXP_NUNCHUK) { channel[16 + 0] = wiimote->device->exp.nunchuk.gforce.x; channel[16 + 1] = wiimote->device->exp.nunchuk.gforce.y; channel[16 + 2] = wiimote->device->exp.nunchuk.gforce.z; channel[16 + 3] = wiimote->device->exp.nunchuk.js.ang; channel[16 + 4] = wiimote->device->exp.nunchuk.js.mag; } if (wiimote->device->exp.type == EXP_CLASSIC) { channel[32 + 0] = wiimote->device->exp.classic.l_shoulder; channel[32 + 1] = wiimote->device->exp.classic.r_shoulder; channel[32 + 2] = wiimote->device->exp.classic.ljs.ang; channel[32 + 3] = wiimote->device->exp.classic.ljs.mag; channel[32 + 4] = wiimote->device->exp.classic.rjs.ang; channel[32 + 5] = wiimote->device->exp.classic.rjs.mag; } if (wiimote->device->exp.type == EXP_GUITAR_HERO_3) { channel[48 + 0] = wiimote->device->exp.gh3.whammy_bar; channel[48 + 1] = wiimote->device->exp.gh3.js.ang; channel[48 + 2] = wiimote->device->exp.gh3.js.mag; } //------------------------------------------------------------------------- // Read the state of the Infrared sensors. }
/** * Get status and values from the wiimotes and send it through callbacks. * @param wim the wiimote object to fill with the datas. */ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll (JNIEnv *env, jobject obj, jobject gath) { /* Variables Declarations */ int i; short leds = 0; jclass cls = (*env)->GetObjectClass(env, gath); jmethodID mid; if (wiiuse_poll(wiimotes, nbMaxWiiMotes)) { /* * This happens if something happened on any wiimote. * So go through each one and check if anything happened. */ for (i=0; i < nbMaxWiiMotes; ++i) { switch (wiimotes[i]->event) { case WIIUSE_EVENT: /* a generic event occured */ mid = (*env)->GetMethodID(env, cls, "prepareWiiMoteEvent", "(ISSS)V"); if (mid == 0) { return; } (*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 * on the virtual screen that the wiimote is pointing to. * * Also make sure that we see at least 1 dot. */ if (WIIUSE_USING_IR(wiimotes[i])) { int a = 0; mid = (*env)->GetMethodID(env, cls, "prepareIRevent", "(IIIIIIIIISS)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->ir.x, wiimotes[i]->ir.y, wiimotes[i]->ir.z, wiimotes[i]->ir.ax, wiimotes[i]->ir.ay, wiimotes[i]->ir.vres[0], wiimotes[i]->ir.vres[1], wiimotes[i]->ir.offset[0], wiimotes[i]->ir.offset[1], wiimotes[i]->ir.pos, wiimotes[i]->ir.aspect); mid = (*env)->GetMethodID(env, cls, "addIRPointToPreparedWiiMoteEvent", "(IISSS)V"); if (mid == 0) { return; } /* go through each of the 4 possible IR sources */ for (; a < 4; a++) { /* check if the source is visible */ if (wiimotes[i]->ir.dot[a].visible) { (*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->ir.dot[a].x, wiimotes[i]->ir.dot[a].y, wiimotes[i]->ir.dot[a].rx, wiimotes[i]->ir.dot[a].ry, wiimotes[i]->ir.dot[a].size); } } } /* Motion Sensing */ if (WIIUSE_USING_ACC(wiimotes[i])) { /* set orientation and gravity force */ mid = (*env)->GetMethodID(env, cls, "addMotionSensingValues", "(FIZFFFFFFFSSS)V"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid, 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]->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"); if (mid == 0) { return; } (*env)->CallVoidMethod(env, gath, mid); break; case WIIUSE_STATUS: /* a status event occured */ mid = (*env)->GetMethodID(env, cls, "addStatusEvent", "(IZFSZIZZZZ)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), WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_CONTINUOUS), WIIUSE_USING_IR(wiimotes[i]),WIIUSE_USING_ACC(wiimotes[i])); break; case WIIUSE_DISCONNECT: /* 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: break; } } } }
/** * @brief Callback that handles an event. * * @param wm Pointer to a wiimote_t structure. * * This function is called automatically by the wiiuse library when an * event occurs on the specified wiimote. */ void handle_event(struct wiimote_t* wm) { CryLogAlways("\n\n--- EVENT [id %i] ---\n", wm->unid); /* if a button is pressed, report it */ if (IS_PRESSED(wm, WIIMOTE_BUTTON_A)) {CryLogAlways("A pressed\n");} if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) {CryLogAlways("B pressed\n");} if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP)) {CryLogAlways("UP pressed\n");} if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) {CryLogAlways("DOWN pressed\n");} if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) {CryLogAlways("LEFT pressed\n");} if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) {CryLogAlways("RIGHT pressed\n");} if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) {CryLogAlways("MINUS pressed\n");} if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) {CryLogAlways("PLUS pressed\n");} if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {CryLogAlways("ONE pressed\n");} if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) {CryLogAlways("TWO pressed\n");} if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) {CryLogAlways("HOME pressed\n");} /* * Pressing minus will tell the wiimote we are no longer interested in movement. * This is useful because it saves battery power. */ if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) {wiiuse_motion_sensing(wm, 0);} /* * Pressing plus will tell the wiimote we are interested in movement. */ if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) {wiiuse_motion_sensing(wm, 1);} /* * Pressing B will toggle the rumble * * if B is pressed but is not held, toggle the rumble */ if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B)) {wiiuse_toggle_rumble(wm);} if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP)) {wiiuse_set_ir(wm, 1);} if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) {wiiuse_set_ir(wm, 0);} /* * Motion+ support */ /* if the accelerometer is turned on then print angles */ if (WIIUSE_USING_ACC(wm)) { CryLogAlways("wiimote roll = %f [%f]\n", wm->orient.roll, wm->orient.a_roll); CryLogAlways("wiimote pitch = %f [%f]\n", wm->orient.pitch, wm->orient.a_pitch); CryLogAlways("wiimote yaw = %f\n", wm->orient.yaw); } /* * If IR tracking is enabled then print the coordinates * on the virtual screen that the wiimote is pointing to. * * Also make sure that we see at least 1 dot. */ if (WIIUSE_USING_IR(wm)) { int i = 0; /* go through each of the 4 possible IR sources */ for (; i < 4; ++i) { /* check if the source is visible */ if (wm->ir.dot[i].visible) { CryLogAlways("IR source %i: (%u, %u)\n", i, wm->ir.dot[i].x, wm->ir.dot[i].y); } } CryLogAlways("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y); CryLogAlways("IR z distance: %f\n", wm->ir.z); } /* show events specific to supported expansions */ if (wm->exp.type == EXP_NUNCHUK) { struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk; if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) { CryLogAlways("Nunchuk: C pressed\n"); } if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) { CryLogAlways("Nunchuk: Z pressed\n"); } CryLogAlways("nunchuk roll = %f\n", nc->orient.roll); CryLogAlways("nunchuk pitch = %f\n", nc->orient.pitch); CryLogAlways("nunchuk yaw = %f\n", nc->orient.yaw); CryLogAlways("nunchuk joystick angle: %f\n", nc->js.ang); CryLogAlways("nunchuk joystick magnitude: %f\n", nc->js.mag); } else if (wm->exp.type == EXP_CLASSIC) { struct classic_ctrl_t* cc = (classic_ctrl_t*)&wm->exp.classic; if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZL)) {CryLogAlways("Classic: ZL pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_B)) {CryLogAlways("Classic: B pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_Y)) {CryLogAlways("Classic: Y pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_A)) {CryLogAlways("Classic: A pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_X)) {CryLogAlways("Classic: X pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZR)) {CryLogAlways("Classic: ZR pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_LEFT)) {CryLogAlways("Classic: LEFT pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_UP)) {CryLogAlways("Classic: UP pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_RIGHT)) {CryLogAlways("Classic: RIGHT pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_DOWN)) {CryLogAlways("Classic: DOWN pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_L)) {CryLogAlways("Classic: FULL L pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_MINUS)) {CryLogAlways("Classic: MINUS pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_HOME)) {CryLogAlways("Classic: HOME pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_PLUS)) {CryLogAlways("Classic: PLUS pressed\n");} if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_R)) {CryLogAlways("Classic: FULL R pressed\n");} CryLogAlways("classic L button pressed: %f\n", cc->l_shoulder); CryLogAlways("classic R button pressed: %f\n", cc->r_shoulder); CryLogAlways("classic left joystick angle: %f\n", cc->ljs.ang); CryLogAlways("classic left joystick magnitude: %f\n", cc->ljs.mag); CryLogAlways("classic right joystick angle: %f\n", cc->rjs.ang); CryLogAlways("classic right joystick magnitude: %f\n", cc->rjs.mag); } else if (wm->exp.type == EXP_WII_BOARD){ struct wii_board_t* wb = (wii_board_t*)&wm->exp.wb; CryLogAlways("WiiBoard roll = [%f]\n", wb->update_calib); CryLogAlways("WiiBoard roll = %f [%f]\n", wb->bl, wb->br); CryLogAlways("WiiBoard pitch = %f [%f]\n", wb->tl,wb->tr); } }
virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo) { int found =-1; int connected; switch (event) { case eFE_Initialize:{ //Sleep(3000); wiimotes = wiiuse_init(1); found = wiiuse_find(wiimotes, 1, 5); if (found!=0) handle_ctrl_status(wiimotes[0]); connected = wiiuse_connect(wiimotes, 1); if (connected) CryLogAlways("Connected to %i wiimotes (of %i found).\n", connected, found); else CryLogAlways("Failed to connect to any wiimote.\n"); wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1); wiiuse_motion_sensing(wiimotes[0], 1); wiiuse_set_ir(wiimotes[0], 1); //trop rapide ! } case eFE_Activate: { //Sleep(3000); //wiimotes = wiiuse_init(1); //found = wiiuse_find(wiimotes, 1, 5); //if (found==0) CryLogAlways("No wiimotes found.\n"); /* connected = wiiuse_connect(wiimotes, 1); if (connected) CryLogAlways("Connected to %i wiimotes (of %i found).\n", connected, found); else CryLogAlways("Failed to connect to any wiimote.\n"); wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1); wiiuse_motion_sensing(wiimotes[0], 1); wiiuse_set_ir(wiimotes[0], 1); //WIIUSE_USING_EXP(wiimotes[0]); //WIIUSE_U //wiimotes[0]->exp.type = EXP_NUNCHUK; */ pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID,true); } break; case eFE_Update: { //int connected = wiiuse_connect(wiimotes, 1); wiiuse_poll(wiimotes, 1); wiimote* wm = wiimotes[0]; //Ne change rien ! juste qu'on a un retour d'IR //handle_ctrl_status(wiimotes[0]); CryLogAlways("attachment: %i",wm->exp.type); /* Gestion des evts */ // A commenter switch (wiimotes[0]->event) { case WIIUSE_EVENT: /* a generic event occured */ handle_event(wiimotes[0]); break; case WIIUSE_STATUS: /* a status event occured */ handle_ctrl_status(wiimotes[0]); break; case WIIUSE_DISCONNECT: case WIIUSE_UNEXPECTED_DISCONNECT: /* the wiimote disconnected */ handle_disconnect(wiimotes[0]); break; case WIIUSE_READ_DATA: /* * Data we requested to read was returned. * Take a look at wiimotes[i]->read_req * for the data. */ break; case WIIUSE_NUNCHUK_INSERTED: /* * a nunchuk was inserted * This is a good place to set any nunchuk specific * threshold values. By default they are the same * as the wiimote. */ //struct nunchuk_t* nc = (nunchuk_t*)&wiimotes[0]->exp.nunchuk; wiiuse_set_nunchuk_orient_threshold(wiimotes[0], 90.0f); wiiuse_set_nunchuk_accel_threshold(wiimotes[0], 100); CryLogAlways("Nunchuk inserted.\n"); break; case WIIUSE_CLASSIC_CTRL_INSERTED: CryLogAlways("Classic controller inserted.\n"); break; case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED: /* some expansion was inserted */ handle_ctrl_status(wiimotes[0]); //printf("Guitar Hero 3 controller inserted.\n"); break; case WIIUSE_NUNCHUK_REMOVED: case WIIUSE_CLASSIC_CTRL_REMOVED: case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED: /* some expansion was removed */ handle_ctrl_status(wiimotes[0]); //printf("An expansion was removed.\n"); break; default: break; } //if (wiiuse_poll(wiimotes, 1)) { //int i = 0; if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_A)) ActivateOutput(pActInfo, WIIMOTE_A,true); else ActivateOutput(pActInfo, WIIMOTE_A,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_B)) ActivateOutput(pActInfo, WIIMOTE_B,true); else ActivateOutput(pActInfo, WIIMOTE_B,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_UP)) ActivateOutput(pActInfo, WIIMOTE_UP,true); else ActivateOutput(pActInfo, WIIMOTE_UP,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_DOWN)) ActivateOutput(pActInfo, WIIMOTE_DOWN,true); else ActivateOutput(pActInfo, WIIMOTE_DOWN,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_LEFT)) ActivateOutput(pActInfo, WIIMOTE_LEFT,true); else ActivateOutput(pActInfo, WIIMOTE_LEFT,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_RIGHT)) ActivateOutput(pActInfo, WIIMOTE_RIGHT,true); else ActivateOutput(pActInfo, WIIMOTE_RIGHT,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_MINUS)) ActivateOutput(pActInfo, WIIMOTE_MINUS,true); else ActivateOutput(pActInfo, WIIMOTE_MINUS,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_PLUS)) ActivateOutput(pActInfo, WIIMOTE_PLUS,true); else ActivateOutput(pActInfo, WIIMOTE_PLUS,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_ONE)) ActivateOutput(pActInfo, WIIMOTE_ONE,true); else ActivateOutput(pActInfo, WIIMOTE_ONE,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_TWO)) ActivateOutput(pActInfo, WIIMOTE_TWO,true); else ActivateOutput(pActInfo, WIIMOTE_TWO,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_HOME)) ActivateOutput(pActInfo, WIIMOTE_HOME,true); else ActivateOutput(pActInfo, WIIMOTE_HOME,false); if (WIIUSE_USING_ACC(wiimotes[0])) { Vec3 output = Vec3(wiimotes[0]->orient.roll,wiimotes[0]->orient.pitch,wiimotes[0]->orient.yaw); ActivateOutput(pActInfo, WIIMOTE_RPY,output); } if (WIIUSE_USING_IR(wiimotes[0])) { Vec3 output = Vec3((float)wiimotes[0]->ir.x,(float)wiimotes[0]->ir.y,(float)wiimotes[0]->ir.z); ActivateOutput(pActInfo, WIIMOTE_IR,output); } /* nunchuk */ //Toujours faux ! if (wm->exp.type == EXP_NUNCHUK) { //nunchuk_t* pt = wm->exp.nunchuk; //REssort 0 a chaque fois !!!! struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk; CryLogAlways("nun gravity x EXPANSION : %f",nc->gforce.x); if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) ActivateOutput(pActInfo, NUNCHUK_C,true); else ActivateOutput(pActInfo, NUNCHUK_C,false); if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) ActivateOutput(pActInfo, NUNCHUK_Z,true); else ActivateOutput(pActInfo, NUNCHUK_Z,false); Vec3 output = Vec3(nc->orient.a_roll,nc->orient.a_pitch,nc->orient.yaw); ActivateOutput(pActInfo, NUNCHUK_RPY,output); Vec3 output2 = Vec3(nc->js.ang,nc->js.mag,0); ActivateOutput(pActInfo, NUNCHUK_JOYSTICK,output2); } /* switch (wiimotes[0]->event) { //case WIIUSE_EVENT: //{ //} //break; case WIIUSE_STATUS: handle_ctrl_status(wiimotes[0]); break; case WIIUSE_DISCONNECT: case WIIUSE_UNEXPECTED_DISCONNECT: handle_disconnect(wiimotes[0]); break; default: break; } */ //} //} } } }
/** * @brief Callback that handles an event. * * @param wm Pointer to a wiimote_t structure. * * This function is called automatically by the wiiuse library when an * event occurs on the specified wiimote. */ void handle_event(struct wiimote_t* wm) { printf("\n\n--- EVENT [id %i] ---\n", wm->unid); /* if a button is pressed, report it */ if (IS_PRESSED(wm, WIIMOTE_BUTTON_A)) { printf("A pressed\n"); } if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) { printf("B pressed\n"); } if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP)) { printf("UP pressed\n"); } if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) { printf("DOWN pressed\n"); } if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) { printf("LEFT pressed\n"); } if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) { printf("RIGHT pressed\n"); } if (IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) { printf("MINUS pressed\n"); } if (IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) { printf("PLUS pressed\n"); } if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) { printf("ONE pressed\n"); } if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) { printf("TWO pressed\n"); } if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) { printf("HOME pressed\n"); } /* * Pressing minus will tell the wiimote we are no longer interested in movement. * This is useful because it saves battery power. */ if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)) { wiiuse_motion_sensing(wm, 0); } /* * Pressing plus will tell the wiimote we are interested in movement. */ if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)) { wiiuse_motion_sensing(wm, 1); } /* * Pressing B will toggle the rumble * * if B is pressed but is not held, toggle the rumble */ if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B)) { wiiuse_toggle_rumble(wm); } if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP)) { wiiuse_set_ir(wm, 1); } if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) { wiiuse_set_ir(wm, 0); } /* * Motion+ support */ if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) { if (WIIUSE_USING_EXP(wm)) { wiiuse_set_motion_plus(wm, 2); // nunchuck pass-through } else { wiiuse_set_motion_plus(wm, 1); // standalone } } if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_TWO)) { wiiuse_set_motion_plus(wm, 0); // off } /* if the accelerometer is turned on then print angles */ if (WIIUSE_USING_ACC(wm)) { printf("wiimote roll = %f [%f]\n", wm->orient.roll, wm->orient.a_roll); printf("wiimote pitch = %f [%f]\n", wm->orient.pitch, wm->orient.a_pitch); printf("wiimote yaw = %f\n", wm->orient.yaw); } /* * If IR tracking is enabled then print the coordinates * on the virtual screen that the wiimote is pointing to. * * Also make sure that we see at least 1 dot. */ if (WIIUSE_USING_IR(wm)) { int i = 0; /* go through each of the 4 possible IR sources */ for (; i < 4; ++i) { /* check if the source is visible */ if (wm->ir.dot[i].visible) { printf("IR source %i: (%u, %u)\n", i, wm->ir.dot[i].x, wm->ir.dot[i].y); } } printf("IR cursor: (%u, %u)\n", wm->ir.x, wm->ir.y); printf("IR z distance: %f\n", wm->ir.z); } /* show events specific to supported expansions */ if (wm->exp.type == EXP_NUNCHUK || wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) { /* nunchuk */ struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk; if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) { printf("Nunchuk: C pressed\n"); } if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) { printf("Nunchuk: Z pressed\n"); } printf("nunchuk roll = %f\n", nc->orient.roll); printf("nunchuk pitch = %f\n", nc->orient.pitch); printf("nunchuk yaw = %f\n", nc->orient.yaw); printf("nunchuk joystick angle: %f\n", nc->js.ang); printf("nunchuk joystick magnitude: %f\n", nc->js.mag); printf("nunchuk joystick vals: %f, %f\n", nc->js.x, nc->js.y); printf("nunchuk joystick calibration (min, center, max): x: %i, %i, %i y: %i, %i, %i\n", nc->js.min.x, nc->js.center.x, nc->js.max.x, nc->js.min.y, nc->js.center.y, nc->js.max.y); } else if (wm->exp.type == EXP_CLASSIC) { /* classic controller */ struct classic_ctrl_t* cc = (classic_ctrl_t*)&wm->exp.classic; if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZL)) { printf("Classic: ZL pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_B)) { printf("Classic: B pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_Y)) { printf("Classic: Y pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_A)) { printf("Classic: A pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_X)) { printf("Classic: X pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_ZR)) { printf("Classic: ZR pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_LEFT)) { printf("Classic: LEFT pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_UP)) { printf("Classic: UP pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_RIGHT)) { printf("Classic: RIGHT pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_DOWN)) { printf("Classic: DOWN pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_L)) { printf("Classic: FULL L pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_MINUS)) { printf("Classic: MINUS pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_HOME)) { printf("Classic: HOME pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_PLUS)) { printf("Classic: PLUS pressed\n"); } if (IS_PRESSED(cc, CLASSIC_CTRL_BUTTON_FULL_R)) { printf("Classic: FULL R pressed\n"); } printf("classic L button pressed: %f\n", cc->l_shoulder); printf("classic R button pressed: %f\n", cc->r_shoulder); printf("classic left joystick angle: %f\n", cc->ljs.ang); printf("classic left joystick magnitude: %f\n", cc->ljs.mag); printf("classic right joystick angle: %f\n", cc->rjs.ang); printf("classic right joystick magnitude: %f\n", cc->rjs.mag); } else if (wm->exp.type == EXP_GUITAR_HERO_3) { /* guitar hero 3 guitar */ struct guitar_hero_3_t* gh3 = (guitar_hero_3_t*)&wm->exp.gh3; if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP)) { printf("Guitar: Strum Up pressed\n"); } if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN)) { printf("Guitar: Strum Down pressed\n"); } if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_YELLOW)) { printf("Guitar: Yellow pressed\n"); } if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_GREEN)) { printf("Guitar: Green pressed\n"); } if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_BLUE)) { printf("Guitar: Blue pressed\n"); } if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_RED)) { printf("Guitar: Red pressed\n"); } if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE)) { printf("Guitar: Orange pressed\n"); } if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_PLUS)) { printf("Guitar: Plus pressed\n"); } if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_MINUS)) { printf("Guitar: Minus pressed\n"); } printf("Guitar whammy bar: %f\n", gh3->whammy_bar); printf("Guitar joystick angle: %f\n", gh3->js.ang); printf("Guitar joystick magnitude: %f\n", gh3->js.mag); } else if (wm->exp.type == EXP_WII_BOARD) { /* wii balance board */ struct wii_board_t* wb = (wii_board_t*)&wm->exp.wb; float total = wb->tl + wb->tr + wb->bl + wb->br; float x = ((wb->tr + wb->br) / total) * 2 - 1; float y = ((wb->tl + wb->tr) / total) * 2 - 1; printf("Weight: %f kg @ (%f, %f)\n", total, x, y); /* printf("Interpolated weight: TL:%f TR:%f BL:%f BR:%f\n", wb->tl, wb->tr, wb->bl, wb->br); */ /* printf("Raw: TL:%d TR:%d BL:%d BR:%d\n", wb->rtl, wb->rtr, wb->rbl, wb->rbr); */ } if (wm->exp.type == EXP_MOTION_PLUS || wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) { printf("Motion+ angular rates (deg/sec): pitch:%03.2f roll:%03.2f yaw:%03.2f\n", wm->exp.mp.angle_rate_gyro.pitch, wm->exp.mp.angle_rate_gyro.roll, wm->exp.mp.angle_rate_gyro.yaw); } }
void FWiimoteInputDevice::handle_event(struct wiimote_t* wm, int id) { UE_LOG(LogWiimote, Log, TEXT("\n\n--- EVENT [id %i] ---"), wm->unid); CurrentStates[0] = IS_PRESSED(wm, WIIMOTE_BUTTON_A) || IS_HELD(wm, WIIMOTE_BUTTON_A); CurrentStates[1] = IS_PRESSED(wm, WIIMOTE_BUTTON_B) || IS_HELD(wm, WIIMOTE_BUTTON_B); CurrentStates[2] = IS_PRESSED(wm, WIIMOTE_BUTTON_ONE) || IS_HELD(wm, WIIMOTE_BUTTON_ONE); CurrentStates[3] = IS_PRESSED(wm, WIIMOTE_BUTTON_TWO) || IS_HELD(wm, WIIMOTE_BUTTON_TWO); CurrentStates[4] = IS_PRESSED(wm, WIIMOTE_BUTTON_PLUS) || IS_HELD(wm, WIIMOTE_BUTTON_PLUS); CurrentStates[5] = IS_PRESSED(wm, WIIMOTE_BUTTON_MINUS) || IS_HELD(wm, WIIMOTE_BUTTON_MINUS); CurrentStates[6] = IS_PRESSED(wm, WIIMOTE_BUTTON_UP) || IS_HELD(wm, WIIMOTE_BUTTON_UP); CurrentStates[7] = IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN) || IS_HELD(wm, WIIMOTE_BUTTON_DOWN); CurrentStates[8] = IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT) || IS_HELD(wm, WIIMOTE_BUTTON_LEFT); CurrentStates[9] = IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT) || IS_HELD(wm, WIIMOTE_BUTTON_RIGHT); if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) { UE_LOG(LogWiimote, Log, TEXT("HOME pressed")); } /* show events specific to supported expansions */ if (wm->exp.type == EXP_NUNCHUK || wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) { /* nunchuk */ struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk; const float DEADZONE = 0.6f; CurrentStates[10] = IS_PRESSED(nc, NUNCHUK_BUTTON_C) || IS_HELD(wm, NUNCHUK_BUTTON_C); CurrentStates[11] = IS_PRESSED(nc, NUNCHUK_BUTTON_Z) || IS_HELD(wm, NUNCHUK_BUTTON_Z); CurrentStates[12] = nc->js.y > DEADZONE; CurrentStates[13] = nc->js.y < -DEADZONE; CurrentStates[14] = nc->js.x < -DEADZONE; CurrentStates[15] = nc->js.x > DEADZONE; UE_LOG(LogWiimote, Log, TEXT("nunchuk roll = %f"), nc->orient.roll); UE_LOG(LogWiimote, Log, TEXT("nunchuk pitch = %f"), nc->orient.pitch); UE_LOG(LogWiimote, Log, TEXT("nunchuk yaw = %f"), nc->orient.yaw); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick angle: %f"), nc->js.ang); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick magnitude: %f"), nc->js.mag); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick vals: %f, %f"), nc->js.x, nc->js.y); UE_LOG(LogWiimote, Log, TEXT("nunchuk joystick calibration (min, center, max): x: %i, %i, %i y: %i, %i, %i"), nc->js.min.x, nc->js.center.x, nc->js.max.x, nc->js.min.y, nc->js.center.y, nc->js.max.y); } /* * If IR tracking is enabled then print the coordinates * on the virtual screen that the wiimote is pointing to. * * Also make sure that we see at least 1 dot. */ if (WIIUSE_USING_IR(wm)) { /* go through each of the 4 possible IR sources */ for (int i = 0; i < 4; ++i) { /* check if the source is visible */ if (wm->ir.dot[i].visible) { UE_LOG(LogWiimote, Log, TEXT("IR source %i: (%u, %u)"), i, wm->ir.dot[i].x, wm->ir.dot[i].y); } } UE_LOG(LogWiimote, Log, TEXT("IR cursor: (%u, %u)"), wm->ir.x, wm->ir.y); UE_LOG(LogWiimote, Log, TEXT("IR z distance: %f"), wm->ir.z); } // Update motion controls. FVector Tilt(0, 0, 0); FVector RotationRate(0, 0, 0); FVector Gravity(0, 0, 0); FVector Acceleration(0, 0, 0); /* if the accelerometer is turned on then print angles */ if (WIIUSE_USING_ACC(wm)) { Tilt.X = -wm->orient.pitch; Tilt.Y = wm->orient.yaw; Tilt.Z = wm->orient.roll; Acceleration.X = wm->accel.x; Acceleration.Y = wm->accel.y; Acceleration.Z = wm->accel.z; } if (wm->exp.type == EXP_MOTION_PLUS || wm->exp.type == EXP_MOTION_PLUS_NUNCHUK) { RotationRate.X = -wm->exp.mp.angle_rate_gyro.pitch; RotationRate.Y = wm->exp.mp.angle_rate_gyro.yaw; RotationRate.Z = wm->exp.mp.angle_rate_gyro.roll; } Gravity.X = wm->gforce.x; Gravity.Y = wm->gforce.y; Gravity.Z = wm->gforce.z; MessageHandler->OnMotionDetected(Tilt, RotationRate, Gravity, Acceleration, id); }