Пример #1
0
        IEnumerator DetectSensor()
        {
            while (this.gameObject.activeSelf && isInitialized)
            {
                if (isLinkHubConnected && isLinkCoreConnected && sensorStatusData != null)
                {
                    // Sensor Connection
                    int sensorScore = 0;
                    int numSensor   = System.Enum.GetValues(typeof(EEGSensorID)).Length;
                    for (int i = 0; i < numSensor; i++)
                    {
                        int score = sensorStatusData.IsSensorOn((EEGSensorID)i) ? 1 : 0;
                        sensorScore += score;
                    }
                    sensorScoreList.Add(sensorScore);
                    if (sensorScoreList.Count > 20)
                    {
                        sensorScoreList.RemoveAt(0);
                    }
                    if (sensorScoreList.Count >= 20 && sensorScoreList.Sum() < 110)
                    {
                        ShowMessage(LooxidLinkMessageType.SensorOff);
                    }
                    else
                    {
                        HideMessage(LooxidLinkMessageType.SensorOff);
                    }

                    // Noise Signal
                    int noiseScore = 0;
                    for (int i = 0; i < numSensor; i++)
                    {
                        int score = sensorStatusData.IsNoiseSignal((EEGSensorID)i) ? 0 : 1;
                        noiseScore += score;
                    }
                    noiseScoreList.Add(noiseScore);
                    if (noiseScoreList.Count > 20)
                    {
                        noiseScoreList.RemoveAt(0);
                    }
                    if (noiseScoreList.Count >= 20 && noiseScoreList.Sum() < 110)
                    {
                        ShowMessage(LooxidLinkMessageType.NoiseSignal);
                    }
                    else
                    {
                        HideMessage(LooxidLinkMessageType.NoiseSignal);
                    }
                }
                else
                {
                    HideMessage(LooxidLinkMessageType.SensorOff);
                    HideMessage(LooxidLinkMessageType.NoiseSignal);
                }

                yield return(new WaitForSeconds(0.1f));
            }
        }
        IEnumerator SuperPower()
        {
            while (true)
            {
                yield return(new WaitForSeconds(1.0f));

                if (sensorStatusData != null)
                {
                    if (!sensorStatusData.IsSensorOn(EEGSensorID.AF3) && !sensorStatusData.IsSensorOn(EEGSensorID.AF4) &&
                        !sensorStatusData.IsSensorOn(EEGSensorID.Fp1) && !sensorStatusData.IsSensorOn(EEGSensorID.Fp2) &&
                        !sensorStatusData.IsSensorOn(EEGSensorID.AF7) && !sensorStatusData.IsSensorOn(EEGSensorID.AF8))
                    {
                        materialB.DisableKeyword("_EMISSION");
                        materialO.DisableKeyword("_EMISSION");
                        materialR.DisableKeyword("_EMISSION");
                        targetGravity = -9.81f;
                        powerData.Clear();
                    }
                    else
                    {
                        if (prevPowerData < 0.0f)
                        {
                            prevPowerData = powerData.Average();

                            materialB.DisableKeyword("_EMISSION");
                            materialO.DisableKeyword("_EMISSION");
                            materialR.DisableKeyword("_EMISSION");
                            targetGravity = -9.81f;
                        }
                        else
                        {
                            if (powerData.Average() > prevPowerData || powerData.Average() > 0.7f)
                            {
                                materialB.EnableKeyword("_EMISSION");
                                materialO.EnableKeyword("_EMISSION");
                                materialR.EnableKeyword("_EMISSION");

                                float gravity_power = powerData.Average() * 1.5f;
                                targetGravity = gravity_power;

                                for (int i = 0; i < CubeList.Count; i++)
                                {
                                    CubeList[i].GetComponent <Rigidbody>().AddTorque(new Vector3(Random.Range(-3.0f, 3.0f), Random.Range(-3.0f, 3.0f), Random.Range(-3.0f, 3.0f)));
                                }
                            }
                            else
                            {
                                materialB.DisableKeyword("_EMISSION");
                                materialO.DisableKeyword("_EMISSION");
                                materialR.DisableKeyword("_EMISSION");
                                targetGravity = -9.81f;
                            }
                        }

                        prevPowerData = powerData.Average();
                        powerData.Clear();
                    }
                }
            }
        }
Пример #3
0
        IEnumerator DisplayData()
        {
            while (this.gameObject.activeSelf)
            {
                yield return(new WaitForSeconds(0.1f));

                if (this.SelectTab == Tab2DVisualizer.SENSOR_STATUS)
                {
                    if (sensorStatusData != null)
                    {
                        Color32 offColor = new Color32(64, 64, 64, 255);

                        AF3SensorImage.color = sensorStatusData.IsSensorOn(EEGSensorID.AF3) ? (Color)LooxidLinkManager.linkColor : (Color)offColor;
                        AF4SensorImage.color = sensorStatusData.IsSensorOn(EEGSensorID.AF4) ? (Color)LooxidLinkManager.linkColor : (Color)offColor;
                        Fp1SensorImage.color = sensorStatusData.IsSensorOn(EEGSensorID.Fp1) ? (Color)LooxidLinkManager.linkColor : (Color)offColor;
                        Fp2SensorImage.color = sensorStatusData.IsSensorOn(EEGSensorID.Fp2) ? (Color)LooxidLinkManager.linkColor : (Color)offColor;
                        AF7SensorImage.color = sensorStatusData.IsSensorOn(EEGSensorID.AF7) ? (Color)LooxidLinkManager.linkColor : (Color)offColor;
                        AF8SensorImage.color = sensorStatusData.IsSensorOn(EEGSensorID.AF8) ? (Color)LooxidLinkManager.linkColor : (Color)offColor;
                    }
                }
                else if (this.SelectTab == Tab2DVisualizer.MIND_INDEX)
                {
                    LeftActivityIndicator.SetValue((float)leftActivity.value);
                    RightActivityIndicator.SetValue((float)rightActivity.value);
                    AttentionIndicator.SetValue((float)attention.value);
                    RelaxationIndicator.SetValue((float)relaxation.value);
                }
                else if (this.SelectTab == Tab2DVisualizer.FEATURE_INDEX)
                {
                    List <EEGFeatureIndex> featureIndexList = LooxidLinkData.Instance.GetEEGFeatureIndexData(10.0f);

                    if (featureIndexList.Count > 0)
                    {
                        List <double> deltaScaleDataList = new List <double>();
                        List <double> thetaScaleDataList = new List <double>();
                        List <double> alphaScaleDataList = new List <double>();
                        List <double> betaScaleDataList  = new List <double>();
                        List <double> gammaScaleDataList = new List <double>();

                        for (int i = 0; i < featureIndexList.Count; i++)
                        {
                            double deltaValue = featureIndexList[i].Delta(SelectChannel);
                            double thetaValue = featureIndexList[i].Theta(SelectChannel);
                            double alphaValue = featureIndexList[i].Alpha(SelectChannel);
                            double betaValue  = featureIndexList[i].Beta(SelectChannel);
                            double gammaValue = featureIndexList[i].Gamma(SelectChannel);

                            if (!double.IsInfinity(deltaValue) && !double.IsNaN(deltaValue))
                            {
                                deltaScaleDataList.Add(deltaValue);
                            }
                            if (!double.IsInfinity(thetaValue) && !double.IsNaN(thetaValue))
                            {
                                thetaScaleDataList.Add(thetaValue);
                            }
                            if (!double.IsInfinity(alphaValue) && !double.IsNaN(alphaValue))
                            {
                                alphaScaleDataList.Add(alphaValue);
                            }
                            if (!double.IsInfinity(betaValue) && !double.IsNaN(betaValue))
                            {
                                betaScaleDataList.Add(betaValue);
                            }
                            if (!double.IsInfinity(gammaValue) && !double.IsNaN(gammaValue))
                            {
                                gammaScaleDataList.Add(gammaValue);
                            }
                        }

                        delta.SetScale(deltaScaleDataList);
                        theta.SetScale(thetaScaleDataList);
                        alpha.SetScale(alphaScaleDataList);
                        beta.SetScale(betaScaleDataList);
                        gamma.SetScale(gammaScaleDataList);
                    }

                    DeltaIndicator.SetValue((float)delta.value);
                    ThetaIndicator.SetValue((float)theta.value);
                    AlphaIndicator.SetValue((float)alpha.value);
                    BetaIndicator.SetValue((float)beta.value);
                    GammaIndicator.SetValue((float)gamma.value);
                }
            }
        }
Пример #4
0
        IEnumerator DisplayData()
        {
            while (this.gameObject.activeSelf)
            {
                yield return(new WaitForSeconds(0.1f));

                // Device Status: Connected Status
                if (ConnectedText[0] != null)
                {
                    ConnectedText[0].text  = (LooxidLinkManager.Instance.isLinkHubConnected) ? "Connected" : "Disconnected";
                    ConnectedText[0].color = (LooxidLinkManager.Instance.isLinkHubConnected) ? ConnectedColor : DisconnectedColor;
                }
                if (ConnectedImage[0] != null)
                {
                    ConnectedImage[0].sprite = (LooxidLinkManager.Instance.isLinkHubConnected) ? ConnectedSprite[0] : ConnectedSprite[1];
                }
                if (ConnectedText[1] != null)
                {
                    ConnectedText[1].text  = (LooxidLinkManager.Instance.isLinkCoreConnected) ? "Connected" : "Disconnected";
                    ConnectedText[1].color = (LooxidLinkManager.Instance.isLinkCoreConnected) ? ConnectedColor : DisconnectedColor;
                }
                if (ConnectedImage[1] != null)
                {
                    ConnectedImage[1].sprite = (LooxidLinkManager.Instance.isLinkCoreConnected) ? ConnectedSprite[0] : ConnectedSprite[1];
                }

                // Device Status: Sensor Status
                if (sensorStatusData != null)
                {
                    int numChannel = System.Enum.GetValues(typeof(EEGSensorID)).Length;
                    for (int i = 0; i < numChannel; i++)
                    {
                        bool isSensorOn = sensorStatusData.IsSensorOn((EEGSensorID)i);
                        if (SensorStatusText[i] != null)
                        {
                            SensorStatusText[i].text   = isSensorOn ? "ON" : "OFF";
                            SensorStatusText[i].color  = isSensorOn ? ConnectedColor : DisconnectedColor;
                            SensorStatusImage[i].color = isSensorOn ? ConnectedColor : DisconnectedColor;
                        }
                    }
                }


                // Mind Indexes: Indicators
                LeftActivityIndicator.SetValue((float)leftActivity.value);
                RightActivityIndicator.SetValue((float)rightActivity.value);
                AttentionIndicator.SetValue((float)attention.value);
                RelaxationIndicator.SetValue((float)relaxation.value);
                AsymmetryText.text = asymmetry.value.ToString("F3");


                // Mind Indexes: Charts
                List <double>    leftActivityDataList  = new List <double>();
                List <double>    rightActivityDataList = new List <double>();
                List <double>    attentionDataList     = new List <double>();
                List <double>    relaxationDataList    = new List <double>();
                int              numIndexList          = 5 * linkFequency;
                List <MindIndex> mindIndexList         = LooxidLinkData.Instance.GetMindIndexData(7.0f);
                for (int i = 0; i < mindIndexList.Count; i++)
                {
                    if (i < numIndexList)
                    {
                        double mindLeftActivity  = (double.IsNaN(mindIndexList[i].leftActivity)) ? 0.0f : LooxidLinkUtility.Scale(LooxidLink.MIND_INDEX_SCALE_MIN, LooxidLink.MIND_INDEX_SCALE_MAX, 0.0f, 1.0f, mindIndexList[i].leftActivity);
                        double mindRightActivity = (double.IsNaN(mindIndexList[i].rightActivity)) ? 0.0f : LooxidLinkUtility.Scale(LooxidLink.MIND_INDEX_SCALE_MIN, LooxidLink.MIND_INDEX_SCALE_MAX, 0.0f, 1.0f, mindIndexList[i].rightActivity);
                        double mindAttention     = (double.IsNaN(mindIndexList[i].attention)) ? 0.0f : LooxidLinkUtility.Scale(LooxidLink.MIND_INDEX_SCALE_MIN, LooxidLink.MIND_INDEX_SCALE_MAX, 0.0f, 1.0f, mindIndexList[i].attention);
                        double mindRelaxation    = (double.IsNaN(mindIndexList[i].relaxation)) ? 0.0f : LooxidLinkUtility.Scale(LooxidLink.MIND_INDEX_SCALE_MIN, LooxidLink.MIND_INDEX_SCALE_MAX, 0.0f, 1.0f, mindIndexList[i].relaxation);
                        leftActivityDataList.Add(mindLeftActivity);
                        rightActivityDataList.Add(mindRightActivity);
                        attentionDataList.Add(mindAttention);
                        relaxationDataList.Add(mindRelaxation);
                    }
                }
                leftActivityDataList.Reverse();
                rightActivityDataList.Reverse();
                attentionDataList.Reverse();
                relaxationDataList.Reverse();

                if (LeftActivityChart != null)
                {
                    LeftActivityChart.SetValue(leftActivityDataList.ToArray());
                }
                if (RightActivityChart != null)
                {
                    RightActivityChart.SetValue(rightActivityDataList.ToArray());
                }
                if (AttentionChart != null)
                {
                    AttentionChart.SetValue(attentionDataList.ToArray());
                }
                if (RelaxationChart != null)
                {
                    RelaxationChart.SetValue(relaxationDataList.ToArray());
                }

                // Feature Indexes: Charts
                int numIndexes = System.Enum.GetValues(typeof(FeatureIndexEnum)).Length;
                for (int i = 0; i < numIndexes; i++)
                {
                    FeatureIndexCharts[i].SetValue(GetFeatureDataList(SelectFeatureSensorID, (FeatureIndexEnum)i).ToArray());
                }
            }
        }