Yes I'll post some of the working code:
Code:
public: delegate void UpdateLabelText(System::Object^ obj, System::String ^text);
public: delegate void UpdateTextBox(System::Object ^obj,unsigned int userID, bool withHeader);
Code:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->label2->Text = "Logging";
logState = true;
Thread^ newLogThread = gcnew Thread(gcnew ParameterizedThreadStart(&SafeThread1));
newLogThread->IsBackground=true;
newLogThread->Start(this);
Code:
static void SafeThread1(System::Object ^obj){
Form1 ^ob = (Form1^) obj;
while (ob->connect== EDK_OK) {
ob->state = EE_EngineGetNextEvent(ob->eEvent);
// New event needs to be handled
if (logState==true && ob->state == EDK_OK) {
EE_Event_t eventType = EE_EmoEngineEventGetType(ob->eEvent);
EE_EmoEngineEventGetUserId(ob->eEvent, &userID);
// Log the EmoState if it has been updated
if (eventType == EE_EmoStateUpdated) {
EE_EmoEngineEventGetEmoState(ob->eEvent, ob->eState);
const float timestamp = ES_GetTimeFromStart(ob->eState);
ob->SetLabelText(ob,"New EmoState at "+timestamp+" from user "+userID);
logEmoState(ob, ofs, userID, writeHeader);
ob->logEmoStateTXT(ob,userID, writeHeader);
//writeHeader = false;
}
}else if (ob->state != EDK_NO_EVENT) {
ob->SetLabelText(ob,"Internal error in Emotiv Engine!");
break;
}
}
ob->SetLabelText(ob,"Logging Stoped!");
}
Code:
static void SetLabelText(System::Object ^obj, System::String^ text)
{
Form1 ^ob = (Form1^) obj;
if (ob->label2->InvokeRequired)
{
ob->label2->BeginInvoke(gcnew UpdateLabelText(&ob->SetLabelText), ob, text);
}//if
else
{
ob->label2->Text = text;
}//else
}
Code:
static void logEmoStateTXT(System::Object ^obj,unsigned int userID, bool withHeader) {
Form1 ^ob = (Form1^) obj;
if (ob->textBox1->InvokeRequired)
{
ob->textBox1->BeginInvoke(gcnew UpdateTextBox(&ob->logEmoStateTXT), ob, userID, withHeader);
}else{
if (withHeader) {
ob->textBox1->AppendText("Time,"+ES_GetTimeFromStart(ob->eState).ToString()+"\n");
ob->textBox1->AppendText("UserID,"+userID.ToString()+"\n");
ob->textBox1->AppendText("Wireless Signal Status,"+static_cast<int>(ES_GetWirelessSignalStatus(ob->eState)).ToString()+"\n");
ob->textBox1->AppendText("Blink,"+ES_ExpressivIsBlink(ob->eState).ToString()+"\n");
ob->textBox1->AppendText("Wink Left,"+ES_ExpressivIsLeftWink(ob->eState).ToString()+"\n");
ob->textBox1->AppendText("Wink Right,"+ES_ExpressivIsRightWink(ob->eState).ToString()+"\n");
ob->textBox1->AppendText("Look Left,"+ES_ExpressivIsLookingLeft(ob->eState).ToString()+"\n");
ob->textBox1->AppendText("Look Right,"+ES_ExpressivIsLookingRight(ob->eState).ToString()+"\n");
std::map<EE_ExpressivAlgo_t, float> expressivStates;
EE_ExpressivAlgo_t upperFaceAction = ES_ExpressivGetUpperFaceAction(ob->eState);
float upperFacePower = ES_ExpressivGetUpperFaceActionPower(ob->eState);
EE_ExpressivAlgo_t lowerFaceAction = ES_ExpressivGetLowerFaceAction(ob->eState);
float lowerFacePower = ES_ExpressivGetLowerFaceActionPower(ob->eState);
expressivStates[ upperFaceAction ] = upperFacePower;
expressivStates[ lowerFaceAction ] = lowerFacePower;
ob->textBox1->AppendText("Eyebrow,"+expressivStates[ EXP_EYEBROW ].ToString()+"\n");
ob->textBox1->AppendText("Furrow," + expressivStates[ EXP_FURROW ].ToString()+ "\n"); // furrow;
ob->textBox1->AppendText("Smile," + expressivStates[ EXP_SMILE ].ToString()+ "\n"); // smile
ob->textBox1->AppendText("Clench,"+ expressivStates[ EXP_CLENCH ].ToString() + "\n"); // clench;
ob->textBox1->AppendText("Smirk Left,"+expressivStates[ EXP_SMIRK_LEFT ].ToString()+ "\n"); // smirk left;
ob->textBox1->AppendText("Smirk Right,"+expressivStates[ EXP_SMIRK_RIGHT ].ToString()+"\n"); // smirk right;
ob->textBox1->AppendText("Laugh,"+expressivStates[ EXP_LAUGH ].ToString() + "\n"); // laugh;
ob->textBox1->AppendText("Short Term Excitement,"+ES_AffectivGetExcitementShortTermScore(ob->eState).ToString()+ "\n");
ob->textBox1->AppendText("Long Term Excitement,"+ES_AffectivGetExcitementLongTermScore(ob->eState).ToString() + "\n");
ob->textBox1->AppendText("Engagement/Boredom,"+ES_AffectivGetEngagementBoredomScore(ob->eState).ToString()+"\n");
ob->textBox1->AppendText("Cognitiv Action,"+static_cast<int>(ES_CognitivGetCurrentAction(ob->eState)).ToString()+"\n");
ob->textBox1->AppendText("Cognitiv Power,"+ES_CognitivGetCurrentActionPower(ob->eState).ToString()+"\n");
ob->textBox1->AppendText("\n");
}
}
}
Lots of code, but this give people that thread an idea of the working solution.