mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-25 08:01:49 +01:00
Change device enumeration routine
This commit is contained in:
parent
c75cb3ba7b
commit
bf11a6d297
@ -7,6 +7,17 @@ using System.Security.Principal;
|
|||||||
|
|
||||||
namespace DS4Windows
|
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
|
public class DS4Devices
|
||||||
{
|
{
|
||||||
// (HID device path, DS4Device)
|
// (HID device path, DS4Device)
|
||||||
@ -17,8 +28,14 @@ namespace DS4Windows
|
|||||||
private static List<HidDevice> DisabledDevices = new List<HidDevice>();
|
private static List<HidDevice> DisabledDevices = new List<HidDevice>();
|
||||||
private static Stopwatch sw = new Stopwatch();
|
private static Stopwatch sw = new Stopwatch();
|
||||||
public static bool isExclusiveMode = false;
|
public static bool isExclusiveMode = false;
|
||||||
private static int[] vids = { 0x054C, 0x1532 };
|
internal const int SONY_VID = 0x054C;
|
||||||
private static int[] pid = { 0xBA0, 0x5C4, 0x09CC, 0x1000 };
|
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)
|
private static string devicePathToInstanceId(string devicePath)
|
||||||
{
|
{
|
||||||
@ -39,7 +56,7 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
lock (Devices)
|
lock (Devices)
|
||||||
{
|
{
|
||||||
IEnumerable<HidDevice> hDevices = HidDevices.Enumerate(vids, pid);
|
IEnumerable<HidDevice> hDevices = HidDevices.EnumerateDS4(knownDevices);
|
||||||
// Sort Bluetooth first in case USB is also connected on the same controller.
|
// Sort Bluetooth first in case USB is also connected on the same controller.
|
||||||
hDevices = hDevices.OrderBy<HidDevice, ConnectionType>((HidDevice d) => { return DS4Device.HidConnectionType(d); });
|
hDevices = hDevices.OrderBy<HidDevice, ConnectionType>((HidDevice d) => { return DS4Device.HidConnectionType(d); });
|
||||||
|
|
||||||
|
@ -42,6 +42,31 @@ namespace DS4Windows
|
|||||||
productIds.Contains(x.Attributes.ProductId));
|
productIds.Contains(x.Attributes.ProductId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<HidDevice> EnumerateDS4(VidPidInfo[] devInfo)
|
||||||
|
{
|
||||||
|
List<HidDevice> foundDevs = new List<HidDevice>();
|
||||||
|
int devInfoLen = devInfo.Length;
|
||||||
|
IEnumerable<DeviceInfo> 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<HidDevice> Enumerate(int vendorId)
|
public static IEnumerable<HidDevice> Enumerate(int vendorId)
|
||||||
{
|
{
|
||||||
return EnumerateDevices().Select(x => new HidDevice(x.Path, x.Description)).Where(x => x.Attributes.VendorId == vendorId);
|
return EnumerateDevices().Select(x => new HidDevice(x.Path, x.Description)).Where(x => x.Attributes.VendorId == vendorId);
|
||||||
|
Loading…
Reference in New Issue
Block a user