void initializeEmotivEngine() { if (IEE_EngineConnect() != EDK_OK) { throw std::runtime_error("Cannot connect to emotiv engine"); } motionDataHandle = IEE_MotionDataCreate(); IEE_MotionDataSetBufferSizeInSec(SECONDS); }
// // 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; IEE_EngineConnect(); #ifdef _WIN32 globalElapsed = GetTickCount(); #endif #ifdef __linux__ 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(); // Clean up IEE_EngineDisconnect(); IEE_EmoStateFree(eState); IEE_EmoEngineEventFree(hEvent); return 0; }
int main(int argc, char **argv) { // location of the machine running the "BlueGirl" head model std::string receiverHost = "localhost"; if (argc > 2) { std::cout << "Usage: " << argv[0] << " <hostname>" << std::endl; std::cout << "The arguments specify the host of the head model " "(Default: localhost)" << std::endl; return 1; } if (argc > 1) { receiverHost = std::string(argv[1]); } EmoEngineEventHandle eEvent = IEE_EmoEngineEventCreate(); EmoStateHandle eState = IEE_EmoStateCreate(); unsigned int userID = 0; const int CONTROL_PANEL_PORT = 3008; try { // Connect to EmoEngine if (IEE_EngineConnect() != EDK_OK) { throw std::runtime_error("EmoEngine start up failed."); } else { std::cout << "EmoEngine started!" << std::endl; } int startSendPort = 30000; std::map<unsigned int, SocketClient> socketMap; std::cout << "Type \"exit\" to quit, \"help\" to list available commands..." << std::endl; promptUser(); while (true) { // Handle the user input if (_kbhit()) { if (!handleUserInput()) { break; } } int state = IEE_EngineGetNextEvent(eEvent); // New event needs to be handled if (state == EDK_OK) { IEE_Event_t eventType = IEE_EmoEngineEventGetType(eEvent); IEE_EmoEngineEventGetUserId(eEvent, &userID); switch (eventType) { // New headset connected // Create a new socket to send the animation case IEE_UserAdded: { std::cout << std::endl << "New user " << userID << " added, sending FacialExpression animation to "; std::cout << receiverHost << ":" << startSendPort << "..." << std::endl; promptUser(); socketMap.insert(std::pair<unsigned int, SocketClient>( userID, SocketClient(receiverHost, startSendPort, UDP))); startSendPort++; break; } // Headset disconnected, remove the existing socket case IEE_UserRemoved: { std::cout << std::endl << "User " << userID << " has been removed." << std::endl; promptUser(); std::map<unsigned int, SocketClient>::iterator iter; iter = socketMap.find(userID); if (iter != socketMap.end()) { socketMap.erase(iter); } break; } // Send the FacialExpression animation // if EmoState has been updated case IEE_EmoStateUpdated: { IEE_EmoEngineEventGetEmoState(eEvent, eState); std::map<unsigned int, SocketClient>::iterator iter; iter = socketMap.find(userID); if (iter != socketMap.end()) { sendFacialExpressionAnimation(iter->second, eState); } break; } // Handle FacialExpression training event case IEE_FacialExpressionEvent: { handleFacialExpressionEvent(std::cout, eEvent); } default: break; } } else if (state != EDK_NO_EVENT) { std::cout << std::endl << "Internal error in Emotiv Engine!" << std::endl; break; } #ifdef _WIN32 Sleep(15); #endif #ifdef __linux__ sleep(1); #endif } } catch (const std::runtime_error& e) { std::cerr << e.what() << std::endl; std::cout << "Press 'Enter' to exit..." << std::endl; getchar(); } // Clean up IEE_EngineDisconnect(); IEE_EmoStateFree(eState); IEE_EmoEngineEventFree(eEvent); return 0; }
int main(int argc, char** argv) { EmoEngineEventHandle eEvent = IEE_EmoEngineEventCreate(); EmoStateHandle eState = IEE_EmoStateCreate(); unsigned int userID = 0; const unsigned short composerPort = 1726; float secs = 1; unsigned int datarate = 0; bool readytocollect = false; int option = 0; int state = 0; std::string input; try { if (argc != 2) { throw std::runtime_error("Please supply the log file name.\n" "Usage: MultiChannelIEEGLogger [log_file_name]."); } std::cout << "===================================================================" << std::endl; std::cout << "Example to show how to log IEEG Data from " << "EmoDriver/EmoComposer." << std::endl; std::cout << "===================================================================" << std::endl; std::cout << "Press '1' to start and connect to the Emotiv Driver " << std::endl; std::cout << "Press '2' to connect to the EmoComposer " << std::endl; std::cout << ">> "; std::getline(std::cin, input, '\n'); option = atoi(input.c_str()); switch (option) { case 1: { if (IEE_EngineConnect() != EDK_OK) { throw std::runtime_error( "Emotiv Driver start up failed."); } break; } case 2: { std::cout << "Target IP of EmoComposer? [127.0.0.1] "; std::getline(std::cin, input, '\n'); if (input.empty()) { input = std::string("127.0.0.1"); } if (IEE_EngineRemoteConnect(input.c_str(), composerPort) != EDK_OK) { std::string errMsg = "Cannot connect to EmoComposer on [" + input + "]"; throw std::runtime_error(errMsg.c_str()); } break; } default: throw std::runtime_error("Invalid option..."); break; } std::cout << "Start receiving IEEG Data! Press any key to stop logging...\n" << std::endl; std::ofstream ofs(argv[1],std::ios::trunc); ofs << header << std::endl; DataHandle hData = IEE_DataCreate(); IEE_DataSetBufferSizeInSec(secs); std::cout << "Buffer size in secs:" << secs << std::endl; while (!_kbhit()) { state = IEE_EngineGetNextEvent(eEvent); if (state == EDK_OK) { IEE_Event_t eventType = IEE_EmoEngineEventGetType(eEvent); IEE_EmoEngineEventGetUserId(eEvent, &userID); // Log the EmoState if it has been updated if (eventType == IEE_UserAdded) { std::cout << "User added"; IEE_DataAcquisitionEnable(userID,true); readytocollect = true; } } if (readytocollect) { IEE_DataUpdateHandle(0, hData); unsigned int nSamplesTaken=0; IEE_DataGetNumberOfSample(hData,&nSamplesTaken); std::cout << "Updated " << nSamplesTaken << std::endl; if (nSamplesTaken != 0) { unsigned int channelCount = sizeof(targetChannelList)/ sizeof(IEE_DataChannel_t); double ** buffer = new double*[channelCount]; for (int i=0; i<channelCount; i++) buffer[i] = new double[nSamplesTaken]; IEE_DataGetMultiChannels(hData, targetChannelList, channelCount, buffer, nSamplesTaken); for (int sampleIdx=0 ; sampleIdx<(int)nSamplesTaken ; ++ sampleIdx) { for (int i = 0 ; i<sizeof(targetChannelList)/ sizeof(IEE_DataChannel_t) ; i++) { ofs << buffer[i][sampleIdx] << ","; } ofs << std::endl; } for (int i=0; i<channelCount; i++) delete buffer[i]; delete buffer; } } std::this_thread::sleep_for(std::chrono::milliseconds(500)); } ofs.close(); IEE_DataFree(hData); } catch (const std::runtime_error& e) { std::cerr << e.what() << std::endl; std::cout << "Press any key to exit..." << std::endl; getchar(); } IEE_EngineDisconnect(); IEE_EmoStateFree(eState); IEE_EmoEngineEventFree(eEvent); return 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; }
int main(int argc, char** argv) { EmoEngineEventHandle eEvent = IEE_EmoEngineEventCreate(); EmoStateHandle eState = IEE_EmoStateCreate(); unsigned int userID = 0; float secs = 1; unsigned int datarate = 0; bool readytocollect = false; int state = 0; try { if (argc != 2) { throw std::runtime_error("Please supply the log file name.\n" "Usage: MotionDataLogger [log_file_name]."); } std::cout << "===================================================================" << std::endl; std::cout << "Example to show how to log Motion Data from EmoDriver." << std::endl; std::cout << "===================================================================" << std::endl; if (IEE_EngineConnect() != EDK_OK) throw std::runtime_error("Emotiv Driver start up failed."); std::cout << "Start receiving IEEG Data! " << "Press any key to stop logging...\n" << std::endl; std::ofstream ofs(argv[1],std::ios::trunc); ofs << header << std::endl; DataHandle hMotionData = IEE_MotionDataCreate(); IEE_MotionDataSetBufferSizeInSec(secs); std::cout << "Buffer size in secs:" << secs << std::endl; while (!_kbhit()) { state = IEE_EngineGetNextEvent(eEvent); if (state == EDK_OK) { IEE_Event_t eventType = IEE_EmoEngineEventGetType(eEvent); IEE_EmoEngineEventGetUserId(eEvent, &userID); // Log the EmoState if it has been updated if (eventType == IEE_UserAdded) { std::cout << "User added"; readytocollect = true; } } if (readytocollect) { IEE_MotionDataUpdateHandle(0, hMotionData); unsigned int nSamplesTaken=0; IEE_MotionDataGetNumberOfSample(hMotionData, &nSamplesTaken); std::cout << "Updated " << nSamplesTaken << std::endl; if (nSamplesTaken != 0) { double* data = new double[nSamplesTaken]; for (int sampleIdx=0 ; sampleIdx<(int)nSamplesTaken ; ++ sampleIdx) { for (int i = 0 ; i<sizeof(targetChannelList)/sizeof(IEE_MotionDataChannel_t) ; i++) { IEE_MotionDataGet(hMotionData, targetChannelList[i], data, nSamplesTaken); ofs << data[sampleIdx] << ","; } ofs << std::endl; } delete[] data; } } #ifdef _WIN32 Sleep(1); #endif #ifdef __linux__ usleep(10000); #endif } ofs.close(); IEE_MotionDataFree(hMotionData); } catch (const std::runtime_error& e) { std::cerr << e.what() << std::endl; std::cout << "Press any key to exit..." << std::endl; getchar(); } IEE_EngineDisconnect(); IEE_EmoStateFree(eState); IEE_EmoEngineEventFree(eEvent); return 0; }
void main() { std::string userName = "******"; std::string password = "******"; std::string profileName = "EmotivProfile"; int version = -1; // Lastest version int option = 0; std::string input; bool ready = false; EmoEngineEventHandle eEvent = IEE_EmoEngineEventCreate(); EmoStateHandle eState = IEE_EmoStateCreate(); unsigned int engineUserID = -1; int userCloudID = -1; int state = 0; if (IEE_EngineConnect() != EDK_OK) { throw std::runtime_error( "Emotiv Driver start up failed."); } std::cout << "===================================================================" << std::endl; std::cout << "Example to saving and loading profile from Emotiv Cloud " << std::endl; std::cout << "===================================================================" << std::endl; std::cout << "Press '1' to saving profile to Emotiv Cloud " << std::endl; std::cout << "Press '2' to loading profile from Emotiv Cloud " << std::endl; std::cout << ">> "; std::getline(std::cin, input, '\n'); option = atoi(input.c_str()); if(!EC_Connect()) { std::cout << "Cannot connect to Emotiv Cloud"; return; } if(!EC_Login(userName.c_str(), password.c_str())) { std::cout << "Your login attempt has failed. The username or password may be incorrect"; _getch(); return; } if (!EC_GetUserDetail(&userCloudID)) return; while (!_kbhit()) { state = IEE_EngineGetNextEvent(eEvent); if (state == EDK_OK) { IEE_Event_t eventType = IEE_EmoEngineEventGetType(eEvent); IEE_EmoEngineEventGetUserId(eEvent, &engineUserID); if (eventType == IEE_UserAdded) { std::cout << "User added" << std::endl; ready = true; } } if (ready) { int getNumberProfile = EC_GetAllProfileName(userCloudID); switch (option) { case 1:{ int profileID = EC_GetProfileId(userCloudID, profileName.c_str()); if (profileID >= 0) { std::cout << "Profile with " << profileName << " is existed" << std::endl; if (EC_UpdateUserProfile(userCloudID, engineUserID, profileID, profileName.c_str())) { std::cout << "Updating finished"; } else std::cout << "Updating failed"; } else if (EC_SaveUserProfile(userCloudID, (int)engineUserID, profileName.c_str(), profileFileType::TRAINING)) { std::cout << "Saving finished"; } else std::cout << "Saving failed"; _getch(); return; } case 2:{ if (getNumberProfile > 0) if (EC_LoadUserProfile(userCloudID, (int)engineUserID, EC_ProfileIDAtIndex(userCloudID, 0))) std::cout << "Loading finished"; else std::cout << "Loading failed"; _getch(); return; } default: throw std::runtime_error("Invalid option..."); break; } } #ifdef _WIN32 Sleep(1); #endif #ifdef linux sleep(1); #endif } IEE_EngineDisconnect(); IEE_EmoStateFree(eState); IEE_EmoEngineEventFree(eEvent); }
int main(int argc, char** argv) { EmoEngineEventHandle eEvent = IEE_EmoEngineEventCreate(); EmoStateHandle eState = IEE_EmoStateCreate(); unsigned int userID = 0; const unsigned short composerPort = 1726; int option = 0; int state = 0; std::string input; try { if (argc != 2) { throw std::runtime_error("Please supply the log file name.\n" "Usage: EmoStateLogger [log_file_name]."); } std::cout << "===================================================================" << std::endl; std::cout << "Example to show how to log the EmoState from EmoEngine/EmoComposer." << std::endl; std::cout << "===================================================================" << std::endl; std::cout << "Press '1' to start and connect to the EmoEngine " << std::endl; std::cout << "Press '2' to connect to the EmoComposer " << std::endl; std::cout << ">> "; std::getline(std::cin, input, '\n'); option = atoi(input.c_str()); switch (option) { case 1: { if (IEE_EngineConnect() != EDK_OK) { throw std::runtime_error("Emotiv Driver start up failed."); } break; } case 2: { std::cout << "Target IP of EmoComposer? [127.0.0.1] "; std::getline(std::cin, input, '\n'); if (input.empty()) { input = std::string("127.0.0.1"); } if (IEE_EngineRemoteConnect(input.c_str(), composerPort) != EDK_OK) { std::string errMsg = "Cannot connect to EmoComposer on [" + input + "]"; throw std::runtime_error(errMsg.c_str()); } break; } default: throw std::runtime_error("Invalid option..."); break; } std::cout << "Start receiving EmoState! Press any key to stop logging...\n" << std::endl; std::ofstream ofs(argv[1]); bool writeHeader = true; while (!_kbhit()) { state = IEE_EngineGetNextEvent(eEvent); // New event needs to be handled if (state == EDK_OK) { IEE_Event_t eventType = IEE_EmoEngineEventGetType(eEvent); IEE_EmoEngineEventGetUserId(eEvent, &userID); // Log the EmoState if it has been updated if (eventType == IEE_EmoStateUpdated) { IEE_EmoEngineEventGetEmoState(eEvent, eState); const float timestamp = IS_GetTimeFromStart(eState); printf("%10.3fs : New EmoState from user %d ...\r", timestamp, userID); logEmoState(ofs, userID, eState, writeHeader); writeHeader = false; } } else if (state != EDK_NO_EVENT) { std::cout << "Internal error in Emotiv Engine!" << std::endl; break; } #ifdef _WIN32 Sleep(1); #endif #ifdef __linux__ sleep(1); #endif } ofs.close(); } catch (const std::runtime_error& e) { std::cerr << e.what() << std::endl; std::cout << "Press any key to exit..." << std::endl; getchar(); } IEE_EngineDisconnect(); IEE_EmoStateFree(eState); IEE_EmoEngineEventFree(eEvent); return 0; }