1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-13 00:58:31 +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
{
@ -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
}
}

View File

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

View File

@ -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

View File

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