示例#1
0
    void Update()
    {
        // ESCAPE: Pause the animation (does not stop acquisition), show toggle button
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (animationRunning)
            {
                animationRunning = false;
                toggleButton.gameObject.SetActive(true);
                text.text     += "\nPAUSIERT";
                Time.timeScale = 0f;
            }
            else
            {
                toggleButton.gameObject.SetActive(false);
                animationRunning = true;
                Time.timeScale   = 1f;
            }
        }

        float[] values = new float[8];

        // for non-live testing purposes, read line of data from prerecorded file
        if (useRecordedFile)
        {
            values = csvP.ReadLine(8);
        }
        else if (acquisitionRunning)
        {
            values = ReadUnicornData();
        }

        if (animationRunning)
        {
            if (useRecordedFile) // if using our test file
            {
                for (int i = 0; i < 8; i++)
                {
                    arrays[i][pos] = Math.Abs(values[i] / 2000000) + 3; // normalize values in some way, save them in the buffer channels
                }
            }

            if (!useRecordedFile)
            {
                double value0 = Math.Abs(values[0]); // filtered value of eeg1

                if (count < startFrames)             // find an initial baseline value
                {
                    if (count > 59)
                    {
                        startAvg += value0 / (startFrames - 60);
                    }
                    count++;
                }
                else
                {
                    baselineFound   = true;
                    eeg1Buffer[pos] = value0;  // filtered value of eeg1
                }
            }

            // move to next buffer position for next update call
            pos = (pos + 1) % arrays[0].Length;
            // if all buffers are full (every time 60 values have been read)
            if (pos == 0)
            {
                float arrayMax = 0;
                if (useRecordedFile)
                {
                    // find the max value out of all 8 buffers
                    for (int i = 0; i < 8; i++)
                    {
                        if (arrayMax < arrays[i].Max())
                        {
                            arrayMax = arrays[i].Max();
                        }
                    }
                }
                else
                {
                    // difference of buffer max and baseline, scaled down
                    if (baselineFound)
                    {
                        arrayMax = (Math.Abs((float)eeg1Buffer.Max() - (float)startAvg)) / 30 + 3;
                    }
                }

                // change noise strength to array max
                var noise = ps.noise;
                noise.strength = arrayMax;
                print(arrayMax);

                // on-screen debug text
                text.text = arrayMax.ToString("N2") + "\nbaseline: " + startAvg.ToString("N2");
                if (acquisitionRunning)
                {
                    text.text += "\nacquisition running";
                }
            }
        }
    }
示例#2
0
    void Update()
    {
        if (animationRunning)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                animationRunning = false;
                text.text       += "\nPAUSIERT";
                Time.timeScale   = 0f;
            }


            float[] values;

            // particle system modules
            var noise = ps.noise;

            // read values from each EEG channel into a buffer

            // for non-live testing purposes, read line of data from prerecorded file
            if (useRecordedFile)
            {
                values = csvP.ReadLine(8);
            }
            else
            {
                values = ReadUnicornData();
            }

            for (int i = 0; i < 8; i++)
            {
                print(values[i]);

                // normalize values in some way, save them in the buffer channels (TODO: find good way to normalize)
                arrays[i][pos] = Math.Abs(values[i] * 1 / 2000000) + 3;
            }

            pos = (pos + 1) % arrays[0].Length;

            // if all buffers are full (every time 60 values have been read)
            if (pos == 0)
            {
                // find the max value out of all 8 buffers
                float arrayMax = 0;
                for (int i = 0; i < 8; i++)
                {
                    if (arrayMax < arrays[i].Max())
                    {
                        arrayMax = arrays[i].Max();
                    }
                }

                // manipulate noise module strength
                noise.strength = arrayMax;

                // on-screen debug text
                text.text = "Höchster Wert auf allen Kanälen:\n" + arrayMax.ToString("F2");
            }
        }
        else
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                animationRunning = true;
                Time.timeScale   = 1f;
            }
        }
    }