Use synchronous write operations for USB and SONYWA connections again

Threaded version caused random device disconnects on Windows 7.
Related to issue #244
This commit is contained in:
Travis Nickles 2018-04-16 05:03:47 -05:00
parent a9348d1488
commit dad4606558

View File

@ -521,17 +521,20 @@ namespace DS4Windows
{ {
if (ds4Input == null) if (ds4Input == null)
{ {
ds4Output = new Thread(performDs4Output); if (conType == ConnectionType.BT)
ds4Output.Priority = ThreadPriority.AboveNormal; {
ds4Output.Name = "DS4 Output thread: " + Mac; ds4Output = new Thread(performDs4Output);
ds4Output.IsBackground = true; ds4Output.Priority = ThreadPriority.AboveNormal;
ds4Output.Start(); ds4Output.Name = "DS4 Output thread: " + Mac;
ds4Output.IsBackground = true;
ds4Output.Start();
timeoutCheckThread = new Thread(timeoutTestThread); timeoutCheckThread = new Thread(timeoutTestThread);
timeoutCheckThread.Priority = ThreadPriority.BelowNormal; timeoutCheckThread.Priority = ThreadPriority.BelowNormal;
timeoutCheckThread.Name = "DS4 Timeout thread: " + Mac; timeoutCheckThread.Name = "DS4 Timeout thread: " + Mac;
timeoutCheckThread.IsBackground = true; timeoutCheckThread.IsBackground = true;
timeoutCheckThread.Start(); timeoutCheckThread.Start();
}
ds4Input = new Thread(performDs4Input); ds4Input = new Thread(performDs4Input);
ds4Input.Priority = ThreadPriority.AboveNormal; ds4Input.Priority = ThreadPriority.AboveNormal;
@ -711,7 +714,7 @@ namespace DS4Windows
timeoutEvent = false; timeoutEvent = false;
ds4InactiveFrame = true; ds4InactiveFrame = true;
idleInput = true; idleInput = true;
bool syncWriteReport = true; bool syncWriteReport = conType == ConnectionType.USB;
int maxBatteryValue = 0; int maxBatteryValue = 0;
int tempBattery = 0; int tempBattery = 0;
@ -1074,7 +1077,7 @@ namespace DS4Windows
if (Report != null) if (Report != null)
Report(this, EventArgs.Empty); Report(this, EventArgs.Empty);
sendOutputReport(false); sendOutputReport(syncWriteReport);
if (!string.IsNullOrEmpty(currerror)) if (!string.IsNullOrEmpty(currerror))
error = currerror; error = currerror;
@ -1153,8 +1156,11 @@ namespace DS4Windows
outputRumble = false; outputRumble = false;
outputPendCount = 3; outputPendCount = 3;
Monitor.Enter(outputReport); if (usingBT)
outReportBuffer.CopyTo(outputReport, 0); {
Monitor.Enter(outputReport);
outReportBuffer.CopyTo(outputReport, 0);
}
try try
{ {
@ -1166,7 +1172,10 @@ namespace DS4Windows
} }
catch { } // If it's dead already, don't worry about it. catch { } // If it's dead already, don't worry about it.
Monitor.Exit(outputReport); if (usingBT)
{
Monitor.Exit(outputReport);
}
} }
else else
{ {