public void OnUpdateMindwaveData(MindwaveDataModel _Data) { //sensorData = _Data.eSense.attention; Debug.Log("nouha meditation : " + _Data.eSense.meditation); meditation = _Data.eSense.meditation; Debug.Log("nouha attention : " + _Data.eSense.attention); attention = _Data.eSense.attention; }
/// <summary> /// Makes an instance of MindwaveDataModel with the given meditation and attention as eSense values. /// </summary> private MindwaveDataModel MakeMindwaveData(float _Meditation, float _Attention) { MindwaveDataModel data = new MindwaveDataModel(); data.eSense.meditation = Mathf.FloorToInt(_Meditation); data.eSense.attention = Mathf.FloorToInt(_Attention); return(data); }
public void OnUpdateMindwaveData(MindwaveDataModel _Data) { if (m_MindwaveData.Count >= m_MaxDataLength) { m_MindwaveData.Dequeue(); } if (m_MindwaveData.Count < m_MaxDataLength) { m_MindwaveData.Enqueue(_Data); } }
/// <summary> /// Called when the MindwaveController sends new values. /// </summary> public void OnUpdateMindwaveData(MindwaveDataModel _Data) { // Update bomb renderer (make the bomb grow depending on the meditation value) m_BombRenderer.Grow(_Data.eSense.meditation); UpdateWickRenderer(_Data.eSense.attention); // If the player is not in a specific phase if (m_CurrentBlastPhase == BlastPhase.None) { // If its meditation is sufficient if (_Data.eSense.meditation >= m_MeditationToInitBlast) { // Start Meditation phase LoadBlast(); } } // If the player is in Meditation phase else if (m_CurrentBlastPhase == BlastPhase.Meditation) { // If its meditation is too low if (_Data.eSense.meditation <= m_MinMeditation) { // Cancels the meditation phase CancelMeditationPhase(); } } // If the player is in focus phase else if (m_CurrentBlastPhase == BlastPhase.Focus) { // If the attention is sufficient if (_Data.eSense.attention >= m_RequiredAttention) { // Make the bomb explode TriggerBlast(); } } }
/// <summary> /// Read datas from Mindwave, and parse them. /// Also call the relative update events. /// </summary> /// <param name="_UpdateRate">Defines the interval between each stream read operation.</param> private IEnumerator ParseData(float _UpdateRate) { if (m_DataStream.CanRead) { int streamBytes = m_DataStream.Read(m_Buffer, 0, m_Buffer.Length); string[] packets = Encoding.ASCII.GetString(m_Buffer, 0, streamBytes).Split('\r'); if (m_ShowDataPackets) { Debug.Log(Encoding.ASCII.GetString(m_Buffer, 0, streamBytes)); } foreach (string packet in packets) { if (string.IsNullOrEmpty(packet)) { continue; } try { // Convert data to JSON IDictionary data = (IDictionary)JsonConvert.Import(typeof(IDictionary), packet); // This kind of packet contains all the EEG infos such as brain waves and attention/meditation metrics if (data.Contains(POOR_SIGNAL_LABEL)) { MindwaveDataModel model = JsonUtility.FromJson <MindwaveDataModel>(packet); // If the current packet reveal a connection trouble, call OnDisconnect delegate if (model.NoSignal) { ConnectedFlag = false; } // Else, data are sent, so emit it else { ConnectedFlag = true; PendingConnection = false; if (OnUpdateMindwaveData != null) { OnUpdateMindwaveData(model); } } } // Check for EEG raw data, and emit it else if (data.Contains(RAW_EEG_LABEL)) { if (OnUpdateRawEEG != null) { OnUpdateRawEEG(int.Parse(data[RAW_EEG_LABEL].ToString())); } } // Check for eye blinking, and emit it else if (data.Contains(BLINK_STRENGTH_LABEL)) { if (OnUpdateBlink != null) { OnUpdateBlink(int.Parse(data[BLINK_STRENGTH_LABEL].ToString())); } } } catch (IOException _JsonException) { if (m_ShowStreamErrors) { Debug.LogWarning("MindwaveBinding stream Error: " + _JsonException.ToString()); } } catch (JsonException _JsonException) { if (m_ShowStreamErrors) { Debug.LogWarning("MindwaveBinding stream Error: " + _JsonException.ToString()); } } catch (System.Exception _Exception) { Debug.LogError("MindwaveBinding error: " + _Exception.ToString()); } } } // Else, if the stream can't be read else { ConnectedFlag = false; } yield return(new WaitForSeconds(_UpdateRate)); m_StreamRoutine = StartCoroutine(ParseData(_UpdateRate)); }
public void OnUpdateMindwaveData(MindwaveDataModel _Data) { AttentionLevel = _Data.eSense.attention; MediLevel = _Data.eSense.meditation; }
public void OnUpdateMindwaveData(MindwaveDataModel _Data) { m_MindwaveData = _Data; }