private void queryGamepad()
        {
            if (m_gamepad != null)
            {
                //Get gamepad State.
                JoystickState state = m_gamepad.CurrentJoystickState;

                bool mandatory = DateTime.Now.Ticks > (lastMandatoryTicks + mandatoryIntervalMs * 10000);

                if (mandatory)
                {
                    lastMandatoryTicks = DateTime.Now.Ticks;
                }

                /*
                string info = "";

                //info = state.ToString().Replace("\n"," ") + "  ";

                ////Capture Position.
                info += "X:" + state.X + " ";
                info += "Y:" + state.Y + " ";
                info += "Z:" + state.Z + " ";
                //info += "sldr0:" + state.GetSlider()[0] + " ";
                //info += "sldr1:" + state.GetSlider()[1] + " ";
                //info += "Rx:" + state.Rx + " ";
                //info += "Ry:" + state.Ry + " ";
                info += "Rz:" + state.Rz + " ";
                */

                //Capture Buttons.
                byte[] buttons = state.GetButtons();

                if (m_buttonStates == null)
                {
                    m_buttonStates = new byte[buttons.Length];
                    for (int i = 0; i < m_buttonStates.Length; i++)
                    {
                        m_buttonStates[i] = 0;
                    }
                }

                for (int i = 0; i < buttons.Length; i++)
                {
                    if (buttons[i] != m_buttonStates[i])
                    {
                        //info += "Btn:" + (i + 1) + " ";

                        RPButtonsEventArgs btnArgs = null;

                        if (buttons[i] > m_buttonStates[i])
                        {
                            // button pressed
                            btnArgs = new RPButtonsEventArgs(true, i + 1);
                        }
                        else if (buttons[i] < m_buttonStates[i])
                        {
                            // button released
                            btnArgs = new RPButtonsEventArgs(false, i + 1);
                        }

                        if (btnArgs != null && btnChangedState != null)
                        {
                            btnChangedState(this, btnArgs);
                        }

                        m_buttonStates[i] = buttons[i];
                    }
                }

                if ((m_leftVpos != state.Y || mandatory) && leftJoystickVertMoved != null)
                {
                    JoystickEventArgs args = new JoystickEventArgs(mandatory, state.Y);
                    m_leftVpos = state.Y;
                    leftJoystickVertMoved(this, args);
                }

                if ((m_rightVpos != state.Rz || mandatory) && rightJoystickVertMoved != null)
                {
                    JoystickEventArgs args = new JoystickEventArgs(mandatory, state.Rz);
                    m_rightVpos = state.Rz;
                    rightJoystickVertMoved(this, args);
                }

            }
        }
        private void gamepad_rightJoystickMoved(Object sender, JoystickEventArgs args)
        {
            int pos = args.position;
            int power = (32767 - pos) / 256 / (int)this.rpSensitivityNumericUpDown.Value;

            //Tracer.Trace("right: " + pos + "  power: " + power);

            rightVertTrackBar.Value = power;
            rightMotorPowerTrackBar.Value = power;
        }
Exemple #3
0
        private void queryGamepad()
        {
            if (m_gamepad != null)
            {
                //Get gamepad State.
                JoystickState state = m_gamepad.CurrentJoystickState;

                bool mandatory = DateTime.Now.Ticks > (lastMandatoryTicks + mandatoryIntervalMs * 10000);

                if (mandatory)
                {
                    lastMandatoryTicks = DateTime.Now.Ticks;
                }

                /*
                 * string info = "";
                 *
                 * //info = state.ToString().Replace("\n"," ") + "  ";
                 *
                 * ////Capture Position.
                 * info += "X:" + state.X + " ";
                 * info += "Y:" + state.Y + " ";
                 * info += "Z:" + state.Z + " ";
                 * //info += "sldr0:" + state.GetSlider()[0] + " ";
                 * //info += "sldr1:" + state.GetSlider()[1] + " ";
                 * //info += "Rx:" + state.Rx + " ";
                 * //info += "Ry:" + state.Ry + " ";
                 * info += "Rz:" + state.Rz + " ";
                 */

                //Capture Buttons.
                byte[] buttons = state.GetButtons();

                if (m_buttonStates == null)
                {
                    m_buttonStates = new byte[buttons.Length];
                    for (int i = 0; i < m_buttonStates.Length; i++)
                    {
                        m_buttonStates[i] = 0;
                    }
                }

                for (int i = 0; i < buttons.Length; i++)
                {
                    if (buttons[i] != m_buttonStates[i])
                    {
                        //info += "Btn:" + (i + 1) + " ";

                        RPButtonsEventArgs btnArgs = null;

                        if (buttons[i] > m_buttonStates[i])
                        {
                            // button pressed
                            btnArgs = new RPButtonsEventArgs(true, i + 1);
                        }
                        else if (buttons[i] < m_buttonStates[i])
                        {
                            // button released
                            btnArgs = new RPButtonsEventArgs(false, i + 1);
                        }

                        if (btnArgs != null && btnChangedState != null)
                        {
                            btnChangedState(this, btnArgs);
                        }

                        m_buttonStates[i] = buttons[i];
                    }
                }

                if ((m_leftVpos != state.Y || mandatory) && leftJoystickVertMoved != null)
                {
                    JoystickEventArgs args = new JoystickEventArgs(mandatory, state.Y);
                    m_leftVpos = state.Y;
                    leftJoystickVertMoved(this, args);
                }

                if ((m_rightVpos != state.Rz || mandatory) && rightJoystickVertMoved != null)
                {
                    JoystickEventArgs args = new JoystickEventArgs(mandatory, state.Rz);
                    m_rightVpos = state.Rz;
                    rightJoystickVertMoved(this, args);
                }
            }
        }