Example #1
0
    private void Update()
    {
        /*
         * if (++cycleCount >= 2 && sendFinished == true)
         * {
         *  if (photoCaptureObject != null)
         *  {
         *      //photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
         *      photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
         *  }
         *
         *  cycleCount = 0;
         * }*/

        targetTime -= Time.deltaTime;

        if (targetTime <= 0.0f)
        {
            if (state == 0)
            {
                if (CONTINUAL)
                {
                    photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
                    targetTime = 5f; //timeout time
                    state      = -1;
                }
                else
                {
                    if (!picture_taken)
                    {
                        photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);
                        picture_taken = true;
                    }
                    stimulusManager.GazeShift();
                    targetTime = 0.5f;
                    state      = 1;
                }
            }

            else if (state == -1)
            {
                state = 0;
            }

            else if (state == 1)
            {
                stimulusManager.StartStimulating();
                targetTime = STIMULATION_DURATION;
                state      = 2;
            }
            else if (state == 2)
            {
                stimulusManager.StopStimulating();
                state = 0;
            }
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        targetTime -= Time.deltaTime;

        if (targetTime <= 0.0f && !textToSpeech.IsSpeaking())
        {
            if (state == 0)
            {
                ++state;
                string s = "Please follow the red target.";
                Debug.Log(s);
                textToSpeech.StartSpeaking(s);
                targetTime = 1f;
            }
        }
        if (targetTime <= 0.0f && state == 1)
        {
            //stimulusManager.GazeShift(trainingTarget);
            stimulusManager.GazeShift();

            if (EVENT_MARKER_TYPE == TCP_EVENT_MARKER)
            {
#if !UNITY_EDITOR
                Connect();
#endif
            }
            else if (EVENT_MARKER_TYPE == LPT_EVENT_MARKER)
            {
                ParallelPortManager.Out32_x64(ParallelPortManager.address, 0);
            }

            if (++trainingTarget == numPerColumn * numPerRow)
            {
                trainingTarget = 0;
            }
            targetTime = 1f;
            state      = 2;
        }
        if (targetTime <= 0.0f && state == 2)
        {
            byte[] msg = new byte[1];
            msg[0] = 1;

            stimulusManager.StartStimulating();

            targetTime = 2f;
            state      = 1;

            if (EVENT_MARKER_TYPE == TCP_EVENT_MARKER)
            {
#if !UNITY_EDITOR
                SendMessage(msg);
#endif
            }
            else if (EVENT_MARKER_TYPE == LPT_EVENT_MARKER)
            {
                ParallelPortManager.Out32_x64(ParallelPortManager.address, 1);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        targetTime -= Time.deltaTime;

        if (targetTime <= 0.0f)
        {
            if (waitKeyState == 1)
            {
                if (setTextFlag == true)
                {
                    textUpdater.setText(s);
                    setTextFlag = false;
                }
                if (Input.anyKeyDown)
                {
                    waitKeyState = 0;
                    textUpdater.setText(" ");
                }
            }

            else if (state == 0)
            {
                ++state;
                if (EVENT_MARKER_TYPE == LPT_EVENT_MARKER)
                {
                    ParallelPortManager.Out32_x64(ParallelPortManager.address, 0);
                }

                if (trialCount == TRIAL_PER_BLOCK)
                {
                    if (conditionCount == CONDITION_NUM)
                    {
                        blockCount    += 1;
                        conditionCount = 0;
                        //Shuffle(conditions);
                        Shuffle(orders);

                        if (blockCount == BLOCK_NUM)
                        {
                            Debug.Log(practiceFlag.ToString());
                            if (practiceFlag == true)
                            {
                                CONDITION_NUM   = EXP_CONDITION_NUM;
                                TRIAL_PER_BLOCK = EXP_TRIAL_PER_BLOCK;
                                BLOCK_NUM       = EXP_BLOCK_NUM;
                                trialCount      = TRIAL_PER_BLOCK;

                                practiceFlag = false;
                                waitKeyState = 1;
                                s            = "Experiment Session";
                                setTextFlag  = true;
                                state        = 0;
                            }
                            else
                            {
                                if (parallelFlag == false)
                                {
                                    parallelFlag = true;
                                    state        = 5;
                                }
                                else
                                {
                                    state = 8;
                                }
                            }

                            conditionCount = 0;
                            blockCount     = 0;
                            stimulusManager.StopStimulating();

                            return;
                        }
                    }

                    if (parallelFlag == true)
                    {
                        setStimulus(conditions[conditionCount]);
                    }


                    conditionCount += 1;
                    stimulusManager.StopStimulating();
                    trialCount   = 0;
                    waitKeyState = 1;
                }

                trialCount++;

                trainingTarget = 0;
                targetTime     = 0f;
            }

            else if (state == 1)
            {
                int trainingTargets = orders[trainingTarget];
                if (parallelFlag == false)
                {
                    setSerialStimulus(orders[trainingTarget], conditions[conditionCount - 1]);
                    stimulusManager.GazeShift(0);
                }
                else
                {
                    stimulusManager.GazeShift(trainingTargets);
                }

                if (EVENT_MARKER_TYPE == TCP_EVENT_MARKER)
                {
#if !UNITY_EDITOR
                    Connect();
#endif
                }
                else if (EVENT_MARKER_TYPE == LPT_EVENT_MARKER)
                {
                    ParallelPortManager.Out32_x64(ParallelPortManager.address, 0);
                }

                targetTime = GAZE_SHIFT_LENGTH;
                state      = 2;
            }
            else if (state == 2)
            {
                targetTime = STIM_LENGTH;
                state      = 1;

                if (++trainingTarget == TARGET_NUM)
                {
                    state = 0;
                }

                stimulusManager.StartStimulating();

                if (practiceFlag == false)
                {
                    int eventValue = conditions[conditionCount - 1] * 10 + (orders[trainingTarget - 1] + 1);
                    //Debug.Log(eventValue.ToString());
                    if (EVENT_MARKER_TYPE == TCP_EVENT_MARKER)
                    {
                        byte[] msg = new byte[2];
                        msg[0] = (byte)(orders[trainingTarget - 1] + 1);
                        msg[1] = (byte)(conditions[conditionCount - 1] * 10);
#if !UNITY_EDITOR
                        SendMessage(msg);
#endif
                    }
                    else if (EVENT_MARKER_TYPE == LPT_EVENT_MARKER)
                    {
                        //Debug.Log((conditionCount - 1).ToString());
                        //Debug.Log((trainingTarget - 1).ToString());
                        //Debug.Log("Block: " + (blockCount + 1) + ". Condition: " + conditions[conditionCount - 1] + ". Trial: " + trialCount + ". Target: " + (orders[trainingTarget - 1] + 1));
                        //int eventValue = (blockCount + 1) * 1000 + conditions[conditionCount - 1] * 100 + trialCount * 10 + (orders[trainingTarget - 1] + 1);
                        ParallelPortManager.Out32_x64(ParallelPortManager.address, eventValue);
                    }
                    else if (EVENT_MARKER_TYPE == LSL_EVENT_MARKER)
                    {
                        string[] sample = new string[1];
                        sample[0] = eventValue.ToString();
                        outlet.push_sample(sample);
                    }
                }
            }
            else if (state == 5)
            {
                waitKeyState = 1;
                s            = "Practice Session";
                setTextFlag  = true;
                state        = 6;
            }
            else if (state == 6)
            {
                practiceFlag    = true;
                CONDITION_NUM   = PRAC_CONDITION_NUM;
                TRIAL_PER_BLOCK = PRAC_TRIAL_PER_BLOCK;
                BLOCK_NUM       = PRAC_BLOCK_NUM;

                trialCount = TRIAL_PER_BLOCK;
                state      = 0;
            }
            else if (state == 8)
            {
                waitKeyState = 1;
                s            = "The experiment is over. Thank you!";
                setTextFlag  = true;
                state        = -100;
            }
        }
    }