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

Razer: Load Debug Device Properties for Each Device Type

This commit is contained in:
Aytaç Kayadelen 2024-03-08 20:28:09 +01:00 committed by Darth Affe
parent a4bd797912
commit d82eebd769
2 changed files with 36 additions and 18 deletions

View File

@ -1,42 +1,55 @@
namespace RGB.NET.Devices.Razer; using System;
namespace RGB.NET.Devices.Razer;
/// <summary> /// <summary>
/// Represents a type of Razer SDK endpoint /// Represents a type of Razer SDK endpoint
/// </summary> /// </summary>
[Flags]
public enum RazerEndpointType public enum RazerEndpointType
{ {
/// <summary>
/// No endpoint
/// </summary>
None = 0,
/// <summary> /// <summary>
/// The keyboard endpoint /// The keyboard endpoint
/// </summary> /// </summary>
Keyboard, Keyboard = 1 << 0,
/// <summary> /// <summary>
/// The laptop keyboard endpoint, shares the <see cref="Keyboard"/> endpoint but has a different LED layout /// The laptop keyboard endpoint, shares the <see cref="Keyboard"/> endpoint but has a different LED layout
/// </summary> /// </summary>
LaptopKeyboard, LaptopKeyboard = 1 << 1,
/// <summary> /// <summary>
/// The mouse endpoint /// The mouse endpoint
/// </summary> /// </summary>
Mouse, Mouse = 1 << 2,
/// <summary> /// <summary>
/// The headset endpoint /// The headset endpoint
/// </summary> /// </summary>
Headset, Headset = 1 << 3,
/// <summary> /// <summary>
/// The mousepad endpoint /// The mousepad endpoint
/// </summary> /// </summary>
Mousepad, Mousepad = 1 << 4,
/// <summary> /// <summary>
/// The keypad endpoint /// The keypad endpoint
/// </summary> /// </summary>
Keypad, Keypad = 1 << 5,
/// <summary> /// <summary>
/// The Chroma Link endpoint /// The Chroma Link endpoint
/// </summary> /// </summary>
ChromaLink, ChromaLink = 1 << 6,
}
/// <summary>
/// All endpoints
/// </summary>
All = ~None
}

View File

@ -50,7 +50,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
/// <summary> /// <summary>
/// Forces to load the devices represented by the emulator even if they aren't reported to exist. /// Forces to load the devices represented by the emulator even if they aren't reported to exist.
/// </summary> /// </summary>
public bool LoadEmulatorDevices { get; set; } = false; public RazerEndpointType LoadEmulatorDevices { get; set; } = RazerEndpointType.None;
private const int VENDOR_ID = 0x1532; private const int VENDOR_ID = 0x1532;
@ -313,21 +313,26 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ {
DeviceDefinitions.LoadFilter = loadFilter; DeviceDefinitions.LoadFilter = loadFilter;
IList<IRGBDevice> devices = base.GetLoadedDevices(loadFilter).ToList(); List<IRGBDevice> devices = base.GetLoadedDevices(loadFilter).ToList();
if (LoadEmulatorDevices) if (LoadEmulatorDevices != RazerEndpointType.None)
{ {
if (loadFilter.HasFlag(RGBDeviceType.Keyboard) && devices.All(d => d is not RazerKeyboardRGBDevice)) if (loadFilter.HasFlag(RGBDeviceType.Keyboard) && (LoadEmulatorDevices.HasFlag(RazerEndpointType.Keyboard) || LoadEmulatorDevices.HasFlag(RazerEndpointType.LaptopKeyboard)) && devices.All(d => d is not RazerKeyboardRGBDevice))
devices.Add(new RazerKeyboardRGBDevice(new RazerKeyboardRGBDeviceInfo("Emulator Keyboard", RazerEndpointType.Keyboard), GetUpdateTrigger(), LedMappings.Keyboard)); devices.Add(new RazerKeyboardRGBDevice(new RazerKeyboardRGBDeviceInfo("Emulator Keyboard", RazerEndpointType.Keyboard), GetUpdateTrigger(), LedMappings.Keyboard));
if (loadFilter.HasFlag(RGBDeviceType.Mouse) && devices.All(d => d is not RazerMouseRGBDevice))
if (loadFilter.HasFlag(RGBDeviceType.Mouse) && LoadEmulatorDevices.HasFlag(RazerEndpointType.Mouse) && devices.All(d => d is not RazerMouseRGBDevice))
devices.Add(new RazerMouseRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Mouse, RazerEndpointType.Mouse, "Emulator Mouse"), GetUpdateTrigger(), LedMappings.Mouse)); devices.Add(new RazerMouseRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Mouse, RazerEndpointType.Mouse, "Emulator Mouse"), GetUpdateTrigger(), LedMappings.Mouse));
if (loadFilter.HasFlag(RGBDeviceType.Headset) && devices.All(d => d is not RazerHeadsetRGBDevice))
if (loadFilter.HasFlag(RGBDeviceType.Headset) && LoadEmulatorDevices.HasFlag(RazerEndpointType.Headset) && devices.All(d => d is not RazerHeadsetRGBDevice))
devices.Add(new RazerHeadsetRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Headset, RazerEndpointType.Headset, "Emulator Headset"), GetUpdateTrigger())); devices.Add(new RazerHeadsetRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Headset, RazerEndpointType.Headset, "Emulator Headset"), GetUpdateTrigger()));
if (loadFilter.HasFlag(RGBDeviceType.Mousepad) && devices.All(d => d is not RazerMousepadRGBDevice))
if (loadFilter.HasFlag(RGBDeviceType.Mousepad) && LoadEmulatorDevices.HasFlag(RazerEndpointType.Mousepad) && devices.All(d => d is not RazerMousepadRGBDevice))
devices.Add(new RazerMousepadRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Mousepad, RazerEndpointType.Mousepad, "Emulator Mousepad"), GetUpdateTrigger())); devices.Add(new RazerMousepadRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Mousepad, RazerEndpointType.Mousepad, "Emulator Mousepad"), GetUpdateTrigger()));
if (loadFilter.HasFlag(RGBDeviceType.Keypad) && devices.All(d => d is not RazerMousepadRGBDevice))
if (loadFilter.HasFlag(RGBDeviceType.Keypad) && LoadEmulatorDevices.HasFlag(RazerEndpointType.Keypad) && devices.All(d => d is not RazerMousepadRGBDevice))
devices.Add(new RazerKeypadRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Keypad, RazerEndpointType.Keypad, "Emulator Keypad"), GetUpdateTrigger())); devices.Add(new RazerKeypadRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Keypad, RazerEndpointType.Keypad, "Emulator Keypad"), GetUpdateTrigger()));
if (loadFilter.HasFlag(RGBDeviceType.Unknown) && devices.All(d => d is not RazerChromaLinkRGBDevice))
if (loadFilter.HasFlag(RGBDeviceType.Unknown) && LoadEmulatorDevices.HasFlag(RazerEndpointType.ChromaLink) && devices.All(d => d is not RazerChromaLinkRGBDevice))
devices.Add(new RazerChromaLinkRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Unknown, RazerEndpointType.ChromaLink, "Emulator Chroma Link"), GetUpdateTrigger())); devices.Add(new RazerChromaLinkRGBDevice(new RazerRGBDeviceInfo(RGBDeviceType.Unknown, RazerEndpointType.ChromaLink, "Emulator Chroma Link"), GetUpdateTrigger()));
} }