From 33a9f49110489884d4c4a59b1c1be1928c88a2e0 Mon Sep 17 00:00:00 2001 From: Cheerpipe Date: Sat, 20 Jun 2020 20:44:24 -0400 Subject: [PATCH] NZXT Devices auto reconnect --- .../Devices/NZXTHUE2Ambient/NZXTHUE2.cs | 17 ++++++++++++++--- .../Project-Aurora/Project-Aurora.csproj | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Project-Aurora/Project-Aurora/Devices/NZXTHUE2Ambient/NZXTHUE2.cs b/Project-Aurora/Project-Aurora/Devices/NZXTHUE2Ambient/NZXTHUE2.cs index 8649c665e..72cceec68 100644 --- a/Project-Aurora/Project-Aurora/Devices/NZXTHUE2Ambient/NZXTHUE2.cs +++ b/Project-Aurora/Project-Aurora/Devices/NZXTHUE2Ambient/NZXTHUE2.cs @@ -25,8 +25,7 @@ public class NZXTHUE2 : Device private DeviceKeys _commitKey; private Color _initialColor = Color.Black; private int _deviceIndex = -1; - private int _connectRetryCount = 0; - private int _maxConnectRetryCount = 3; + private int _connectRetryCountLeft = 3; private Dictionary> _deviceMap; public bool Initialize() { @@ -35,6 +34,7 @@ public bool Initialize() KillProcessByName("NZXT CAM.exe"); if (!ListenerRunning()) { + Global.logger.Warn(string.Format("{0} device listener not running. Starting.", _devicename)); StartListenerForDevice(); } _isConnected = true; @@ -221,8 +221,9 @@ public bool UpdateDevice(Dictionary keyColors, DoWorkEventArg } return true; } - catch + catch (Exception ex) { + Global.logger.Warn(string.Format("{0} error while sending commands. Error: {1}", _devicename, ex.Message)); return false; } } @@ -236,6 +237,16 @@ public bool UpdateDevice(DeviceColorComposition colorComposition, DoWorkEventArg _watch.Stop(); _lastUpdateTime = _watch.ElapsedMilliseconds; + if (_lastUpdateTime > 50 && _connectRetryCountLeft > 0) + { + Reset(); + _connectRetryCountLeft--; + Global.logger.Warn(string.Format("{0} device reseted automatically.", _devicename)); + } + else + { + _connectRetryCountLeft = 3; + } return update_result; } diff --git a/Project-Aurora/Project-Aurora/Project-Aurora.csproj b/Project-Aurora/Project-Aurora/Project-Aurora.csproj index f9fdd0ba0..384d75f77 100644 --- a/Project-Aurora/Project-Aurora/Project-Aurora.csproj +++ b/Project-Aurora/Project-Aurora/Project-Aurora.csproj @@ -55,6 +55,7 @@ true documentation\Aurora.XML 3 + true C:\Program Files\Aurora\