1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 01:58:30 +00:00

Merge pull request #203 from DarthAffe/SDK/Corsair

Sdk/corsair
This commit is contained in:
DarthAffe 2021-04-19 20:31:34 +02:00 committed by GitHub
commit b8ccc16f49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 282 additions and 393 deletions

View File

@ -3,8 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native; using RGB.NET.Devices.Corsair.Native;
@ -85,7 +83,17 @@ namespace RGB.NET.Devices.Corsair
Throw(new CUEException(LastError)); Throw(new CUEException(LastError));
} }
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> LoadDevices() protected override IEnumerable<IRGBDevice> LoadDevices()
{
foreach (ICorsairRGBDevice corsairDevice in LoadCorsairDevices())
{
corsairDevice.Initialize();
yield return corsairDevice;
}
}
private IEnumerable<ICorsairRGBDevice> LoadCorsairDevices()
{ {
int deviceCount = _CUESDK.CorsairGetDeviceCount(); int deviceCount = _CUESDK.CorsairGetDeviceCount();
for (int i = 0; i < deviceCount; i++) for (int i = 0; i < deviceCount; i++)
@ -122,6 +130,14 @@ namespace RGB.NET.Devices.Corsair
yield return new CorsairMemoryRGBDevice(new CorsairMemoryRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); yield return new CorsairMemoryRGBDevice(new CorsairMemoryRGBDeviceInfo(i, nativeDeviceInfo), updateQueue);
break; break;
case CorsairDeviceType.Mainboard:
yield return new CorsairMainboardRGBDevice(new CorsairMainboardRGBDeviceInfo(i, nativeDeviceInfo), updateQueue);
break;
case CorsairDeviceType.GraphicsCard:
yield return new CorsairGraphicsCardRGBDevice(new CorsairGraphicsCardRGBDeviceInfo(i, nativeDeviceInfo), updateQueue);
break;
case CorsairDeviceType.Cooler: case CorsairDeviceType.Cooler:
case CorsairDeviceType.CommanderPro: case CorsairDeviceType.CommanderPro:
case CorsairDeviceType.LightningNodePro: case CorsairDeviceType.LightningNodePro:
@ -129,6 +145,7 @@ namespace RGB.NET.Devices.Corsair
if (channelsInfo != null) if (channelsInfo != null)
{ {
IntPtr channelInfoPtr = channelsInfo.channels; IntPtr channelInfoPtr = channelsInfo.channels;
int ledOffset = 0;
for (int channel = 0; channel < channelsInfo.channelsCount; channel++) for (int channel = 0; channel < channelsInfo.channelsCount; channel++)
{ {
@ -144,9 +161,10 @@ namespace RGB.NET.Devices.Corsair
{ {
_CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo))!; _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo))!;
yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(info, nativeDeviceInfo, channelDeviceInfo, referenceLed), updateQueue); yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(info, nativeDeviceInfo, channelDeviceInfo, referenceLed, ledOffset), updateQueue);
referenceLed += channelDeviceInfo.deviceLedCount; referenceLed += channelDeviceInfo.deviceLedCount;
ledOffset += channelDeviceInfo.deviceLedCount;
channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize); channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize);
} }
@ -155,7 +173,6 @@ namespace RGB.NET.Devices.Corsair
} }
} }
break; break;
default: default:
Throw(new RGBDeviceException("Unknown Device-Type")); Throw(new RGBDeviceException("Unknown Device-Type"));
break; break;

View File

@ -1,8 +1,10 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System.Collections.Generic; using System;
using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
{ {
@ -12,12 +14,6 @@ namespace RGB.NET.Devices.Corsair
/// </summary> /// </summary>
public class CorsairCustomRGBDevice : CorsairRGBDevice<CorsairCustomRGBDeviceInfo>, IUnknownDevice public class CorsairCustomRGBDevice : CorsairRGBDevice<CorsairCustomRGBDeviceInfo>, IUnknownDevice
{ {
#region Properties & Fields
private readonly Dictionary<LedId, CorsairLedId> _idMapping = new();
#endregion
#region Constructors #region Constructors
/// <inheritdoc /> /// <inheritdoc />
@ -26,46 +22,52 @@ namespace RGB.NET.Devices.Corsair
/// </summary> /// </summary>
/// <param name="info">The specific information provided by CUE for the custom-device.</param> /// <param name="info">The specific information provided by CUE for the custom-device.</param>
internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, updateQueue) : base(info, new LedMapping<CorsairLedId>(), updateQueue)
{ { }
InitializeLayout();
}
#endregion #endregion
#region Methods #region Methods
private void InitializeLayout() /// <inheritdoc />
protected override void InitializeLayout()
{ {
LedId referenceId = GetReferenceLed(DeviceInfo.DeviceType); Mapping.Clear();
_CorsairLedPositions? nativeLedPositions = (_CorsairLedPositions?)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex), typeof(_CorsairLedPositions));
if (nativeLedPositions == null) return;
int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
IntPtr ptr = new(nativeLedPositions.pLedPosition.ToInt64() + (structSize * DeviceInfo.LedOffset));
LedId referenceLedId = GetReferenceLed(DeviceInfo.DeviceType);
for (int i = 0; i < DeviceInfo.LedCount; i++) for (int i = 0; i < DeviceInfo.LedCount; i++)
{ {
LedId ledId = referenceId + i; LedId ledId = referenceLedId + i;
_idMapping.Add(ledId, DeviceInfo.ReferenceCorsairLed + i); _CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
AddLed(ledId, new Point(i * 10, 0), new Size(10, 10)); if (ledPosition == null)
{
ptr = new IntPtr(ptr.ToInt64() + structSize);
continue;
}
Mapping.Add(ledId, ledPosition.LedId);
Rectangle rectangle = ledPosition.ToRectangle();
AddLed(ledId, rectangle.Location, rectangle.Size);
ptr = new IntPtr(ptr.ToInt64() + structSize);
} }
} }
protected override object GetLedCustomData(LedId ledId) => _idMapping.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid; private static LedId GetReferenceLed(RGBDeviceType deviceType)
=> deviceType switch
protected virtual LedId GetReferenceLed(RGBDeviceType deviceType)
{
switch (deviceType)
{ {
case RGBDeviceType.LedStripe: RGBDeviceType.LedStripe => LedId.LedStripe1,
return LedId.LedStripe1; RGBDeviceType.Fan => LedId.Fan1,
RGBDeviceType.Cooler => LedId.Cooler1,
case RGBDeviceType.Fan: _ => LedId.Custom1
return LedId.Fan1; };
case RGBDeviceType.Cooler:
return LedId.Cooler1;
default:
return LedId.Custom1;
}
}
#endregion #endregion
} }

View File

@ -17,6 +17,7 @@ namespace RGB.NET.Devices.Corsair
public CorsairLedId ReferenceCorsairLed { get; } public CorsairLedId ReferenceCorsairLed { get; }
public int LedCount { get; } public int LedCount { get; }
internal int LedOffset { get; }
#endregion #endregion
@ -31,11 +32,11 @@ namespace RGB.NET.Devices.Corsair
/// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param> /// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
/// <param name="channelDeviceInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairChannelDeviceInfo"/> representing this device.</param> /// <param name="channelDeviceInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairChannelDeviceInfo"/> representing this device.</param>
/// <param name="referenceCorsairLed">The id of the first led of this device.</param> /// <param name="referenceCorsairLed">The id of the first led of this device.</param>
/// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param> internal CorsairCustomRGBDeviceInfo(CorsairRGBDeviceInfo info, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, CorsairLedId referenceCorsairLed, int ledOffset)
internal CorsairCustomRGBDeviceInfo(CorsairRGBDeviceInfo info, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, CorsairLedId referenceCorsairLed)
: base(info.CorsairDeviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo, GetModelName(info, channelDeviceInfo)) : base(info.CorsairDeviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo, GetModelName(info, channelDeviceInfo))
{ {
this.ReferenceCorsairLed = referenceCorsairLed; this.ReferenceCorsairLed = referenceCorsairLed;
this.LedOffset = ledOffset;
LedCount = channelDeviceInfo.deviceLedCount; LedCount = channelDeviceInfo.deviceLedCount;
} }

View File

@ -1,4 +1,7 @@
using RGB.NET.Core; using System;
using System.Runtime.InteropServices;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
{ {
@ -9,15 +12,57 @@ namespace RGB.NET.Devices.Corsair
public abstract class CorsairRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, ICorsairRGBDevice public abstract class CorsairRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, ICorsairRGBDevice
where TDeviceInfo : CorsairRGBDeviceInfo where TDeviceInfo : CorsairRGBDeviceInfo
{ {
#region Properties & Fields
protected LedMapping<CorsairLedId> Mapping { get; }
#endregion
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="CorsairRGBDevice{TDeviceInfo}"/> class. /// Initializes a new instance of the <see cref="CorsairRGBDevice{TDeviceInfo}"/> class.
/// </summary> /// </summary>
/// <param name="info">The generic information provided by CUE for the device.</param> /// <param name="info">The generic information provided by CUE for the device.</param>
protected CorsairRGBDevice(TDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) protected CorsairRGBDevice(TDeviceInfo info, LedMapping<CorsairLedId> mapping, CorsairDeviceUpdateQueue updateQueue)
: base(info, updateQueue) : base(info, updateQueue)
{ } {
this.Mapping = mapping;
}
#endregion
#region Methods
void ICorsairRGBDevice.Initialize() => InitializeLayout();
protected virtual 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;
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
{
_CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
if (ledPosition == null)
{
ptr = new IntPtr(ptr.ToInt64() + structSize);
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);
}
}
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => Mapping.TryGetValue(ledId, out CorsairLedId corsairLedId) ? corsairLedId : CorsairLedId.Invalid;
#endregion #endregion
} }

View File

@ -36,6 +36,7 @@ namespace RGB.NET.Devices.Corsair
/// <inheritdoc /> /// <inheritdoc />
public string Model { get; } public string Model { get; }
/// <inheritdoc />
public object? LayoutMetadata { get; set; } public object? LayoutMetadata { get; set; }
/// <summary> /// <summary>
@ -53,7 +54,6 @@ namespace RGB.NET.Devices.Corsair
/// <param name="deviceIndex">The index of the <see cref="CorsairRGBDevice{TDeviceInfo}"/>.</param> /// <param name="deviceIndex">The index of the <see cref="CorsairRGBDevice{TDeviceInfo}"/>.</param>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param> /// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param> /// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
/// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo) internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo)
{ {
this.CorsairDeviceIndex = deviceIndex; this.CorsairDeviceIndex = deviceIndex;
@ -72,7 +72,6 @@ namespace RGB.NET.Devices.Corsair
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param> /// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param> /// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
/// <param name="modelName">The name of the device-model (overwrites the one provided with the device info).</param> /// <param name="modelName">The name of the device-model (overwrites the one provided with the device info).</param>
/// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo, string modelName) internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo, string modelName)
{ {
this.CorsairDeviceIndex = deviceIndex; this.CorsairDeviceIndex = deviceIndex;
@ -84,11 +83,6 @@ namespace RGB.NET.Devices.Corsair
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model); DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
} }
#endregion
#region Methods
#endregion #endregion
} }
} }

View File

@ -6,5 +6,7 @@ namespace RGB.NET.Devices.Corsair
/// Represents a corsair RGB-device. /// Represents a corsair RGB-device.
/// </summary> /// </summary>
public interface ICorsairRGBDevice : IRGBDevice public interface ICorsairRGBDevice : IRGBDevice
{ } {
internal void Initialize();
}
} }

View File

@ -1,12 +1,51 @@
using System.Collections.Generic; using RGB.NET.Core;
using RGB.NET.Core;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
{ {
internal static class KeyboardIdMapping public static class LedMappings
{ {
internal static readonly Dictionary<LedId, CorsairLedId> DEFAULT = new() static LedMappings()
{ {
for (int i = 0; i <= (CorsairLedId.GPU50 - CorsairLedId.GPU1); i++)
GraphicsCard.Add(LedId.GraphicsCard1 + i, (CorsairLedId.GPU1 + i));
for (int i = 0; i <= (CorsairLedId.HeadsetStandZone9 - CorsairLedId.HeadsetStandZone1); i++)
HeadsetStand.Add(LedId.HeadsetStand1 + i, (CorsairLedId.HeadsetStandZone1 + i));
for (int i = 0; i <= (CorsairLedId.Mainboard100 - CorsairLedId.Mainboard1); i++)
Mainboard.Add(LedId.Mainboard1 + i, (CorsairLedId.Mainboard1 + i));
for (int i = 0; i <= (CorsairLedId.DRAM12 - CorsairLedId.DRAM1); i++)
Memory.Add(LedId.DRAM1 + i, (CorsairLedId.DRAM1 + i));
for (int i = 0; i <= (CorsairLedId.Zone15 - CorsairLedId.Zone1); i++)
Mousepad.Add(LedId.Mousepad1 + i, (CorsairLedId.Zone1 + i));
}
public static LedMapping<CorsairLedId> GraphicsCard = new();
public static LedMapping<CorsairLedId> HeadsetStand = new();
public static LedMapping<CorsairLedId> Mainboard = new();
public static LedMapping<CorsairLedId> Memory = new();
public static LedMapping<CorsairLedId> Mousepad = new();
public static LedMapping<CorsairLedId> Headset = new()
{
{ LedId.Headset1, CorsairLedId.LeftLogo },
{ LedId.Headset2, CorsairLedId.RightLogo },
};
public static LedMapping<CorsairLedId> Mouse = new()
{
{ LedId.Mouse1, CorsairLedId.B1 },
{ LedId.Mouse2, CorsairLedId.B2 },
{ LedId.Mouse3, CorsairLedId.B3 },
{ LedId.Mouse4, CorsairLedId.B4 },
{ LedId.Mouse5, CorsairLedId.B5 },
{ LedId.Mouse6, CorsairLedId.B6 },
};
public static LedMapping<CorsairLedId> Keyboard = new()
{
{ LedId.Invalid, CorsairLedId.Invalid }, { LedId.Invalid, CorsairLedId.Invalid },
{ LedId.Logo, CorsairLedId.Logo }, { LedId.Logo, CorsairLedId.Logo },
{ LedId.Keyboard_Escape, CorsairLedId.Escape }, { LedId.Keyboard_Escape, CorsairLedId.Escape },

View File

@ -0,0 +1,27 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.Corsair
{
/// <inheritdoc cref="CorsairRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a corsair graphics card.
/// </summary>
public class CorsairGraphicsCardRGBDevice : CorsairRGBDevice<CorsairGraphicsCardRGBDeviceInfo>, IGraphicsCard
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairGraphicsCardRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the graphics card.</param>
internal CorsairGraphicsCardRGBDevice(CorsairGraphicsCardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.GraphicsCard, updateQueue)
{ }
#endregion
}
}

View File

@ -0,0 +1,29 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
{
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Corsair.CorsairGraphicsCardRGBDevice" />.
/// </summary>
public class CorsairGraphicsCardRGBDeviceInfo : CorsairRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairGraphicsCardRGBDeviceInfo" />.
/// </summary>
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairGraphicsCardRGBDevice" />.</param>
/// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
internal CorsairGraphicsCardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, RGBDeviceType.GraphicsCard, nativeInfo)
{ }
#endregion
}
}

View File

@ -19,22 +19,8 @@ namespace RGB.NET.Devices.Corsair
/// </summary> /// </summary>
/// <param name="info">The specific information provided by CUE for the headset</param> /// <param name="info">The specific information provided by CUE for the headset</param>
internal CorsairHeadsetRGBDevice(CorsairHeadsetRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) internal CorsairHeadsetRGBDevice(CorsairHeadsetRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, updateQueue) : base(info, LedMappings.Headset, updateQueue)
{ { }
InitializeLayout();
}
#endregion
#region Methods
private void InitializeLayout()
{
AddLed(LedId.Headset1, new Point(0, 0), new Size(10, 10));
AddLed(LedId.Headset2, new Point(10, 0), new Size(10, 10));
}
protected override object GetLedCustomData(LedId ledId) => HeadsetIdMapping.DEFAULT.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;
#endregion #endregion
} }

View File

@ -1,14 +0,0 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Corsair
{
internal static class HeadsetIdMapping
{
internal static readonly Dictionary<LedId, CorsairLedId> DEFAULT = new()
{
{ LedId.Headset1, CorsairLedId.LeftLogo },
{ LedId.Headset2, CorsairLedId.RightLogo },
};
}
}

View File

@ -1,12 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.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.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
{ {
@ -24,44 +19,8 @@ namespace RGB.NET.Devices.Corsair
/// </summary> /// </summary>
/// <param name="info">The specific information provided by CUE for the headset stand</param> /// <param name="info">The specific information provided by CUE for the headset stand</param>
internal CorsairHeadsetStandRGBDevice(CorsairHeadsetStandRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) internal CorsairHeadsetStandRGBDevice(CorsairHeadsetStandRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, updateQueue) : base(info, LedMappings.HeadsetStand, 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;
#endregion #endregion
} }

View File

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

View File

@ -1,11 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
{ {
@ -29,38 +25,8 @@ namespace RGB.NET.Devices.Corsair
/// </summary> /// </summary>
/// <param name="info">The specific information provided by CUE for the keyboard</param> /// <param name="info">The specific information provided by CUE for the keyboard</param>
internal CorsairKeyboardRGBDevice(CorsairKeyboardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) internal CorsairKeyboardRGBDevice(CorsairKeyboardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, updateQueue) : base(info, LedMappings.Keyboard, 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 = KeyboardIdMapping.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) => KeyboardIdMapping.DEFAULT.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;
#endregion #endregion
} }

View File

@ -0,0 +1,27 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
namespace RGB.NET.Devices.Corsair
{
/// <inheritdoc cref="CorsairRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a corsair memory.
/// </summary>
public class CorsairMainboardRGBDevice : CorsairRGBDevice<CorsairMainboardRGBDeviceInfo>, IMainboard
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMainboardRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the memory.</param>
internal CorsairMainboardRGBDevice(CorsairMainboardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, LedMappings.Mainboard, updateQueue)
{ }
#endregion
}
}

View File

@ -0,0 +1,29 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
{
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Corsair.CorsairMainboardRGBDevice" />.
/// </summary>
public class CorsairMainboardRGBDeviceInfo : CorsairRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Corsair.CorsairMainboardRGBDeviceInfo" />.
/// </summary>
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMainboardRGBDevice" />.</param>
/// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
internal CorsairMainboardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, RGBDeviceType.Mainboard, nativeInfo)
{ }
#endregion
}
}

View File

@ -1,11 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
{ {
@ -23,38 +19,8 @@ namespace RGB.NET.Devices.Corsair
/// </summary> /// </summary>
/// <param name="info">The specific information provided by CUE for the memory.</param> /// <param name="info">The specific information provided by CUE for the memory.</param>
internal CorsairMemoryRGBDevice(CorsairMemoryRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) internal CorsairMemoryRGBDevice(CorsairMemoryRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, updateQueue) : base(info, LedMappings.Memory, 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;
#endregion #endregion
} }

View File

@ -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 },
};
}
}

View File

@ -1,7 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System;
using RGB.NET.Core; using RGB.NET.Core;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
@ -20,51 +19,8 @@ namespace RGB.NET.Devices.Corsair
/// </summary> /// </summary>
/// <param name="info">The specific information provided by CUE for the mouse</param> /// <param name="info">The specific information provided by CUE for the mouse</param>
internal CorsairMouseRGBDevice(CorsairMouseRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) internal CorsairMouseRGBDevice(CorsairMouseRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, updateQueue) : base(info, LedMappings.Mouse, updateQueue)
{ { }
InitializeLayout();
}
#endregion
#region Methods
private void InitializeLayout()
{
switch (DeviceInfo.PhysicalLayout)
{
case CorsairPhysicalMouseLayout.Zones1:
AddLed(LedId.Mouse1, new Point(0, 0), new Size(10, 10));
break;
case CorsairPhysicalMouseLayout.Zones2:
AddLed(LedId.Mouse1, new Point(0, 0), new Size(10, 10));
AddLed(LedId.Mouse2, new Point(10, 0), new Size(10, 10));
break;
case CorsairPhysicalMouseLayout.Zones3:
AddLed(LedId.Mouse1, new Point(0, 0), new Size(10, 10));
AddLed(LedId.Mouse2, new Point(10, 0), new Size(10, 10));
AddLed(LedId.Mouse3, new Point(20, 0), new Size(10, 10));
break;
case CorsairPhysicalMouseLayout.Zones4:
AddLed(LedId.Mouse1, new Point(0, 0), new Size(10, 10));
AddLed(LedId.Mouse2, new Point(10, 0), new Size(10, 10));
AddLed(LedId.Mouse3, new Point(20, 0), new Size(10, 10));
AddLed(LedId.Mouse4, new Point(30, 0), new Size(10, 10));
break;
default:
throw new RGBDeviceException($"Can't initialize mouse with layout '{DeviceInfo.PhysicalLayout}'");
}
}
protected override object GetLedCustomData(LedId ledId)
{
if (string.Equals(DeviceInfo.Model, "GLAIVE RGB", StringComparison.OrdinalIgnoreCase))
return MouseIdMapping.GLAIVE.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;
else if (string.Equals(DeviceInfo.Model, "M65 RGB ELITE", StringComparison.OrdinalIgnoreCase))
return MouseIdMapping.M65_RGB_ELITE.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;
else
return MouseIdMapping.DEFAULT.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;
}
#endregion #endregion
} }

View File

@ -1,31 +0,0 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Corsair
{
internal static class MouseIdMapping
{
internal static readonly Dictionary<LedId, CorsairLedId> DEFAULT = new()
{
{ LedId.Mouse1, CorsairLedId.B1 },
{ LedId.Mouse2, CorsairLedId.B2 },
{ LedId.Mouse3, CorsairLedId.B3 },
{ LedId.Mouse4, CorsairLedId.B4 },
{ LedId.Mouse5, CorsairLedId.B5 },
{ LedId.Mouse6, CorsairLedId.B6 },
};
internal static readonly Dictionary<LedId, CorsairLedId> GLAIVE = new()
{
{ LedId.Mouse1, CorsairLedId.B1 },
{ LedId.Mouse2, CorsairLedId.B2 },
{ LedId.Mouse3, CorsairLedId.B5 },
};
internal static readonly Dictionary<LedId, CorsairLedId> M65_RGB_ELITE = new()
{
{ LedId.Mouse1, CorsairLedId.B1 },
{ LedId.Mouse2, CorsairLedId.B3 },
};
}
}

View File

@ -1,12 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.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.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
{ {
@ -24,43 +19,8 @@ namespace RGB.NET.Devices.Corsair
/// </summary> /// </summary>
/// <param name="info">The specific information provided by CUE for the mousepad</param> /// <param name="info">The specific information provided by CUE for the mousepad</param>
internal CorsairMousepadRGBDevice(CorsairMousepadRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) internal CorsairMousepadRGBDevice(CorsairMousepadRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, updateQueue) : base(info, LedMappings.Mousepad, 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 = MousepadIdMapping.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);
}
}
protected override object GetLedCustomData(LedId ledId) => MousepadIdMapping.DEFAULT.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;
#endregion #endregion
} }

View File

@ -1,27 +0,0 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Corsair
{
internal static class MousepadIdMapping
{
internal static readonly Dictionary<LedId, CorsairLedId> DEFAULT = new()
{
{ LedId.Mousepad1, CorsairLedId.Zone1 },
{ LedId.Mousepad2, CorsairLedId.Zone2 },
{ LedId.Mousepad3, CorsairLedId.Zone3 },
{ LedId.Mousepad4, CorsairLedId.Zone4 },
{ LedId.Mousepad5, CorsairLedId.Zone5 },
{ LedId.Mousepad6, CorsairLedId.Zone6 },
{ LedId.Mousepad7, CorsairLedId.Zone7 },
{ LedId.Mousepad8, CorsairLedId.Zone8 },
{ LedId.Mousepad9, CorsairLedId.Zone9 },
{ LedId.Mousepad10, CorsairLedId.Zone10 },
{ LedId.Mousepad11, CorsairLedId.Zone11 },
{ LedId.Mousepad12, CorsairLedId.Zone12 },
{ LedId.Mousepad13, CorsairLedId.Zone13 },
{ LedId.Mousepad14, CorsairLedId.Zone14 },
{ LedId.Mousepad15, CorsairLedId.Zone15 }
};
}
}

View File

@ -1,8 +1,10 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generic_005Cupdate/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generic_005Cupdate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=graphicscard/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=headsetstand/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=headsetstand/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=helper/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=helper/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=libs/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=libs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mainboard/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=memory/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=memory/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mousepad/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mousepad/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=native/@EntryIndexedValue">False</s:Boolean> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=native/@EntryIndexedValue">False</s:Boolean>