Tweak updating of pending output report

This commit is contained in:
Travis Nickles 2017-10-07 00:55:14 -05:00
parent 3425a0edb3
commit 957ad3b1d5

View File

@ -569,8 +569,6 @@ namespace DS4Windows
} }
private void performDs4Output() private void performDs4Output()
{
lock (outputReport)
{ {
try try
{ {
@ -578,12 +576,20 @@ namespace DS4Windows
while (!exitOutputThread) while (!exitOutputThread)
{ {
bool result = false; bool result = false;
if (outputRumble) if (outputRumble)
{ {
lock (outputReportBuffer)
{
outputReportBuffer.CopyTo(outputReport, 0);
outputRumble = false;
}
result = writeOutput(); result = writeOutput();
if (!result) if (!result)
{ {
outputRumble = true;
int thisError = Marshal.GetLastWin32Error(); int thisError = Marshal.GetLastWin32Error();
if (lastError != thisError) if (lastError != thisError)
{ {
@ -592,16 +598,16 @@ namespace DS4Windows
lastError = thisError; lastError = thisError;
} }
} }
else
{
outputRumble = false;
}
} }
if (!outputRumble) if (!outputRumble)
{ {
lastError = 0; lastError = 0;
Monitor.Wait(outputReport); lock (outputReportBuffer)
{
Monitor.Wait(outputReportBuffer);
}
/*if (testRumble.IsRumbleSet()) // repeat test rumbles periodically; rumble has auto-shut-off in the DS4 firmware /*if (testRumble.IsRumbleSet()) // repeat test rumbles periodically; rumble has auto-shut-off in the DS4 firmware
Monitor.Wait(outputReport, 10000); // DS4 firmware stops it after 5 seconds, so let the motors rest for that long, too. Monitor.Wait(outputReport, 10000); // DS4 firmware stops it after 5 seconds, so let the motors rest for that long, too.
else else
@ -612,8 +618,6 @@ namespace DS4Windows
} }
catch (ThreadInterruptedException) catch (ThreadInterruptedException)
{ {
}
} }
} }
@ -1020,6 +1024,9 @@ namespace DS4Windows
setTestRumble(); setTestRumble();
setHapticState(); setHapticState();
bool quitOutputThread = false;
lock (outputReportBuffer)
{
if (conType == ConnectionType.BT) if (conType == ConnectionType.BT)
{ {
outputReportBuffer[0] = 0x11; outputReportBuffer[0] = 0x11;
@ -1058,10 +1065,6 @@ namespace DS4Windows
} }
} }
bool quitOutputThread = false;
lock (outputReport)
{
if (synchronous) if (synchronous)
{ {
outputRumble = false; outputRumble = false;
@ -1090,8 +1093,7 @@ namespace DS4Windows
if (output) if (output)
{ {
outputRumble = true; outputRumble = true;
outputReportBuffer.CopyTo(outputReport, 0); Monitor.Pulse(outputReportBuffer);
Monitor.Pulse(outputReport);
} }
} }
} }