Fixed some stuff to get Corsair-Devices working

This commit is contained in:
DarthAffe committed 2017-01-26 20:14:38 +01:00
1 parent 7f6c8e6a70
commit 05c0633348
18 files changed
+308 -35

No files matched your search

@@ -6,15 +6,18 @@ namespace RGB.NET.Devices.Corsair
/// <summary>
/// Represents a Id of a <see cref="Led"/> on a <see cref="CorsairRGBDevice"/>.
/// </summary>
[DebuggerDisplay("{" + nameof(_ledId) + "}")]
[DebuggerDisplay("{" + nameof(LedId) + "}")]
public class CorsairLedId : ILedId
{
#region Properties & Fields
private readonly CorsairLedIds _ledId;
internal readonly CorsairLedIds LedId;
/// <inheritdoc />
public bool IsValid => _ledId != CorsairLedIds.Invalid;
public IRGBDevice Device { get; }
/// <inheritdoc />
public bool IsValid => LedId != CorsairLedIds.Invalid;
#endregion
@@ -23,10 +26,12 @@ namespace RGB.NET.Devices.Corsair
/// <summary>
/// Initializes a new instance of the <see cref="CorsairLedId"/> class.
/// </summary>
/// <param name="ledId">The corsair-id of the represented <see cref="Led"/>.</param>
public CorsairLedId(CorsairLedIds ledId)
/// <param name="device">The <see cref="IRGBDevice"/> the <see cref="ILedId"/> belongs to.</param>
/// <param name="ledId">The <see cref="CorsairLedId"/> of the represented <see cref="Led"/>.</param>
public CorsairLedId(IRGBDevice device, CorsairLedIds ledId)
{
this._ledId = ledId;
this.Device = device;
this.LedId = ledId;
}
#endregion
@@ -39,7 +44,7 @@ namespace RGB.NET.Devices.Corsair
/// <returns>A string that contains the Id of this <see cref="CorsairLedId"/>. For example "Enter".</returns>
public override string ToString()
{
return _ledId.ToString();
return LedId.ToString();
}
/// <summary>
@@ -59,7 +64,7 @@ namespace RGB.NET.Devices.Corsair
if (GetType() != compareLedId.GetType())
return false;
return compareLedId._ledId == _ledId;
return compareLedId.LedId == LedId;
}
/// <summary>
@@ -68,7 +73,7 @@ namespace RGB.NET.Devices.Corsair
/// <returns>An integer value that specifies the hash code for this <see cref="CorsairLedId" />.</returns>
public override int GetHashCode()
{
return _ledId.GetHashCode();
return LedId.GetHashCode();
}
#endregion
@@ -1,5 +1,9 @@
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
{
@@ -51,6 +55,34 @@ namespace RGB.NET.Devices.Corsair
/// </summary>
protected abstract void InitializeLeds();
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
{
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
if (leds.Count > 0) // CUE seems to crash if 'CorsairSetLedsColors' is called with a zero length array
{
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
IntPtr ptr = Marshal.AllocHGlobal(structSize * leds.Count);
IntPtr addPtr = new IntPtr(ptr.ToInt64());
foreach (Led led in leds)
{
_CorsairLedColor color = new _CorsairLedColor
{
ledId = (int)((CorsairLedId)led.Id).LedId,
r = led.Color.R,
g = led.Color.G,
b = led.Color.B
};
Marshal.StructureToPtr(color, addPtr, false);
addPtr = new IntPtr(addPtr.ToInt64() + structSize);
}
_CUESDK.CorsairSetLedsColors(leds.Count, ptr);
Marshal.FreeHGlobal(ptr);
}
}
#endregion
}
}