/// <summary>
 /// Initializes a new instance of the <see cref="GazeHidPositionsParser"/> class.
 /// </summary>
 /// <param name="gazeDevice"><see cref="GazeDevicePreview"/> used to parse.</param>
 public GazeHidPositionsParser(GazeDevicePreview gazeDevice)
 {
     _leftEyePositionParser  = new GazeHidPositionParser(gazeDevice, (ushort)GazeHidUsages.Usage_LeftEyePosition);
     _rightEyePositionParser = new GazeHidPositionParser(gazeDevice, (ushort)GazeHidUsages.Usage_RightEyePosition);
     _headPositionParser     = new GazeHidPositionParser(gazeDevice, (ushort)GazeHidUsages.Usage_HeadPosition);
     _headRotationParser     = new GazeHidRotationParser(gazeDevice, (ushort)GazeHidUsages.Usage_HeadDirectionPoint);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Check if eye-tracking device is viable.
 /// </summary>
 /// <param name="gazeDevice">Reference to eye-tracking device.</param>
 /// <returns>True, if device is viable; otherwise, false.</returns>
 private bool IsSupportedDevice(GazeDevicePreview gazeDevice)
 {
     TrackerState.Text = gazeDevice.ConfigurationState.ToString();
     return(gazeDevice.CanTrackEyes &&
            gazeDevice.ConfigurationState ==
            GazeDeviceConfigurationStatePreview.Ready);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="GazeHidRotationParser"/> class.
        /// </summary>
        /// <param name="gazeDevice"><see cref="GazeDevicePreview"/> used to parse.</param>
        /// <param name="usage">The <see cref="GazeHidUsages"/> used to parse.</param>
        public GazeHidRotationParser(GazeDevicePreview gazeDevice, ushort usage)
        {
            _usage = usage;

            // Find all the rotation usages from the device's
            // descriptor and store them for easy access
            _x = GazeHidParsersHelpers.GetGazeUsageFromCollectionId(gazeDevice, (ushort)GazeHidUsages.Usage_RotationX, _usage);
            _y = GazeHidParsersHelpers.GetGazeUsageFromCollectionId(gazeDevice, (ushort)GazeHidUsages.Usage_RotationY, _usage);
            _z = GazeHidParsersHelpers.GetGazeUsageFromCollectionId(gazeDevice, (ushort)GazeHidUsages.Usage_RotationZ, _usage);
        }
Ejemplo n.º 4
0
            public GazeRotationHidParser(GazeDevicePreview gazeDevice, UInt16 usage)
            {
                _usage = usage;

                // Find all the head rotation usage from the device's
                // descriptor and store them for easy access
                _X = GetGazeUsageFromCollectionId(gazeDevice, GazeExtendedUsages.Usage_RotationX, _usage);
                _Y = GetGazeUsageFromCollectionId(gazeDevice, GazeExtendedUsages.Usage_RotationY, _usage);
                _Z = GetGazeUsageFromCollectionId(gazeDevice, GazeExtendedUsages.Usage_RotationZ, _usage);
            }
Ejemplo n.º 5
0
        /// <summary>
        /// Initialize gaze tracking.
        /// </summary>
        /// <param name="gazeDevice"></param>
        private async void TryEnableGazeTrackingAsync(GazeDevicePreview gazeDevice)
        {
            // If eye-tracking device is ready, declare event handlers and start tracking.
            if (IsSupportedDevice(gazeDevice))
            {
                timerGaze.Interval = new TimeSpan(0, 0, 0, 0, 20);
                timerGaze.Tick    += TimerGaze_Tick;

                SetGazeTargetLocation();

                // This must be called from the UI thread.
                gazeInputSource = GazeInputSourcePreview.GetForCurrentView();

                gazeInputSource.GazeEntered += GazeEntered;
                gazeInputSource.GazeMoved   += GazeMoved;
                gazeInputSource.GazeExited  += GazeExited;
            }
            // Notify if device calibration required.
            else if (gazeDevice.ConfigurationState ==
                     GazeDeviceConfigurationStatePreview.UserCalibrationNeeded ||
                     gazeDevice.ConfigurationState ==
                     GazeDeviceConfigurationStatePreview.ScreenSetupNeeded)
            {
                // Device isn't calibrated, so invoke the calibration handler.
                System.Diagnostics.Debug.WriteLine(
                    "Your device needs to calibrate. Please wait for it to finish.");
                await gazeDevice.RequestCalibrationAsync();
            }
            // Notify if device calibration underway.
            else if (gazeDevice.ConfigurationState ==
                     GazeDeviceConfigurationStatePreview.Configuring)
            {
                // Device is currently undergoing calibration.
                // A device update is sent when calibration complete.
                System.Diagnostics.Debug.WriteLine(
                    "Your device is being configured. Please wait for it to finish");
            }
            // Device is not viable.
            else if (gazeDevice.ConfigurationState == GazeDeviceConfigurationStatePreview.Unknown)
            {
                // Notify if device is in unknown state.
                // Reconfigure/recalbirate the device.
                System.Diagnostics.Debug.WriteLine(
                    "Your device is not ready. Please set up your device or reconfigure it.");
            }
        }
Ejemplo n.º 6
0
        private static HidNumericControlDescription GetGazeUsageFromCollectionId(GazeDevicePreview gazeDevice, UInt16 childUsageId, UInt16 parentUsageId)
        {
            var numericControls = gazeDevice.GetNumericControlDescriptions(
                GazeExtendedUsages.UsagePage_EyeHeadTracker, childUsageId);

            for (int i = 0; i < numericControls.Count; i++)
            {
                var parentCollections = numericControls[i].ParentCollections;
                if (parentCollections.Count > 0 &&
                    parentCollections[0].UsagePage == GazeExtendedUsages.UsagePage_EyeHeadTracker &&
                    parentCollections[0].UsageId == parentUsageId)
                {
                    return(numericControls[i]);
                }
            }
            return(null);
        }
Ejemplo n.º 7
0
        public static HidNumericControlDescription GetGazeUsageFromCollectionId(
            GazeDevicePreview gazeDevice,
            ushort childUsageId,
            ushort parentUsageId)
        {
            var numericControls = gazeDevice.GetNumericControlDescriptions(
                (ushort)GazeHidUsages.UsagePage_EyeHeadTracker, childUsageId);

            for (int i = 0; i < numericControls.Count; i++)
            {
                var parentCollections = numericControls[i].ParentCollections;
                if (parentCollections.Count > 0 &&
                    parentCollections[0].UsagePage == (ushort)GazeHidUsages.UsagePage_EyeHeadTracker &&
                    parentCollections[0].UsageId == parentUsageId)
                {
                    return(numericControls[i]);
                }
            }

            return(null);
        }
Ejemplo n.º 8
0
        private void Log(string message, GazeDevicePreview device)
        {
            var identifiedMessage = $"{message}\tId={device.Id}, State={device.ConfigurationState}, Eyes={device.CanTrackEyes}, Head={device.CanTrackHead}";

            Log(identifiedMessage);
        }
Ejemplo n.º 9
0
 private bool IsSupportedDevice(GazeDevicePreview gazeDevice)
 {
     return(gazeDevice.CanTrackEyes &&
            gazeDevice.ConfigurationState ==
            GazeDeviceConfigurationStatePreview.Ready);
 }