コード例 #1
0
ファイル: logger.cpp プロジェクト: Damsolla/projetBomberman
void dataAcquisition(CWii& wii, CWiimote& wiimote, const string logfile)
{
	int enbAcq = 0;
	int count = 0;
	
	string fileacc;
	
	Dataset* dataset = new Dataset();
	Training* training = new Training(WiiC::LOG_ACC);

	cout << "Trainings will be stored in " << logfile << endl;
	cout << "  - Press PLUS button to acquire the training" << endl;
	cout << "  - Release PLUS button to end the training acquisition" << endl;
	cout << "  - Press HOME button to go back to the main menu" << endl;
	enbAcq = 1;

	while(enbAcq) {
		wii.Poll();
		
		//Inizio acquisizione dati
		while(enbAcq && wiimote.Buttons.isPressed(CButtons::BUTTON_PLUS)) {
			float x, y, z;
			wiimote.Accelerometer.GetGravityVector(x,y,z);
			training->addSample(new AccSample(x,y,z));	
		  	enbAcq = 2;		
		  	usleep(10000);
			wii.Poll();					
		}
		
		if(enbAcq == 2) {
			dataset->addTraining(training);
			count++;
			cout << "Training " << count << " acquired" << endl;
			cout << "  - Press PLUS button to acquire the training" << endl;
			cout << "  - Release PLUS button to end the training acquisition" << endl;
			cout << "  - Press HOME button to go back to the main menu" << endl;
			enbAcq = 1;		
			training = new Training(WiiC::LOG_ACC);
		}

		if(enbAcq == 1 && wiimote.Buttons.isJustPressed(CButtons::BUTTON_HOME)) {
			dataset->save(logfile.c_str());
			enbAcq = 0;
		}
	}
	
	if(training)
		delete training;
	training = 0;

	if(dataset)
		delete dataset;
	dataset = 0;		
}
コード例 #2
0
ファイル: logger.cpp プロジェクト: Damsolla/projetBomberman
void acquireGesture(CWii& wii, CWiimote& wiimote, Training* training)
{
	cout << "  - Press PLUS button to acquire the training" << endl;
	cout << "  - Release PLUS button to end the training acquisition" << endl;
	int enbAcq = 1;

	while(enbAcq) {
		wii.Poll();
		
		//Inizio acquisizione dati
		while(enbAcq && wiimote.Buttons.isPressed(CButtons::BUTTON_PLUS)) {
			float x, y, z;
			wiimote.Accelerometer.GetGravityVector(x,y,z);
			training->addSample(new AccSample(x,y,z));	
		  	enbAcq = 2;		
		  	usleep(10000);
			wii.Poll();					
		}
		
		if(enbAcq == 2) {
			enbAcq = 0;		
		}
	}
}
コード例 #3
0
ファイル: wiimote_test.cpp プロジェクト: Airstriker/viewer
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;
}
コード例 #4
0
ファイル: logger.cpp プロジェクト: Damsolla/projetBomberman
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;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: Gariben/Raspberry-Pi
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;

}
コード例 #6
0
ファイル: example.cpp プロジェクト: mickaelgadroy/wmavo
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;
}