Skip to content

Commit

Permalink
Razer: Load Debug Device Properties for Each Device Type
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln authored and DarthAffe committed Mar 8, 2024
1 parent a4bd797 commit d82eebd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
31 changes: 22 additions & 9 deletions RGB.NET.Devices.Razer/Enum/RazerEndpointType.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,55 @@
namespace RGB.NET.Devices.Razer;
using System;

namespace RGB.NET.Devices.Razer;

/// <summary>
/// Represents a type of Razer SDK endpoint
/// </summary>
[Flags]
public enum RazerEndpointType
{
/// <summary>
/// No endpoint
/// </summary>
None = 0,

/// <summary>
/// The keyboard endpoint
/// </summary>
Keyboard,
Keyboard = 1 << 0,

/// <summary>
/// The laptop keyboard endpoint, shares the <see cref="Keyboard"/> endpoint but has a different LED layout
/// </summary>
LaptopKeyboard,
LaptopKeyboard = 1 << 1,

/// <summary>
/// The mouse endpoint
/// </summary>
Mouse,
Mouse = 1 << 2,

/// <summary>
/// The headset endpoint
/// </summary>
Headset,
Headset = 1 << 3,

/// <summary>
/// The mousepad endpoint
/// </summary>
Mousepad,
Mousepad = 1 << 4,

/// <summary>
/// The keypad endpoint
/// </summary>
Keypad,
Keypad = 1 << 5,

/// <summary>
/// The Chroma Link endpoint
/// </summary>
ChromaLink,
}
ChromaLink = 1 << 6,

/// <summary>
/// All endpoints
/// </summary>
All = ~None
}
23 changes: 14 additions & 9 deletions RGB.NET.Devices.Razer/RazerDeviceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static RazerDeviceProvider Instance
/// <summary>
/// Forces to load the devices represented by the emulator even if they aren't reported to exist.
/// </summary>
public bool LoadEmulatorDevices { get; set; } = false;
public RazerEndpointType LoadEmulatorDevices { get; set; } = RazerEndpointType.None;

private const int VENDOR_ID = 0x1532;

Expand Down Expand Up @@ -313,21 +313,26 @@ protected override IEnumerable<IRGBDevice> GetLoadedDevices(RGBDeviceType loadFi
{
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));
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()));
}

Expand Down

0 comments on commit d82eebd

Please sign in to comment.