From 315797fe536499744290faa0a5a0b4e5a7b48e46 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Fri, 4 Aug 2017 06:10:48 -0500 Subject: [PATCH] Minor changes to exclusive mode routine --- DS4Windows/DS4Library/DS4Devices.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/DS4Windows/DS4Library/DS4Devices.cs b/DS4Windows/DS4Library/DS4Devices.cs index c478df7..0afb6aa 100644 --- a/DS4Windows/DS4Library/DS4Devices.cs +++ b/DS4Windows/DS4Library/DS4Devices.cs @@ -13,6 +13,7 @@ namespace DS4Windows private static HashSet DevicePaths = new HashSet(); // Keep instance of opened exclusive mode devices not in use (Charging while using BT connection) private static List DisabledDevices = new List(); + private static Stopwatch sw = new Stopwatch(); public static bool isExclusiveMode = false; private static string devicePathToInstanceId(string devicePath) @@ -46,7 +47,7 @@ namespace DS4Windows string devicePlural = "device" + (devCount == 0 || devCount > 1 ? "s" : ""); //Log.LogToGui("Found " + devCount + " possible " + devicePlural + ". Examining " + devicePlural + ".", false); - for (int i = 0; i < devCount; i++) + for (int i = 0; i < devCount; i++) //foreach (HidDevice hDevice in hDevices) { HidDevice hDevice = tempList[i]; @@ -249,7 +250,6 @@ namespace DS4Windows public static void reEnableDevice(string deviceInstanceId) { - Stopwatch sw = new Stopwatch(); bool success; Guid hidGuid = new Guid(); NativeMethods.HidD_GetHidGuid(ref hidGuid); @@ -285,7 +285,7 @@ namespace DS4Windows } //System.Threading.Thread.Sleep(50); - sw.Start(); + sw.Restart(); while (sw.ElapsedMilliseconds < 50) { // Use SpinWait to keep control of current thread. Using Sleep could potentially @@ -306,15 +306,6 @@ namespace DS4Windows throw new Exception("Error enabling device, error code = " + Marshal.GetLastWin32Error()); } - //System.Threading.Thread.Sleep(10); - sw.Restart(); - while (sw.ElapsedMilliseconds < 10) - { - // Use SpinWait to keep control of current thread. Using Sleep could potentially - // cause other events to get run out of order - System.Threading.Thread.SpinWait(20); - } - sw.Stop(); NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet); } }