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 );
}
/**
 *	@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 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);
}
예제 #4
0
/**
 * 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;
			}
		}
	}
}
예제 #5
0
/**
 * 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;
			}
		}
	}
}
예제 #6
0
int main(int argc, char** argv)
{
    InitWiimotes();

    bool bLoop = true;
    int nCursorControl = CUR_CTRL_ARROWS;
    float fMouseSpeedX=0;
    float fMouseSpeedY=0;

    int nPrecX, nPrecY;


    while(bLoop)
    {

        int n;

        if(wiiuse_poll(WMTable, nConnectedWM))
        {
            for (n=0 ; n>nConnectedWM; n++);
            {
                switch(WMTable[n]->event)
                {
                    case WIIUSE_NONE:
                        break;

                    case WIIUSE_CONNECT:
                        printf("Wiimote connectee\n");break;
					case WIIUSE_DISCONNECT:
                        printf("Wiimote deconnectee\n");break;
					case WIIUSE_UNEXPECTED_DISCONNECT:
                        printf("Wiimote deconnectee a la bourrin\n");break;

                    case WIIUSE_EVENT:


                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_TWO)) printf("2 NON SUPPORTE\n");

                        //Touche combo !
                        while(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_ONE) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_ONE))
                        {
                            while(wiiuse_poll(WMTable, nConnectedWM))
                            {
                                if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_B))
                                {
                                    printf("Controle du curseur par pointage\n");
                                    nPrecX=-1;
                                    nPrecY=-1;
                                    nCursorControl = CUR_CTRL_MOTPOINT;
                                    break;
                                }
                                else if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_A))
                                {
                                    printf("Controle du curseur en manette\n");
                                    nPrecX=-1;
                                    nPrecY=-1;
                                    nCursorControl = CUR_CTRL_MOTPAD;
                                    break;
                                }
                                else if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_HOME))
                                {
                                    printf("Controle du curseur via IR\n");
                                    nPrecX=-1;
                                    nPrecY=-1;
                                    nCursorControl = CUR_CTRL_IR;
                                    break;
                                }
                                else if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_UP) || IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_DOWN) || IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_RIGHT) || IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_LEFT))
                                {
                                    printf("Controle du curseur avec les fleches\n");
                                    nPrecX=-1;
                                    nPrecY=-1;
                                    nCursorControl = CUR_CTRL_ARROWS;
                                    break;
                                }
                            }
                        }


                        //Souris . Clic gauche = B
                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_B))
                            mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
                        if(IS_RELEASED(WMTable[n], WIIMOTE_BUTTON_B))
                            mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
                        //

                        //Souris . molette haut
                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_MINUS))
                            mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 120, 0);
                        //

                        //Souris . Bouton milieu = HOME
                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_HOME))
                            mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
                        if(IS_RELEASED(WMTable[n], WIIMOTE_BUTTON_HOME))
                            mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);
                        //

                        //Souris . molette bas
                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_PLUS))
                            mouse_event(MOUSEEVENTF_WHEEL, 0, 0, -120, 0);
                        //

                        //Souris . Clic droit = A
                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_A))
                            mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
                        if(IS_RELEASED(WMTable[n], WIIMOTE_BUTTON_A))
                            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
                        //
                        break;

					case WIIUSE_STATUS:
                        printf("Wiimote status\n");
                        printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", WMTable[n]->unid);
                        printf("leds:            %i %i %i %i\n", WIIUSE_IS_LED_SET(WMTable[n], 1), WIIUSE_IS_LED_SET(WMTable[n], 2), WIIUSE_IS_LED_SET(WMTable[n], 3), WIIUSE_IS_LED_SET(WMTable[n], 4));
                        printf("battery:         %.1f %%\n", 100*WMTable[n]->battery_level);
                        break;

					case WIIUSE_READ_DATA:
                        printf("Wiimote read\n");
                        break;


					case WIIUSE_NUNCHUK_INSERTED:
                        printf("Nunchuk insere\n");break;
					case WIIUSE_NUNCHUK_REMOVED:
                        printf("Nunchuk enleve\n");break;

					case WIIUSE_CLASSIC_CTRL_INSERTED:
					case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
					case WIIUSE_CLASSIC_CTRL_REMOVED:
					case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
                        break;
                }
            }
        }
        //else//Pas d'event
        {
            for (n=0 ; n>nConnectedWM; n++);
            {

                //Déplacement de la souris
                tagPOINT CursorPos;

                if(nCursorControl==CUR_CTRL_MOTPOINT || nCursorControl==CUR_CTRL_MOTPAD)
                {
                    //Décélération permanente
                    if(fMouseSpeedX<0)
                    {
                        if(fMouseSpeedX+ABSOLUTE_DECEL>0)fMouseSpeedX=0;
                        else fMouseSpeedX+=ABSOLUTE_DECEL;
                    }
                    else if(fMouseSpeedX>0)
                    {
                        if(fMouseSpeedX-ABSOLUTE_DECEL<0)fMouseSpeedX=0;
                        else fMouseSpeedX-=ABSOLUTE_DECEL;
                    }
                    if(fMouseSpeedY<0)
                    {
                        if(fMouseSpeedY+ABSOLUTE_DECEL>0)fMouseSpeedY=0;
                        else fMouseSpeedY+=ABSOLUTE_DECEL;
                    }
                    else if(fMouseSpeedY>0)
                    {
                        if(fMouseSpeedY-ABSOLUTE_DECEL<0)fMouseSpeedY=0;
                        else fMouseSpeedY-=ABSOLUTE_DECEL;
                    }



                    //Calcul des coordonnées sur l'écran du point donné par la wiimote
                    int nWiimoteX;
                    int nWiimoteY;
                    if(nCursorControl==CUR_CTRL_MOTPOINT)
                    {
                        nWiimoteX = ((WMTable[0]->orient.roll+45)/90)*SCREEN_WIDTH;
                        nWiimoteY = ((WMTable[0]->orient.pitch+60)/90)*SCREEN_HEIGHT;
                    }
                    else if(nCursorControl==CUR_CTRL_MOTPAD)
                    {
                        nWiimoteX = ((WMTable[0]->orient.pitch+45)/90)*SCREEN_WIDTH;
                        nWiimoteY = ((-WMTable[0]->orient.roll+45)/90)*SCREEN_HEIGHT;
                    }

                    //Calcul de la vitesse du curseur
                    GetCursorPos(&CursorPos);


                    //Elimination des valeurs parasites
                    //if((abs(nWiimoteX-nPrecX)<10 && abs(nWiimoteY-nPrecY)<10) || (nPrecX==-1 && nPrecY==-1))
                    {
                        fMouseSpeedX = (nWiimoteX - CursorPos.x)/RELATIVE_ACCEL_RATIO;
                        fMouseSpeedY = (nWiimoteY - CursorPos.y)/RELATIVE_ACCEL_RATIO;
                    }
                    /*else
                    {
                        fMouseSpeedX = (nPrecX - CursorPos.x)/RELATIVE_ACCEL_RATIO;
                        fMouseSpeedY = (nPrecY - CursorPos.y)/RELATIVE_ACCEL_RATIO;
                    }*/
                    //

                    SetCursorPos(CursorPos.x+fMouseSpeedX, CursorPos.y+fMouseSpeedY);

                    nPrecX=nWiimoteX;
                    nPrecY=nWiimoteY;


                }
                else if(nCursorControl==CUR_CTRL_IR)
                {

                    int nSommeX=0, nSommeY=0, nDots=0;
                    for(int i=0 ; i<4 ; i++)
                    {
                        if(WMTable[n]->ir.dot[i].visible)
                        {
                            nDots++;
                            nSommeX+=WMTable[n]->ir.dot[i].x;
                            nSommeY+=WMTable[n]->ir.dot[i].y;
                        }
                    }

                    float fCenterX=-1.0, fCenterY=-1.0;

                    if(nDots!=0)
                    {
                        fCenterX=nSommeX/nDots;
                        fCenterY=nSommeY/nDots;
                    }


                    if(fCenterX!=-1.0 && fCenterY!=-1.0)
                    {


                        int nWiimoteX = (fCenterX/1024)*(SCREEN_WIDTH+512)-256;
                        int nWiimoteY = (fCenterY/768)*(SCREEN_HEIGHT+384)-192;
                        SetCursorPos(nWiimoteX, nWiimoteY);
                    }



                }
                else
                {
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_UP) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_UP))
                    {
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x, CursorPos.y-ARROW_SPEED);
                    }
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_DOWN) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_DOWN))
                    {
                        tagPOINT CursorPos;
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x, CursorPos.y+ARROW_SPEED);
                    }
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_LEFT) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_LEFT))
                    {
                        tagPOINT CursorPos;
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x-ARROW_SPEED, CursorPos.y);
                    }
                    if(IS_PRESSED(WMTable[n], WIIMOTE_BUTTON_RIGHT) || IS_HELD(WMTable[n], WIIMOTE_BUTTON_RIGHT))
                    {
                        tagPOINT CursorPos;
                        GetCursorPos(&CursorPos);
                        SetCursorPos(CursorPos.x+ARROW_SPEED, CursorPos.y);
                    }
                }
            }
        }
    }
    EndWiimotes();
}
예제 #7
0
int main(int argc, char** argv)
{
    InitWiimotes();


    bool bLoop = true;

    float fRatio = -1.0;
    float fScale = -1.0;




    while(bLoop)
    {

        int n;

        if(wiiuse_poll(WMTable, nConnectedWM))
        {
            for (n=0 ; n>nConnectedWM; n++);
            {
                switch(WMTable[n]->event)
                {
                    case WIIUSE_NONE:
                        break;

                    case WIIUSE_CONNECT:
                        printf("Wiimote connectee\n");break;
					case WIIUSE_DISCONNECT:
                        printf("Wiimote deconnectee\n");break;
					case WIIUSE_UNEXPECTED_DISCONNECT:
                        printf("Wiimote deconnectee a la bourrin\n");break;

                    case WIIUSE_EVENT:
                        if(IS_JUST_PRESSED(WMTable[n], WIIMOTE_BUTTON_A))
                        {
                            /*
                            //Recherche des deux sources infrarouges
                            for(int i=0 ; i<4 && (dot0==0 && dot1==0) ; i++)
                            {
                                if(WMTable[n]->ir.dot[i].visible)
                                {
                                    if(dot0==0)
                                        dot0 = &WMTable[n]->ir.dot[i];
                                    else
                                        dot1 = &WMTable[n]->ir.dot[i];
                                }
                            }*/

                            dot0=&WMTable[n]->ir.dot[0];
                            dot1=&WMTable[n]->ir.dot[1];

                            if(dot0->visible && dot1->visible)
                            {
                                //Calibration !

                                float fDistDotToDot = GetDistanceBetweenDots();


                                fRatio = DIST_DOT2WM_MM*fDistDotToDot;

                                //TESTS ONLY :
                                fRatio = DIST_DOT2WM_MM*273.1;


                                fScale = DIST_DOT2DOT_MM/fDistDotToDot;

                                //TESTS ONLY
                                fScale = DIST_DOT2DOT_MM/273.1;





                                printf("Wiimote calibree !\n");

                            }
                            else
                            {
                                printf("La calibration requiers deux sources infrarouges\n");
                            }

                        }

                        break;

					case WIIUSE_STATUS:
                        printf("Wiimote status\n");
                        printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", WMTable[n]->unid);
                        printf("leds:            %i %i %i %i\n", WIIUSE_IS_LED_SET(WMTable[n], 1), WIIUSE_IS_LED_SET(WMTable[n], 2), WIIUSE_IS_LED_SET(WMTable[n], 3), WIIUSE_IS_LED_SET(WMTable[n], 4));
                        printf("battery:         %.1f %%\n", 100*WMTable[n]->battery_level);

                        printf("\n\nWIIMOTE NON CALIBREE ! Appuyez sur A une fois les sources placees a %dmm de la wiimote\n", DIST_DOT2WM_MM);
                        break;

					case WIIUSE_READ_DATA:
                        printf("Wiimote read\n");
                        break;


					case WIIUSE_NUNCHUK_INSERTED:
                        printf("Nunchuk insere\n");break;
					case WIIUSE_NUNCHUK_REMOVED:
                        printf("Nunchuk enleve\n");break;

					case WIIUSE_CLASSIC_CTRL_INSERTED:
					case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
					case WIIUSE_CLASSIC_CTRL_REMOVED:
					case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
                        break;
                }
            }
        }

        #define ARROW_SPEED 3

        #define SCREEN_WIDTH 1920
        #define SCREEN_HEIGHT 1080
        struct coord posA, posB, posC;
        for (n=0 ; n>nConnectedWM; n++);
        {



        }


        if(fRatio!=-1.0 && fScale!=-1.0)
        {
            printf("\n\nPosition :\n");
            if(dot0->visible && dot1->visible)
            {
                //Positon des dots
                posA.x = dot0->x;
                posA.y = 768-dot0->y;
                posB.x = dot1->x;
                posB.y = 768-dot1->y;

                //Position du centre
                posC.x = (posA.x+posB.x)/2;
                posC.y = (posA.y+posB.y)/2;

                //Calcul de la sistance en px séparant les dots
                float fDistDotToDot = sqrt( (dot0->x-dot1->x)*(dot0->x-dot1->x)+(dot0->y-dot1->y)*(dot0->y-dot1->y) );

                //Distance suivant z
                //float fZ = fRatio/fDistDotToDot;

                //printf("x=%.2fmm      y=%.2fmm      z=%.2fmm\n", (posC.x-512)*fScale*fZ/DIST_DOT2WM_MM, (posC.y-384)*fScale*fZ/DIST_DOT2WM_MM, fZ);

                float fY=-fRatio/fDistDotToDot;
                float fX=-(posC.x-512)*fScale*fY/DIST_DOT2WM_MM;
                float fZ=(posC.y-384)*fScale*fY/DIST_DOT2WM_MM;

                printf("x=%.2fmm      y=%.2fmm      z=%.2fmm\n", fX, fY, fZ);
            }
            else
                printf("Sources IR hors du champ de vision\n");
        }



        //SDL_Flip(oApp);


    }
    EndWiimotes();

    return 0;
}