mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Added a device filter to LoadDevices and device Initialize
This commit is contained in:
parent
b700c84b8d
commit
11ca959328
@ -31,10 +31,11 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="IRGBDeviceProvider"/> if not already happened or reloads it if it is already initialized.
|
||||
/// </summary>
|
||||
/// <param name="loadFilter">Specifies which types of devices to load.</param>
|
||||
/// <param name="exclusiveAccessIfPossible">Specifies whether the application should request exclusive access of possible or not.</param>
|
||||
/// <param name="throwExceptions">Specifies whether exception during the initialization sequence should be thrown or not.</param>
|
||||
/// <returns></returns>
|
||||
bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false);
|
||||
bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false);
|
||||
|
||||
/// <summary>
|
||||
/// Resets all handled <see cref="IRGBDevice"/> back top default.
|
||||
|
||||
@ -8,10 +8,15 @@ namespace RGB.NET.Core
|
||||
[Flags]
|
||||
public enum RGBDeviceType
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents nothing.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Represents a device where the type is not known or not present in the list.
|
||||
/// </summary>
|
||||
Unknown = 0,
|
||||
Unknown = -1,
|
||||
|
||||
/// <summary>
|
||||
/// Represents a keyboard.
|
||||
@ -62,5 +67,10 @@ namespace RGB.NET.Core
|
||||
/// Represents a headset stand
|
||||
/// </summary>
|
||||
HeadsetStand = 1 << 9,
|
||||
|
||||
/// <summary>
|
||||
/// Represents all devices
|
||||
/// </summary>
|
||||
All = 0xFFFFFFF
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,13 +13,15 @@ namespace RGB.NET.Core
|
||||
/// Loads all devices the given <see cref="IRGBDeviceProvider"/> is able to provide.
|
||||
/// </summary>
|
||||
/// <param name="deviceProvider">The <see cref="IRGBDeviceProvider"/> to load the devices from.</param>
|
||||
/// <param name="loadFilter">Specifies which types of devices to load.</param>
|
||||
/// <param name="exclusiveAccessIfPossible">Specifies whether the application should request exclusive access of possible or not.</param>
|
||||
/// <param name="throwExceptions">Specifies whether exception during the initialization sequence should be thrown or not.</param>
|
||||
public void LoadDevices(IRGBDeviceProvider deviceProvider, bool throwExceptions = false)
|
||||
public void LoadDevices(IRGBDeviceProvider deviceProvider, RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
{
|
||||
if (_deviceProvider.Contains(deviceProvider) || _deviceProvider.Any(x => x.GetType() == deviceProvider.GetType())) return;
|
||||
|
||||
List<IRGBDevice> addedDevices = new List<IRGBDevice>();
|
||||
if (deviceProvider.IsInitialized || deviceProvider.Initialize(throwExceptions))
|
||||
if (deviceProvider.IsInitialized || deviceProvider.Initialize(loadFilter, exclusiveAccessIfPossible, throwExceptions))
|
||||
{
|
||||
_deviceProvider.Add(deviceProvider);
|
||||
|
||||
|
||||
@ -81,7 +81,7 @@ namespace RGB.NET.Devices.Asus
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
{
|
||||
IsInitialized = false;
|
||||
|
||||
@ -93,6 +93,7 @@ namespace RGB.NET.Devices.Asus
|
||||
|
||||
#region Mainboard
|
||||
|
||||
if (loadFilter.HasFlag(RGBDeviceType.Mainboard))
|
||||
try
|
||||
{
|
||||
//TODO DarthAffe 26.11.2017: This is not a fix! There might really be a second controller on the mainboard, but for now this should prevent the random crash for some guys.
|
||||
@ -125,6 +126,7 @@ namespace RGB.NET.Devices.Asus
|
||||
|
||||
//TODO DarthAffe 21.10.2017: This somehow returns non-existant gpus (at least for me) which cause huge lags (if a real asus-ready gpu is connected this doesn't happen)
|
||||
|
||||
if (loadFilter.HasFlag(RGBDeviceType.GraphicsCard))
|
||||
try
|
||||
{
|
||||
int graphicCardCount = _AsusSDK.EnumerateGPU(IntPtr.Zero, 0);
|
||||
@ -182,6 +184,7 @@ namespace RGB.NET.Devices.Asus
|
||||
|
||||
#region Keyboard
|
||||
|
||||
if (loadFilter.HasFlag(RGBDeviceType.Keyboard))
|
||||
try
|
||||
{
|
||||
IntPtr keyboardHandle = Marshal.AllocHGlobal(IntPtr.Size);
|
||||
@ -199,6 +202,7 @@ namespace RGB.NET.Devices.Asus
|
||||
|
||||
#region Mouse
|
||||
|
||||
if (loadFilter.HasFlag(RGBDeviceType.Mouse))
|
||||
try
|
||||
{
|
||||
IntPtr mouseHandle = Marshal.AllocHGlobal(IntPtr.Size);
|
||||
|
||||
@ -82,7 +82,7 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
{
|
||||
IsInitialized = false;
|
||||
|
||||
@ -101,8 +101,11 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
_CoolerMasterSDK.SetControlDevice(index);
|
||||
if (_CoolerMasterSDK.IsDevicePlugged())
|
||||
{
|
||||
RGBDeviceType deviceType = index.GetDeviceType();
|
||||
if (!loadFilter.HasFlag(deviceType)) continue;
|
||||
|
||||
ICoolerMasterRGBDevice device;
|
||||
switch (index.GetDeviceType())
|
||||
switch (deviceType)
|
||||
{
|
||||
case RGBDeviceType.Keyboard:
|
||||
CoolerMasterPhysicalKeyboardLayout physicalLayout = _CoolerMasterSDK.GetDeviceLayout();
|
||||
|
||||
@ -89,7 +89,7 @@ namespace RGB.NET.Devices.Corsair
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="RGBDeviceException">Thrown if the SDK is already initialized or if the SDK is not compatible to CUE.</exception>
|
||||
/// <exception cref="CUEException">Thrown if the CUE-SDK provides an error.</exception>
|
||||
public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
{
|
||||
IsInitialized = false;
|
||||
|
||||
@ -129,34 +129,9 @@ namespace RGB.NET.Devices.Corsair
|
||||
if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting))
|
||||
continue; // Everything that doesn't support lighting control is useless
|
||||
|
||||
ICorsairRGBDevice device;
|
||||
switch (info.CorsairDeviceType)
|
||||
{
|
||||
case CorsairDeviceType.Keyboard:
|
||||
device = new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
break;
|
||||
ICorsairRGBDevice device = GetRGBDevice(info, i, nativeDeviceInfo);
|
||||
if ((device == null) || !loadFilter.HasFlag(device.DeviceInfo.DeviceType)) continue;
|
||||
|
||||
case CorsairDeviceType.Mouse:
|
||||
device = new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
break;
|
||||
|
||||
case CorsairDeviceType.Headset:
|
||||
device = new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
break;
|
||||
|
||||
case CorsairDeviceType.Mousepad:
|
||||
device = new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
break;
|
||||
|
||||
case CorsairDeviceType.HeadsetStand:
|
||||
device = new CorsairHeadsetStandRGBDevice(new CorsairHeadsetStandRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
break;
|
||||
|
||||
// ReSharper disable once RedundantCaseLabel
|
||||
case CorsairDeviceType.Unknown:
|
||||
default:
|
||||
throw new RGBDeviceException("Unknown Device-Type");
|
||||
}
|
||||
device.Initialize();
|
||||
AddSpecialParts(device);
|
||||
|
||||
@ -182,6 +157,32 @@ namespace RGB.NET.Devices.Corsair
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ICorsairRGBDevice GetRGBDevice(CorsairRGBDeviceInfo info, int i, _CorsairDeviceInfo nativeDeviceInfo)
|
||||
{
|
||||
switch (info.CorsairDeviceType)
|
||||
{
|
||||
case CorsairDeviceType.Keyboard:
|
||||
return new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
|
||||
case CorsairDeviceType.Mouse:
|
||||
return new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
|
||||
case CorsairDeviceType.Headset:
|
||||
return new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
|
||||
case CorsairDeviceType.Mousepad:
|
||||
return new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
|
||||
case CorsairDeviceType.HeadsetStand:
|
||||
return new CorsairHeadsetStandRGBDevice(new CorsairHeadsetStandRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
|
||||
// ReSharper disable once RedundantCaseLabel
|
||||
case CorsairDeviceType.Unknown:
|
||||
default:
|
||||
throw new RGBDeviceException("Unknown Device-Type");
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSpecialParts(ICorsairRGBDevice device)
|
||||
{
|
||||
if (device.DeviceInfo.Model.Equals("K95 RGB Platinum", StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
@ -75,7 +75,7 @@ namespace RGB.NET.Devices.Logitech
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -101,11 +101,14 @@ namespace RGB.NET.Devices.Logitech
|
||||
if (DeviceChecker.IsPerKeyDeviceConnected)
|
||||
{
|
||||
(string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData;
|
||||
if (loadFilter.HasFlag(deviceType)) //TODO DarthAffe 07.12.2017: Check if it's worth to try another device if the one returned doesn't match the filter
|
||||
{
|
||||
ILogitechRGBDevice device = new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.PerKeyRGB, imageBasePath, imageLayout, layoutPath));
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
try
|
||||
@ -113,11 +116,14 @@ namespace RGB.NET.Devices.Logitech
|
||||
if (DeviceChecker.IsPerDeviceDeviceConnected)
|
||||
{
|
||||
(string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerDeviceDeviceData;
|
||||
if (loadFilter.HasFlag(deviceType)) //TODO DarthAffe 07.12.2017: Check if it's worth to try another device if the one returned doesn't match the filter
|
||||
{
|
||||
ILogitechRGBDevice device = new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, imageBasePath, imageLayout, layoutPath));
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||
|
||||
@ -81,7 +81,7 @@ namespace RGB.NET.Devices.Msi
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
{
|
||||
IsInitialized = false;
|
||||
|
||||
|
||||
@ -58,7 +58,7 @@ namespace RGB.NET.Devices.Novation
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Initialize(bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
{
|
||||
IsInitialized = false;
|
||||
|
||||
@ -66,6 +66,7 @@ namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
||||
|
||||
if (loadFilter.HasFlag(RGBDeviceType.LedMatrix))
|
||||
for (int index = 0; index < OutputDeviceBase.DeviceCount; index++)
|
||||
{
|
||||
try
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user