예제 #1
0
파일: main.cpp 프로젝트: JuanaV/insight_sdk
void updateDisplay(void)
{	  
   int gyroX = 0,gyroY = 0;
   IEE_HeadsetGetGyroDelta(0,&gyroX,&gyroY);
   xmax += gyroX;
   ymax += gyroY;

   if( outOfBound )
   {
	   if( preX != gyroX && preY != gyroY )
	   {
		   xmax = currX;
		   ymax = currY;
	   }
   }

   double val = sqrt((float)(xmax*xmax + ymax*ymax));
  
    std::cout << "xmax : " << xmax << " ; ymax : " << ymax
              << std::endl;

   
   if( val >= maxRadius )
   {
	   changeXY(1);	
	   outOfBound = true;
	   preX = gyroX;
	   preY = gyroY;
   }
   else
   {		
	   outOfBound = false;
		if(oldXVal == gyroX && oldYVal == gyroY)
		{
			++count;
			if( count > 10 )
			{									
				changeXY(0);
			}
		}
		else
		{
			count = 0;
			currX = xmax;
			currY = ymax;
			oldXVal = gyroX;
			oldYVal = gyroY;			
		}
   }
    
#ifdef _WIN32
    Sleep(15);
#endif
#ifdef __linux__
    sleep(1);
#endif
    
    glutPostRedisplay();
}
예제 #2
0
/* 
 *  Request double buffer display mode.
 *  Register mouse input callback functions
 */
int main(int argc, char** argv)
{
	EmoEngineEventHandle hEvent = IEE_EmoEngineEventCreate();
	EmoStateHandle eState = IEE_EmoStateCreate();
	unsigned int userID = -1;
	int state           = 0;
	bool ready          = false;
	
	if (IEE_EngineConnect() != EDK_OK) {
		std::cout << "Emotiv Driver start up failed.";
		return -1;
	}
	
	std::cout << "Please make sure your headset is on and don't move your head.";
	std::cout << std::endl;

	while(true)
	{

		state = IEE_EngineGetNextEvent(hEvent);

		if (state == EDK_OK) 
		{
		    IEE_Event_t eventType = IEE_EmoEngineEventGetType(hEvent);
			IEE_EmoEngineEventGetUserId(hEvent, &userID);

			if (eventType == IEE_UserAdded) {
		         std::cout << "User added" << std::endl << std::endl;
				 userID = 0;
		         ready = true;
			}
		}

		if(!ready) continue;

		int gyroX = 0, gyroY = 0;
		int err = IEE_HeadsetGetGyroDelta(userID, &gyroX, &gyroY);
				
		if (err == EDK_OK){
			std::cout << std::endl;
			std::cout << "You can move your head now." << std::endl;

#ifdef _WIN32
			Sleep(1000);
#endif
#if __linux__ || __APPLE__
            usleep(10000);
#endif
			break;
		}else if (err == EDK_GYRO_NOT_CALIBRATED){
			std::cout << "Gyro is not calibrated. Please stay still." << std::endl;
		}else if (err == EDK_CANNOT_ACQUIRE_DATA){
			std::cout << "Cannot acquire data" << std::endl;
		}else{
			std::cout << "No headset is connected" << std::endl;
		}

#ifdef _WIN32
		Sleep(100);
#endif
#if __linux__ || __APPLE__
        usleep(10000);
#endif
	}

#ifdef _WIN32
   globalElapsed = GetTickCount();
#endif
#if __linux__|| __APPLE__
   globalElapsed = ( unsigned long ) GetTickCount();
#endif

   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
   glutInitWindowSize (650, 650); 
   glutInitWindowPosition (100, 100);
   glutCreateWindow (argv[0]);
   init ();
   glutDisplayFunc(display); 
   glutReshapeFunc(reshape); 
   glutIdleFunc(updateDisplay);
   glutMainLoop();  
      
   IEE_EngineDisconnect();
   IEE_EmoStateFree(eState);
   IEE_EmoEngineEventFree(hEvent);	

   return 0;
}