1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-13 09:08:34 +00:00

Finished wrapper around "CorsairSetLedsColors", changed device-constructors to internal

This commit is contained in:
unknown 2015-09-19 09:44:57 +02:00
parent b69689e1f8
commit 599491e630
4 changed files with 35 additions and 11 deletions

View File

@ -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 public abstract class AbstractCueDevice : ICueDevice
{ {
@ -19,6 +23,21 @@
#region Methods #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 #endregion
} }
} }

View File

@ -9,7 +9,7 @@
#region Constructors #region Constructors
public CueHeadset(CorsairDeviceInfo info) internal CueHeadset(CorsairDeviceInfo info)
: base(info) : base(info)
{ } { }

View File

@ -1,6 +1,4 @@
using System; using System.Drawing;
using System.Drawing;
using System.Runtime.InteropServices;
using CUE.NET.Enums; using CUE.NET.Enums;
using CUE.NET.Native; using CUE.NET.Native;
@ -14,7 +12,7 @@ namespace CUE.NET.Wrapper
#region Constructors #region Constructors
public CueKeyboard(CorsairDeviceInfo info) internal CueKeyboard(CorsairDeviceInfo info)
: base(info) : base(info)
{ } { }
@ -26,11 +24,18 @@ namespace CUE.NET.Wrapper
{ {
CorsairLedId id = _CUESDK.CorsairGetLedIdForKeyName(key); CorsairLedId id = _CUESDK.CorsairGetLedIdForKeyName(key);
_CorsairLedColor ledColor = new _CorsairLedColor { ledId = id, r = color.R, g = color.G, b = color.B }; _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 public void SetKeyColors(char[] keys, Color color)
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(_CorsairLedColor))); {
Marshal.StructureToPtr(ledColor, ptr, true); _CorsairLedColor[] ledColors = new _CorsairLedColor[keys.Length];
_CUESDK.CorsairSetLedsColors(1, ptr); 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 #endregion

View File

@ -9,7 +9,7 @@
#region Constructors #region Constructors
public CueMouse(CorsairDeviceInfo info) internal CueMouse(CorsairDeviceInfo info)
: base(info) : base(info)
{ } { }