1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Updated corsair-SDK to 2.18.127

This commit is contained in:
Darth Affe 2017-11-26 08:53:43 +01:00
parent 83a3ea4e01
commit 86bc26233b
4 changed files with 52 additions and 40 deletions

View File

@ -127,6 +127,38 @@ namespace RGB.NET.Devices.Corsair
} }
} }
/// <summary>
/// Reads the current color-data from the device
/// </summary>
/// <returns>A dictionary mapping the <see cref="CorsairLedIds"/> to the current <see cref="Color"/>.</returns>
protected Dictionary<CorsairLedIds, Color> 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<CorsairLedIds, Color> colorData = new Dictionary<CorsairLedIds, Color>();
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 #endregion
} }
} }

View File

@ -43,6 +43,7 @@ namespace RGB.NET.Devices.Corsair.Native
_dllHandle = LoadLibrary(dllPath); _dllHandle = LoadLibrary(dllPath);
_corsairSetLedsColorsPointer = (CorsairSetLedsColorsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairSetLedsColors"), typeof(CorsairSetLedsColorsPointer)); _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)); _corsairGetDeviceCountPointer = (CorsairGetDeviceCountPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceCount"), typeof(CorsairGetDeviceCountPointer));
_corsairGetDeviceInfoPointer = (CorsairGetDeviceInfoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceInfo"), typeof(CorsairGetDeviceInfoPointer)); _corsairGetDeviceInfoPointer = (CorsairGetDeviceInfoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceInfo"), typeof(CorsairGetDeviceInfoPointer));
_corsairGetLedPositionsPointer = (CorsairGetLedPositionsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedPositions"), typeof(CorsairGetLedPositionsPointer)); _corsairGetLedPositionsPointer = (CorsairGetLedPositionsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedPositions"), typeof(CorsairGetLedPositionsPointer));
@ -79,6 +80,7 @@ namespace RGB.NET.Devices.Corsair.Native
#region Pointers #region Pointers
private static CorsairSetLedsColorsPointer _corsairSetLedsColorsPointer; private static CorsairSetLedsColorsPointer _corsairSetLedsColorsPointer;
private static CorsairGetLedsColorsPointer _corsairGetLedsColorsPointer;
private static CorsairGetDeviceCountPointer _corsairGetDeviceCountPointer; private static CorsairGetDeviceCountPointer _corsairGetDeviceCountPointer;
private static CorsairGetDeviceInfoPointer _corsairGetDeviceInfoPointer; private static CorsairGetDeviceInfoPointer _corsairGetDeviceInfoPointer;
private static CorsairGetLedPositionsPointer _corsairGetLedPositionsPointer; private static CorsairGetLedPositionsPointer _corsairGetLedPositionsPointer;
@ -96,6 +98,9 @@ namespace RGB.NET.Devices.Corsair.Native
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool CorsairSetLedsColorsPointer(int size, IntPtr ledsColors); private delegate bool CorsairSetLedsColorsPointer(int size, IntPtr ledsColors);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool CorsairGetLedsColorsPointer(int size, IntPtr ledsColors);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int CorsairGetDeviceCountPointer(); private delegate int CorsairGetDeviceCountPointer();
@ -130,83 +135,58 @@ namespace RGB.NET.Devices.Corsair.Native
/// <summary> /// <summary>
/// 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. /// 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.
/// </summary> /// </summary>
internal static bool CorsairSetLedsColors(int size, IntPtr ledsColors) internal static bool CorsairSetLedsColors(int size, IntPtr ledsColors) => _corsairSetLedsColorsPointer(size, ledsColors);
{
return _corsairSetLedsColorsPointer(size, ledsColors); /// <summary>
} /// CUE-SDK: get current color for the list of requested LEDs.
/// </summary>
internal static bool CorsairGetLedsColors(int size, IntPtr ledsColors) => _corsairGetLedsColorsPointer(size, ledsColors);
/// <summary> /// <summary>
/// CUE-SDK: returns number of connected Corsair devices that support lighting control. /// CUE-SDK: returns number of connected Corsair devices that support lighting control.
/// </summary> /// </summary>
internal static int CorsairGetDeviceCount() internal static int CorsairGetDeviceCount() => _corsairGetDeviceCountPointer();
{
return _corsairGetDeviceCountPointer();
}
/// <summary> /// <summary>
/// CUE-SDK: returns information about device at provided index. /// CUE-SDK: returns information about device at provided index.
/// </summary> /// </summary>
internal static IntPtr CorsairGetDeviceInfo(int deviceIndex) internal static IntPtr CorsairGetDeviceInfo(int deviceIndex) => _corsairGetDeviceInfoPointer(deviceIndex);
{
return _corsairGetDeviceInfoPointer(deviceIndex);
}
/// <summary> /// <summary>
/// CUE-SDK: provides list of keyboard LEDs with their physical positions. /// CUE-SDK: provides list of keyboard LEDs with their physical positions.
/// </summary> /// </summary>
internal static IntPtr CorsairGetLedPositions() internal static IntPtr CorsairGetLedPositions() => _corsairGetLedPositionsPointer();
{
return _corsairGetLedPositionsPointer();
}
/// <summary> /// <summary>
/// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions. /// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions.
/// </summary> /// </summary>
internal static IntPtr CorsairGetLedPositionsByDeviceIndex(int deviceIndex) internal static IntPtr CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => _corsairGetLedPositionsByDeviceIndexPointer(deviceIndex);
{
return _corsairGetLedPositionsByDeviceIndexPointer(deviceIndex);
}
/// <summary> /// <summary>
/// CUE-SDK: retrieves led id for key name taking logical layout into account. /// CUE-SDK: retrieves led id for key name taking logical layout into account.
/// </summary> /// </summary>
internal static CorsairLedIds CorsairGetLedIdForKeyName(char keyName) internal static CorsairLedIds CorsairGetLedIdForKeyName(char keyName) => _corsairGetLedIdForKeyNamePointer(keyName);
{
return _corsairGetLedIdForKeyNamePointer(keyName);
}
/// <summary> /// <summary>
/// CUE-SDK: requestes control using specified access mode. /// 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. /// By default client has shared control over lighting so there is no need to call CorsairRequestControl unless client requires exclusive control.
/// </summary> /// </summary>
internal static bool CorsairRequestControl(CorsairAccessMode accessMode) internal static bool CorsairRequestControl(CorsairAccessMode accessMode) => _corsairRequestControlPointer(accessMode);
{
return _corsairRequestControlPointer(accessMode);
}
/// <summary> /// <summary>
/// CUE-SDK: releases previously requested control for specified access mode. /// CUE-SDK: releases previously requested control for specified access mode.
/// </summary> /// </summary>
internal static bool CorsairReleaseControl(CorsairAccessMode accessMode) internal static bool CorsairReleaseControl(CorsairAccessMode accessMode) => _corsairReleaseControlPointer(accessMode);
{
return _corsairReleaseControlPointer(accessMode);
}
/// <summary> /// <summary>
/// CUE-SDK: checks file and protocol version of CUE to understand which of SDK functions can be used with this version of CUE. /// CUE-SDK: checks file and protocol version of CUE to understand which of SDK functions can be used with this version of CUE.
/// </summary> /// </summary>
internal static _CorsairProtocolDetails CorsairPerformProtocolHandshake() internal static _CorsairProtocolDetails CorsairPerformProtocolHandshake() => _corsairPerformProtocolHandshakePointer();
{
return _corsairPerformProtocolHandshakePointer();
}
/// <summary> /// <summary>
/// CUE-SDK: returns last error that occured while using any of Corsair* functions. /// CUE-SDK: returns last error that occured while using any of Corsair* functions.
/// </summary> /// </summary>
internal static CorsairError CorsairGetLastError() internal static CorsairError CorsairGetLastError() => _corsairGetLastErrorPointer();
{
return _corsairGetLastErrorPointer();
}
// ReSharper restore EventExceptionNotDocumented // ReSharper restore EventExceptionNotDocumented