Example #1
0
        private void plotRaw(Device.DataEventArgs de)
        {
            NeuroSky.ThinkGear.DataRow[] tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            if (eegTime && closeAllThread == false)
            {
                chart6.Invoke((MethodInvoker)(() => chart6.ChartAreas[0].AxisY.Minimum = -400));
                chart6.Invoke((MethodInvoker)(() => chart6.ChartAreas[0].AxisY.Maximum = 400));
                for (int i = 0; i < tgParser.ParsedData.Length; i++)
                {
                    if (tgParser.ParsedData[i].ContainsKey("Raw"))
                    {
                        eegTime = false;
                        chart6.Invoke((MethodInvoker)(() => chart6.Series["EEG"].Points.AddY(tgParser.ParsedData[i]["Raw"])));
                    }
                    if (chart6.Series["EEG"].Points.Count > 200)
                    {
                        chart6.Invoke((MethodInvoker)(() => chart6.Series["EEG"].Points.RemoveAt(0)));
                    }
                }
            }

            Thread.CurrentThread.Abort();
        }
Example #2
0
        void OnDataReceived(object sender, EventArgs e)
        {
            Device.DataEventArgs de = (Device.DataEventArgs)e;
            NeuroSky.ThinkGear.DataRow[] tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();
            tgParser.Read(de.DataRowArray);

            bool hasBlink = false;
            int blinkeye = 0;

            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (radio_att.Checked==true
                    && tgParser.ParsedData[i].ContainsKey("Attention"))
                {

                    updateAttentionMode(tgParser, i);

                }
                else if (radio_me.Checked==true
                    && tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    updateMediationMode(tgParser, i);
                }
                else
                {
                    updateBlinkMode(tgParser, ref hasBlink, ref blinkeye, i);
                }
            }
        }
Example #3
0
        // Called when data is received from a device
        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[] tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();
            tgParser.Read(de.DataRowArray);

            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            for (int i = 0; i < tgParser.ParsedData.Length; i++){

                if (tgParser.ParsedData[i].ContainsKey("Raw")){

                    //Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);

                }

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal")){

                    //The following line prints the Time associated with the parsed data
                    //Console.WriteLine("Time:" + tgParser.ParsedData[i]["Time"]);

                    //A Poor Signal value of 0 indicates that your headset is fitting properly
                    Console.WriteLine("Poor Signal:" + tgParser.ParsedData[i]["PoorSignal"]);

                    poorSig = (byte)tgParser.ParsedData[i]["PoorSignal"];
                }

                if (tgParser.ParsedData[i].ContainsKey("Attention")) {

                    //Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);

                }

                if (tgParser.ParsedData[i].ContainsKey("Meditation")) {

                    //Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);

                }

                if(tgParser.ParsedData[i].ContainsKey("EegPowerDelta")) {

                    //Console.WriteLine("Delta: " + tgParser.ParsedData[i]["EegPowerDelta"]);

                }

                if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                {

                    //Console.WriteLine("Eyeblink " + tgParser.ParsedData[i]["BlinkStrength"]);

                }

            }
        }
Example #4
0
        // Called when data is received from a device

        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);



            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    //Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    //The following line prints the Time associated with the parsed data
                    //Console.WriteLine("Time:" + tgParser.ParsedData[i]["Time"]);

                    //A Poor Signal value of 0 indicates that your headset is fitting properly
                    Console.WriteLine("Poor Signal:" + tgParser.ParsedData[i]["PoorSignal"]);

                    poorSig = (byte)tgParser.ParsedData[i]["PoorSignal"];
                }


                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    //Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                }


                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    //Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                }


                if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta"))
                {
                    //Console.WriteLine("Delta: " + tgParser.ParsedData[i]["EegPowerDelta"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                {
                    //Console.WriteLine("Eyeblink " + tgParser.ParsedData[i]["BlinkStrength"]);
                }
            }
        }
Example #5
0
        // Called when data is received from a device

        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);



            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);

                    double Rd = tgParser.ParsedData[i]["Meditation"];

                    Rd = (Rd - 0) / (100 - 0) * (255 - 0) + 0;

                    int R = Convert.ToInt32(Rd);


                    if (Lv <= R)
                    {
                        G  = G - Math.Abs(R - Lv);
                        Lv = R;
                    }

                    if (Lv > R)
                    {
                        G  = G + Math.Abs(Lv - R);
                        Lv = R;
                    }

                    var send = R + ";" + G + ";";

                    port.WriteLine(send);

                    Console.WriteLine(send);

                    Thread.Sleep(1000);

                    Console.WriteLine("recieved = " + port.ReadExisting());
                }
            }
        }
Example #6
0
        private void plotParam(Device.DataEventArgs de)
        {
            NeuroSky.ThinkGear.DataRow[] tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    label2.Invoke((MethodInvoker)(() => label2.Text = "Signal: " + (100 - tgParser.ParsedData[i]["PoorSignal"]) + "%"));
                }

                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    label3.Invoke((MethodInvoker)(() => label3.Text = "Attention: " + tgParser.ParsedData[i]["Attention"]));
                    progressBar1.Invoke((MethodInvoker)(() => progressBar1.Value = (int)tgParser.ParsedData[i]["Attention"]));
                    // if (tgParser.ParsedData[i]["Attention"] > 90 && atflag == false)
                    //{
                    //     System.Diagnostics.Process.Start("C:\\Users\\Rs\\Documents\\test.mp3");
                    //   atflag = true;
                    // }
                }

                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    label4.Invoke((MethodInvoker)(() => label4.Text = "Meditation: " + tgParser.ParsedData[i]["Meditation"]));
                    progressBar2.Invoke((MethodInvoker)(() => progressBar2.Value = (int)tgParser.ParsedData[i]["Meditation"]));
                    if (tgParser.ParsedData[i]["Meditation"] > 90 && atflag == false)
                    {
                        System.Diagnostics.Process.Start("C:\\Users\\Rs\\Documents\\test.mp3");
                        //atflag = true;
                    }
                }



                if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                {
                    label13.Invoke((MethodInvoker)(() => label13.Text = "Blink: " + tgParser.ParsedData[i]["BlinkStrength"]));
                }


                if (closeAllThread)
                {
                    Thread.CurrentThread.Abort();
                }
            }
        }
Example #7
0
        // Called when data is received from a device

        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);



            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                    // Value between 0 and 100. How more relaxed you are how lower it is. How more stressed you are how
                    //higher it becomes.

                    WriteMessage(tgParser.ParsedData[i]["Meditation"].ToString() + ";");
                    //This is how to write a message to the Arduino
                }


                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                    //Value betweem 0 and 100. How more you focus on one object how higher this value becomes.
                }


                if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                {
                    if (tgParser.ParsedData[i]["BlinkStrength"] > 60)
                    {
                        Console.WriteLine("Blink detected");
                    }

                    else
                    {
                        Console.WriteLine("No Blink detected");
                    }
                }
            }
        }
        private void OnDataReceived(object sender, EventArgs e)
        {
            Device d = (Device)sender;
            TextBox lm_value = new TextBox();
            lm_value.Text = "datarecieved";
            Device.DataEventArgs de = (Device.DataEventArgs)e;
            NeuroSky.ThinkGear.DataRow[] tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();
            tgParser.Read(de.DataRowArray);

            //bool hasBlink = false;
            //int blinkeye = 0;

            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            //            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            //            {
            //                if (radio_att.Checked == true & tgParser.ParsedData[i].ContainsKey("Attention")
            //                    )
            //                {
            //
            //                    updateAttentionMode(tgParser, i);
            //
            //                }
            //                else if (radio_me.Checked == true & tgParser.ParsedData[i].ContainsKey("Meditation")
            //                    )
            //                {
            //                    updateMediationMode(tgParser, i);
            //                }
            //
            //             }

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {

                    lm_value.AppendText("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                    Equals("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {

                    lm_value.AppendText("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                    Equals("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                }
            }
        }
    void HandleOnDataReceived(object sender, EventArgs e)
    {
        Debug.Log("ThinkGearController DataReceived: " + e);
        /* Cast the event sender as a Device object, and e as the Device's DataEventArgs */
        //Device d = (Device) sender;
        Device.DataEventArgs de = (Device.DataEventArgs)e;
        /* Create a TGParser to parse the Device's DataRowArray[] */
        TGParser tgParser = new TGParser();

        tgParser.Read(de.DataRowArray);
        /* Loop through parsed data TGParser for its parsed data... */
        for (int i = 0; i < tgParser.ParsedData.Length; i++)
        {
            ReportData(tgParser.ParsedData[i]);
        }
    }
Example #10
0
        // Called when data is received from a device

        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    Console.WriteLine("att Value:" + tgParser.ParsedData[i]["Attention"]);



                    if (tgParser.ParsedData[i]["Attention"] > 60)
                    {
                        port.WriteLine(1 + ";" + 0 + ";");
                        Console.WriteLine(1);
                    }
                    else
                    {
                        port.WriteLine(0 + ";" + 0 + ";");
                        Console.WriteLine(0);
                    }


                    Thread.Sleep(2000);

                    Console.WriteLine("recieved = " + port.ReadExisting());
                }
            }
        }
Example #11
0
        // Called when data is received from a device

        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);



            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);


                    double Med = tgParser.ParsedData[i]["Meditation"];

                    int MedValue = Convert.ToInt32(Med);

                    var send = MedValue + ";";

                    port.WriteLine(send);

                    Console.WriteLine(send);

                    Thread.Sleep(1500);

                    Console.WriteLine("recieved = " + port.ReadExisting());
                }
            }
        }
Example #12
0
        // Called when data is received from a device

        static void OnDataReceived(object sender, EventArgs e)
        {
            /* Cast the event sender as a Device object, and e as the Device's DataEventArgs */
            Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;

            /* Create a TGParser to parse the Device's DataRowArray[] */
            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            /* Loop through parsed data TGParser for its parsed data... */
            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                // See the Data Types documentation for valid keys such
                // as "Raw", "PoorSignal", "Attention", etc.

                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    Console.WriteLine("PQ Value:" + tgParser.ParsedData[i]["PoorSignal"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                }
            }
        }
Example #13
0
        // Called when data is received from a device
        public void OnDataReceived(object sender, EventArgs e)
        {
            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            /* Loops through the newly parsed data of the connected headset */
            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha"))
                {
                    AlphaValue = tgParser.ParsedData[i]["EegPowerAlpha"];
                    Console.WriteLine("Alpha: " + AlphaValue);
                    // Raise the AlphaReceived event with the new reading.
                    OnAlphaReceived(new AlphaReceivedEventArgs()
                    {
                        Alpha = AlphaValue
                    });
                }
            }
        }
    public void OnDataReceived(object sender, EventArgs e)
    {
        //Device d = (Device)sender;
        Device.DataEventArgs de = (Device.DataEventArgs)e;

        DataRow[] tempDataRowArray = de.DataRowArray;
        TGParser  tgParser         = new TGParser();

        tgParser.Read(de.DataRowArray);

        /* Loops through the newly parsed data of the connected headset*/
        // The comments below indicate and can be used to print out the different data outputs.
        String       ruta_archivo = System.AppDomain.CurrentDomain.BaseDirectory + "ondas.txt";
        StreamWriter archO        = File.AppendText(ruta_archivo);
        TimeSpan     stop;
        TimeSpan     start = new TimeSpan(DateTime.Now.Ticks);

        for (int i = 0; i < tgParser.ParsedData.Length; i++)
        {
            if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
            {
                //The following line prints the Time associated with the parsed data
                //Console.WriteLine("Time:" + tgParser.ParsedData[i]["Time"]);
                //A Poor Signal value of 0 indicates that your headset is fitting properly
                numS++;
                //Console.WriteLine("Poor Signal:" + tgParser.ParsedData[i]["PoorSignal"]);
                archO.WriteLine(numS);
                archO.WriteLine("Poor Signal: " + tgParser.ParsedData[i]["PoorSignal"]);
                PoorSig = (byte)tgParser.ParsedData[i]["PoorSignal"];
            }

            if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta"))
            {
                archO.WriteLine("Delta: " + tgParser.ParsedData[i]["EegPowerDelta"]);
                //Console.WriteLine("Delta: " + tgParser.ParsedData[i]["EegPowerDelta"]);
            }

            if (tgParser.ParsedData[i].ContainsKey("EegPowerTheta"))
            {
                archO.WriteLine("Theta: " + tgParser.ParsedData[i]["EegPowerTheta"]);
                //Console.WriteLine("Theta: " + tgParser.ParsedData[i]["EegPowerTheta"]);
            }

            if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha1"))
            {
                archO.WriteLine("Alpha1: " + tgParser.ParsedData[i]["EegPowerAlpha1"]);
                //Console.WriteLine("Alpha1: " + tgParser.ParsedData[i]["EegPowerAlpha1"]);
            }

            if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha2"))
            {
                archO.WriteLine("Alpha2: " + tgParser.ParsedData[i]["EegPowerAlpha2"]);
                //Console.WriteLine("Alpha2: " + tgParser.ParsedData[i]["EegPowerAlpha2"]);
            }

            if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta1"))
            {
                archO.WriteLine("Beta1: " + tgParser.ParsedData[i]["EegPowerBeta1"]);
                //Console.WriteLine("Beta1: " + tgParser.ParsedData[i]["EegPowerBeta1"]);
            }

            if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta2"))
            {
                archO.WriteLine("Beta2: " + tgParser.ParsedData[i]["EegPowerBeta2"]);
                //Console.WriteLine("Beta2: " + tgParser.ParsedData[i]["EegPowerBeta2"]);
            }

            if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma1"))
            {
                archO.WriteLine("Gamma1: " + tgParser.ParsedData[i]["EegPowerGamma1"]);
                //Console.WriteLine("Gamma1: " + tgParser.ParsedData[i]["EegPowerGamma1"]);
            }

            if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma2"))
            {
                archO.WriteLine("Gamma2: " + tgParser.ParsedData[i]["EegPowerGamma2"]);
                //Console.WriteLine("Gamma2: " + tgParser.ParsedData[i]["EegPowerGamma2"]);
            }

            /*if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
             * {
             *  archO.WriteLine("Eyeblink " + tgParser.ParsedData[i]["BlinkStrength"]);
             *  Console.WriteLine("Eyeblink " + tgParser.ParsedData[i]["BlinkStrength"]);
             * }
             *
             * if (tgParser.ParsedData[i].ContainsKey("Raw"))
             * {
             *  //Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);
             * }
             *
             * if (tgParser.ParsedData[i].ContainsKey("Attention"))
             * {
             *  archO.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
             *  //Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
             * }
             *
             * if (tgParser.ParsedData[i].ContainsKey("Meditation"))
             * {
             *  archO.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
             *  //Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
             * }*/
        }
        stop = new TimeSpan(DateTime.Now.Ticks);
        //archO.WriteLine("Time:" +(double) stop.Subtract(start).TotalMilliseconds);
        archO.Close();
    }
Example #15
0
        // Called when data is received from a device

        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);



            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                /*
                 *
                 * if (tgParser.ParsedData[i].ContainsKey("Raw")){
                 *
                 *  //Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);
                 *
                 * }
                 *
                 * if (tgParser.ParsedData[i].ContainsKey("PoorSignal")){
                 *
                 *  //The following line prints the Time associated with the parsed data
                 *  //Console.WriteLine("Time:" + tgParser.ParsedData[i]["Time"]);
                 *
                 *  //A Poor Signal value of 0 indicates that your headset is fitting properly
                 * // Console.WriteLine("Poor Signal:" + tgParser.ParsedData[i]["PoorSignal"]);
                 *
                 * // poorSig = (byte)tgParser.ParsedData[i]["PoorSignal"];
                 * }
                 *
                 */
                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                    //hoe meer je concentreet hoe hoger de attention waarde. 80 is een goede treshold
                }


                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    //Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                    // rustigheid waarde. Hoe rustiger je bent hoe lager die is. Erg nauwkeurig deze waarde!
                }


                if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta"))
                {
                    //Console.WriteLine("Delta: " + tgParser.ParsedData[i]["EegPowerDelta"]);
                }


                /*
                 * if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                 * {
                 *
                 *  Console.WriteLine("Eyeblink " + tgParser.ParsedData[i]["BlinkStrength"]);
                 *  //of je knipper of niet. Treshold 60 waarde
                 *
                 * }
                 */
            }
        }
Example #16
0
        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;

            Device.DataEventArgs         de = (Device.DataEventArgs)e;
            NeuroSky.ThinkGear.DataRow[] tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);



            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.
            int            SetThemAll = 0;
            List <PosTime> RAW        = new List <PosTime>();

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    //   Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);
                    RAW.Add(new PosTime(tgParser.ParsedData[i]["Raw"], tgParser.ParsedData[i]["Time"]));
                }

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    //The following line prints the Time associated with the parsed data
                    //Console.WriteLine("Time:" + tgParser.ParsedData[i]["Time"]);

                    //A Poor Signal value of 0 indicates that your headset is fitting properly
                    //              Console.WriteLine("Poor Signal:" + tgParser.ParsedData[i]["PoorSignal"]);

                    //  poorSig = (byte)tgParser.ParsedData[i]["PoorSignal"];
                }


                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    SetThemAll++;
                    //                Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                    BS.Attention = tgParser.ParsedData[i]["Attention"];
                }


                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    SetThemAll++;
                    //     Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                    BS.Meditation = tgParser.ParsedData[i]["Meditation"];
                }


                if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta"))
                {
                    BS.Delta = tgParser.ParsedData[i]["EegPowerDelta"];
                    //         Console.WriteLine("Delta: " + tgParser.ParsedData[i]["EegPowerDelta"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerTheta"))
                {
                    BS.Theta = tgParser.ParsedData[i]["EegPowerTheta"];
                    //        Console.WriteLine("Theta: " + tgParser.ParsedData[i]["EegPowerTheta"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha1"))
                {
                    BS.A1 = tgParser.ParsedData[i]["EegPowerAlpha1"];
                    //        Console.WriteLine("Alpha1: " + tgParser.ParsedData[i]["EegPowerAlpha1"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha2"))
                {
                    BS.A2 = tgParser.ParsedData[i]["EegPowerAlpha2"];
                    //       Console.WriteLine("Alpha2: " + tgParser.ParsedData[i]["EegPowerAlpha2"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta1"))
                {
                    BS.B1 = tgParser.ParsedData[i]["EegPowerBeta1"];
                    //       Console.WriteLine("Beta1: " + tgParser.ParsedData[i]["EegPowerBeta1"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta2"))
                {
                    BS.B2 = tgParser.ParsedData[i]["EegPowerBeta2"];
                    //      Console.WriteLine("Beta2: " + tgParser.ParsedData[i]["EegPowerBeta2"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma1"))
                {
                    BS.G1 = tgParser.ParsedData[i]["EegPowerGamma1"];
                    //     Console.WriteLine("Gamma1: " + tgParser.ParsedData[i]["EegPowerGamma1"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma2"))
                {
                    BS.G2 = tgParser.ParsedData[i]["EegPowerGamma2"];
                    //      Console.WriteLine("Gamma2: " + tgParser.ParsedData[i]["EegPowerGamma2"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                {
                    //       Console.WriteLine("Eyeblink " + tgParser.ParsedData[i]["BlinkStrength"]);
                }
            }
            if (dt_last == null)
            {
                dt_last = DateTime.Now;
            }
            else
            {
                ts      = DateTime.Now - dt_last;
                dt_last = DateTime.Now;
            }
            incomelength = RAW.Count;
            lock (forlock)
            {
                if (RAW.Count > 0)
                {
                    for (int j = 0; j < RAW.Count; j++)
                    {
                        RAW_DATA.Add(RAW[j]);
                    }
                    if (RAW_DATA.Count > 1000)
                    {
                        int k = RAW_DATA.Count;
                        for (int j = 0; j < k - 1000; j++)
                        {
                            RAW_DATA.RemoveAt(0);
                        }
                    }
                    //Signal s = new Signal()
                    ComplexSignal CS = new ComplexSignal(1, RAW_DATA.Count, 1);
                    if (RAW_DATA.Count >= 999)
                    {
                        data = new double[RAW_DATA.Count];
                        for (int i = 0; i < RAW_DATA.Count; i++)
                        {
                            data[i] = RAW_DATA[i].Pos;//10 * Math.Sin(Math.PI * (i / 15.0));//// +
                        }
                        Accord.Math.CosineTransform.DCT(data);
                    }
                }
            }
            if (SetThemAll == 10)
            {
                M.AddToMemory(BS);
            }
        }
Example #17
0
        /**
         * Called when data is received from a device
         */
        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;
            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;
            string   mybyte;
            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            //Console.WriteLine(buffer[0] + buffer[1]);
            //if (buffer=='1')
            //{
            //    Console.WriteLine("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww");
            //}
            /* Loop through new parsed data */
            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("MSG_MODEL_IDENTIFIED"))
                {
                    Console.WriteLine("Model Identified");
                    connector.setMentalEffortRunContinuous(true);
                    connector.setMentalEffortEnable(true);
                    connector.setTaskFamiliarityRunContinuous(true);
                    connector.setTaskFamiliarityEnable(true);
                    connector.setPositivityEnable(false);
                    //
                    // the following are included to demonstrate the overide messages
                    //
                    connector.setRespirationRateEnable(true); // not allowed with EEG
                    connector.setPositivityEnable(true);      // not allowed when famil/diff are enabled
                }
                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    // NOTE: this doesn't work well with BMD sensors Dual Headband or CardioChip

                    rcv_poorSignal = (byte)tgParser.ParsedData[i]["PoorSignal"];
                    if (rcv_poorSignal != rcv_poorSignal_last || rcv_poorSig_cnt >= 30)
                    {
                        // when there is a change of state OR every 30 reports
                        rcv_poorSig_cnt     = 0; // reset counter
                        rcv_poorSignal_last = rcv_poorSignal;
                        if (rcv_poorSignal == 0)
                        {
                            // signal is good, we are connected to a subject
                            Console.WriteLine("SIGNAL: we have good contact with the subject");
                            mybyte = "9";
                            tcp2.Send(Encoding.UTF8.GetBytes(mybyte));
                            //tcpClient1.Send(Encoding.UTF8.GetBytes(mybyte), mybyte.Length, ipEndPoint);
                        }
                        else
                        {
                            Console.WriteLine("SIGNAL: is POOR: " + rcv_poorSignal);
                            mybyte = "8";
                            tcp2.Send(Encoding.UTF8.GetBytes(mybyte));
                            //udpClient.Send(Encoding.UTF8.GetBytes(mybyte), mybyte.Length, ipEndPoint);
                        }
                    }
                    else
                    {
                        rcv_poorSig_cnt++;
                    }
                }


                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    if (tgParser.ParsedData[i]["Meditation"] != 0)
                    {
                        Console.WriteLine("Meditation: " + tgParser.ParsedData[i]["Meditation"]);

                        if (tgParser.ParsedData[i]["Meditation"] > 100)
                        {
                            tag = 4;
                        }
                        if (tgParser.ParsedData[i]["Meditation"] < 20)
                        {
                            tag = 6;
                        }
                        y = (int)tgParser.ParsedData[i]["Meditation"];
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    if (tgParser.ParsedData[i]["Attention"] != 0)
                    {
                        Console.WriteLine("Attention : " + tgParser.ParsedData[i]["Attention"]);
                        flag  = 0;
                        flag1 = 0;
                        num++;
                        if (tgParser.ParsedData[i]["Attention"] > 90)
                        {
                            tag = 5;
                        }
                        x = (int)tgParser.ParsedData[i]["Attention"];
                    }
                }
                if (!golfZoneDemo) // turn this off for the Golf Zone Demo
                {
                    if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                    {
                        if (tgParser.ParsedData[i]["BlinkStrength"] > 55)
                        {
                            Console.WriteLine("\t\tBlinkStrength: " + tgParser.ParsedData[i]["BlinkStrength"]);
                            if (num >= 2)
                            {
                                flag++;
                                num = 0;
                            }
                            flag1++;
                            if (buffer[0] + buffer[1] == 97)
                            {
                                if (flag1 == 1)
                                {
                                    Console.WriteLine("KKKKKKKKKK");
                                    mybyte = "1";
                                    tcp2.Send(Encoding.UTF8.GetBytes(mybyte));
                                    //udpClient.Send(Encoding.UTF8.GetBytes(mybyte), mybyte.Length, ipEndPoint2);
                                }
                            }
                            else if (buffer[0] + buffer[1] == 98)
                            {
                                if (flag == 1 && flag1 == 1)
                                {
                                    Console.WriteLine("KKKKKKKKKK");
                                    mybyte = "1";
                                    tcp2.Send(Encoding.UTF8.GetBytes(mybyte));
                                    //udpClient.Send(Encoding.UTF8.GetBytes(mybyte), mybyte.Length, ipEndPoint2);
                                }
                            }
                        }
                    }
                }

                if ((x > 0 && y > 0) || tag > 0)
                {
                    mybyte = x * 10000 + y * 10 + tag + "";
                    tcp1.Send(Encoding.UTF8.GetBytes(mybyte));
                    //udpClient.Send(Encoding.UTF8.GetBytes(mybyte), mybyte.Length, ipEndPoint);
                    x   = 0;
                    y   = 0;
                    tag = 0;
                }
            }
        }
        static void OnDataReceived(object sender, EventArgs e)
        {
            BrainWaveVector waveVector = new BrainWaveVector(trainingClassNumber);

            //Device d = (Device)sender;
            form.SetStatusText("Receiving Data");

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            //      MentalEffort mentalEffort = new MentalEffort();
            //      mentalEffort.CalculateMentalEffort(, TGsensorType.);

            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                #region Build waveVector with ParsedData
                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    if (collectClickTrainingSample)
                    {
                        rawTrainingSampleArray.Add(tgParser.ParsedData[i]["Raw"]);
                    }
                    else if (finishedTraining)
                    {
                        AddData(tgParser.ParsedData[i]["Raw"]);
                    }
                }
                #region Parse EEG Power Values
                if (tgParser.ParsedData[i].ContainsKey("EegPowerTheta"))
                {
                    waveVector.AddValue(0, tgParser.ParsedData[i]["EegPowerTheta"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta"))
                {
                    waveVector.AddValue(1, tgParser.ParsedData[i]["EegPowerDelta"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha1"))
                {
                    waveVector.AddValue(2, tgParser.ParsedData[i]["EegPowerAlpha1"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha2"))
                {
                    waveVector.AddValue(3, tgParser.ParsedData[i]["EegPowerAlpha2"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta1"))
                {
                    waveVector.AddValue(4, tgParser.ParsedData[i]["EegPowerBeta1"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta2"))
                {
                    waveVector.AddValue(5, tgParser.ParsedData[i]["EegPowerBeta2"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma1"))
                {
                    waveVector.AddValue(6, tgParser.ParsedData[i]["EegPowerGamma1"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma2"))
                {
                    waveVector.AddValue(7, tgParser.ParsedData[i]["EegPowerGamma2"]);
                }
                #endregion
                #endregion

                #region ParsedData if statements from sample - kept for reference

                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    //Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);
                    //                  form.SetDataText((tgParser.ParsedData[i]["Raw"]) +"\t");
                    //                   AddData(tgParser.ParsedData[i]["Raw"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    //The following line prints the Time associated with the parsed data
                    //Console.WriteLine("Time:" + tgParser.ParsedData[i]["Time"]);

                    //A Poor Signal value of 0 indicates that your headset is fitting properly
                    //                    Console.WriteLine("Poor Signal:" + tgParser.ParsedData[i]["PoorSignal"]);

                    //                    poorSig = (byte)tgParser.ParsedData[i]["PoorSignal"];
                }


                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    //Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                }


                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    //Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                {
                    //Console.WriteLine("Eyeblink " + tgParser.ParsedData[i]["BlinkStrength"]);
                }

                /*                if (tgParser.ParsedData[i].ContainsKey("MentalEffort"))
                 *              {
                 *
                 *                  form.SetDataText((tgParser.ParsedData[i]["MentalEffort"]) + "\t");
                 *                  AddData(tgParser.ParsedData[i]["MentalEffort"]);
                 *              } */

                /*                foreach(string key in tgParser.ParsedData[i].Keys.ToArray())
                 *              {
                 *                  form.SetDataText(key + "\t");
                 *              } */
                //                CalculateAndDisplayAverage();

                #endregion

                if (finishedTraining)
                {
                    if (waveVector.HasValue())
                    {
                        //Check if correspondes to ClickTrainingSample
                        // form.SetClickAverageText(CheckForEvent(clickTrainingSample, waveVector).ToString());
                        //            form.SetDataText(waveVector.ReturnVector()[1].ToString() + '\t');
                    }
                    bool sampleMatch        = CheckForEvent(dataBuffer, rawTrainingSampleAverage, out rawDataAverage);
                    bool complexSampleMatch = CheckForEvent(sampleMagnitudeAverage, dataComplex, out rawDataMagnitudeAverage);
                    form.SetRelaxAverageText(sampleMatch.ToString());
                    form.SetClickAverageText(rawTrainingSampleAverage.ToString());
                    //form.SetDataText(rawDataAverage.ToString() + '\t');
                    form.SetDataText(rawDataMagnitudeAverage.ToString() + '\t');
                    form.SetMagnitudeEventText(complexSampleMatch.ToString());

                    if (sampleMatch)
                    {
                        if (matchCounter >= numberOfConsecutiveMatchesRequired && allowKeyEvent)
                        {
                            //                           TieIntoWindow();
                            // allowKeyEvent = false;
                            matchCounter = 0;
                        }
                        matchCounter++;
                    }
                    else
                    {
                        matchCounter = 0;
                    }

                    if (complexSampleMatch)
                    {
                        if (transformedMatchCounter >= numberOfConsecutiveMatchesRequired && allowKeyEvent)
                        {
                            TieIntoWindow();
                            allowKeyEvent = false;
                            ResetDataBuffer();
                            //timer ensures event cannot be read for 1 second
                            // form.StartEventRestTimer();

                            transformedMatchCounter = 0;
                        }
                        transformedMatchCounter++;
                    }
                    else
                    {
                        transformedMatchCounter = 0;
                        allowKeyEvent           = true;
                    }
                }
                else if (collectClickTrainingSample && waveVector.HasValue())
                {
                    clickTrainingSample.AddVectorToMatrix(waveVector);
                    jointTrainingSample.AddVectorToMatrix(waveVector);
                }
                else if (collectRelaxTrainingSample && waveVector.HasValue())
                {
                    relaxTrainingSample.AddVectorToMatrix(waveVector);
                    jointTrainingSample.AddVectorToMatrix(waveVector);
                }
            }
        }
Example #19
0
        // Called when data is received from a device

        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);
            if (tgParser.ParsedData.Length == 0)
            {
                return;
            }

            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            List <string> list = new List <string>();

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                var parsedData = tgParser.ParsedData[i];
                if (parsedData.ContainsKey("Raw"))
                {
                    //Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);
                    //list.Add("Raw:" + parsedData["Raw"].ToString());
                }

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    //The following line prints the Time associated with the parsed data
                    //Console.WriteLine("Time:" + tgParser.ParsedData[i]["Time"]);

                    //A Poor Signal value of 0 indicates that your headset is fitting properly
                    //Console.WriteLine("Poor Signal:" + tgParser.ParsedData[i]["PoorSignal"]);
                    poorSig = (byte)tgParser.ParsedData[i]["PoorSignal"];
                }


                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    //Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                    list.Add("Att:" + parsedData["Attention"].ToString());
                    //buff = Encoding.UTF8.GetBytes("Att:" + tgParser.ParsedData[i]["Attention"]);

                    // 서버에 데이타 전송
                    //sock.Send(buff, SocketFlags.None);
                }


                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    //Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                    //list.Add("Med:" + parsedData["Meditation"].ToString());
                    //buff = Encoding.UTF8.GetBytes("Med:" + tgParser.ParsedData[i]["Meditation"]);

                    // 서버에 데이타 전송
                    //sock.Send(buff, SocketFlags.None);
                }


                if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta"))
                {
                    //Console.WriteLine("Delta: " + tgParser.ParsedData[i]["EegPowerDelta"]);
                    //buff = Encoding.UTF8.GetBytes("Delta:" + tgParser.ParsedData[i]["EegPowerDelta"]);

                    // 서버에 데이타 전송
                    // sock.Send(buff, SocketFlags.None);
                }

                if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                {
                    //list.Add("Blink:" + parsedData["BlinkStrength"].ToString());
                    //Console.WriteLine("Eyeblink: " + tgParser.ParsedData[i]["BlinkStrength"]);
                    //buff = Encoding.UTF8.GetBytes("Blink:" + tgParser.ParsedData[i]["BlinkStrength"]);

                    // 서버에 데이타 전송
                    //sock.Send(buff, SocketFlags.None);
                }
            }

            if (list.Count == 0)
            {
                return;
            }

            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            var ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9999);

            sock.Connect(ep);

            foreach (string x in list)
            {
                sock.Send(Encoding.UTF8.GetBytes(x + System.Environment.NewLine));
            }

            sock.Disconnect(true);
            sock.Close();
        }
Example #20
0
        static void OnDataReceived(object sender, EventArgs e)
        {

            //Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            NeuroSky.ThinkGear.DataRow[] tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();
            tgParser.Read(de.DataRowArray);



            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs. 
            int SetThemAll = 0;
            List<PosTime> RAW = new List<PosTime>();
            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {

                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {

                    //   Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);
                    RAW.Add(new PosTime(tgParser.ParsedData[i]["Raw"],tgParser.ParsedData[i]["Time"]));

                }

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {

                    //The following line prints the Time associated with the parsed data
                    //Console.WriteLine("Time:" + tgParser.ParsedData[i]["Time"]);

                    //A Poor Signal value of 0 indicates that your headset is fitting properly
                    //              Console.WriteLine("Poor Signal:" + tgParser.ParsedData[i]["PoorSignal"]);

                  //  poorSig = (byte)tgParser.ParsedData[i]["PoorSignal"];
                }
                

                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    SetThemAll++;
                    //                Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                    BS.Attention = tgParser.ParsedData[i]["Attention"];
                }


                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    SetThemAll++;
                    //     Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                    BS.Meditation = tgParser.ParsedData[i]["Meditation"];
                }


                if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta"))
                {
                    BS.Delta = tgParser.ParsedData[i]["EegPowerDelta"];
           //         Console.WriteLine("Delta: " + tgParser.ParsedData[i]["EegPowerDelta"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerTheta"))
                {
                    BS.Theta = tgParser.ParsedData[i]["EegPowerTheta"];
            //        Console.WriteLine("Theta: " + tgParser.ParsedData[i]["EegPowerTheta"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha1"))
                {
                    BS.A1 = tgParser.ParsedData[i]["EegPowerAlpha1"];
            //        Console.WriteLine("Alpha1: " + tgParser.ParsedData[i]["EegPowerAlpha1"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha2"))
                {
                    BS.A2 = tgParser.ParsedData[i]["EegPowerAlpha2"];
             //       Console.WriteLine("Alpha2: " + tgParser.ParsedData[i]["EegPowerAlpha2"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta1"))
                {
                    BS.B1 = tgParser.ParsedData[i]["EegPowerBeta1"];
             //       Console.WriteLine("Beta1: " + tgParser.ParsedData[i]["EegPowerBeta1"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta2"))
                {
                    BS.B2 = tgParser.ParsedData[i]["EegPowerBeta2"];
              //      Console.WriteLine("Beta2: " + tgParser.ParsedData[i]["EegPowerBeta2"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma1"))
                {
                    BS.G1 = tgParser.ParsedData[i]["EegPowerGamma1"];
               //     Console.WriteLine("Gamma1: " + tgParser.ParsedData[i]["EegPowerGamma1"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma2"))
                {
                    BS.G2 = tgParser.ParsedData[i]["EegPowerGamma2"];
              //      Console.WriteLine("Gamma2: " + tgParser.ParsedData[i]["EegPowerGamma2"]);
                    SetThemAll++;
                }
                if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                {

                    //       Console.WriteLine("Eyeblink " + tgParser.ParsedData[i]["BlinkStrength"]);

                }
               

            }
            if (dt_last == null)
                dt_last = DateTime.Now;
            else
            {
                ts = DateTime.Now - dt_last;
                dt_last = DateTime.Now;
               
            }
            incomelength = RAW.Count;
            lock (forlock)
            {
                if (RAW.Count > 0)
                {
                    for (int j = 0; j < RAW.Count; j++)
                        RAW_DATA.Add(RAW[j]);
                    if (RAW_DATA.Count > 1000)
                    {
                        int k = RAW_DATA.Count;
                        for (int j = 0; j < k - 1000; j++)
                        {
                            RAW_DATA.RemoveAt(0);
                        }
                    }
                    //Signal s = new Signal()
                    ComplexSignal CS = new ComplexSignal(1, RAW_DATA.Count, 1);
                    if (RAW_DATA.Count >= 999)
                    {
                        data = new double[RAW_DATA.Count];
                        for (int i = 0; i < RAW_DATA.Count; i++)
                        {
                            data[i] = RAW_DATA[i].Pos;//10 * Math.Sin(Math.PI * (i / 15.0));//// +
                        }
                        Accord.Math.CosineTransform.DCT(data);
                    }
                }
            }
            if (SetThemAll == 10)
            {
                M.AddToMemory(BS);
            }
        }
        private void updateMediationMode(TGParser tgParser, int i)
        {
            if (tgParser.ParsedData[i]["Meditation"] >= 10)
            {
            //this.progressBar2.Value = 100;
                Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                lb_value.Text = tgParser.ParsedData[i]["Meditation"].ToString();

                System.Media.SystemSounds.Asterisk.Play();
            //                progressBar2.Visible = true;

                //pictureBox1.Image = Properties.Resources.on;
            }
            else
            {
                //pictureBox1.Image = Properties.Resources.off;
            }
        }
        /**
         * Called when data is received from a device
         */
        void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;
            Device.DataEventArgs         de = (Device.DataEventArgs)e;
            NeuroSky.ThinkGear.DataRow[] tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            /* Loop through new parsed data */
            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    richTextBox1.Text += tgParser.ParsedData[i]["Raw"].ToString() + "\t" + DateTime.Now.ToString("HHmmss.fff") + "\t" + oddball + "\n";
                    result.Add(DateTime.Now.ToString("HHmmss.fff") + "\t" + tgParser.ParsedData[i]["Raw"].ToString() + "\t" + oddball);
                    oddball = stimuli;
                }

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    //Console.WriteLine("Time:" + tgParser.ParsedData[i]["Time"]);
                    //Console.WriteLine("PQ Value:" + tgParser.ParsedData[i]["PoorSignal"]);
                    poorSig = (byte)tgParser.ParsedData[i]["PoorSignal"];

                    //this is required because heart rate value is not returned when you have poor signal 200
                    if (poorSig != 200)
                    {
                        int      recovery     = heartRateRecovery.getHeartRateRecovery(0, poorSig);
                        double[] acceleration = heartRateAcceleration.getAcceleration(0, poorSig);
                    }
                }

                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    //Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    //Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta"))
                {
                    //Console.WriteLine("Delta: " + tgParser.ParsedData[i]["EegPowerDelta"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("EnergyLevel"))
                {
                    //Console.WriteLine("Energy: " + tgParser.ParsedData[i]["EnergyLevel"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("HeartRate"))
                {
                    //Console.WriteLine("HeartRate: " + tgParser.ParsedData[i]["HeartRate"]);

                    //int recovery = heartRateRecovery.getHeartRateRecovery((int)tgParser.ParsedData[i]["HeartRate"], poorSig);
                    //double[] acceleration = heartRateAcceleration.getAcceleration((int)tgParser.ParsedData[i]["HeartRate"], poorSig);

                    //if (recovery != -501) {
                    //    Console.WriteLine("heart rate recovery: " + recovery);

                    //    heartRateRecovery.enableHeartRateRecovery();
                    //}

                    //if (acceleration[0] > 0) {
                    //    Console.WriteLine("average heart rate = " + acceleration[0] + " and heart rate acceleration = " + acceleration[1] + " beats/min^2");
                    //}
                }

                if (tgParser.ParsedData[i].ContainsKey("HeartAge"))
                {
                    //Console.WriteLine("Heart Age: " + tgParser.ParsedData[i]["HeartAge"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("Positivity"))
                {
                    //Console.WriteLine("Positivity: " + tgParser.ParsedData[i]["Positivity"]);
                }
            }
        }
        private void updateAttentionMode(TGParser tgParser, int i)
        {
            if (tgParser.ParsedData[i]["Attention"] >= 50)
            {
                Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                lb_value.Text = tgParser.ParsedData[i]["Attention"].ToString();
                progressBar2.Value = Convert.ToInt32(tgParser.ParsedData[i]["Attention"]);

                progressBar2.Visible = true;

            }
        }
        /**
         * Called when data is received from a device
         */



        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;
            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    OneBuffer.Add(tgParser.ParsedData[i]["Raw"]);
                    FiveBuffer.Insert(0, tgParser.ParsedData[i]["Raw"]);
                    if (FiveBuffer.Count > 512)
                    {
                        FiveBuffer.RemoveAt(512);
                    }
                    if (OneBuffer.Count >= 512)
                    {
                        double[] _FiveBuffer = new double[5 * 512];
                        _FiveBuffer = FiveBuffer.ToArray(typeof(double)) as double[];
                        double[] pf = FFT(_FiveBuffer, 1000);

                        for (int j = 0; j < 256; j++)
                        {
                            if ((double)(df * j) >= 1.0 && (double)(df * j) < 58.0)  //
                            {
                                total += pf[j];
                            }
                            if ((double)(df * j) >= 20.0 && (double)(df * j) <= 30.0)   // 미간 사이에 둬야 인식이 잘 됨
                            {
                                hbeta += pf[j];
                            }
                        }
                        Console.WriteLine("High-Beta : " + hbeta);
                        Console.WriteLine("total : " + total);

                        rp = hbeta / total;  // smr wave의 relative power
                        Console.WriteLine(rp);
                        //    Result.Add(new KeyValuePair<string, double>("name", rp));  // name에는 각각의 test 이름을 넣어줄 것. 아니면 순서는 고정 값으로 정해놓고 값만 넣든지
                        hbeta = 0;
                        total = 0;

                        /*
                         * string path = @"C:\Users\user\Desktop\BrainWave items\HelloEEG\HelloEEG\bin\Debug\text.txt";
                         * FileInfo fi = new FileInfo(path);
                         * if(fi.Exists==false)
                         * {
                         *  System.IO.File.WriteAllText(path, rp.ToString());
                         * }*/

                        // string source = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");


                        //string source = DateTime.Now.ToString("dd  HH-mm-ss");

                        //string makeFolder_path= @"C:\Users\김나혜\Desktop\";
                        // DirectoryInfo dir = new DirectoryInfo(@"C:\Users\김나혜\Desktop\");
                        // dir.Name = source;
                        // dir.Create();

                        /*  string makeFolder_path = @"C:\Users\김나혜\Desktop\";
                         * string source = DateTime.Now.ToString("dd  HH-mm-ss");
                         * string folderName = makeFolder_path + source;
                         * DirectoryInfo f = new DirectoryInfo(folderName);
                         * f.Create();*/

                        /*  DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Users\김나혜\Desktop\DB");
                         * FileInfo fileInfo = null;
                         * try
                         *    {
                         *        if (directoryInfo.Exists)
                         *        {
                         *            fileInfo = new FileInfo(Path.Combine(directoryInfo.FullName, "DB"));
                         *            try
                         *            {
                         *                if (fileInfo.Exists)
                         *                {
                         *                //StreamWriter wr = new StreamWriter(fileInfo, FileMode.Append);
                         *                StreamWriter wr = new StreamWriter(@"C:\Users\김나혜\Desktop\DB" + count + ".txt");
                         *                count++;
                         *                }
                         *                else
                         *                {
                         *                    fileInfo.Create();
                         *                }
                         *            }
                         *        }
                         *        else
                         *        {
                         *            directoryInfo.Create();
                         *        }
                         *    }*/
                        //폴더 생성
                        string        makeFolder_path = @"C:\Users\정민지\Desktop\";
                        string        folderName      = makeFolder_path + "DB";
                        DirectoryInfo f = new DirectoryInfo(folderName);
                        f.Create();

                        StreamWriter wr = new StreamWriter(@"C:\Users\정민지\Desktop\DB\" + count + ".txt");
                        count++;

                        double val = rp;
                        wr.WriteLine(val);
                        wr.Close();

                        OneBuffer.Clear();
                        break;
                    }
                }

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    //Console.WriteLine("Time:" + tgParser.ParsedData[i]["Time"]);
                    //Console.WriteLine("PQ Value:" + tgParser.ParsedData[i]["PoorSignal"]);
                    poorSig = (byte)tgParser.ParsedData[i]["PoorSignal"];

                    //this is required because heart rate value is not returned when you have poor signal 200
                    if (poorSig != 200)
                    {
                        int      recovery     = heartRateRecovery.getHeartRateRecovery(0, poorSig);
                        double[] acceleration = heartRateAcceleration.getAcceleration(0, poorSig);
                    }
                }

                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    //Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    //Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta"))
                {
                    //Console.WriteLine("Delta: " + tgParser.ParsedData[i]["EegPowerDelta"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("EnergyLevel"))
                {
                    //Console.WriteLine("Energy: " + tgParser.ParsedData[i]["EnergyLevel"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("HeartRate"))
                {
                    //Console.WriteLine("HeartRate: " + tgParser.ParsedData[i]["HeartRate"]);

                    //int recovery = heartRateRecovery.getHeartRateRecovery((int)tgParser.ParsedData[i]["HeartRate"], poorSig);
                    //double[] acceleration = heartRateAcceleration.getAcceleration((int)tgParser.ParsedData[i]["HeartRate"], poorSig);

                    //if (recovery != -501)
                    //{
                    //    Console.WriteLine("heart rate recovery: " + recovery);

                    //    heartRateRecovery.enableHeartRateRecovery();
                    //}

                    //if (acceleration[0] > 0)
                    //{
                    //    Console.WriteLine("average heart rate = " + acceleration[0] + " and heart rate acceleration = " + acceleration[1] + " beats/min^2");
                    //}
                }

                if (tgParser.ParsedData[i].ContainsKey("HeartAge"))
                {
                    //Console.WriteLine("Heart Age: " + tgParser.ParsedData[i]["HeartAge"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("Positivity"))
                {
                    //Console.WriteLine("Positivity: " + tgParser.ParsedData[i]["Positivity"]);
                }
            }
        }
Example #25
0
        void OnDataReceived(object sender, EventArgs e)
        {
            /* Cast the event sender as a Device object, and e as the Device's DataEventArgs */
            Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;

            /* Create a TGParser to parse the Device's DataRowArray[] */
            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            /* Loop through parsed data TGParser for its parsed data... */
            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                // See the Data Types documentation for valid keys such
                // as "Raw", "PoorSignal", "Attention", etc.

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    Console.WriteLine("PQ Value:" + tgParser.ParsedData[i]["PoorSignal"]);
                    Console.WriteLine("LAN" + timing.ToString());
                }

                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta1"))
                {
                    low = tgParser.ParsedData[i]["EegPowerBeta1"].ToString();
                    if (startClick == true)
                    {
                        dtlow(low.ToString(), 1);
                    }

                    Console.WriteLine("Beta1:" + low);
                }
                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    raw = tgParser.ParsedData[i]["Raw"].ToString();
                    if (startClick == true)
                    {
                        dtraw(raw.ToString(), 1);
                        //playsound random
                    }

                    // Console.WriteLine("Raw:" + raw);
                }
                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta2"))
                {
                    high = tgParser.ParsedData[i]["EegPowerBeta2"].ToString();
                    if (startClick == true)
                    {
                        dthigh(high.ToString(), 1);
                        //playsound random
                    }
                    Console.WriteLine("Beta2:" + high);
                }
            }
        }
 void OnDataReceived(object sender, EventArgs e)
 {
     /* Cast the event sender as a Device object, and e as the Device's DataEventArgs */
     Device d = (Device)sender; Device.DataEventArgs de = (Device.DataEventArgs)e;
     /* Create a TGParser to parse the Device's DataRowArray[] */
     TGParser tgParser = new TGParser(); tgParser.Read(de.DataRowArray);
     /* Loop through parsed data TGParser for its parsed data... */
     for (int i = 0; i < tgParser.ParsedData.Length; i++)
     {
         // See the Data Types documentation for valid keys such        // as "Raw", "PoorSignal", "Attention", etc.
         if (tgParser.ParsedData[i].ContainsKey("Raw")) { Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]); }
         if (tgParser.ParsedData[i].ContainsKey("PoorSignal")) { Console.WriteLine("PQ Value:" + tgParser.ParsedData[i]["PoorSignal"]); }
         if (tgParser.ParsedData[i].ContainsKey("Attention")) { Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]); }
         if (tgParser.ParsedData[i].ContainsKey("Meditation")) { Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]); }
     }
 }
        void OnDataReceived(object sender, EventArgs e, TextBox v_text, ProgressBar v_progress)
        {
            /* Cast the event sender as a Device object, and e as the Device's DataEventArgs */
            Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            /* Create a TGParser to parse the Device's DataRowArray[] */
            TGParser tgParser = new TGParser();
            tgParser.Read(de.DataRowArray);

            /* Loop through parsed data TGParser for its parsed data... */
            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                // See the Data Types documentation for valid keys such
                // as "Raw", "PoorSignal", "Attention", etc.
                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        v_text.Text = (tgParser.ParsedData[i]["Raw"]).ToString();
                    }));

                    //Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                {
                    if (tgParser.ParsedData[i]["BlinkStrength"] > 50)
                    {
                        this.Dispatcher.Invoke((Action)(() =>
                        {
                            SolidColorBrush mySolidColorBrush = new SolidColorBrush();
                            Console.WriteLine(square.Fill.ToString());
                            if (square.Fill.ToString() == "#642048FF")
                            {
                                mySolidColorBrush.Color = Color.FromArgb(100, 201, 10, 10);
                            }
                            else
                            {
                                mySolidColorBrush.Color = Color.FromArgb(100, 32, 72, 255);
                            }
                            square.Fill = mySolidColorBrush;
                            //v_progress.Value = 100 - (Double)(tgParser.ParsedData[i]["PoorSignal"]);
                        }));
                    }
                    Console.WriteLine("Blink:" + tgParser.ParsedData[i]["BlinkStrength"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        v_progress.Value = 100 - (Double)(tgParser.ParsedData[i]["PoorSignal"]);
                    }));
                     Console.WriteLine("PQ Value:" + tgParser.ParsedData[i]["PoorSignal"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {

                    Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("MindWandering"))
                {
                    Console.WriteLine("MindWandering Level:" + tgParser.ParsedData[i]["MindWandering"]);
                }
            }
        }
Example #28
0
        /**
         * Called when data is received from a device
         */
        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;
            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            /* Loop through new parsed data */
            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("MSG_MODEL_IDENTIFIED"))
                {
                    Console.WriteLine("Model Identified");


                    connector.setMentalEffortRunContinuous(true);
                    connector.setMentalEffortEnable(true);
                    connector.setTaskFamiliarityRunContinuous(true);
                    connector.setTaskFamiliarityEnable(true);
                    connector.setPositivityEnable(false);
                    //
                    // the following are included to demonstrate the overide messages
                    //
                    connector.setRespirationRateEnable(true); // not allowed with EEG
                    connector.setPositivityEnable(true);      // not allowed when famil/diff are enabled
                }
                if (tgParser.ParsedData[i].ContainsKey("MSG_ERR_CFG_OVERRIDE"))
                {
                    Console.WriteLine("ErrorConfigurationOverride: " + tgParser.ParsedData[i]["MSG_ERR_CFG_OVERRIDE"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("MSG_ERR_NOT_PROVISIONED"))
                {
                    Console.WriteLine("ErrorModuleNotProvisioned: " + tgParser.ParsedData[i]["MSG_ERR_NOT_PROVISIONED"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("TimeStamp"))
                {
                    //Console.WriteLine("TimeStamp");
                }
                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    //Console.WriteLine("Raw: " + tgParser.ParsedData[i]["Raw"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("RespiratoryRate"))
                {
                    Console.WriteLine("RespiratoryRate: " + tgParser.ParsedData[i]["RespiratoryRate"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("RawCh1"))
                {
                    //Console.WriteLine("RawCh1: " + tgParser.ParsedData[i]["RawCh1"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("RawCh2"))
                {
                    //Console.Write(", Raw Ch2:" + tgParser.ParsedData[i]["RawCh2"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    // NOTE: this doesn't work well with BMD sensors Dual Headband or CardioChip

                    rcv_poorSignal = (byte)tgParser.ParsedData[i]["PoorSignal"];
                    if (rcv_poorSignal != rcv_poorSignal_last || rcv_poorSig_cnt >= 30)
                    {
                        // when there is a change of state OR every 30 reports
                        rcv_poorSig_cnt     = 0; // reset counter
                        rcv_poorSignal_last = rcv_poorSignal;
                        if (rcv_poorSignal == 0)
                        {
                            // signal is good, we are connected to a subject
                            Console.WriteLine("SIGNAL: we have good contact with the subject");
                        }
                        else
                        {
                            Console.WriteLine("SIGNAL: is POOR: " + rcv_poorSignal);
                        }
                    }
                    else
                    {
                        rcv_poorSig_cnt++;
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    if (tgParser.ParsedData[i]["Attention"] != 0)
                    {
                        Console.WriteLine("Attention : " + tgParser.ParsedData[i]["Attention"]);
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Attention 1"))
                {
                    if (tgParser.ParsedData[i]["Attention 1"] != 0)
                    {
                        Console.WriteLine("Attention 1: " + tgParser.ParsedData[i]["Attention 1"]);
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Attention 2"))
                {
                    if (tgParser.ParsedData[i]["Attention 2"] != 0)
                    {
                        Console.WriteLine("Attention 2: " + tgParser.ParsedData[i]["Attention 2"]);
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    if (tgParser.ParsedData[i]["Meditation"] != 0)
                    {
                        Console.WriteLine("Meditation: " + tgParser.ParsedData[i]["Meditation"]);
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Meditation 1"))
                {
                    if (tgParser.ParsedData[i]["Meditation 1"] != 0)
                    {
                        Console.WriteLine("Meditation 1: " + tgParser.ParsedData[i]["Meditation 1"]);
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Meditation 2"))
                {
                    if (tgParser.ParsedData[i]["Meditation 2"] != 0)
                    {
                        Console.WriteLine("Meditation 2: " + tgParser.ParsedData[i]["Meditation 2"]);
                    }
                }
                if (!golfZoneDemo) // turn this off for the Golf Zone Demo
                {
                    if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                    {
                        Console.WriteLine("\t\tBlinkStrength: " + tgParser.ParsedData[i]["BlinkStrength"]);
                    }

                    if (tgParser.ParsedData[i].ContainsKey("MentalEffort"))
                    {
                        mental_eff_cur = (Double)tgParser.ParsedData[i]["MentalEffort"];
                        if (mental_eff_first)
                        {
                            mental_eff_first = false;
                        }
                        else
                        {
                            /*
                             * calculate the percentage change from the previous sample
                             */
                            mental_eff_change = calcPercentChange(mental_eff_baseline, mental_eff_cur);
                            if (mental_eff_change > 500.0 || mental_eff_change < -500.0)
                            {
                                Console.WriteLine("\t\tMental Effort: excessive range");
                            }
                            else
                            {
                                Console.WriteLine("\t\tMental Effort: " + mental_eff_change + " %");
                            }
                        }
                        mental_eff_baseline = mental_eff_cur;
                    }

                    if (tgParser.ParsedData[i].ContainsKey("TaskFamiliarity"))
                    {
                        task_famil_cur = (Double)tgParser.ParsedData[i]["TaskFamiliarity"];
                        if (task_famil_first)
                        {
                            task_famil_first = false;
                        }
                        else
                        {
                            /*
                             * calculate the percentage change from the previous sample
                             */
                            task_famil_change = calcPercentChange(task_famil_baseline, task_famil_cur);
                            if (task_famil_change > 500.0 || task_famil_change < -500.0)
                            {
                                Console.WriteLine("\t\tTask Familiarity: excessive range");
                            }
                            else
                            {
                                Console.WriteLine("\t\tTask Familiarity: " + task_famil_change + " %");
                            }
                        }
                        task_famil_baseline = task_famil_cur;
                    }

                    if (tgParser.ParsedData[i].ContainsKey("Positivity"))
                    {
                        Console.WriteLine("\t\tPositivity: " + tgParser.ParsedData[i]["Positivity"]);
                    }
                }
                if (golfZoneDemo)
                {
                    if (tgParser.ParsedData[i].ContainsKey("ReadyZone"))
                    {
                        Console.Write("\t\tGolfZone: ");
                        if (tgParser.ParsedData[i]["ReadyZone"] == 3)
                        {
                            Console.WriteLine("Elite: you are the best, putt when you are ready");
                        }
                        else if (tgParser.ParsedData[i]["ReadyZone"] == 2)
                        {
                            Console.WriteLine("Intermediate: you are good, relax and putt smoothly");
                        }
                        else if (tgParser.ParsedData[i]["ReadyZone"] == 1)
                        {
                            Console.WriteLine("Beginner: take a breath and don't rush");
                        }
                        else
                        {
                            Console.WriteLine("Try to relax, focus on your target");
                        }
                    }
                }
            }
        }
Example #29
0
        private void updateMediationMode(TGParser tgParser, int i)
        {
            lb_value.Text = tgParser.ParsedData[i]["Meditation"].ToString();
            progressBar1.Value = Convert.ToInt32(tgParser.ParsedData[i]["Meditation"]);

            progressBar1.Visible = true;

            if (tgParser.ParsedData[i]["Meditation"] >= 50)
            {
                pictureBox1.Image = Properties.Resources.on;
            }
            else
            {
                pictureBox1.Image = Properties.Resources.off;
            }
        }
Example #30
0
        private void TGConnector_DataReceived(object sender, EventArgs e)
        {
            Device device = (Device)sender;

            // Parse Data #1
            var TGParser = new TGParser();

            TGParser.Read((e as Device.DataEventArgs).DataRowArray);

            // Parse Data #2
            var TGDataRow        = new TGData();
            var TGDataProperties = typeof(TGData).GetProperties();

            for (int i = 0; i < TGParser.ParsedData.Length; i++)
            {
                foreach (var Key in TGParser.ParsedData[i].Keys)
                {
                    if (Key == "Time")
                    {
                        continue;
                    }
                    if (Key == "Raw")
                    {
                        continue;
                    }
                    var PropertyInfo = TGDataProperties.Where(prop => prop.Name == Key).FirstOrDefault();
                    if (PropertyInfo == null)
                    {
                        Debug.Assert(false, "اطلاعات به صورت کامل ترجمه نشده است");
                        continue;
                    }
                    PropertyInfo.SetValue(TGDataRow, TGParser.ParsedData[i][PropertyInfo.Name]);

                    // IMP: This algorithm is resource and computation intensive.
                    // If you need to run with the Debugger, be aware that this calculation may take many minutes to complete
                    // when the debugger is engaged. It will output its results only after its calculations are complete.
                    //
                    // If these methods are called before the MSG_MODEL_IDENTIFIED has been received,
                    // it is considered a request to be processed when the connected equipment is identified.
                    // It is possible to Enable this feature and later find that it is no longer enabled.
                    // Once the connected equipment has been identified, if the request is incompatible with the hardware
                    // or software it will be overridden and the MSG_ERR_CFG_OVERRIDE message sent to provide notification.
                    if (Key == "MSG_MODEL_IDENTIFIED")
                    {
                        LogAdd("MSG_MODEL_IDENTIFIED Recevied...");
                        TGConnector.setMentalEffortRunContinuous(true);
                        TGConnector.setMentalEffortEnable(true);
                        TGConnector.setTaskFamiliarityRunContinuous(true);
                        TGConnector.setTaskFamiliarityEnable(true);
                        TGConnector.setPositivityEnable(false);

                        // the following are included to demonstrate the overide messages
                        TGConnector.setRespirationRateEnable(true); // not allowed with EEG
                        TGConnector.setPositivityEnable(true);      // not allowed when famil/diff are enabled
                    }

                    // If these methods are called before the MSG_MODEL_IDENTIFIED has been received,
                    // it is considered a request to be processed when the connected equipment is identified.
                    // It is possible to Enable this feature and later find that it is no longer enabled.
                    // Once the connected equipment has been identified, if the request is incompatible with the hardware
                    // or software it will be overridden and the MSG_ERR_CFG_OVERRIDE message sent to provide notification.
                    if (TGParser.ParsedData[i].ContainsKey("MSG_ERR_CFG_OVERRIDE"))
                    {
                        LogAdd($"ErrorConfigurationOverride: {TGParser.ParsedData[i]["MSG_ERR_CFG_OVERRIDE"]} Recevied...");
                    }
                    if (TGParser.ParsedData[i].ContainsKey("MSG_ERR_NOT_PROVISIONED"))
                    {
                        LogAdd($"ErrorModuleNotProvisioned: {TGParser.ParsedData[i]["MSG_ERR_NOT_PROVISIONED"]} Recevied...");
                    }
                }
            }

            // Add TGDataRow to Queue
            if (TGDataRow.EegPowerDelta != 0)
            {
                TGQueue.Enqueue(TGDataRow);
            }
            this.RefreshUI(TGDataRow);
        }
Example #31
0
        /**
         * Called when data is received from a device
         */
        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;
            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            /* Loop through new parsed data */
            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("MSG_MODEL_IDENTIFIED"))
                {
                    Console.WriteLine("Model Identified");

                    connector.setMentalEffortRunContinuous(false);
                    connector.setMentalEffortEnable(false);
                    connector.setTaskFamiliarityRunContinuous(false);
                    connector.setTaskFamiliarityEnable(false);
                    connector.setPositivityEnable(false);
                    connector.setBlinkDetectionEnabled(false);

                    //
                    // the following are included to demonstrate the overide messages
                    //
                    connector.setRespirationRateEnable(true); // not allowed with EEG
                }
                if (tgParser.ParsedData[i].ContainsKey("MSG_ERR_CFG_OVERRIDE"))
                {
                    Console.WriteLine("ErrorConfigurationOverride: " + tgParser.ParsedData[i]["MSG_ERR_CFG_OVERRIDE"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("MSG_ERR_NOT_PROVISIONED"))
                {
                    Console.WriteLine("ErrorModuleNotProvisioned: " + tgParser.ParsedData[i]["MSG_ERR_NOT_PROVISIONED"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("TimeStamp"))
                {
                    //Console.WriteLine("TimeStamp");
                }
                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    //Console.WriteLine("Raw: " + tgParser.ParsedData[i]["Raw"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("RawCh1"))
                {
                    //Console.WriteLine("RawCh1: " + tgParser.ParsedData[i]["RawCh1"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("RawCh2"))
                {
                    //Console.Write(", Raw Ch2:" + tgParser.ParsedData[i]["RawCh2"]);
                }
                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    // NOTE: this doesn't work well with BMD sensors Dual Headband or CardioChip

                    rcv_poorSignal = (byte)tgParser.ParsedData[i]["PoorSignal"];
                    if (rcv_poorSignal != rcv_poorSignal_last || rcv_poorSig_cnt >= 30)
                    {
                        // when there is a change of state OR every 30 reports
                        rcv_poorSig_cnt     = 0; // reset counter
                        rcv_poorSignal_last = rcv_poorSignal;
                        if (rcv_poorSignal == 0)
                        {
                            // signal is good, we are connected to a subject
                            Console.WriteLine("SIGNAL: we have good contact with the subject");
                        }
                        else
                        {
                            Console.WriteLine("SIGNAL: is POOR: " + rcv_poorSignal);
                        }
                    }
                    else
                    {
                        rcv_poorSig_cnt++;
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    if (tgParser.ParsedData[i]["Attention"] != 0)
                    {
                        Console.WriteLine("Attention : " + tgParser.ParsedData[i]["Attention"]);
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Attention 1"))
                {
                    if (tgParser.ParsedData[i]["Attention 1"] != 0)
                    {
                        Console.WriteLine("Attention 1: " + tgParser.ParsedData[i]["Attention 1"]);
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Attention 2"))
                {
                    if (tgParser.ParsedData[i]["Attention 2"] != 0)
                    {
                        Console.WriteLine("Attention 2: " + tgParser.ParsedData[i]["Attention 2"]);
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    if (tgParser.ParsedData[i]["Meditation"] != 0)
                    {
                        Console.WriteLine("Meditation: " + tgParser.ParsedData[i]["Meditation"]);
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Meditation 1"))
                {
                    if (tgParser.ParsedData[i]["Meditation 1"] != 0)
                    {
                        Console.WriteLine("Meditation 1: " + tgParser.ParsedData[i]["Meditation 1"]);
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Meditation 2"))
                {
                    if (tgParser.ParsedData[i]["Meditation 2"] != 0)
                    {
                        Console.WriteLine("Meditation 2: " + tgParser.ParsedData[i]["Meditation 2"]);
                    }
                }
                if (tgParser.ParsedData[i].ContainsKey("Positivity"))
                {
                    Console.WriteLine("\t\tPositivity: " + tgParser.ParsedData[i]["Positivity"]);
                }
                if (!golfZoneDemo) // turn this off for the Golf Zone Demo
                {
                    if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                    {
                        Console.WriteLine("\t\tBlinkStrength: " + tgParser.ParsedData[i]["BlinkStrength"]);
                    }
                    if (tgParser.ParsedData[i].ContainsKey("MentalEffort"))
                    {
                        Console.WriteLine("\t\tMental Effort: " + tgParser.ParsedData[i]["MentalEffort"]);
                    }

                    if (tgParser.ParsedData[i].ContainsKey("TaskFamiliarity"))
                    {
                        Console.WriteLine("\t\tTask Familiarity: " + tgParser.ParsedData[i]["TaskFamiliarity"]);
                    }
                }
                if (golfZoneDemo)
                {
                    if (tgParser.ParsedData[i].ContainsKey("ReadyZone"))
                    {
                        byte zone = (byte)tgParser.ParsedData[i]["ReadyZone"];
                        Console.Write("\t\tGolfZone: ");
                        switch (zone)
                        {
                        case 9:
                            Console.WriteLine("9: Elite: you are the best, putt when you are ready");
                            break;

                        case 8:
                            Console.WriteLine("8:");
                            break;

                        case 7:
                            Console.WriteLine("7:");
                            break;

                        case 6:
                            Console.WriteLine("6:");
                            break;

                        case 5:
                            Console.WriteLine("5: Intermediate: you are good, relax and putt smoothly");
                            break;

                        case 4:
                            Console.WriteLine("4:");
                            break;

                        case 3:
                            Console.WriteLine("3:");
                            break;

                        case 2:
                            Console.WriteLine("2:");
                            break;

                        case 1:
                            Console.WriteLine("1: Beginner: take a breath and don't rush");
                            break;

                        case 0:
                            Console.WriteLine("0: Try to relax, focus on your target");
                            break;

                        default:
                            Console.WriteLine("OOPS: zone value out of range: " + zone);
                            break;
                        }
                    }
                }
            }
        }
Example #32
0
        // Called when data is received from a device

        static void OnDataReceived(object sender, EventArgs e)
        {
            //Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.
            int password = 0;
            int attempt  = 0;

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    Console.WriteLine("att Value:" + tgParser.ParsedData[i]["Attention"]);



                    if (tgParser.ParsedData[i]["Attention"] > 60)
                    {
                        port.WriteLine(1 + ";" + 0 + ";");
                        Console.WriteLine(1);

                        // Blink Counter and password saver
                        if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
                        {
                            Console.WriteLine("To start blink Counter, Blink Again");

                            var startTime = DateTime.UtcNow;     // Initialize Timer
                            int pass      = 0;

                            while (DateTime.UtcNow - startTime < TimeSpan.FromSeconds(5000))     // 5 second timer
                            {
                                Console.WriteLine("Blink counter started");
                                if (tgParser.ParsedData[i]["BlinkStrength"] > 60)
                                {
                                    Console.WriteLine("Blink Strength Value: " + tgParser.ParsedData[i]["BlinkStrength"]);
                                    pass++;
                                    password = pass;
                                }
                                else
                                {
                                    Console.WriteLine("No Blink Detected, No password created, Restart Program");
                                }
                            }
                            Console.WriteLine("Password: "******"BlinkStrength"))
                {
                    Console.WriteLine("Blink to start unlocking");
                    if (attempt == password)
                    {
                        port.WriteLine(0 + ";" + 1 + ";");
                        Console.WriteLine(1);
                    }

                    else if (attempt < password)
                    {
                        attempt++;
                        Console.WriteLine("Attempt: " + attempt + "Password: "******"Error, attempt cannot be greater than password");
                    }
                }


                /* else
                 * {
                 *   port.WriteLine(0 + ";" + 0 + ";");
                 *   Console.WriteLine(0);
                 * }
                 */

                Thread.Sleep(2000);

                Console.WriteLine("recieved = " + port.ReadExisting());
            }
        }
Example #33
0
        private void plotWaves(Device.DataEventArgs de)
        {
            NeuroSky.ThinkGear.DataRow[] tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta") && tgParser.ParsedData[i]["EegPowerDelta"] > 0)
                {
                    label5.Invoke((MethodInvoker)(() => label5.Text = "Delta: " + tgParser.ParsedData[i]["EegPowerDelta"]));
                    chart1.Invoke((MethodInvoker)(() => chart1.Series["Delta"].Points.AddY(tgParser.ParsedData[i]["EegPowerDelta"])));
                    chart7.Invoke((MethodInvoker)(() => chart7.Series["Delta"].Points.AddY(Math.Log(tgParser.ParsedData[i]["EegPowerDelta"]))));

                    if (chart1.Series["Delta"].Points.Count > 20)
                    {
                        chart1.Invoke((MethodInvoker)(() => chart1.Series["Delta"].Points.RemoveAt(0)));
                        chart7.Invoke((MethodInvoker)(() => chart7.Series["Delta"].Points.RemoveAt(0)));
                        button6.Invoke((MethodInvoker)(() => button6.Enabled = true));
                    }

                    chart7.Invoke((MethodInvoker)(() => chart7.ChartAreas[0].AxisY.Maximum = 15));
                    chart7.Invoke((MethodInvoker)(() => chart7.ChartAreas[0].AxisY.Minimum = 5));
                    chart2.Invoke((MethodInvoker)(() => chart2.ChartAreas[0].AxisY.Maximum = 1000000));
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerTheta") && tgParser.ParsedData[i]["EegPowerTheta"] > 0)
                {
                    label6.Invoke((MethodInvoker)(() => label6.Text = "Theta: " + tgParser.ParsedData[i]["EegPowerTheta"]));
                    chart2.Invoke((MethodInvoker)(() => chart2.Series["Theta"].Points.AddY(tgParser.ParsedData[i]["EegPowerTheta"])));
                    chart7.Invoke((MethodInvoker)(() => chart7.Series["Theta"].Points.AddY(Math.Log(tgParser.ParsedData[i]["EegPowerTheta"]))));

                    if (chart2.Series["Theta"].Points.Count > 20)
                    {
                        chart2.Invoke((MethodInvoker)(() => chart2.Series["Theta"].Points.RemoveAt(0)));
                        chart7.Invoke((MethodInvoker)(() => chart7.Series["Theta"].Points.RemoveAt(0)));
                    }

                    chart2.Invoke((MethodInvoker)(() => chart2.ChartAreas[0].AxisY.Maximum = 400000));
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha1") && tgParser.ParsedData[i]["EegPowerAlpha1"] > 0)
                {
                    label7.Invoke((MethodInvoker)(() => label7.Text = "Low Alpha: " + tgParser.ParsedData[i]["EegPowerAlpha1"]));
                    chart3.Invoke((MethodInvoker)(() => chart3.Series["Low Alpha"].Points.AddY(tgParser.ParsedData[i]["EegPowerAlpha1"])));
                    chart7.Invoke((MethodInvoker)(() => chart7.Series["Low Alpha"].Points.AddY(Math.Log(tgParser.ParsedData[i]["EegPowerAlpha1"]))));

                    if (chart3.Series["Low Alpha"].Points.Count > 20)
                    {
                        chart3.Invoke((MethodInvoker)(() => chart3.Series["Low Alpha"].Points.RemoveAt(0)));
                        chart7.Invoke((MethodInvoker)(() => chart7.Series["Low Alpha"].Points.RemoveAt(0)));
                    }

                    chart3.Invoke((MethodInvoker)(() => chart3.ChartAreas[0].AxisY.Maximum = 100000));
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha2") && tgParser.ParsedData[i]["EegPowerAlpha2"] > 0)
                {
                    label8.Invoke((MethodInvoker)(() => label8.Text = "High Alpha: " + tgParser.ParsedData[i]["EegPowerAlpha2"]));
                    chart3.Invoke((MethodInvoker)(() => chart3.Series["High Alpha"].Points.AddY(tgParser.ParsedData[i]["EegPowerAlpha2"])));
                    chart7.Invoke((MethodInvoker)(() => chart7.Series["High Alpha"].Points.AddY(Math.Log(tgParser.ParsedData[i]["EegPowerAlpha2"]))));

                    if (chart3.Series["High Alpha"].Points.Count > 20)
                    {
                        chart3.Invoke((MethodInvoker)(() => chart3.Series["High Alpha"].Points.RemoveAt(0)));
                        chart7.Invoke((MethodInvoker)(() => chart7.Series["High Alpha"].Points.RemoveAt(0)));
                    }
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta1") && tgParser.ParsedData[i]["EegPowerAlpha1"] > 0)
                {
                    label9.Invoke((MethodInvoker)(() => label9.Text = "Low Beta: " + tgParser.ParsedData[i]["EegPowerBeta1"]));
                    chart4.Invoke((MethodInvoker)(() => chart4.Series["Low Beta"].Points.AddY(tgParser.ParsedData[i]["EegPowerBeta1"])));
                    chart7.Invoke((MethodInvoker)(() => chart7.Series["Low Beta"].Points.AddY(Math.Log(tgParser.ParsedData[i]["EegPowerBeta1"]))));

                    if (chart4.Series["Low Beta"].Points.Count > 20)
                    {
                        chart4.Invoke((MethodInvoker)(() => chart4.Series["Low Beta"].Points.RemoveAt(0)));
                        chart7.Invoke((MethodInvoker)(() => chart7.Series["Low Beta"].Points.RemoveAt(0)));
                    }

                    chart4.Invoke((MethodInvoker)(() => chart4.ChartAreas[0].AxisY.Maximum = 50000));
                    //  chart4.Invoke((MethodInvoker)(() => chart4.ChartAreas[0].AxisY.Minimum = 5));
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta2") && tgParser.ParsedData[i]["EegPowerBeta2"] > 0)
                {
                    label10.Invoke((MethodInvoker)(() => label10.Text = "High Beta: " + tgParser.ParsedData[i]["EegPowerBeta2"]));
                    chart4.Invoke((MethodInvoker)(() => chart4.Series["High Beta"].Points.AddY(tgParser.ParsedData[i]["EegPowerBeta2"])));
                    chart7.Invoke((MethodInvoker)(() => chart7.Series["High Beta"].Points.AddY(Math.Log(tgParser.ParsedData[i]["EegPowerBeta2"]))));


                    if (chart4.Series["High Beta"].Points.Count > 20)
                    {
                        chart4.Invoke((MethodInvoker)(() => chart4.Series["High Beta"].Points.RemoveAt(0)));
                        chart7.Invoke((MethodInvoker)(() => chart7.Series["High Beta"].Points.RemoveAt(0)));
                    }
                }


                if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma1") && tgParser.ParsedData[i]["EegPowerGamma1"] > 0)
                {
                    label11.Invoke((MethodInvoker)(() => label11.Text = "Low Gamma: " + tgParser.ParsedData[i]["EegPowerGamma1"]));
                    chart5.Invoke((MethodInvoker)(() => chart5.Series["Low Gamma"].Points.AddY(tgParser.ParsedData[i]["EegPowerGamma1"])));
                    chart7.Invoke((MethodInvoker)(() => chart7.Series["Low Gamma"].Points.AddY(Math.Log(tgParser.ParsedData[i]["EegPowerGamma1"]))));

                    if (chart5.Series["Low Gamma"].Points.Count > 20)
                    {
                        chart5.Invoke((MethodInvoker)(() => chart5.Series["Low Gamma"].Points.RemoveAt(0)));
                        chart7.Invoke((MethodInvoker)(() => chart7.Series["Low Gamma"].Points.RemoveAt(0)));
                    }

                    chart5.Invoke((MethodInvoker)(() => chart5.ChartAreas[0].AxisY.Maximum = 20000));
                }


                if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma2") && tgParser.ParsedData[i]["EegPowerGamma2"] > 0)
                {
                    label12.Invoke((MethodInvoker)(() => label12.Text = "High Gamma: " + tgParser.ParsedData[i]["EegPowerGamma2"]));
                    chart5.Invoke((MethodInvoker)(() => chart5.Series["High Gamma"].Points.AddY(tgParser.ParsedData[i]["EegPowerGamma2"])));
                    chart7.Invoke((MethodInvoker)(() => chart7.Series["High Gamma"].Points.AddY(Math.Log(tgParser.ParsedData[i]["EegPowerGamma2"]))));

                    if (chart5.Series["High Gamma"].Points.Count > 20)
                    {
                        chart5.Invoke((MethodInvoker)(() => chart5.Series["High Gamma"].Points.RemoveAt(0)));
                        chart7.Invoke((MethodInvoker)(() => chart7.Series["High Gamma"].Points.RemoveAt(0)));
                    }
                }

                if (closeAllThread)
                {
                    Thread.CurrentThread.Abort();
                }
            }
        }
Example #34
0
        private void updateBlinkMode(TGParser tgParser, ref bool hasBlink, ref int blinkeye, int i)
        {
            progressBar1.Visible = false;

            if (tgParser.ParsedData[i].ContainsKey("BlinkStrength"))
            {
                if (tgParser.ParsedData[i]["BlinkStrength"] != blinkeye)
                {
                    hasBlink = true;
                }
                lb_value.Text = tgParser.ParsedData[i]["BlinkStrength"].ToString();
                blinkeye = Convert.ToInt32(tgParser.ParsedData[i]["BlinkStrength"]);
            }

            if (hasBlink == true)
            {
                pictureBox1.Image = Properties.Resources.on;
                Thread.Sleep(1000);
                pictureBox1.Image = Properties.Resources.off;
                hasBlink = false;
            }
        }
        private void OnDataReceived(object sender, EventArgs e)
        {
            Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                if (tgParser.ParsedData[i].ContainsKey("Raw"))
                {
                    //Console.WriteLine("Raw Value:" + tgParser.ParsedData[i]["Raw"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {
                    //Console.WriteLine("PQ Value:" + tgParser.ParsedData[i]["PoorSignal"]);
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta"))
                {
                    SetEegPowerDelta(tgParser.ParsedData[i]["EegPowerDelta"]);
                    Console.WriteLine("Power Delta: {0}", EegPowerDelta);
                    _event.EegPowerDelta = EegPowerDelta;
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerTheta"))
                {
                    SetEegPowerTheta(tgParser.ParsedData[i]["EegPowerTheta"]);
                    Console.WriteLine("Power Theta: {0}", EegPowerTheta);
                    _event.EegPowerTheta = EegPowerTheta;
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha1"))
                {
                    SetEegPowerAlpha1(tgParser.ParsedData[i]["EegPowerAlpha1"]);
                    Console.WriteLine("Power Alpha1: {0}", EegPowerAlpha1);
                    _event.EegPowerAlpha1 = EegPowerAlpha1;
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha2"))
                {
                    SetEegPowerAlpha2(tgParser.ParsedData[i]["EegPowerAlpha2"]);
                    Console.WriteLine("Power Alpha2: {0}", EegPowerAlpha2);

                    _event.EegPowerAlpha2 = EegPowerAlpha2;
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta1"))
                {
                    SetEegPowerBeta1(tgParser.ParsedData[i]["EegPowerBeta1"]);
                    Console.WriteLine("Power Beta1: {0}", EegPowerBeta1);
                    _event.EegPowerBeta1 = EegPowerBeta1;
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta2"))
                {
                    SetEegPowerBeta2(tgParser.ParsedData[i]["EegPowerBeta2"]);
                    Console.WriteLine("Power Beta2: {0}", EegPowerBeta2);
                    _event.EegPowerBeta2 = EegPowerBeta2;
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma1"))
                {
                    SetEegPowerGamma1(tgParser.ParsedData[i]["EegPowerGamma1"]);
                    Console.WriteLine("Power Gamma1: {0}", EegPowerGamma1);
                    _event.EegPowerGamma1 = EegPowerGamma1;
                }

                if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma2"))
                {
                    SetEegPowerGamma2(tgParser.ParsedData[i]["EegPowerGamma2"]);
                    Console.WriteLine("Power Gamma2: {0}", EegPowerGamma2);
                    _event.EegPowerGamma2 = EegPowerGamma2;
                }

                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    SetAttention(tgParser.ParsedData[i]["Attention"]);
                    //Console.WriteLine("Att Value:" + Attention);
                    _event.AttValue = Attention;
                }

                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {
                    SetMeditation(tgParser.ParsedData[i]["Meditation"]);
                    //Console.WriteLine("Med Value:" + Meditation);
                    _event.MedValue = Meditation;
                }
            }
        }
Example #36
0
        // Called when data is received from a device
        static void OnDataReceived(object sender, EventArgs e)
        {
            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[]            tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();

            tgParser.Read(de.DataRowArray);

            string[] keys = { "PoorSignal", "Attention", "Meditation", "MentalEffort", "TaskFamiliarity", "EegPowerDelta", "EegPowerTheta", "EegPowerAlpha1", "EegPowerAlpha2", "EegPowerBeta1", "EegPowerBeta2", "EegPowerGamma1", "EegPowerGamma2" };
            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {
                string row  = tgParser.ParsedData[i]["Time"] + " ";
                bool   trip = false;
                foreach (string key in keys)
                {
                    if (tgParser.ParsedData[i].ContainsKey(key))
                    {
                        trip = true;
                        row += tgParser.ParsedData[i][key] + " ";

                        if (key == "PoorSignal" && tgParser.ParsedData[i][key] > 0)
                        {
                            Console.WriteLine("");
                            Console.WriteLine("There is a poor signal. Please adjust headset or check battery.");
                            Console.Write("Comment:");
                        }
                        if (key == "Attention")
                        {
                            AttentionTot += (uint)tgParser.ParsedData[i][key];
                            AttentionCount++;
                        }
                        if (key == "Meditation")
                        {
                            MeditationTot += (uint)tgParser.ParsedData[i][key];
                            MeditationCount++;
                        }
                        string subStr = key.Substring(0, 8);
                        if (subStr == "EegPower")
                        {
                            if (EegPowerMax < tgParser.ParsedData[i][key])
                            {
                                EegPowerMax = (uint)tgParser.ParsedData[i][key];
                            }
                            if (key == "EegPowerDelta")
                            {
                                EegPowerCount++;
                                DeltaTot  += (uint)tgParser.ParsedData[i][key];
                                ThetaTot  += (uint)tgParser.ParsedData[i]["EegPowerTheta"];
                                Alpha1Tot += (uint)tgParser.ParsedData[i]["EegPowerAlpha1"];
                                Alpha2Tot += (uint)tgParser.ParsedData[i]["EegPowerAlpha2"];
                                Beta1Tot  += (uint)tgParser.ParsedData[i]["EegPowerBeta1"];
                                Beta2Tot  += (uint)tgParser.ParsedData[i]["EegPowerBeta2"];
                                Gamma1Tot += (uint)tgParser.ParsedData[i]["EegPowerGamma1"];
                                Gamma2Tot += (uint)tgParser.ParsedData[i]["EegPowerGamma2"];
                            }
                        }
                    }
                    else
                    {
                        row += "- ";
                    }
                }
                if (trip == true)
                {
                    File.AppendAllText(path + "data.txt", row + "\n");
                }
            }
        }
        private void OnDataReceived(object sender, EventArgs e)
        {
            // Cast the event sender as a Device object, and e as the Device's DataEventArgs
            //this.neursoSkyHeadset = (Device)sender;
            Device.DataEventArgs deviceDataEventArgs = (Device.DataEventArgs)e;

            // Create a TGParser to parse the Device's DataRowArray[]
            TGParser tgParser = new TGParser();

            if (tgParser == null)
            {
                this.Disconnect();
            }
            else
            {
                tgParser.Read(deviceDataEventArgs.DataRowArray);

                for (int i = 0; i < tgParser.ParsedData.Length; i++)
                {
                    if (tgParser.ParsedData[i].ContainsKey("EegPowerDelta"))
                    {
                        this.deltaPower = tgParser.ParsedData[i]["EegPowerDelta"];
                        this.UpdateDeltaPower((int)this.deltaPower);
                    }
                    if (tgParser.ParsedData[i].ContainsKey("EegPowerTheta"))
                    {
                        this.thetaPower = tgParser.ParsedData[i]["EegPowerTheta"];
                        this.UpdateThetaPower((int)this.thetaPower);
                    }
                    if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha1"))
                    {
                        this.alphaLowPower = tgParser.ParsedData[i]["EegPowerAlpha1"];
                        this.UpdateAlphaLowPower((int)this.alphaLowPower);
                    }
                    if (tgParser.ParsedData[i].ContainsKey("EegPowerAlpha2"))
                    {
                        this.alphaHighPower = tgParser.ParsedData[i]["EegPowerAlpha2"];
                        this.UpdateAlphaHighPower((int)this.alphaHighPower);
                    }
                    if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta1"))
                    {
                        this.betaLowPower = tgParser.ParsedData[i]["EegPowerBeta1"];
                        this.UpdateBetaLowPower((int)this.betaLowPower);
                    }
                    if (tgParser.ParsedData[i].ContainsKey("EegPowerBeta2"))
                    {
                        this.betaHighPower = tgParser.ParsedData[i]["EegPowerBeta2"];
                        this.UpdateBetaHighPower((int)this.betaHighPower);
                    }
                    if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma1"))
                    {
                        this.gammaLowPower = tgParser.ParsedData[i]["EegPowerGamma1"];
                        this.UpdateGammaLowPower((int)this.gammaLowPower);
                    }
                    if (tgParser.ParsedData[i].ContainsKey("EegPowerGamma2"))
                    {
                        this.gammaHighPower = tgParser.ParsedData[i]["EegPowerGamma2"];
                        this.UpdateGammaHighPower((int)this.gammaHighPower);
                    }
                    if (tgParser.ParsedData[i].ContainsKey("Attention"))
                    {
                        this.attentionLevel = tgParser.ParsedData[i]["Attention"];
                        this.UpdateAttentionLevel(this.attentionLevel);
                    }
                    if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                    {
                        this.medtitationLevel = tgParser.ParsedData[i]["Meditation"];
                        this.UpdateMeditationLevel(this.medtitationLevel);
                    }
                    if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                    {
                        this.poorSignal = tgParser.ParsedData[i]["PoorSignal"];
                        this.UpdatePoorSignal((int)this.poorSignal);
                    }
                }
            }
        }
        private void OnDataReceived(object sender, EventArgs e)
        {

            Device d = (Device)sender;

            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[] tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();
            tgParser.Read(de.DataRowArray);


            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {

                    Console.WriteLine("Poor Signal:" + tgParser.ParsedData[i]["PoorSignal"]);

                    int connection = Convert.ToInt32(tgParser.ParsedData[i]["PoorSignal"]);

                    ChangeConnectionQuality(connection);

                }


                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {

                    Console.WriteLine("Att Value:" + tgParser.ParsedData[i]["Attention"]);

                    int value = Convert.ToInt32(tgParser.ParsedData[i]["Attention"]);

                    ChangeAttentionValue(value);

                }

                if (tgParser.ParsedData[i].ContainsKey("Meditation"))
                {

                    Console.WriteLine("Med Value:" + tgParser.ParsedData[i]["Meditation"]);

                    int value = Convert.ToInt32(tgParser.ParsedData[i]["Meditation"]);

                    ChangeMeditationValue(value);

                }

            }

        }
Example #39
0
        public void OnDataReceived(object sender, EventArgs e)
        {
            Device.DataEventArgs de = (Device.DataEventArgs)e;
            DataRow[] tempDataRowArray = de.DataRowArray;

            TGParser tgParser = new TGParser();
            tgParser.Read(de.DataRowArray);

            /* Loops through the newly parsed data of the connected headset*/
            // The comments below indicate and can be used to print out the different data outputs.

            for (int i = 0; i < tgParser.ParsedData.Length; i++)
            {

                if (tgParser.ParsedData[i].ContainsKey("PoorSignal"))
                {

                    Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
                    {
                        poorSignalTextBlock.Text = "Poor Signal:" + tgParser.ParsedData[i]["PoorSignal"];

                    }));

                }

                if (tgParser.ParsedData[i].ContainsKey("Attention"))
                {
                    Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
                    {
                        attentionTextBlock.Text = "Att Value:" + tgParser.ParsedData[i]["Attention"];
                        Attention.Text = tgParser.ParsedData[i]["Attention"].ToString();
                        attentionValuesCollection.Add(new Data(tgParser.ParsedData[i]["Attention"], DateTime.Now));

                        //Puzzle solving statistics.
                        attentionValueSum += (int)tgParser.ParsedData[i]["Attention"];
                        attentionComingCounter += 1;

                        //Sending data to another app.
                        //try
                        //{
                        //    byte[] data = { 10, 8, 6, 4 };
                        //    uSender.SendData(data);
                        //}
                        //catch (UException exc)
                        //{
                        //    Console.WriteLine(exc.Message);
                        //}

                    }));

                }

            }
        }