From 3e0e5bebfceb9c3cb4dbed9b632bdac80bd9bc22 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 23 Mar 2017 01:12:50 -0700 Subject: [PATCH] Change interval used for warnings depending on protocol --- DS4Windows/DS4Library/DS4Device.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 73a7e04..21dc79e 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -115,6 +115,10 @@ namespace DS4Windows private const int BT_INPUT_REPORT_LENGTH = 547; // Use large value for worst case scenario private static int READ_STREAM_TIMEOUT = 100; + // Isolated BT report can have latency as high as 15 ms + // due to hardware. + private static int WARN_INTERVAL_BT = 20; + private static int WARN_INTERVAL_USB = 10; private HidDevice hDevice; private string Mac; private DS4State cState = new DS4State(); @@ -138,6 +142,7 @@ namespace DS4Windows public DateTime firstActive = DateTime.UtcNow; private bool charging; private bool outputRumble = false; + private int warnInterval = WARN_INTERVAL_USB; public event EventHandler Report = null; public event EventHandler Removal = null; @@ -228,6 +233,7 @@ namespace DS4Windows inputReport2 = new byte[64]; outputReport = new byte[hDevice.Capabilities.OutputReportByteLength]; outputReportBuffer = new byte[hDevice.Capabilities.OutputReportByteLength]; + warnInterval = WARN_INTERVAL_USB; } else { @@ -235,6 +241,7 @@ namespace DS4Windows inputReport = new byte[btInputReport.Length - 2]; outputReport = new byte[BT_OUTPUT_REPORT_LENGTH]; outputReportBuffer = new byte[BT_OUTPUT_REPORT_LENGTH]; + warnInterval = WARN_INTERVAL_BT; } touchpad = new DS4Touchpad(); sixAxis = new DS4SixAxis(); @@ -358,7 +365,7 @@ namespace DS4Windows } private byte priorInputReport30 = 0xff; public double Latency = 0; - bool warn; + bool warn = false; public string error; private void performDs4Input() { @@ -381,12 +388,12 @@ namespace DS4Windows this.Latency = Latency.Average(); - if (this.Latency > 10 && !warn && sw.ElapsedMilliseconds > 4000) + if (this.Latency > warnInterval && !warn && sw.ElapsedMilliseconds > 4000) { warn = true; //System.Diagnostics.Trace.WriteLine(System.DateTime.UtcNow.ToString("o") + "> " + "Controller " + /*this.DeviceNum*/ + 1 + " (" + this.MacAddress + ") is experiencing latency issues. Currently at " + Math.Round(this.Latency, 2).ToString() + "ms of recomended maximum 10ms"); } - else if (this.Latency <= 10 && warn) warn = false; + else if (this.Latency <= warnInterval && warn) warn = false; if (readTimeout.Interval != 3000.0) {