diff --git a/DS4Windows/DS4Library/DS4Devices.cs b/DS4Windows/DS4Library/DS4Devices.cs index 5ca6cef..1aef610 100644 --- a/DS4Windows/DS4Library/DS4Devices.cs +++ b/DS4Windows/DS4Library/DS4Devices.cs @@ -7,6 +7,17 @@ using System.Security.Principal; namespace DS4Windows { + public class VidPidInfo + { + public readonly int vid; + public readonly int pid; + internal VidPidInfo(int vid, int pid) + { + this.vid = vid; + this.pid = pid; + } + } + public class DS4Devices { // (HID device path, DS4Device) @@ -17,8 +28,14 @@ namespace DS4Windows private static List DisabledDevices = new List(); private static Stopwatch sw = new Stopwatch(); public static bool isExclusiveMode = false; - private static int[] vids = { 0x054C, 0x1532 }; - private static int[] pid = { 0xBA0, 0x5C4, 0x09CC, 0x1000 }; + internal const int SONY_VID = 0x054C; + internal const int RAZER_VID = 0x1532; + + private static VidPidInfo[] knownDevices = + { + new VidPidInfo(SONY_VID, 0xBA0), new VidPidInfo(SONY_VID, 0x5C4), + new VidPidInfo(SONY_VID, 0x09CC), new VidPidInfo(RAZER_VID, 0x1000) + }; private static string devicePathToInstanceId(string devicePath) { @@ -39,7 +56,7 @@ namespace DS4Windows { lock (Devices) { - IEnumerable hDevices = HidDevices.Enumerate(vids, pid); + IEnumerable hDevices = HidDevices.EnumerateDS4(knownDevices); // Sort Bluetooth first in case USB is also connected on the same controller. hDevices = hDevices.OrderBy((HidDevice d) => { return DS4Device.HidConnectionType(d); }); diff --git a/DS4Windows/HidLibrary/HidDevices.cs b/DS4Windows/HidLibrary/HidDevices.cs index d6c7f1c..c847c86 100644 --- a/DS4Windows/HidLibrary/HidDevices.cs +++ b/DS4Windows/HidLibrary/HidDevices.cs @@ -42,6 +42,31 @@ namespace DS4Windows productIds.Contains(x.Attributes.ProductId)); } + public static IEnumerable EnumerateDS4(VidPidInfo[] devInfo) + { + List foundDevs = new List(); + int devInfoLen = devInfo.Length; + IEnumerable temp = EnumerateDevices(); + for (int i = 0, len = temp.Count(); i < len; i++) + { + DeviceInfo x = temp.ElementAt(i); + HidDevice tempDev = new HidDevice(x.Path, x.Description); + bool found = false; + for (int j = 0; !found && j < devInfoLen; j++) + { + VidPidInfo tempInfo = devInfo[j]; + if (tempDev.Attributes.VendorId == tempInfo.vid && + tempDev.Attributes.ProductId == tempInfo.pid) + { + found = true; + foundDevs.Add(tempDev); + } + } + } + + return foundDevs; + } + public static IEnumerable Enumerate(int vendorId) { return EnumerateDevices().Select(x => new HidDevice(x.Path, x.Description)).Where(x => x.Attributes.VendorId == vendorId);