Follow

Example 1: EmoStateLogger

This example demonstrates the use of the core Emotiv API functions described in the overview section. It logs all Xavier detection results for the attached users after successfully establishing a connection to Emotiv EmoEngine™ or XavierComposer™.

The program first initializes the connection with Emotiv EmoEngine™ by calling EE_EngineConnect() or, with XavierComposer™, via EE_EngineRemoteConnect() together with the target IP address of the XavierComposer machine and the fixed port 1726.  It ensures that the remote connection has been successfully established by verifying the return value of the EE_EngineRemoteConnect() function.  

 

An EmoEngineEventHandle is created by EE_EmoEngineEventCreate().  An EmoState™ buffer is created by calling EE_EmoStateCreate().  The program then queries the EmoEngine to get the current EmoEngine event by invoking EE_EngineGetNextEvent().  If the result of getting the event type using EE_EmoEngineEventGetType() is EE_EmoStateUpdated, then there is a new detection event for a particular user (extract via EE_EmoEngineEventGetUserID()).  The function EE_EmoEngineEventGetEmoState() can be used to copy the EmoState™ information from the event handle into the pre-allocated EmoState buffer.

Note that EE_EngineGetNextEvent() will return EDK_NO_EVENT if no new events have been published by EmoEngine since the previous call.  The user should also check for other error codes returned from EE_EngineGetNextEvent() to handle potential problems that are reported by the EmoEngine.

Specific detection results are retrieved from an EmoState by calling the corresponding EmoState accessor functions defined in EmoState.h.  For example, to access the blink detection, ES_ExpressivIsBlink(eState) should be used.

Before the end of the program, EE_EngineDisconnect() is called to terminate the connection with the EmoEngine and free up resources associated with the connection.  The user should also call EE_EmoStateFree() and EE_EmoEngineEventFree() to free up memory allocated for the EmoState buffer and EmoEngineEventHandle.

Before compiling the example, use the Property Pages and set the Configuration PropertiesàDebuggingàCommand Arguments to the name of the log file you wish to create, such as log.txt, and then build the example.

To test the example, launch XavierComposer.  Start a new instance of EmoStateLogger and when prompted, select option 2 (Connect to XavierComposer).  The EmoStates generated by XavierComposer will then be logged to the file log.txt.

Tip: If you examine the log file, and it is empty, it may be because you have not used the controls in the XavierComposer to generate any EmoStates.  SDKLite users should only choose option 2 to connect to XavierComposer since option 1 (Connect to EmoEngine) assumes that the user will attach a neuroheadset to the computer.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk