public StreamEngineTracker(StreamEngineTracker_Description description = null, StreamEngineConnection connection = null)
        {
            if (description == null)
            {
                description = new StreamEngineTracker_Description();
            }

            if (connection == null)
            {
                connection = new StreamEngineConnection(new InteropWrapper());
            }

            LocalLatestData = new TobiiXR_EyeTrackingData();

            _connection = connection;

            if (TryConnectToTracker(_connection, _stopwatch, description) == false)
            {
                throw new Exception("Failed to connect to tracker");
            }

            _nativePointerToSelf = GCHandle.Alloc(this);
            if (SubscribeToWearableData(_connection.Context.Device, GCHandle.ToIntPtr(_nativePointerToSelf)) == false)
            {
                throw new Exception("Failed to subscribe to tracker");
            }

            CheckForCapabilities(_connection.Context.Device);
        }
        public bool Open(FieldOfUse fieldOfUse, StreamEngineTracker_Description description)
        {
            IntPtr apiContext;

            if (Context != null)
            {
                throw new InvalidOperationException("There is already an instantiated connection");
            }

            if (CreateApiContext(_interop, out apiContext, _customLog) == false)
            {
                return(false);
            }

            List <string> connectedDevices;

            if (GetAvailableTrackers(_interop, apiContext, out connectedDevices) == false)
            {
                DestroyApiContext(_interop, apiContext);
                return(false);
            }

            IntPtr deviceContext;
            string hmdEyeTrackerUrl;
            var    interopFieldOfUse = fieldOfUse == FieldOfUse.Interactive ? Interop.tobii_field_of_use_t.TOBII_FIELD_OF_USE_INTERACTIVE : Interop.tobii_field_of_use_t.TOBII_FIELD_OF_USE_ANALYTICAL;

            if (GetFirstSupportedTracker(_interop, apiContext, interopFieldOfUse, connectedDevices, description, out deviceContext, out hmdEyeTrackerUrl) == false)
            {
                DestroyApiContext(_interop, apiContext);
                return(false);
            }

            Context = new StreamEngineContext(apiContext, deviceContext, hmdEyeTrackerUrl);
            return(true);
        }
        public StreamEngineTracker(StreamEngineTracker_Description description = null, StreamEngineConnection connection = null)
        {
            if (description == null)
            {
                description = new StreamEngineTracker_Description();
            }

            if (connection == null)
            {
                connection = new StreamEngineConnection(new InteropWrapper());
            }

            LocalLatestData = new TobiiXR_EyeTrackingData();

            _connection = connection;

            if (TryConnectToTracker(_connection, _stopwatch, description) == false)
            {
                throw new Exception("Failed to connect to tracker");
            }

            _wearableDataCallback = OnWearableData;
            if (SubscribeToWearableData(_connection.Context.Device, _wearableDataCallback) == false)
            {
                throw new Exception("Failed to subscribe to tracker");
            }

            CheckForCapabilities(_connection.Context.Device);
        }
        public bool Open(StreamEngineTracker_Description description)
        {
            IntPtr apiContext;

            if (Context != null)
            {
                throw new InvalidOperationException("There is already an instantiated connection");
            }

            if (CreateApiContext(_interop, out apiContext, _customLog) == false)
            {
                return(false);
            }

            List <string> connectedDevices;

            if (GetAvailableTrackers(_interop, apiContext, out connectedDevices) == false)
            {
                DestroyApiContext(_interop, apiContext);
                return(false);
            }

            IntPtr deviceContext;
            string hmdEyeTrackerUrl;

            if (GetFirstSupportedTracker(_interop, apiContext, connectedDevices, description, out deviceContext, out hmdEyeTrackerUrl) == false)
            {
                DestroyApiContext(_interop, apiContext);
                return(false);
            }

            Context = new StreamEngineContext(apiContext, deviceContext, hmdEyeTrackerUrl);
            return(true);
        }
        public bool InitializeWithLicense(string licenseKey, bool enableAdvanced)
        {
            var createInfo = new StreamEngineTracker_Description();

            if (!string.IsNullOrEmpty(licenseKey))
            {
                createInfo.License = new[] { licenseKey };
            }

            try
            {
                _hmdToWorldTransformer = new HmdToWorldTransformer(estimatedEyeTrackerLatency_s: 0.012f);
                _streamEngineTracker   = new StreamEngineTracker(createInfo);

                // Subscribe to relevant streams
                var startInfo = new StreamEngineTrackerStartInfo();
                if (enableAdvanced)
                {
                    startInfo.WearableAdvancedDataCallback = OnAdvancedWearableData;
                }
                else
                {
                    startInfo.WearableDataCallback = OnWearableData;
                }
                _streamEngineTracker.Start(startInfo);

                return(true);
            }
            catch (Exception e)
            {
                Debug.Log(e.Message);
                return(false);
            }
        }
Exemplo n.º 6
0
 private bool Initialize(StreamEngineTracker_Description description)
 {
     try
     {
         return(Initialize(new StreamEngineTracker(description)));
     }
     catch (Exception e)
     {
         Debug.Log(e.Message);
         return(false);
     }
 }
Exemplo n.º 7
0
        public static bool TryConnect(IStreamEngineInterop interop, StreamEngineTracker_Description description, out StreamEngineContext context, tobii_custom_log_t customLog = null)
        {
            _stopwatch.Reset();
            _stopwatch.Start();

            context = null;
            IntPtr apiContext;

            if (CreateApiContext(interop, out apiContext, customLog) == false)
            {
                return(false);
            }

            try
            {
                List <string> connectedDevices;
                if (GetAvailableTrackers(interop, apiContext, out connectedDevices) == false)
                {
                    DestroyApiContext(interop, apiContext);
                    return(false);
                }

                IntPtr deviceContext;
                string hmdEyeTrackerUrl;
                if (GetFirstSupportedTracker(interop, apiContext, connectedDevices, description, out deviceContext, out hmdEyeTrackerUrl) == false)
                {
                    DestroyApiContext(interop, apiContext);
                    return(false);
                }

                context = new StreamEngineContext(apiContext, deviceContext, hmdEyeTrackerUrl);
                _stopwatch.Stop();
                UnityEngine.Debug.Log(string.Format("Connected to SE tracker: {0} and it took {1}ms",
                                                    context.Url, _stopwatch.ElapsedMilliseconds));
                return(true);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError("Error connecting to eye tracker: " + e.ToString());
                return(false);
            }
        }
Exemplo n.º 8
0
        public StreamEngineTracker(StreamEngineTracker_Description description)
        {
            _streamEngineInteropWrapper = new StreamEngineInteropWrapper();

            if (description == null)
            {
                description = new StreamEngineTracker_Description();
            }

            // Connect
            var customLog = new tobii_custom_log_t {
                log_func = LogCallback
            };
            StreamEngineContext context;

            if (ConnectionHelper.TryConnect(_streamEngineInteropWrapper, description, out context, customLog) == false)
            {
                throw new Exception("Failed to connect to tracker");
            }
            Context = context;

            // Start background thread that handles processing of data and reconnecting
            _processInBackground = true;
            _backgroundThread    = new Thread(ProcessLoop)
            {
                IsBackground = true
            };
            _backgroundThread.Start();

            // Get connection metadata
            CheckForCapabilities(Context.Device);
            tobii_feature_group_t licenseLevel;

            Interop.tobii_get_feature_group(Context.Device, out licenseLevel);
            LicenseLevel = licenseLevel;
        }
        private static bool TryConnectToTracker(StreamEngineConnection connection, Stopwatch stopwatch, StreamEngineTracker_Description description)
        {
            StartStopwatch(stopwatch);

            try
            {
                if (connection.Open(description) == false)
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError("Error connecting to eye tracker: " + e.ToString());
                return(false);
            }

            var elapsedTime = StopStopwatch(stopwatch);

            UnityEngine.Debug.Log(string.Format("Connected to SE tracker: {0} and it took {1}ms", connection.Context.Url, elapsedTime));
            return(true);
        }
        private static bool GetFirstSupportedTracker(IStreamEngineInterop interop, IntPtr apiContext, Interop.tobii_field_of_use_t fieldOfUse, IList <string> connectedDevices, StreamEngineTracker_Description description, out IntPtr deviceContext, out string deviceUrl)
        {
            deviceContext = IntPtr.Zero;
            deviceUrl     = "";

            for (var i = 0; i < connectedDevices.Count; i++)
            {
                var connectedDeviceUrl = connectedDevices[i];
                if (CreateDeviceContext(interop, connectedDeviceUrl, fieldOfUse, apiContext, description.License, out deviceContext) == false)
                {
                    continue;
                }

                tobii_device_info_t info;
                var result = interop.tobii_get_device_info(deviceContext, out info);
                if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
                {
                    DestroyDeviceContext(interop, deviceContext);
                    UnityEngine.Debug.LogWarning("Failed to get device info. " + result);
                    continue;
                }

                var integrationType = info.integration_type.ToLowerInvariant();
                if (integrationType != description.SupportedIntegrationType)
                {
                    DestroyDeviceContext(interop, deviceContext);
                    continue;
                }

                deviceUrl = connectedDeviceUrl;
                return(true);
            }

            UnityEngine.Debug.LogWarning(string.Format("Failed to find Tobii eye trackers of integration type {0}", description.SupportedIntegrationType));
            return(false);
        }
Exemplo n.º 11
0
        public StreamEngineTracker(StreamEngineTracker_Description description)
        {
            _streamEngineInteropWrapper = new StreamEngineInteropWrapper();
            _customLog = new tobii_custom_log_t {
                log_func = LogCallback
            };

            if (description == null)
            {
                description = new StreamEngineTracker_Description();
            }

            // Connect
            StreamEngineContext context;

            if (ConnectionHelper.TryConnect(_streamEngineInteropWrapper, description, out context, _customLog) == false)
            {
                throw new Exception("Failed to connect to tracker");
            }
            Context = context;

            // Subscribe to requested streams
            tobii_error_t result;

            if (description.WearableDataCallback != null)
            {
                _wearableDataCallbackPointer = GCHandle.Alloc(description.WearableDataCallback);
                result = Interop.tobii_wearable_consumer_data_subscribe(context.Device, WearableDataCallback, GCHandle.ToIntPtr(_wearableDataCallbackPointer));
                if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
                {
                    throw new Exception("Failed to subscribe to eye tracking data: " + result);
                }
            }

            if (description.WearableAdvancedDataCallback != null)
            {
                _wearableAdvancedDataCallbackPointer = GCHandle.Alloc(description.WearableAdvancedDataCallback);
                result = Interop.tobii_wearable_advanced_data_subscribe(context.Device, AdvancedWearableDataCallback, GCHandle.ToIntPtr(_wearableAdvancedDataCallbackPointer));
                if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
                {
                    throw new Exception("Failed to subscribe to eye tracking data: " + result);
                }
            }

            if (description.WearableFoveatedDataCallback != null)
            {
                _wearableFoveatedDataCallbackPointer = GCHandle.Alloc(description.WearableFoveatedDataCallback);
                result = Interop.tobii_wearable_foveated_gaze_subscribe(context.Device, WearableFoveatedGazeCallback, GCHandle.ToIntPtr(_wearableFoveatedDataCallbackPointer));
                if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
                {
                    throw new Exception("Failed to subscribe to eye tracking data: " + result);
                }
            }

            // Get connection metadata
            CheckForCapabilities(Context.Device);
            tobii_feature_group_t licenseLevel;

            Interop.tobii_get_feature_group(Context.Device, out licenseLevel);
            LicenseLevel = licenseLevel;
        }