Skip to content

Commit

Permalink
NZXT Devices auto reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheerpipe committed Jun 21, 2020
1 parent 03cad0e commit 33a9f49
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Project-Aurora/Project-Aurora/Devices/NZXTHUE2Ambient/NZXTHUE2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeviceKeys, List<DeviceMapState>> _deviceMap;
public bool Initialize()
{
Expand All @@ -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;
Expand Down Expand Up @@ -221,8 +221,9 @@ public bool UpdateDevice(Dictionary<DeviceKeys, Color> 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;
}
}
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions Project-Aurora/Project-Aurora/Project-Aurora.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>documentation\Aurora.XML</DocumentationFile>
<WarningLevel>3</WarningLevel>
<Optimize>true</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>C:\Program Files\Aurora\</OutputPath>
Expand Down

0 comments on commit 33a9f49

Please sign in to comment.