//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; }
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){} } //} }
virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo) { int found =-1; int connected; switch (event) { case eFE_Initialize:{ //Sleep(3000); wiimotes = wiiuse_init(1); found = wiiuse_find(wiimotes, 1, 5); if (found!=0) handle_ctrl_status(wiimotes[0]); connected = wiiuse_connect(wiimotes, 1); if (connected) CryLogAlways("Connected to %i wiimotes (of %i found).\n", connected, found); else CryLogAlways("Failed to connect to any wiimote.\n"); wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1); wiiuse_motion_sensing(wiimotes[0], 1); wiiuse_set_ir(wiimotes[0], 1); //trop rapide ! } case eFE_Activate: { //Sleep(3000); //wiimotes = wiiuse_init(1); //found = wiiuse_find(wiimotes, 1, 5); //if (found==0) CryLogAlways("No wiimotes found.\n"); /* connected = wiiuse_connect(wiimotes, 1); if (connected) CryLogAlways("Connected to %i wiimotes (of %i found).\n", connected, found); else CryLogAlways("Failed to connect to any wiimote.\n"); wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1); wiiuse_motion_sensing(wiimotes[0], 1); wiiuse_set_ir(wiimotes[0], 1); //WIIUSE_USING_EXP(wiimotes[0]); //WIIUSE_U //wiimotes[0]->exp.type = EXP_NUNCHUK; */ pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID,true); } break; case eFE_Update: { //int connected = wiiuse_connect(wiimotes, 1); wiiuse_poll(wiimotes, 1); wiimote* wm = wiimotes[0]; //Ne change rien ! juste qu'on a un retour d'IR //handle_ctrl_status(wiimotes[0]); CryLogAlways("attachment: %i",wm->exp.type); /* Gestion des evts */ // A commenter switch (wiimotes[0]->event) { case WIIUSE_EVENT: /* a generic event occured */ handle_event(wiimotes[0]); break; case WIIUSE_STATUS: /* a status event occured */ handle_ctrl_status(wiimotes[0]); break; case WIIUSE_DISCONNECT: case WIIUSE_UNEXPECTED_DISCONNECT: /* the wiimote disconnected */ handle_disconnect(wiimotes[0]); break; case WIIUSE_READ_DATA: /* * Data we requested to read was returned. * Take a look at wiimotes[i]->read_req * for the data. */ break; case WIIUSE_NUNCHUK_INSERTED: /* * a nunchuk was inserted * This is a good place to set any nunchuk specific * threshold values. By default they are the same * as the wiimote. */ //struct nunchuk_t* nc = (nunchuk_t*)&wiimotes[0]->exp.nunchuk; wiiuse_set_nunchuk_orient_threshold(wiimotes[0], 90.0f); wiiuse_set_nunchuk_accel_threshold(wiimotes[0], 100); CryLogAlways("Nunchuk inserted.\n"); break; case WIIUSE_CLASSIC_CTRL_INSERTED: CryLogAlways("Classic controller inserted.\n"); break; case WIIUSE_GUITAR_HERO_3_CTRL_INSERTED: /* some expansion was inserted */ handle_ctrl_status(wiimotes[0]); //printf("Guitar Hero 3 controller inserted.\n"); break; case WIIUSE_NUNCHUK_REMOVED: case WIIUSE_CLASSIC_CTRL_REMOVED: case WIIUSE_GUITAR_HERO_3_CTRL_REMOVED: /* some expansion was removed */ handle_ctrl_status(wiimotes[0]); //printf("An expansion was removed.\n"); break; default: break; } //if (wiiuse_poll(wiimotes, 1)) { //int i = 0; if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_A)) ActivateOutput(pActInfo, WIIMOTE_A,true); else ActivateOutput(pActInfo, WIIMOTE_A,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_B)) ActivateOutput(pActInfo, WIIMOTE_B,true); else ActivateOutput(pActInfo, WIIMOTE_B,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_UP)) ActivateOutput(pActInfo, WIIMOTE_UP,true); else ActivateOutput(pActInfo, WIIMOTE_UP,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_DOWN)) ActivateOutput(pActInfo, WIIMOTE_DOWN,true); else ActivateOutput(pActInfo, WIIMOTE_DOWN,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_LEFT)) ActivateOutput(pActInfo, WIIMOTE_LEFT,true); else ActivateOutput(pActInfo, WIIMOTE_LEFT,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_RIGHT)) ActivateOutput(pActInfo, WIIMOTE_RIGHT,true); else ActivateOutput(pActInfo, WIIMOTE_RIGHT,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_MINUS)) ActivateOutput(pActInfo, WIIMOTE_MINUS,true); else ActivateOutput(pActInfo, WIIMOTE_MINUS,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_PLUS)) ActivateOutput(pActInfo, WIIMOTE_PLUS,true); else ActivateOutput(pActInfo, WIIMOTE_PLUS,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_ONE)) ActivateOutput(pActInfo, WIIMOTE_ONE,true); else ActivateOutput(pActInfo, WIIMOTE_ONE,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_TWO)) ActivateOutput(pActInfo, WIIMOTE_TWO,true); else ActivateOutput(pActInfo, WIIMOTE_TWO,false); if (IS_PRESSED(wiimotes[0], WIIMOTE_BUTTON_HOME)) ActivateOutput(pActInfo, WIIMOTE_HOME,true); else ActivateOutput(pActInfo, WIIMOTE_HOME,false); if (WIIUSE_USING_ACC(wiimotes[0])) { Vec3 output = Vec3(wiimotes[0]->orient.roll,wiimotes[0]->orient.pitch,wiimotes[0]->orient.yaw); ActivateOutput(pActInfo, WIIMOTE_RPY,output); } if (WIIUSE_USING_IR(wiimotes[0])) { Vec3 output = Vec3((float)wiimotes[0]->ir.x,(float)wiimotes[0]->ir.y,(float)wiimotes[0]->ir.z); ActivateOutput(pActInfo, WIIMOTE_IR,output); } /* nunchuk */ //Toujours faux ! if (wm->exp.type == EXP_NUNCHUK) { //nunchuk_t* pt = wm->exp.nunchuk; //REssort 0 a chaque fois !!!! struct nunchuk_t* nc = (nunchuk_t*)&wm->exp.nunchuk; CryLogAlways("nun gravity x EXPANSION : %f",nc->gforce.x); if (IS_PRESSED(nc, NUNCHUK_BUTTON_C)) ActivateOutput(pActInfo, NUNCHUK_C,true); else ActivateOutput(pActInfo, NUNCHUK_C,false); if (IS_PRESSED(nc, NUNCHUK_BUTTON_Z)) ActivateOutput(pActInfo, NUNCHUK_Z,true); else ActivateOutput(pActInfo, NUNCHUK_Z,false); Vec3 output = Vec3(nc->orient.a_roll,nc->orient.a_pitch,nc->orient.yaw); ActivateOutput(pActInfo, NUNCHUK_RPY,output); Vec3 output2 = Vec3(nc->js.ang,nc->js.mag,0); ActivateOutput(pActInfo, NUNCHUK_JOYSTICK,output2); } /* switch (wiimotes[0]->event) { //case WIIUSE_EVENT: //{ //} //break; case WIIUSE_STATUS: handle_ctrl_status(wiimotes[0]); break; case WIIUSE_DISCONNECT: case WIIUSE_UNEXPECTED_DISCONNECT: handle_disconnect(wiimotes[0]); break; default: break; } */ //} //} } } }
/** * @brief 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; }
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]; } } } } }
/** * @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 = wiic_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 = wiic_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 = wiic_connect( wiimotes, found, 0 ); 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). */ wiic_set_leds( wiimotes[0], WIIMOTE_LED_1 ); wiic_rumble( wiimotes[0], 1 ); usleep( 200000 ); wiic_rumble( wiimotes[0], 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 wiic_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. */ wiic_status( wiimotes[0] ); printf( "\nPress PLUS (MINUS) to enable (disable) Motion Sensing Report (only accelerometers)\n" ); printf( "Press RIGHT (LEFT) to enable (disable) Motion Plus (requires Motion Sensing enabled)\n" ); printf( "Press UP (DOWN) to enable (disable) IR camera (requires some IR led)\n" ); /* * This is the main loop * * wiic_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 ( !exiting ) { if ( wiic_poll( wiimotes, connected ) ) { /* * 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 WIIC_EVENT: // a generic event occured handle_event( wiimotes[i] ); break; case WIIC_STATUS: // a status event occured handle_ctrl_status( wiimotes[i] ); break; case WIIC_DISCONNECT: case WIIC_UNEXPECTED_DISCONNECT: // the wiimote disconnected handle_disconnect( wiimotes[i] ); break; case WIIC_READ_DATA: /* * Data we requested to read was returned. * Take a look at wiimotes[i]->read_req * for the data. */ break; case WIIC_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. */ printf( "Nunchuk inserted.\n" ); break; case WIIC_CLASSIC_CTRL_INSERTED: printf( "Classic controller inserted.\n" ); break; case WIIC_GUITAR_HERO_3_CTRL_INSERTED: // some expansion was inserted handle_ctrl_status( wiimotes[i] ); break; case WIIC_MOTION_PLUS_INSERTED: printf( "Motion Plus inserted.\n" ); break; case WIIC_BALANCE_BOARD_INSERTED: printf( "Balance Board connected.\n" ); break; case WIIC_BALANCE_BOARD_REMOVED: printf( "Balance Board disconnected.\n" ); break; case WIIC_NUNCHUK_REMOVED: case WIIC_CLASSIC_CTRL_REMOVED: case WIIC_GUITAR_HERO_3_CTRL_REMOVED: case WIIC_MOTION_PLUS_REMOVED: // some expansion was removed handle_ctrl_status( wiimotes[i] ); printf( "An expansion was removed.\n" ); break; default: break; } } } } /* * Disconnect the wiimotes */ wiic_cleanup( wiimotes, MAX_WIIMOTES ); return 0; }