Esempio n. 1
0
        /// <summary>
        /// Gets the Capabilities.
        /// </summary>
        /// <returns></returns>
        public XInputCapabilities GetCapabilities()
        {
            var capabilities = new XInputCapabilities();

            XInputInterops.XInputGetCapabilities(_playerIndex, XInputConstants.XINPUT_FLAG_GAMEPAD, ref capabilities);
            return(capabilities);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the object.
        /// </summary>
        /// <param name="gameTime">The GameTime.</param>
        public void Update(GameTime gameTime)
        {
            int result = XInputInterops.XInputGetState(_playerIndex, ref _gamepadStateCurrent);

            IsAvailable = (result == 0);
            if (!IsAvailable)
            {
                return;
            }

            UpdateBatteryState();
            _gamepadStatePrev.Copy(_gamepadStateCurrent);

            if (_vibrationTime > 0)
            {
                _vibrationTime -= gameTime.ElapsedGameTime;
            }

            if (_vibrationTime <= 0 && !_vibrationStopped)
            {
                var stopStrength = new XInputVibration {
                    LeftMotorSpeed = 0, RightMotorSpeed = 0
                };
                XInputInterops.XInputSetState(_playerIndex, ref stopStrength);
                _vibrationStopped = true;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Updates the BatteryState.
        /// </summary>
        internal void UpdateBatteryState()
        {
            XInputBatteryInformation headset = new XInputBatteryInformation(),
                                     gamepad = new XInputBatteryInformation();

            XInputInterops.XInputGetBatteryInformation(_playerIndex, (byte)BatteryDeviceType.BATTERY_DEVTYPE_GAMEPAD,
                                                       ref gamepad);
            XInputInterops.XInputGetBatteryInformation(_playerIndex, (byte)BatteryDeviceType.BATTERY_DEVTYPE_HEADSET,
                                                       ref headset);

            BatteryInformationHeadset = headset;
            BatteryInformationGamepad = gamepad;
        }
Esempio n. 4
0
 /// <summary>
 /// Vibrates the controller.
 /// </summary>
 /// <param name="strength">The Strength.</param>
 /// <param name="length">The Length.</param>
 internal void Vibrate(XInputVibration strength, float length)
 {
     XInputInterops.XInputSetState(_playerIndex, ref strength);
     _vibrationStopped = false;
     _vibrationTime    = length;
 }