From a65dfa062480223dd92e9cf100e3d56d9c8f00ca Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 6 Apr 2017 08:30:41 -0700 Subject: [PATCH] Only attempt device removal on exit when using Sony dongle --- DS4Windows/DS4Control/ControlSerivce.cs | 2 +- DS4Windows/DS4Library/DS4Device.cs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/DS4Windows/DS4Control/ControlSerivce.cs b/DS4Windows/DS4Control/ControlSerivce.cs index f9bfc8f..97961da 100644 --- a/DS4Windows/DS4Control/ControlSerivce.cs +++ b/DS4Windows/DS4Control/ControlSerivce.cs @@ -180,7 +180,7 @@ namespace DS4Windows } else if (DS4Controllers[i].ConnectionType == ConnectionType.SONYWA) { - DS4Controllers[i].DisconnectDongle(); + DS4Controllers[i].DisconnectDongle(true); } } else diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index cd1de47..7983153 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -498,6 +498,7 @@ namespace DS4Windows else { //HidDevice.ReadStatus res = hDevice.ReadFile(inputReport); + //Array.Clear(inputReport, 0, inputReport.Length); HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(inputReport, READ_STREAM_TIMEOUT); readTimeout.Enabled = false; if (res != HidDevice.ReadStatus.Success) @@ -759,7 +760,7 @@ namespace DS4Windows return false; } - public bool DisconnectDongle() + public bool DisconnectDongle(bool remove=false) { bool result = false; byte[] disconnectReport = new byte[65]; @@ -767,8 +768,9 @@ namespace DS4Windows disconnectReport[1] = 0x02; for (int i = 2; i < 65; i++) disconnectReport[i] = 0; + result = hDevice.WriteFeatureReport(disconnectReport); - if (result) + if (result && remove) { IsDisconnecting = true; StopOutputUpdate();