diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs
index e230a61..8724c6a 100644
--- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs
+++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs
@@ -127,6 +127,38 @@ namespace RGB.NET.Devices.Corsair
}
}
+ ///
+ /// Reads the current color-data from the device
+ ///
+ /// A dictionary mapping the to the current .
+ protected Dictionary GetColors()
+ {
+ int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
+ IntPtr ptr = Marshal.AllocHGlobal(structSize * LedMapping.Count);
+ IntPtr addPtr = new IntPtr(ptr.ToInt64());
+ foreach (Led led in this)
+ {
+ _CorsairLedColor color = new _CorsairLedColor { ledId = (int)((CorsairLedId)led.Id).LedId };
+ Marshal.StructureToPtr(color, addPtr, false);
+ addPtr = new IntPtr(addPtr.ToInt64() + structSize);
+ }
+ _CUESDK.CorsairGetLedsColors(LedMapping.Count, ptr);
+
+ IntPtr readPtr = ptr;
+ Dictionary colorData = new Dictionary();
+ for (int i = 0; i < LedMapping.Count; i++)
+ {
+ _CorsairLedColor ledColor = (_CorsairLedColor)Marshal.PtrToStructure(readPtr, typeof(_CorsairLedColor));
+ colorData.Add((CorsairLedIds)ledColor.ledId, new Color((byte)ledColor.r, (byte)ledColor.g, (byte)ledColor.b));
+
+ readPtr = new IntPtr(readPtr.ToInt64() + structSize);
+ }
+
+ Marshal.FreeHGlobal(ptr);
+
+ return colorData;
+ }
+
#endregion
}
}
diff --git a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs
index b7b20c7..84c8d81 100644
--- a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs
+++ b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs
@@ -43,6 +43,7 @@ namespace RGB.NET.Devices.Corsair.Native
_dllHandle = LoadLibrary(dllPath);
_corsairSetLedsColorsPointer = (CorsairSetLedsColorsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairSetLedsColors"), typeof(CorsairSetLedsColorsPointer));
+ _corsairGetLedsColorsPointer = (CorsairGetLedsColorsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedsColors"), typeof(CorsairGetLedsColorsPointer));
_corsairGetDeviceCountPointer = (CorsairGetDeviceCountPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceCount"), typeof(CorsairGetDeviceCountPointer));
_corsairGetDeviceInfoPointer = (CorsairGetDeviceInfoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceInfo"), typeof(CorsairGetDeviceInfoPointer));
_corsairGetLedPositionsPointer = (CorsairGetLedPositionsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedPositions"), typeof(CorsairGetLedPositionsPointer));
@@ -79,6 +80,7 @@ namespace RGB.NET.Devices.Corsair.Native
#region Pointers
private static CorsairSetLedsColorsPointer _corsairSetLedsColorsPointer;
+ private static CorsairGetLedsColorsPointer _corsairGetLedsColorsPointer;
private static CorsairGetDeviceCountPointer _corsairGetDeviceCountPointer;
private static CorsairGetDeviceInfoPointer _corsairGetDeviceInfoPointer;
private static CorsairGetLedPositionsPointer _corsairGetLedPositionsPointer;
@@ -96,6 +98,9 @@ namespace RGB.NET.Devices.Corsair.Native
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool CorsairSetLedsColorsPointer(int size, IntPtr ledsColors);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ private delegate bool CorsairGetLedsColorsPointer(int size, IntPtr ledsColors);
+
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int CorsairGetDeviceCountPointer();
@@ -130,83 +135,58 @@ namespace RGB.NET.Devices.Corsair.Native
///
/// CUE-SDK: set specified leds to some colors. The color is retained until changed by successive calls. This function does not take logical layout into account.
///
- internal static bool CorsairSetLedsColors(int size, IntPtr ledsColors)
- {
- return _corsairSetLedsColorsPointer(size, ledsColors);
- }
+ internal static bool CorsairSetLedsColors(int size, IntPtr ledsColors) => _corsairSetLedsColorsPointer(size, ledsColors);
+
+ ///
+ /// CUE-SDK: get current color for the list of requested LEDs.
+ ///
+ internal static bool CorsairGetLedsColors(int size, IntPtr ledsColors) => _corsairGetLedsColorsPointer(size, ledsColors);
///
/// CUE-SDK: returns number of connected Corsair devices that support lighting control.
///
- internal static int CorsairGetDeviceCount()
- {
- return _corsairGetDeviceCountPointer();
- }
+ internal static int CorsairGetDeviceCount() => _corsairGetDeviceCountPointer();
///
/// CUE-SDK: returns information about device at provided index.
///
- internal static IntPtr CorsairGetDeviceInfo(int deviceIndex)
- {
- return _corsairGetDeviceInfoPointer(deviceIndex);
- }
+ internal static IntPtr CorsairGetDeviceInfo(int deviceIndex) => _corsairGetDeviceInfoPointer(deviceIndex);
///
/// CUE-SDK: provides list of keyboard LEDs with their physical positions.
///
- internal static IntPtr CorsairGetLedPositions()
- {
- return _corsairGetLedPositionsPointer();
- }
+ internal static IntPtr CorsairGetLedPositions() => _corsairGetLedPositionsPointer();
///
/// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions.
///
- internal static IntPtr CorsairGetLedPositionsByDeviceIndex(int deviceIndex)
- {
- return _corsairGetLedPositionsByDeviceIndexPointer(deviceIndex);
- }
+ internal static IntPtr CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => _corsairGetLedPositionsByDeviceIndexPointer(deviceIndex);
///
/// CUE-SDK: retrieves led id for key name taking logical layout into account.
///
- internal static CorsairLedIds CorsairGetLedIdForKeyName(char keyName)
- {
- return _corsairGetLedIdForKeyNamePointer(keyName);
- }
+ internal static CorsairLedIds CorsairGetLedIdForKeyName(char keyName) => _corsairGetLedIdForKeyNamePointer(keyName);
///
/// CUE-SDK: requestes control using specified access mode.
/// By default client has shared control over lighting so there is no need to call CorsairRequestControl unless client requires exclusive control.
///
- internal static bool CorsairRequestControl(CorsairAccessMode accessMode)
- {
- return _corsairRequestControlPointer(accessMode);
- }
+ internal static bool CorsairRequestControl(CorsairAccessMode accessMode) => _corsairRequestControlPointer(accessMode);
///
/// CUE-SDK: releases previously requested control for specified access mode.
///
- internal static bool CorsairReleaseControl(CorsairAccessMode accessMode)
- {
- return _corsairReleaseControlPointer(accessMode);
- }
+ internal static bool CorsairReleaseControl(CorsairAccessMode accessMode) => _corsairReleaseControlPointer(accessMode);
///
/// CUE-SDK: checks file and protocol version of CUE to understand which of SDK functions can be used with this version of CUE.
///
- internal static _CorsairProtocolDetails CorsairPerformProtocolHandshake()
- {
- return _corsairPerformProtocolHandshakePointer();
- }
+ internal static _CorsairProtocolDetails CorsairPerformProtocolHandshake() => _corsairPerformProtocolHandshakePointer();
///
/// CUE-SDK: returns last error that occured while using any of Corsair* functions.
///
- internal static CorsairError CorsairGetLastError()
- {
- return _corsairGetLastErrorPointer();
- }
+ internal static CorsairError CorsairGetLastError() => _corsairGetLastErrorPointer();
// ReSharper restore EventExceptionNotDocumented
diff --git a/RGB.NET.Devices.Corsair/libs/x64/CUESDK.dll b/RGB.NET.Devices.Corsair/libs/x64/CUESDK.dll
index 6e5da8c..139ba27 100644
Binary files a/RGB.NET.Devices.Corsair/libs/x64/CUESDK.dll and b/RGB.NET.Devices.Corsair/libs/x64/CUESDK.dll differ
diff --git a/RGB.NET.Devices.Corsair/libs/x86/CUESDK.dll b/RGB.NET.Devices.Corsair/libs/x86/CUESDK.dll
index 70d678f..b0e6996 100644
Binary files a/RGB.NET.Devices.Corsair/libs/x86/CUESDK.dll and b/RGB.NET.Devices.Corsair/libs/x86/CUESDK.dll differ