diff --git a/CueSDK.cs b/CueSDK.cs
index 011d0a4..400548e 100644
--- a/CueSDK.cs
+++ b/CueSDK.cs
@@ -1,5 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global
+using System.Collections.Generic;
using System.Runtime.InteropServices;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Generic.Enums;
@@ -124,6 +125,74 @@ namespace CUE.NET
}
}
+ ///
+ /// Reinitialize the CUE-SDK and temporarily hand back full control to CUE.
+ ///
+ public static void Reinitialize()
+ {
+ Reinitialize(HasExclusiveAccess);
+ }
+
+ ///
+ /// Reinitialize the CUE-SDK and temporarily hand back full control to CUE.
+ ///
+ /// Specifies whether the application should request exclusive access or not.
+ public static void Reinitialize(bool exclusiveAccess)
+ {
+ if (ProtocolDetails == null)
+ throw new WrapperException("CueSDK isn't initialized.");
+
+ KeyboardSDK?.ResetLeds();
+ MouseSDK?.ResetLeds();
+ HeadsetSDK?.ResetLeds();
+
+ _CUESDK.Reload();
+
+ _CUESDK.CorsairPerformProtocolHandshake();
+
+ CorsairError error = LastError;
+ if (error != CorsairError.Success)
+ Throw(error);
+
+ if (ProtocolDetails.BreakingChanges)
+ throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n" +
+ $"CUE-Version: {ProtocolDetails.ServerVersion} (Protocol {ProtocolDetails.ServerProtocolVersion})\r\n" +
+ $"SDK-Version: {ProtocolDetails.SdkVersion} (Protocol {ProtocolDetails.SdkProtocolVersion})");
+
+ if (exclusiveAccess)
+ if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
+ Throw(LastError);
+ HasExclusiveAccess = exclusiveAccess;
+
+ int deviceCount = _CUESDK.CorsairGetDeviceCount();
+ Dictionary reloadedDevices = new Dictionary();
+ for (int i = 0; i < deviceCount; i++)
+ {
+ GenericDeviceInfo info = new GenericDeviceInfo((_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo)));
+ if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting))
+ continue; // Everything that doesn't support lighting control is useless
+
+ reloadedDevices.Add(info.Type, info);
+
+ error = LastError;
+ if (error != CorsairError.Success)
+ Throw(error);
+ }
+
+ if (KeyboardSDK != null)
+ if (!reloadedDevices.ContainsKey(CorsairDeviceType.Keyboard)
+ || KeyboardSDK.KeyboardDeviceInfo.Model != reloadedDevices[CorsairDeviceType.Keyboard].Model)
+ throw new WrapperException("The previously loaded Keyboard got disconnected.");
+ if (MouseSDK != null)
+ if (!reloadedDevices.ContainsKey(CorsairDeviceType.Mouse)
+ || MouseSDK.MouseDeviceInfo.Model != reloadedDevices[CorsairDeviceType.Mouse].Model)
+ throw new WrapperException("The previously loaded Mouse got disconnected.");
+ if (HeadsetSDK != null)
+ if (!reloadedDevices.ContainsKey(CorsairDeviceType.Headset)
+ || HeadsetSDK.HeadsetDeviceInfo.Model != reloadedDevices[CorsairDeviceType.Headset].Model)
+ throw new WrapperException("The previously loaded Headset got disconnected.");
+ }
+
private static void Throw(CorsairError error)
{
ProtocolDetails = null;
diff --git a/Devices/Generic/AbstractCueDevice.cs b/Devices/Generic/AbstractCueDevice.cs
index 7d3ce60..b29ff7a 100644
--- a/Devices/Generic/AbstractCueDevice.cs
+++ b/Devices/Generic/AbstractCueDevice.cs
@@ -296,6 +296,15 @@ namespace CUE.NET.Devices.Generic
OnException?.Invoke(this, new OnExceptionEventArgs(ex));
}
+ ///
+ /// Resets all loaded LEDs back to default.
+ ///
+ internal void ResetLeds()
+ {
+ foreach (CorsairLed led in Leds.Values)
+ led.Reset();
+ }
+
#endregion
}
}
diff --git a/Devices/Generic/CorsairLed.cs b/Devices/Generic/CorsairLed.cs
index 9c3e3fe..78f9026 100644
--- a/Devices/Generic/CorsairLed.cs
+++ b/Devices/Generic/CorsairLed.cs
@@ -54,19 +54,33 @@ namespace CUE.NET.Devices.Generic
#endregion
#region Constructors
-
+
internal CorsairLed() { }
#endregion
#region Methods
+ ///
+ /// Updates the LED to the requested color.
+ ///
internal void Update()
{
_color = RequestedColor;
IsUpdated = false;
}
+ ///
+ /// Resets the LED back to default
+ ///
+ internal void Reset()
+ {
+ _color = Color.Transparent;
+ RequestedColor = Color.Transparent;
+ IsUpdated = false;
+ IsLocked = false;
+ }
+
#endregion
}
}
diff --git a/Examples/SimpleDevTest/Program.cs b/Examples/SimpleDevTest/Program.cs
index ad9274c..2b26511 100644
--- a/Examples/SimpleDevTest/Program.cs
+++ b/Examples/SimpleDevTest/Program.cs
@@ -44,8 +44,9 @@ namespace SimpleDevTest
Wait(3);
- keyboard.Brush = CueProfiles.LoadProfileByID()[null];
- keyboard.Update();
+ CueSDK.Reinitialize();
+ //keyboard.Brush = CueProfiles.LoadProfileByID()[null];
+ //keyboard.Update();
Wait(3);
@@ -54,8 +55,8 @@ namespace SimpleDevTest
// OR work with a key group containing all keys and leave the background black - this should be always the prefered solution
keyboard.Brush = new SolidColorBrush(Color.Black);
keyboard.Update();
- keyboard.Brush = CueProfiles.LoadProfileByID()["K95 RGB Default 2"];
- keyboard.Update();
+ //keyboard.Brush = CueProfiles.LoadProfileByID()["K95 RGB Default 2"];
+ //keyboard.Update();
Wait(3);