private static bool CreateDeviceContext(IStreamEngineInterop interop, string url, Interop.tobii_field_of_use_t fieldOfUse, IntPtr apiContext, string[] licenseKeys, out IntPtr deviceContext)
        {
            if (licenseKeys == null || licenseKeys.Length == 0)
            {
                return(interop.tobii_device_create(apiContext, url, fieldOfUse, out deviceContext) == tobii_error_t.TOBII_ERROR_NO_ERROR);
            }

            var licenseResults = new List <tobii_license_validation_result_t>();
            var result         = interop.tobii_device_create_ex(apiContext, url, fieldOfUse, licenseKeys, licenseResults, out deviceContext);

            if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
            {
                UnityEngine.Debug.LogError(string.Format("Failed to create device context for {0}. {1}", url, result));
                return(false);
            }

            for (int i = 0; i < licenseKeys.Length; i++)
            {
                var licenseResult = licenseResults[i];
                if (licenseResult == tobii_license_validation_result_t.TOBII_LICENSE_VALIDATION_RESULT_OK)
                {
                    continue;
                }

                UnityEngine.Debug.LogError("License " + licenseKeys[i] + " failed. Return code " + licenseResult);
            }

            return(true);
        }
 public StreamEngineConnection(IStreamEngineInterop interop)
 {
     _interop   = interop;
     _customLog = new tobii_custom_log_t {
         log_func = LogCallback
     };
 }
예제 #3
0
        public static void Disconnect(IStreamEngineInterop interop, StreamEngineContext context)
        {
            if (context == null)
            {
                return;
            }

            DestroyDeviceContext(interop, context.Device);
            DestroyApiContext(interop, context.Api);
        }
예제 #4
0
        public static bool TryReconnect(IStreamEngineInterop interop, IntPtr deviceContext)
        {
            var result = interop.tobii_device_reconnect(deviceContext);

            if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
            {
                return(false);
            }

            UnityEngine.Debug.Log("Reconnected.");
            return(true);
        }
        private static bool ReconnectToDevice(IStreamEngineInterop interop, IntPtr deviceContext)
        {
            var nativeContext = deviceContext;
            var result        = interop.tobii_device_reconnect(nativeContext);

            if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
            {
                return(false);
            }

            UnityEngine.Debug.Log("Reconnected.");
            return(true);
        }
        private static bool CreateApiContext(IStreamEngineInterop interop, out IntPtr apiContext, tobii_custom_log_t customLog = null)
        {
            var result = interop.tobii_api_create(out apiContext, customLog);

            if (result == tobii_error_t.TOBII_ERROR_NO_ERROR)
            {
                return(true);
            }

            UnityEngine.Debug.LogError("Failed to create api context. " + result);
            apiContext = IntPtr.Zero;
            return(false);
        }
        private static void DestroyApiContext(IStreamEngineInterop interop, IntPtr apiContext)
        {
            if (apiContext == IntPtr.Zero)
            {
                return;
            }

            var result = interop.tobii_api_destroy(apiContext);

            if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
            {
                UnityEngine.Debug.LogError(string.Format("Failed to destroy api context. Error {0}", result));
            }
        }
예제 #8
0
        private static bool GetFirstSupportedTracker(IStreamEngineInterop interop, IntPtr apiContext, IList <string> connectedDevices, StreamEngineTracker_Description description, out IntPtr deviceContext, out string deviceUrl)
        {
            var index = -1;

            deviceContext = IntPtr.Zero;
            deviceUrl     = "";

            for (var i = 0; i < connectedDevices.Count; i++)
            {
                var connectedDeviceUrl = connectedDevices[i];
                // TODO: Use field of use from facade
                if (CreateDeviceContext(interop, connectedDeviceUrl, Interop.tobii_field_of_use_t.TOBII_FIELD_OF_USE_INTERACTIVE, apiContext, description.License, out deviceContext) == false)
                {
                    return(false);
                }

                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);
                    return(false);
                }

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

                index     = i;
                deviceUrl = connectedDeviceUrl;
                break;
            }

            if (index != -1)
            {
                return(true);
            }

            UnityEngine.Debug.LogWarning(string.Format("Failed to find Tobii eye trackers of integration type {0}", description.SupportedIntegrationType));
            DestroyDeviceContext(interop, deviceContext);
            return(false);
        }
예제 #9
0
        private static bool GetAvailableTrackers(IStreamEngineInterop interop, IntPtr apiContext, out List <string> connectedDevices)
        {
            var result = interop.tobii_enumerate_local_device_urls(apiContext, out connectedDevices);

            if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
            {
                UnityEngine.Debug.LogError("Failed to enumerate connected devices. " + result);
                return(false);
            }

            if (connectedDevices.Count >= 1)
            {
                return(true);
            }

            UnityEngine.Debug.LogWarning("No connected eye trackers found.");
            return(false);
        }
예제 #10
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);
            }
        }
        private static bool GetAvailableTrackers(IStreamEngineInterop interop, IntPtr apiContext, out List <string> connectedDevices)
        {
            connectedDevices = new List <string>();
            GCHandle gch    = GCHandle.Alloc(connectedDevices);
            var      result = interop.tobii_enumerate_local_device_urls_internal(apiContext, _deviceUrlReceiver, GCHandle.ToIntPtr(gch));

            if (result != tobii_error_t.TOBII_ERROR_NO_ERROR)
            {
                UnityEngine.Debug.LogError("Failed to enumerate connected devices. " + result);
                return(false);
            }

            if (connectedDevices.Count >= 1)
            {
                return(true);
            }

            UnityEngine.Debug.LogWarning("No connected eye trackers found.");
            return(false);
        }
예제 #12
0
 public StreamEngineConnection(IStreamEngineInterop interop)
 {
     _interop = interop;
 }