From 08018d27a1fea15ec011732e03d805ee5617b3b4 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sat, 14 Mar 2020 15:34:59 -0500 Subject: [PATCH] Added wait event to use for refreshing controller readings Only display state change when device is waiting for new report --- DS4Windows/DS4Forms/ControllerReadingsControl.xaml.cs | 3 +++ DS4Windows/DS4Library/DS4Device.cs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/DS4Windows/DS4Forms/ControllerReadingsControl.xaml.cs b/DS4Windows/DS4Forms/ControllerReadingsControl.xaml.cs index 4016306..85dd38f 100644 --- a/DS4Windows/DS4Forms/ControllerReadingsControl.xaml.cs +++ b/DS4Windows/DS4Forms/ControllerReadingsControl.xaml.cs @@ -183,6 +183,8 @@ namespace DS4WinWPF.DS4Forms Dispatcher.Invoke(() => { + ds.ReadWaitEv.Wait(); + ds.ReadWaitEv.Reset(); int x = baseState.LX; int y = baseState.LY; @@ -272,6 +274,7 @@ namespace DS4WinWPF.DS4Forms } prevWarnMode = warnMode; + ds.ReadWaitEv.Set(); }); } diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index f9e3052..5ebc571 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -429,6 +429,9 @@ namespace DS4Windows return runCalib; } + private ManualResetEventSlim readWaitEv = new ManualResetEventSlim(); + public ManualResetEventSlim ReadWaitEv { get => readWaitEv; } + public DS4Device(HidDevice hidDevice, string disName) { hDevice = hidDevice; @@ -809,6 +812,8 @@ namespace DS4Windows //Latency = latencyQueue.Average(); Latency = latencySum / tempLatencyCount; + readWaitEv.Set(); + if (conType == ConnectionType.BT) { //HidDevice.ReadStatus res = hDevice.ReadFile(btInputReport); @@ -893,6 +898,9 @@ namespace DS4Windows } } + readWaitEv.Wait(); + readWaitEv.Reset(); + curtime = Stopwatch.GetTimestamp(); testelapsed = curtime - oldtime; lastTimeElapsedDouble = testelapsed * (1.0 / Stopwatch.Frequency) * 1000.0;