Example #1
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 FWiimoteInputDevice::SetMotionSensingEnabled(int32 ControllerId, bool IsEnabled)
{
    if (GWiimotes[ControllerId] == nullptr)
        return;
    if (IsEnabled)
    {
        wiiuse_motion_sensing(GWiimotes[ControllerId], 1);
    }
    else
    {
        wiiuse_motion_sensing(GWiimotes[ControllerId], 0);
    }
}
Example #3
0
/** Enables or disables the accelerometer in wiimotes (to save battery life).
 *  \param state True if the accelerometer should be enabled.
 */
void WiimoteManager::enableAccelerometer(bool state)
{
    for (unsigned int i=0; i < m_wiimotes.size(); ++i)
    {
        wiiuse_motion_sensing(m_wiimotes[i]->getWiimoteHandle(), state ? 1 : 0);
    }
}   // enableAccelerometer
Example #4
0
int32_t wiimote_find(CSOUND *csound, WIIMOTE *p)
{
    int32_t n, i;
    wiimote **wiimotes;
    wiirange_t *wiirange;
    int32_t max_wiimotes;

    wiimotes = (wiimote**)csound->QueryGlobalVariable(csound, "wiiMote");
    if (wiimotes == NULL) {
      csound->CreateGlobalVariable(csound, "wiiMote",
                                           MAX_WIIMOTES*sizeof(wiimote*));
      wiimotes = (wiimote**)csound->QueryGlobalVariable(csound, "wiiMote");
    }
    wiirange = (wiirange_t *)csound->QueryGlobalVariable(csound, "wiiRange");
    if (wiirange == NULL) {
      csound->CreateGlobalVariable(csound, "wiiRange",
                                           MAX_WIIMOTES*sizeof(wiirange_t));
      wiirange = (wiirange_t *)csound->QueryGlobalVariable(csound, "wiiRange");
    }
    {                           /* Use our copy not his */
      wiimote** ww = wiiuse_init(MAX_WIIMOTES);
      memcpy(wiimotes, ww, MAX_WIIMOTES*sizeof(wiimote*));
      free(ww);
    }
    i = (int32_t)*p->kControl;
    if (i<=0) i = 10;           /* default timeout */
    max_wiimotes = (int32_t)*p->num;
    if (max_wiimotes<=0 || max_wiimotes>MAX_WIIMOTES) max_wiimotes = MAX_WIIMOTES;
    n  = wiiuse_find(wiimotes, max_wiimotes, i);
    if (LIKELY(n!=0)) n = wiiuse_connect(wiimotes, max_wiimotes);
    if (UNLIKELY(n==0)) {
      return csound->InitError(csound, "%s", Str("unable to open wiimote\n"));
    }
    /* Initialise ranges */
    for (i=0; i<n; i++) {
      wiiuse_set_leds(wiimotes[i], WIIMOTE_LED_1<<i);
      wiirange[i].axis_x_min    = FL(0.0);
      wiirange[i].axis_x_scale  = FL(1.0);
      wiirange[i].axis_y_min    = FL(0.0);
      wiirange[i].axis_y_scale  = FL(1.0);
      wiirange[i].axis_z_min    = FL(0.0);
      wiirange[i].axis_z_scale  = FL(1.0);
      wiirange[i].pitch_min    = -FL(90.0);
      wiirange[i].pitch_scale  = FL(1.0);
      wiirange[i].roll_min    = -FL(90.0);
      wiirange[i].roll_scale  = FL(1.0);
      wiirange[i].nunchuk_pitch_min   = -FL(90.0);
      wiirange[i].nunchuk_pitch_scale = FL(1.0);
      wiirange[i].nunchuk_roll_min   = -FL(90.0);
      wiirange[i].nunchuk_roll_scale = FL(1.0);
      wiiuse_status(wiimotes[i]);
      wiiuse_motion_sensing(wiimotes[i], 1);
    }
    p->wii = wiimotes;
    p->max_wiimotes = n;
    *p->res = FL(1.0);
    return OK;
}
bool CryVR_WiimoteManagerPlugin::SetMotionSensing( int id, bool value )
{
    if ( init )
    {
        if ( id < found && id >= 0 )
        {
            if ( value )
            {
                wiiuse_motion_sensing( wiimotes[id], 1 );
            }

            else
            {
                wiiuse_motion_sensing( wiimotes[id], 0 );
            }

            return true;
        }
    }

    return false;
}
Example #6
0
void find_wiimote(GtkWidget *widget, gpointer user_data)
{
	wiimotes = wiiuse_init(2);
	found = wiiuse_find(wiimotes, 2, 5); /* Find remotes (5s timeout) */
	if(found>0)
	{
		wiiuse_connect(wiimotes, found); /* Connect to as many wiimotes that were found */
	}
	else
	{
		printf("No wiimotes found\n");
		return;
	}
	printf("Found %d wiimote%s\n",found, (found!=1)?("s"):(""));
	
	wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1|WIIMOTE_LED_4);
	wiiuse_motion_sensing(wiimotes[0], 1);
	if(found>1)
	{
		wiiuse_set_leds(wiimotes[1], WIIMOTE_LED_2|WIIMOTE_LED_3);
		wiiuse_motion_sensing(wiimotes[1], 1);
	}
	g_thread_create((GThreadFunc)handle_hit, NULL, FALSE, NULL);
}
bool CryVR_WiimoteManagerPlugin::SetMotionSensing( bool value )
{
    if ( init && found > 0 )
    {
        int i = 0;
        int mot = 0;

        if ( value )
        {
            mot = 1;
        }

        for ( ; i < MAX_WIIMOTES; ++i )
        {
            wiiuse_motion_sensing( wiimotes[i], mot );
        }

        return true;
    }

    return false;
}
Example #8
0
void vrpn_WiiMote::initialize_wiimote_state(void)
{
    if ( !wiimote->device || !wiimote->found || !wiimote->connected) {
        return;
    }

    // Turn on a light so we know which device we are.
    switch (wiimote->which) {
    case 0:
        wiiuse_set_leds(wiimote->device, WIIMOTE_LED_1);
        break;
    case 1:
        wiiuse_set_leds(wiimote->device, WIIMOTE_LED_2);
        break;
    case 2:
        wiiuse_set_leds(wiimote->device, WIIMOTE_LED_3);
        break;
    case 3:
        wiiuse_set_leds(wiimote->device, WIIMOTE_LED_4);
        break;
    default:
        struct timeval now;
        vrpn_gettimeofday(&now, NULL);
        char msg[1024];
        sprintf(msg, "Too-large remote %d (0-3 available)", wiimote->which);
        send_text_message(msg, now, vrpn_TEXT_ERROR);
        break;
    }

    // Ask to look for motion sensing
    wiiuse_motion_sensing(wiimote->device, 1);

    // Turn off rumbling
    wiiuse_rumble(wiimote->device, 0);

    // Turn on IR sensing
    wiiuse_set_ir(wiimote->device, 1);
}
Example #9
0
void triple_buffer(BITMAP **page) {
	int i = 0, w, repeat, active_page = 0;
	int time_diff, bar_number, *used_voices = NULL, hw_voices;
	int text_bar_height, half_bar_size;
	unsigned int radius;
	
	coord_t dot[2], dot_old[2], cal[2], cal_tmp[2];
	
	wiimote *wiimote;
	
	char *fonts[NUM_MAX_FONTS] = FONTS;
	FONT *font_msg, *font_notes;
	BITMAP *background;
	bars *bar;
	
	/* dot_old data initialization. dot_old's X coord is not used */
	dot_old[0].y = SCREEN_H;
	dot_old[1].y = SCREEN_H;
	
	/* Wiimote initialization*/
	wiimote = *wiiuse_init(1);
	
	/* Load fonts, size of font is related to SCREEN_W */
	do {
		font_msg = load_font(fonts[i], NULL, NULL);
		__ASSERT(font_msg, ERROR_CANT_LOAD_FONT(fonts[i]));
		w = text_length(font_msg, WIIMOTE_CONNECTION_MSG);
	} while (w >= SCREEN_W && ++i < (NUM_MAX_FONTS-1));
	
	/* Notes' font is smaller than messages' font */
	font_notes = load_font(fonts[i], NULL, NULL);
	__ASSERT(font_notes, ERROR_CANT_LOAD_FONT(fonts[i]));
	
	/* Initialize and calculate bars size, point radius, text bar height, and calculate half bar size for text output under bars */
	bar = bar_create(NUM_BARS);
	radius = RADIUS(bar);
	text_bar_height = TEXT_BAR_HEIGHT;
	half_bar_size = HALF_BAR_SIZE(bar);
	
	/* Control the max number of available hardware voices. Though ALSA driver voices are up to 64, max hardware voices generally are 8-16. Checking the allocated voices after the driver allocation seems to be the only way */
	hw_voices = get_mixer_voices();
	if (hw_voices < NUM_BARS)
		used_voices = reallocate_voices(bar, hw_voices);
	
	/* Install timer, 10 ticks a second */
	LOCK_VARIABLE(timer);
	LOCK_FUNCTION(inc_timer);
	install_int_ex(inc_timer, BPS_TO_TIMER(10));
	
	/* Load background from file */
	background = load_tga("images/back.tga", NULL);
	__ASSERT(background, ERROR_CANT_LOAD_IMAGE("back.tga"));
	
	/* Enables vertical syncronization*/
	vsync();
	
	i = 0;
	/* First frame, this lasts until wiimote is connected, the user is prompted to activate the wiimote by pressing 1 & 2 keys on the wiimote */
	while(i == 0 && !keypressed()) {
		active_page = start_credits3buf(page, active_page);
		
		clear_keybuf();
		
		title3buf(page, active_page, font_msg);
		
		clear_keybuf();
		
		repeat = 0;
		while(repeat++ < 8 && i == 0 && !keypressed()) {
			stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H); // background
			if(repeat%2 == 1)
				textout_centre_ex(page[active_page], font_msg, WIIMOTE_CONNECTION_MSG, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt
			
			release_bitmap(page[active_page]);
			/* make sure the last flip request has actually happened */
			do {
			} while (poll_scroll());
			
			/* post a request to display the page we just drew */
			request_video_bitmap(page[active_page]);

			/* update counters to point to the next page */
			switch (active_page) {
				case 0: active_page = 1; break;
				case 1: active_page = 2; break;
				case 2: active_page = 0; break;
			}

			/* Search for a wiimote */
			i = wiiuse_find(&wiimote, 1, 1);
		}
	}
	
	/* Try to connect to the wiimote */
	__ASSERT(wiiuse_connect(&wiimote, 1) > 0, ERROR_CANT_OPEN_WIIMOTE);
	
	/* Activate the first led on the wiimote */
	wiiuse_set_leds(wiimote, WIIMOTE_LED_1);
	
	/* Activate the ir module on the wiimote */
	wiiuse_set_ir(wiimote, TRUE);
	
	wiiuse_motion_sensing(wiimote, FALSE);
	
	wiiuse_set_ir_sensitivity(wiimote, 1);
	wiiuse_set_flags(wiimote, WIIUSE_CONTINUOUS, 0);
	
	cal[0].x = 0;
	cal[0].y = 0;
	cal[1].x = 1023;
	cal[1].y = 767;
	
	/* CALIBRATION LOOP */
	for(repeat=0;repeat<2;repeat++) {
		clear_keybuf();
		
		while(!keypressed()) {
			if (wiiuse_poll(&wiimote, 1)) // if there are datas pending from/to wiimote or ESC is pressed
				if (key[KEY_ESC] || wiimote->event == WIIUSE_DISCONNECT || wiimote->event == WIIUSE_UNEXPECTED_DISCONNECT || IS_PRESSED(wiimote, WIIMOTE_BUTTON_HOME)) { // if ESC is pressed, if wiimote update fails, or if HOME key on wiimote is pressed
				wiiuse_disconnect(wiimote);
				destroy_bitmap(background);
				destroy_font(font_msg);
				destroy_font(font_notes);
				for (i=0;i<NUM_BARS;i++) {
					deallocate_voice(bar[i].voice);
					destroy_sample(bar[i].sound);
				}
				free(bar); // YO!! :-)
				free(used_voices);
				
				return;
				}
			/* background */
			stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H);
			
			if (wiimote->ir.dot[0].visible) { // if ir source is visible
				/* Read coords from the wiimote's ir*/
				dot[0] = transpose(wiimote->ir.dot[0], cal, 0);
			}
			
			switch(repeat) {
				case 0:
					textout_centre_ex(page[active_page], font_msg, WIIMOTE_CAL_ASX, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt
					rect(page[active_page], dot[0].x, dot[0].y, SCREEN_W+1, SCREEN_H+1, makecol(0, 0, 0));
					break;
				case 1:
					textout_centre_ex(page[active_page], font_msg, WIIMOTE_CAL_BDX, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), -1); // text prompt
					
					rect(page[active_page], dot[1].x, dot[1].y, SCREEN_W+1, SCREEN_H+1, makecol(0, 0, 0));
					rect(page[active_page], -1, -1, dot[0].x, dot[0].y, makecol(0, 0, 0));
					break;
			}
			circlefill(page[active_page], dot[0].x, dot[0].y, radius, makecol(0, 0, 0));

			release_bitmap(page[active_page]);
			
			/* make sure the last flip request has actually happened */
			do {
			} while (poll_scroll());

			/* post a request to display the page we just drew */
			request_video_bitmap(page[active_page]);

			/* update counters to point to the next page */
			switch (active_page) {
				case 0: active_page = 1; break;
				case 1: active_page = 2; break;
				case 2: active_page = 0; break;
			}
		}
		
		cal_tmp[repeat].x = wiimote->ir.dot[0].x;
		cal_tmp[repeat].y = wiimote->ir.dot[0].y;
		dot[1] = dot[0];
	}
	
	__ASSERT((cal_tmp[0].x < cal_tmp[1].x && cal_tmp[0].y > cal_tmp[1].y), ERROR_WHILE_CALIBRATING);
	
	cal[0].x = cal_tmp[0].x;
	cal[0].y = 767-cal_tmp[0].y;
	cal[1].x = cal_tmp[1].x;
	cal[1].y = 767-cal_tmp[1].y;
	
	/* MAIN LOOP */
	while (TRUE) {
		/* Draw a frame */
		if (wiiuse_poll(&wiimote, 1) || key[KEY_ESC]) // if there are datas pending from/to wiimote or ESC is pressed
			if (key[KEY_ESC] || wiimote->event == WIIUSE_DISCONNECT || wiimote->event == WIIUSE_UNEXPECTED_DISCONNECT || IS_PRESSED(wiimote, WIIMOTE_BUTTON_HOME)) { // if ESC is pressed, if wiimote update fails, or if HOME key on wiimote is pressed
				wiiuse_disconnect(wiimote);
				destroy_bitmap(background);
				destroy_font(font_msg);
				destroy_font(font_notes);
				for (i=0;i<NUM_BARS;i++) {
					deallocate_voice(bar[i].voice);
					destroy_sample(bar[i].sound);
				}
				free(bar); // YO!! :-)
				free(used_voices);
				
				return;
			}
		
		/* background */
		stretch_blit(background, page[active_page], 0, 0, background->w, background->h, 0, 0, SCREEN_W, SCREEN_H);
		
		/* Xylophone's bars and notes names */
		for(i=0;i<NUM_BARS;i++) {
			if (bar[i].t_start != -1 && (time_diff = timer-bar[i].t_start) > TICKS_TO_BLACK) // if color animation ends
				bar[i].t_start = -1;
			if (bar[i].t_start == -1) // if no color animation
				bar[i].color = 0;
			else	bar[i].color = COLORVAL(time_diff); // if color animation is running
			
			/* Draw bar */
			rectfill(page[active_page], bar[i].min.x, bar[i].min.y, bar[i].max.x, bar[i].max.y, makecol(bar[i].color, bar[i].color, bar[i].color));
			/* Print bar's associated note */
			textout_centre_ex(page[active_page], font_notes, bar[i].note, (bar[i].min.x + half_bar_size), text_bar_height, makecol(0, 0, 0), -1);
		}
		
		// da normalizzare e da contenere nello schermo, ir
		for(i=0;i<MAX_IR_DOTS;i++) {
			if (wiimote->ir.dot[i].visible) { // if ir source is visible
				/* Read coords from the wiimote's ir*/
				dot[i] = transpose(wiimote->ir.dot[i], cal, radius);
				
				/* If the ir source is under the bars and in previous frame it was above the bars, then play the sound and start the animation */
				if (dot[i].y > bar[0].min.y-radius) {
					if(dot_old[i].y <= bar[0].min.y-radius) {
						/* This calculates on which bar the ir source actually is */
						bar_number = is_onbar(bar, dot[i].x, NUM_BARS);
						
						/* play bar_number's sound with specified volume */
						play_bar_voice(bar, bar_number, volume(dot[i].y-dot_old[i].y), used_voices, hw_voices);
					}
					
					/* The dot have not to go under the bars or out of the screen */
					circlefill(page[active_page], dot[i].x, bar[0].min.y-radius, radius, makecol(0, 0, 0));
				}
				else	circlefill(page[active_page], dot[i].x, dot[i].y, radius, makecol(0, 0, 0));
				
				dot_old[i].y = dot[i].y;
			}
			else dot_old[i].y = SCREEN_H;
		}

		release_bitmap(page[active_page]);

		/* make sure the last flip request has actually happened */
		do {
		} while (poll_scroll());

		/* post a request to display the page we just drew */
		request_video_bitmap(page[active_page]);

		/* update counters to point to the next page */
		switch (active_page) {
			case 0: active_page = 1; break;
			case 1: active_page = 2; break;
			case 2: active_page = 0; break;
		}
	}
}
Example #10
0
/**
 * Deactivate Motion Sensing for the wiimote with the given id.
 * @param id the id of the wiimote.Must be 1 or 2.
 */
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateMotionSensing
(JNIEnv *env, jobject obj, jint id) {
	wiiuse_motion_sensing(wiimotes[id-1], 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) {
	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);
	}
	
}
void controllerClass::calibrate()
{

  Sint16 x=0;
  if(SDL_JoystickOpened(0))
  {

    x = SDL_JoystickGetAxis(joystick, 0);

    if(SDL_JoystickGetButton(joystick, 0))
    {
      if(!joyBtnALock && var.menuJoyCalStage != 5)
      {
        var.menuJoyCalStage++;
        joyBtnALock=1;
      }
    } else {
      joyBtnALock=0;
    }
  }

  switch(var.menuJoyCalStage)
  {
    case 0:
      calMin=0;
      calMax=0;
      calLowJitter=0;
      calHighJitter=0;
    break;
    case 1:
      if(x < calLowJitter)
        calLowJitter=x;
      else if(x > calHighJitter)
        calHighJitter=x;
    break;
    case 2:
      if(x < calMin)
        calMin=x;
    break;
    case 3:
      if(x > calMax)
        calMax=x;
    break;
    case 4:
      setting.JoyCalMin=calMin;
      setting.JoyCalMax=calMax;
      setting.JoyCalLowJitter=calLowJitter;
      setting.JoyCalHighJitter=calHighJitter;
      cout << "Joystick calibration report:" << endl;
      cout << "calMin: " << calMin << endl << "calMax: " << calMax << endl;
      cout << "lowJit: " << calLowJitter << endl << "higJit: " << calHighJitter << endl;
      var.menuJoyCalStage++;
      writeSettings();
    break;
    #ifdef WITH_WIIUSE
    case -1: //We do this to make it draw a frame before freezing (searching)
      var.menuJoyCalStage--;
    break;
    case -2:
      wiimotes =  wiiuse_init(MAX_WIIMOTES);
      if(wiiuse_find(wiimotes, MAX_WIIMOTES, 4))
      {
        var.wiiConnect=1;
      } else {
        var.wiiConnect=0;
      }
      if(var.wiiConnect)
      {
        var.wiiConnect=0;
        if(wiiuse_connect(wiimotes, MAX_WIIMOTES))
        {
          var.wiiConnect=1;
          wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1);
          wiiuse_rumble(wiimotes[0], 1);
          usleep(500000);
          wiiuse_rumble(wiimotes[0], 0);
          wiiuse_motion_sensing(wiimotes[0], 1);
        }
        var.menuJoyCalStage=-3;
      } else {
        var.menuJoyCalStage=-4;
      }
    break;
    #endif
  }
}
Example #13
0
static u32 WII_Run(void *par)
{
	GF_BitStream *bs;
	char *buf;
	u32 i, buf_size, count, scan_delay;
	const char *opt;

	GF_InputSensorDevice *ifce = (GF_InputSensorDevice *)par;
	GF_WiiMote *wii = (GF_WiiMote *)ifce->udta;


	scan_delay = 5;
	opt = gf_modules_get_option((GF_BaseInterface*)ifce, "WII", "ScanDelay");
	if (opt) scan_delay = atoi(opt);

	/*locate the wiimotes*/
	count = wiiuse_find(wii->wiimotes, wii->nb_wiimotes, scan_delay); 
	GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[Wii] Found %d wiimotes\n", count));
	count = wiiuse_connect(wii->wiimotes, wii->nb_wiimotes);
	if (count) {
		GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[Wii] Connected to %d connected wiimotes\n", count));
	} else {
		GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[Wii] Failed to connect to any wiimote\n"));
	}

	opt = gf_modules_get_option((GF_BaseInterface*)ifce, "WII", "MotionSensing");
	/*enable motion sensing*/
	if (!opt || !strcmp(opt, "yes")) {
		Float smooth_alpha = 0.5;
		Float ori_threshold = 10.0;
		opt = gf_modules_get_option((GF_BaseInterface*)ifce, "WII", "OrientationThreshold");
		if (opt) ori_threshold = (Float) atof(opt);
		opt = gf_modules_get_option((GF_BaseInterface*)ifce, "WII", "SmoothAlpha");
		if (opt) {
			smooth_alpha = (Float) atof(opt);
			if (smooth_alpha<0) smooth_alpha = 0.5;
			else if (smooth_alpha>1.0) smooth_alpha=0.5;
		}
		GF_LOG(GF_LOG_INFO, GF_LOG_MMIO, ("[Wii] Enabling motion sensing - Alpha smoothing %f - Orientation Threshold %f\n", smooth_alpha, ori_threshold));

		for (i=0; i<count; i++) {
			wiiuse_motion_sensing(wii->wiimotes[i], 1);
			wiiuse_set_smooth_alpha(wii->wiimotes[i],smooth_alpha);
			wiiuse_set_orient_threshold(wii->wiimotes[i], ori_threshold);
		}
	}

	while (wii->running) { 
		count = wiiuse_poll(wii->wiimotes, wii->nb_wiimotes);
		if (!count) {
			continue;
		}
		for (i=0; i<count; i++) {
			struct wiimote_t* wm = wii->wiimotes[i];
			switch (wm->event) { 
			case WIIUSE_EVENT:/* A generic event occured on the wiimote. */
				/*create the data frame*/
				bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);
				/*if not the same wiimote write the UID*/
				if (wii->prev_id != wm->unid) {
					gf_bs_write_int(bs, 1, 1); 
					gf_bs_write_int(bs,  wm->unid, 32); 
					wii->prev_id = wm->unid;
				} else {
					gf_bs_write_int(bs, 0, 1); 
				}

				/*write buttons state*/
				WRITE_BUTTON(WIIMOTE_BUTTON_ONE);
				WRITE_BUTTON(WIIMOTE_BUTTON_TWO);
				WRITE_BUTTON(WIIMOTE_BUTTON_A);
				WRITE_BUTTON(WIIMOTE_BUTTON_B);
				WRITE_BUTTON(WIIMOTE_BUTTON_MINUS);
				WRITE_BUTTON(WIIMOTE_BUTTON_HOME);
				WRITE_BUTTON(WIIMOTE_BUTTON_PLUS);
				WRITE_BUTTON(WIIMOTE_BUTTON_LEFT);
				WRITE_BUTTON(WIIMOTE_BUTTON_RIGHT);
				WRITE_BUTTON(WIIMOTE_BUTTON_DOWN);
				WRITE_BUTTON(WIIMOTE_BUTTON_UP);

				/*write yaw-pitch-roll - FIXME: wiiuse seems to output NaN in these values upon init*/
				gf_bs_write_int(bs, 1, 1); 
				gf_bs_write_float(bs, WII_PI * wm->orient.yaw / 24 );
				gf_bs_write_float(bs, WII_PI * wm->orient.pitch / 180);
				gf_bs_write_float(bs, WII_PI * wm->orient.roll / 180);

				/*write gravity - FIXME: wiiuse seems to output NaN in these values upon init*/
				gf_bs_write_int(bs, 1, 1); 
				gf_bs_write_float(bs, wm->gforce.x);
				gf_bs_write_float(bs, wm->gforce.y);
				gf_bs_write_float(bs, wm->gforce.z);

				gf_bs_align(bs);
				gf_bs_get_content(bs, &buf, &buf_size);
				gf_bs_del(bs);

				ifce->DispatchFrame(ifce, buf, buf_size);
				gf_free(buf);
				break;
			case WIIUSE_STATUS: /*A status report was obtained from the wiimote. */
				break;
			case WIIUSE_DISCONNECT:/*The wiimote disconnected. */
				break;
			case WIIUSE_READ_DATA:/* Data was returned that was previously requested from the wiimote ROM/registers. */
				break;
			case WIIUSE_NUNCHUK_INSERTED: 
			case WIIUSE_NUNCHUK_REMOVED:
			case  WIIUSE_CLASSIC_CTRL_INSERTED: 
			case WIIUSE_CLASSIC_CTRL_REMOVED:
			case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
			case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
				break;
			}
		}
	} 
	return 0;
}
Example #14
0
/**
 *	@brief main()
 *
 *	Connect to up to two wiimotes and print any events
 *	that occur on either device.
 */
ControlResult TickRemote()
{
   // If not connected then attempt to connect
   if (sControlMode == ControlMode::Off)
   {
      sResult.steering_demand.x = 0;
      sResult.steering_demand.y = 0;
      sResult.steering_demand.z = 0;
      sResult.fire = false;
      sResult.exit = false;

      int found = wiiuse_find(sWiimotes, 1, 5);
      
      if (found > 0)
      {
         int connected = wiiuse_connect(sWiimotes, 1);
         if (connected > 0)
         {
            change_control_mode(ControlMode::Slaved);
            wiiuse_set_leds(sWiimotes[0], WIIMOTE_LED_1);
            wiiuse_motion_sensing(sWiimotes[0], 0);
            usleep(100000);
            wiiuse_set_ir(sWiimotes[0], 1);
            wiiuse_set_ir_sensitivity(sWiimotes[0], 3);
         }
      }
   }

   bool first = true;
   while (sControlMode != ControlMode::Off &&
          wiiuse_poll(sWiimotes, 1)) // Returns number of events to be processed
   {
      if (first)
      {
         first = false;
         sResult.steering_demand.x = 0;
         sResult.steering_demand.y = 0;
         sResult.steering_demand.z = 0;
         sResult.fire = false;
         sResult.exit = false;
      }

      switch (sWiimotes[0]->event) {
         case WIIUSE_EVENT:
            /* a generic event occured */
            handle_event(sWiimotes[0]);
            break;

         case WIIUSE_DISCONNECT:
         case WIIUSE_UNEXPECTED_DISCONNECT:
            /* the wiimote disconnected */
            wiiuse_disconnected(sWiimotes[0]);
            change_control_mode(ControlMode::Off);
            break;

         default:
            break;
      }
   }

   clock_t current_time = clock();
   if (sControlMode == ControlMode::Seeking)
   {
      if (current_time > sTrackAge + 0.25 * CLOCKS_PER_SEC && sTrackValid)
      {
         sResult.steering_demand.x = 0;
         sResult.steering_demand.y = 0;
         sTrackValid = false;
         Log("Lost track\n"); 
      }

      if (current_time > sTrackAge + 1 * CLOCKS_PER_SEC)
      {
         change_control_mode(ControlMode::Searching);
         sSearchDirectionChangeTime = current_time + 2 * CLOCKS_PER_SEC;
         sSearchDirection = 1;
      }
   }

   if (sControlMode == ControlMode::Searching)
   {
      if (current_time > sSearchDirectionChangeTime)
      {
         sSearchDirectionChangeTime = current_time + 2 * CLOCKS_PER_SEC;
         Log("Turning\n"); 
         sSearchDirection *= -1;
      }
      sResult.steering_demand.x = sSearchDirection;
      sResult.steering_demand.y = 0;
      sResult.steering_demand.z = -1;

   } 
   
   return sResult;
}
Example #15
0
	virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
	{
		int found =-1;
		int connected;
		
		
		switch (event)
		{
		case eFE_Initialize:{
			//Sleep(3000);
			wiimotes = wiiuse_init(1); 
			found = wiiuse_find(wiimotes, 1, 5);
			if (found!=0) handle_ctrl_status(wiimotes[0]);

			connected = wiiuse_connect(wiimotes, 1);
			if (connected) CryLogAlways("Connected to %i wiimotes (of %i found).\n", connected, found);
			else CryLogAlways("Failed to connect to any wiimote.\n");
			wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1);
			
			wiiuse_motion_sensing(wiimotes[0], 1);
			wiiuse_set_ir(wiimotes[0], 1);

			//trop rapide !
			
		}
		case eFE_Activate:
			{	

				//Sleep(3000);

				//wiimotes = wiiuse_init(1); 
				//found = wiiuse_find(wiimotes, 1, 5);
				//if (found==0) CryLogAlways("No wiimotes found.\n");
				
				/*
				connected = wiiuse_connect(wiimotes, 1);
				if (connected) CryLogAlways("Connected to %i wiimotes (of %i found).\n", connected, found);
				else CryLogAlways("Failed to connect to any wiimote.\n");
				wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1);

				wiiuse_motion_sensing(wiimotes[0], 1);
				wiiuse_set_ir(wiimotes[0], 1);
				//WIIUSE_USING_EXP(wiimotes[0]);
				//WIIUSE_U

				//wiimotes[0]->exp.type = EXP_NUNCHUK;
				
				*/
				

				pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID,true);
			}
			break;
		
		case eFE_Update:
			{
				//int connected = wiiuse_connect(wiimotes, 1); 
				wiiuse_poll(wiimotes, 1);
				wiimote* wm =  wiimotes[0];
				//Ne change rien ! juste qu'on a un retour d'IR
				//handle_ctrl_status(wiimotes[0]);
				CryLogAlways("attachment:      %i",wm->exp.type);

				/*

				Gestion des evts

				*/

				
				
				// A commenter
				switch (wiimotes[0]->event) {
					case WIIUSE_EVENT:
						/* a generic event occured */
						handle_event(wiimotes[0]);
						break;

					case WIIUSE_STATUS:
						/* a status event occured */
						handle_ctrl_status(wiimotes[0]);
						break;

					case WIIUSE_DISCONNECT:
					case WIIUSE_UNEXPECTED_DISCONNECT:
						/* the wiimote disconnected */
						handle_disconnect(wiimotes[0]);
						break;

					case WIIUSE_READ_DATA:
						/*
						 *	Data we requested to read was returned.
						 *	Take a look at wiimotes[i]->read_req
						 *	for the data.
						 */
						break;

					case WIIUSE_NUNCHUK_INSERTED:
						/*
						 *	a nunchuk was inserted
						 *	This is a good place to set any nunchuk specific
						 *	threshold values.  By default they are the same
						 *	as the wiimote.
						 */
						//struct nunchuk_t* nc = (nunchuk_t*)&wiimotes[0]->exp.nunchuk;
						 wiiuse_set_nunchuk_orient_threshold(wiimotes[0], 90.0f);
						 wiiuse_set_nunchuk_accel_threshold(wiimotes[0], 100);
						CryLogAlways("Nunchuk inserted.\n");
						break;

					case WIIUSE_CLASSIC_CTRL_INSERTED:
						CryLogAlways("Classic controller inserted.\n");
						break;

					case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
						/* some expansion was inserted */
						handle_ctrl_status(wiimotes[0]);
						//printf("Guitar Hero 3 controller inserted.\n");
						break;

					case WIIUSE_NUNCHUK_REMOVED:
					case WIIUSE_CLASSIC_CTRL_REMOVED:
					case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
						/* some expansion was removed */
						handle_ctrl_status(wiimotes[0]);
						//printf("An expansion was removed.\n");
						break;

					default:
						break;
				}














				
					//if (wiiuse_poll(wiimotes, 1)) {
						//int i = 0;
				
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_A))			ActivateOutput(pActInfo, WIIMOTE_A,true); else ActivateOutput(pActInfo, WIIMOTE_A,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_B))			ActivateOutput(pActInfo, WIIMOTE_B,true); else ActivateOutput(pActInfo, WIIMOTE_B,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_UP))			ActivateOutput(pActInfo, WIIMOTE_UP,true); else ActivateOutput(pActInfo, WIIMOTE_UP,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_DOWN))		ActivateOutput(pActInfo, WIIMOTE_DOWN,true); else ActivateOutput(pActInfo, WIIMOTE_DOWN,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_LEFT))		ActivateOutput(pActInfo, WIIMOTE_LEFT,true); else ActivateOutput(pActInfo, WIIMOTE_LEFT,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_RIGHT))		ActivateOutput(pActInfo, WIIMOTE_RIGHT,true); else ActivateOutput(pActInfo, WIIMOTE_RIGHT,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_MINUS))		ActivateOutput(pActInfo, WIIMOTE_MINUS,true); else ActivateOutput(pActInfo, WIIMOTE_MINUS,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_PLUS))		ActivateOutput(pActInfo, WIIMOTE_PLUS,true); else ActivateOutput(pActInfo, WIIMOTE_PLUS,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_ONE))		ActivateOutput(pActInfo, WIIMOTE_ONE,true); else ActivateOutput(pActInfo, WIIMOTE_ONE,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_TWO))		ActivateOutput(pActInfo, WIIMOTE_TWO,true); else ActivateOutput(pActInfo, WIIMOTE_TWO,false);
						if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_HOME))		ActivateOutput(pActInfo, WIIMOTE_HOME,true); else ActivateOutput(pActInfo, WIIMOTE_HOME,false);

						if (WIIUSE_USING_ACC(wiimotes[0])) {
							Vec3 output = Vec3(wiimotes[0]->orient.roll,wiimotes[0]->orient.pitch,wiimotes[0]->orient.yaw);
							ActivateOutput(pActInfo, WIIMOTE_RPY,output);
						}
						if (WIIUSE_USING_IR(wiimotes[0])) {
							Vec3 output = Vec3((float)wiimotes[0]->ir.x,(float)wiimotes[0]->ir.y,(float)wiimotes[0]->ir.z);
							ActivateOutput(pActInfo, WIIMOTE_IR,output);
						}
						/* nunchuk */
						//Toujours faux !
						
						if (wm->exp.type == EXP_NUNCHUK) {
							
							//nunchuk_t* pt =  wm->exp.nunchuk;
						//REssort 0 a chaque fois !!!!
							struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk;
							CryLogAlways("nun gravity x EXPANSION : %f",nc->gforce.x);
							if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) ActivateOutput(pActInfo, NUNCHUK_C,true); else ActivateOutput(pActInfo, NUNCHUK_C,false);
							if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) ActivateOutput(pActInfo, NUNCHUK_Z,true); else ActivateOutput(pActInfo, NUNCHUK_Z,false);
							
							Vec3 output = Vec3(nc->orient.a_roll,nc->orient.a_pitch,nc->orient.yaw);
							ActivateOutput(pActInfo, NUNCHUK_RPY,output);
							
							Vec3 output2 = Vec3(nc->js.ang,nc->js.mag,0);
							ActivateOutput(pActInfo, NUNCHUK_JOYSTICK,output2);
						} 


						/*
						switch (wiimotes[0]->event) {
							//case WIIUSE_EVENT:
								//{
								//}
								//break;

							case WIIUSE_STATUS:
								handle_ctrl_status(wiimotes[0]);
								break;

							case WIIUSE_DISCONNECT:
							case WIIUSE_UNEXPECTED_DISCONNECT:
								handle_disconnect(wiimotes[0]);
								break;
								
							default:
								break;
						}
						*/
					//}
				//}
			}
				
		}
	}
Example #16
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 #17
0
void Wiimote::motionSensing(int status){
    wiiuse_motion_sensing(this->wm, status);
}
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;
}
	virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
	{
		
		
		
		switch (event)
		{
		case eFE_Initialize: 
			//Sleep(5000);
			break;
		case eFE_Activate:
			{	
				//Sleep(3000); // <-- Dernière chose ajoutée
				wiimotes = wiiuse_init(MAX_WIIMOTES); 
				found = wiiuse_find(wiimotes,  MAX_WIIMOTES, 5);
				//if (found!=0) 
					//handle_ctrl_status(wiimotes[0]);

				connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
				if (connected) {

					CryLogAlways("Connected to %i wiimotes (of %i found).\n", connected, found);
				}
				else CryLogAlways("Failed to connect to any wiimote.\n");
				wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_2);
			
				wiiuse_motion_sensing(wiimotes[0], 1);
				//wiiuse_set_ir(wiimotes[0], 1);
				pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID,true);
				//break; // <-- Dernière chose commentée !
			}
		
		case eFE_Update:
			{
				//CryLogAlways("Update !");
				if(GetPortBool(pActInfo, 0)){
					wiimotes = wiiuse_init(MAX_WIIMOTES); 
					connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
				}
				
		
				if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) {
					/*
					 *	This happens if something happened on any wiimote.
					 *	So go through each one and check if anything happened.
					 */
					int i = 0;
					for (; i < MAX_WIIMOTES; ++i) {
						CryLogAlways("attachment:  wiimote :%i  attachement : %i",i,wiimotes[i]->exp.type);

						switch (wiimotes[i]->event) {
							case WIIUSE_EVENT:
								/* a generic event occured */
								CryLogAlways("Generic event");
								handle_event(wiimotes[i]);
								break;
							case WIIUSE_CONNECT:
								CryLogAlways("Connexion");
								break;
							case WIIUSE_STATUS:
								/* a status event occured */
								CryLogAlways("Demande de status");
								handle_ctrl_status(wiimotes[i]);
								break;

							case WIIUSE_DISCONNECT:
							case WIIUSE_UNEXPECTED_DISCONNECT:
								/* the wiimote disconnected */
								CryLogAlways("Deconnexion");
								handle_disconnect(wiimotes[i]);
								break;

							case WIIUSE_READ_DATA:
								/*
								 *	Data we requested to read was returned.
								 *	Take a look at wiimotes[i]->read_req
								 *	for the data.
								 */
								break;

							case WIIUSE_NUNCHUK_INSERTED:
								/*
								 *	a nunchuk was inserted
								 *	This is a good place to set any nunchuk specific
								 *	threshold values.  By default they are the same
								 *	as the wiimote.
								 */
								 //wiiuse_set_nunchuk_orient_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 90.0f);
								 //wiiuse_set_nunchuk_accel_threshold((struct nunchuk_t*)&wiimotes[i]->exp.nunchuk, 100);
								handle_ctrl_status(wiimotes[i]);
								printf("Nunchuk inserted.\n");
								break;

							case WIIUSE_CLASSIC_CTRL_INSERTED:
								handle_ctrl_status(wiimotes[i]);
								printf("Classic controller inserted.\n");
								break;

							case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
								/* some expansion was inserted */
								handle_ctrl_status(wiimotes[i]);
								printf("Guitar Hero 3 controller inserted.\n");
								break;

							case WIIUSE_NUNCHUK_REMOVED:
							case WIIUSE_CLASSIC_CTRL_REMOVED:
							case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
								/* some expansion was removed */
								handle_ctrl_status(wiimotes[i]);
								printf("An expansion was removed.\n");
								break;

							default:
								break;
						}
			
					}
				}
			}
			//catch(EXCEPINFO e){}
		}
		
		//}
	}
Example #20
0
/**
 * Deactivate Motion Sensing for the wiimote with the given id.
 * @param id the id of the wiimote.Must be 1 or 2.
 */
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateMotionSensing
(JNIEnv *env, jobject obj, jint id) {
	wiiuse_motion_sensing(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), 0);
}
Example #21
0
void IRThread::initialize()
{
    // wiiuse setup
    /*
    *	Initialize an array of wiimote objects.
    *
    *	The parameter is the number of wiimotes I want to create.
    */

    wiimotes =  wiiuse_init(MAX_WIIMOTES);

    /*
    *	Find wiimote devices
    *
    *	Now we need to find some wiimotes.
    *	Give the function the wiimote array we created, and tell it there
    *	are MAX_WIIMOTES wiimotes we are interested in.
    *
    *	Set the timeout to be 5 seconds.
    *
    *	This will return the number of actual wiimotes that are in discovery mode.
    */

    found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5);
    if (!found) {
            printf ("No wiimotes found.");
            exit(-1);
    }
    /*
    *	Connect to the wiimotes
    *
    *	Now that we found some wiimotes, connect to them.
    *	Give the function the wiimote array and the number
    *	of wiimote devices we found.
    *
    *	This will return the number of established connections to the found wiimotes.
    */

    isConnected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
    if (isConnected) {
            printf("isConnected to %i wiimotes (of %i found).\n", isConnected, found);
            emit connected();
    }
    else {
            printf("Failed to connect to any wiimote.\n");
            return;
    }

    /*
    *	Now set the LEDs and rumble for a second so it's easy
    *	to tell which wiimotes are connected (just like the wii does).
    */


    wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1);
    wiiuse_rumble(wiimotes[0], 1);

    #ifndef WIN32
            usleep(200000);
    #else
            Sleep(200);
    #endif

    wiiuse_rumble(wiimotes[0], 0);
    wiiuse_set_ir(wiimotes[0], 1);
    // enable motion sensing to get the IR point nonvisible transition events
    wiiuse_motion_sensing(wiimotes[0], 1);

    //wiiuse_set_ir_sensitivity(wiimotes[0], 2);

    for(int i = 0; i < 4; i++) {
        previousPoints[i].setX(0);
        previousPoints[i].setY(0);
        irpoints[i].setX(0);
        irpoints[i].setY(0);
    }

    previous[0] = false;
}
/**
 *	@brief Callback that handles an event.
 *
 *	@param wm		Pointer to a wiimote_t structure.
 *
 *	This function is called automatically by the wiiuse library when an
 *	event occurs on the specified wiimote.
 */
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);
	}
}
Example #23
0
File: sdl.c Project: 0xheart0/xbmc
int main(int argc, char** argv) {
#else
int WINAPI WinMain(HINSTANCE hInstance,	HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
#endif
	int found, connected;
	int wm;

	//printf("wiiuse version = %s\n", wiiuse_version());

	wiimotes =  wiiuse_init(MAX_WIIMOTES);
	found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5);
	if (!found)
		return 0;
	connected = wiiuse_connect(wiimotes, MAX_WIIMOTES);
	if (connected)
		printf("Connected to %i wiimotes (of %i found).\n", connected, found);
	else {
		printf("Failed to connect to any wiimote.\n");
		return 0;
	}
	wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1 | WIIMOTE_LED_4);
	wiiuse_set_leds(wiimotes[1], WIIMOTE_LED_2 | WIIMOTE_LED_4);
	wiiuse_rumble(wiimotes[0], 1);

	#ifndef WIN32
		usleep(200000);
	#else
		Sleep(200);
	#endif

	wiiuse_rumble(wiimotes[0], 0);

	/* enable IR and motion sensing for all wiimotes */
	for (wm = 0; wm < MAX_WIIMOTES; ++wm) {
		wiiuse_motion_sensing(wiimotes[wm], 1);
		wiiuse_set_ir(wiimotes[wm], 1);
	}

	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		printf("Failed to initialize SDL: %s\n", SDL_GetError());
		return 0;
	}

	SDL_WM_SetCaption("wiiuse SDL IR Example", "wiiuse SDL IR Example");

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);

	/* set window size */
	width = wiimotes[0]->ir.vres[0];
	height = wiimotes[0]->ir.vres[1];
	SDL_SetVideoMode(width, height, 16, SDL_RESIZABLE | SDL_OPENGL);

	for (wm = 0; wm < MAX_WIIMOTES; ++wm)
		wiiuse_set_ir_vres(wiimotes[wm], width, height);

	/* set OpenGL stuff */
	glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
	glEnable(GL_NORMALIZE);
	glEnable(GL_BLEND);

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDepthFunc(GL_LEQUAL);
    glClearColor(0, 0, 0, 0);

	/* set the size of the window */
	resize_window(width, height);

	display();

	#ifdef WIN32
		last_render = GetTickCount();
	#endif

	while (1) {
		SDL_Event event;

		if (SDL_PollEvent(&event)) {
			switch (event.type) {
				case SDL_VIDEORESIZE:
				{
					/* resize the window */
					resize_window(event.resize.w, event.resize.h);
					break;
				}
				case SDL_QUIT:
				{
					/* shutdown */
					SDL_Quit();
					wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
					return 0;
				}
				default:
				{
				}
			}
		}

		if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) {
			/*
			 *	This happens if something happened on any wiimote.
			 *	So go through each one and check if anything happened.
			 */
			int i = 0;
			for (; i < MAX_WIIMOTES; ++i) {
				switch (wiimotes[i]->event) {
					case WIIUSE_EVENT:
						/* a generic event occured */
						handle_event(wiimotes[i]);
						break;

					default:
						break;
				}
			}
		}

		display();
	}
}