mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-25 08:01:49 +01:00
Remove unnecessary timer and add some minor tweaks
This commit is contained in:
parent
a65dfa0624
commit
a239f50192
@ -441,8 +441,6 @@ namespace DS4Windows
|
|||||||
private void performDs4Input()
|
private void performDs4Input()
|
||||||
{
|
{
|
||||||
firstActive = DateTime.UtcNow;
|
firstActive = DateTime.UtcNow;
|
||||||
System.Timers.Timer readTimeout = new System.Timers.Timer(); // Await 30 seconds for the initial packet, then 3 seconds thereafter.
|
|
||||||
readTimeout.Elapsed += delegate { HidDevice.CancelIO(); };
|
|
||||||
NativeMethods.HidD_SetNumInputBuffers(hDevice.safeReadHandle.DangerousGetHandle(), 2);
|
NativeMethods.HidD_SetNumInputBuffers(hDevice.safeReadHandle.DangerousGetHandle(), 2);
|
||||||
List<long> Latency = new List<long>();
|
List<long> Latency = new List<long>();
|
||||||
long oldtime = 0;
|
long oldtime = 0;
|
||||||
@ -466,19 +464,10 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
else if (this.Latency <= warnInterval && warn) warn = false;
|
else if (this.Latency <= warnInterval && warn) warn = false;
|
||||||
|
|
||||||
if (readTimeout.Interval != 3000.0)
|
|
||||||
{
|
|
||||||
if (readTimeout.Interval != 30000.0)
|
|
||||||
readTimeout.Interval = 30000.0;
|
|
||||||
else
|
|
||||||
readTimeout.Interval = 3000.0;
|
|
||||||
}
|
|
||||||
readTimeout.Enabled = true;
|
|
||||||
if (conType == ConnectionType.BT)
|
if (conType == ConnectionType.BT)
|
||||||
{
|
{
|
||||||
//HidDevice.ReadStatus res = hDevice.ReadFile(btInputReport);
|
//HidDevice.ReadStatus res = hDevice.ReadFile(btInputReport);
|
||||||
HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(btInputReport, READ_STREAM_TIMEOUT);
|
HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(btInputReport, READ_STREAM_TIMEOUT);
|
||||||
readTimeout.Enabled = false;
|
|
||||||
if (res == HidDevice.ReadStatus.Success)
|
if (res == HidDevice.ReadStatus.Success)
|
||||||
{
|
{
|
||||||
Array.Copy(btInputReport, 2, inputReport, 0, inputReport.Length);
|
Array.Copy(btInputReport, 2, inputReport, 0, inputReport.Length);
|
||||||
@ -500,7 +489,6 @@ namespace DS4Windows
|
|||||||
//HidDevice.ReadStatus res = hDevice.ReadFile(inputReport);
|
//HidDevice.ReadStatus res = hDevice.ReadFile(inputReport);
|
||||||
//Array.Clear(inputReport, 0, inputReport.Length);
|
//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;
|
|
||||||
if (res != HidDevice.ReadStatus.Success)
|
if (res != HidDevice.ReadStatus.Success)
|
||||||
{
|
{
|
||||||
Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + Marshal.GetLastWin32Error());
|
Console.WriteLine(MacAddress.ToString() + " " + System.DateTime.UtcNow.ToString("o") + "> disconnect due to read failure: " + Marshal.GetLastWin32Error());
|
||||||
@ -515,11 +503,13 @@ namespace DS4Windows
|
|||||||
//Array.Copy(inputReport2, 0, inputReport, 0, inputReport.Length);
|
//Array.Copy(inputReport2, 0, inputReport, 0, inputReport.Length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ConnectionType == ConnectionType.BT && btInputReport[0] != 0x11)
|
|
||||||
|
if (conType == ConnectionType.BT && btInputReport[0] != 0x11)
|
||||||
{
|
{
|
||||||
//Received incorrect report, skip it
|
//Received incorrect report, skip it
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime utcNow = System.DateTime.UtcNow; // timestamp with UTC in case system time zone changes
|
DateTime utcNow = System.DateTime.UtcNow; // timestamp with UTC in case system time zone changes
|
||||||
resetHapticState();
|
resetHapticState();
|
||||||
cState.ReportTimeStamp = utcNow;
|
cState.ReportTimeStamp = utcNow;
|
||||||
@ -580,6 +570,7 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { currerror = "Index out of bounds: battery"; }
|
catch { currerror = "Index out of bounds: battery"; }
|
||||||
|
|
||||||
// XXX DS4State mapping needs fixup, turn touches into an array[4] of structs. And include the touchpad details there instead.
|
// XXX DS4State mapping needs fixup, turn touches into an array[4] of structs. And include the touchpad details there instead.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -606,23 +597,30 @@ namespace DS4Windows
|
|||||||
Console.Write(" " + inputReport[i].ToString("x2"));
|
Console.Write(" " + inputReport[i].ToString("x2"));
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
} */
|
} */
|
||||||
if (!isDS4Idle())
|
|
||||||
|
bool ds4Idle = cState.FrameCounter == pState.FrameCounter;
|
||||||
|
if (!ds4Idle)
|
||||||
lastActive = utcNow;
|
lastActive = utcNow;
|
||||||
|
|
||||||
if (conType == ConnectionType.BT)
|
if (conType == ConnectionType.BT)
|
||||||
{
|
{
|
||||||
bool shouldDisconnect = false;
|
bool shouldDisconnect = false;
|
||||||
if (IdleTimeout > 0)
|
int idleTime = IdleTimeout;
|
||||||
|
if (idleTime > 0)
|
||||||
{
|
{
|
||||||
if (isDS4Idle())
|
bool idleInput = isDS4Idle();
|
||||||
|
if (idleInput)
|
||||||
{
|
{
|
||||||
DateTime timeout = lastActive + TimeSpan.FromSeconds(IdleTimeout);
|
DateTime timeout = lastActive + TimeSpan.FromSeconds(idleTime);
|
||||||
if (!Charging)
|
if (!charging)
|
||||||
shouldDisconnect = utcNow >= timeout;
|
shouldDisconnect = utcNow >= timeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldDisconnect && DisconnectBT())
|
if (shouldDisconnect && DisconnectBT())
|
||||||
return; // all done
|
return; // all done
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX fix initialization ordering so the null checks all go away
|
// XXX fix initialization ordering so the null checks all go away
|
||||||
if (Report != null)
|
if (Report != null)
|
||||||
Report(this, EventArgs.Empty);
|
Report(this, EventArgs.Empty);
|
||||||
|
Loading…
Reference in New Issue
Block a user