From af5d06c42bc75188c82c7423b39d666030bdd5e8 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Wed, 12 Feb 2020 12:38:07 -0600 Subject: [PATCH] Opt to use high resolution counter --- DS4Windows/DS4Library/DS4Device.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index 39f9009..50fd34f 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -770,6 +770,7 @@ namespace DS4Windows long oldtime = 0; string currerror = string.Empty; long curtime = 0; + long testelapsed = 0; Stopwatch sw = new Stopwatch(); sw.Start(); timeoutEvent = false; @@ -895,14 +896,20 @@ namespace DS4Windows } } - curTimeDouble = sw.Elapsed.TotalMilliseconds; - curtime = sw.ElapsedMilliseconds; - - lastTimeElapsed = curtime - oldtime; - lastTimeElapsedDouble = (curTimeDouble - oldTimeDouble); - + curtime = Stopwatch.GetTimestamp(); + testelapsed = curtime - oldtime; + lastTimeElapsedDouble = testelapsed * (1.0 / Stopwatch.Frequency) * 1000.0; + lastTimeElapsed = (long)lastTimeElapsedDouble; oldtime = curtime; - oldTimeDouble = curTimeDouble; + + //curTimeDouble = sw.Elapsed.TotalMilliseconds; + //curtime = sw.ElapsedMilliseconds; + + //lastTimeElapsed = curtime - oldtime; + //lastTimeElapsedDouble = (curTimeDouble - oldTimeDouble); + + //oldtime = curtime; + //oldTimeDouble = curTimeDouble; if (conType == ConnectionType.BT && btInputReport[0] != 0x11) {