コード例 #1
0
ファイル: bplate.c プロジェクト: ElFeesho/OldCProjects
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);
	}
}
コード例 #2
0
ファイル: irthread.cpp プロジェクト: abom/watchntouch
void IRThread::run()
{
    int visiblePointCount = 0;
    while(!isConnected)
        initialize();

    int poll_res = 0;
    while(1) {
        poll_res = wiiuse_poll(wiimotes, MAX_WIIMOTES);
        //qWarning() << "poll result" << poll_res;
        if (poll_res) {
            //qWarning() << "wii event: " << wiimotes[0]->event;
            if(wiimotes[0]->event == WIIUSE_EVENT) {
                if (WIIUSE_USING_IR(wiimotes[0])) {
                    int i = 0;
                    //count number of visible points
                    visiblePointCount = 0;
                    for(int i = 0; i < 4; i++) {
                        if(wiimotes[0]->ir.dot[i].visible) {
                            irpoints[i].setX(wiimotes[0]->ir.dot[i].rx);
                            irpoints[i].setY(wiimotes[0]->ir.dot[i].ry);
                            visiblePointCount++;
                        }
                        else {
                            //qWarning() << "else";
                            irpoints[i].setX(-1);
                            irpoints[i].setY(-1);
                        }
                    }
                    //qWarning() << "visible points:" << visiblePointCount;
                    // process ir dot #0
                    if (wiimotes[0]->ir.dot[0].visible) {
                        if(previous[0] == false) {
                            previous[0] = true;
                            emit IRInputReceived(irpoints,0,MOUSE_PRESSED,visiblePointCount);
                            copyPoints(irpoints,previousPoints);
                        }
                        else if(previous[0] == true) {
                            emit IRInputReceived(irpoints,0,MOUSE_MOVE,visiblePointCount);
                            copyPoints(irpoints,previousPoints);
                        }
                    }
                    else if(previous[0] == true) {
                        previous[0] = false;
                        //emit IRInputReceived(wiimotes[0]->ir.dot[0].rx, wiimotes[0]->ir.dot[0].ry,0,MOUSE_RELEASED,visiblePointCount);
                        //previousPoint = QPoint(wiimotes[0]->ir.dot[0].rx,wiimotes[0]->ir.dot[0].ry);
                        emit IRInputReceived(previousPoints, 0, MOUSE_RELEASED, visiblePointCount);
                    }
                    else if(previous[0] == false) {
                        // do nothing
                    }
                }
            }
        }
    }

    exec();
}
コード例 #3
0
        virtual void ProcessEvent( EFlowEvent event, SActivationInfo* pActInfo )
        {

            if ( event == eFE_Initialize )
            {
                m_actInfo = *pActInfo;
                active = GetPortBool( pActInfo, 0 );
                pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, true );
            }

            if ( event == eFE_Activate )
            {
                active = GetPortBool( pActInfo, 0 );
            }

            if ( event == eFE_Update  && active )
            {

                int w_id = GetPortInt( pActInfo, 1 );

                if ( w_id < 0 || w_id >= CryVR_WiimoteManagerPlugin::found )
                {
                    return ;
                }


                int i = 0;
                wiimote** manettes =  CryVR_WiimoteManagerPlugin::GetWiimotes();

                //Optimisation v0.1
                wiimote_move = false;
                nunchuk_move = false;


                while ( wiiuse_poll( manettes, CryVR_WiimoteManagerPlugin::found ) && i < GetPortInt( pActInfo, 2 ) )
                {
                    if ( CryVR_WiimoteManagerPlugin::GetWiimotes( w_id )->event == WIIUSE_EVENT )
                    {
                        i++;
                        handle_event( CryVR_WiimoteManagerPlugin::GetWiimotes( w_id ) );
                    }

                    else if ( CryVR_WiimoteManagerPlugin::GetWiimotes( w_id )->event == WIIUSE_NUNCHUK_INSERTED || CryVR_WiimoteManagerPlugin::GetWiimotes( w_id )->event == WIIUSE_NUNCHUK_REMOVED )
                    {
                        CryVR_WiimoteManagerPlugin::Status( w_id );
                    }

                    //Recherche d'optimisation.
                    if ( nunchuk_move && wiimote_move && GetPortBool( pActInfo, 3 ) )
                    {

                        return ;
                    }

                }
            }
        }
コード例 #4
0
ファイル: wiiusej_WiiUseApi.c プロジェクト: RicoBoone/wiiusej
/**
 * Get status and values from the wiimotes and send it through callbacks.
 * @param wim the wiimote object to fill with the datas.
 */
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
(JNIEnv *env, jobject obj, jobject wim) {

	globalEnv = env;
	globalObj = obj;
	globalWim = wim;

	wiiuse_poll(wiimotes, 2);
}
コード例 #5
0
ファイル: wiimote_manager.cpp プロジェクト: Benau/stk-code
/** Thread update method - wiimotes state is updated in another thread to
 *  avoid latency problems */
void WiimoteManager::threadFunc()
{
#ifdef WIIMOTE_THREADING
    while(!m_shut)
#endif
    {
        if(wiiuse_poll(m_all_wiimote_handles, MAX_WIIMOTES))
        {
            for (unsigned int i=0; i < m_wiimotes.size(); ++i)
            {
                switch (m_all_wiimote_handles[i]->event)
                {
                case WIIUSE_EVENT:
                    m_wiimotes[i]->update();
                    //printf("DEBUG: wiimote event\n");
                    break;

                case WIIUSE_STATUS:
                    //printf("DEBUG: status event\n");
                    break;

                case WIIUSE_DISCONNECT:
                case WIIUSE_UNEXPECTED_DISCONNECT:
                    //printf("DEBUG: wiimote disconnected\n");
                    m_wiimotes[i]->setConnected(false);
                    break;

                case WIIUSE_READ_DATA:
                    //printf("DEBUG: WIIUSE_READ_DATA\n");
                    break;

                case WIIUSE_NUNCHUK_INSERTED:
                    //printf("DEBUG: Nunchuk inserted.\n");
                    break;

                case WIIUSE_CLASSIC_CTRL_INSERTED:
                    //printf("DEBUG: Classic controller inserted.\n");
                    break;

                case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
                    //printf("DEBUG: Guitar Hero 3 controller inserted.\n");
                    break;

                case WIIUSE_NUNCHUK_REMOVED:
                case WIIUSE_CLASSIC_CTRL_REMOVED:
                case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
                    //printf("DEBUG: An expansion was removed.\n");
                    break;
                default:
                    break;
                }
            }
        }

        StkTime::sleep(1);  // 'cause come on, the whole CPU is not ours :)
    } // end while
}   // threadFunc
コード例 #6
0
	virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
	{

		if(event==eFE_Initialize) {
			m_actInfo = *pActInfo;
			return ;
		}

		if(event==eFE_Activate){
			CryLogAlways(" *** GuitarHero Controler beta version *** ");
			active = GetPortBool(pActInfo, 0);
			
			pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID,true);
			return ;
		}

		if(event== eFE_Update) 
			{
				gh3_move = false;
				int i = 0;
				int w_id = GetPortInt(pActInfo, 1);
				if(!active || w_id < 0 || w_id >= CryVR_WiimoteManager::found) return ;

				
				
				if(CryVR_WiimoteManager::GetMotionSensing(w_id) && CryVR_WiimoteManager::GetWiimotes(w_id)->exp.type == 0){
					was_motion_sensing_active = true;
					CryLogAlways(" *** GuitarHero Controler force Motion Sensing off during connection *** ");
					CryVR_WiimoteManager::SetMotionSensing(w_id,false);
				}

				if(CryVR_WiimoteManager::GetWiimotes(w_id)->exp.type == EXP_CLASSIC && was_motion_sensing_active){
					CryLogAlways(" *** GuitarHero set Motion Sensing previous state *** ");
					//CryVR_WiimoteManager::SetMotionSensing(w_id,true);
					was_motion_sensing_active = false;
					CryVR_WiimoteManager::Status(CryVR_WiimoteManager::GetWiimotes(w_id));
				}
				
				
				/* fait planter la balance board ! */

				while (wiiuse_poll(CryVR_WiimoteManager::GetWiimotes(), CryVR_WiimoteManager::found) && i<GetPortInt(pActInfo, 2)) 
					{	
						if(CryVR_WiimoteManager::GetWiimotes(w_id)->event == WIIUSE_EVENT) {
							handle_event(CryVR_WiimoteManager::GetWiimotes(w_id));
						}

						//Recherche d'optimisation.
						if (GetPortBool(pActInfo, 3)) {
							return ; 
						}
						i++;
					}
			}
	}
コード例 #7
0
ファイル: wiimote.c プロジェクト: csound/csound
int32_t wiimote_poll(CSOUND *csound, WIIMOTE *p)
{
    wiimote **wiimotes = p->wii;
    int32_t i;
    int32_t max_wiimotes = p->max_wiimotes;

    wiiuse_poll(wiimotes, max_wiimotes);
    for (i=0; i < max_wiimotes; ++i) {
      switch (wiimotes[i]->event) {
      case WIIUSE_EVENT:
      case WIIUSE_STATUS:
      case WIIUSE_READ_DATA:
        break;
      case WIIUSE_DISCONNECT:
      case WIIUSE_UNEXPECTED_DISCONNECT:
        /* the wiimote disconnected */
        csound->Warning(csound,
                        Str("wiimote %i disconnected\n"), wiimotes[i]->unid);
        *p->res = FL(0.0);
        return OK;
      case WIIUSE_NUNCHUK_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); */
        csound->Warning(csound, "%s", Str("Nunchuk inserted.\n"));
        break;
      case WIIUSE_NUNCHUK_REMOVED:
        /* some expansion was removed */
        csound->Warning(csound, Str("Nunchuk for wiimote %i was removed.\n"), i);
        break;
      default:
        break;
      }
    }
    *p->res = FL(1.0);
    return OK;
}
コード例 #8
0
void CryVR_WiimoteManagerPlugin::ProcessEvent( EFlowEvent event, SActivationInfo* pActInfo )
{


    if ( event == eFE_Activate  && GetPortBool( pActInfo, 0 ) )
    {
        CryLogAlways( "Evenement init wiimote" );
        Init( GetPortBool( pActInfo, 1 ), GetPortBool( pActInfo, 1 ), GetPortInt( pActInfo, 2 ), GetPortFloat( pActInfo, 3 ), GetPortInt( pActInfo, 4 ), GetPortInt( pActInfo, 5 ), GetPortBool( pActInfo, 6 ), GetPortInt( pActInfo, 7 ) );

        //Sleep(1000);
        while ( wiiuse_poll( wiimotes, CryVR_WiimoteManagerPlugin::found ) )
        {
            CryLogAlways( "Initial Event" );
            Status( wiimotes[0] );
        }

        ActivateOutput( pActInfo, 0, true );
    }



}
コード例 #9
0
int main(int argc, char** argv) 
{
  long timeout = 0;
  bool connected = 0;
  wiimote** wiimotes;
  wiimotes =  wiiuse_init(MAX_WIIMOTES);
  CWiiController controller;
  wiimote* wm;
  {
  //Main Loop
  while (1)
    {
    if (!connected) connected = (connectWiimote(wiimotes));
    wm = wiimotes[0]; // Only worry about 1 controller. No need for more?
    controller.m_buttonDownTime = getTicks() - timeout;

//Handle ACC, Repeat, and IR outside of the Event loop so that buttons can be continuously sent
    if (timeout)
    {
      if ((controller.m_buttonDownTime > g_hold_button_timeout) && controller.m_holdableHeld)
        controller.handleACC(wm->orient.roll, wm->orient.pitch);
      if ((controller.m_buttonDownTime  > g_repeat_rate) && controller.m_repeatableHeld)
        controller.handleRepeat();
    }
    if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) 
    {
      for (int i = 0; i < MAX_WIIMOTES; ++i)
      //MAX_WIIMOTES hardcoded at 1.
      {
        switch (wiimotes[i]->event) 
        {
        case WIIUSE_EVENT:

	  controller.get_keys(wm);  //Load up the CWiiController
          controller.handleKeyPress();
          if (!controller.m_buttonHeld && (controller.m_holdableHeld || controller.m_repeatableHeld))
          {
            //Prepare to repeat or hold. Do this only once.
            timeout = getTicks();
            EnableMotionSensing(wm);
            controller.m_abs_roll = 0;
            controller.m_abs_pitch = 0;
            controller.m_start_roll = 0;
            controller.m_start_pitch = 0;
          }
          if (controller.m_buttonReleased)
          {
            DisableMotionSensing(wm);
            controller.m_currentAction = ACTION_NONE;
          }
        break;
        case WIIUSE_STATUS:
        break;
        case WIIUSE_DISCONNECT:
        case WIIUSE_UNEXPECTED_DISCONNECT:
        handle_disconnect(wm);
	connected = 0;
        break;
        case WIIUSE_READ_DATA:
        break;
        default:
        break;
	}
      }
    }
  }
  }
  wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
  return 0;
}
コード例 #10
0
ファイル: vrpn_WiiMote.C プロジェクト: hunghtbk/eeglab411
// VRPN main loop
// Poll the device and let the VRPN change notifications fire
void vrpn_WiiMote::mainloop() {
    static time_t last_error = time(NULL);

    vrpn_gettimeofday(&_timestamp, NULL);

    //XXX Try to connect once a second if we have found but not connected device.

    server_mainloop();

    // Poll to get the status of the device.  When an event happens, call
    // the appropriate handler to fill in our data structures.  To do this,
    // we need a list of pointers to WiiMotes, so we create one with a single
    // entry.
    wiimote_t *selected_one[1];
    selected_one[0] = wiimote->device;
    if (wiimote->connected && wiiuse_poll(selected_one, 1) ) {
        switch (wiimote->device->event) {
        case WIIUSE_EVENT:  // A generic event
            handle_event();
            break;

        case WIIUSE_STATUS: // A status event
            // Nothing to do here, we're polling what we need to know in mainloop.
            break;

        case WIIUSE_DISCONNECT:
        case WIIUSE_UNEXPECTED_DISCONNECT:
            wiimote->connected = false;
            send_text_message("Disconnected", _timestamp, vrpn_TEXT_ERROR);
            break;

        case WIIUSE_READ_DATA:
            // Data we requested was returned.  Take a look at wiimote->device->read_req
            // for the info.
            break;

        case WIIUSE_NUNCHUK_INSERTED:
            send_text_message("Nunchuck inserted", _timestamp);
            break;

        case WIIUSE_CLASSIC_CTRL_INSERTED:
            send_text_message("Classic controller inserted", _timestamp);
            break;

        case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
            send_text_message("Guitar Hero 3 controller inserted", _timestamp);
            break;

        case WIIUSE_NUNCHUK_REMOVED:
        case WIIUSE_CLASSIC_CTRL_REMOVED:
        case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
            send_text_message("An expansion controller was removed", _timestamp,
                              vrpn_TEXT_WARNING);
            break;

        default:
            send_text_message("unknown event", _timestamp);
            break;
        }
    }

    // Send any changes out over the connection.
    vrpn_gettimeofday(&_timestamp, NULL);
    report_changes();
}
コード例 #11
0
ファイル: triple_buffer.c プロジェクト: zAvo/xylo
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;
		}
	}
}
コード例 #12
0
	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){}
		}
		
		//}
	}
コード例 #13
0
ファイル: wiiusej_WiiUseApi.c プロジェクト: RicoBoone/wiiusej
/**
 * Get status and values from the wiimotes and send it through callbacks.
 * @param wim the wiimote object to fill with the datas.
 */
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
(JNIEnv *env, jobject obj, jobject gath) {

	/* Variables Declarations */
	int i;
	short leds = 0;
	jclass cls = (*env)->GetObjectClass(env, gath);
	jmethodID mid;

	if (wiiuse_poll(wiimotes, nbMaxWiiMotes)) {
		/*
		 *	This happens if something happened on any wiimote.
		 *	So go through each one and check if anything happened.
		 */
		for (i=0; i < nbMaxWiiMotes; ++i) {
			switch (wiimotes[i]->event) {
				case WIIUSE_EVENT:
				/* a generic event occured */
				mid = (*env)->GetMethodID(env, cls, "prepareWiiMoteEvent", "(ISSS)V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid, wiimotes[i]->btns,
						wiimotes[i]->btns_released, wiimotes[i]->btns_held);
				/*
				 *	If IR tracking is enabled then print the coordinates
				 *	on the virtual screen that the wiimote is pointing to.
				 *
				 *	Also make sure that we see at least 1 dot.
				 */
				if (WIIUSE_USING_IR(wiimotes[i])) {
					int a = 0;

					mid = (*env)->GetMethodID(env, cls, "prepareIRevent",
							"(IIIIIIIIISS)V");
					if (mid == 0) {
						return;
					}
					(*env)->CallVoidMethod(env, gath, mid,
							wiimotes[i]->ir.x, wiimotes[i]->ir.y, wiimotes[i]->ir.z,
							wiimotes[i]->ir.ax, wiimotes[i]->ir.ay,
							wiimotes[i]->ir.vres[0], wiimotes[i]->ir.vres[1],
							wiimotes[i]->ir.offset[0], wiimotes[i]->ir.offset[1],
							wiimotes[i]->ir.pos, wiimotes[i]->ir.aspect);

					mid = (*env)->GetMethodID(env, cls, "addIRPointToPreparedWiiMoteEvent",
							"(IISSS)V");
					if (mid == 0) {
						return;
					}
					/* go through each of the 4 possible IR sources */
					for (; a < 4; a++) {
						/* check if the source is visible */
						if (wiimotes[i]->ir.dot[a].visible) {
							(*env)->CallVoidMethod(env, gath, mid,
									wiimotes[i]->ir.dot[a].x, wiimotes[i]->ir.dot[a].y,
									wiimotes[i]->ir.dot[a].rx, wiimotes[i]->ir.dot[a].ry,
									wiimotes[i]->ir.dot[a].size);
						}
					}
				}

				/* Motion Sensing */
				if (WIIUSE_USING_ACC(wiimotes[i])) {
					/* set orientation and gravity force */
					mid = (*env)->GetMethodID(env, cls,
							"addMotionSensingValues", "(FIZFFFFFFFSSS)V");
					if (mid == 0) {
						return;
					}
					(*env)->CallVoidMethod(env, gath, mid,
							wiimotes[i]->orient_threshold, wiimotes[i]->accel_threshold,
							WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING), wiimotes[i]->accel_calib.st_alpha,
							wiimotes[i]->orient.roll, wiimotes[i]->orient.pitch, wiimotes[i]->orient.yaw,
							wiimotes[i]->gforce.x, wiimotes[i]->gforce.y, wiimotes[i]->gforce.z,
							wiimotes[i]->accel.x, wiimotes[i]->accel.y, wiimotes[i]->accel.z);
				}

				/* add generic event to java object used to gather events in c environment */
				mid = (*env)->GetMethodID(env, cls, "addWiimoteEvent",
						"()V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid);
				break;

				case WIIUSE_STATUS:
				/* a status event occured */
				mid = (*env)->GetMethodID(env, cls, "addStatusEvent", "(IZFSZIZZZZ)V");
				if (mid == 0) {
					return;
				}
				/* LEDS */
				if (WIIUSE_IS_LED_SET(wiimotes[i], 1)) leds += 1;
				if (WIIUSE_IS_LED_SET(wiimotes[i], 2)) leds += 2;
				if (WIIUSE_IS_LED_SET(wiimotes[i], 3)) leds += 4;
				if (WIIUSE_IS_LED_SET(wiimotes[i], 4)) leds += 8;

				(*env)->CallVoidMethod(env, gath, mid,
						wiimotes[i]->unid, WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_CONNECTED),
						wiimotes[i]->battery_level, leds, WIIUSE_USING_SPEAKER(wiimotes[i]),
						wiimotes[i]->exp.type,WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_RUMBLE),
						WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_CONTINUOUS),
						WIIUSE_USING_IR(wiimotes[i]),WIIUSE_USING_ACC(wiimotes[i]));
				break;

				case WIIUSE_DISCONNECT:
				/* the wiimote disconnected */
				mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
				break;

				default:
				break;
			}
		}
	}
}
コード例 #14
0
ファイル: main.cpp プロジェクト: CromFr/WiimoteTests
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();
}
コード例 #15
0
ファイル: sdl.c プロジェクト: 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();
	}
}
コード例 #16
0
ファイル: example.c プロジェクト: AchimTuran/wiiuse
/**
 *	@brief main()
 *
 *	Connect to up to two wiimotes and print any events
 *	that occur on either device.
 */
int main(int argc, char** argv) {
	wiimote** wiimotes;
	int found, connected;

	/*
	 *	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.\n");
		return 0;
	}

	/*
	 *	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.
	 */
	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;
	}

	/*
	 *	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_set_leds(wiimotes[1], WIIMOTE_LED_2);
	wiiuse_set_leds(wiimotes[2], WIIMOTE_LED_3);
	wiiuse_set_leds(wiimotes[3], WIIMOTE_LED_4);
	wiiuse_rumble(wiimotes[0], 1);
	wiiuse_rumble(wiimotes[1], 1);

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

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

	printf("\nControls:\n");
	printf("\tB toggles rumble.\n");
	printf("\t+ to start Wiimote accelerometer reporting, - to stop\n");
	printf("\tUP to start IR camera (sensor bar mode), DOWN to stop.\n");
	printf("\t1 to start Motion+ reporting, 2 to stop.\n");
	printf("\n\n");

	/*
	 *	Maybe I'm interested in the battery power of the 0th
	 *	wiimote.  This should be WIIMOTE_ID_1 but to be sure
	 *	you can get the wiimote associated with WIIMOTE_ID_1
	 *	using the wiiuse_get_by_id() function.
	 *
	 *	A status request will return other things too, like
	 *	if any expansions are plugged into the wiimote or
	 *	what LEDs are lit.
	 */
	/* wiiuse_status(wiimotes[0]); */

	/*
	 *	This is the main loop
	 *
	 *	wiiuse_poll() needs to be called with the wiimote array
	 *	and the number of wiimote structures in that array
	 *	(it doesn't matter if some of those wiimotes are not used
	 *	or are not connected).
	 *
	 *	This function will set the event flag for each wiimote
	 *	when the wiimote has things to report.
	 */
	while (any_wiimote_connected(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) {
				switch (wiimotes[i]->event) {
					case WIIUSE_EVENT:
						/* a generic event occurred */
						handle_event(wiimotes[i]);
						break;

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

					case WIIUSE_DISCONNECT:
					case WIIUSE_UNEXPECTED_DISCONNECT:
						/* the wiimote disconnected */
						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); */
						printf("Nunchuk inserted.\n");
						break;

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

					case WIIUSE_WII_BOARD_CTRL_INSERTED:
						printf("Balance board 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_MOTION_PLUS_ACTIVATED:
						printf("Motion+ was activated\n");
						break;

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

					default:
						break;
				}
			}
		}
	}

	/*
	 *	Disconnect the wiimotes
	 */
	wiiuse_cleanup(wiimotes, MAX_WIIMOTES);

	return 0;
}
コード例 #17
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;
						}
						*/
					//}
				//}
			}
				
		}
	}
コード例 #18
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;
}
コード例 #19
0
ファイル: wiiis.c プロジェクト: Kurtnoise/gpac
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;
}
int main(void)
{
    wiimote *wm;
    wiimote** wiimotes;
    int found, connected;
    HANDLE canHandle;
    TPCANMsg Message;
    int wiimote_led_state;
    int exit = 0;

    canHandle = initCAN();
    if(canHandle == NULL)
    {
        printf("Error opening CAN device!\n");
        return -1;
    }

    wiimotes =  wiiuse_init(MAX_WIIMOTES);

    found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5);
    if (!found)
    {
        printf ("No wiimotes found.\n");
        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;
    }

    wm = wiimotes[0];
    wiiuse_status(wm);
    while(wm->event != WIIUSE_STATUS)
    {
        wiiuse_poll(wiimotes, MAX_WIIMOTES);
    }
    printf("Battery level: %f%%\n", wm->battery_level*100);

    while (1)
    {
        if(exit)
            break;
        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]);
                        Message.ID = CAN_INPUT_MSG_ID;
                        Message.MSGTYPE = MSGTYPE_STANDARD;
                        Message.LEN = 7;
                        Message.DATA[0] = carInputs.accel;
                        Message.DATA[1] = carInputs.brake;
                        Message.DATA[2] = carInputs.steer;
                        Message.DATA[3] = carInputs.gear;
                        Message.DATA[4] = carInputs.clutch;
                        Message.DATA[5] = carInputs.controls;
			Message.DATA[6] = carInputs.cruisedist;
                        CAN_Write(canHandle,&Message);

                        // Show the status of ABS/TC/Cruise on the LEDs
                        wiimote_led_state = 0;
                        if(carInputs.controls & ABS)
                            wiimote_led_state |= WIIMOTE_LED_1;
                        if(carInputs.controls & TC)
                            wiimote_led_state |= WIIMOTE_LED_2;
                        if(carInputs.controls & STABILITY)
                            wiimote_led_state |= WIIMOTE_LED_3;
                        if(carInputs.controls & CRUISE)
                            wiimote_led_state |= WIIMOTE_LED_4;
                        wiiuse_set_leds(wm, wiimote_led_state);

                        break;
                    case WIIUSE_DISCONNECT:
                    case WIIUSE_UNEXPECTED_DISCONNECT:
                        /* the wiimote disconnected */
                        handle_disconnect(wiimotes[i]);
                        exit = 1;
                        break;
                    default:
                        break;
                }
            }
        }
    }
    wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
    return 0;

}
コード例 #21
0
ファイル: main.c プロジェクト: ElFeesho/OldCProjects
gboolean handle_hit(gpointer *data)
{
	static int down[2] = { 0 };
	started = 1;
	for(;!exitting;)
	{
		if(wiiuse_poll(wiimotes,found))
		{
			if(wiimotes[0]->event == WIIUSE_EVENT)
			{
				if(wiimotes[0]->gforce.z<gtk_range_get_value(GTK_RANGE(dwn[0])) && !down[0])
				{
					lhit[0] = SDL_GetTicks();
					down[0] = 1;
					if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_A))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_CRASH],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_B))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_HIHAT],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_MINUS))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_HTOM],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_HOME))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_MTOM],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_PLUS))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_LTOM],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_DOWN))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_RIDE],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_LEFT))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_CHCRASH],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_RIGHT))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SPLASH],0);
					}
					else if(IS_HELD(wiimotes[0], WIIMOTE_BUTTON_ONE) || IS_HELD(wiimotes[0], WIIMOTE_BUTTON_TWO))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SNAREST],0);
					}
					else
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SNAREL],0);
					}
				}
				if(wiimotes[0]->gforce.z>gtk_range_get_value(GTK_RANGE(up[0])) && down[0])
				{
					down[0] = 0;
				}
			}
			if(wiimotes[1]->event == WIIUSE_EVENT)
			{
				if(wiimotes[1]->gforce.z<gtk_range_get_value(GTK_RANGE(dwn[1])) && !down[1])
				{
					lhit[1] = SDL_GetTicks();
					down[1] = 1;
					if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_A))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_CRASH],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_B))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_HIHAT],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_MINUS))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_HTOM],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_HOME))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_MTOM],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_PLUS))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_LTOM],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_DOWN))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_RIDE],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_LEFT))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_CHCRASH],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_RIGHT))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SPLASH],0);
					}
					else if(IS_HELD(wiimotes[1], WIIMOTE_BUTTON_ONE) || IS_HELD(wiimotes[0], WIIMOTE_BUTTON_TWO))
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SNAREST],0);
					}
					else
					{
						Mix_PlayChannel(-1,drum_sounds[DRUM_SNARER],0);
					}
				}
				if(wiimotes[1]->gforce.z>gtk_range_get_value(GTK_RANGE(up[1])) && down[1])
				{
					down[1] = 0;
				}
			}
		}		
		gtk_widget_queue_draw(ggraph);
	}
}
コード例 #22
0
bool controllerClass::get()
{
  Uint8 *keyStates;
  Uint8 keyDown[3]; //Need this since its not a good idea to write to keyStates for some reason
  shotTime += globalTicks;
  SDL_PumpEvents();
  keyStates = SDL_GetKeyState( NULL );
  keyDown[0] = keyStates[setting.keyLeft];
  keyDown[1] = keyStates[setting.keyRight];
  keyDown[2] = keyStates[setting.keyShoot];
  
  itemSelectTime += globalTicks;
  //Read joystick here so we can override keypresses if the joystick is digital
  //We shouldn't need to check if the joystick is enabled, since it won't be opened if its not enabled anyway.
  if(setting.joyEnabled && SDL_JoystickOpened(0))
  {
    joystickx = SDL_JoystickGetAxis(joystick, 0);
    joysticky = SDL_JoystickGetAxis(joystick, 1);
    joystickbtnA = SDL_JoystickGetButton(joystick, 0);
    joystickbtnB = SDL_JoystickGetButton(joystick, 1);


    if(joystickbtnA)
    {
      keyDown[2] = 1;
    }
    if(joystickbtnB && itemSelectTime > ITEMSELECTTIME)
    {
      itemSelectTime=0;
      gVar.shopBuyItem=1;
    }

    if(setting.joyIsDigital)
    {
      if(joystickx < -200)
      {
        keyDown[0]=1;
      } else if(joystickx > 200)
      {
        keyDown[1]=1;
      }
      if(joysticky < -200 && itemSelectTime > ITEMSELECTTIME)
      {
        itemSelectTime=0;
        gVar.shopNextItem = 1;
      } else if(joysticky > 200 && itemSelectTime > ITEMSELECTTIME)
      {
        itemSelectTime=0;
        gVar.shopPrevItem = 1;
      }
      
    } else {
      GLfloat x; //This is the actual traveling speed of the paddle
      if(joystickx > setting.JoyCalHighJitter)
      {
        x = joystickRightX * joystickx;
      } else if(joystickx < setting.JoyCalLowJitter)
      {
        x = -(joystickLeftX * joystickx);
      }
      
      if(joysticky < setting.JoyCalLowJitter && itemSelectTime > ITEMSELECTTIME)
      {
        itemSelectTime=0;
        gVar.shopNextItem = 1;
      } else if(joysticky > setting.JoyCalHighJitter && itemSelectTime > ITEMSELECTTIME)
      {
        itemSelectTime=0;
        gVar.shopPrevItem = 1;
      }
      //Move the paddle:
      movePaddle( paddle->posx += (x*globalMilliTicks) );
    }
  }

  #ifdef WITH_WIIUSE
  if(var.wiiConnect)
  {
    if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) {
      switch(wiimotes[0]->event)
      {
        case WIIUSE_EVENT:
          if(IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_TWO))
          {
            keyDown[2]=1;
          } else if(IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_ONE) && itemSelectTime > ITEMSELECTTIME)
          {
            gVar.shopBuyItem = 1;
            itemSelectTime=0;
          }else if(IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_UP) && itemSelectTime > ITEMSELECTTIME)
          {
            itemSelectTime=0;
            gVar.shopPrevItem = 1;
          }else if(IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_DOWN) && itemSelectTime > ITEMSELECTTIME)
          {
            itemSelectTime=0;
            gVar.shopNextItem = 1;
          } else if(WIIUSE_USING_ACC(wiimotes[0]))
          {
            motePitch = wiimotes[0]->orient.pitch;
            motePitch *=-1;
	  }

        break;
        case WIIUSE_DISCONNECT:
        case WIIUSE_UNEXPECTED_DISCONNECT:
          var.wiiConnect=0;
          cout << "WiiMote disconnected." << endl;
          wiiuse_cleanup(wiimotes, MAX_WIIMOTES);
        break;
      }
    }
    if(motePitch < -0.2 || motePitch > 0.2)
    {
      movePaddle( paddle->posx += ( moteAccel*motePitch)*globalMilliTicks );
    }
  }
  #endif

  //React to keystates here, this way, if joyisdig it will press keys
  if(keyDown[0])
  {
    accel+=globalMilliTicks*setting.controlAccel;
    if(accel > setting.controlMaxSpeed)
      accel=setting.controlMaxSpeed;
    movePaddle( paddle->posx - ( accel*globalMilliTicks) );
  } else if(keyDown[1])
  {
    accel+=globalMilliTicks*setting.controlAccel;
    if(accel > setting.controlMaxSpeed)
      accel=setting.controlMaxSpeed;
    movePaddle( paddle->posx + ( accel*globalMilliTicks) );
  } else {
      accel = setting.controlStartSpeed;
  }

  if(keyDown[2])
  {
    btnPress();
    return(1);
  } else {
    return(0);
  }
}
コード例 #23
0
ファイル: wiimote.c プロジェクト: RainbowLyte/ProjetC
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;
}
コード例 #24
0
ファイル: horde.c プロジェクト: LofaroLabs/darwin-op-robocup
int main(int argc, char** argv) {
  wiimote** wiimotes;
  int found, connected;

  // init
  printf("[INFO] Looking for wiimotes (5 seconds)...\n");
  wiimotes =  wiiuse_init(1);

  // find wii (wait for 5 seconds)
  found = wiiuse_find(wiimotes, 1, 5);
  if (!found) {
    printf ("[INFO] No wiimotes found.\n");
    return 0;
  }

  // connect
  connected = wiiuse_connect(wiimotes, 1);
  if (connected)
    printf("[INFO] Connected to %i wiimotes (of %i found).\n", connected, found);
  else {
    printf("[ERROR] Failed to connect to any wiimote.\n");
    return 0;
  }

  // rumble and set leds
  wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1);
  wiiuse_rumble(wiimotes[0], 1);
  usleep(200000);
  wiiuse_rumble(wiimotes[0], 0);
  
  //set up socket to Java code
  server_type = SERVER_TYPE_SERIAL; 
  int fd = wait_on_socket(); 

  char write_buffer[128]; 
 
  int button=0; 
  currently_training = 0; 
  // continuously poll wiimote and handle events
  while (1) {
     if (wiiuse_poll(wiimotes, 1)) {
      switch (wiimotes[0]->event) {
      case WIIUSE_EVENT:
	button = handle_event(wiimotes[0]); 
	break;
      case WIIUSE_DISCONNECT:
      case WIIUSE_UNEXPECTED_DISCONNECT:
	goto exit;
	break;

      default:
	break;
	} 
      }

     usleep(50); 

    // tell Java code info about the wiimote
    sprintf (write_buffer, "%d:%d\n", currently_training, button); 
    writen(fd, write_buffer, strlen(write_buffer)); 
  }
 exit:
  wiiuse_cleanup(wiimotes, 1);
  close(fd); 

  return 0;
}
コード例 #25
0
ファイル: wiiusej_WiiUseApi.c プロジェクト: RicoBoone/wiiusej
/**
 * Get status and values from the wiimotes and send it through callbacks.
 * @param wim the wiimote object to fill with the datas.
 */
JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_specialPoll
(JNIEnv *env, jobject obj, jobject gath) {

	/* Variables Declarations */
	int i;
	short leds = 0;
	jclass cls = (*env)->GetObjectClass(env, gath);
	jmethodID mid;

	if (wiiuse_poll(wiimotes, nbMaxWiimotes)) {
		/*
		 *	This happens if something happened on any wiimote.
		 *	So go through each one and check if anything happened.
		 */
		for (i=0; i < nbMaxWiimotes; ++i) {
			switch (wiimotes[i]->event) {
				case WIIUSE_EVENT:
				/* a generic event occured */
				mid = (*env)->GetMethodID(env, cls, "prepareWiiMoteEvent", "(ISSS)V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid, wiimotes[i]->btns,
						wiimotes[i]->btns_released, wiimotes[i]->btns_held);
				/*
				 *	If IR tracking is enabled then print the coordinates
				 *	on the virtual screen that the wiimote is pointing to.
				 *
				 *	Also make sure that we see at least 1 dot.
				 */
				if (WIIUSE_USING_IR(wiimotes[i])) {
					int a;
					WIIUSE_GET_IR_SENSITIVITY_CORRECTED(wiimotes[i], &a);

					mid = (*env)->GetMethodID(env, cls, "prepareIRevent",
							"(IIFIIIIIISSSF)V");
					if (mid == 0) {
						return;
					}
					(*env)->CallVoidMethod(env, gath, mid,
							wiimotes[i]->ir.x, wiimotes[i]->ir.y, wiimotes[i]->ir.z,
							wiimotes[i]->ir.ax, wiimotes[i]->ir.ay,
							wiimotes[i]->ir.vres[0], wiimotes[i]->ir.vres[1],
							wiimotes[i]->ir.offset[0], wiimotes[i]->ir.offset[1],
							wiimotes[i]->ir.pos, wiimotes[i]->ir.aspect,
							a , wiimotes[i]->ir.distance);

					mid = (*env)->GetMethodID(env, cls, "addIRPointToPreparedWiiMoteEvent",
							"(IISSS)V");
					if (mid == 0) {
						return;
					}
					/* go through each of the 4 possible IR sources */
					for (a=0; a < 4; a++) {
						/* check if the source is visible */
						if (wiimotes[i]->ir.dot[a].visible) {
							(*env)->CallVoidMethod(env, gath, mid,
									wiimotes[i]->ir.dot[a].x, wiimotes[i]->ir.dot[a].y,
									wiimotes[i]->ir.dot[a].rx, wiimotes[i]->ir.dot[a].ry,
									wiimotes[i]->ir.dot[a].size);
						}
					}
				}

				/* Motion Sensing */
				if (WIIUSE_USING_ACC(wiimotes[i])) {
					/* set orientation and gravity force */
					mid = (*env)->GetMethodID(env, cls,
							"addMotionSensingValues", "(FIZFFFFFFFFFSSS)V");
					if (mid == 0) {
						return;
					}
					(*env)->CallVoidMethod(env, gath, mid,
							wiimotes[i]->orient_threshold, wiimotes[i]->accel_threshold,
							WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING), wiimotes[i]->accel_calib.st_alpha,
							wiimotes[i]->orient.roll, wiimotes[i]->orient.pitch, wiimotes[i]->orient.yaw,
							wiimotes[i]->orient.a_roll, wiimotes[i]->orient.a_pitch,
							wiimotes[i]->gforce.x, wiimotes[i]->gforce.y, wiimotes[i]->gforce.z,
							wiimotes[i]->accel.x, wiimotes[i]->accel.y, wiimotes[i]->accel.z);
				}

				/* Expansions support support*/
				if (WIIUSE_USING_EXP(wiimotes[i])) {
					/* Nunchuk support */
					if (wiimotes[i]->exp.type == EXP_NUNCHUK) {
						/* put nunchuk values in wiimote generic event */
						mid = (*env)->GetMethodID(env, cls,
								"addNunchunkEventToPreparedWiimoteEvent", "(SSSFIZFFFFFFFFFSSSFFSSSSSS)V");
						if (mid == 0) {
							return;
						}
						struct nunchuk_t* nc = (nunchuk_t*)&wiimotes[i]->exp.nunchuk;

						(*env)->CallVoidMethod(env, gath, mid,
								/* buttons */
								nc->btns,nc->btns_released,nc->btns_held,
								/* motion sensing */
								nc->orient_threshold,nc->accel_threshold,
								WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_SMOOTHING),nc->accel_calib.st_alpha,
								nc->orient.roll, nc->orient.pitch, nc->orient.yaw,
								nc->orient.a_roll, nc->orient.a_pitch,
								nc->gforce.x, nc->gforce.y, nc->gforce.z,
								nc->accel.x, nc->accel.y, nc->accel.z,
								/* joystick */
								nc->js.ang,nc->js.mag,
								nc->js.max.x,nc->js.max.y,
								nc->js.min.x,nc->js.min.y,
								nc->js.center.x,nc->js.center.y);
					} else if (wiimotes[i]->exp.type == EXP_GUITAR_HERO_3) {
						/* put guitar hero values in wiimote generic event */
						mid = (*env)->GetMethodID(env, cls,
								"addGuitarHeroEventToPreparedWiimoteEvent", "(SSSFFFSSSSSS)V");
						if (mid == 0) {
							return;
						}
						struct guitar_hero_3_t* gh = (guitar_hero_3_t*)&wiimotes[i]->exp.gh3;

						(*env)->CallVoidMethod(env, gath, mid,
								/* buttons */
								gh->btns,gh->btns_released,gh->btns_held,
								/* whammy bar */
								gh->whammy_bar,
								/* joystick */
								gh->js.ang,gh->js.mag,
								gh->js.max.x,gh->js.max.y,
								gh->js.min.x,gh->js.min.y,
								gh->js.center.x,gh->js.center.y);
					}if (wiimotes[i]->exp.type == EXP_CLASSIC) {
						/* put classic controller values in wiimote generic event */
						mid = (*env)->GetMethodID(env, cls,
								"addClassicControllerEventToPreparedWiimoteEvent", "(SSSFFFFSSSSSSFFSSSSSS)V");
						if (mid == 0) {
							return;
						}
						struct classic_ctrl_t* cl = (classic_ctrl_t*)&wiimotes[i]->exp.classic;

						(*env)->CallVoidMethod(env, gath, mid,
								/* buttons */
								cl->btns,cl->btns_released,cl->btns_held,
								/* shoulder buttons */
								cl->r_shoulder,cl->l_shoulder,
								/* joystick left*/
								cl->ljs.ang,cl->ljs.mag,
								cl->ljs.max.x,cl->ljs.max.y,
								cl->ljs.min.x,cl->ljs.min.y,
								cl->ljs.center.x,cl->ljs.center.y,
								/* joystick right */
								cl->rjs.ang,cl->rjs.mag,
								cl->rjs.max.x,cl->rjs.max.y,
								cl->rjs.min.x,cl->rjs.min.y,
								cl->rjs.center.x,cl->rjs.center.y);
					}
				}

				/* add generic event to java object used to gather events in c environment */
				mid = (*env)->GetMethodID(env, cls, "addWiimoteEvent",
						"()V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid);
				break;

				case WIIUSE_DISCONNECT:
				/* the wiimote disconnected */
				mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
				break;

				case WIIUSE_UNEXPECTED_DISCONNECT:
				/* the wimote disconnected */
				mid = (*env)->GetMethodID(env, cls, "addDisconnectionEvent", "(I)V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
				break;

				case WIIUSE_NUNCHUK_INSERTED:
				/* the nunchuk was just connected */
				mid = (*env)->GetMethodID(env, cls, "addNunchukInsertedEvent", "(I)V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
				break;

				case WIIUSE_NUNCHUK_REMOVED:
				/* the nunchuk disconnected */
				mid = (*env)->GetMethodID(env, cls, "addNunchukRemovedEvent", "(I)V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
				break;

				case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
				/* the guitar hero was just connected */
				mid = (*env)->GetMethodID(env, cls, "addGuitarHeroInsertedEvent", "(I)V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
				break;

				case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED:
				/* the guitar hero disconnected */
				mid = (*env)->GetMethodID(env, cls, "addGuitarHeroRemovedEvent", "(I)V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
				break;

				case WIIUSE_CLASSIC_CTRL_INSERTED:
				/* the classic controller was just connected */
				mid = (*env)->GetMethodID(env, cls, "addClassicControllerInsertedEvent", "(I)V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
				break;

				case WIIUSE_CLASSIC_CTRL_REMOVED:
				/* the classic controller disconnected */
				mid = (*env)->GetMethodID(env, cls, "addClassicControllerRemovedEvent", "(I)V");
				if (mid == 0) {
					return;
				}
				(*env)->CallVoidMethod(env, gath, mid, wiimotes[i]->unid);
				break;

				case WIIUSE_STATUS:
				/* a status event occured */
				mid = (*env)->GetMethodID(env, cls, "addStatusEvent", "(IZFSZIZZZZ)V");
				if (mid == 0) {
					return;
				}
				/* LEDS */
				if (WIIUSE_IS_LED_SET(wiimotes[i], 1)) leds += 1;
				if (WIIUSE_IS_LED_SET(wiimotes[i], 2)) leds += 2;
				if (WIIUSE_IS_LED_SET(wiimotes[i], 3)) leds += 4;
				if (WIIUSE_IS_LED_SET(wiimotes[i], 4)) leds += 8;

				(*env)->CallVoidMethod(env, gath, mid,
						wiimotes[i]->unid, WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_CONNECTED),
						wiimotes[i]->battery_level, leds, WIIUSE_USING_SPEAKER(wiimotes[i]),
						wiimotes[i]->exp.type,WIIMOTE_IS_SET(wiimotes[i], WIIMOTE_STATE_RUMBLE),
						WIIMOTE_IS_FLAG_SET(wiimotes[i],WIIUSE_CONTINUOUS),
						WIIUSE_USING_IR(wiimotes[i]),WIIUSE_USING_ACC(wiimotes[i]));
				break;

				default:
				break;
			}
		}
	}
}
コード例 #26
0
ファイル: main.cpp プロジェクト: CromFr/WiimoteTests
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;
}
コード例 #27
0
//int main(int argc, char** argv) {
int _tmain(int argc, _TCHAR* argv[])
{
		wiimote** wiimotes;
	int found, connected;

	/*
	 *	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.");
		return 0;
	}

	/*
	 *	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.
	 */
	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;
	}

	/*
	 *	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_set_leds(wiimotes[1], WIIMOTE_LED_2);
	wiiuse_set_leds(wiimotes[2], WIIMOTE_LED_3);
	wiiuse_set_leds(wiimotes[3], WIIMOTE_LED_4);
	wiiuse_rumble(wiimotes[0], 1);
	wiiuse_rumble(wiimotes[1], 1);

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

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

	/*
	 *	Maybe I'm interested in the battery power of the 0th
	 *	wiimote.  This should be WIIMOTE_ID_1 but to be sure
	 *	you can get the wiimote assoicated with WIIMOTE_ID_1
	 *	using the wiiuse_get_by_id() function.
	 *
	 *	A status request will return other things too, like
	 *	if any expansions are plugged into the wiimote or
	 *	what LEDs are lit.
	 */
	//wiiuse_status(wiimotes[0]);

	/*
	 *	This is the main loop
	 *
	 *	wiiuse_poll() needs to be called with the wiimote array
	 *	and the number of wiimote structures in that array
	 *	(it doesn't matter if some of those wiimotes are not used
	 *	or are not connected).
	 *
	 *	This function will invoke the callbacks set in wiiuse_init()
	 *	when the wiimote has things to report.
	 */
	while (1) {
		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;

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

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

					case WIIUSE_NUNCHUK_INSERTED:
						/*
						 *	a nunchuk was inserted
						 *	This is a good place to set and 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);

					case WIIUSE_CLASSIC_CTRL_INSERTED:
					case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED:
						/* some expansion was inserted */
						handle_ctrl_status(wiimotes[i]);
						printf("An expansion was 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;
				}
			}
		}
	}

	/*
	 *	Disconnect the wiimotes
	 */
	wiiuse_cleanup(wiimotes, MAX_WIIMOTES);

	return 0;
	return 0;
}
コード例 #28
0
void FWiimoteInputDevice::SendControllerEvents()
{
    /*
    *   Maybe I'm interested in the battery power of the 0th
    *   wiimote.  This should be WIIMOTE_ID_1 but to be sure
    *   you can get the wiimote associated with WIIMOTE_ID_1
    *   using the wiiuse_get_by_id() function.
    *
    *   A status request will return other things too, like
    *   if any expansions are plugged into the wiimote or
    *   what LEDs are lit.
    */
    /* wiiuse_status(wiimotes[0]); */

    /*
    *   This is the main loop
    *
    *   wiiuse_poll() needs to be called with the wiimote array
    *   and the number of wiimote structures in that array
    *   (it doesn't matter if some of those wiimotes are not used
    *   or are not connected).
    *
    *   This function will set the event flag for each wiimote
    *   when the wiimote has things to report.
    */
    if (AnyWiimoteConnected())
    {
        if (wiiuse_poll(GWiimotes, MAX_WIIMOTES))
        {
            /*
            *   This happens if something happened on any wiimote.
            *   So go through each one and check if anything happened.
            */
            const double CurrentTime = FPlatformTime::Seconds();
            for (int i = 0; i < MAX_WIIMOTES; ++i)
            {
                FControllerState& ControllerState = ControllerStates[i];
                ControllerState.Wiimote = GWiimotes[i];
                if (ControllerState.Wiimote && WIIMOTE_IS_CONNECTED(ControllerState.Wiimote))
                {
                    // Check Analog state
                    if (ControllerState.Wiimote->exp.type == EXP_NUNCHUK ||
                        ControllerState.Wiimote->exp.type == EXP_MOTION_PLUS_NUNCHUK)
                    {
                        /* nunchuk */
                        struct nunchuk_t* nc = (nunchuk_t*)&ControllerState.Wiimote->exp.nunchuk;

                        if (ControllerState.LeftXAnalog != nc->js.x)
                        {
                            MessageHandler->OnControllerAnalog(FGamepadKeyNames::LeftAnalogX, ControllerState.ControllerId, nc->js.x);
                            ControllerState.LeftXAnalog = nc->js.x;
                        }

                        if (ControllerState.LeftYAnalog != nc->js.y)
                        {
                            MessageHandler->OnControllerAnalog(FGamepadKeyNames::LeftAnalogY, ControllerState.ControllerId, nc->js.y);
                            ControllerState.LeftYAnalog = nc->js.y;
                        }
                    }
                }

                FMemory::Memzero(CurrentStates);

                switch (ControllerState.Wiimote->event)
                {
                case WIIUSE_EVENT:
                    /* a generic event occurred */
                    handle_event(ControllerState.Wiimote, i);
                    break;

                case WIIUSE_STATUS:
                    /* a status event occurred */
                    handle_ctrl_status(ControllerState.Wiimote, i);
                    break;

                case WIIUSE_DISCONNECT:
                case WIIUSE_UNEXPECTED_DISCONNECT:
                    /* the wiimote disconnected */
                    handle_disconnect(ControllerState.Wiimote, i);
                    break;

                case WIIUSE_READ_DATA:
                    /*
                    *   Data we requested to read was returned.
                    *   Take a look at ControllerState.Wiimote>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); */
                    UE_LOG(LogWiimote, Log, TEXT("Nunchuk inserted."));
                    break;

                case WIIUSE_MOTION_PLUS_ACTIVATED:
                    UE_LOG(LogWiimote, Log, TEXT("Motion+ was activated"));
                    break;

                case WIIUSE_NUNCHUK_REMOVED:
                case WIIUSE_MOTION_PLUS_REMOVED:
                    /* some expansion was removed */
                    handle_ctrl_status(ControllerState.Wiimote, i);
                    UE_LOG(LogWiimote, Log, TEXT("An expansion was removed."));
                    break;

                default:
                    break;
                }

                // For each button check against the previous state and send the correct message if any
                for (int32 ButtonIndex = 0; ButtonIndex < MAX_NUM_WIIMOTE_BUTTONS; ++ButtonIndex)
                {
                    if (CurrentStates[ButtonIndex] != ControllerState.ButtonStates[ButtonIndex])
                    {
                        if (CurrentStates[ButtonIndex])
                        {
                            MessageHandler->OnControllerButtonPressed(Buttons[ButtonIndex], ControllerState.ControllerId, false);
                        }
                        else
                        {
                            MessageHandler->OnControllerButtonReleased(Buttons[ButtonIndex], ControllerState.ControllerId, false);
                        }

                        if (CurrentStates[ButtonIndex] != 0)
                        {
                            // this button was pressed - set the button's NextRepeatTime to the InitialButtonRepeatDelay
                            ControllerState.NextRepeatTime[ButtonIndex] = CurrentTime + InitialButtonRepeatDelay;
                        }
                    }
                    else if (CurrentStates[ButtonIndex] != 0 && ControllerState.NextRepeatTime[ButtonIndex] <= CurrentTime)
                    {
                        MessageHandler->OnControllerButtonPressed(Buttons[ButtonIndex], ControllerState.ControllerId, true);

                        // set the button's NextRepeatTime to the ButtonRepeatDelay
                        ControllerState.NextRepeatTime[ButtonIndex] = CurrentTime + ButtonRepeatDelay;
                    }

                    // Update the state for next time
                    ControllerState.ButtonStates[ButtonIndex] = CurrentStates[ButtonIndex];
                }

            }
        }
    }
}