Exemple #1
0
 void CollectKeyEvents()
 {
     if (IsMacOS())
     {
         int eventCount = UnityEPL.CountKeyEvents();
         if (eventCount >= 1)
         {
             int    keyCode   = UnityEPL.PopKeyKeycode();
             double timestamp = UnityEPL.PopKeyTimestamp();
             bool   downState;
             keyDownStates.TryGetValue(keyCode, out downState);
             keyDownStates[keyCode] = !downState;
             ReportKey(keyCode, keyDownStates[keyCode], OSXTimestampToTimestamp(timestamp));
         }
     }
     else
     {
         foreach (KeyCode keyCode in System.Enum.GetValues(typeof(KeyCode)))
         {
             if (Input.GetKeyDown(keyCode))
             {
                 ReportKey((int)keyCode, true, DataReporter.RealWorldTime());
             }
             if (Input.GetKeyUp(keyCode))
             {
                 ReportKey((int)keyCode, false, DataReporter.RealWorldTime());
             }
         }
     }
 }
Exemple #2
0
    //ramulator expects this when you display words to the subject.
    //for words, stateName is "WORD"
    public void SetState(string stateName, bool stateToggle, System.Collections.Generic.Dictionary <string, object> sessionData)
    {
        sessionData.Add("name", stateName);
        sessionData.Add("value", stateToggle.ToString());
        DataPoint sessionDataPoint = new DataPoint("STATE", DataReporter.RealWorldTime(), sessionData);

        SendMessageToRamulator(sessionDataPoint.ToJSON());
    }
Exemple #3
0
    void CollectMousePosition()
    {
        Dictionary <string, object> dataDict = new Dictionary <string, object>();

        dataDict.Add("position", Input.mousePosition);
        eventQueue.Enqueue(new DataPoint("mouse position", DataReporter.RealWorldTime(), dataDict));
        lastMousePositionReportFrame = Time.frameCount;
    }
Exemple #4
0
    public void SendMathMessage(string problem, string response, int responseTimeMs, bool correct)
    {
        Dictionary <string, object> mathData = new Dictionary <string, object>();

        mathData.Add("problem", problem);
        mathData.Add("response", response);
        mathData.Add("response_time_ms", responseTimeMs.ToString());
        mathData.Add("correct", correct.ToString());
        DataPoint mathDataPoint = new DataPoint("MATH", DataReporter.RealWorldTime(), mathData);

        SendMessageToRamulator(mathDataPoint.ToJSON());
    }
Exemple #5
0
    //ramulator expects this before the beginning of a new list
    public void BeginNewTrial(int trialNumber)
    {
        if (zmqSocket == null)
        {
            throw new Exception("Please begin a session before beginning trials");
        }
        System.Collections.Generic.Dictionary <string, object> sessionData = new Dictionary <string, object>();
        sessionData.Add("trial", trialNumber.ToString());
        DataPoint sessionDataPoint = new DataPoint("TRIAL", DataReporter.RealWorldTime(), sessionData);

        SendMessageToRamulator(sessionDataPoint.ToJSON());
    }
Exemple #6
0
    //this coroutine connects to ramulator and communicates how ramulator expects it to
    //in order to start the experiment session.  follow it up with BeginNewTrial and
    //SetState calls
    public IEnumerator BeginNewSession(int sessionNumber)
    {
        //Connect to ramulator///////////////////////////////////////////////////////////////////
        zmqSocket = new NetMQ.Sockets.PairSocket();
        zmqSocket.Bind(address);
        //Debug.Log ("socket bound");


        yield return(WaitForMessage("CONNECTED", "Ramulated not connected."));


        //SendSessionEvent//////////////////////////////////////////////////////////////////////
        System.Collections.Generic.Dictionary <string, object> sessionData = new Dictionary <string, object>();
        sessionData.Add("name", UnityEPL.GetExperimentName());
        sessionData.Add("version", Application.version);
        sessionData.Add("subject", UnityEPL.GetParticipants()[0]);
        sessionData.Add("session_number", sessionNumber.ToString());
        DataPoint sessionDataPoint = new DataPoint("SESSION", DataReporter.RealWorldTime(), sessionData);

        SendMessageToRamulator(sessionDataPoint.ToJSON());
        yield return(null);


        //Begin Heartbeats///////////////////////////////////////////////////////////////////////
        InvokeRepeating("SendHeartbeat", 0, 1);


        //SendReadyEvent////////////////////////////////////////////////////////////////////
        DataPoint ready = new DataPoint("READY", DataReporter.RealWorldTime(), new Dictionary <string, object>());

        SendMessageToRamulator(ready.ToJSON());
        yield return(null);


        yield return(WaitForMessage("START", "Start signal not received"));


        InvokeRepeating("ReceiveHeartbeat", 0, 1);
    }
Exemple #7
0
 public static double MillisecondsSinceTheEpoch()
 {
     return(DataPoint.ConvertToMillisecondsSinceEpoch(DataReporter.RealWorldTime()));
 }
Exemple #8
0
    private void SendHeartbeat()
    {
        DataPoint sessionDataPoint = new DataPoint("HEARTBEAT", DataReporter.RealWorldTime(), null);

        SendMessageToRamulator(sessionDataPoint.ToJSON());
    }
    protected IEnumerator DoMicrophoneTest(string title, string press_any_key, string recording, string playing, string confirmation)
    {
        DisplayTitle(title);
        bool   repeat = false;
        string wavFilePath;

        do
        {
            yield return(PressAnyKey(press_any_key));

            lowBeep.Play();
            textDisplayer.DisplayText("microphone test recording", recording);
            textDisplayer.ChangeColor(Color.red);
            yield return(new WaitForSeconds(lowBeep.clip.length));

            wavFilePath = System.IO.Path.Combine(UnityEPL.GetDataPath(), "microphone_test_" + DataReporter.RealWorldTime().ToString("yyyy-MM-dd_HH_mm_ss") + ".wav");
            soundRecorder.StartRecording(wavFilePath);
            yield return(new WaitForSeconds(MICROPHONE_TEST_LENGTH));

            soundRecorder.StopRecording();

            textDisplayer.DisplayText("microphone test playing", playing);
            textDisplayer.ChangeColor(Color.green);

            audioPlayback.clip = soundRecorder.AudioClipFromDatapath(wavFilePath);
            audioPlayback.Play();
            yield return(new WaitForSeconds(MICROPHONE_TEST_LENGTH));

            textDisplayer.ClearText();
            textDisplayer.OriginalColor();

            SetRamulatorState("WAITING", true, new Dictionary <string, object>());
            textDisplayer.DisplayText("microphone test confirmation", confirmation);
            while (!Input.GetKeyDown(KeyCode.Y) && !Input.GetKeyDown(KeyCode.N) && !Input.GetKeyDown(KeyCode.C))
            {
                yield return(null);
            }
            textDisplayer.ClearText();
            SetRamulatorState("WAITING", false, new Dictionary <string, object>());
            if (Input.GetKey(KeyCode.C))
            {
                Quit();
            }
            repeat = Input.GetKey(KeyCode.N);
        }while (repeat);

        if (!System.IO.File.Exists(wavFilePath))
        {
            yield return(PressAnyKey("WARNING: Wav output file not detected.  Sounds may not be successfully recorded to disk."));
        }

        ClearTitle();
    }
Exemple #10
0
    protected IEnumerator DoMicrophoneTest()
    {
        microphoneTestMessage.SetActive(true);
        bool   repeat = false;
        string wavFilePath;

        do
        {
            yield return(PressAnyKey("Press the spacebar to record a sound after the beep.", new KeyCode[] { KeyCode.Space }, textDisplayer));

            lowBeep.Play();
            textDisplayer.DisplayText("microphone test recording", "Recording...");
            textDisplayer.ChangeColor(Color.red);
            yield return(new WaitForSeconds(lowBeep.clip.length));

            wavFilePath = System.IO.Path.Combine(UnityEPL.GetDataPath(), "microphone_test_" + DataReporter.RealWorldTime().ToString("yyyy-MM-dd_HH_mm_ss") + ".wav");
            soundRecorder.StartRecording();
            yield return(new WaitForSeconds(5f));

            soundRecorder.StopRecording(wavFilePath);
            textDisplayer.ClearText();

            yield return(new WaitForSeconds(1f));

            textDisplayer.DisplayText("microphone test playing", "Playing...");
            textDisplayer.ChangeColor(Color.green);
            audioPlayback.clip = soundRecorder.AudioClipFromDatapath(wavFilePath);
            audioPlayback.Play();
            yield return(new WaitForSeconds(5f));

            textDisplayer.ClearText();
            textDisplayer.OriginalColor();

            textDisplayer.DisplayText("microphone test confirmation", "Did you hear the recording? \n(Y=Continue / N=Try Again / C=Cancel).");
            while (!Input.GetKeyDown(KeyCode.Y) && !Input.GetKeyDown(KeyCode.N) && !Input.GetKeyDown(KeyCode.C))
            {
                yield return(null);
            }
            textDisplayer.ClearText();

            if (Input.GetKey(KeyCode.C))
            {
                Quit();
            }
            repeat = Input.GetKey(KeyCode.N);
        }while (repeat);

        if (!System.IO.File.Exists(wavFilePath))
        {
            yield return(PressAnyKey("WARNING: Wav output file not detected.  Sounds may not be successfully recorded to disk.", new KeyCode[] { KeyCode.Return }, textDisplayer));
        }

        microphoneTestMessage.SetActive(false);
    }