From d82eebd7694e54caa98acdc01b4818f74f3daf23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ayta=C3=A7=20Kayadelen?= Date: Fri, 8 Mar 2024 20:28:09 +0100 Subject: [PATCH] Razer: Load Debug Device Properties for Each Device Type --- .../Enum/RazerEndpointType.cs | 31 +++++++++++++------ RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 23 ++++++++------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/RGB.NET.Devices.Razer/Enum/RazerEndpointType.cs b/RGB.NET.Devices.Razer/Enum/RazerEndpointType.cs index 01bb0609..c48bfcd8 100644 --- a/RGB.NET.Devices.Razer/Enum/RazerEndpointType.cs +++ b/RGB.NET.Devices.Razer/Enum/RazerEndpointType.cs @@ -1,42 +1,55 @@ -namespace RGB.NET.Devices.Razer; +using System; + +namespace RGB.NET.Devices.Razer; /// /// Represents a type of Razer SDK endpoint /// +[Flags] public enum RazerEndpointType { + /// + /// No endpoint + /// + None = 0, + /// /// The keyboard endpoint /// - Keyboard, + Keyboard = 1 << 0, /// /// The laptop keyboard endpoint, shares the endpoint but has a different LED layout /// - LaptopKeyboard, + LaptopKeyboard = 1 << 1, /// /// The mouse endpoint /// - Mouse, + Mouse = 1 << 2, /// /// The headset endpoint /// - Headset, + Headset = 1 << 3, /// /// The mousepad endpoint /// - Mousepad, + Mousepad = 1 << 4, /// /// The keypad endpoint /// - Keypad, + Keypad = 1 << 5, /// /// The Chroma Link endpoint /// - ChromaLink, -} \ No newline at end of file + ChromaLink = 1 << 6, + + /// + /// All endpoints + /// + All = ~None +} diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 638fdda0..047705d7 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -50,7 +50,7 @@ public static RazerDeviceProvider Instance /// /// Forces to load the devices represented by the emulator even if they aren't reported to exist. /// - public bool LoadEmulatorDevices { get; set; } = false; + public RazerEndpointType LoadEmulatorDevices { get; set; } = RazerEndpointType.None; private const int VENDOR_ID = 0x1532; @@ -313,21 +313,26 @@ protected override IEnumerable GetLoadedDevices(RGBDeviceType loadFi { DeviceDefinitions.LoadFilter = loadFilter; - IList devices = base.GetLoadedDevices(loadFilter).ToList(); + List 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)); - 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)); - 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())); - 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())); - 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())); - 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())); }