Changeset 343
- Timestamp:
- 03/27/12 18:03:41 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/project/PuzzleboxSynapseEmotiv/PuzzleboxSynapseEmotiv/main.cpp
r342 r343 14 14 #define USE_COMPOSER = True; 15 15 16 //void logEmotivUpdate(std::ostream& os, unsigned int userID, EmoStateHandle eState, bool withHeader = false); 17 void logEmotivUpdate(unsigned int userID, EmoStateHandle eState, bool withHeader = false); 16 bool print_to_console = 1; 17 18 EmoEngineEventHandle eEvent = EE_EmoEngineEventCreate(); 19 EmoStateHandle eState = EE_EmoStateCreate(); 20 unsigned int userID = 0; 21 22 void printHeaders(); 23 void processEmotivUpdate(); 24 //void logEmotivUpdate(unsigned int userID, EmoStateHandle eState, bool withHeader = false); 25 void logEmotivUpdate(bool withHeader = false); 18 26 19 27 int main(int argc, char** argv) { 20 28 21 EmoEngineEventHandle eEvent = EE_EmoEngineEventCreate();22 EmoStateHandle eState = EE_EmoStateCreate();23 unsigned int userID= 0;29 //EmoEngineEventHandle eEvent = EE_EmoEngineEventCreate(); 30 //EmoStateHandle eState = EE_EmoStateCreate(); 31 //unsigned int userID = 0; 24 32 std::string emotivHost = "127.0.0.1"; 25 33 const unsigned short composerPort = 1726; … … 36 44 } 37 45 38 std::cout << "Start receiving EmoState! Press any key to stop logging...\n" << std::endl; 39 40 //std::ofstream ofs(argv[1]); 41 bool writeHeader = true; 42 43 while (!_kbhit()) { 44 45 state = EE_EngineGetNextEvent(eEvent); 46 47 // New event needs to be handled 48 if (state == EDK_OK) { 49 50 EE_Event_t eventType = EE_EmoEngineEventGetType(eEvent); 51 EE_EmoEngineEventGetUserId(eEvent, &userID); 52 53 // Log the EmoState if it has been updated 54 if (eventType == EE_EmoStateUpdated) { 55 56 EE_EmoEngineEventGetEmoState(eEvent, eState); 57 const float timestamp = ES_GetTimeFromStart(eState); 58 59 //printf("%10.3fs : New EmoState from user %d ...\r", timestamp, userID); 60 61 //logEmotivUpdate(ofs, userID, eState, writeHeader); 62 logEmotivUpdate(userID, eState, writeHeader); 63 writeHeader = false; 64 } 65 } 66 else if (state != EDK_NO_EVENT) { 67 std::cout << "Internal error in Emotiv Engine!" << std::endl; 68 break; 69 } 70 71 Sleep(1); 46 printHeaders(); 47 48 while (1) { 49 processEmotivUpdate(); 72 50 } 73 51 74 //ofs.close(); 52 53 //std::cout << "Start receiving EmoState! Press any key to stop logging...\n" << std::endl; 54 55 //bool writeHeader = true; 56 // 57 //while (!_kbhit()) { 58 59 // state = EE_EngineGetNextEvent(eEvent); 60 61 // // New event needs to be handled 62 // if (state == EDK_OK) { 63 64 // EE_Event_t eventType = EE_EmoEngineEventGetType(eEvent); 65 // EE_EmoEngineEventGetUserId(eEvent, &userID); 66 67 // // Log the EmoState if it has been updated 68 // if (eventType == EE_EmoStateUpdated) { 69 70 // EE_EmoEngineEventGetEmoState(eEvent, eState); 71 // const float timestamp = ES_GetTimeFromStart(eState); 72 73 // //printf("%10.3fs : New EmoState from user %d ...\r", timestamp, userID); 74 // 75 // //logEmotivUpdate(userID, eState, writeHeader); 76 // logEmotivUpdate(writeHeader); 77 // writeHeader = false; 78 // } 79 // } 80 // else if (state != EDK_NO_EVENT) { 81 // std::cout << "Internal error in Emotiv Engine!" << std::endl; 82 // break; 83 // } 84 85 // Sleep(1); 86 //} 87 75 88 } 76 89 catch (const std::exception& e) { … … 88 101 89 102 103 void printHeaders() { 104 std::cout << "Time,"; 105 std::cout << "Emotiv UserID,"; 106 std::cout << "Wireless Signal Status,"; 107 std::cout << "Headset On,"; 108 109 std::cout << "Short Term Excitement,"; 110 std::cout << "Long Term Excitement,"; 111 std::cout << "Meditation,"; 112 std::cout << "Frustration,"; 113 std::cout << "Engagement/Boredom,"; 114 std::cout << "Cognitiv Action,"; 115 std::cout << "Cognitiv Power"; 116 std::cout << std::endl; 117 } 118 119 //void processEmotivUpdate(unsigned int userID, EmoStateHandle eState, bool withHeader) { 120 void processEmotivUpdate() { 121 122 int state = EE_EngineGetNextEvent(eEvent); 123 124 // New event needs to be handled 125 if (state == EDK_OK) { 126 127 EE_Event_t eventType = EE_EmoEngineEventGetType(eEvent); 128 EE_EmoEngineEventGetUserId(eEvent, &userID); 129 130 // Log the EmoState if it has been updated 131 if (eventType == EE_EmoStateUpdated) { 132 133 EE_EmoEngineEventGetEmoState(eEvent, eState); 134 135 //if (print_to_console) { 136 // std::cout << "Time,"; 137 // std::cout << "Emotiv UserID,"; 138 // std::cout << "Wireless Signal Status,"; 139 // std::cout << "Headset On,"; 140 141 // std::cout << "Short Term Excitement,"; 142 // std::cout << "Long Term Excitement,"; 143 // std::cout << "Meditation,"; 144 // std::cout << "Frustration,"; 145 // std::cout << "Engagement/Boredom,"; 146 // std::cout << "Cognitiv Action,"; 147 // std::cout << "Cognitiv Power,"; 148 // std::cout << std::endl; 149 //} // DEBUG 150 151 152 153 // Log the time stamp and user ID 154 float time_from_start = ES_GetTimeFromStart(eState); 155 //std::cout << userID << ","; 156 int wireless_signal_status = static_cast<int>(ES_GetWirelessSignalStatus(eState)); 157 int headset_on = static_cast<int>(ES_GetHeadsetOn(eState)); 158 159 // Affectiv Suite results 160 float excitement = ES_AffectivGetExcitementShortTermScore(eState); 161 float excitement_long_term = ES_AffectivGetExcitementLongTermScore(eState); 162 float meditation = ES_AffectivGetMeditationScore(eState); 163 float frustration = ES_AffectivGetFrustrationScore(eState); 164 float engagement_boredome = ES_AffectivGetEngagementBoredomScore(eState); 165 166 // Cognitiv Suite results 167 int cognitiv_action = static_cast<int>(ES_CognitivGetCurrentAction(eState)); 168 float cognitive_power = ES_CognitivGetCurrentActionPower(eState); 169 170 if (print_to_console) { 171 // Log the time stamp and user ID 172 std::cout << time_from_start << ","; 173 std::cout << userID << ","; 174 std::cout << wireless_signal_status << ","; 175 std::cout << headset_on << ","; 176 std::cout << excitement << ","; 177 std::cout << meditation << ","; 178 std::cout << frustration << ","; 179 std::cout << engagement_boredome << ","; 180 std::cout << cognitiv_action << ","; 181 std::cout << cognitive_power; 182 std::cout << std::endl; 183 } // DEBUG 184 185 } 186 } 187 } 188 189 90 190 //void logEmotivUpdate(std::ostream& os, unsigned int userID, EmoStateHandle eState, bool withHeader) { 91 void logEmotivUpdate(unsigned int userID, EmoStateHandle eState, bool withHeader) { 191 //void logEmotivUpdate(unsigned int userID, EmoStateHandle eState, bool withHeader) { 192 void logEmotivUpdate(bool withHeader) { 92 193 93 194 // Create the top header 94 195 if (withHeader) { 95 196 std::cout << "Time,"; 96 //std::cout << "UserID,";197 std::cout << "Emotiv UserID,"; 97 198 std::cout << "Wireless Signal Status,"; 98 199 std::cout << "Headset On,"; … … 123 224 // Log the time stamp and user ID 124 225 std::cout << ES_GetTimeFromStart(eState) << ","; 125 //std::cout << userID << ",";226 std::cout << userID << ","; 126 227 std::cout << static_cast<int>(ES_GetWirelessSignalStatus(eState)) << ","; 127 228 std::cout << static_cast<int>(ES_GetHeadsetOn(eState)) << ",";
Note: See TracChangeset
for help on using the changeset viewer.