mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-11-11 04:57:15 +00:00
Rewrote Corsair device handling to use mappings
This commit is contained in:
1 parent
2d0fd93b5f
commit
1e229324be
23 files changed
+284
-395
No files matched your search
@@ -1,12 +1,7 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
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
|
||||
{
|
||||
@@ -24,44 +19,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CUE for the headset stand</param>
|
||||
internal CorsairHeadsetStandRGBDevice(CorsairHeadsetStandRGBDeviceInfo 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;
|
||||
|
||||
List<_CorsairLedPosition> positions = new();
|
||||
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
|
||||
{
|
||||
_CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
|
||||
if (ledPosition == null) continue;
|
||||
|
||||
ptr = new IntPtr(ptr.ToInt64() + structSize);
|
||||
positions.Add(ledPosition);
|
||||
}
|
||||
|
||||
Dictionary<CorsairLedId, LedId> mapping = HeadsetStandIdMapping.DEFAULT.SwapKeyValue();
|
||||
foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.LedId))
|
||||
{
|
||||
LedId ledId = mapping.TryGetValue(ledPosition.LedId, out LedId id) ? id : LedId.Invalid;
|
||||
Rectangle rectangle = ledPosition.ToRectangle();
|
||||
AddLed(ledId, rectangle.Location, rectangle.Size);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override object GetLedCustomData(LedId ledId) => HeadsetStandIdMapping.DEFAULT.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;
|
||||
: base(info, LedMappings.HeadsetStand, updateQueue)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
internal static class HeadsetStandIdMapping
|
||||
{
|
||||
internal static readonly Dictionary<LedId, CorsairLedId> DEFAULT = new()
|
||||
{
|
||||
{ LedId.HeadsetStand1, CorsairLedId.HeadsetStandZone1 },
|
||||
{ LedId.HeadsetStand2, CorsairLedId.HeadsetStandZone2 },
|
||||
{ LedId.HeadsetStand3, CorsairLedId.HeadsetStandZone3 },
|
||||
{ LedId.HeadsetStand4, CorsairLedId.HeadsetStandZone4 },
|
||||
{ LedId.HeadsetStand5, CorsairLedId.HeadsetStandZone5 },
|
||||
{ LedId.HeadsetStand6, CorsairLedId.HeadsetStandZone6 },
|
||||
{ LedId.HeadsetStand7, CorsairLedId.HeadsetStandZone7 },
|
||||
{ LedId.HeadsetStand8, CorsairLedId.HeadsetStandZone8 },
|
||||
{ LedId.HeadsetStand9, CorsairLedId.HeadsetStandZone9 }
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user