private static void OnSerialExists(HidDevice hDevice) { // happens when the BT endpoint already is open and the USB is plugged into the same host if (IsExclusiveMode && hDevice.IsExclusive && !DisabledDevices.Contains(hDevice)) { // Grab reference to exclusively opened HidDevice so device // stays hidden to other processes DisabledDevices.Add(hDevice); //DevicePaths.Add(hDevice.DevicePath); } }
public static void StopControllers() { lock (Devices) { IEnumerable <DS4Device> devices = GetDS4Controllers(); foreach (DS4Device device in devices) { device.StopUpdate(); device.HidDevice.CloseDevice(); } Devices.Clear(); DevicePaths.Clear(); DeviceSerials.Clear(); DisabledDevices.Clear(); } }
private static void PurgeHiddenExclusiveDevices() { int disabledDevCount = DisabledDevices.Count; if (disabledDevCount > 0) { List <HidDevice> disabledDevList = new List <HidDevice>(); for (var devEnum = DisabledDevices.GetEnumerator(); devEnum.MoveNext();) //for (int i = 0, arlen = disabledDevCount; i < arlen; i++) { //HidDevice tempDev = DisabledDevices.ElementAt(i); HidDevice tempDev = devEnum.Current; if (tempDev != null) { if (tempDev.IsOpen && tempDev.IsConnected) { disabledDevList.Add(tempDev); } else if (tempDev.IsOpen) { if (!tempDev.IsConnected) { try { tempDev.CloseDevice(); } catch { } } if (DevicePaths.Contains(tempDev.DevicePath)) { DevicePaths.Remove(tempDev.DevicePath); } } } } DisabledDevices.Clear(); DisabledDevices.AddRange(disabledDevList); } }
// Enumerates ds4 controllers in the system public static void FindControllers() { lock (Devices) { // Sort Bluetooth first in case USB is also connected on the same controller. var hids = HidDevices.EnumerateDS4(KnownDevices).Where(dev => IsRealDS4(dev)).OrderBy(d2 => DS4Device.GetHidConnectionType(d2)); PurgeHiddenExclusiveDevices(); var disabledCopy = DisabledDevices.ToList(); foreach (HidDevice hDevice in hids) { EvalHid(hDevice); } foreach (HidDevice hDevice in disabledCopy) { EvalHid(hDevice); } } }