Exemple #1
0
        public bool UpdateState()
        {
            bool canRun = true;

            int result = 0;

            try
            {
                XInputNative.XInputGetState(_playerIndex, ref gamepadStateCurrent);
            }
            catch (Exception)
            {
                canRun = false;
            }

            IsConnected = (result == 0);

            UpdateBatteryState();
            if (gamepadStateCurrent.PacketNumber != gamepadStatePrev.PacketNumber)
            {
                OnStateChanged();
            }
            gamepadStatePrev.Copy(gamepadStateCurrent);

            if (_stopMotorTimerActive && (DateTime.Now >= _stopMotorTime))
            {
                try
                {
                    XInputVibration stopStrength = new XInputVibration()
                    {
                        LeftMotorSpeed = 0, RightMotorSpeed = 0
                    };
                    XInputNative.XInputSetState(_playerIndex, ref stopStrength);
                }
                catch (Exception)
                {
                    canRun = false;
                }
            }

            // event motion check
            if (_eventMotion)
            {
                if (gamepadStateCurrent.Gamepad.bLeftTrigger < 20)
                {
                    _eventMotion = false;
                }
            }
            else
            {
                if (gamepadStateCurrent.Gamepad.bLeftTrigger > 190 &&
                    gamepadStateCurrent.Gamepad.bRightTrigger > 190)
                {
                    _eventMotion = true;

                    OnEventMotionTrigger?.Invoke();
                }
            }

            return(canRun);
        }
Exemple #2
0
 public static extern int XInputSetState
 (
     int dwUserIndex,               // [in] Index of the gamer associated with the device
     ref XInputVibration pVibration // [in, out] The vibration information to send to the controller
 );
Exemple #3
0
 public void Vibrate(XInputVibration strength)
 {
     _stopMotorTimerActive = false;
     XInputNative.XInputSetState(_playerIndex, ref strength);
 }