mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-11-10 20:46:24 +00:00
Changed all namespaces to file-scope
This commit is contained in:
1 parent
a0c6ccebea
commit
30624035f1
353 files changed
+35775
-36129
No files matched your search
@@ -1,36 +1,35 @@
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Specifies the <see cref="T:RGB.NET.Core.RGBDeviceType" /> of a field.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class DeviceTypeAttribute : Attribute
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="RGBDeviceType"/>.
|
||||
/// </summary>
|
||||
public RGBDeviceType DeviceType { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Specifies the <see cref="T:RGB.NET.Core.RGBDeviceType" /> of a field.
|
||||
/// Internal constructor of the <see cref="T:RGB.NET.Devices.CoolerMaster.DeviceTypeAttribute" /> class.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class DeviceTypeAttribute : Attribute
|
||||
/// <param name="deviceType">The <see cref="T:RGB.NET.Core.RGBDeviceType" />.</param>
|
||||
public DeviceTypeAttribute(RGBDeviceType deviceType)
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="RGBDeviceType"/>.
|
||||
/// </summary>
|
||||
public RGBDeviceType DeviceType { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Internal constructor of the <see cref="T:RGB.NET.Devices.CoolerMaster.DeviceTypeAttribute" /> class.
|
||||
/// </summary>
|
||||
/// <param name="deviceType">The <see cref="T:RGB.NET.Core.RGBDeviceType" />.</param>
|
||||
public DeviceTypeAttribute(RGBDeviceType deviceType)
|
||||
{
|
||||
this.DeviceType = deviceType;
|
||||
}
|
||||
|
||||
#endregion
|
||||
this.DeviceType = deviceType;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -7,101 +7,100 @@ using RGB.NET.Core;
|
||||
using RGB.NET.Devices.CoolerMaster.Helper;
|
||||
using RGB.NET.Devices.CoolerMaster.Native;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a device provider responsible for Cooler Master devices.
|
||||
/// </summary>
|
||||
public class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
|
||||
{
|
||||
/// <inheritdoc />
|
||||
#region Properties & Fields
|
||||
|
||||
private static CoolerMasterDeviceProvider? _instance;
|
||||
/// <summary>
|
||||
/// Represents a device provider responsible for Cooler Master devices.
|
||||
/// Gets the singleton <see cref="CoolerMasterDeviceProvider"/> instance.
|
||||
/// </summary>
|
||||
public class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
|
||||
public static CoolerMasterDeviceProvider Instance => _instance ?? new CoolerMasterDeviceProvider();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
|
||||
/// The first match will be used.
|
||||
/// </summary>
|
||||
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/CMSDK.dll" };
|
||||
|
||||
/// <summary>
|
||||
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
|
||||
/// The first match will be used.
|
||||
/// </summary>
|
||||
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/CMSDK.dll" };
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CoolerMasterDeviceProvider"/> class.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
|
||||
public CoolerMasterDeviceProvider()
|
||||
{
|
||||
#region Properties & Fields
|
||||
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CoolerMasterDeviceProvider)}");
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
private static CoolerMasterDeviceProvider? _instance;
|
||||
/// <summary>
|
||||
/// Gets the singleton <see cref="CoolerMasterDeviceProvider"/> instance.
|
||||
/// </summary>
|
||||
public static CoolerMasterDeviceProvider Instance => _instance ?? new CoolerMasterDeviceProvider();
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
|
||||
/// The first match will be used.
|
||||
/// </summary>
|
||||
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/CMSDK.dll" };
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
|
||||
/// The first match will be used.
|
||||
/// </summary>
|
||||
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/CMSDK.dll" };
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeSDK()
|
||||
{
|
||||
_CoolerMasterSDK.Reload();
|
||||
if (_CoolerMasterSDK.GetSDKVersion() <= 0) Throw(new RGBDeviceException("Failed to initialize CoolerMaster-SDK"), true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CoolerMasterDeviceProvider"/> class.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
|
||||
public CoolerMasterDeviceProvider()
|
||||
/// <inheritdoc />
|
||||
protected override IEnumerable<IRGBDevice> LoadDevices()
|
||||
{
|
||||
foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
|
||||
{
|
||||
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CoolerMasterDeviceProvider)}");
|
||||
_instance = this;
|
||||
}
|
||||
RGBDeviceType deviceType = index.GetDeviceType();
|
||||
if (deviceType == RGBDeviceType.None) continue;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeSDK()
|
||||
{
|
||||
_CoolerMasterSDK.Reload();
|
||||
if (_CoolerMasterSDK.GetSDKVersion() <= 0) Throw(new RGBDeviceException("Failed to initialize CoolerMaster-SDK"), true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override IEnumerable<IRGBDevice> LoadDevices()
|
||||
{
|
||||
foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
|
||||
if (_CoolerMasterSDK.IsDevicePlugged(index))
|
||||
{
|
||||
RGBDeviceType deviceType = index.GetDeviceType();
|
||||
if (deviceType == RGBDeviceType.None) continue;
|
||||
|
||||
if (_CoolerMasterSDK.IsDevicePlugged(index))
|
||||
if (!_CoolerMasterSDK.EnableLedControl(true, index))
|
||||
Throw(new RGBDeviceException("Failed to enable LED control for device " + index));
|
||||
else
|
||||
{
|
||||
if (!_CoolerMasterSDK.EnableLedControl(true, index))
|
||||
Throw(new RGBDeviceException("Failed to enable LED control for device " + index));
|
||||
else
|
||||
switch (deviceType)
|
||||
{
|
||||
switch (deviceType)
|
||||
{
|
||||
case RGBDeviceType.Keyboard:
|
||||
yield return new CoolerMasterKeyboardRGBDevice(new CoolerMasterKeyboardRGBDeviceInfo(index, _CoolerMasterSDK.GetDeviceLayout(index)), GetUpdateTrigger());
|
||||
break;
|
||||
case RGBDeviceType.Keyboard:
|
||||
yield return new CoolerMasterKeyboardRGBDevice(new CoolerMasterKeyboardRGBDeviceInfo(index, _CoolerMasterSDK.GetDeviceLayout(index)), GetUpdateTrigger());
|
||||
break;
|
||||
|
||||
case RGBDeviceType.Mouse:
|
||||
yield return new CoolerMasterMouseRGBDevice(new CoolerMasterMouseRGBDeviceInfo(index), GetUpdateTrigger());
|
||||
break;
|
||||
case RGBDeviceType.Mouse:
|
||||
yield return new CoolerMasterMouseRGBDevice(new CoolerMasterMouseRGBDeviceInfo(index), GetUpdateTrigger());
|
||||
break;
|
||||
|
||||
default:
|
||||
Throw(new RGBDeviceException("Unknown Device-Type"));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
Throw(new RGBDeviceException("Unknown Device-Type"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
|
||||
try { _CoolerMasterSDK.Reload(); }
|
||||
catch { /* Unlucky.. */ }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
|
||||
try { _CoolerMasterSDK.Reload(); }
|
||||
catch { /* Unlucky.. */ }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -6,98 +6,97 @@ using RGB.NET.Core;
|
||||
|
||||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <summary>
|
||||
/// Contains a list of available device-indexes.
|
||||
/// </summary>
|
||||
public enum CoolerMasterDevicesIndexes
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains a list of available device-indexes.
|
||||
/// </summary>
|
||||
public enum CoolerMasterDevicesIndexes
|
||||
{
|
||||
[Description("MasterKeys Pro L")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_L = 0,
|
||||
[Description("MasterKeys Pro L")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_L = 0,
|
||||
|
||||
[Description("MasterKeys ProS")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_S = 1,
|
||||
[Description("MasterKeys ProS")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_S = 1,
|
||||
|
||||
[Description("MasterKeys Pro L White")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_L_White = 2,
|
||||
[Description("MasterKeys Pro L White")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_L_White = 2,
|
||||
|
||||
[Description("MasterKeys Pro M White")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_M_White = 3,
|
||||
[Description("MasterKeys Pro M White")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_M_White = 3,
|
||||
|
||||
[Description("MasterMouse Pro L")]
|
||||
[DeviceType(RGBDeviceType.Mouse)]
|
||||
MasterMouse_L = 4,
|
||||
[Description("MasterMouse Pro L")]
|
||||
[DeviceType(RGBDeviceType.Mouse)]
|
||||
MasterMouse_L = 4,
|
||||
|
||||
[Description("MasterMouse S")]
|
||||
[DeviceType(RGBDeviceType.Mouse)]
|
||||
MasterMouse_S = 5,
|
||||
[Description("MasterMouse S")]
|
||||
[DeviceType(RGBDeviceType.Mouse)]
|
||||
MasterMouse_S = 5,
|
||||
|
||||
[Description("MasterKeys Pro M")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_M = 6,
|
||||
[Description("MasterKeys Pro M")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_M = 6,
|
||||
|
||||
[Description("MasterKeys Pro S White")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_S_White = 7,
|
||||
[Description("MasterKeys Pro S White")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_S_White = 7,
|
||||
|
||||
[Description("MM520")]
|
||||
[DeviceType(RGBDeviceType.Mouse)]
|
||||
MM520 = 8,
|
||||
[Description("MM520")]
|
||||
[DeviceType(RGBDeviceType.Mouse)]
|
||||
MM520 = 8,
|
||||
|
||||
[Description("MM530")]
|
||||
[DeviceType(RGBDeviceType.Mouse)]
|
||||
MM530 = 9,
|
||||
[Description("MM530")]
|
||||
[DeviceType(RGBDeviceType.Mouse)]
|
||||
MM530 = 9,
|
||||
|
||||
[Description("MasterKeys MK750")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_MK750 = 10,
|
||||
[Description("MasterKeys MK750")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MasterKeys_MK750 = 10,
|
||||
|
||||
[Description("CK372")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
CK372 = 11,
|
||||
[Description("CK372")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
CK372 = 11,
|
||||
|
||||
[Description("CK550")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
CK550 = 12,
|
||||
[Description("CK550")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
CK550 = 12,
|
||||
|
||||
[Description("CK551")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
CK551 = 13,
|
||||
[Description("CK551")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
CK551 = 13,
|
||||
|
||||
[Description("MM830")]
|
||||
[DeviceType(RGBDeviceType.Mouse)]
|
||||
MM830 = 14,
|
||||
[Description("MM830")]
|
||||
[DeviceType(RGBDeviceType.Mouse)]
|
||||
MM830 = 14,
|
||||
|
||||
[Description("CK530")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
CK530 = 15,
|
||||
[Description("CK530")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
CK530 = 15,
|
||||
|
||||
[Description("MK850")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MK850 = 16,
|
||||
[Description("MK850")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MK850 = 16,
|
||||
|
||||
[Description("SK630")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
SK630 = 17,
|
||||
[Description("SK630")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
SK630 = 17,
|
||||
|
||||
[Description("SK650")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
SK650 = 18,
|
||||
[Description("SK650")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
SK650 = 18,
|
||||
|
||||
[Description("SK621")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
SK621 = 19,
|
||||
[Description("SK621")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
SK621 = 19,
|
||||
|
||||
[Description("MK730")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MK730 = 20,
|
||||
[Description("MK730")]
|
||||
[DeviceType(RGBDeviceType.Keyboard)]
|
||||
MK730 = 20,
|
||||
|
||||
[DeviceType(RGBDeviceType.None)]
|
||||
Default = 0xFFFF
|
||||
}
|
||||
}
|
||||
[DeviceType(RGBDeviceType.None)]
|
||||
Default = 0xFFFF
|
||||
}
|
||||
@@ -3,39 +3,38 @@
|
||||
|
||||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <summary>
|
||||
/// Contains a list of available effects.
|
||||
/// </summary>
|
||||
public enum CoolerMasterEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains a list of available effects.
|
||||
/// </summary>
|
||||
public enum CoolerMasterEffects
|
||||
{
|
||||
FullOn = 0,
|
||||
Breath = 1,
|
||||
BreathCycle = 2,
|
||||
Single = 3,
|
||||
Wave = 4,
|
||||
Ripple = 5,
|
||||
Cross = 6,
|
||||
Rain = 7,
|
||||
Star = 8,
|
||||
Snake = 9,
|
||||
Rec = 10,
|
||||
FullOn = 0,
|
||||
Breath = 1,
|
||||
BreathCycle = 2,
|
||||
Single = 3,
|
||||
Wave = 4,
|
||||
Ripple = 5,
|
||||
Cross = 6,
|
||||
Rain = 7,
|
||||
Star = 8,
|
||||
Snake = 9,
|
||||
Rec = 10,
|
||||
|
||||
Spectrum = 11,
|
||||
RapidFire = 12,
|
||||
Indicator = 13, //mouse Effect
|
||||
FireBall = 14,
|
||||
WaterRipple = 15,
|
||||
ReactivePunch = 16,
|
||||
Snowing = 17,
|
||||
HeartBeat = 18,
|
||||
ReactiveTornade = 19,
|
||||
Spectrum = 11,
|
||||
RapidFire = 12,
|
||||
Indicator = 13, //mouse Effect
|
||||
FireBall = 14,
|
||||
WaterRipple = 15,
|
||||
ReactivePunch = 16,
|
||||
Snowing = 17,
|
||||
HeartBeat = 18,
|
||||
ReactiveTornade = 19,
|
||||
|
||||
Multi1 = 0xE0,
|
||||
Multi2 = 0xE1,
|
||||
Multi3 = 0xE2,
|
||||
Multi4 = 0xE3,
|
||||
Off = 0xFE
|
||||
}
|
||||
}
|
||||
Multi1 = 0xE0,
|
||||
Multi2 = 0xE1,
|
||||
Multi3 = 0xE2,
|
||||
Multi4 = 0xE3,
|
||||
Off = 0xFE
|
||||
}
|
||||
@@ -3,16 +3,15 @@
|
||||
|
||||
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <summary>
|
||||
/// Contains list of available physical layouts for cooler master keyboards.
|
||||
/// </summary>
|
||||
public enum CoolerMasterPhysicalKeyboardLayout
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains list of available physical layouts for cooler master keyboards.
|
||||
/// </summary>
|
||||
public enum CoolerMasterPhysicalKeyboardLayout
|
||||
{
|
||||
UNINIT = 0,
|
||||
US = 1,
|
||||
EU = 2,
|
||||
JP = 3
|
||||
}
|
||||
}
|
||||
UNINIT = 0,
|
||||
US = 1,
|
||||
EU = 2,
|
||||
JP = 3
|
||||
}
|
||||
@@ -2,39 +2,38 @@
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.CoolerMaster.Native;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
|
||||
/// <summary>
|
||||
/// Represents a generic CoolerMaster-device. (keyboard, mouse, headset, mousepad).
|
||||
/// </summary>
|
||||
public abstract class CoolerMasterRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, ICoolerMasterRGBDevice
|
||||
where TDeviceInfo : CoolerMasterRGBDeviceInfo
|
||||
{
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Represents a generic CoolerMaster-device. (keyboard, mouse, headset, mousepad).
|
||||
/// Initializes a new instance of the <see cref="CoolerMasterRGBDevice{TDeviceInfo}"/> class.
|
||||
/// </summary>
|
||||
public abstract class CoolerMasterRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, ICoolerMasterRGBDevice
|
||||
where TDeviceInfo : CoolerMasterRGBDeviceInfo
|
||||
/// <param name="info">The generic information provided by CoolerMaster for the device.</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
protected CoolerMasterRGBDevice(TDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, new CoolerMasterUpdateQueue(updateTrigger, info.DeviceIndex))
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc cref="IDisposable.Dispose" />
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}.Dispose" />
|
||||
public override void Dispose()
|
||||
{
|
||||
#region Constructors
|
||||
_CoolerMasterSDK.EnableLedControl(false, DeviceInfo.DeviceIndex);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CoolerMasterRGBDevice{TDeviceInfo}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The generic information provided by CoolerMaster for the device.</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
protected CoolerMasterRGBDevice(TDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, new CoolerMasterUpdateQueue(updateTrigger, info.DeviceIndex))
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc cref="IDisposable.Dispose" />
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}.Dispose" />
|
||||
public override void Dispose()
|
||||
{
|
||||
_CoolerMasterSDK.EnableLedControl(false, DeviceInfo.DeviceIndex);
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,54 +1,53 @@
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.CoolerMaster.Helper;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a Corsair-<see cref="T:RGB.NET.Core.IRGBDevice" />.
|
||||
/// </summary>
|
||||
public class CoolerMasterRGBDeviceInfo : IRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceType DeviceType { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string DeviceName { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Manufacturer => "Cooler Master";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Model { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public object? LayoutMetadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Represents a generic information for a Corsair-<see cref="T:RGB.NET.Core.IRGBDevice" />.
|
||||
/// Gets the <see cref="CoolerMasterDevicesIndexes"/> of the <see cref="CoolerMasterRGBDevice{TDeviceInfo}"/>.
|
||||
/// </summary>
|
||||
public class CoolerMasterRGBDeviceInfo : IRGBDeviceInfo
|
||||
public CoolerMasterDevicesIndexes DeviceIndex { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="CoolerMasterRGBDeviceInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="deviceIndex">The <see cref="CoolerMasterDevicesIndexes"/> of the <see cref="IRGBDevice"/>.</param>
|
||||
internal CoolerMasterRGBDeviceInfo(RGBDeviceType deviceType, CoolerMasterDevicesIndexes deviceIndex)
|
||||
{
|
||||
#region Properties & Fields
|
||||
this.DeviceType = deviceType;
|
||||
this.DeviceIndex = deviceIndex;
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceType DeviceType { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string DeviceName { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Manufacturer => "Cooler Master";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Model { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public object? LayoutMetadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CoolerMasterDevicesIndexes"/> of the <see cref="CoolerMasterRGBDevice{TDeviceInfo}"/>.
|
||||
/// </summary>
|
||||
public CoolerMasterDevicesIndexes DeviceIndex { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="CoolerMasterRGBDeviceInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
|
||||
/// <param name="deviceIndex">The <see cref="CoolerMasterDevicesIndexes"/> of the <see cref="IRGBDevice"/>.</param>
|
||||
internal CoolerMasterRGBDeviceInfo(RGBDeviceType deviceType, CoolerMasterDevicesIndexes deviceIndex)
|
||||
{
|
||||
this.DeviceType = deviceType;
|
||||
this.DeviceIndex = deviceIndex;
|
||||
|
||||
Model = deviceIndex.GetDescription();
|
||||
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
|
||||
}
|
||||
|
||||
#endregion
|
||||
Model = deviceIndex.GetDescription();
|
||||
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,52 +2,51 @@
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.CoolerMaster.Native;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents the update-queue performing updates for cooler master devices.
|
||||
/// </summary>
|
||||
public class CoolerMasterUpdateQueue : UpdateQueue
|
||||
{
|
||||
/// <inheritdoc />
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly CoolerMasterDevicesIndexes _deviceIndex;
|
||||
private readonly _CoolerMasterColorMatrix _deviceMatrix;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Represents the update-queue performing updates for cooler master devices.
|
||||
/// Initializes a new instance of the <see cref="CoolerMasterUpdateQueue"/> class.
|
||||
/// </summary>
|
||||
public class CoolerMasterUpdateQueue : UpdateQueue
|
||||
/// <param name="updateTrigger">The update trigger used by this queue.</param>
|
||||
/// <param name="deviceIndex">The <see cref="CoolerMasterDevicesIndexes"/> of the device this queue performs updates for.</param>
|
||||
public CoolerMasterUpdateQueue(IDeviceUpdateTrigger updateTrigger, CoolerMasterDevicesIndexes deviceIndex)
|
||||
: base(updateTrigger)
|
||||
{
|
||||
#region Properties & Fields
|
||||
this._deviceIndex = deviceIndex;
|
||||
|
||||
private readonly CoolerMasterDevicesIndexes _deviceIndex;
|
||||
private readonly _CoolerMasterColorMatrix _deviceMatrix;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CoolerMasterUpdateQueue"/> class.
|
||||
/// </summary>
|
||||
/// <param name="updateTrigger">The update trigger used by this queue.</param>
|
||||
/// <param name="deviceIndex">The <see cref="CoolerMasterDevicesIndexes"/> of the device this queue performs updates for.</param>
|
||||
public CoolerMasterUpdateQueue(IDeviceUpdateTrigger updateTrigger, CoolerMasterDevicesIndexes deviceIndex)
|
||||
: base(updateTrigger)
|
||||
{
|
||||
this._deviceIndex = deviceIndex;
|
||||
|
||||
_deviceMatrix = new _CoolerMasterColorMatrix { KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS] };
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
{
|
||||
(int row, int column) = ((int, int))key;
|
||||
_deviceMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(color.GetR(), color.GetG(), color.GetB());
|
||||
}
|
||||
|
||||
_CoolerMasterSDK.SetAllLedColor(_deviceMatrix, _deviceIndex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
_deviceMatrix = new _CoolerMasterColorMatrix { KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS] };
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
{
|
||||
(int row, int column) = ((int, int))key;
|
||||
_deviceMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(color.GetR(), color.GetG(), color.GetB());
|
||||
}
|
||||
|
||||
_CoolerMasterSDK.SetAllLedColor(_deviceMatrix, _deviceIndex);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a CoolerMaster RGB-device.
|
||||
/// </summary>
|
||||
public interface ICoolerMasterRGBDevice : IRGBDevice
|
||||
{ }
|
||||
}
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a CoolerMaster RGB-device.
|
||||
/// </summary>
|
||||
public interface ICoolerMasterRGBDevice : IRGBDevice
|
||||
{ }
|
||||
@@ -3,42 +3,41 @@ using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster.Helper
|
||||
namespace RGB.NET.Devices.CoolerMaster.Helper;
|
||||
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for enum related things.
|
||||
/// </summary>
|
||||
internal static class EnumExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for enum related things.
|
||||
/// Gets the value of the <see cref="DescriptionAttribute"/>.
|
||||
/// </summary>
|
||||
internal static class EnumExtension
|
||||
/// <param name="source">The enum value to get the description from.</param>
|
||||
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="Enum.ToString()" /> result of the source.</returns>
|
||||
internal static string GetDescription(this Enum source)
|
||||
=> source.GetAttribute<DescriptionAttribute>()?.Description ?? source.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the <see cref="DeviceTypeAttribute"/>.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the description from.</param>
|
||||
/// <returns>The value of the <see cref="DeviceTypeAttribute"/> or the <see cref="Enum.ToString()" /> result of the source.</returns>
|
||||
internal static RGBDeviceType GetDeviceType(this Enum source)
|
||||
=> source.GetAttribute<DeviceTypeAttribute>()?.DeviceType ?? RGBDeviceType.Unknown;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attribute of type T.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the attribute from</param>
|
||||
/// <typeparam name="T">The generic attribute type</typeparam>
|
||||
/// <returns>The <see cref="Attribute"/>.</returns>
|
||||
private static T? GetAttribute<T>(this Enum source)
|
||||
where T : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the value of the <see cref="DescriptionAttribute"/>.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the description from.</param>
|
||||
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="Enum.ToString()" /> result of the source.</returns>
|
||||
internal static string GetDescription(this Enum source)
|
||||
=> source.GetAttribute<DescriptionAttribute>()?.Description ?? source.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the <see cref="DeviceTypeAttribute"/>.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the description from.</param>
|
||||
/// <returns>The value of the <see cref="DeviceTypeAttribute"/> or the <see cref="Enum.ToString()" /> result of the source.</returns>
|
||||
internal static RGBDeviceType GetDeviceType(this Enum source)
|
||||
=> source.GetAttribute<DeviceTypeAttribute>()?.DeviceType ?? RGBDeviceType.Unknown;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attribute of type T.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the attribute from</param>
|
||||
/// <typeparam name="T">The generic attribute type</typeparam>
|
||||
/// <returns>The <see cref="Attribute"/>.</returns>
|
||||
private static T? GetAttribute<T>(this Enum source)
|
||||
where T : Attribute
|
||||
{
|
||||
FieldInfo? fi = source.GetType().GetField(source.ToString());
|
||||
if (fi == null) return null;
|
||||
T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false);
|
||||
return attributes.Length > 0 ? attributes[0] : null;
|
||||
}
|
||||
FieldInfo? fi = source.GetType().GetField(source.ToString());
|
||||
if (fi == null) return null;
|
||||
T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false);
|
||||
return attributes.Length > 0 ? attributes[0] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,52 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <inheritdoc cref="CoolerMasterRGBDevice{TDeviceInfo}" />
|
||||
/// <summary>
|
||||
/// Represents a CoolerMaster keyboard.
|
||||
/// </summary>
|
||||
public class CoolerMasterKeyboardRGBDevice : CoolerMasterRGBDevice<CoolerMasterKeyboardRGBDeviceInfo>, IKeyboard
|
||||
{
|
||||
/// <inheritdoc cref="CoolerMasterRGBDevice{TDeviceInfo}" />
|
||||
#region Properties & Fields
|
||||
|
||||
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a CoolerMaster keyboard.
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" /> class.
|
||||
/// </summary>
|
||||
public class CoolerMasterKeyboardRGBDevice : CoolerMasterRGBDevice<CoolerMasterKeyboardRGBDeviceInfo>, IKeyboard
|
||||
/// <param name="info">The specific information provided by CoolerMaster for the keyboard</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal CoolerMasterKeyboardRGBDevice(CoolerMasterKeyboardRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CoolerMaster for the keyboard</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal CoolerMasterKeyboardRGBDevice(CoolerMasterKeyboardRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
InitializeLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void InitializeLayout()
|
||||
{
|
||||
if (!CoolerMasterKeyboardLedMappings.Mapping.TryGetValue(DeviceInfo.DeviceIndex, out Dictionary<CoolerMasterPhysicalKeyboardLayout, Dictionary<LedId, (int row, int column)>>? deviceMappings))
|
||||
throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex}");
|
||||
if (!deviceMappings.TryGetValue(DeviceInfo.PhysicalLayout, out Dictionary<LedId, (int row, int column)>? mapping))
|
||||
throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex} with physical layout {DeviceInfo.PhysicalLayout}");
|
||||
|
||||
foreach ((LedId ledId, (int row, int column)) in mapping)
|
||||
AddLed(ledId, new Point(column * 19, row * 19), new Size(19, 19));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override object GetLedCustomData(LedId ledId) => CoolerMasterKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout][ledId];
|
||||
|
||||
#endregion
|
||||
InitializeLayout();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void InitializeLayout()
|
||||
{
|
||||
if (!CoolerMasterKeyboardLedMappings.Mapping.TryGetValue(DeviceInfo.DeviceIndex, out Dictionary<CoolerMasterPhysicalKeyboardLayout, Dictionary<LedId, (int row, int column)>>? deviceMappings))
|
||||
throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex}");
|
||||
if (!deviceMappings.TryGetValue(DeviceInfo.PhysicalLayout, out Dictionary<LedId, (int row, int column)>? mapping))
|
||||
throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex} with physical layout {DeviceInfo.PhysicalLayout}");
|
||||
|
||||
foreach ((LedId ledId, (int row, int column)) in mapping)
|
||||
AddLed(ledId, new Point(column * 19, row * 19), new Size(19, 19));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override object GetLedCustomData(LedId ledId) => CoolerMasterKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout][ledId];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,46 +1,45 @@
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.
|
||||
/// </summary>
|
||||
public class CoolerMasterKeyboardRGBDeviceInfo : CoolerMasterRGBDeviceInfo, IKeyboardDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public KeyboardLayoutType Layout { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.
|
||||
/// Gets the <see cref="CoolerMasterPhysicalKeyboardLayout"/> of the <see cref="CoolerMasterKeyboardRGBDevice"/>.
|
||||
/// </summary>
|
||||
public class CoolerMasterKeyboardRGBDeviceInfo : CoolerMasterRGBDeviceInfo, IKeyboardDeviceInfo
|
||||
public CoolerMasterPhysicalKeyboardLayout PhysicalLayout { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDeviceInfo" />.
|
||||
/// </summary>
|
||||
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.</param>
|
||||
/// <param name="physicalKeyboardLayout">The <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterPhysicalKeyboardLayout" /> of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.</param>
|
||||
internal CoolerMasterKeyboardRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex, CoolerMasterPhysicalKeyboardLayout physicalKeyboardLayout)
|
||||
: base(RGBDeviceType.Keyboard, deviceIndex)
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public KeyboardLayoutType Layout { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CoolerMasterPhysicalKeyboardLayout"/> of the <see cref="CoolerMasterKeyboardRGBDevice"/>.
|
||||
/// </summary>
|
||||
public CoolerMasterPhysicalKeyboardLayout PhysicalLayout { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDeviceInfo" />.
|
||||
/// </summary>
|
||||
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.</param>
|
||||
/// <param name="physicalKeyboardLayout">The <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterPhysicalKeyboardLayout" /> of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.</param>
|
||||
internal CoolerMasterKeyboardRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex, CoolerMasterPhysicalKeyboardLayout physicalKeyboardLayout)
|
||||
: base(RGBDeviceType.Keyboard, deviceIndex)
|
||||
this.PhysicalLayout = physicalKeyboardLayout;
|
||||
this.Layout = physicalKeyboardLayout switch
|
||||
{
|
||||
this.PhysicalLayout = physicalKeyboardLayout;
|
||||
this.Layout = physicalKeyboardLayout switch
|
||||
{
|
||||
CoolerMasterPhysicalKeyboardLayout.UNINIT => KeyboardLayoutType.Unknown,
|
||||
CoolerMasterPhysicalKeyboardLayout.US => KeyboardLayoutType.ANSI,
|
||||
CoolerMasterPhysicalKeyboardLayout.EU => KeyboardLayoutType.ISO,
|
||||
CoolerMasterPhysicalKeyboardLayout.JP => KeyboardLayoutType.JIS,
|
||||
_ => KeyboardLayoutType.Unknown
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
CoolerMasterPhysicalKeyboardLayout.UNINIT => KeyboardLayoutType.Unknown,
|
||||
CoolerMasterPhysicalKeyboardLayout.US => KeyboardLayoutType.ANSI,
|
||||
CoolerMasterPhysicalKeyboardLayout.EU => KeyboardLayoutType.ISO,
|
||||
CoolerMasterPhysicalKeyboardLayout.JP => KeyboardLayoutType.JIS,
|
||||
_ => KeyboardLayoutType.Unknown
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,70 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <summary>
|
||||
/// Contains all the hardware-id mappings for CoolerMaster devices.
|
||||
/// </summary>
|
||||
internal static class CoolerMasterMouseLedMappings
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Contains all the hardware-id mappings for CoolerMaster devices.
|
||||
/// </summary>
|
||||
internal static class CoolerMasterMouseLedMappings
|
||||
{
|
||||
#region Properties & Fields
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static readonly Dictionary<CoolerMasterDevicesIndexes, Dictionary<LedId, (int row, int column)>> Mapping =
|
||||
new()
|
||||
{
|
||||
{ CoolerMasterDevicesIndexes.MasterMouse_L, new Dictionary<LedId, (int row, int column)>
|
||||
{
|
||||
{ LedId.Mouse1, (0,0) },
|
||||
{ LedId.Mouse2, (0,1) },
|
||||
{ LedId.Mouse3, (0,2) },
|
||||
{ LedId.Mouse4, (0,3) }
|
||||
}
|
||||
},
|
||||
|
||||
/// <summary>
|
||||
/// Contains all the hardware-id mappings for CoolerMaster devices.
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public static readonly Dictionary<CoolerMasterDevicesIndexes, Dictionary<LedId, (int row, int column)>> Mapping =
|
||||
new()
|
||||
{
|
||||
{ CoolerMasterDevicesIndexes.MasterMouse_L, new Dictionary<LedId, (int row, int column)>
|
||||
{
|
||||
{ LedId.Mouse1, (0,0) },
|
||||
{ LedId.Mouse2, (0,1) },
|
||||
{ LedId.Mouse3, (0,2) },
|
||||
{ LedId.Mouse4, (0,3) }
|
||||
}
|
||||
},
|
||||
{ CoolerMasterDevicesIndexes.MasterMouse_S, new Dictionary<LedId, (int row, int column)>
|
||||
{
|
||||
{ LedId.Mouse1, (0,0) },
|
||||
{ LedId.Mouse2, (0,1) }
|
||||
}
|
||||
},
|
||||
|
||||
{ CoolerMasterDevicesIndexes.MasterMouse_S, new Dictionary<LedId, (int row, int column)>
|
||||
{
|
||||
{ LedId.Mouse1, (0,0) },
|
||||
{ LedId.Mouse2, (0,1) }
|
||||
}
|
||||
},
|
||||
{ CoolerMasterDevicesIndexes.MM530, new Dictionary<LedId, (int row, int column)>
|
||||
{
|
||||
{ LedId.Mouse1, (0,0) },
|
||||
{ LedId.Mouse2, (0,1) },
|
||||
{ LedId.Mouse3, (0,2) }
|
||||
}
|
||||
},
|
||||
|
||||
{ CoolerMasterDevicesIndexes.MM530, new Dictionary<LedId, (int row, int column)>
|
||||
{
|
||||
{ LedId.Mouse1, (0,0) },
|
||||
{ LedId.Mouse2, (0,1) },
|
||||
{ LedId.Mouse3, (0,2) }
|
||||
}
|
||||
},
|
||||
{ CoolerMasterDevicesIndexes.MM520, new Dictionary<LedId, (int row, int column)>
|
||||
{
|
||||
{ LedId.Mouse1, (0,0) },
|
||||
{ LedId.Mouse2, (0,1) },
|
||||
{ LedId.Mouse3, (0,2) }
|
||||
}
|
||||
},
|
||||
|
||||
{ CoolerMasterDevicesIndexes.MM520, new Dictionary<LedId, (int row, int column)>
|
||||
{
|
||||
{ LedId.Mouse1, (0,0) },
|
||||
{ LedId.Mouse2, (0,1) },
|
||||
{ LedId.Mouse3, (0,2) }
|
||||
}
|
||||
},
|
||||
{ CoolerMasterDevicesIndexes.MM830, new Dictionary<LedId, (int row, int column)>
|
||||
{
|
||||
{ LedId.Mouse1, (0,0) },
|
||||
{ LedId.Mouse2, (0,1) },
|
||||
{ LedId.Mouse3, (0,2) },
|
||||
{ LedId.Mouse4, (0,3) },
|
||||
{ LedId.Mouse5, (0,4) },
|
||||
{ LedId.Mouse6, (0,5) },
|
||||
{ LedId.Mouse7, (0,6) },
|
||||
{ LedId.Mouse8, (0,7) },
|
||||
{ LedId.Mouse9, (0,8) },
|
||||
{ LedId.Mouse10, (0,9) },
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
{ CoolerMasterDevicesIndexes.MM830, new Dictionary<LedId, (int row, int column)>
|
||||
{
|
||||
{ LedId.Mouse1, (0,0) },
|
||||
{ LedId.Mouse2, (0,1) },
|
||||
{ LedId.Mouse3, (0,2) },
|
||||
{ LedId.Mouse4, (0,3) },
|
||||
{ LedId.Mouse5, (0,4) },
|
||||
{ LedId.Mouse6, (0,5) },
|
||||
{ LedId.Mouse7, (0,6) },
|
||||
{ LedId.Mouse8, (0,7) },
|
||||
{ LedId.Mouse9, (0,8) },
|
||||
{ LedId.Mouse10, (0,9) },
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,43 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <inheritdoc cref="CoolerMasterRGBDevice{TDeviceInfo}" />
|
||||
/// <summary>
|
||||
/// Represents a CoolerMaster mouse.
|
||||
/// </summary>
|
||||
public class CoolerMasterMouseRGBDevice : CoolerMasterRGBDevice<CoolerMasterMouseRGBDeviceInfo>, IMouse
|
||||
{
|
||||
/// <inheritdoc cref="CoolerMasterRGBDevice{TDeviceInfo}" />
|
||||
/// <summary>
|
||||
/// Represents a CoolerMaster mouse.
|
||||
/// </summary>
|
||||
public class CoolerMasterMouseRGBDevice : CoolerMasterRGBDevice<CoolerMasterMouseRGBDeviceInfo>, IMouse
|
||||
{
|
||||
#region Constructors
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CoolerMaster for the mouse</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal CoolerMasterMouseRGBDevice(CoolerMasterMouseRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
InitializeLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void InitializeLayout()
|
||||
{
|
||||
Dictionary<LedId, (int row, int column)> mapping = CoolerMasterMouseLedMappings.Mapping[DeviceInfo.DeviceIndex];
|
||||
|
||||
foreach (KeyValuePair<LedId, (int row, int column)> led in mapping)
|
||||
AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override object GetLedCustomData(LedId ledId) => CoolerMasterMouseLedMappings.Mapping[DeviceInfo.DeviceIndex][ledId];
|
||||
|
||||
#endregion
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by CoolerMaster for the mouse</param>
|
||||
/// <param name="updateTrigger">The update trigger used to update this device.</param>
|
||||
internal CoolerMasterMouseRGBDevice(CoolerMasterMouseRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger)
|
||||
: base(info, updateTrigger)
|
||||
{
|
||||
InitializeLayout();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void InitializeLayout()
|
||||
{
|
||||
Dictionary<LedId, (int row, int column)> mapping = CoolerMasterMouseLedMappings.Mapping[DeviceInfo.DeviceIndex];
|
||||
|
||||
foreach (KeyValuePair<LedId, (int row, int column)> led in mapping)
|
||||
AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override object GetLedCustomData(LedId ledId) => CoolerMasterMouseLedMappings.Mapping[DeviceInfo.DeviceIndex][ledId];
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,24 +1,23 @@
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster
|
||||
namespace RGB.NET.Devices.CoolerMaster;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDevice" />.
|
||||
/// </summary>
|
||||
public class CoolerMasterMouseRGBDeviceInfo : CoolerMasterRGBDeviceInfo
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDevice" />.
|
||||
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDeviceInfo" />.
|
||||
/// </summary>
|
||||
public class CoolerMasterMouseRGBDeviceInfo : CoolerMasterRGBDeviceInfo
|
||||
{
|
||||
#region Constructors
|
||||
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDevice" />.</param>
|
||||
internal CoolerMasterMouseRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex)
|
||||
: base(RGBDeviceType.Mouse, deviceIndex)
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDeviceInfo" />.
|
||||
/// </summary>
|
||||
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDevice" />.</param>
|
||||
internal CoolerMasterMouseRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex)
|
||||
: base(RGBDeviceType.Mouse, deviceIndex)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,26 +1,25 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster.Native
|
||||
namespace RGB.NET.Devices.CoolerMaster.Native;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
internal struct _CoolerMasterColorMatrix
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
internal struct _CoolerMasterColorMatrix
|
||||
{
|
||||
#region Constants
|
||||
#region Constants
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
internal const int ROWS = 8;
|
||||
internal const int COLUMNS = 24;
|
||||
internal const int ROWS = 8;
|
||||
internal const int COLUMNS = 24;
|
||||
|
||||
// ReSharper restore MemberCanBePrivate.Global
|
||||
// ReSharper restore MemberCanBePrivate.Global
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
#region Properties & Fields
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ROWS * COLUMNS)]
|
||||
public _CoolerMasterKeyColor[,] KeyColor;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ROWS * COLUMNS)]
|
||||
public _CoolerMasterKeyColor[,] KeyColor;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -3,28 +3,27 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable NotAccessedField.Global
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster.Native
|
||||
namespace RGB.NET.Devices.CoolerMaster.Native;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
internal struct _CoolerMasterKeyColor
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
internal struct _CoolerMasterKeyColor
|
||||
#region Properties & Fields
|
||||
|
||||
public byte R;
|
||||
public byte G;
|
||||
public byte B;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal _CoolerMasterKeyColor(byte r, byte g, byte b)
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public byte R;
|
||||
public byte G;
|
||||
public byte B;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal _CoolerMasterKeyColor(byte r, byte g, byte b)
|
||||
{
|
||||
this.R = r;
|
||||
this.G = g;
|
||||
this.B = b;
|
||||
}
|
||||
|
||||
#endregion
|
||||
this.R = r;
|
||||
this.G = g;
|
||||
this.B = b;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -9,158 +9,157 @@ using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.CoolerMaster.Native
|
||||
namespace RGB.NET.Devices.CoolerMaster.Native;
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
internal static class _CoolerMasterSDK
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
internal static class _CoolerMasterSDK
|
||||
#region Libary Management
|
||||
|
||||
private static IntPtr _dllHandle = IntPtr.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Reloads the SDK.
|
||||
/// </summary>
|
||||
internal static void Reload()
|
||||
{
|
||||
#region Libary Management
|
||||
|
||||
private static IntPtr _dllHandle = IntPtr.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Reloads the SDK.
|
||||
/// </summary>
|
||||
internal static void Reload()
|
||||
if (_dllHandle != IntPtr.Zero)
|
||||
{
|
||||
if (_dllHandle != IntPtr.Zero)
|
||||
{
|
||||
foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
|
||||
EnableLedControl(false, index);
|
||||
}
|
||||
else
|
||||
LoadCMSDK();
|
||||
foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
|
||||
EnableLedControl(false, index);
|
||||
}
|
||||
|
||||
private static void LoadCMSDK()
|
||||
{
|
||||
if (_dllHandle != IntPtr.Zero) return;
|
||||
|
||||
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
|
||||
List<string> possiblePathList = Environment.Is64BitProcess ? CoolerMasterDeviceProvider.PossibleX64NativePaths : CoolerMasterDeviceProvider.PossibleX86NativePaths;
|
||||
string? dllPath = possiblePathList.FirstOrDefault(File.Exists);
|
||||
if (dllPath == null) throw new RGBDeviceException($"Can't find the CoolerMaster-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
|
||||
|
||||
_dllHandle = LoadLibrary(dllPath);
|
||||
if (_dllHandle == IntPtr.Zero) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastWin32Error()}");
|
||||
|
||||
_getSDKVersionPointer = (GetSDKVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "GetCM_SDK_DllVer"), typeof(GetSDKVersionPointer));
|
||||
_setControlDevicenPointer = (SetControlDevicePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetControlDevice"), typeof(SetControlDevicePointer));
|
||||
_isDevicePlugPointer = (IsDevicePlugPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "IsDevicePlug"), typeof(IsDevicePlugPointer));
|
||||
_getDeviceLayoutPointer = (GetDeviceLayoutPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "GetDeviceLayout"), typeof(GetDeviceLayoutPointer));
|
||||
_enableLedControlPointer = (EnableLedControlPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "EnableLedControl"), typeof(EnableLedControlPointer));
|
||||
_refreshLedPointer = (RefreshLedPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "RefreshLed"), typeof(RefreshLedPointer));
|
||||
_setLedColorPointer = (SetLedColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetLedColor"), typeof(SetLedColorPointer));
|
||||
_setAllLedColorPointer = (SetAllLedColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetAllLedColor"), typeof(SetAllLedColorPointer));
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern IntPtr LoadLibrary(string dllToLoad);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
|
||||
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
|
||||
|
||||
#endregion
|
||||
|
||||
#region SDK-METHODS
|
||||
|
||||
#region Pointers
|
||||
|
||||
private static GetSDKVersionPointer? _getSDKVersionPointer;
|
||||
private static SetControlDevicePointer? _setControlDevicenPointer;
|
||||
private static IsDevicePlugPointer? _isDevicePlugPointer;
|
||||
private static GetDeviceLayoutPointer? _getDeviceLayoutPointer;
|
||||
private static EnableLedControlPointer? _enableLedControlPointer;
|
||||
private static RefreshLedPointer? _refreshLedPointer;
|
||||
private static SetLedColorPointer? _setLedColorPointer;
|
||||
private static SetAllLedColorPointer? _setAllLedColorPointer;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delegates
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate int GetSDKVersionPointer();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate void SetControlDevicePointer(CoolerMasterDevicesIndexes devicesIndexes);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool IsDevicePlugPointer(CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate CoolerMasterPhysicalKeyboardLayout GetDeviceLayoutPointer(CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool EnableLedControlPointer(bool value, CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool RefreshLedPointer(bool autoRefresh, CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool SetLedColorPointer(int row, int column, byte r, byte g, byte b, CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool SetAllLedColorPointer(_CoolerMasterColorMatrix colorMatrix, CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
#endregion
|
||||
|
||||
// ReSharper disable EventExceptionNotDocumented
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: Get SDK Dll's Version.
|
||||
/// </summary>
|
||||
internal static int GetSDKVersion() => (_getSDKVersionPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke();
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: set operating device
|
||||
/// </summary>
|
||||
internal static void SetControlDevice(CoolerMasterDevicesIndexes devicesIndexes)
|
||||
=> (_setControlDevicenPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(devicesIndexes);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: verify if the deviced is plugged in
|
||||
/// </summary>
|
||||
internal static bool IsDevicePlugged(CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_isDevicePlugPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(devIndex);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: Obtain current device layout
|
||||
/// </summary>
|
||||
internal static CoolerMasterPhysicalKeyboardLayout GetDeviceLayout(CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_getDeviceLayoutPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(devIndex);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: set control over device’s LED
|
||||
/// </summary>
|
||||
internal static bool EnableLedControl(bool value, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_enableLedControlPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(value, devIndex);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: Print out the lights setting from Buffer to LED
|
||||
/// </summary>
|
||||
internal static bool RefreshLed(bool autoRefresh, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_refreshLedPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(autoRefresh, devIndex);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: Set single Key LED color
|
||||
/// </summary>
|
||||
internal static bool SetLedColor(int row, int column, byte r, byte g, byte b, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_setLedColorPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(row, column, r, g, b, devIndex);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: Set Keyboard "every LED" color
|
||||
/// </summary>
|
||||
internal static bool SetAllLedColor(_CoolerMasterColorMatrix colorMatrix, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_setAllLedColorPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(colorMatrix, devIndex);
|
||||
|
||||
// ReSharper restore EventExceptionNotDocumented
|
||||
|
||||
#endregion
|
||||
else
|
||||
LoadCMSDK();
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadCMSDK()
|
||||
{
|
||||
if (_dllHandle != IntPtr.Zero) return;
|
||||
|
||||
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
|
||||
List<string> possiblePathList = Environment.Is64BitProcess ? CoolerMasterDeviceProvider.PossibleX64NativePaths : CoolerMasterDeviceProvider.PossibleX86NativePaths;
|
||||
string? dllPath = possiblePathList.FirstOrDefault(File.Exists);
|
||||
if (dllPath == null) throw new RGBDeviceException($"Can't find the CoolerMaster-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
|
||||
|
||||
_dllHandle = LoadLibrary(dllPath);
|
||||
if (_dllHandle == IntPtr.Zero) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastWin32Error()}");
|
||||
|
||||
_getSDKVersionPointer = (GetSDKVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "GetCM_SDK_DllVer"), typeof(GetSDKVersionPointer));
|
||||
_setControlDevicenPointer = (SetControlDevicePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetControlDevice"), typeof(SetControlDevicePointer));
|
||||
_isDevicePlugPointer = (IsDevicePlugPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "IsDevicePlug"), typeof(IsDevicePlugPointer));
|
||||
_getDeviceLayoutPointer = (GetDeviceLayoutPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "GetDeviceLayout"), typeof(GetDeviceLayoutPointer));
|
||||
_enableLedControlPointer = (EnableLedControlPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "EnableLedControl"), typeof(EnableLedControlPointer));
|
||||
_refreshLedPointer = (RefreshLedPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "RefreshLed"), typeof(RefreshLedPointer));
|
||||
_setLedColorPointer = (SetLedColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetLedColor"), typeof(SetLedColorPointer));
|
||||
_setAllLedColorPointer = (SetAllLedColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetAllLedColor"), typeof(SetAllLedColorPointer));
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
private static extern IntPtr LoadLibrary(string dllToLoad);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
|
||||
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
|
||||
|
||||
#endregion
|
||||
|
||||
#region SDK-METHODS
|
||||
|
||||
#region Pointers
|
||||
|
||||
private static GetSDKVersionPointer? _getSDKVersionPointer;
|
||||
private static SetControlDevicePointer? _setControlDevicenPointer;
|
||||
private static IsDevicePlugPointer? _isDevicePlugPointer;
|
||||
private static GetDeviceLayoutPointer? _getDeviceLayoutPointer;
|
||||
private static EnableLedControlPointer? _enableLedControlPointer;
|
||||
private static RefreshLedPointer? _refreshLedPointer;
|
||||
private static SetLedColorPointer? _setLedColorPointer;
|
||||
private static SetAllLedColorPointer? _setAllLedColorPointer;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delegates
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate int GetSDKVersionPointer();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate void SetControlDevicePointer(CoolerMasterDevicesIndexes devicesIndexes);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool IsDevicePlugPointer(CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate CoolerMasterPhysicalKeyboardLayout GetDeviceLayoutPointer(CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool EnableLedControlPointer(bool value, CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool RefreshLedPointer(bool autoRefresh, CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool SetLedColorPointer(int row, int column, byte r, byte g, byte b, CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
private delegate bool SetAllLedColorPointer(_CoolerMasterColorMatrix colorMatrix, CoolerMasterDevicesIndexes devIndex);
|
||||
|
||||
#endregion
|
||||
|
||||
// ReSharper disable EventExceptionNotDocumented
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: Get SDK Dll's Version.
|
||||
/// </summary>
|
||||
internal static int GetSDKVersion() => (_getSDKVersionPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke();
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: set operating device
|
||||
/// </summary>
|
||||
internal static void SetControlDevice(CoolerMasterDevicesIndexes devicesIndexes)
|
||||
=> (_setControlDevicenPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(devicesIndexes);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: verify if the deviced is plugged in
|
||||
/// </summary>
|
||||
internal static bool IsDevicePlugged(CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_isDevicePlugPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(devIndex);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: Obtain current device layout
|
||||
/// </summary>
|
||||
internal static CoolerMasterPhysicalKeyboardLayout GetDeviceLayout(CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_getDeviceLayoutPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(devIndex);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: set control over device’s LED
|
||||
/// </summary>
|
||||
internal static bool EnableLedControl(bool value, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_enableLedControlPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(value, devIndex);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: Print out the lights setting from Buffer to LED
|
||||
/// </summary>
|
||||
internal static bool RefreshLed(bool autoRefresh, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_refreshLedPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(autoRefresh, devIndex);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: Set single Key LED color
|
||||
/// </summary>
|
||||
internal static bool SetLedColor(int row, int column, byte r, byte g, byte b, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_setLedColorPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(row, column, r, g, b, devIndex);
|
||||
|
||||
/// <summary>
|
||||
/// CM-SDK: Set Keyboard "every LED" color
|
||||
/// </summary>
|
||||
internal static bool SetAllLedColor(_CoolerMasterColorMatrix colorMatrix, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
|
||||
=> (_setAllLedColorPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(colorMatrix, devIndex);
|
||||
|
||||
// ReSharper restore EventExceptionNotDocumented
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user