Example #1
0
int event_thread(void *data)
{
	for(;;)
	{
		SDL_mutexP(wii_lock);

		if(wiiuse_poll(wiimotes, wiimotes_connected))
		{
			int i;
			for(i = 0;i<wiimotes_connected;i++)
			{
				if(wiimotes[i]->event == WIIUSE_EVENT)
				{
					if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_A))
					{
						play_beep();
					}
					if (IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_B))
					{
						play_ricochet();
					}
				}
				else if(wiimotes[i]->event == WIIUSE_DISCONNECT)
				{
					wiiuse_cleanup(wiimotes, 4);
					wiimotes_connected = 0;
					wiimotes = NULL;
					break;
				}
			}
		}

		SDL_mutexV(wii_lock);
	}
}
Example #2
0
File: sdl.c Project: 0xheart0/xbmc
void handle_event(struct wiimote_t* wm) {
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS))
		wiiuse_motion_sensing(wm, 1);
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS))
		wiiuse_motion_sensing(wm, 0);

	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 (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_B))
		wiiuse_toggle_rumble(wm);

	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_ONE)) {
		int level;
		WIIUSE_GET_IR_SENSITIVITY(wm, &level);
		wiiuse_set_ir_sensitivity(wm, level+1);
	}
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_TWO)) {
		int level;
		WIIUSE_GET_IR_SENSITIVITY(wm, &level);
		wiiuse_set_ir_sensitivity(wm, level-1);
	}

	#if 0
	if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_A)) {
		if (render_mode == IR)
			render_mode = TEAPOT;
		else
			render_mode = IR;
		resize_window(width, height);
	}
	#endif
}
void handle_event(struct wiimote_t* wm) {
	
	if (wm->exp.type == EXP_GUITAR_HERO_3) 
	{
		
		struct guitar_hero_3_t* gh3 = (guitar_hero_3_t*)&wm->exp.gh3;

		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP))				ActivateOutput(&m_actInfo, GH3_STRUM_UP, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN))			ActivateOutput(&m_actInfo, GH3_STRUM_DOWN, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_YELLOW))				ActivateOutput(&m_actInfo, GH3_YELLOW, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_GREEN))				ActivateOutput(&m_actInfo, GH3_GREEN, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_BLUE))					ActivateOutput(&m_actInfo, GH3_BLUE, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_RED))					ActivateOutput(&m_actInfo, GH3_RED, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE))				ActivateOutput(&m_actInfo, GH3_ORANGE, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_PLUS))					ActivateOutput(&m_actInfo, GH3_PLUS, true);
		if(IS_JUST_PRESSED(gh3, GUITAR_HERO_3_BUTTON_MINUS))				ActivateOutput(&m_actInfo, GH3_MINUS, true);
			
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP))					ActivateOutput(&m_actInfo, GH3_STRUM_UP, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN))				ActivateOutput(&m_actInfo, GH3_STRUM_DOWN, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_YELLOW))					ActivateOutput(&m_actInfo, GH3_YELLOW, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_GREEN))					ActivateOutput(&m_actInfo, GH3_GREEN, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_BLUE))						ActivateOutput(&m_actInfo, GH3_BLUE, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_RED))						ActivateOutput(&m_actInfo, GH3_RED, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_ORANGE))					ActivateOutput(&m_actInfo, GH3_ORANGE, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_PLUS))						ActivateOutput(&m_actInfo, GH3_PLUS, false);
		if(IS_RELEASED(gh3, GUITAR_HERO_3_BUTTON_MINUS))					ActivateOutput(&m_actInfo, GH3_MINUS, false);
		
		
		if(!gh3_move) {
			ActivateOutput(&m_actInfo, GH3_BAR,  gh3->whammy_bar);
			ActivateOutput(&m_actInfo, GH3_JOYSTICK_ANGLE, gh3->js.ang);
			ActivateOutput(&m_actInfo, GH3_JOYSTICK_MAG, gh3->js.mag);
		}

		gh3_move=true;
	}
}
Example #4
0
int handle_event(struct wiimote_t *wm)
{
  if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_A)) { 
    currently_training = 1 - currently_training; 
  }

  int button = STOP_BUTTON; 

  //if (IS_PRESSED(wm, WIIMOTE_BUTTON_UP))
  //  button = FORWARD_BUTTON; 

  if (IS_PRESSED(wm, WIIMOTE_BUTTON_B)) { 
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) { 
      button = FORWARD_BUTTON; 
    }
    else if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) { 
      button = FORWARD_BUTTON + 1000; 
    }
    }
  //else if (IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) { 
   // button = BACKWARD_BUTTON; 
  //}
  else if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) { 
    button = LEFT_TURN_BUTTON; 
  }
  else if (IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) { 
    button = RIGHT_TURN_BUTTON; 
  }
  else if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE)) { 
    button = ONE_BUTTON; 
  }
  else if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO)) { 
    button = TWO_BUTTON; 
  }

  return button; 
}
/**
 *	@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);
	}
}
void handle_event(struct wiimote_t* wm)
{
    static uint8_t controls = ABS | TC | STABILITY;
#if 0
    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");
#endif
    /*
     *	Pressing home will tell the wiimote we are interested in movement.
     */
    if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_HOME))
    {
        wiiuse_set_orient_threshold(wm, 0.5);
        wiiuse_motion_sensing(wm, 1);
    }

    if(IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_PLUS)){
	carInputs.gear++;
	if(carInputs.gear>7)	carInputs.gear = 7;
        controls ^= ABS;
	}
    if(IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_UP)){
	carInputs.cruisedist = carInputs.cruisedist +10;
	if(carInputs.cruisedist > 100) carInputs.cruisedist = 100;
    }
    if(IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_DOWN)){
	carInputs.cruisedist = carInputs.cruisedist -10;
        if(carInputs.cruisedist <50) carInputs.cruisedist = 50;
    }
    if(IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_MINUS)){
	if(carInputs.gear>=2)
	carInputs.gear--;

        controls ^= TC;
	}
    if (IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)){
	controls ^= STABILITY;
	carInputs.gear = 0;
    	}

    if(IS_JUST_PRESSED(wm, WIIMOTE_BUTTON_A))
        controls ^= CRUISE;

    if (WIIUSE_USING_ACC(wm))
    {
        // obtain the steering angle input from wiimote
        float steer_temp =  wm->orient.pitch;
        if(steer_temp < -90)
            steer_temp = -90;
        else if(steer_temp > 90)
            steer_temp = 90;

        if(steer_temp != 0)
            carInputs.steer = (steer_temp/abs(steer_temp))*pow(steer_temp/90,2)*50;
        else
            carInputs.steer = 0;
        //printf("steer: %d\n", carInputs.steer);
    }

    // obtain acceleration input from WiiMote
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_ONE))
    {
        carInputs.accel = 100;
    }
    else
        carInputs.accel = 0;

    // obtain brake input from WiiMote
    if (IS_PRESSED(wm, WIIMOTE_BUTTON_TWO))
    {
        carInputs.brake = 100;
        controls &= ~(CRUISE);
    }
    else
        carInputs.brake = 0;

    if (IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT))
        carInputs.gear = -1;
    carInputs.clutch = 0;
    carInputs.controls = controls;
}
	/**
 *	@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);
	}
	
}
Example #8
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();
}
Example #9
0
/**
 *	@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);
	}
}
Example #10
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;
}
        void handle_event( struct wiimote_t* wm )
        {

            if ( wm->exp.type == EXP_CLASSIC )
            {

                struct classic_ctrl_t* cc = ( classic_ctrl_t* )&wm->exp.classic;

                //OK
                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_A ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_A, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_B ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_B, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_X ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_X, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_Y ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_Y, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_ZL ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_ZL, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_ZR ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_ZR, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_UP ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_TOP, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_DOWN ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_DOWN, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_LEFT ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_LEFT, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_RIGHT ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_RIGHT, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_FULL_L ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_FULL_L, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_FULL_R ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_FULL_R, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_MINUS ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_MINUS, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_PLUS ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_PLUS, true );
                }

                if ( IS_JUST_PRESSED( cc, CLASSIC_CTRL_BUTTON_HOME ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_HOME, true );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_A ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_A, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_B ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_B, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_X ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_X, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_Y ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_Y, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_ZL ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_ZL, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_ZR ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_ZR, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_UP ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_TOP, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_DOWN ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_DOWN, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_LEFT ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_LEFT, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_RIGHT ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_RIGHT, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_FULL_L ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_FULL_L, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_FULL_R ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_FULL_R, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_MINUS ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_MINUS, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_PLUS ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_PLUS, false );
                }

                if ( IS_RELEASED( cc, CLASSIC_CTRL_BUTTON_HOME ) )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_HOME, false );
                }


                //Optimisation
                if ( !classic_move )
                {
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_SHOULDER_L, cc->l_shoulder );
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_SHOULDER_R, cc->r_shoulder );
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_LEFT_ANGLE, cc->ljs.ang );
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_LEFT_MAG, cc->ljs.mag );
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_RIGHT_ANGLE, cc->rjs.ang );
                    ActivateOutput( &m_actInfo, CLASSIC_ANALOG_RIGHT_MAG, cc->rjs.mag );

                    classic_move = true;
                }
            }

            /*
            else {
                //ActivateOutput(&m_actInfo, 0, "Incompatible expansion type");
                //CryLogAlways("Bad Expansion type");
            }
            */
        }
        void handle_event( struct wiimote_t* wm )
        {

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_A ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_A, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_A ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_A, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_B ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_B, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_B ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_B, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_DOWN ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_DOWN, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_DOWN ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_DOWN, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_LEFT ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_LEFT, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_LEFT ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_LEFT, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_RIGHT ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_RIGHT, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_RIGHT ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_RIGHT, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_UP ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_UP, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_UP ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_UP, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_MINUS ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_MINUS, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_MINUS ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_MINUS, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_PLUS ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_PLUS, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_PLUS ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_PLUS, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_HOME ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_HOME, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_HOME ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_HOME, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_ONE ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_ONE, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_ONE ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_ONE, false );
            }

            if ( IS_JUST_PRESSED( wm, WIIMOTE_BUTTON_TWO ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_TWO, true );
            }

            if ( IS_RELEASED( wm, WIIMOTE_BUTTON_TWO ) )
            {
                ActivateOutput( &m_actInfo, WIIMOTE_TWO, false );
            }



            if ( WIIUSE_USING_ACC( wm ) && !wiimote_move )
            {
                //Optimisation v0.1
                wiimote_move = true;
                Vec3 orient = Vec3( wm->orient.a_roll, wm->orient.a_pitch, wm->orient.yaw );
                ActivateOutput( &m_actInfo, WIIMOTE_RPY, orient );
            }

            /*
            if (WIIUSE_USING_IR(wm)) {
                int i = 0;

                for (; i < 4; ++i) {
                    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 && !nunchuk_move )
            {
                nunchuk_move = true;
                struct nunchuk_t* nc = ( nunchuk_t* )&wm->exp.nunchuk;

                if ( IS_PRESSED( nc, NUNCHUK_BUTTON_C ) )
                {
                    ActivateOutput( &m_actInfo, NUNCHUK_C, true );

                }

                if ( IS_PRESSED( nc, NUNCHUK_BUTTON_Z ) )
                {
                    ActivateOutput( &m_actInfo, NUNCHUK_Z, true );

                }

                //Optimisation necessaire ici !
                Vec3 orient = Vec3( nc->orient.roll, nc->orient.pitch, nc->orient.yaw );
                ActivateOutput( &m_actInfo, NUNCHUK_RPY, orient );

                Vec3 joy = Vec3( nc->js.ang, nc->js.mag, 0 );
                ActivateOutput( &m_actInfo, NUNCHUK_JOYSTICK, joy );
            }

        }
Example #13
0
enum state input_wiimote(struct game* game, enum state state2) { // state : 0 = MENU, 1 = GAME

	key_event_t key_event;
	SDLKey key;
	enum state state = state2;

	if(wiiuse_poll(wiimotes, MAX_WIIMOTES)) {
		for (int i = 0; i < MAX_WIIMOTES; ++i) {
			//printf("wiimote %d: btns: %d,  held, %d releaded: %d\n", i, wiimotes[i]->btns, wiimotes[i]->btns_held, wiimotes[i]->btns_released);
			if(wiimotes[i]->event == WIIUSE_EVENT) {

				if(IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_RIGHT)) {
					switch(i) {
					case 0:
						key = SDLK_UP;
						break;
					case 1:
						key = SDLK_z;
						break;
					case 2:
						key = SDLK_t;
						break;
					case 3:
						key = SDLK_i;
						break;
					}
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_LEFT)) {
					switch(i) {
					case 0:
						key = SDLK_DOWN;
						break;
					case 1:
						key = SDLK_s;
						break;
					case 2:
						key = SDLK_g;
						break;
					case 3:
						key = SDLK_k;
						break;
					}
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_UP)) {
					switch(i) {
					case 0:
						key = SDLK_LEFT;
						break;
					case 1:
						key = SDLK_q;
						break;
					case 2:
						key = SDLK_f;
						break;
					case 3:
						key = SDLK_j;
						break;
					}
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_DOWN)) {
					switch(i) {
					case 0:
						key = SDLK_RIGHT;
						break;
					case 1:
						key = SDLK_d;
						break;
					case 2:
						key = SDLK_h;
						break;
					case 3:
						key = SDLK_l;
						break;
					}
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[i], WIIMOTE_BUTTON_ONE)) {
					switch(i) {
					case 0:
						key = SDLK_SPACE;
						break;
					case 1:
						key = SDLK_a;
						break;
					case 2:
						key = SDLK_r;
						break;
					case 3:
						key = SDLK_u;
						break;
					}
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[0], WIIMOTE_BUTTON_TWO)) {
					key = SDLK_RETURN;
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_JUST_PRESSED(wiimotes[0], WIIMOTE_BUTTON_HOME)) {
					key = SDLK_ESCAPE;
					key_event = DOWN;
					state = wiimote_send_event(state, game, key, key_event);
				}

				if(IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_RIGHT)) {
					switch(i) {
					case 0:
						key = SDLK_UP;
						break;
					case 1:
						key = SDLK_z;
						break;
					case 2:
						key = SDLK_t;
						break;
					case 3:
						key = SDLK_i;
						break;
					}
					key_event = UP;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_LEFT)) {
					switch(i) {
					case 0:
						key = SDLK_DOWN;
						break;
					case 1:
						key = SDLK_s;
						break;
					case 2:
						key = SDLK_g;
						break;
					case 3:
						key = SDLK_k;
						break;
					}
					key_event = UP;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_UP)) {
					switch(i) {
					case 0:
						key = SDLK_LEFT;
						break;
					case 1:
						key = SDLK_q;
						break;
					case 2:
						key = SDLK_f;
						break;
					case 3:
						key = SDLK_j;
						break;
					}
					key_event = UP;
					state = wiimote_send_event(state, game, key, key_event);
				}
				if(IS_RELEASED(wiimotes[i], WIIMOTE_BUTTON_DOWN)) {
					switch(i) {
					case 0:
						key = SDLK_RIGHT;
						break;
					case 1:
						key = SDLK_d;
						break;
					case 2:
						key = SDLK_h;
						break;
					case 3:
						key = SDLK_l;
						break;
					}
					key_event = UP;
					state = wiimote_send_event(state, game, key, key_event);
				}
			}
		}
	}
	return state;
}
Example #14
0
int32_t wii_data(CSOUND *csound, WIIMOTE *p)
{
    wiimote **wii = p->wii;
    wiirange_t *wiir = p->wiir;
    int32_t n = (int32_t)*p->num;
    int32_t kontrol = (int32_t)(*p->kControl+FL(0.5));
    if (UNLIKELY(n>=MAX_WIIMOTES || !(wii[n]->state & WIIMOTE_STATE_CONNECTED))) {
      printf("state of wii %d is %x\n", n, wii[n]->state);
      return csound->PerfError(csound, &(p->h),
                               Str("wiimote %d does not exist"), n);
    }
    if (kontrol<0) {
      printf("%f -- %.4x: "
             "tilt=[%f %f];\nforce=(%f %f %f)\n",
             100.0*wii[n]->battery_level, wii[n]->btns,
             wiir[n].pitch_min+wiir[n].pitch_scale*(FL(90.0)+
                                                    (MYFLT)wii[n]->orient.pitch),
             wiir[n].roll_min+wiir[n].roll_scale*(FL(90.0)-
                                                  (MYFLT)wii[n]->orient.roll),
             wii[n]->gforce.x, wii[n]->gforce.y, wii[n]->gforce.z);
      *p->res = FL(0.0);
      return OK;
    }
    if (kontrol>0 && kontrol<17) {
      *p->res = (MYFLT)IS_JUST_PRESSED(wii[n], 1<<(kontrol-1));
    }
    if (kontrol>100 && kontrol<117) {
      *p->res = (MYFLT)IS_PRESSED(wii[n], 1<<(kontrol-101));
      return OK;
     }
    if (kontrol>200 && kontrol<217) {
      *p->res = (MYFLT)IS_HELD(wii[n], 1<<(kontrol-201));
      return OK;
     }
    if (kontrol>300 && kontrol<317) {
      *p->res = (MYFLT)IS_RELEASED(wii[n], 1<<(kontrol-301));
      return OK;
     }
    else switch (kontrol) {
    case WII_BUTTONS:
      *p->res = (MYFLT)(wii[n]->btns&WIIMOTE_BUTTON_ALL);
      return OK;
    /* case 17: */
    /*   *p->res = wiir[n].axis_x_min+wiir[n].axis_x_scale*(MYFLT)wii[n]->axis.x; */
    /*   return OK; */
    /* case 18: */
    /*   *p->res = wiir[n].axis_y_min+wiir[n].axis_y_scale*(MYFLT)wii[n]->axis.y; */
    /*   return OK; */
    /* case 19: */
    /*   *p->res = wiir[n].axis_z_min+wiir[n].axis_z_scale*(MYFLT)wii[n]->axis.z; */
    /*   return OK; */
    case WII_PITCH:
      /* I think the sign is wrong so negated; inplies negative is down */
      *p->res = wiir[n].pitch_min+
        wiir[n].pitch_scale*(FL(90.0)-(MYFLT)wii[n]->orient.pitch);
      return OK;
    case WII_ROLL:
      *p->res = wiir[n].roll_min+
        wiir[n].roll_scale*(FL(90.0)+(MYFLT)wii[n]->orient.roll);
      return OK;
    /* case 22: */
    /*   *p->res = wiir[n].tilt_z_min+
         wiir[n].tilt_z_scale*(FL(90.0)-(MYFLT)wii[n]->tilt.z); */
    /*   return OK; */
    case WII_FORCE_X:
      *p->res = (MYFLT)wii[n]->gforce.x;
      return OK;
    case WII_FORCE_Y:
      *p->res = (MYFLT)wii[n]->gforce.y;
      return OK;
    case WII_FORCE_Z:
      *p->res = (MYFLT)wii[n]->gforce.z;
      return OK;
    case WII_FORCE_TOTAL:
      *p->res = SQRT(wii[n]->gforce.x*wii[n]->gforce.x+
                     wii[n]->gforce.y*wii[n]->gforce.y+
                     wii[n]->gforce.z*wii[n]->gforce.z);
      return OK;
    case WII_BATTERY:
      *p->res = FL(100.0)*(MYFLT)wii[n]->battery_level;
      return OK;
    case WII_NUNCHUK_ANG:
      *p->res = (MYFLT)wii[n]->exp.nunchuk.js.ang;
      return OK;
    case WII_NUNCHUK_MAG:
      *p->res = (MYFLT)wii[n]->exp.nunchuk.js.mag;
      return OK;
    case WII_NUNCHUK_PITCH:
      *p->res = wiir[n].nunchuk_pitch_min+
        wiir[n].nunchuk_pitch_scale*(FL(90.0)-
                                     (MYFLT)wii[n]->exp.nunchuk.orient.pitch);
      return OK;
    case WII_NUNCHUK_ROLL:
      *p->res = wiir[n].nunchuk_roll_min+
        wiir[n].nunchuk_roll_scale*(FL(90.0)-
                                    (MYFLT)wii[n]->exp.nunchuk.orient.roll);
     return OK;
    /* case 32: */
    /*   *p->res = (MYFLT)wii[n]->exp.nunchuk.axis.z; */
    /*   return OK; */
    case WII_NUNCHUK_Z:
      *p->res = (MYFLT)((wii[n]->exp.nunchuk.btns & NUNCHUK_BUTTON_Z)==
                        NUNCHUK_BUTTON_Z);
      return OK;
    case WII_NUNCHUK_C:
      *p->res = (MYFLT)((wii[n]->exp.nunchuk.btns & NUNCHUK_BUTTON_C)==
                        NUNCHUK_BUTTON_C);
      return OK;
    case WII_IR1_X:
      *p->res = (MYFLT)wii[n]->ir.x;
      return OK;
    case WII_IR1_Y:
      *p->res = (MYFLT)wii[n]->ir.y;
      return OK;
    case WII_IR1_Z:
      *p->res = (MYFLT)wii[n]->ir.z;
      return OK;
    }
    return NOTOK;
}