1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-12 16:58:29 +00:00

Implemented a reinitialize-functionality

This commit is contained in:
Darth Affe 2016-02-20 10:05:33 +01:00
parent b13a08bdf4
commit a64d27c5ae
4 changed files with 98 additions and 5 deletions

View File

@ -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
}
}
/// <summary>
/// Reinitialize the CUE-SDK and temporarily hand back full control to CUE.
/// </summary>
public static void Reinitialize()
{
Reinitialize(HasExclusiveAccess);
}
/// <summary>
/// Reinitialize the CUE-SDK and temporarily hand back full control to CUE.
/// </summary>
/// <param name="exclusiveAccess">Specifies whether the application should request exclusive access or not.</param>
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<CorsairDeviceType, GenericDeviceInfo> reloadedDevices = new Dictionary<CorsairDeviceType, GenericDeviceInfo>();
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;

View File

@ -296,6 +296,15 @@ namespace CUE.NET.Devices.Generic
OnException?.Invoke(this, new OnExceptionEventArgs(ex));
}
/// <summary>
/// Resets all loaded LEDs back to default.
/// </summary>
internal void ResetLeds()
{
foreach (CorsairLed led in Leds.Values)
led.Reset();
}
#endregion
}
}

View File

@ -54,19 +54,33 @@ namespace CUE.NET.Devices.Generic
#endregion
#region Constructors
internal CorsairLed() { }
#endregion
#region Methods
/// <summary>
/// Updates the LED to the requested color.
/// </summary>
internal void Update()
{
_color = RequestedColor;
IsUpdated = false;
}
/// <summary>
/// Resets the LED back to default
/// </summary>
internal void Reset()
{
_color = Color.Transparent;
RequestedColor = Color.Transparent;
IsUpdated = false;
IsLocked = false;
}
#endregion
}
}

View File

@ -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);