Rewrote Corsair device handling to use mappings

This commit is contained in:
DarthAffe committed 2021-04-18 19:33:12 +02:00
1 parent 2d0fd93b5f
commit 1e229324be
23 files changed
+284 -395

No files matched your search

@@ -1,11 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
{
@@ -23,38 +19,8 @@ namespace RGB.NET.Devices.Corsair
/// </summary>
/// <param name="info">The specific information provided by CUE for the memory.</param>
internal CorsairMemoryRGBDevice(CorsairMemoryRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, updateQueue)
{
InitializeLayout();
}
#endregion
#region Methods
private void InitializeLayout()
{
_CorsairLedPositions? nativeLedPositions = (_CorsairLedPositions?)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex), typeof(_CorsairLedPositions));
if (nativeLedPositions == null) return;
int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
IntPtr ptr = nativeLedPositions.pLedPosition;
Dictionary<CorsairLedId, LedId> mapping = MemoryIdMapping.DEFAULT.SwapKeyValue();
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
{
_CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
if (ledPosition == null) continue;
LedId ledId = mapping.TryGetValue(ledPosition.LedId, out LedId id) ? id : LedId.Invalid;
Rectangle rectangle = ledPosition.ToRectangle();
AddLed(ledId, rectangle.Location, rectangle.Size);
ptr = new IntPtr(ptr.ToInt64() + structSize);
}
}
protected override object GetLedCustomData(LedId ledId) => MemoryIdMapping.DEFAULT.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;
: base(info, LedMappings.Memory, updateQueue)
{ }
#endregion
}
@@ -1,25 +0,0 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Corsair
{
internal static class MemoryIdMapping
{
internal static readonly Dictionary<LedId, CorsairLedId> DEFAULT = new()
{
{ LedId.Invalid, CorsairLedId.Invalid },
{ LedId.DRAM1, CorsairLedId.DRAM1 },
{ LedId.DRAM2, CorsairLedId.DRAM2 },
{ LedId.DRAM3, CorsairLedId.DRAM3 },
{ LedId.DRAM4, CorsairLedId.DRAM4 },
{ LedId.DRAM5, CorsairLedId.DRAM5 },
{ LedId.DRAM6, CorsairLedId.DRAM6 },
{ LedId.DRAM7, CorsairLedId.DRAM7 },
{ LedId.DRAM8, CorsairLedId.DRAM8 },
{ LedId.DRAM9, CorsairLedId.DRAM9 },
{ LedId.DRAM10, CorsairLedId.DRAM10 },
{ LedId.DRAM11, CorsairLedId.DRAM11 },
{ LedId.DRAM12, CorsairLedId.DRAM12 },
};
}
}