From 4057c829cd35adce00fe68a15cf429295eecb00c Mon Sep 17 00:00:00 2001 From: Kylemc1413 Date: Wed, 25 May 2022 19:10:57 -0400 Subject: [PATCH 1/2] Move touch input sending to its own thread --- Assets/Script/Serial.cs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Assets/Script/Serial.cs b/Assets/Script/Serial.cs index b8a04ce..759f02c 100644 --- a/Assets/Script/Serial.cs +++ b/Assets/Script/Serial.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Threading; using System.IO.Ports; using System.Linq; using UnityEngine; @@ -16,6 +17,8 @@ public class Serial : MonoBehaviour const byte CMD_BEGIN_WRITE = 0x77; const byte CMD_NEXT_WRITE = 0x20; + private Thread _touchThread; + private Queue _touchQueue; static SerialPort ComL = new SerialPort ("COM5", 115200); static SerialPort ComR = new SerialPort ("COM6", 115200); @@ -50,11 +53,29 @@ public class Serial : MonoBehaviour SetSettingData_162(); SetSettingData_148(); //Send touch update periodically to keep "read" alive - InvokeRepeating("SendTouchState", 0, 1); + _touchQueue = Queue.Synchronized(new Queue()); + _touchThread = new Thread(TouchThreadLoop); + InvokeRepeating("PingTouchThread", 0, 1); //Send touch updates whenever actual state changes to achieve desired update frequency without overloading - ColliderToSerial.touchDidChange += SendTouchState; + ColliderToSerial.touchDidChange += PingTouchThread; } + private void PingTouchThread() + { + _touchQueue.Enqueue(1); + } + + private void TouchThreadLoop() + { + while(true) + { + if(_touchQueue.Count > 0) + { + _touchQueue.Dequeue(); + SendTouchState(); + } + } + } private void OnDestroy() { ComL.Close(); @@ -182,6 +203,8 @@ public class Serial : MonoBehaviour Serial.Write(SettingData_201.ToArray(), 0, 3); Debug.Log($"START AUTO SCAN SIDE {side}"); StartUp = true; + if (!_touchThread.IsAlive) + _touchThread.Start(); break; case CMD_BEGIN_WRITE: // Debug.Log($"Begin Write For Side {side}"); From 7ab8421db648967cf416df0e6415aae9964af664 Mon Sep 17 00:00:00 2001 From: Kylemc1413 Date: Wed, 25 May 2022 19:11:47 -0400 Subject: [PATCH 2/2] Change capture framerate to match game, turn off expensive updatetitle --- Assets/Scenes/WACVR.unity | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Scenes/WACVR.unity b/Assets/Scenes/WACVR.unity index 5680a79..b82f932 100644 --- a/Assets/Scenes/WACVR.unity +++ b/Assets/Scenes/WACVR.unity @@ -10348,9 +10348,9 @@ MonoBehaviour: captureMode: 1 capturePriority: 0 captureRequestTiming: 0 - captureFrameRate: 240 + captureFrameRate: 60 drawCursor: 0 - updateTitle: 1 + updateTitle: 0 searchAnotherWindowWhenInvalid: 0 scaleControlType: 3 scalePer1000Pixel: 1