Beispiel #1
0
    private void OnStateChanged(AsyncData data)
    {
        using (data)
        {
            ResultCode resultCode;
            if (!data.TryGetResultCode(out resultCode) || resultCode != ResultCode.Ok)
            {
                return;
            }

            using (var stateBag = data.GetDataAs <StateBag>())
            {
                if (stateBag != null)
                {
                    if (_isInitialized)
                    {
                        T value;
                        if (GetData(stateBag, out value))
                        {
                            _currentValue = new EyeXEngineStateValue <T>(value);
                        }
                    }
                }
            }
        }
    }
Beispiel #2
0
    public static EyeXDeviceStatus ConvertToEyeXDeviceStatus(EyeXEngineStateValue <EyeTrackingDeviceStatus> state)
    {
        if (state == null || !state.IsValid)
        {
            return(EyeXDeviceStatus.Unknown);
        }

        switch (state.Value)
        {
        // Pending?
        case EyeTrackingDeviceStatus.Initializing:
        case EyeTrackingDeviceStatus.Configuring:
            return(EyeXDeviceStatus.Pending);

        // Tracking?
        case EyeTrackingDeviceStatus.Tracking:
            return(EyeXDeviceStatus.Tracking);

        // Disabled?
        case EyeTrackingDeviceStatus.TrackingPaused:
            return(EyeXDeviceStatus.Disabled);

        // Not available
        default:
            return(EyeXDeviceStatus.NotAvailable);
        }
    }
Beispiel #3
0
    public static EyeXUserPresence ConvertToEyeXUserPresence(EyeXEngineStateValue <UserPresence> state)
    {
        if (state == null || !state.IsValid)
        {
            return(EyeXUserPresence.Unknown);
        }

        switch (state.Value)
        {
        // Present?
        case UserPresence.Present:
            return(EyeXUserPresence.Present);

        // Not present?
        case UserPresence.NotPresent:
            return(EyeXUserPresence.NotPresent);

        // Unknown?
        case UserPresence.Unknown:
            return(EyeXUserPresence.Unknown);

        default:
            throw new InvalidOperationException("Unrecognized user presence value.");
        }
    }
Beispiel #4
0
    public static EyeXGazeTracking ConvertToEyeXGazeTracking(EyeXHost host, EyeXEngineStateValue <GazeTracking> state)
    {
        if (host.EngineVersion == null || (host.EngineVersion != null && host.EngineVersion.Major >= 1 && host.EngineVersion.Minor >= 4))
        {
            if (state == null || !state.IsValid || state.Value == 0)
            {
                return(EyeXGazeTracking.Unknown);
            }

            switch (state.Value)
            {
            // Gaze tracked?
            case GazeTracking.GazeTracked:
                return(EyeXGazeTracking.GazeTracked);

            // Gaze not tracked?
            case GazeTracking.GazeNotTracked:
                return(EyeXGazeTracking.GazeNotTracked);

            default:
                throw new InvalidOperationException("Unknown gaze tracking value.");
            }
        }
        return(EyeXGazeTracking.NotSupported);
    }
    public static EyeXUserPresence ConvertToEyeXUserPresence(EyeXEngineStateValue<UserPresence> state)
    {
        if (state == null || !state.IsValid)
        {
            return EyeXUserPresence.Unknown;
        }

        switch (state.Value)
        {
            // Present?
            case UserPresence.Present:
                return EyeXUserPresence.Present;

            // Not present?
            case UserPresence.NotPresent:
                return EyeXUserPresence.NotPresent;

            // Unknown?
            case UserPresence.Unknown:
                return EyeXUserPresence.Unknown;

            default:
                throw new InvalidOperationException("Unrecognized user presence value.");
        }
    }
    public static EyeXGazeTracking ConvertToEyeXGazeTracking(EyeXHost host, EyeXEngineStateValue<GazeTracking> state)
    {
        if(host.EngineVersion == null || (host.EngineVersion != null && host.EngineVersion.Major >= 1 && host.EngineVersion.Minor >= 4))
        {
            if (state == null || !state.IsValid || state.Value == 0)
            {
                return EyeXGazeTracking.Unknown;
            }

            switch (state.Value)
            {
                // Gaze tracked?
                case GazeTracking.GazeTracked:
                    return EyeXGazeTracking.GazeTracked;

                // Gaze not tracked?
                case GazeTracking.GazeNotTracked:
                    return EyeXGazeTracking.GazeNotTracked;

                default:
                    throw new InvalidOperationException("Unknown gaze tracking value.");
            }
        }
        return EyeXGazeTracking.NotSupported;
    }
    public static EyeXDeviceStatus ConvertToEyeXDeviceStatus(EyeXEngineStateValue<EyeTrackingDeviceStatus> state)
    {
        if (state == null || !state.IsValid)
        {
            return EyeXDeviceStatus.Unknown;
        }

        switch (state.Value)
        {
            // Pending?
            case EyeTrackingDeviceStatus.Initializing:
            case EyeTrackingDeviceStatus.Configuring:
                return EyeXDeviceStatus.Pending;

            // Tracking?
            case EyeTrackingDeviceStatus.Tracking:
                return EyeXDeviceStatus.Tracking;

            // Disabled?
            case EyeTrackingDeviceStatus.TrackingPaused:
                return EyeXDeviceStatus.Disabled;

            // Not available
            default:
                return EyeXDeviceStatus.NotAvailable;
        }
    }
Beispiel #8
0
 /// <summary>
 /// Method to be invoked when the connection to the EyeX Engine has been lost.
 /// </summary>
 public void OnDisconnected()
 {
     if (_isInitialized)
     {
         // When disconnected: raise a state-changed event marking the state as invalid.
         _currentValue = EyeXEngineStateValue <T> .Invalid;
     }
 }
Beispiel #9
0
    /// <summary>
    /// Gets the current value of the engine state.
    /// </summary>
    /// <param name="context">The interaction context.</param>
    /// <returns>The state value.</returns>
    public EyeXEngineStateValue <T> GetCurrentValue(Context context)
    {
        if (_currentValue == null)
        {
            // This is the first time someone asks for the current value.
            // We don't have a value yet, but we'll make sure we get one.
            _currentValue = EyeXEngineStateValue <T> .Invalid;

            // Register the state changed handler.
            RegisterStateChangedHandler(context);
        }

        return(_currentValue);
    }
Beispiel #10
0
    private void UpdateProfiles(
        EyeXEngineStateValue <string[]> profiles,
        EyeXEngineStateValue <string> currentProfile)
    {
        if (profiles.IsValid && currentProfile.IsValid)
        {
            // Draw the title.
            GuiHelpers.DrawText("Click a profile button to activate it.", new Vector2(10, 60), 18, GuiHelpers.Black);

            for (int index = 0; index < profiles.Value.Length; index++)
            {
                // Get the profile name.
                var profileName = profiles.Value[index];

                // Should we disable the GUI?
                var isCurrentProfile = profileName == currentProfile.Value;
                if (isCurrentProfile)
                {
                    GUI.enabled = false;
                }

                // Draw the button.
                var buttonX    = buttonMargin;
                var buttonY    = 100 + (index * (buttonHeight + buttonMargin));
                var buttonRect = new Rect(buttonX, buttonY, buttonWidth, buttonHeight);
                if (GUI.Button(buttonRect, profileName))
                {
                    // Set the current user profile.
                    _host.SetCurrentProfile(profileName);
                }

                // Re-enable the GUI.
                GUI.enabled = true;
            }
        }
        else
        {
            // No valid profile name.
            GuiHelpers.DrawText("Error: Could not retrieve profile names.", new Vector2(10, 60), 18, GuiHelpers.Red);
        }
    }
Beispiel #11
0
    private void UpdateProfiles(
        EyeXEngineStateValue<string[]> profiles,
        EyeXEngineStateValue<string> currentProfile)
    {
        if(profiles.IsValid && currentProfile.IsValid)
        {
            // Draw the title.
            GuiHelpers.DrawText("Click a profile button to activate it.", new Vector2(10, 60), 18, GuiHelpers.Black);

            for(int index = 0; index < profiles.Value.Length; index++)
            {
                // Get the profile name.
                var profileName = profiles.Value[index];

                // Should we disable the GUI?
                var isCurrentProfile = profileName == currentProfile.Value;
                if(isCurrentProfile)
                {
                    GUI.enabled = false;
                }

                // Draw the button.
                var buttonX = buttonMargin;
                var buttonY = 100 + (index * (buttonHeight + buttonMargin));
                var buttonRect = new Rect(buttonX, buttonY, buttonWidth, buttonHeight);
                if (GUI.Button(buttonRect, profileName))
                {
                    // Set the current user profile.
                    _host.SetCurrentProfile(profileName);
                }

                // Re-enable the GUI.
                GUI.enabled = true;
            }
        }
        else
        {
            // No valid profile name.
            GuiHelpers.DrawText("Error: Could not retrieve profile names.", new Vector2(10, 60), 18, GuiHelpers.Red);
        }
    }