int main(int argc, char** argv) { CWii wii; // Defaults to 4 remotes std::vector<CWiimote>::iterator i; int reloadWiimotes = 0; int numFound; int index; bool help = false; string option; if(argc == 2) { option = string(argv[1]); if(option == "help") { cout << endl << "wiic-logger is a utility to collect accelerometer data in a log." << endl; cout << "wiic-logger is part of WiiC (http://wiic.sf.net)" << endl << endl; cout << "Usage: wiic-logger <log_filename>" << endl; cout << " wiic-logger RANDOM <num_samples> <filename1> ... <filenameN>" << endl; cout << " <log_filename>: full pathname of the output log file" << endl; cout << " <num_samples>: number of samples for each file" << endl << endl; cout << " <filename1> ... <filenameN>: full pathname of each gesture file" << endl << endl; return 1; } } else if(argc >= 3) { option = string(argv[1]); if(option != "RANDOM") { cout << endl << "Bad Syntax!" << endl; cout << "Type wiic-logger help for a brief documentation." << endl << endl; return 1; } } else { cout << endl << "Bad Syntax!" << endl; cout << "Type wiic-logger help for a brief documentation." << endl << endl; return 1; } cout << "Searching for wiimotes... Turn them on!" << endl; //Find the wiimote numFound = wii.Find(1); // Search for up to five seconds; cout << "Found " << numFound << " wiimotes" << endl; cout << "Connecting to wiimotes..." << endl; // Connect to the wiimote std::vector<CWiimote>& wiimotes = wii.Connect(); cout << "Connected to " << (unsigned int)wiimotes.size() << " wiimotes" << endl; if(wiimotes.size() == 0) { cout << "Error: no connected Wiimote" << endl; return 1; } // Use a reference to make working with the iterator handy. CWiimote & wiimote = wiimotes[0]; //Rumble for 0.2 seconds as a connection ack wiimote.SetRumbleMode(CWiimote::ON); usleep(200000); wiimote.SetRumbleMode(CWiimote::OFF); wiimote.SetMotionSensingMode(CWiimote::ON); if(option == "RANDOM") { // Num of samples for each file int numSamples = atoi(argv[2]); // Load candidate files vector<string> gestures; int i = 3; while (i < argc) gestures.push_back(string(argv[i++])); randomAcquisition(wii, wiimote, numSamples, gestures); } else dataAcquisition(wii, wiimote, option); return 0; }
int main(int argc, char** argv) { //std::vector<CIRDot*> a ; //a.clear() ; CWii wii; // Defaults to 4 remotes int reloadWiimotes=0 ; int numFound=0 ; traveledDistance = 0 ; //Find the wiimote & search for up to five seconds. printf("Searching for wiimotes... Turn them on!\n"); numFound = wii.Find(5); printf("Found %d wiimotes\n", numFound); // Under Windows, even if a Wiimote is not connected but it can appear // in "Devices and printers", so it connects it ... if( numFound <= 0 ) return 0 ; // Connect to the wiimote printf( "Connecting to wiimotes...\n" ) ; std::vector<CWiimote*>& wiimotes = wii.Connect() ; printf( "Connected to %d wiimotes\n", (int)wiimotes.size() ) ; if( (int) wiimotes.size() <= 0 ) return 0 ; // Setup the wiimotes int index=0 ; for( size_t i = 0; i < wiimotes.size() ; ++i ) { // Use a reference to make working with the iterator handy. CWiimote *wiimote = wiimotes[i]; //Set Leds wiimote->SetLEDs(LED_MAP[++index]); // Continuous information. //wiimote->SetFlags( CWiimote::FLAG_CONTINUOUS, 0x0 ) ; //Rumble for 0.2 seconds as a connection ack wiimote->SetRumbleMode(CWiimote::ON); #ifndef WIN32 usleep(200000); #else Sleep(200); #endif wiimote->SetRumbleMode(CWiimote::OFF); } while( wiimotes.size() ) // Go so long as there are wiimotes left to poll { if( reloadWiimotes ) { // Regenerate the list of wiimotes wiimotes = wii.GetWiimotes(); reloadWiimotes = 0; } // (My) Bad idea. // The data are received in continuous when the accelerometer values are on. // So the received data is late ... Worse, latency appears. #ifndef WIN32 //usleep(200000); #else //Sleep(20); #endif //Poll the wiimotes to get the status like pitch or roll if( wii.Poll() ) { for( size_t i = 0; i < wiimotes.size() ; ++i ) { // Use a reference to make working with the iterator handy. CWiimote *wiimote = wiimotes[i]; CWiimoteData *wm=wiimote->copyData() ; 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_NUNCHUK_REMOVED: case CWiimote::EVENT_CLASSIC_CTRL_REMOVED: case CWiimote::EVENT_GUITAR_HERO_3_CTRL_REMOVED: printf("An expansion was removed.\n"); HandleStatus(*wiimote); reloadWiimotes = 1; break; default: break; } } } } return 0; }