1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Razer - Moved to HID-based device detection

Razer - Added all OpenRazer provided PIDs
Razer - Use device-specific SDK endpoints, allowing access to all Razer devices
This commit is contained in:
Robert 2021-02-27 12:00:12 +01:00
parent 0e30c93db4
commit 587ae8f6e2
26 changed files with 313 additions and 280 deletions

View File

@ -6,11 +6,11 @@ using RGB.NET.Devices.Razer.Native;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc cref="RazerRGBDevice{TDeviceInfo}" />
/// <inheritdoc cref="RazerRGBDevice" />
/// <summary>
/// Represents a razer chroma link.
/// </summary>
public class RazerChromaLinkRGBDevice : RazerRGBDevice<RazerChromaLinkRGBDeviceInfo>, ILedStripe
public class RazerChromaLinkRGBDevice : RazerRGBDevice, IUnknownDevice
{
#region Constructors
@ -19,7 +19,7 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerChromaLinkRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the chroma link.</param>
internal RazerChromaLinkRGBDevice(RazerChromaLinkRGBDeviceInfo info)
internal RazerChromaLinkRGBDevice(RazerRGBDeviceInfo info)
: base(info)
{ }
@ -38,7 +38,7 @@ namespace RGB.NET.Devices.Razer
protected override object? GetLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Custom1;
/// <inheritdoc />
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerChromaLinkUpdateQueue(updateTrigger, DeviceInfo.DeviceId);
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerChromaLinkUpdateQueue(updateTrigger);
#endregion
}

View File

@ -1,26 +0,0 @@
using System;
using RGB.NET.Core;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerChromaLinkRGBDevice" />.
/// </summary>
public class RazerChromaLinkRGBDeviceInfo : RazerRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerChromaLinkRGBDeviceInfo" />.
/// </summary>
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
internal RazerChromaLinkRGBDeviceInfo(Guid deviceId, string model)
: base(deviceId, RGBDeviceType.LedStripe, model)
{ }
#endregion
}
}

View File

@ -17,9 +17,8 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="RazerChromaLinkUpdateQueue" /> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used to update this queue.</param>
/// <param name="deviceId">The id of the device updated by this queue.</param>
public RazerChromaLinkUpdateQueue(IDeviceUpdateTrigger updateTrigger, Guid deviceId)
: base(updateTrigger, deviceId)
public RazerChromaLinkUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{ }
#endregion

View File

@ -4,13 +4,12 @@ using RGB.NET.Core;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
/// <inheritdoc cref="AbstractRGBDevice{RazerRGBDeviceInfo}" />
/// <inheritdoc cref="IRazerRGBDevice" />
/// <summary>
/// Represents a generic razer-device. (keyboard, mouse, headset, mousepad).
/// </summary>
public abstract class RazerRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, IRazerRGBDevice
where TDeviceInfo : RazerRGBDeviceInfo
public abstract class RazerRGBDevice : AbstractRGBDevice<RazerRGBDeviceInfo>, IRazerRGBDevice
{
#region Properties & Fields
@ -18,7 +17,7 @@ namespace RGB.NET.Devices.Razer
/// <summary>
/// Gets information about the <see cref="T:RGB.NET.Devices.Razer.RazerRGBDevice" />.
/// </summary>
public override TDeviceInfo DeviceInfo { get; }
public override RazerRGBDeviceInfo DeviceInfo { get; }
/// <summary>
/// Gets or sets the update queue performing updates for this device.
@ -31,10 +30,10 @@ namespace RGB.NET.Devices.Razer
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RazerRGBDevice{TDeviceInfo}"/> class.
/// Initializes a new instance of the <see cref="RazerRGBDevice"/> class.
/// </summary>
/// <param name="info">The generic information provided by razer for the device.</param>
protected RazerRGBDevice(TDeviceInfo info)
protected RazerRGBDevice(RazerRGBDeviceInfo info)
{
this.DeviceInfo = info;

View File

@ -11,11 +11,6 @@ namespace RGB.NET.Devices.Razer
{
#region Properties & Fields
/// <summary>
/// Gets the Id of the <see cref="RazerRGBDevice{TDeviceInfo}"/>.
/// </summary>
public Guid DeviceId { get; }
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
@ -38,12 +33,10 @@ namespace RGB.NET.Devices.Razer
/// <summary>
/// Internal constructor of managed <see cref="RazerRGBDeviceInfo"/>.
/// </summary>
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
internal RazerRGBDeviceInfo(Guid deviceId, RGBDeviceType deviceType, string model)
internal RazerRGBDeviceInfo(RGBDeviceType deviceType, string model)
{
this.DeviceId = deviceId;
this.DeviceType = deviceType;
this.Model = model;

View File

@ -11,8 +11,7 @@ namespace RGB.NET.Devices.Razer
public abstract class RazerUpdateQueue : UpdateQueue
{
#region Properties & Fields
private readonly Guid _deviceId;
private Guid? _lastEffect;
#endregion
@ -23,11 +22,9 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="RazerUpdateQueue" /> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used to update this queue.</param>
/// <param name="deviceId">The id of the device updated by this queue.</param>
protected RazerUpdateQueue(IDeviceUpdateTrigger updateTrigger, Guid deviceId)
protected RazerUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{
this._deviceId = deviceId;
}
#endregion
@ -54,7 +51,7 @@ namespace RGB.NET.Devices.Razer
/// </summary>
/// <param name="effectParams">The parameters of the effect.</param>
/// <param name="effectId">The id this effect is created with.</param>
protected virtual void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateEffect(_deviceId, _Defines.EFFECT_ID, effectParams, ref effectId);
protected abstract void CreateEffect(IntPtr effectParams, ref Guid effectId);
/// <inheritdoc />
public override void Reset()

View File

@ -0,0 +1,184 @@
using System.Collections.Generic;
using System.Linq;
using HidSharp;
using RGB.NET.Core;
using DeviceDataList = System.Collections.Generic.List<(string model, RGB.NET.Core.RGBDeviceType deviceType, int id)>;
namespace RGB.NET.Devices.Razer.HID
{
internal static class DeviceChecker
{
#region Constants
private const int VENDOR_ID = 0x1532;
private static readonly DeviceDataList DEVICES
= new()
{
// Keyboards
("BlackWidow Ultimate 2012", RGBDeviceType.Keyboard, 0x010D),
("BlackWidow Classic (Alternate)", RGBDeviceType.Keyboard, 0x010E),
("Anansi", RGBDeviceType.Keyboard, 0x010F),
("BlackWidow Ultimate 2013", RGBDeviceType.Keyboard, 0x011A),
("BlackWidow Stealth", RGBDeviceType.Keyboard, 0x011B),
("DeathStalker Expert", RGBDeviceType.Keyboard, 0x0202),
("BlackWidow Chroma", RGBDeviceType.Keyboard, 0x0203),
("DeathStalker Chroma", RGBDeviceType.Keyboard, 0x0204),
("Blade Stealth", RGBDeviceType.Keyboard, 0x0205),
("BlackWidow Tournament Edition Chroma", RGBDeviceType.Keyboard, 0x0209),
("Blade QHD", RGBDeviceType.Keyboard, 0x020F),
("Blade Pro (Late 2016)", RGBDeviceType.Keyboard, 0x0210),
("BlackWidow Chroma (Overwatch)", RGBDeviceType.Keyboard, 0x0211),
("BlackWidow Ultimate 2016", RGBDeviceType.Keyboard, 0x0214),
("BlackWidow X Chroma", RGBDeviceType.Keyboard, 0x0216),
("BlackWidow X Ultimate", RGBDeviceType.Keyboard, 0x0217),
("BlackWidow X Tournament Edition Chroma", RGBDeviceType.Keyboard, 0x021A),
("Ornata Chroma", RGBDeviceType.Keyboard, 0x021E),
("Ornata", RGBDeviceType.Keyboard, 0x021F),
("Blade Stealth (Late 2016)", RGBDeviceType.Keyboard, 0x0220),
("BlackWidow Chroma V2", RGBDeviceType.Keyboard, 0x0221),
("Blade (Late 2016)", RGBDeviceType.Keyboard, 0x0224),
("Blade Pro (2017)", RGBDeviceType.Keyboard, 0x0225),
("Huntsman Elite", RGBDeviceType.Keyboard, 0x0226),
("Huntsman", RGBDeviceType.Keyboard, 0x0227),
("BlackWidow Elite", RGBDeviceType.Keyboard, 0x0228),
("Cynosa Chroma", RGBDeviceType.Keyboard, 0x022A),
("Blade Stealth (Mid 2017)", RGBDeviceType.Keyboard, 0x022D),
("Blade Pro FullHD (2017)", RGBDeviceType.Keyboard, 0x022F),
("Blade Stealth (Late 2017)", RGBDeviceType.Keyboard, 0x0232),
("Blade 15 (2018)", RGBDeviceType.Keyboard, 0x0233),
("Blade Pro 17 (2019)", RGBDeviceType.Keyboard, 0x0234),
("BlackWidow Lite (2018)", RGBDeviceType.Keyboard, 0x0235),
("BlackWidow Essential", RGBDeviceType.Keyboard, 0x0237),
("Blade Stealth (2019)", RGBDeviceType.Keyboard, 0x0239),
("Blade 15 (2019) Advanced", RGBDeviceType.Keyboard, 0x023A),
("Blade 15 (2018) Base Model", RGBDeviceType.Keyboard, 0x023B),
("Cynosa Lite", RGBDeviceType.Keyboard, 0x023F),
("Blade 15 (2018) Mercury", RGBDeviceType.Keyboard, 0x0240),
("BlackWidow (2019)", RGBDeviceType.Keyboard, 0x0241),
("Huntsman Tournament Edition", RGBDeviceType.Keyboard, 0x0243),
("Blade 15 (Mid 2019) Mercury", RGBDeviceType.Keyboard, 0x0245),
("Blade 15 (Mid 2019) Base", RGBDeviceType.Keyboard, 0x0246),
("Blade Stealth (Late 2019)", RGBDeviceType.Keyboard, 0x024A),
("Blade Pro (Late 2019)", RGBDeviceType.Keyboard, 0x024C),
("Blade 15 Studio Edition (2019)", RGBDeviceType.Keyboard, 0x024D),
("Blade Stealth (Early 2020)", RGBDeviceType.Keyboard, 0x0252),
("Blade 15 Advanced (2020)", RGBDeviceType.Keyboard, 0x0253),
("Blade 15 (Early 2020) Base", RGBDeviceType.Keyboard, 0x0255),
("Blade Stealth (Late 2020)", RGBDeviceType.Keyboard, 0x0259),
("Ornata Chroma V2", RGBDeviceType.Keyboard, 0x025D),
("Cynosa V2", RGBDeviceType.Keyboard, 0x025E),
// Mice
("Orochi 2011", RGBDeviceType.Mouse, 0x0013),
("DeathAdder 3.5G", RGBDeviceType.Mouse, 0x0016),
("Abyssus 1800", RGBDeviceType.Mouse, 0x0020),
("Mamba 2012 (Wired)", RGBDeviceType.Mouse, 0x0024),
("Mamba 2012 (Wireless)", RGBDeviceType.Mouse, 0x0025),
("Naga 2012", RGBDeviceType.Mouse, 0x002E),
("Imperator 2012", RGBDeviceType.Mouse, 0x002F),
("Ouroboros 2012", RGBDeviceType.Mouse, 0x0032),
("Taipan", RGBDeviceType.Mouse, 0x0034),
("Naga Hex (Red)", RGBDeviceType.Mouse, 0x0036),
("DeathAdder 2013", RGBDeviceType.Mouse, 0x0037),
("DeathAdder 1800", RGBDeviceType.Mouse, 0x0038),
("Orochi 2013", RGBDeviceType.Mouse, 0x0039),
("Naga 2014", RGBDeviceType.Mouse, 0x0040),
("Naga Hex", RGBDeviceType.Mouse, 0x0041),
("Abyssus 2014", RGBDeviceType.Mouse, 0x0042),
("DeathAdder Chroma", RGBDeviceType.Mouse, 0x0043),
("Mamba (Wired)", RGBDeviceType.Mouse, 0x0044),
("Mamba (Wireless)", RGBDeviceType.Mouse, 0x0045),
("Mamba Tournament Edition", RGBDeviceType.Mouse, 0x0046),
("Orochi (Wired)", RGBDeviceType.Mouse, 0x0048),
("Diamondback Chroma", RGBDeviceType.Mouse, 0x004C),
("DeathAdder 2000", RGBDeviceType.Mouse, 0x004F),
("Naga Hex V2", RGBDeviceType.Mouse, 0x0050),
("Naga Chroma", RGBDeviceType.Mouse, 0x0053),
("DeathAdder 3500", RGBDeviceType.Mouse, 0x0054),
("Lancehead (Wired)", RGBDeviceType.Mouse, 0x0059),
("Lancehead (Wireless)", RGBDeviceType.Mouse, 0x005A),
("Abyssus V2", RGBDeviceType.Mouse, 0x005B),
("DeathAdder Elite", RGBDeviceType.Mouse, 0x005C),
("Abyssus 2000", RGBDeviceType.Mouse, 0x005E),
("Lancehead Tournament Edition", RGBDeviceType.Mouse, 0x0060),
("Atheris (Receiver)", RGBDeviceType.Mouse, 0x0062),
("Basilisk", RGBDeviceType.Mouse, 0x0064),
("Naga Trinity", RGBDeviceType.Mouse, 0x0067),
("Abyssus Elite (D.Va Edition)", RGBDeviceType.Mouse, 0x006A),
("Abyssus Essential", RGBDeviceType.Mouse, 0x006B),
("Mamba Elite (Wired)", RGBDeviceType.Mouse, 0x006C),
("DeathAdder Essential", RGBDeviceType.Mouse, 0x006E),
("Lancehead Wireless (Receiver)", RGBDeviceType.Mouse, 0x006F),
("Lancehead Wireless (Wired)", RGBDeviceType.Mouse, 0x0070),
("DeathAdder Essential (White Edition)", RGBDeviceType.Mouse, 0x0071),
("Mamba Wireless (Receiver)", RGBDeviceType.Mouse, 0x0072),
("Mamba Wireless (Wired)", RGBDeviceType.Mouse, 0x0073),
("Viper", RGBDeviceType.Mouse, 0x0078),
("Viper Ultimate (Wired)", RGBDeviceType.Mouse, 0x007A),
("Viper Ultimate (Wireless)", RGBDeviceType.Mouse, 0x007B),
("DeathAdder V2 Pro (Wired)", RGBDeviceType.Mouse, 0x007C),
("DeathAdder V2 Pro (Wireless)", RGBDeviceType.Mouse, 0x007D),
("Basilisk X HyperSpeed", RGBDeviceType.Mouse, 0x0083),
("Basilisk Ultimate", RGBDeviceType.Mouse, 0x0088),
("DeathAdder V2", RGBDeviceType.Mouse, 0x0084),
("Viper Mini", RGBDeviceType.Mouse, 0x008A),
// Mousepads
("Firefly Hyperflux", RGBDeviceType.Mousepad, 0x0068),
("Firefly", RGBDeviceType.Mousepad, 0x0C00),
("Goliathus", RGBDeviceType.Mousepad, 0x0C01),
("Goliathus Extended", RGBDeviceType.Mousepad, 0x0C02),
("Firefly v2", RGBDeviceType.Mousepad, 0x0C04),
// Headsets
("Kraken 7.1", RGBDeviceType.Headset, 0x0501),
("Kraken 7.1 Chroma", RGBDeviceType.Headset, 0x0504),
("Kraken 7.1", RGBDeviceType.Headset, 0x0506),
("Kraken 7.1 V2", RGBDeviceType.Headset, 0x0510),
("Kraken Ultimate", RGBDeviceType.Headset, 0x0527),
("Kraken Kitty Edition", RGBDeviceType.Headset, 0x0F19),
// Keypads
("Nostromo", RGBDeviceType.Keypad, 0x0111),
("Orbweaver", RGBDeviceType.Keypad, 0x0113),
("Tartarus", RGBDeviceType.Keypad, 0x0201),
("Orbweaver Chroma", RGBDeviceType.Keypad, 0x0207),
("Tartarus Chroma", RGBDeviceType.Keypad, 0x0208),
("Tartarus V2", RGBDeviceType.Keypad, 0x022B),
("Tartarus Pro", RGBDeviceType.Keypad, 0x0244),
// Misc - unsupported through the effects API
// ("Core", RGBDeviceType.GraphicsCard, 0x0215),
// ("Base Station Chroma", RGBDeviceType.HeadsetStand, 0x0F08),
// ("Nommo Chroma", RGBDeviceType.Unknown, 0x0517),
// ("Nommo Pro", RGBDeviceType.Unknown, 0x0518),
// ("Chroma Mug Holder", RGBDeviceType.Unknown, 0x0F07),
// ("Chroma Hardware Development Kit (HDK)", RGBDeviceType.Unknown, 0x0F09),
// ("Mouse Bungee V3 Chroma", RGBDeviceType.Unknown, 0x0F1D),
// ("Base Station V2 Chroma", RGBDeviceType.Unknown, 0x0F20)
};
#endregion
#region Properties & Fields
public static DeviceDataList ConnectedDevices { get; } = new();
#endregion
#region Methods
internal static void LoadDeviceList(RGBDeviceType loadFilter)
{
ConnectedDevices.Clear();
HashSet<int> ids = new(DeviceList.Local.GetHidDevices(VENDOR_ID).Select(x => x.ProductID).Distinct());
DeviceDataList connectedDevices = DEVICES.Where(d => ids.Contains(d.id) && loadFilter.HasFlag(d.deviceType)).ToList();
ConnectedDevices.AddRange(connectedDevices);
}
#endregion
}
}

View File

@ -6,11 +6,11 @@ using RGB.NET.Devices.Razer.Native;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc cref="RazerRGBDevice{TDeviceInfo}" />
/// <inheritdoc cref="RazerRGBDevice" />
/// <summary>
/// Represents a razer headset.
/// </summary>
public class RazerHeadsetRGBDevice : RazerRGBDevice<RazerHeadsetRGBDeviceInfo>, IHeadset
public class RazerHeadsetRGBDevice : RazerRGBDevice, IHeadset
{
#region Constructors
@ -19,7 +19,7 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerHeadsetRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the headset.</param>
internal RazerHeadsetRGBDevice(RazerHeadsetRGBDeviceInfo info)
internal RazerHeadsetRGBDevice(RazerRGBDeviceInfo info)
: base(info)
{ }
@ -38,7 +38,7 @@ namespace RGB.NET.Devices.Razer
protected override object? GetLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Headset1;
/// <inheritdoc />
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerHeadsetUpdateQueue(updateTrigger, DeviceInfo.DeviceId);
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerHeadsetUpdateQueue(updateTrigger);
#endregion
}

View File

@ -1,26 +0,0 @@
using System;
using RGB.NET.Core;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerHeadsetRGBDevice" />.
/// </summary>
public class RazerHeadsetRGBDeviceInfo : RazerRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerHeadsetRGBDeviceInfo" />.
/// </summary>
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
internal RazerHeadsetRGBDeviceInfo(Guid deviceId, string model)
: base(deviceId, RGBDeviceType.Headset, model)
{ }
#endregion
}
}

View File

@ -17,9 +17,8 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="RazerHeadsetUpdateQueue" /> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used to update this queue.</param>
/// <param name="deviceId">The id of the device updated by this queue.</param>
public RazerHeadsetUpdateQueue(IDeviceUpdateTrigger updateTrigger, Guid deviceId)
: base(updateTrigger, deviceId)
public RazerHeadsetUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{ }
#endregion

View File

@ -6,15 +6,15 @@ using RGB.NET.Devices.Razer.Native;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc cref="RazerRGBDevice{TDeviceInfo}" />
/// <inheritdoc cref="RazerRGBDevice" />
/// <summary>
/// Represents a razer keyboard.
/// </summary>
public class RazerKeyboardRGBDevice : RazerRGBDevice<RazerKeyboardRGBDeviceInfo>, IKeyboard
public class RazerKeyboardRGBDevice : RazerRGBDevice, IKeyboard
{
#region Properties & Fields
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
IKeyboardDeviceInfo IKeyboard.DeviceInfo => (IKeyboardDeviceInfo) DeviceInfo;
#endregion
@ -45,7 +45,7 @@ namespace RGB.NET.Devices.Razer
protected override object? GetLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Keyboard_Escape;
/// <inheritdoc />
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerKeyboardUpdateQueue(updateTrigger, DeviceInfo.DeviceId);
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerKeyboardUpdateQueue(updateTrigger);
#endregion
}

View File

@ -1,7 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System;
using RGB.NET.Core;
namespace RGB.NET.Devices.Razer
@ -24,10 +23,9 @@ namespace RGB.NET.Devices.Razer
/// <summary>
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerKeyboardRGBDeviceInfo" />.
/// </summary>
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
internal RazerKeyboardRGBDeviceInfo(Guid deviceId, string model)
: base(deviceId, RGBDeviceType.Keyboard, model)
internal RazerKeyboardRGBDeviceInfo(string model)
: base(RGBDeviceType.Keyboard, model)
{ }
#endregion

View File

@ -17,9 +17,8 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="RazerKeyboardUpdateQueue" /> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used to update this queue.</param>
/// <param name="deviceId">The id of the device updated by this queue.</param>
public RazerKeyboardUpdateQueue(IDeviceUpdateTrigger updateTrigger, Guid deviceId)
: base(updateTrigger, deviceId)
public RazerKeyboardUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{ }
#endregion

View File

@ -6,11 +6,11 @@ using RGB.NET.Devices.Razer.Native;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc cref="RazerRGBDevice{TDeviceInfo}" />
/// <inheritdoc cref="RazerRGBDevice" />
/// <summary>
/// Represents a razer keypad.
/// </summary>
public class RazerKeypadRGBDevice : RazerRGBDevice<RazerKeypadRGBDeviceInfo>, IKeypad
public class RazerKeypadRGBDevice : RazerRGBDevice, IKeypad
{
#region Constructors
@ -19,7 +19,7 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerKeypadRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the keypad.</param>
internal RazerKeypadRGBDevice(RazerKeypadRGBDeviceInfo info)
internal RazerKeypadRGBDevice(RazerRGBDeviceInfo info)
: base(info)
{ }
@ -39,7 +39,7 @@ namespace RGB.NET.Devices.Razer
protected override object? GetLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Keypad1;
/// <inheritdoc />
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerKeypadUpdateQueue(updateTrigger, DeviceInfo.DeviceId);
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerKeypadUpdateQueue(updateTrigger);
#endregion
}

View File

@ -1,26 +0,0 @@
using System;
using RGB.NET.Core;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerKeypadRGBDevice" />.
/// </summary>
public class RazerKeypadRGBDeviceInfo : RazerRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerKeypadRGBDeviceInfo" />.
/// </summary>
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
internal RazerKeypadRGBDeviceInfo(Guid deviceId, string model)
: base(deviceId, RGBDeviceType.Keypad, model)
{ }
#endregion
}
}

View File

@ -17,9 +17,8 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="RazerKeypadUpdateQueue" /> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used to update this queue.</param>
/// <param name="deviceId">The id of the device updated by this queue.</param>
public RazerKeypadUpdateQueue(IDeviceUpdateTrigger updateTrigger, Guid deviceId)
: base(updateTrigger, deviceId)
public RazerKeypadUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{ }
#endregion
@ -43,6 +42,9 @@ namespace RGB.NET.Devices.Razer
return ptr;
}
/// <inheritdoc />
protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateKeypadEffect(_Defines.KEYPAD_EFFECT_ID, effectParams, ref effectId);
#endregion
}
}

View File

@ -6,11 +6,11 @@ using RGB.NET.Devices.Razer.Native;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc cref="RazerRGBDevice{TDeviceInfo}" />
/// <inheritdoc cref="RazerRGBDevice" />
/// <summary>
/// Represents a razer mouse.
/// </summary>
public class RazerMouseRGBDevice : RazerRGBDevice<RazerMouseRGBDeviceInfo>, IMouse
public class RazerMouseRGBDevice : RazerRGBDevice, IMouse
{
#region Constructors
@ -19,7 +19,7 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerMouseRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the mouse.</param>
internal RazerMouseRGBDevice(RazerMouseRGBDeviceInfo info)
internal RazerMouseRGBDevice(RazerRGBDeviceInfo info)
: base(info)
{ }
@ -39,7 +39,7 @@ namespace RGB.NET.Devices.Razer
protected override object? GetLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Mouse1;
/// <inheritdoc />
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerMouseUpdateQueue(updateTrigger, DeviceInfo.DeviceId);
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerMouseUpdateQueue(updateTrigger);
#endregion
}

View File

@ -1,26 +0,0 @@
using System;
using RGB.NET.Core;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerMouseRGBDevice" />.
/// </summary>
public class RazerMouseRGBDeviceInfo : RazerRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerMouseRGBDeviceInfo" />.
/// </summary>
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
internal RazerMouseRGBDeviceInfo(Guid deviceId, string model)
: base(deviceId, RGBDeviceType.Mouse, model)
{ }
#endregion
}
}

View File

@ -17,9 +17,8 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="RazerMouseUpdateQueue" /> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used to update this queue.</param>
/// <param name="deviceId">The id of the device updated by this queue.</param>
public RazerMouseUpdateQueue(IDeviceUpdateTrigger updateTrigger, Guid deviceId)
: base(updateTrigger, deviceId)
public RazerMouseUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{ }
#endregion
@ -43,6 +42,10 @@ namespace RGB.NET.Devices.Razer
return ptr;
}
/// <inheritdoc />
protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateMouseEffect(_Defines.MOUSE_EFFECT_ID, effectParams, ref effectId);
#endregion
}
}

View File

@ -6,11 +6,11 @@ using RGB.NET.Devices.Razer.Native;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc cref="RazerRGBDevice{TDeviceInfo}" />
/// <inheritdoc cref="RazerRGBDevice" />
/// <summary>
/// Represents a razer mousepad.
/// </summary>
public class RazerMousepadRGBDevice : RazerRGBDevice<RazerMousepadRGBDeviceInfo>, IMousepad
public class RazerMousepadRGBDevice : RazerRGBDevice, IMousepad
{
#region Constructors
@ -19,7 +19,7 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerMousepadRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the mousepad.</param>
internal RazerMousepadRGBDevice(RazerMousepadRGBDeviceInfo info)
internal RazerMousepadRGBDevice(RazerRGBDeviceInfo info)
: base(info)
{ }
@ -38,7 +38,7 @@ namespace RGB.NET.Devices.Razer
protected override object? GetLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Mousepad1;
/// <inheritdoc />
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerMousepadUpdateQueue(updateTrigger, DeviceInfo.DeviceId);
protected override RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger) => new RazerMousepadUpdateQueue(updateTrigger);
#endregion
}

View File

@ -1,26 +0,0 @@
using System;
using RGB.NET.Core;
namespace RGB.NET.Devices.Razer
{
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerMousepadRGBDevice" />.
/// </summary>
public class RazerMousepadRGBDeviceInfo : RazerRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Razer.RazerMousepadRGBDeviceInfo" />.
/// </summary>
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
internal RazerMousepadRGBDeviceInfo(Guid deviceId, string model)
: base(deviceId, RGBDeviceType.Mousepad, model)
{ }
#endregion
}
}

View File

@ -17,9 +17,8 @@ namespace RGB.NET.Devices.Razer
/// Initializes a new instance of the <see cref="RazerMousepadUpdateQueue" /> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used to update this queue.</param>
/// <param name="deviceId">The id of the device updated by this queue.</param>
public RazerMousepadUpdateQueue(IDeviceUpdateTrigger updateTrigger, Guid deviceId)
: base(updateTrigger, deviceId)
public RazerMousepadUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{ }
#endregion

View File

@ -7,6 +7,8 @@
internal const int CHROMALINK_EFFECT_ID = 1;
internal const int KEYBOARD_EFFECT_ID = 9;
internal const int MOUSEPAD_EFFECT_ID = 6;
internal const int MOUSE_EFFECT_ID = 3;
internal const int KEYPAD_EFFECT_ID = 2;
internal const int KEYBOARD_MAX_ROW = 8;
internal const int KEYBOARD_MAX_COLUMN = 24;

View File

@ -44,6 +44,8 @@ namespace RGB.NET.Devices.Razer.Native
_createHeadsetEffectPointer = (CreateHeadsetEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CreateHeadsetEffect"), typeof(CreateHeadsetEffectPointer));
_createChromaLinkEffectPointer = (CreateChromaLinkEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CreateChromaLinkEffect"), typeof(CreateChromaLinkEffectPointer));
_createKeyboardEffectPointer = (CreateKeyboardEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CreateKeyboardEffect"), typeof(CreateKeyboardEffectPointer));
_createKeypadEffectPointer = (CreateKeypadEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CreateKeypadEffect"), typeof(CreateKeypadEffectPointer));
_createMouseEffectPointer = (CreateMouseEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CreateMouseEffect"), typeof(CreateMouseEffectPointer));
_createMousepadEffectPointer = (CreateMousepadEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CreateMousepadEffect"), typeof(CreateMousepadEffectPointer));
_setEffectPointer = (SetEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetEffect"), typeof(SetEffectPointer));
_deleteEffectPointer = (DeleteEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "DeleteEffect"), typeof(DeleteEffectPointer));
@ -80,6 +82,8 @@ namespace RGB.NET.Devices.Razer.Native
private static CreateHeadsetEffectPointer? _createHeadsetEffectPointer;
private static CreateChromaLinkEffectPointer? _createChromaLinkEffectPointer;
private static CreateKeyboardEffectPointer? _createKeyboardEffectPointer;
private static CreateKeypadEffectPointer? _createKeypadEffectPointer;
private static CreateMouseEffectPointer? _createMouseEffectPointer;
private static CreateMousepadEffectPointer? _createMousepadEffectPointer;
private static SetEffectPointer? _setEffectPointer;
private static DeleteEffectPointer? _deleteEffectPointer;
@ -109,6 +113,12 @@ namespace RGB.NET.Devices.Razer.Native
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate RazerError CreateKeyboardEffectPointer(int effectType, IntPtr param, ref Guid effectId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate RazerError CreateKeypadEffectPointer(int effectType, IntPtr param, ref Guid effectId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate RazerError CreateMouseEffectPointer(int effectType, IntPtr param, ref Guid effectId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate RazerError CreateMousepadEffectPointer(int effectType, IntPtr param, ref Guid effectId);
@ -151,11 +161,15 @@ namespace RGB.NET.Devices.Razer.Native
internal static RazerError CreateEffect(Guid deviceId, int effectType, IntPtr param, ref Guid effectId) => (_createEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(deviceId, effectType, param, ref effectId);
internal static RazerError CreateHeadsetEffect(int effectType, IntPtr param, ref Guid effectId) => (_createHeadsetEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectType, param, ref effectId);
internal static RazerError CreateChromaLinkEffect(int effectType, IntPtr param, ref Guid effectId) => (_createChromaLinkEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectType, param, ref effectId);
internal static RazerError CreateKeyboardEffect(int effectType, IntPtr param, ref Guid effectId) => (_createKeyboardEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectType, param, ref effectId);
internal static RazerError CreateKeypadEffect(int effectType, IntPtr param, ref Guid effectId) => (_createKeypadEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectType, param, ref effectId);
internal static RazerError CreateMouseEffect(int effectType, IntPtr param, ref Guid effectId) => (_createMouseEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectType, param, ref effectId);
internal static RazerError CreateMousepadEffect(int effectType, IntPtr param, ref Guid effectId) => (_createMousepadEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectType, param, ref effectId);
internal static RazerError SetEffect(Guid effectId) => (_setEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectId);

View File

@ -50,6 +50,10 @@
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HidSharp" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" />
</ItemGroup>

View File

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.Razer.HID;
using RGB.NET.Devices.Razer.Native;
namespace RGB.NET.Devices.Razer
@ -29,13 +30,14 @@ namespace RGB.NET.Devices.Razer
/// 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() { @"%systemroot%\SysWOW64\RzChromaSDK.dll" };
public static List<string> PossibleX86NativePaths { get; } = new() {@"%systemroot%\SysWOW64\RzChromaSDK.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() { @"%systemroot%\System32\RzChromaSDK.dll", @"%systemroot%\System32\RzChromaSDK64.dll" };
public static List<string> PossibleX64NativePaths { get; } =
new() {@"%systemroot%\System32\RzChromaSDK.dll", @"%systemroot%\System32\RzChromaSDK64.dll"};
/// <inheritdoc />
/// <summary>
@ -66,7 +68,8 @@ namespace RGB.NET.Devices.Razer
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public RazerDeviceProvider()
{
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(RazerDeviceProvider)}");
if (_instance != null)
throw new InvalidOperationException($"There can be only one instance of type {nameof(RazerDeviceProvider)}");
_instance = this;
UpdateTrigger = new DeviceUpdateTrigger();
@ -96,84 +99,45 @@ namespace RGB.NET.Devices.Razer
ThrowRazerError(error);
IList<IRGBDevice> devices = new List<IRGBDevice>();
DeviceChecker.LoadDeviceList(loadFilter);
if (loadFilter.HasFlag(RGBDeviceType.Keyboard))
foreach ((Guid guid, string model) in Razer.Devices.KEYBOARDS)
try
{
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.KEYBOARDS.FirstOrDefault().guid != guid))) continue;
foreach ((var model, RGBDeviceType deviceType, int _) in DeviceChecker.ConnectedDevices)
{
RazerRGBDevice device = deviceType switch
{
RGBDeviceType.Keyboard => new RazerKeyboardRGBDevice(new RazerKeyboardRGBDeviceInfo(model)),
RGBDeviceType.Mouse => new RazerMouseRGBDevice(new RazerRGBDeviceInfo(deviceType, model)),
RGBDeviceType.Headset => new RazerHeadsetRGBDevice(new RazerRGBDeviceInfo(deviceType, model)),
RGBDeviceType.Mousepad => new RazerMousepadRGBDevice(new RazerRGBDeviceInfo(deviceType, model)),
RGBDeviceType.Keypad => new RazerKeypadRGBDevice(new RazerRGBDeviceInfo(deviceType, model)),
RGBDeviceType.Unknown => new RazerChromaLinkRGBDevice(new RazerRGBDeviceInfo(deviceType, model)),
_ => throw new RGBDeviceException($"Razer SDK does not support {deviceType} devices")
};
RazerKeyboardRGBDevice device = new(new RazerKeyboardRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
catch { if (throwExceptions) throw; }
devices.Add(device);
}
if (loadFilter.HasFlag(RGBDeviceType.Mouse))
foreach ((Guid guid, string model) in Razer.Devices.MICE)
try
{
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.MICE.FirstOrDefault().guid != guid))) continue;
if (LoadEmulatorDevices)
{
if (loadFilter.HasFlag(RGBDeviceType.Keyboard) && devices.All(d => d.DeviceInfo.DeviceType != RGBDeviceType.Keyboard))
devices.Add(new RazerKeyboardRGBDevice(new RazerKeyboardRGBDeviceInfo("Emulator Keyboard")));
if (loadFilter.HasFlag(RGBDeviceType.Mouse) && devices.All(d => d.DeviceInfo.DeviceType != RGBDeviceType.Mouse))
devices.Add(new RazerMouseRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Mouse, "Emulator Mouse")));
if (loadFilter.HasFlag(RGBDeviceType.Headset) && devices.All(d => d.DeviceInfo.DeviceType != RGBDeviceType.Headset))
devices.Add(new RazerHeadsetRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Headset, "Emulator Headset")));
if (loadFilter.HasFlag(RGBDeviceType.Mousepad) && devices.All(d => d.DeviceInfo.DeviceType != RGBDeviceType.Mousepad))
devices.Add(new RazerMousepadRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Mousepad, "Emulator Mousepad")));
if (loadFilter.HasFlag(RGBDeviceType.Keypad) && devices.All(d => d.DeviceInfo.DeviceType != RGBDeviceType.Keypad))
devices.Add(new RazerKeypadRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Keypad, "Emulator Keypad")));
if (loadFilter.HasFlag(RGBDeviceType.Unknown) && devices.All(d => d.DeviceInfo.DeviceType != RGBDeviceType.Unknown))
devices.Add(new RazerChromaLinkRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Unknown, "Emulator Chroma Link")));
}
RazerMouseRGBDevice device = new(new RazerMouseRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
catch { if (throwExceptions) throw; }
if (loadFilter.HasFlag(RGBDeviceType.Headset))
foreach ((Guid guid, string model) in Razer.Devices.HEADSETS)
try
{
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.HEADSETS.FirstOrDefault().guid != guid))) continue;
RazerHeadsetRGBDevice device = new(new RazerHeadsetRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
catch { if (throwExceptions) throw; }
if (loadFilter.HasFlag(RGBDeviceType.Mousepad))
foreach ((Guid guid, string model) in Razer.Devices.MOUSEMATS)
try
{
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.MOUSEMATS.FirstOrDefault().guid != guid))) continue;
RazerMousepadRGBDevice device = new(new RazerMousepadRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
catch { if (throwExceptions) throw; }
if (loadFilter.HasFlag(RGBDeviceType.Keypad))
foreach ((Guid guid, string model) in Razer.Devices.KEYPADS)
try
{
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.KEYPADS.FirstOrDefault().guid != guid))) continue;
RazerKeypadRGBDevice device = new(new RazerKeypadRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
catch { if (throwExceptions) throw; }
if (loadFilter.HasFlag(RGBDeviceType.Keyboard))
foreach ((Guid guid, string model) in Razer.Devices.CHROMALINKS)
try
{
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.CHROMALINKS.FirstOrDefault().guid != guid))) continue;
RazerChromaLinkRGBDevice device = new(new RazerChromaLinkRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
catch { if (throwExceptions) throw; }
foreach (var rgbDevice in devices)
{
RazerRGBDevice device = (RazerRGBDevice)rgbDevice;
device.Initialize(UpdateTrigger);
}
UpdateTrigger.Start();
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
@ -188,24 +152,31 @@ namespace RGB.NET.Devices.Razer
return true;
}
private void ThrowRazerError(RazerError errorCode) => throw new RazerException(errorCode);
private void TryUnInit()
{
try { _RazerSDK.UnInit(); }
catch { /* We tried our best */ }
catch
{ /* We tried our best */
}
}
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
catch
{ /* at least we tried */
}
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
catch
{ /* at least we tried */
}
Devices = Enumerable.Empty<IRGBDevice>();
TryUnInit();