Example #1
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     try
     {
         EEGLogger.startLog();
         btnStopRecord.Enabled = true;
     }
     catch
     {
         Utils.UserMessage("Connection failed. Please try again. Check console for more details.", messageType: Globals.MessageTypes.Error);
     }
 }
Example #2
0
    public static void WaitingForUser()
    {
        Debug.Log("Create the waiting thread!");
        EEGLogger logger = new EEGLogger();

        while (userID == -1)
        {
            Debug.Log("waiting thread!");
            Thread.Sleep(1000);
        }
        //SceneManager.LoadScene("MainMenu");
        Application.LoadLevel("MainMenu");
    }
Example #3
0
    void Awake()
    {
        EEGLogger logger = new EEGLogger();

        Debug.Log("WAITING!");
        //WaitForUser = new Thread(EEGLogger.WaitingForUser);
        //WaitForUser.Start();
        int counter = 100;

        for (; counter > 0; counter--)
        {
            Debug.Log("Main");
            Thread.Sleep(1000);
        }
        //WaitForUser.Abort();
        Debug.Log("Abort wait!");
    }
Example #4
0
    public static void OnRetrieveData()
    {
        Debug.Log("OnRetrieveData Thread Created!");

        EEGLogger logger = new EEGLogger();

        TextWriter file;
        float      attentionSc = -1;
        int        attentionLv = -1;

        //string root_path= Environment.CurrentDirectory;
        //string path = Directory.GetParent(root_path).ToString();//Directory.GetCurrentDirectory()//.Parent
        string dataLocation = EEGLogger.gameAttentFile;//path + "\\testdata\\Game\\" + DateTime.Now.ToString(@"yyyyddMM_HHmm") + ".csv";

        try
        {
            file = new StreamWriter(dataLocation, true);
            file.WriteLine("AttentionScore , AttentionLevel ");
            file.Close();
        }
        catch (Exception e) {
            Debug.Log("problem writing attention data!");
            Debug.Log(e);
        }

        file = new StreamWriter(dataLocation, true);
        //if (testMode) {


        double[] AF3 = new double[320];
        double[] O1  = new double[320];
        double[] O2  = new double[320];
        double[] AF4 = new double[320];



        //}//end if



        int readcount = 0;

        while (true)
        {
            Debug.Log("EEG RUNNING!");

            //if (testMode) {
            double[] eeg = new double[32];
            Array.Copy(AF4, 32 * (readcount % 10), eeg, 0, 32); //Array.Copy(data, index, result, 0, length);;
                                                                //attention_sc += SampEn(2, 0.25 * std(eeg), eeg);
                                                                //end
            MWNumericArray a         = new MWNumericArray(1, 32, (double[])eeg);
            SampEnClass    sampClass = new SampEnClass();       //(float)logger.generateFakeAttention(); //0-100
            double         std_value = logger.StandDeviation(eeg);
            //sampResults = sampClass.SampEn(2, 0.25 * std_value, a);
            //attenScore = sampResults[0];
            //Debug.Log(attenScore);

            //attentionLv = logger.CalAttensionLevel(attentionSc); ;


            Player.attentionScore = attentionSc;
            Player.attentionLvl   = attentionLv;
            Player.UpdateHorizontalSpeed();
            file.WriteLine(attentionSc + ",  " + attentionLv);
            file.Close();

            //}
            //else
            //{
            //    Debug.Log("Real mode: Continue!");
            //    if (userID > -1)
            //    {

            //        if (logger.Run())
            //        {
            //            file = new StreamWriter(dataLocation, true);
            //            logger.readCount++;
            //            logger.TimeToFrq32();
            //            attentionSc = (float)logger.CalculateAttention();
            //            attentionLv = logger.CalAttensionLevel(attentionSc); ;
            //            Player.attentionScore = attentionSc;
            //            Player.attentionLvl = attentionLv;

            //            file.WriteLine(attentionSc + ",  " + attentionLv);
            //            file.Close();
            //            TODO: Update UI display
            //        }
            //}
            //}//end if/else

            Thread.Sleep(250);
        }
    }//end while
Example #5
0
    public static void SetThresholdR()
    {
        Debug.Log("Relax Training Thread Created!");

        EEGLogger logger = new EEGLogger();

        TextWriter file;
        float      attentionSc  = -1;
        string     dataLocation = EEGLogger.trainRAttentFile;

        file = new StreamWriter(dataLocation, true);

        //set up threshold for attention
        //if (testMode){
        //logger.setFakeThresholds();
        //EEGLogger.

        // EEGLogger.
        //ThresholdSet = true;
        //}
        //else
        //{

        if (testMode)
        {
            string fileName = root_path + "\\testdata\\signals_2.csv";
            Debug.Log(fileName);


            //read line by line
            try
            {
                var reader = new StreamReader(File.OpenRead(fileName));
                var line   = reader.ReadLine();
                var values = line.Split(',');
                var temp   = values.Select(x => Double.Parse(x)).OrderBy(x => x).ToArray();
                Array.Copy(temp, 0, logger.AF3, 0, 320);
                Debug.Log(logger.AF3);
                //Array.Copy(values, logger.AF3, 320);

                //line = reader.ReadLine();
                //values = line.Split(',');
                //Array.Copy(values, logger.O1, 320);

                //line = reader.ReadLine();
                //values = line.Split(',');
                //Array.Copy(values, logger.O2, 320);

                //line = reader.ReadLine();
                //values = line.Split(',');
                //Array.Copy(values, logger.AF4, 320);
            }
            catch (Exception e) {
                Debug.Log(e);
            }
            // var reader = new StreamReader(File.OpenRead(fileName));


            //compute attentionScores
            Debug.Log("EEG RUNNING!");
            int counter = 0;
            for (counter = 0; counter < 5; counter++)
            {
                Debug.Log(counter);
                try
                {
                    double attenScore = logger.FakeRun(counter);
                }
                catch (Exception e) {
                    Debug.Log(e);
                }

                counter++;
                Thread.Sleep(250);
            }
        }
        else
        {
            int counter;

            if (userID > -1)
            {
                for (counter = 0; counter < 127; counter++)
                {
                    if (logger.Run())
                    {
                        logger.TimeToFrq32();
                        attentionSc += logger.CalculateAttention();
                        file.WriteLine(attentionSc);
                    }
                    Thread.Sleep(250);
                }
                file.Close();
            }
            else
            {
                Debug.Log("No user! Can not compute thresholdR!");
            }
        }



        //    if (userID > -1)
        //    {

        //        if (logger.Run())
        //        {
        //            file = new StreamWriter(dataLocation, true);
        //            logger.readCount++;
        //            logger.TimeToFrq32();
        //            attentionSc = (float)logger.CalculateAttention();
        //            attentionLv = logger.CalAttensionLevel(attentionSc); ;
        //            Player.attentionScore = attentionSc;
        //            Player.attentionLvl = attentionLv;

        //            file.WriteLine(attentionSc + ",  " + attentionLv);
        //            file.Close();
        //            //TODO: Update UI display
        //        }
        //    }

        EEGLogger.thresholdR = attentionSc / 128;
        Console.WriteLine("thresholdR = " + EEGLogger.thresholdR);

        //}
        file.Close();
        ThresholdRSet = true;
        Debug.Log("thresholdR set!");
        //GameObject relaxController = GetComponent<RelaxTraining>();

        //while (true)
        //{
        //    Thread.Sleep(250);

        //    //if (testMode){
        //    file = new StreamWriter(dataLocation, true);
        //    logger.readCount++;
        //    attentionSc = (float)logger.generateFakeAttention(); //0-100
        //    attentionLv = logger.CalAttensionLevel(attentionSc); ;
        //    Player.attentionScore = attentionSc;
        //    Player.attentionLvl = attentionLv;
        //    Player.UpdateHorizontalSpeed();
        //    file.WriteLine(attentionSc + ",  " + attentionLv);
        //    file.Close();

        //    //}else{
        //    if (userID > -1)
        //    {

        //        if (logger.Run())
        //        {
        //            file = new StreamWriter(dataLocation, true);
        //            logger.readCount++;
        //            logger.TimeToFrq32();
        //            attentionSc = (float)logger.CalculateAttention();
        //            attentionLv = logger.CalAttensionLevel(attentionSc); ;
        //            Player.attentionScore = attentionSc;
        //            Player.attentionLvl = attentionLv;

        //            file.WriteLine(attentionSc + ",  " + attentionLv);
        //            file.Close();
        //            //TODO: Update UI display
        //        }
        //    }
        //}

        //   }
    }