mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
CoolerMaster fixes
Fixed duplicate values in the LED mappings Added SetAllLeds for fast bulk LED updating on keyboards
This commit is contained in:
parent
4c32eedee0
commit
835e5a0a32
@ -336,7 +336,6 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
{ LedId.Keyboard_PeriodAndBiggerThan, (4,10) },
|
||||
{ LedId.Keyboard_SlashAndQuestionMark, (4,11) },
|
||||
{ LedId.Keyboard_RightShift, (4,14) },
|
||||
{ LedId.Keyboard_U, (4,16) },
|
||||
{ LedId.Keyboard_Num1, (4,15) },
|
||||
{ LedId.Keyboard_Num2, (4,16) },
|
||||
{ LedId.Keyboard_Num3, (4,17) },
|
||||
@ -439,7 +438,6 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
{ LedId.Keyboard_PeriodAndBiggerThan, (4,10) },
|
||||
{ LedId.Keyboard_SlashAndQuestionMark, (4,11) },
|
||||
{ LedId.Keyboard_RightShift, (4,14) },
|
||||
{ LedId.Keyboard_U, (4,16) },
|
||||
{ LedId.Keyboard_Num1, (4,15) },
|
||||
{ LedId.Keyboard_Num2, (4,16) },
|
||||
{ LedId.Keyboard_Num3, (4,17) },
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.CoolerMaster.Native;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
{
|
||||
@ -24,6 +26,27 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
||||
{
|
||||
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
|
||||
|
||||
if (leds.Count > 0)
|
||||
{
|
||||
// 6 by 22 seems hard-coded but it's what the CM SDK expects regardless of keyboard size
|
||||
var matrix = new _CoolerMasterSDK.COLOR_MATRIX { KeyColor = new _CoolerMasterSDK.KEY_COLOR[6, 22] };
|
||||
foreach (Led led in leds)
|
||||
{
|
||||
(int row, int column) = ((int, int))led.CustomData;
|
||||
matrix.KeyColor[row, column] = new _CoolerMasterSDK.KEY_COLOR(led.Color.R, led.Color.G, led.Color.B);
|
||||
}
|
||||
|
||||
_CoolerMasterSDK.SetControlDevice(DeviceInfo.DeviceIndex);
|
||||
_CoolerMasterSDK.SetAllLedColor(matrix);
|
||||
_CoolerMasterSDK.RefreshLed(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeLayout()
|
||||
{
|
||||
|
||||
@ -49,6 +49,7 @@ namespace RGB.NET.Devices.CoolerMaster.Native
|
||||
_enableLedControlPointer = (EnableLedControlPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "EnableLedControl"), typeof(EnableLedControlPointer));
|
||||
_refreshLedPointer = (RefreshLedPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "RefreshLed"), typeof(RefreshLedPointer));
|
||||
_setLedColorPointer = (SetLedColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetLedColor"), typeof(SetLedColorPointer));
|
||||
_setAllLedColorPointer = (SetAllLedColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetAllLedColor"), typeof(SetAllLedColorPointer));
|
||||
}
|
||||
|
||||
private static void UnloadCMSDK()
|
||||
@ -73,6 +74,31 @@ namespace RGB.NET.Devices.CoolerMaster.Native
|
||||
|
||||
#region SDK-METHODS
|
||||
|
||||
#region Structs
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
internal struct KEY_COLOR
|
||||
{
|
||||
public byte r;
|
||||
public byte g;
|
||||
public byte b;
|
||||
|
||||
public KEY_COLOR(byte colR, byte colG, byte colB)
|
||||
{
|
||||
r = colR;
|
||||
g = colG;
|
||||
b = colB;
|
||||
}
|
||||
}
|
||||
|
||||
internal struct COLOR_MATRIX
|
||||
{
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 132)] public KEY_COLOR[,] KeyColor;
|
||||
}
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
||||
#endregion
|
||||
|
||||
#region Pointers
|
||||
|
||||
private static GetSDKVersionPointer _getSDKVersionPointer;
|
||||
@ -82,6 +108,7 @@ namespace RGB.NET.Devices.CoolerMaster.Native
|
||||
private static EnableLedControlPointer _enableLedControlPointer;
|
||||
private static RefreshLedPointer _refreshLedPointer;
|
||||
private static SetLedColorPointer _setLedColorPointer;
|
||||
private static SetAllLedColorPointer _setAllLedColorPointer;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -112,6 +139,10 @@ namespace RGB.NET.Devices.CoolerMaster.Native
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool SetLedColorPointer(int row, int column, byte r, byte g, byte b);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool SetAllLedColorPointer(COLOR_MATRIX colorMatrix);
|
||||
|
||||
#endregion
|
||||
|
||||
// ReSharper disable EventExceptionNotDocumented
|
||||
@ -172,6 +203,14 @@ namespace RGB.NET.Devices.CoolerMaster.Native
|
||||
return _setLedColorPointer(row, column, r, g, b);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: Set Keyboard "every LED" color
|
||||
/// </summary>
|
||||
internal static bool SetAllLedColor(COLOR_MATRIX colorMatrix)
|
||||
{
|
||||
return _setAllLedColorPointer(colorMatrix);
|
||||
}
|
||||
|
||||
// ReSharper restore EventExceptionNotDocumented
|
||||
|
||||
#endregion
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user