/// <summary> /// ctor and init /// </summary> /// <param name="device">A DXInput device</param> /// <param name="hwnd">The WinHandle of the main window</param> /// <param name="panel">The respective JS panel to show the properties</param> public GamepadCls( SharpDX.XInput.Controller device, UC_GpadPanel panel, int tabIndex ) { log.DebugFormat( "GamepadCls ctor - Entry with index {0}", device.ToString( ) ); m_device = device; m_gPanel = panel; MyTabPageIndex = tabIndex; Activated = false; m_senseLimit = AppConfiguration.AppConfig.gpSenseLimit; // can be changed in the app.config file if it is still too little // Set BufferSize in order to use buffered data. log.Debug( "Get GP Objects" ); try { m_gpCaps = m_device.GetCapabilities( DeviceQueryType.Gamepad ); } catch ( Exception ex ) { log.Error( "Get GamepadCapabilities failed", ex ); } m_gPanel.Caption = DevName; int n = 0; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadDown ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadLeft ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadRight ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.DPadUp ) ) n++; m_gPanel.nDPads = n.ToString( ); m_gPanel.DPadE = ( n > 0 ); n = 0; if ( ( m_gpCaps.Gamepad.LeftThumbX != 0 ) || ( m_gpCaps.Gamepad.LeftThumbY != 0 ) || Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.LeftThumb ) ) { n++; m_gPanel.TStickLE = true; } if ( ( m_gpCaps.Gamepad.RightThumbX != 0 ) || ( m_gpCaps.Gamepad.RightThumbY != 0 ) || Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.RightThumb ) ) { n++; m_gPanel.TStickRE = true; } m_gPanel.nTSticks = n.ToString( ); n = 0; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.A ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.B ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.X ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.Y ) ) n++; if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.Start ) ) { n++; m_gPanel.StartE = true; } if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.Back ) ) { n++; m_gPanel.BackE = true; } if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.LeftShoulder ) ) { n++; m_gPanel.ShoulderLE = true; } if ( Bit( m_gpCaps.Gamepad.Buttons, GamepadButtonFlags.RightShoulder ) ) { n++; m_gPanel.ShoulderRE = true; } m_gPanel.nButtons = n.ToString( ); n = 0; if ( m_gpCaps.Gamepad.LeftTrigger > 0 ) { n++; m_gPanel.TriggerLE = true; } if ( m_gpCaps.Gamepad.RightTrigger > 0 ) { n++; m_gPanel.TriggerRE = true; } m_gPanel.nTriggers = n.ToString( ); m_gPanel.ButtonE = true; // what else ... ApplySettings( ); // get whatever is needed here from Settings Activated = true; }
private void CheckConnection() { if (IsConnected) { return; } Capabilities caps; if (xboxController.GetCapabilities(DeviceQueryType.Any, out caps)) { IsConnected = true; Type = (ControllerType)caps.SubType; } }
/// <summary> /// Initializes a new instance of the <see cref="XInputController"/> class. /// </summary> /// <param name="owner">The input factory that owns this device.</param> /// <param name="joystickID">The ID of the joystick.</param> /// <param name="name">The name of the joystick.</param> /// <param name="controller">Controller instance to bind to this joystick.</param> internal XInputController(GorgonInputFactory owner, int joystickID, string name, XI.Controller controller) : base(owner, name) { AllowExclusiveMode = false; _controller = controller; _controllerID = joystickID; if (controller.IsConnected) { IsConnected = true; #if DEBUG XI.Capabilities caps = controller.GetCapabilities(XI.DeviceQueryType.Any); Gorgon.Log.Print("XInput XBOX 360 controller device {0} interface created (ID:{1}).", LoggingLevel.Simple, caps.SubType.ToString(), joystickID); #endif } else { Gorgon.Log.Print("Disconnected XInput XBOX 360 controller device #{0} interface created.", LoggingLevel.Simple, joystickID); IsConnected = false; } }
/// <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); }
uint XInputGetCapabilities_Hooked(int dwUserIndex, DeviceQueryType dwFlags, out Capabilities pCapabilities) { pCapabilities = new Capabilities(); var controller = new Controller((UserIndex)dwUserIndex); if (controller.IsConnected) { try { pCapabilities = controller.GetCapabilities(dwFlags); } catch { return ERROR_DEVICE_NOT_CONNECTED; } } else { if ((UserIndex) dwUserIndex == UserIndex.One || (UserIndex) dwUserIndex == UserIndex.Any) { pCapabilities.Flags = CapabilityFlags.None; pCapabilities.Type = DeviceType.Gamepad; pCapabilities.SubType = DeviceSubType.Gamepad; pCapabilities.Gamepad.Buttons = GamepadButtonFlags.A | GamepadButtonFlags.B | GamepadButtonFlags.Back | GamepadButtonFlags.DPadDown | GamepadButtonFlags.DPadLeft | GamepadButtonFlags.DPadRight | GamepadButtonFlags.DPadUp | GamepadButtonFlags.LeftShoulder | GamepadButtonFlags.LeftThumb | GamepadButtonFlags.RightShoulder | GamepadButtonFlags.RightThumb | GamepadButtonFlags.Start | GamepadButtonFlags.X | GamepadButtonFlags.Y; pCapabilities.Gamepad.LeftTrigger = 0xFF; pCapabilities.Gamepad.RightTrigger = 0xFF; pCapabilities.Gamepad.LeftThumbX = short.MaxValue; pCapabilities.Gamepad.LeftThumbY = short.MaxValue; pCapabilities.Gamepad.RightThumbX = short.MaxValue; pCapabilities.Gamepad.RightThumbY = short.MaxValue; pCapabilities.Vibration.LeftMotorSpeed = 0xFF; pCapabilities.Vibration.RightMotorSpeed = 0xFF; } } return ERROR_SUCCESS; }
/// <summary> /// Function to retrieve the capabilities of the xinput device. /// </summary> /// <param name="controller"></param> public void GetCaps(XI.Controller controller) { Capabilities = GamingDeviceCapabilityFlags.None; controller.GetCapabilities(XI.DeviceQueryType.Any, out XI.Capabilities capabilities); // Get vibration caps. var vibrationRanges = new List <GorgonRange>(); if (capabilities.Vibration.LeftMotorSpeed != 0) { vibrationRanges.Add(new GorgonRange(0, ushort.MaxValue)); Capabilities |= GamingDeviceCapabilityFlags.SupportsVibration; } if (capabilities.Vibration.RightMotorSpeed != 0) { vibrationRanges.Add(new GorgonRange(0, ushort.MaxValue)); Capabilities |= GamingDeviceCapabilityFlags.SupportsVibration; } VibrationMotorRanges = vibrationRanges; if (((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadDown) == XI.GamepadButtonFlags.DPadDown) || ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadUp) == XI.GamepadButtonFlags.DPadUp) || ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadLeft) == XI.GamepadButtonFlags.DPadLeft) || ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadRight) == XI.GamepadButtonFlags.DPadRight)) { Capabilities |= GamingDeviceCapabilityFlags.SupportsPOV; } // Get buttons, and remap to the button indices present in the gaming device control panel app. if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.A) == XI.GamepadButtonFlags.A) { SupportedButtons[XI.GamepadButtonFlags.A] = 0; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.B) == XI.GamepadButtonFlags.B) { SupportedButtons[XI.GamepadButtonFlags.B] = 1; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.X) == XI.GamepadButtonFlags.X) { SupportedButtons[XI.GamepadButtonFlags.X] = 2; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.Y) == XI.GamepadButtonFlags.Y) { SupportedButtons[XI.GamepadButtonFlags.Y] = 3; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.LeftShoulder) == XI.GamepadButtonFlags.LeftShoulder) { SupportedButtons[XI.GamepadButtonFlags.LeftShoulder] = 4; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.RightShoulder) == XI.GamepadButtonFlags.RightShoulder) { SupportedButtons[XI.GamepadButtonFlags.RightShoulder] = 5; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.Back) == XI.GamepadButtonFlags.Back) { SupportedButtons[XI.GamepadButtonFlags.Back] = 6; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.Start) == XI.GamepadButtonFlags.Start) { SupportedButtons[XI.GamepadButtonFlags.Start] = 7; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.LeftThumb) == XI.GamepadButtonFlags.LeftThumb) { SupportedButtons[XI.GamepadButtonFlags.LeftThumb] = 8; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.RightThumb) == XI.GamepadButtonFlags.RightThumb) { SupportedButtons[XI.GamepadButtonFlags.RightThumb] = 9; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadUp) == XI.GamepadButtonFlags.DPadUp) { SupportedButtons[XI.GamepadButtonFlags.DPadUp] = 10; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadRight) == XI.GamepadButtonFlags.DPadRight) { SupportedButtons[XI.GamepadButtonFlags.DPadRight] = 11; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadDown) == XI.GamepadButtonFlags.DPadDown) { SupportedButtons[XI.GamepadButtonFlags.DPadDown] = 12; } if ((capabilities.Gamepad.Buttons & XI.GamepadButtonFlags.DPadLeft) == XI.GamepadButtonFlags.DPadLeft) { SupportedButtons[XI.GamepadButtonFlags.DPadLeft] = 13; } // Find out the ranges for each axis. var axes = new Dictionary <GamingDeviceAxis, GorgonRange>(new GorgonGamingDeviceAxisEqualityComparer()); if (capabilities.Gamepad.LeftThumbX != 0) { axes[GamingDeviceAxis.XAxis] = new GorgonRange(short.MinValue, short.MaxValue); } if (capabilities.Gamepad.LeftThumbY != 0) { axes[GamingDeviceAxis.YAxis] = new GorgonRange(short.MinValue, short.MaxValue); } if (capabilities.Gamepad.RightThumbX != 0) { axes[GamingDeviceAxis.XAxis2] = new GorgonRange(short.MinValue, short.MaxValue); Capabilities |= GamingDeviceCapabilityFlags.SupportsSecondaryXAxis; } if (capabilities.Gamepad.RightThumbY != 0) { axes[GamingDeviceAxis.YAxis2] = new GorgonRange(short.MinValue, short.MaxValue); Capabilities |= GamingDeviceCapabilityFlags.SupportsSecondaryYAxis; } if (capabilities.Gamepad.LeftTrigger != 0) { axes[GamingDeviceAxis.LeftTrigger] = new GorgonRange(0, byte.MaxValue); Capabilities |= GamingDeviceCapabilityFlags.SupportsRudder; } if (capabilities.Gamepad.RightTrigger != 0) { axes[GamingDeviceAxis.RightTrigger] = new GorgonRange(0, byte.MaxValue); Capabilities |= GamingDeviceCapabilityFlags.SupportsThrottle; } AxisInfo = new GorgonGamingDeviceAxisList <GorgonGamingDeviceAxisInfo>(axes.Select(item => new GorgonGamingDeviceAxisInfo(item.Key, item.Value, 0))); }