private void ThreadConnect() { EyeLink _el = new EyeLink(); _el.setEyelinkAddress(IP, -1); threadRunning = true; while (threadRunning) { if (!elOnline) { try { //Debug.Log("Trying to connect"); _el.broadcastOpen(); } catch { } if (_el.isConnected()) { elOnline = true; threadRunning = false; continue; } } } }
// Update is called once per frame void Update() { Sample s; //Sample s; double lastSampleTime = 0.0; // if not connected, has eye calibration and no thread: Initialize thread if (!el.isConnected() && !checker.RunCheck() && !checker.CheckELOnline() && eyecal.has_calibration) { // Configure eye switch (eyecal.GetTrackedEye()) { case 0: el_Eye = EL_EYE.EL_LEFT; break; case 1: el_Eye = EL_EYE.EL_RIGHT; break; default: el_Eye = EL_EYE.EL_EYE_NONE; break; } // Spawn checker thread to test connection checker.StartThread(eyecal.GetEyeLinkIP()); s = null; } // If checker created else if (!el.isConnected() && checker.CheckELOnline() && eyecal.has_calibration) { // Eyelink Online // Connect el.setEyelinkAddress(eyecal.GetEyeLinkIP(), -1); el.broadcastOpen(); if (el.isConnected()) { Debug.Log("EyeLink Connected"); checker.StopThread(); // el.resetData(); el.dataSwitch(4 | 8); } s = null; } // If connected, has calibration and tracker is in record mode: get sample else if (el.isConnected() && eyecal.has_calibration && el.getTrackerMode() == 14) { try { s = el.getNewestSample(); } catch { //Debug.Log(e.ToString()); s = null; } } else { s = null; } // Get position on screen in pixels if (s != null && s.time != lastSampleTime) { if (el_Eye != EL_EYE.EL_EYE_NONE) { if (el_Eye == EL_EYE.EL_BINOCULAR) { el_Eye = EL_EYE.EL_LEFT; } _eyeRaw.x = s.get_px(el_Eye); _eyeRaw.y = s.get_py(el_Eye); eyecal.RawToPix(_eyeRaw, out _eyeDeg, out _eyePix); gazeProcess.ProcessGaze(_eyePix, out float[] gazeTargets, out float[] gazeCounts, out Vector3[] hitPoints);