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

@ -520,6 +520,8 @@ namespace DS4Windows
public void StartUpdate() public void StartUpdate()
{ {
if (ds4Input == null) if (ds4Input == null)
{
if (conType == ConnectionType.BT)
{ {
ds4Output = new Thread(performDs4Output); ds4Output = new Thread(performDs4Output);
ds4Output.Priority = ThreadPriority.AboveNormal; ds4Output.Priority = ThreadPriority.AboveNormal;
@ -532,6 +534,7 @@ namespace DS4Windows
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;
if (usingBT)
{
Monitor.Enter(outputReport); Monitor.Enter(outputReport);
outReportBuffer.CopyTo(outputReport, 0); outReportBuffer.CopyTo(outputReport, 0);
}
try try
{ {
@ -1166,8 +1172,11 @@ namespace DS4Windows
} }
catch { } // If it's dead already, don't worry about it. catch { } // If it's dead already, don't worry about it.
if (usingBT)
{
Monitor.Exit(outputReport); Monitor.Exit(outputReport);
} }
}
else else
{ {
bool output = outputPendCount > 0, change = false; bool output = outputPendCount > 0, change = false;