Ejemplo n.º 1
0
        /// <summary>
        /// Function to update the values for the axes on the joystick.
        /// </summary>
        /// <param name="state">The current state of the controller.</param>
        private void UpdateAxisValues(XI.Gamepad state)
        {
            if (Axis.TryGetValue(GamingDeviceAxis.LeftStickX, out GorgonGamingDeviceAxis xAxis))
            {
                xAxis.Value = state.LeftThumbX;
            }

            if (Axis.TryGetValue(GamingDeviceAxis.LeftStickY, out GorgonGamingDeviceAxis yAxis))
            {
                yAxis.Value = state.LeftThumbY;
            }

            if ((Info.Capabilities & GamingDeviceCapabilityFlags.SupportsSecondaryXAxis) == GamingDeviceCapabilityFlags.SupportsSecondaryXAxis)
            {
                Axis[GamingDeviceAxis.RightStickX].Value = state.RightThumbX;
            }

            if ((Info.Capabilities & GamingDeviceCapabilityFlags.SupportsSecondaryYAxis) == GamingDeviceCapabilityFlags.SupportsSecondaryYAxis)
            {
                Axis[GamingDeviceAxis.RightStickY].Value = state.RightThumbY;
            }

            if ((Info.Capabilities & GamingDeviceCapabilityFlags.SupportsThrottle) == GamingDeviceCapabilityFlags.SupportsThrottle)
            {
                Axis[GamingDeviceAxis.RightTrigger].Value = state.RightTrigger;
            }

            if ((Info.Capabilities & GamingDeviceCapabilityFlags.SupportsRudder) == GamingDeviceCapabilityFlags.SupportsRudder)
            {
                Axis[GamingDeviceAxis.LeftTrigger].Value = state.LeftTrigger;
            }
        }
Ejemplo n.º 2
0
        private int[] calculateOutput()
        {
            gamepad = controller.GetState().Gamepad;

            PadState["leftThumbX"]  = (Math.Abs((float)gamepad.LeftThumbX) < deadband) ? 0 : gamepad.LeftThumbX / short.MaxValue * 1000;
            PadState["leftThumbY"]  = (Math.Abs((float)gamepad.LeftThumbY) < deadband) ? 0 : gamepad.LeftThumbY / short.MaxValue * 1000;
            PadState["rightThumbY"] = (Math.Abs((float)gamepad.RightThumbY) < deadband) ? 0 : gamepad.RightThumbY / short.MaxValue * 1000;
            PadState["rightThumbX"] = (Math.Abs((float)gamepad.RightThumbX) < deadband) ? 0 : gamepad.RightThumbX / short.MaxValue * 1000;
            //values are between -1000 and 1000
            PadState["leftTrigger"]  = gamepad.LeftTrigger / 255 * 1000;
            PadState["rightTrigger"] = gamepad.RightTrigger / 255 * 1000;



            controlState[0] = PadState[Assignment["roll"]];                                      //roll
            controlState[1] = PadState[Assignment["pitch"]];                                     //pitch
            controlState[2] = PadState[Assignment["yaw"]];                                       //yaw
            controlState[3] = PadState[Assignment["throttle"]];                                  //throttle
            controlState[4] = PadState[Assignment["emerge"]] - PadState[Assignment["submerge"]]; //emerge

            int[] ret = new int[channels];
            for (int i = 0; i < channels; i++)
            {
                ret[i] = (int)Math.Round(controlState[i]);
                if (Math.Abs(ret[i]) > 1000)
                {
                    ret[i] = Math.Abs(ret[i]) / ret[i] * 1000;
                }
            }

            return(ret);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="gamePadIndex"></param>
        /// <param name="deadZone"></param>
        public GamePad(GamePadIndex gamePadIndex, GamePadDeadZone deadZone)
        {
            this.Index = gamePadIndex;
            this.deadZone = deadZone;

            this.controller = new XInput.Controller(ConvertGamePadIndexToUserIndex(this.Index));
            this.state = new XInput.Gamepad();
        }
Ejemplo n.º 4
0
        private void ShowButtonStatus(Gamepad pad)
        {
            pButtonA.BackColor = (pad.Buttons & GamepadButtonFlags.A) != 0 ? Color.Green : Color.White;
            pButtonB.BackColor = (pad.Buttons & GamepadButtonFlags.B) != 0 ? Color.Red : Color.White;
            pButtonX.BackColor = (pad.Buttons & GamepadButtonFlags.X) != 0 ? Color.Blue : Color.White;
            pButtonY.BackColor = (pad.Buttons & GamepadButtonFlags.Y) != 0 ? Color.Yellow : Color.White;

            pTriggerL.BackColor = Color.FromArgb(0, pad.LeftTrigger, 0);
            pTriggerR.BackColor = Color.FromArgb(0, pad.RightTrigger, 0);
        }
Ejemplo n.º 5
0
        private void ShowButtonStatus(Gamepad pad)
        {
            pButtonA.BackColor = pad.Buttons.HasFlag(GamepadButtonFlags.A) ? Color.Green : Color.White;
            pButtonB.BackColor = pad.Buttons.HasFlag(GamepadButtonFlags.B)  ? Color.Red : Color.White;
            pButtonX.BackColor = pad.Buttons.HasFlag(GamepadButtonFlags.X) ? Color.Blue : Color.White;
            pButtonY.BackColor = pad.Buttons.HasFlag(GamepadButtonFlags.Y) ? Color.Yellow : Color.White;

            pButtonBack.BackColor = pad.Buttons.HasFlag(GamepadButtonFlags.Back) ? Color.Black : Color.White;
            pButtonStart.BackColor = pad.Buttons.HasFlag(GamepadButtonFlags.Start) ? Color.Black : Color.White;

            pTriggerL.BackColor = Color.FromArgb(0, pad.LeftTrigger, 0);
            pTriggerR.BackColor = Color.FromArgb(0, pad.RightTrigger, 0);
        }
Ejemplo n.º 6
0
 public bool GetCurrentState(out Gamepad gamepad)
 {
     if (controller.IsConnected)
     {
         gamepad = controller.GetState().Gamepad;
         return true;
     }
     else
     {
         gamepad = new Gamepad();
         return false;
     }
 }
Ejemplo n.º 7
0
        public void Update()
        {
            if (!connected)
            {
                return;
            }

            gamepad = controller.GetState().Gamepad;

            leftThumb.X  = (int)((Math.Abs((float)gamepad.LeftThumbX) < deadband) ? 0 : (float)gamepad.LeftThumbX / short.MinValue * -100);
            leftThumb.Y  = (int)((Math.Abs((float)gamepad.LeftThumbY) < deadband) ? 0 : (float)gamepad.LeftThumbY / short.MaxValue * 100);
            rightThumb.X = (int)((Math.Abs((float)gamepad.RightThumbX) < deadband) ? 0 : (float)gamepad.RightThumbX / short.MaxValue * 100);
            rightThumb.Y = (int)((Math.Abs((float)gamepad.RightThumbY) < deadband) ? 0 : (float)gamepad.RightThumbY / short.MaxValue * 100);

            leftTrigger  = gamepad.LeftTrigger;
            rightTrigger = gamepad.RightTrigger;
        }
Ejemplo n.º 8
0
        private void ShowDPad(Gamepad pad)
        {
            Graphics g = pDPad.CreateGraphics();
            g.Clear(Color.White);
            int angle = 0;
            int offset = 0;

            if ((pad.Buttons & GamepadButtonFlags.DPadUp) != 0)
            {
                angle = 270;
                offset = 45;
            }

            if ((pad.Buttons & GamepadButtonFlags.DPadDown) != 0)
            {
                angle = 90;
                offset = 45;
            }

            if ((pad.Buttons & GamepadButtonFlags.DPadLeft) != 0)
            {
                if (angle == 270)
                    angle = 225;
                else if (angle == 90)
                    angle = 135;
                else
                    angle = 180;

                offset = 45;
            }

            if ((pad.Buttons & GamepadButtonFlags.DPadRight) != 0)
            {

                if (angle == 270)
                    angle = 315;
                else if (angle == 90)
                    angle = 45;
                else
                    angle = 0;

                offset = 45;
            }

            g.FillPie(Brushes.Red, 0, 0, 100, 100, angle - 22.5F, offset);
        }
        private void ShowJoyAxis(Gamepad pad)
        {
            int leftL = (pad.LeftThumbX * 50) / 32768;
            int topL = (pad.LeftThumbY * 50) / -32768;

            if (leftL < 0)
            {
                btn_left.Visibility = Visibility.Collapsed;
            }
            else if (leftL == 0)
            {
                btn_left.Visibility = Visibility.Visible;
            }

            if (leftL > 0)
            {
                btn_right.Visibility = Visibility.Collapsed;
            }
            else if (leftL == 0)
            {
                btn_right.Visibility = Visibility.Visible;
            }

            if (topL < 0)
            {
                btn_up.Visibility = Visibility.Collapsed;
            }
            else if (leftL == 0)
            {
                btn_up.Visibility = Visibility.Visible;
            }

            if (topL > 0)
            {
                btn_down.Visibility = Visibility.Collapsed;
            }
            else if (topL == 0)
            {
                btn_down.Visibility = Visibility.Visible;
            }
        }
Ejemplo n.º 10
0
 private bool IsGamepadLTriggerPressed(Gamepad pad, byte threshold = 30)
 {
     return pad.LeftTrigger >= threshold;
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Updates the state of the GamePad.
        /// </summary>
        public void Update()
        {
            if (this.controller.IsConnected)
            {
                this.oldState = this.state;
                this.state = this.controller.GetState().Gamepad;

                this.LeftThumbStick = ApplyThumbStickDeadZone(new Vector2(ConvertThumbStickAxisValue(this.state.LeftThumbX), -ConvertThumbStickAxisValue(this.state.LeftThumbY)), this.deadZone.LeftThumbStick);
                this.RightThumbStick = ApplyThumbStickDeadZone(new Vector2(ConvertThumbStickAxisValue(this.state.RightThumbX), -ConvertThumbStickAxisValue(this.state.RightThumbY)), this.deadZone.RightThumbStick);

                this.LeftTrigger = ConvertTriggerValue(this.state.LeftTrigger);
                this.RightTrigger = ConvertTriggerValue(this.state.RightTrigger);
            }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="NormalizedGamepad"/> class.
		/// </summary>
		/// <param name="gamepad">The gamepad to get normalized values for.</param>
		public NormalizedGamepad(Gamepad gamepad)
		{
			pad = gamepad;
		}
Ejemplo n.º 13
0
 internal ControllerState(Gamepad state)
 {
     this.state = state;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Querries all current input states.
        /// </summary>
        public IEnumerable <InputStateBase> GetInputStates()
        {
            // Update connected states first
            for (int loop = 0; loop < m_controllers.Length; loop++)
            {
                bool isConnected = m_controllers[loop].IsConnected;

                if (!isConnected)
                {
                    m_states[loop].NotifyConnected(false);
                    continue;
                }
                m_states[loop].NotifyConnected(true);

                // Query all state structures
                XI.State   xiState   = m_controllers[loop].GetState();
                XI.Gamepad xiGamepad = xiState.Gamepad;

                // Convert float values
                GamepadReportedState repState = new GamepadReportedState()
                {
                    LeftThumbstickX  = EngineMath.Clamp((float)xiGamepad.LeftThumbX / (float)short.MaxValue, -1f, 1f),
                    LeftThumbstickY  = EngineMath.Clamp((float)xiGamepad.LeftThumbY / (float)short.MaxValue, -1f, 1f),
                    LeftTrigger      = EngineMath.Clamp((float)xiGamepad.LeftTrigger / 255f, 0f, 1f),
                    RightThumbstickX = EngineMath.Clamp((float)xiGamepad.RightThumbX / (float)short.MaxValue, -1f, 1f),
                    RightThumbstickY = EngineMath.Clamp((float)xiGamepad.RightThumbY / (float)short.MaxValue, -1f, 1f),
                    RightTrigger     = EngineMath.Clamp((float)xiGamepad.RightTrigger / 255f, 0, 1f)
                };

                // Convert button states
                GamepadButton pressedButtons = GamepadButton.None;
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.A))
                {
                    pressedButtons |= GamepadButton.A;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.B))
                {
                    pressedButtons |= GamepadButton.B;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.Back))
                {
                    pressedButtons |= GamepadButton.View;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.DPadDown))
                {
                    pressedButtons |= GamepadButton.DPadDown;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.DPadLeft))
                {
                    pressedButtons |= GamepadButton.DPadLeft;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.DPadRight))
                {
                    pressedButtons |= GamepadButton.DPadRight;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.DPadUp))
                {
                    pressedButtons |= GamepadButton.DPadUp;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.LeftShoulder))
                {
                    pressedButtons |= GamepadButton.LeftShoulder;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.LeftThumb))
                {
                    pressedButtons |= GamepadButton.LeftThumbstick;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.RightShoulder))
                {
                    pressedButtons |= GamepadButton.RightShoulder;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.RightThumb))
                {
                    pressedButtons |= GamepadButton.RightThumbstick;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.Start))
                {
                    pressedButtons |= GamepadButton.Menu;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.X))
                {
                    pressedButtons |= GamepadButton.X;
                }
                if (xiGamepad.Buttons.HasFlag(XI.GamepadButtonFlags.Y))
                {
                    pressedButtons |= GamepadButton.Y;
                }
                repState.Buttons = pressedButtons;

                // Report controller state to the system
                m_states[loop].NotifyState(repState);
            }

            // Now return all input states
            for (int loop = 0; loop < m_states.Length; loop++)
            {
                yield return(m_states[loop]);
            }
        }
Ejemplo n.º 15
0
        private void ShowButtonStatus(Gamepad pad)
        {

            if ((pad.Buttons & GamepadButtonFlags.A) != 0)
            {
                btn_circle.Visibility = Visibility.Collapsed;// hide
            }
            else if ((pad.Buttons & GamepadButtonFlags.A) == 0)
            {
                btn_circle.Visibility = Visibility.Visible;// visible
            }

            if ((pad.Buttons & GamepadButtonFlags.B) != 0)
            {
                btn_cross.Visibility = Visibility.Collapsed;// hide
            }
            else if ((pad.Buttons & GamepadButtonFlags.B) == 0)
            {
                btn_cross.Visibility = Visibility.Visible;// visible
            }

            if ((pad.Buttons & GamepadButtonFlags.X) != 0)
            {
                btn_triangle.Visibility = Visibility.Collapsed;// hide
            }
            else if ((pad.Buttons & GamepadButtonFlags.X) == 0)
            {
                btn_triangle.Visibility = Visibility.Visible;// visible
            }

            if ((pad.Buttons & GamepadButtonFlags.Y) != 0)
            {
                btn_square.Visibility = Visibility.Collapsed;// hide
            }
            else if ((pad.Buttons & GamepadButtonFlags.Y) == 0)
            {
                btn_square.Visibility = Visibility.Visible;// visible
            }

            if ((pad.Buttons & GamepadButtonFlags.Back) != 0)
            {
                btn_select.Visibility = Visibility.Collapsed;// hide
                BT_Controll.writeData_SerialPort(ControlConstant.DECREASE_GRIPPER_TORGUE);
                //System.Threading.Thread.Sleep(200);
            }
            else if ((pad.Buttons & GamepadButtonFlags.Back) == 0)
            {
                btn_select.Visibility = Visibility.Visible;// visible
            }

            if ((pad.Buttons & GamepadButtonFlags.Start) != 0)
            {
                btn_start.Visibility = Visibility.Collapsed;// hide
                BT_Controll.writeData_SerialPort(ControlConstant.CLOSE_MANDIBLES);
                //System.Threading.Thread.Sleep(200);
            }
            else if ((pad.Buttons & GamepadButtonFlags.Start) == 0)
            {
                btn_start.Visibility = Visibility.Visible;// visible
            }

            if ((pad.LeftTrigger) != 0)
            {
                L1.Visibility = Visibility.Collapsed;// hide
            }
            else if ((pad.LeftTrigger) == 0)
            {
                L1.Visibility = Visibility.Visible;// visible
            }

            if ((pad.RightTrigger) != 0)
            {
                R1.Visibility = Visibility.Collapsed;// hide
            }
            else if ((pad.RightTrigger) == 0)
            {
                R1.Visibility = Visibility.Visible;// visible
            }

            if ((pad.Buttons & GamepadButtonFlags.LeftShoulder) != 0)
            {
                L2.Visibility = Visibility.Collapsed;// hide
            }
            else if ((pad.Buttons & GamepadButtonFlags.LeftShoulder) == 0)
            {
                L2.Visibility = Visibility.Visible;// visible
            }

            if ((pad.Buttons & GamepadButtonFlags.RightShoulder) != 0)
            {
                R2.Visibility = Visibility.Collapsed;// hide
            }
            else if ((pad.Buttons & GamepadButtonFlags.RightShoulder) == 0)
            {
                R2.Visibility = Visibility.Visible;// visible
            }

        }
Ejemplo n.º 16
0
        private void ShowDPad(Gamepad pad)
        {
            if ((pad.Buttons & GamepadButtonFlags.DPadUp) != 0)
            {
                btn_up.Visibility = Visibility.Collapsed;// hide
                if (Open)
                {
                    //BT_Controll.writeData_SerialPort(ControlConstant.DECREASE_GRIPPER_TORGUE);
                }
            }
            else if ((pad.Buttons & GamepadButtonFlags.DPadUp) == 0)
            {
                btn_up.Visibility = Visibility.Visible;// visible

            }

            if ((pad.Buttons & GamepadButtonFlags.DPadDown) != 0)
            {
                btn_down.Visibility = Visibility.Collapsed;// hide
                //BT_Controll.writeData_SerialPort(ControlConstant.DECREASE_GRIPPER_TORGUE);
            }
            else if ((pad.Buttons & GamepadButtonFlags.DPadDown) == 0)
            {
                btn_down.Visibility = Visibility.Visible;// visible
            }

            if ((pad.Buttons & GamepadButtonFlags.DPadLeft) != 0)
            {
                btn_left.Visibility = Visibility.Collapsed;// hide
            }
            else if ((pad.Buttons & GamepadButtonFlags.DPadLeft) == 0)
            {
                btn_left.Visibility = Visibility.Visible;// visible
            }

            if ((pad.Buttons & GamepadButtonFlags.DPadRight) != 0)
            {
                btn_right.Visibility = Visibility.Collapsed;// hide
            }
            else if ((pad.Buttons & GamepadButtonFlags.DPadRight) == 0)
            {
                btn_right.Visibility = Visibility.Visible;// visible
            }
        }
Ejemplo n.º 17
0
        private void ShowLeftAxis(Gamepad pad)
        {
            Graphics g = pLeft.CreateGraphics();
            g.Clear(System.Drawing.Color.White);

            int leftL = (pad.LeftThumbX * 50) / 32768;
            int topL = (pad.LeftThumbY * 50) / -32768;
            g.FillEllipse(Brushes.Red, leftL + 45, topL + 45, 10, 10);
        }
Ejemplo n.º 18
0
 // Метод, который вызывается в потоке и служит для обработки джойстика и 
 // проверки его подключения
 public void CheckConnectionAndPolling()
 { 
     IsConnected = _controller.IsConnected;
     if (_isConnected)
     {
         _gamepad = _controller.GetState().Gamepad;
         PollJoystick();
         PollButtons();
         PollLeftAndRightTriggers(NewMaxRightTrigger, NewMaxLeftTrigger);
     }  
 }