diff --git a/Wrapper/AbstractCueDevice.cs b/Wrapper/AbstractCueDevice.cs index d6e42ec..1f349c5 100644 --- a/Wrapper/AbstractCueDevice.cs +++ b/Wrapper/AbstractCueDevice.cs @@ -1,4 +1,8 @@ -namespace CUE.NET.Wrapper +using System; +using System.Runtime.InteropServices; +using CUE.NET.Native; + +namespace CUE.NET.Wrapper { public abstract class AbstractCueDevice : ICueDevice { @@ -19,6 +23,21 @@ #region Methods + //TODO DarthAffe 19.09.2015: Wrap struct + protected void SetKeyColors(params _CorsairLedColor[] colors) + { + int structSize = Marshal.SizeOf(typeof(_CorsairLedColor)); + IntPtr ptr = Marshal.AllocHGlobal(structSize * colors.Length); + IntPtr addPtr = new IntPtr(ptr.ToInt64()); + foreach (_CorsairLedColor color in colors) + { + Marshal.StructureToPtr(color, addPtr, false); + addPtr = new IntPtr(addPtr.ToInt64() + structSize); + } + _CUESDK.CorsairSetLedsColors(colors.Length, ptr); + Marshal.FreeHGlobal(ptr); + } + #endregion } } diff --git a/Wrapper/CueHeadset.cs b/Wrapper/CueHeadset.cs index e0651a5..9cb823f 100644 --- a/Wrapper/CueHeadset.cs +++ b/Wrapper/CueHeadset.cs @@ -9,7 +9,7 @@ #region Constructors - public CueHeadset(CorsairDeviceInfo info) + internal CueHeadset(CorsairDeviceInfo info) : base(info) { } diff --git a/Wrapper/CueKeyboard.cs b/Wrapper/CueKeyboard.cs index 5083bf3..8b73f64 100644 --- a/Wrapper/CueKeyboard.cs +++ b/Wrapper/CueKeyboard.cs @@ -1,6 +1,4 @@ -using System; -using System.Drawing; -using System.Runtime.InteropServices; +using System.Drawing; using CUE.NET.Enums; using CUE.NET.Native; @@ -14,7 +12,7 @@ namespace CUE.NET.Wrapper #region Constructors - public CueKeyboard(CorsairDeviceInfo info) + internal CueKeyboard(CorsairDeviceInfo info) : base(info) { } @@ -26,11 +24,18 @@ namespace CUE.NET.Wrapper { CorsairLedId id = _CUESDK.CorsairGetLedIdForKeyName(key); _CorsairLedColor ledColor = new _CorsairLedColor { ledId = id, r = color.R, g = color.G, b = color.B }; + SetKeyColors(ledColor); + } - //TODO DarthAffe 18.09.2015: Generalize and move to base class - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(_CorsairLedColor))); - Marshal.StructureToPtr(ledColor, ptr, true); - _CUESDK.CorsairSetLedsColors(1, ptr); + public void SetKeyColors(char[] keys, Color color) + { + _CorsairLedColor[] ledColors = new _CorsairLedColor[keys.Length]; + for (int i = 0; i < keys.Length; i++) + { + CorsairLedId id = _CUESDK.CorsairGetLedIdForKeyName(keys[i]); + ledColors[i] = new _CorsairLedColor { ledId = id, r = color.R, g = color.G, b = color.B }; + } + SetKeyColors(ledColors); } #endregion diff --git a/Wrapper/CueMouse.cs b/Wrapper/CueMouse.cs index ebe440c..c8748e5 100644 --- a/Wrapper/CueMouse.cs +++ b/Wrapper/CueMouse.cs @@ -9,7 +9,7 @@ #region Constructors - public CueMouse(CorsairDeviceInfo info) + internal CueMouse(CorsairDeviceInfo info) : base(info) { }