Example #1
0
 public void Setup()
 {
     if (_controller == null)
     {
         _controller = new PupilController(Settings, ConnectionSettings);
     }
 }
Example #2
0
 void Update()
 {
     if (IsMonitoring)
     {
         PupilController.Update();
     }
     if (PupilController.IsCalibrating)
     {
         PupilController.Calibration.UpdateCalibration();
     }
 }
Example #3
0
 public void Disconnect()
 {
     if (!IsConnected)
     {
         return;
     }
     if (IsMonitoring)
     {
         StopMonitoring();
     }
     PupilController.Disconnect();
     _controller = null;
 }
        static readonly float TimeBetweenCalibrationPoints = 0.02f; // was 0.1, 1000/60 ms wait in old version
        public void UpdateCalibration()
        {
            var t = Time.realtimeSinceStartup;

            if (!(t - _lastTimeStamp > TimeBetweenCalibrationPoints))
            {
                return;
            }
            _lastTimeStamp = t;
            UpdateCalibrationPoint();

            //Adding the calibration reference data to the list that wil;l be passed on, once the required sample amount is met.
            if (_currentCalibrationSamples > samplesToIgnoreForEyeMovement)
            {
                PupilController.AddCalibrationPointReferencePosition(currentCalibrationPointPosition, t);
            }

            if (PupilManager.Instance.Settings.debug.printSampling)
            {
                Debug.Log("Point: " + _currentCalibrationPoint + ", " + "Sampling at : " +
                          _currentCalibrationSamples + ". On the position : " + currentCalibrationPointPosition[0] +
                          " | " + currentCalibrationPointPosition[1]);
            }

            _currentCalibrationSamples++; //Increment the current calibration sample. (Default sample amount per calibration point is 120)

            if (_currentCalibrationSamples < currentCalibrationType.samplesPerDepth)
            {
                return;
            }
            _currentCalibrationSamples = 0;
            _currentCalibrationDepth++;

            if (_currentCalibrationDepth < currentCalibrationType.vectorDepthRadius.Length)
            {
                return;
            }
            _currentCalibrationDepth = 0;
            _currentCalibrationPoint++;

            //Send the current relevant calibration data for the current calibration point. _CalibrationPoints returns _calibrationData as an array of a Dictionary<string,object>.
            PupilController.AddCalibrationReferenceData();

            if (_currentCalibrationPoint >= currentCalibrationType.points)
            {
                PupilController.StopCalibration();
            }
        }
Example #5
0
 public void StopMonitoring()
 {
     if (!IsConnected)
     {
         return;
     }
     if (!IsMonitoring)
     {
         return;
     }
     Debug.Log("Stopping monitoring");
     PupilController.UnSubscribeFrom("pupil.");
     PupilController.OnReceiveData -= DataReceived;
     IsMonitoring = false;
     PupilController.Update(); //the sockets are closed during the update
 }
Example #6
0
 public void StartMonitoring()
 {
     if (!IsConnected)
     {
         return;
     }
     if (IsMonitoring)
     {
         return;
     }
     Debug.Log("Starting monitoring");
     //PupilController.CalibrationMode = PupilCalibration.Mode._2D;
     PupilController.SubscribeTo("pupil.");
     PupilController.OnReceiveData += DataReceived;
     IsMonitoring = true;
 }
        public void InitializeSubscriptionSocket(string topic)
        {
            if (SubscriptionSocketForTopic.ContainsKey(topic))
            {
                return;
            }
            SubscriptionSocketForTopic.Add(topic, new SubscriberSocket(Settings.IPHeader + Settings.Subport));
            SubscriptionSocketForTopic[topic].Subscribe(topic);

            Debug.Log("initializing conneciton " + topic);
            //André: Is this necessary??
            //subscriptionSocketForTopic[topic].Options.SendHighWatermark = PupilSettings.numberOfMessages;// 6;
            SubscriptionSocketForTopic[topic].ReceiveReady += (s, a) =>
            {
                var m = new NetMQMessage();
                while (a.Socket.TryReceiveMultipartMessage(ref m))
                {
                    // We read all the messages from the socket, but disregard the ones after a certain point
                    //				if ( i > PupilSettings.numberOfMessages ) // 6)
                    //					continue;

                    var msgType = m[0].ConvertToString();
                    _mStream = new MemoryStream(m[1].ToByteArray());
                    byte[] thirdFrame = null;
                    if (m.FrameCount >= 3)
                    {
                        thirdFrame = m[2].ToByteArray();
                    }
                    if (PupilManager.Instance.Settings.debug.printMessageType)
                    {
                        Debug.Log(msgType);
                    }
                    if (PupilManager.Instance.Settings.debug.printMessage)
                    {
                        Debug.Log(MessagePackSerializer.ToJson(m[1].ToByteArray()));
                    }
                    if (PupilController.ReceiveDataIsSet)
                    {
                        PupilController.ReceiveData(msgType, MessagePackSerializer.Deserialize <Dictionary <string, object> >(_mStream), thirdFrame);
                    }

                    switch (msgType)
                    {
                    case "notify.calibration.successful":
                        PupilController.CalibrationFinished();
                        Debug.Log(msgType);
                        break;

                    case "notify.calibration.failed":
                        PupilController.CalibrationFailed();
                        Debug.Log(msgType);
                        break;

                    case "gaze":
                    case "gaze.2d.0.":
                    case "gaze.2d.1.":
                    case "pupil.0":
                    case "pupil.1":
                    case "gaze.3d.0.":
                    case "gaze.3d.1.":
                    case "gaze.3d.01.":
                        var dictionary = MessagePackSerializer.Deserialize <Dictionary <string, object> >(_mStream);
                        var confidence = PupilDataParser.FloatFromDictionary(dictionary, "confidence");
                        if (PupilController.IsCalibrating)
                        {
                            var eyeID = PupilDataParser.StringFromDictionary(dictionary, "id");
                            PupilController.UpdateCalibrationConfidence(eyeID, confidence);
                        }
                        else if (msgType.StartsWith("gaze") & confidence > Settings.ConfidenceThreshold)
                        {
                            PupilController.gazeDictionary = dictionary;
                        }
                        break;

                    case "frame.eye.0":
                    case "frame.eye.1":
                        break;

                    default:
                        Debug.Log("No case to handle message with message type " + msgType);
                        break;
                    }
                }
            };
        }
Example #8
0
 public void Connect()
 {
     Setup();
     StartCoroutine(PupilController.Connect(retry: true, retryDelay: 5f));
 }