int main(int argc, char** argv) { CWii wii; // Defaults to 4 remotes std::vector<CWiimote>::iterator i; int reloadWiimotes = 0; int index; // Find and connect to the wiimotes std::vector<CWiimote>& wiimotes = wii.FindAndConnect(); if (!wiimotes.size()) { cout << "No wiimotes found." << endl; return 0; } // Setup the wiimotes for(index = 0, i = wiimotes.begin(); i != wiimotes.end(); ++i, ++index) { // Use a reference to make working with the iterator handy. CWiimote & wiimote = *i; //Set Leds wiimote.SetLEDs(LED_MAP[index]); } cout << "\nPress PLUS (MINUS) to enable (disable) Motion Sensing Report (only accelerometers)" << endl; cout << "Press RIGHT (LEFT) to enable (disable) Motion Plus (requires Motion Sensing enabled)" << endl; cout << "Press UP (DOWN) to enable (disable) IR camera (requires some IR led)" << endl; do { if(reloadWiimotes) { // Regenerate the list of wiimotes wiimotes = wii.GetWiimotes(); reloadWiimotes = 0; } //Poll the wiimotes to get the status like pitch or roll if(wii.Poll()) { for(i = wiimotes.begin(); i != wiimotes.end(); ++i) { // Use a reference to make working with the iterator handy. CWiimote & wiimote = *i; switch(wiimote.GetEvent()) { case CWiimote::EVENT_EVENT: HandleEvent(wiimote); break; case CWiimote::EVENT_STATUS: HandleStatus(wiimote); break; case CWiimote::EVENT_DISCONNECT: case CWiimote::EVENT_UNEXPECTED_DISCONNECT: HandleDisconnect(wiimote); reloadWiimotes = 1; break; case CWiimote::EVENT_READ_DATA: HandleReadData(wiimote); break; case CWiimote::EVENT_NUNCHUK_INSERTED: HandleNunchukInserted(wiimote); reloadWiimotes = 1; break; case CWiimote::EVENT_CLASSIC_CTRL_INSERTED: HandleClassicInserted(wiimote); reloadWiimotes = 1; break; case CWiimote::EVENT_GUITAR_HERO_3_CTRL_INSERTED: HandleGH3Inserted(wiimote); reloadWiimotes = 1; break; case CWiimote::EVENT_MOTION_PLUS_INSERTED: cout << "Motion Plus inserted." << endl; break; case CWiimote::EVENT_BALANCE_BOARD_INSERTED: cout << "Balance Board connected.\n" << endl; break; case CWiimote::EVENT_BALANCE_BOARD_REMOVED: cout << "Balance Board disconnected.\n" << endl; break; case CWiimote::EVENT_NUNCHUK_REMOVED: case CWiimote::EVENT_CLASSIC_CTRL_REMOVED: case CWiimote::EVENT_GUITAR_HERO_3_CTRL_REMOVED: case CWiimote::EVENT_MOTION_PLUS_REMOVED: cout << "An expansion was removed." << endl; HandleStatus(wiimote); reloadWiimotes = 1; break; default: break; } } } } while(wiimotes.size()); // Go so long as there are wiimotes left to poll return 0; }
int main(){ //wiringPi setup-------------------------------------------------------------- wiringPiSetup(); Shield gpio; bool bSpin = true; bool bReconnect = false; //wiimote synack------------------------------------------------------------- std::vector<CWiimote>& wiimotes = wii.FindAndConnect(1); while(!wiimotes.size()) { printf("%sAttempting to connect to wiimote...\n", HEADER.c_str()); wiimotes = wii.FindAndConnect(1); gpio.BlinkOnce(); delay(200); } gpio.Glow(); CWiimote& wiimote = wiimotes[0]; wiimote.SetLEDs(CWiimote::LED_1); printf("\n***********************************************************************\n"); printf("%sBeginning Control sequence:\n\n\n", HEADER.c_str()); int count = 1; do{ if(bReconnect){ // Regenerate the list of wiimotes printf("%sUnexpected disconnect. Attempting to reconnect...\n", HEADER.c_str()); wiimotes = wii.GetWiimotes(); bReconnect = false; } bool sync = false; if(wii.Poll()){ CWiimote & wiimote = *wiimotes.begin(); switch(wiimote.GetEvent()){ case CWiimote::EVENT_EVENT: bSpin = HandleInput(wiimote, gpio, count); count++; break; case CWiimote::EVENT_DISCONNECT: case CWiimote::EVENT_UNEXPECTED_DISCONNECT: bReconnect = true; break; default: break; } } } while(wiimotes.size() && bSpin); printf("\n***********************************************************************\n"); printf("%sExiting Application.\n", HEADER.c_str()); digitalWrite(0, LOW); //Shield destructor automatically kills pins! return 0; }