Only attempt device removal on exit when using Sony dongle

This commit is contained in:
Travis Nickles 2017-04-06 08:30:41 -07:00
parent 51cbe22a90
commit a65dfa0624
2 changed files with 5 additions and 3 deletions

View File

@ -180,7 +180,7 @@ namespace DS4Windows
} }
else if (DS4Controllers[i].ConnectionType == ConnectionType.SONYWA) else if (DS4Controllers[i].ConnectionType == ConnectionType.SONYWA)
{ {
DS4Controllers[i].DisconnectDongle(); DS4Controllers[i].DisconnectDongle(true);
} }
} }
else else

View File

@ -498,6 +498,7 @@ namespace DS4Windows
else else
{ {
//HidDevice.ReadStatus res = hDevice.ReadFile(inputReport); //HidDevice.ReadStatus res = hDevice.ReadFile(inputReport);
//Array.Clear(inputReport, 0, inputReport.Length);
HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(inputReport, READ_STREAM_TIMEOUT); HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(inputReport, READ_STREAM_TIMEOUT);
readTimeout.Enabled = false; readTimeout.Enabled = false;
if (res != HidDevice.ReadStatus.Success) if (res != HidDevice.ReadStatus.Success)
@ -759,7 +760,7 @@ namespace DS4Windows
return false; return false;
} }
public bool DisconnectDongle() public bool DisconnectDongle(bool remove=false)
{ {
bool result = false; bool result = false;
byte[] disconnectReport = new byte[65]; byte[] disconnectReport = new byte[65];
@ -767,8 +768,9 @@ namespace DS4Windows
disconnectReport[1] = 0x02; disconnectReport[1] = 0x02;
for (int i = 2; i < 65; i++) for (int i = 2; i < 65; i++)
disconnectReport[i] = 0; disconnectReport[i] = 0;
result = hDevice.WriteFeatureReport(disconnectReport); result = hDevice.WriteFeatureReport(disconnectReport);
if (result) if (result && remove)
{ {
IsDisconnecting = true; IsDisconnecting = true;
StopOutputUpdate(); StopOutputUpdate();