From a1d083609172bb1c8b8e15909ee00d7a337d5547 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sun, 25 Mar 2018 23:36:46 -0500 Subject: [PATCH] Tweaks to improve hotplug detection Check status of first output report before adding device to the list --- DS4Windows/DS4Control/ScpUtil.cs | 2 +- DS4Windows/DS4Library/DS4Device.cs | 17 +++++++++-------- DS4Windows/DS4Library/DS4Devices.cs | 9 ++++++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs index 80a9fca..807a926 100644 --- a/DS4Windows/DS4Control/ScpUtil.cs +++ b/DS4Windows/DS4Control/ScpUtil.cs @@ -235,7 +235,7 @@ namespace DS4Windows public static string appDataPpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Windows"; public static string oldappdatapath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool"; public static bool runHotPlug = false; - public const int XINPUT_UNPLUG_SETTLE_TIME = 500; // Inhibit races that occur with the asynchronous teardown of ScpVBus -> X360 driver instance. + public const int XINPUT_UNPLUG_SETTLE_TIME = 250; // Inhibit races that occur with the asynchronous teardown of ScpVBus -> X360 driver instance. public static string[] tempprofilename = new string[5] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty }; public static bool[] tempprofileDistance = new bool[5] { false, false, false, false, false }; public static bool[] useDInputOnly = new bool[5] { true, true, true, true, true }; diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index df58fec..19a1814 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -156,6 +156,7 @@ namespace DS4Windows } private bool exitOutputThread = false; + public bool ExitOutputThread => exitOutputThread; private bool exitInputThread = false; private object exitLocker = new object(); @@ -449,6 +450,13 @@ namespace DS4Windows sixAxis = new DS4SixAxis(); Crc32Algorithm.InitializeTable(DefaultPolynomial); refreshCalibration(); + + if (!hDevice.IsFileStreamOpen()) + { + hDevice.OpenFileStream(inputReport.Length); + } + + sendOutputReport(true); // initialize the output report } private void timeoutTestThread() @@ -513,14 +521,6 @@ namespace DS4Windows { if (ds4Input == null) { - if (!hDevice.IsFileStreamOpen()) - { - hDevice.OpenFileStream(inputReport.Length); - } - - //Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> start"); - sendOutputReport(true); // initialize the output report - ds4Output = new Thread(performDs4Output); ds4Output.Priority = ThreadPriority.AboveNormal; ds4Output.Name = "DS4 Output thread: " + Mac; @@ -1195,6 +1195,7 @@ namespace DS4Windows if (quitOutputThread) { StopOutputUpdate(); + exitOutputThread = true; } } diff --git a/DS4Windows/DS4Library/DS4Devices.cs b/DS4Windows/DS4Library/DS4Devices.cs index cc7b92b..f3c7563 100644 --- a/DS4Windows/DS4Library/DS4Devices.cs +++ b/DS4Windows/DS4Library/DS4Devices.cs @@ -143,9 +143,12 @@ namespace DS4Windows { DS4Device ds4Device = new DS4Device(hDevice); //ds4Device.Removal += On_Removal; - Devices.Add(hDevice.DevicePath, ds4Device); - DevicePaths.Add(hDevice.DevicePath); - deviceSerials.Add(serial); + if (!ds4Device.ExitOutputThread) + { + Devices.Add(hDevice.DevicePath, ds4Device); + DevicePaths.Add(hDevice.DevicePath); + deviceSerials.Add(serial); + } } } }