/// <summary> /// Fills in the event referred to by hEvent with an EE_ProfileEvent event that contains the profile data for the specified user. /// </summary> /// <param name="userId">user ID</param> /// <returns>user profile</returns> public Profile GetUserProfile(UInt32 userId) { Profile tempProfile = new Profile(); errorHandler(EdkDll.EE_GetUserProfile(userId, tempProfile.GetHandle())); return tempProfile; }
private void cogDataFileWrite(string filename) { FileStream fs; fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite); BinaryWriter bw = new BinaryWriter(fs); //准备不同类型的数据 profile = EmoEngine.Instance.GetUserProfile(0); //利用Write 方法的多种重载形式写入数据 bw.Write(profile.GetBytes()); fs.Close(); bw.Close(); }
/// <summary> /// Loads an EmoEngine profile for the specified user. /// </summary> /// <param name="userId">user ID</param> /// <param name="profile">user profile previously returned from EmoEngine.</param> public void SetUserProfile(UInt32 userId, Profile profile) { if (profile == null) { throw new NullReferenceException(); } byte[] profileBytes = profile.GetBytes(); errorHandler(EdkDll.EE_SetUserProfile(userId, profileBytes, (UInt32)profileBytes.Length)); }
// 状态界面线程方法 void judge() { Thread.Sleep(1000); while (true) { //执行 使得状态改变 p.judgeOnContact(); //连接状态 if (p.getConnectedStatus() == true) { string str = "已连接"; this.contactStatusDelegateMethod(str); } else { string str = "未连入"; this.contactStatusDelegateMethod(str); electricPowerDelegateMethod(0, 5); //图形显示 electricPowerStatusDelegateMethod("0%"); //比例显示 this.starttimeDelegateMethod("00.00 s"); } //电量的显示 if (p.getConnectedStatus() == true) { //开始时间的显示 double timeFromStart = ((double)((int)((p.getTimeFromStart() + 0.005) * 100))) / 100; this.starttimeDelegateMethod(timeFromStart.ToString() + " s"); } //电量的显示 if (p.getConnectedStatus() == true) { Int32 chargeLevel = p.getChargeLevel(); Int32 maxChargeLevel = p.getMaxChargeLevel(); if (chargeLevel < 0) chargeLevel = 0; if (maxChargeLevel < 0) chargeLevel = 5; String chargePercentage = ((Int32)((chargeLevel * 1.0 / maxChargeLevel) * 100)).ToString() + "%"; electricPowerDelegateMethod(chargeLevel, maxChargeLevel); //图形显示 electricPowerStatusDelegateMethod(chargePercentage); //比例显示 } int signalStrength = p.getSignalStrength(); if (signalStrength == 2) { signalStrengthGoodDelegateMethod(); signalStrengthStatusDelegateMethod("强"); } else if (signalStrength == 1) { signalStrengthBadDelegateMethod(); signalStrengthStatusDelegateMethod("弱"); } else { signalStrengthNoSignalDelegateMethod(); signalStrengthStatusDelegateMethod("无信号"); p.disconnected(); } //信号可用性的显示 if (p.getConnectedStatus() == true) { int numCqChan = p.getNumContactQualityChannelsChargeLevel(); EdkDll.EE_EEG_ContactQuality_t[] cqfc = p.getContactQualityFromAllChannels(); bool flagP3 = false; bool flagP4 = false; for (Int32 i = 0; i < numCqChan; ++i) { //信号差 if (cqfc[i] == EdkDll.EE_EEG_ContactQuality_t.EEG_CQ_VERY_BAD) { // P3信号 if (i == 0) { this.p3BadDelegateMethod(); flagP3 = false; } // P4信号 else if (i == 1) { this.p4BadDelegateMethod(); flagP4 = false; } // AF3信号 else if (i == 2 && flagP3 == true && flagP4 == true) { this.af3BadDelegateMethod(); } // F7信号 else if (i == 3 && flagP3 == true && flagP4 == true) { this.f7BadDelegateMethod(); } // F3信号 else if (i == 4 && flagP3 == true && flagP4 == true) { this.f3BadDelegateMethod(); } // FC5信号 else if (i == 5 && flagP3 == true && flagP4 == true) { this.fc5BadDelegateMethod(); } // T7信号 else if (i == 6 && flagP3 == true && flagP4 == true) { this.t7BadDelegateMethod(); } // T7信号 else if (i == 7 && flagP3 == true && flagP4 == true) { this.p7BadDelegateMethod(); } // O1信号 else if (i == 8 && flagP3 == true && flagP4 == true) { this.o1BadDelegateMethod(); } // O2信号 else if (i == 9 && flagP3 == true && flagP4 == true) { this.o2BadDelegateMethod(); } // P8信号 else if (i == 10 && flagP3 == true && flagP4 == true) { this.p8BadDelegateMethod(); } // T8信号 else if (i == 11 && flagP3 == true && flagP4 == true) { this.t8BadDelegateMethod(); } // FC6信号 else if (i == 12 && flagP3 == true && flagP4 == true) { this.fc6BadDelegateMethod(); } // F4信号 else if (i == 13 && flagP3 == true && flagP4 == true) { this.f4BadDelegateMethod(); } // F8信号 else if (i == 14 && flagP3 == true && flagP4 == true) { this.f8BadDelegateMethod(); } // AF4信号 else if (i == 15 && flagP3 == true && flagP4 == true) { this.af4BadDelegateMethod(); } } //信号不好 else if (cqfc[i] == EdkDll.EE_EEG_ContactQuality_t.EEG_CQ_POOR) { // P3信号 if (i == 0) { this.p3PoorDelegateMethod(); flagP3 = false; } // P4信号 else if (i == 1) { this.p4PoorDelegateMethod(); flagP4 = false; } // AF3信号 else if (i == 2 && flagP3 == true && flagP4 == true) { this.af3PoorDelegateMethod(); } // F7信号 else if (i == 3 && flagP3 == true && flagP4 == true) { this.f7PoorDelegateMethod(); } // F3信号 else if (i == 4 && flagP3 == true && flagP4 == true) { this.f3PoorDelegateMethod(); } // FC5信号 else if (i == 5 && flagP3 == true && flagP4 == true) { this.fc5PoorDelegateMethod(); } // T7信号 else if (i == 6 && flagP3 == true && flagP4 == true) { this.t7PoorDelegateMethod(); } // T7信号 else if (i == 7 && flagP3 == true && flagP4 == true) { this.p7PoorDelegateMethod(); } // O1信号 else if (i == 8 && flagP3 == true && flagP4 == true) { this.o1PoorDelegateMethod(); } // O2信号 else if (i == 9 && flagP3 == true && flagP4 == true) { this.o2PoorDelegateMethod(); } // P8信号 else if (i == 10 && flagP3 == true && flagP4 == true) { this.p8PoorDelegateMethod(); } // T8信号 else if (i == 11 && flagP3 == true && flagP4 == true) { this.t8PoorDelegateMethod(); } // FC6信号 else if (i == 12 && flagP3 == true && flagP4 == true) { this.fc6PoorDelegateMethod(); } // F4信号 else if (i == 13 && flagP3 == true && flagP4 == true) { this.f4PoorDelegateMethod(); } // F8信号 else if (i == 14 && flagP3 == true && flagP4 == true) { this.f8PoorDelegateMethod(); } // AF4信号 else if (i == 15 && flagP3 == true && flagP4 == true) { this.af4PoorDelegateMethod(); } } //信号良好 else if (cqfc[i] == EdkDll.EE_EEG_ContactQuality_t.EEG_CQ_FAIR) { // P3信号 if (i == 0) { this.p3FairDelegateMethod(); flagP3 = false; } // P4信号 else if (i == 1) { this.p4FairDelegateMethod(); flagP4 = false; } // AF3信号 else if (i == 2 && flagP3 == true && flagP4 == true) { this.af3FairDelegateMethod(); } // F7信号 else if (i == 3 && flagP3 == true && flagP4 == true) { this.f7FairDelegateMethod(); } // F3信号 else if (i == 4 && flagP3 == true && flagP4 == true) { this.f3FairDelegateMethod(); } // FC5信号 else if (i == 5 && flagP3 == true && flagP4 == true) { this.fc5FairDelegateMethod(); } // T7信号 else if (i == 6 && flagP3 == true && flagP4 == true) { this.t7FairDelegateMethod(); } // T7信号 else if (i == 7 && flagP3 == true && flagP4 == true) { this.p7FairDelegateMethod(); } // O1信号 else if (i == 8 && flagP3 == true && flagP4 == true) { this.o1FairDelegateMethod(); } // O2信号 else if (i == 9 && flagP3 == true && flagP4 == true) { this.o2FairDelegateMethod(); } // P8信号 else if (i == 10 && flagP3 == true && flagP4 == true) { this.p8FairDelegateMethod(); } // T8信号 else if (i == 11 && flagP3 == true && flagP4 == true) { this.t8FairDelegateMethod(); } // FC6信号 else if (i == 12 && flagP3 == true && flagP4 == true) { this.fc6FairDelegateMethod(); } // F4信号 else if (i == 13 && flagP3 == true && flagP4 == true) { this.f4FairDelegateMethod(); } // F8信号 else if (i == 14 && flagP3 == true && flagP4 == true) { this.f8FairDelegateMethod(); } // AF4信号 else if (i == 15 && flagP3 == true && flagP4 == true) { this.af4FairDelegateMethod(); } } //信号好 else if (cqfc[i] == EdkDll.EE_EEG_ContactQuality_t.EEG_CQ_GOOD) { // P3信号 if (i == 0) { this.p3GoodDelegateMethod(); flagP3 = true; } // P4信号 else if (i == 1) { this.p4GoodDelegateMethod(); flagP4 = true; } // AF3信号 else if (i == 2 && flagP3 == true && flagP4 == true) { this.af3GoodDelegateMethod(); } // F7信号 else if (i == 3 && flagP3 == true && flagP4 == true) { this.f7GoodDelegateMethod(); } // F3信号 else if (i == 4 && flagP3 == true && flagP4 == true) { this.f3GoodDelegateMethod(); } // FC5信号 else if (i == 5 && flagP3 == true && flagP4 == true) { this.fc5GoodDelegateMethod(); } // T7信号 else if (i == 6 && flagP3 == true && flagP4 == true) { this.t7GoodDelegateMethod(); } // T7信号 else if (i == 7 && flagP3 == true && flagP4 == true) { this.p7GoodDelegateMethod(); } // O1信号 else if (i == 8 && flagP3 == true && flagP4 == true) { this.o1GoodDelegateMethod(); } // O2信号 else if (i == 9 && flagP3 == true && flagP4 == true) { this.o2GoodDelegateMethod(); } // P8信号 else if (i == 10 && flagP3 == true && flagP4 == true) { this.p8GoodDelegateMethod(); } // T8信号 else if (i == 11 && flagP3 == true && flagP4 == true) { this.t8GoodDelegateMethod(); } // FC6信号 else if (i == 12 && flagP3 == true && flagP4 == true) { this.fc6GoodDelegateMethod(); } // F4信号 else if (i == 13 && flagP3 == true && flagP4 == true) { this.f4GoodDelegateMethod(); } // F8信号 else if (i == 14 && flagP3 == true && flagP4 == true) { this.f8GoodDelegateMethod(); } // AF4信号 else if (i == 15 && flagP3 == true && flagP4 == true) { this.af4GoodDelegateMethod(); } } //没信号 else { // P3信号 if (i == 0) { this.p3NoSignalDelegateMethod(); flagP3 = false; } // P4信号 else if (i == 1) { this.p4NoSignalDelegateMethod(); flagP4 = false; } if (flagP4 == false && flagP3 == false) { // 显示改为没信号 this.af3NoSignalDelegateMethod(); this.f7NoSignalDelegateMethod(); this.f3NoSignalDelegateMethod(); this.fc5NoSignalDelegateMethod(); this.t7NoSignalDelegateMethod(); this.p7NoSignalDelegateMethod(); this.o1NoSignalDelegateMethod(); this.o2NoSignalDelegateMethod(); this.p8NoSignalDelegateMethod(); this.t8NoSignalDelegateMethod(); this.fc6NoSignalDelegateMethod(); this.f4NoSignalDelegateMethod(); this.f8NoSignalDelegateMethod(); this.af4NoSignalDelegateMethod(); } } } } else { // 显示改为没信号 this.p3NoSignalDelegateMethod(); this.p4NoSignalDelegateMethod(); this.af3NoSignalDelegateMethod(); this.f7NoSignalDelegateMethod(); this.f3NoSignalDelegateMethod(); this.fc5NoSignalDelegateMethod(); this.t7NoSignalDelegateMethod(); this.p7NoSignalDelegateMethod(); this.o1NoSignalDelegateMethod(); this.o2NoSignalDelegateMethod(); this.p8NoSignalDelegateMethod(); this.t8NoSignalDelegateMethod(); this.fc6NoSignalDelegateMethod(); this.f4NoSignalDelegateMethod(); this.f8NoSignalDelegateMethod(); this.af4NoSignalDelegateMethod(); } Thread.Sleep(100); if (p.getConnectedStatus() == true && fll == true) { fll = false; // 读取本地脑波数据 if (File.Exists(cogDataFileName)) { EmoEngine.Instance.LoadUserProfile(0, cogDataFileName); profile = EmoEngine.Instance.GetUserProfile(0); EmoEngine.Instance.SetUserProfile(0, profile); Console.WriteLine("load profile"); } // 读取本地脑波已存在的数据数量 // 读取本地脑波数据 if (File.Exists(cogNumFileName)) { cogNum = cogNumFileRead(cogNumFileName); for (int i = 0; i < cogNum.Length; i++) { if (cogNum[i].ToString() == "N") { cogStatusOk_1DelegateMethod(); } else if (cogNum[i].ToString() == "U") { cogStatusOk_2DelegateMethod(); } else if (cogNum[i].ToString() == "D") { cogStatusOk_3DelegateMethod(); } else if (cogNum[i].ToString() == "L") { cogStatusOk_4DelegateMethod(); } else if (cogNum[i].ToString() == "R") { cogStatusOk_5DelegateMethod(); } else if (cogNum[i].ToString() == "F") { cogStatusOk_6DelegateMethod(); } else if (cogNum[i].ToString() == "B") { cogStatusOk_7DelegateMethod(); } } } } } }