public StreamEngineConnection(IStreamEngineInterop interop) { _interop = interop; _customLog = new tobii_custom_log_t { log_func = LogCallback }; }
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; }
public bool init() { // Initialize the Tobii API. tobii_custom_log_t customLog = new tobii_custom_log_t(); customLog.log_func = new Interop.tobii_log_func_t(tobiiLogOut); customLog.log_context = IntPtr.Zero; tobii_error_t err = Interop.tobii_api_create(out tobiiApiPtr, customLog); if (err != tobii_error_t.TOBII_ERROR_NO_ERROR) { Console.WriteLine("Failed to initialize stream api: " + err); return(false); } err = Interop.tobii_engine_create(tobiiApiPtr, out tobiiEnginePtr); if (err != tobii_error_t.TOBII_ERROR_NO_ERROR) { Console.WriteLine("Failed to initialize stream engine: " + err); cleanup(); return(false); } // Find a device to attach to. List <tobii_enumerated_device_t> devices; err = Interop.tobii_enumerate_devices(tobiiEnginePtr, out devices); if (err != tobii_error_t.TOBII_ERROR_NO_ERROR) { Console.WriteLine("Failed to enumerate devices: " + err); cleanup(); return(false); } if (devices.Count == 0) { Console.WriteLine("No tobii devices available."); cleanup(); return(false); } tobii_enumerated_device_t enumDev = devices.First(); deviceHandle = IntPtr.Zero; err = Interop.tobii_device_create(tobiiApiPtr, enumDev.url, out deviceHandle); if (err != tobii_error_t.TOBII_ERROR_NO_ERROR) { Console.WriteLine("Failed to open devices: " + err); cleanup(); return(false); } // Register callbacks. err = Interop.tobii_gaze_point_subscribe(deviceHandle, new tobii_gaze_point_callback_t(gazePointCallback)); if (err != tobii_error_t.TOBII_ERROR_NO_ERROR) { Console.WriteLine("Failed to subscribe to gaze points."); cleanup(); return(false); } isInitialized = true; return(true); }
public tobii_error_t tobii_api_create(out IntPtr apiContext, tobii_custom_log_t logger) { return(Interop.tobii_api_create(out apiContext, logger)); }
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); }
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 extern tobii_error_t tobii_api_create(out IntPtr api, IntPtr customAlloc, tobii_custom_log_t custom_log); // Custom alloc doesn't make sense in .NET
public static tobii_error_t tobii_api_create(out IntPtr api, tobii_custom_log_t custom_log) { return(tobii_api_create(out api, IntPtr.Zero, custom_log)); }
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; }