Ejemplo n.º 1
0
        public DirectXControllerPOVHat(DirectXControllerInterface controllerInterface, int povNumber)
        {
            _lastPollValue = POVDirection.Center;
            _povNumber = povNumber;
            _name = "POV " + (_povNumber + 1);

            _value = new HeliosValue(controllerInterface, new BindingValue(-1d), "", _name, "Current state for " + _name + ".", "-1 = Centered, 0 = Up, 45 = Up and Right, 90 = Right, 135 = Down and Right, 180 = Down, 225 = Down and Left, 270 = Left, 315 = Up and Left", BindingValueUnits.Boolean);

            _centerEnter = new HeliosTrigger(controllerInterface, _name, "center", "entered", "Fires when hat enters the center position.");
            _triggers.Add(_centerEnter);
            _centerExit = new HeliosTrigger(controllerInterface, _name, "center", "exited", "Fires when the hat leaves the center position.");
            _triggers.Add(_centerExit);

            _rightEnter = new HeliosTrigger(controllerInterface, _name, "right", "entered", "Fires when hat enters the right position.");
            _triggers.Add(_rightEnter);
            _rightExit = new HeliosTrigger(controllerInterface, _name, "right", "exited", "Fires when the hat leaves the right position.");
            _triggers.Add(_rightExit);

            _leftEnter = new HeliosTrigger(controllerInterface, _name, "left", "entered", "Fires when hat enters the left position.");
            _triggers.Add(_leftEnter);
            _leftExit = new HeliosTrigger(controllerInterface, _name, "left", "exited", "Fires when the hat leaves the left position.");
            _triggers.Add(_leftExit);


            _upEnter = new HeliosTrigger(controllerInterface, _name, "up", "entered", "Fires when hat enters the up position.");
            _triggers.Add(_upEnter);
            _upExit = new HeliosTrigger(controllerInterface, _name, "up", "exited", "Fires when the hat leaves the up position.");
            _triggers.Add(_upExit);
            _upLeftEnter = new HeliosTrigger(controllerInterface, _name, "up and left", "entered", "Fires when hat enters the upper left position.");
            _triggers.Add(_upLeftEnter);
            _upLeftExit = new HeliosTrigger(controllerInterface, _name, "up and left", "exited", "Fires when the hat leaves the upper left position.");
            _triggers.Add(_upLeftExit);
            _upRightEnter = new HeliosTrigger(controllerInterface, _name, "up and right", "entered", "Fires when hat enters the upper right position.");
            _triggers.Add(_upRightEnter);
            _upRightExit = new HeliosTrigger(controllerInterface, _name, "up and right", "exited", "Fires when the hat leaves the upper right position.");
            _triggers.Add(_upRightExit);

            _downEnter = new HeliosTrigger(controllerInterface, _name, "down", "entered", "Fires when hat enters the down position.");
            _triggers.Add(_downEnter);
            _downExit = new HeliosTrigger(controllerInterface, _name, "down", "exited", "Fires when the hat leaves the down position.");
            _triggers.Add(_downExit);
            _downLeftEnter = new HeliosTrigger(controllerInterface, _name, "down and left", "entered", "Fires when hat enters the downper left position.");
            _triggers.Add(_downLeftEnter);
            _downLeftExit = new HeliosTrigger(controllerInterface, _name, "down and left", "exited", "Fires when the hat leaves the downper left position.");
            _triggers.Add(_downLeftExit);
            _downRightEnter = new HeliosTrigger(controllerInterface, _name, "down and right", "entered", "Fires when hat enters the downper right position.");
            _triggers.Add(_downRightEnter);
            _downRightExit = new HeliosTrigger(controllerInterface, _name, "down and right", "exited", "Fires when the hat leaves the downper right position.");
            _triggers.Add(_downRightExit);
        }
        public DirectXControllerPOVHat(DirectXControllerInterface controllerInterface, int povNumber)
        {
            _lastPollValue = POVDirection.Center;
            _povNumber     = povNumber;
            _name          = "POV " + (_povNumber + 1);

            _value = new HeliosValue(controllerInterface, new BindingValue(-1d), "", _name, "Current state for " + _name + ".", "-1 = Centered, 0 = Up, 45 = Up and Right, 90 = Right, 135 = Down and Right, 180 = Down, 225 = Down and Left, 270 = Left, 315 = Up and Left", BindingValueUnits.Boolean);

            _centerEnter = new HeliosTrigger(controllerInterface, _name, "center", "entered", "Fires when hat enters the center position.");
            _triggers.Add(_centerEnter);
            _centerExit = new HeliosTrigger(controllerInterface, _name, "center", "exited", "Fires when the hat leaves the center position.");
            _triggers.Add(_centerExit);

            _rightEnter = new HeliosTrigger(controllerInterface, _name, "right", "entered", "Fires when hat enters the right position.");
            _triggers.Add(_rightEnter);
            _rightExit = new HeliosTrigger(controllerInterface, _name, "right", "exited", "Fires when the hat leaves the right position.");
            _triggers.Add(_rightExit);

            _leftEnter = new HeliosTrigger(controllerInterface, _name, "left", "entered", "Fires when hat enters the left position.");
            _triggers.Add(_leftEnter);
            _leftExit = new HeliosTrigger(controllerInterface, _name, "left", "exited", "Fires when the hat leaves the left position.");
            _triggers.Add(_leftExit);


            _upEnter = new HeliosTrigger(controllerInterface, _name, "up", "entered", "Fires when hat enters the up position.");
            _triggers.Add(_upEnter);
            _upExit = new HeliosTrigger(controllerInterface, _name, "up", "exited", "Fires when the hat leaves the up position.");
            _triggers.Add(_upExit);
            _upLeftEnter = new HeliosTrigger(controllerInterface, _name, "up and left", "entered", "Fires when hat enters the upper left position.");
            _triggers.Add(_upLeftEnter);
            _upLeftExit = new HeliosTrigger(controllerInterface, _name, "up and left", "exited", "Fires when the hat leaves the upper left position.");
            _triggers.Add(_upLeftExit);
            _upRightEnter = new HeliosTrigger(controllerInterface, _name, "up and right", "entered", "Fires when hat enters the upper right position.");
            _triggers.Add(_upRightEnter);
            _upRightExit = new HeliosTrigger(controllerInterface, _name, "up and right", "exited", "Fires when the hat leaves the upper right position.");
            _triggers.Add(_upRightExit);

            _downEnter = new HeliosTrigger(controllerInterface, _name, "down", "entered", "Fires when hat enters the down position.");
            _triggers.Add(_downEnter);
            _downExit = new HeliosTrigger(controllerInterface, _name, "down", "exited", "Fires when the hat leaves the down position.");
            _triggers.Add(_downExit);
            _downLeftEnter = new HeliosTrigger(controllerInterface, _name, "down and left", "entered", "Fires when hat enters the downper left position.");
            _triggers.Add(_downLeftEnter);
            _downLeftExit = new HeliosTrigger(controllerInterface, _name, "down and left", "exited", "Fires when the hat leaves the downper left position.");
            _triggers.Add(_downLeftExit);
            _downRightEnter = new HeliosTrigger(controllerInterface, _name, "down and right", "entered", "Fires when hat enters the downper right position.");
            _triggers.Add(_downRightEnter);
            _downRightExit = new HeliosTrigger(controllerInterface, _name, "down and right", "exited", "Fires when the hat leaves the downper right position.");
            _triggers.Add(_downRightExit);
        }
Ejemplo n.º 3
0
        public override void PollValue(JoystickState state)
        {
            POVDirection newValue = GetValue(state);

            if (_lastPollValue != newValue)
            {
                BindingValue bindValue = new BindingValue((double)newValue);
                switch (_lastPollValue)
                {
                    case POVDirection.Up:
                        _upExit.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.UpAndRight:
                        _upRightExit.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.Right:
                        _rightExit.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.DownAndRight:
                        _downRightEnter.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.Down:
                        _downExit.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.DownAndLeft:
                        _downLeftExit.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.Left:
                        _leftEnter.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.UpAndLeft:
                        _upLeftExit.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.Center:
                        _centerExit.FireTrigger(BindingValue.Empty);
                        break;
                }

                switch (newValue)
                {
                    case POVDirection.Up:
                        _upEnter.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.UpAndRight:
                        _upRightEnter.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.Right:
                        _rightEnter.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.DownAndRight:
                        _downRightEnter.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.Down:
                        _downEnter.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.DownAndLeft:
                        _downLeftEnter.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.Left:
                        _leftEnter.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.UpAndLeft:
                        _upLeftEnter.FireTrigger(BindingValue.Empty);
                        break;
                    case POVDirection.Center:
                        _centerEnter.FireTrigger(BindingValue.Empty);
                        break;
                }

                _value.SetValue(bindValue, false);
                _lastPollValue = newValue;
            }
        }
Ejemplo n.º 4
0
 public DirectXControllerPOVHat(DirectXControllerInterface controllerInterface, int povNumber, JoystickState initialState)
     : this(controllerInterface, povNumber)
 {
     _lastPollValue = GetValue(initialState);
     _value.SetValue(new BindingValue((double)_lastPollValue), true);
 }
Ejemplo n.º 5
0
        public void SetPOV(int pov, POVDirection direction, bool state, uint id)
        {
            if (_states.ContainsKey(id) && _activeDirections.ContainsKey(id))
            {
                _activeDirections[id][direction] = state;
                var  current = _states[id];
                var  device  = Devices.Find((d) => d.ID == id);
                uint value   = 0xFF;

                if (device != null)
                {
                    // If using a 4 direction POV Hat
                    if (device.POV4Ds > 0)
                    {
                        string dir = direction.ToString().Substring(2);

                        // If this direction is being released, look for another active direciton
                        if (!state)
                        {
                            POVDirection d = POVDirection._1Up;
                            if (Enum.TryParse("_" + pov + "Up", true, out d) && _activeDirections[id][d])
                            {
                                dir = "Up";
                            }
                            else if (Enum.TryParse("_" + pov + "Right", true, out d) && _activeDirections[id][d])
                            {
                                dir = "Right";
                            }
                            else if (Enum.TryParse("_" + pov + "Down", true, out d) && _activeDirections[id][d])
                            {
                                dir = "Down";
                            }
                            else if (Enum.TryParse("_" + pov + "Left", true, out d) && _activeDirections[id][d])
                            {
                                dir = "Left";
                            }
                            else
                            {
                                dir = "Neutral";
                            }
                        }

                        // Set the value based ont he direction to be applied
                        switch (dir)
                        {
                        case "Up":
                            value = 0x00;
                            break;

                        case "Right":
                            value = 0x01;
                            break;

                        case "Down":
                            value = 0x02;
                            break;

                        case "Left":
                            value = 0x03;
                            break;

                        default:
                            value = 0xFF;
                            break;
                        }

                        // Set new Hat value
                        var shift = ((pov - 1) * 4);
                        current.bHats &= (0xFFFFFFFF & (uint)(0x00 << shift));
                        current.bHats |= (value << shift);
                    }
                    else
                    {
                        value = 0xFFFFFFFF;
                        POVDirection d     = POVDirection._1Up;
                        bool         up    = false;
                        bool         left  = false;
                        bool         down  = false;
                        bool         right = false;
                        if (Enum.TryParse("_" + pov + "Up", true, out d))
                        {
                            up = _activeDirections[id][d];
                        }
                        if (Enum.TryParse("_" + pov + "Right", true, out d))
                        {
                            right = _activeDirections[id][d];
                        }
                        if (Enum.TryParse("_" + pov + "Down", true, out d))
                        {
                            down = _activeDirections[id][d];
                        }
                        if (Enum.TryParse("_" + pov + "Left", true, out d))
                        {
                            left = _activeDirections[id][d];
                        }

                        if (state)
                        {
                            // New state takes priority
                            string dir = direction.ToString().Substring(2);

                            switch (dir)
                            {
                            case "Up":
                                if (left)
                                {
                                    value = 31500;
                                }
                                else if (right)
                                {
                                    value = 4500;
                                }
                                else
                                {
                                    value = 0;
                                }
                                break;

                            case "Right":
                                if (up)
                                {
                                    value = 4500;
                                }
                                else if (down)
                                {
                                    value = 13500;
                                }
                                else
                                {
                                    value = 9000;
                                }
                                break;

                            case "Down":
                                if (right)
                                {
                                    value = 13500;
                                }
                                else if (left)
                                {
                                    value = 22500;
                                }
                                else
                                {
                                    value = 18000;
                                }
                                break;

                            case "Left":
                                if (up)
                                {
                                    value = 31500;
                                }
                                else if (down)
                                {
                                    value = 22500;
                                }
                                else
                                {
                                    value = 27000;
                                }
                                break;

                            default:
                                value = 0xFFFFFFFF;
                                break;
                            }
                        }
                        else
                        {
                            if (up)
                            {
                                if (left)
                                {
                                    value = 31500;
                                }
                                else if (right)
                                {
                                    value = 4500;
                                }
                                else
                                {
                                    value = 0;
                                }
                            }
                            else if (right)
                            {
                                // up & right already handled
                                if (down)
                                {
                                    value = 13500;
                                }
                                else
                                {
                                    value = 9000;
                                }
                            }
                            else if (down)
                            {
                                // down & right already handled
                                if (left)
                                {
                                    value = 22500;
                                }
                                else
                                {
                                    value = 18000;
                                }
                            }
                            else if (left)
                            {
                                // up & left, down & left already handled
                                value = 27000;
                            }
                            else
                            {
                                value = 0xFFFFFFFF;
                            }
                        }

                        // Set the new Hat value
                        switch (pov)
                        {
                        case 1:
                            current.bHats = value;
                            break;

                        case 2:
                            current.bHatsEx1 = value;
                            break;

                        case 3:
                            current.bHatsEx2 = value;
                            break;

                        case 4:
                            current.bHatsEx3 = value;
                            break;

                        default: break;
                        }
                    }

                    _states[id] = current;
                }
            }
        }
        public override void PollValue(JoystickState state)
        {
            POVDirection newValue = GetValue(state);

            if (_lastPollValue != newValue)
            {
                BindingValue bindValue = new BindingValue((double)newValue);
                switch (_lastPollValue)
                {
                case POVDirection.Up:
                    _upExit.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.UpAndRight:
                    _upRightExit.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.Right:
                    _rightExit.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.DownAndRight:
                    _downRightEnter.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.Down:
                    _downExit.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.DownAndLeft:
                    _downLeftExit.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.Left:
                    _leftEnter.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.UpAndLeft:
                    _upLeftExit.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.Center:
                    _centerExit.FireTrigger(BindingValue.Empty);
                    break;
                }

                switch (newValue)
                {
                case POVDirection.Up:
                    _upEnter.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.UpAndRight:
                    _upRightEnter.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.Right:
                    _rightEnter.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.DownAndRight:
                    _downRightEnter.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.Down:
                    _downEnter.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.DownAndLeft:
                    _downLeftEnter.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.Left:
                    _leftEnter.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.UpAndLeft:
                    _upLeftEnter.FireTrigger(BindingValue.Empty);
                    break;

                case POVDirection.Center:
                    _centerEnter.FireTrigger(BindingValue.Empty);
                    break;
                }

                _value.SetValue(bindValue, false);
                _lastPollValue = newValue;
            }
        }
 public DirectXControllerPOVHat(DirectXControllerInterface controllerInterface, int povNumber, JoystickState initialState)
     : this(controllerInterface, povNumber)
 {
     _lastPollValue = GetValue(initialState);
     _value.SetValue(new BindingValue((double)_lastPollValue), true);
 }
Ejemplo n.º 8
0
 //would have made this an enum method, but they don't exist
 public static int GetPOVMultiplier(POVDirection dir)
 {
     return(((int)dir) - 1);
 }