/// <summary> /// Function to poll the joystick for data. /// </summary> protected override void PollJoystick() { if (!_controller.IsConnected) { Gorgon.Log.Print("XInput Controller {0} disconnected.", LoggingLevel.Verbose, _controllerID); IsConnected = false; return; } // If we weren't connected before, then get the caps for the device. if (!IsConnected) { var previousDeadZone = DeadZone; Initialize(); IsConnected = true; // Restore the dead zone. DeadZone.Rudder = new GorgonRange(previousDeadZone.Rudder); DeadZone.Throttle = new GorgonRange(previousDeadZone.Throttle); DeadZone.X = new GorgonRange(previousDeadZone.X); DeadZone.Y = new GorgonRange(previousDeadZone.Y); DeadZone.SecondaryX = new GorgonRange(previousDeadZone.SecondaryX); DeadZone.SecondaryY = new GorgonRange(previousDeadZone.SecondaryY); #if DEBUG XI.Capabilities caps = _controller.GetCapabilities(XI.DeviceQueryType.Any); Gorgon.Log.Print("XInput Controller {0} (ID:{1}) re-connected.", LoggingLevel.Verbose, caps.SubType.ToString(), _controllerID); #endif } XI.State state = _controller.GetState(); // Do nothing if the data has not changed since the last poll. if (LastPacket == state.PacketNumber) { return; } // Get axis data. X = state.Gamepad.LeftThumbX; Y = state.Gamepad.LeftThumbY; SecondaryX = state.Gamepad.RightThumbX; SecondaryY = state.Gamepad.RightThumbY; Throttle = state.Gamepad.RightTrigger; Rudder = state.Gamepad.LeftTrigger; // Get button info. if (state.Gamepad.Buttons != XI.GamepadButtonFlags.None) { // ReSharper disable once ForCanBeConvertedToForeach for (int i = 0; i < _button.Length; i++) { _buttonList.SetButtonState(_button[i], (_button[i] != XI.GamepadButtonFlags.None) && ((state.Gamepad.Buttons & _button[i]) == _button[i])); } } // Get POV values. GetPOVData(state.Gamepad.Buttons); }