public GamePad(DirectInput directInput, DeviceInstance deviceInstance) { this.directInput = directInput; this.device = new Joystick(directInput, deviceInstance.InstanceGuid); this.device.Acquire(); UpdateState(); }
private unsafe int DirectInputEnumDevicesImpl(void* deviceInstance, IntPtr data) { var newDevice = new DeviceInstance(); newDevice.__MarshalFrom(ref *((DeviceInstance.__Native*)deviceInstance)); DeviceInstances.Add(newDevice); // Return true to continue iterating return 1; }
/// <summary> /// Initializes a new instance of the <see cref="DirectInputDeviceInfo"/> class. /// </summary> /// <param name="devInstance">The DirectInput device instance.</param> public DirectInputDeviceInfo(DI.DeviceInstance devInstance) { VibrationMotorRanges = Array.Empty <GorgonRange>(); InstanceGuid = devInstance.InstanceGuid; ProductGuid = devInstance.ProductGuid; Description = devInstance.ProductName; AxisMappings = new Dictionary <GamingDeviceAxis, DI.DeviceObjectId>(new GorgonGamingDeviceAxisEqualityComparer()); }
public void LoadData(DeviceInstance di, int padIndex) { _di = di; _padIndex = padIndex; Text = string.Format(Text, di.ProductName); Step1TabPage.Text = string.Format("{0} - {1:N}", di.ProductName, di.InstanceGuid); Step2TabPage.Text = string.Format("{0} - {1:N}", di.ProductName, di.InstanceGuid); DescriptionLabel.Text = string.Format(DescriptionLabel.Text, di.ProductName, di.InstanceGuid.ToString("N")); BackButton.Visible = false; ResultsLabel.Text = ""; UpdateButtons(); }
/// <summary> /// Function to determine if the device is an XInput controller. /// </summary> /// <param name="device">Device to evaluate.</param> /// <returns><b>true</b> if the device is an xinput controller, <b>false</b> if not.</returns> private bool IsXInputController(DI.DeviceInstance device) { StringBuilder buffer = new StringBuilder(device.ProductGuid.ToString()).Remove(0, 8); foreach (string deviceID in _xinputDeviceIDs.Value) { buffer.Insert(0, deviceID); if (new Guid(buffer.ToString()) == device.ProductGuid) { return(true); } buffer.Remove(0, 8); } return(false); }
/// <summary> /// Get array[4] of direct input devices. /// </summary> DeviceInstance[] GetDevices() { var devices = Manager.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices).ToArray(); var orderedDevices = new DeviceInstance[4]; // Assign devices to their positions. for (int d = 0; d < devices.Length; d++) { var ig = devices[d].InstanceGuid; var section = SettingManager.Current.GetInstanceSection(ig); var ini2 = new Ini(SettingManager.IniFileName); string v = ini2.GetValue(section, SettingName.MapToPad); int mapToPad = 0; if (int.TryParse(v, out mapToPad) && mapToPad > 0 && mapToPad <= 4) { // If position is not occupied then... if (orderedDevices[mapToPad - 1] == null) { orderedDevices[mapToPad - 1] = devices[d]; } } } // Get list of unassigned devices. var unassignedDevices = devices.Except(orderedDevices).ToArray(); for (int i = 0; i < unassignedDevices.Length; i++) { // Assign to first empty slot. for (int d = 0; d < orderedDevices.Length; d++) { // If position is not occupied then... if (orderedDevices[d] == null) { orderedDevices[d] = unassignedDevices[i]; break; } } } return orderedDevices; }
public void SetPadSetting(string padSectionName, DeviceInstance di) { var ini2 = new Ini(IniFileName); //ps.PadSettingChecksum = Guid.Empty; ini2.SetValue(padSectionName, SettingName.ProductName, di.ProductName); ini2.SetValue(padSectionName, SettingName.ProductGuid, di.ProductGuid.ToString()); ini2.SetValue(padSectionName, SettingName.InstanceGuid, di.InstanceGuid.ToString()); }
/// <summary> /// Get array[4] of direct input devices. /// </summary> DeviceInstance[] GetDevices() { var devices = Manager.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AllDevices).ToList(); if (SettingManager.Current.ExcludeSuplementals) { // Supplemental devices are specialized device with functionality unsuitable for the main control of an application, // such as pedals used with a wheel.The following subtypes are defined. var supplementals = devices.Where(x => x.Type == SharpDX.DirectInput.DeviceType.Supplemental).ToArray(); foreach (var supplemental in supplementals) { devices.Remove(supplemental); } } // Move gaming wheels to the top index position by default. // Games like GTA need wheel to be first device to work properly. var wheels = devices.Where(x => x.Type == SharpDX.DirectInput.DeviceType.Driving || x.Subtype == (int)DeviceSubType.Wheel).ToArray(); foreach (var wheel in wheels) { devices.Remove(wheel); devices.Insert(0, wheel); } var orderedDevices = new DeviceInstance[4]; // Assign devices to their positions. for (int d = 0; d < devices.Count; d++) { var ig = devices[d].InstanceGuid; var section = SettingManager.Current.GetInstanceSection(ig); var ini2 = new Ini(SettingManager.IniFileName); string v = ini2.GetValue(section, SettingName.MapToPad); int mapToPad = 0; if (int.TryParse(v, out mapToPad) && mapToPad > 0 && mapToPad <= 4) { // If position is not occupied then... if (orderedDevices[mapToPad - 1] == null) { orderedDevices[mapToPad - 1] = devices[d]; } } } // Get list of unassigned devices. var unassignedDevices = devices.Except(orderedDevices).ToArray(); for (int i = 0; i < unassignedDevices.Length; i++) { // Assign to first empty slot. for (int d = 0; d < orderedDevices.Length; d++) { // If position is not occupied then... if (orderedDevices[d] == null) { orderedDevices[d] = unassignedDevices[i]; break; } } } return orderedDevices; }
public void ConnectDevice(DeviceInstance device) { using (log4net.ThreadContext.Stacks["NDC"].Push("ConnectDevice")) { stick = new SharpDX.DirectInput.Joystick(dinput, device.InstanceGuid); stick.SetCooperativeLevel(_boundForm, CooperativeLevel.Exclusive | CooperativeLevel.Background); if (stick == null) { throw new JoystickNotFoundException(); } foreach (DeviceObjectInstance deviceObject in stick.GetObjects()) { if(log.IsDebugEnabled) log.DebugFormat("deviceObject {0}", deviceObject.Name); UpdateControl(deviceObject); } // acquire the device stick.Acquire(); } }