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

Refactoring

This commit is contained in:
Darth Affe 2021-02-06 17:07:41 +01:00
parent a0a1521658
commit 6a4ebb3d2a
37 changed files with 123 additions and 300 deletions

View File

@ -1,6 +1,4 @@
using System;
namespace RGB.NET.Core
namespace RGB.NET.Core
{
/// <summary>
/// Represents a generic information for a <see cref="IRGBDevice"/>

View File

@ -21,5 +21,11 @@ namespace RGB.NET.Core
IEnumerable<IRGBDevice> Devices { get; }
#endregion
#region Methods
bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false);
#endregion
}
}

View File

@ -1,83 +0,0 @@
using System;
using System.IO;
using System.Reflection;
namespace RGB.NET.Core
{
/// <summary>
/// Offers some helper-methods for file-path related things.
/// </summary>
public static class PathHelper
{
#region Events
/// <summary>
/// Occurs when a path is resolving.
/// </summary>
public static event EventHandler<ResolvePathEventArgs>? ResolvingAbsolutePath;
#endregion
#region Methods
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="relativePath">The relative part of the path to convert.</param>
/// <returns>The absolute path.</returns>
public static string GetAbsolutePath(string relativePath) => GetAbsolutePath((object?)null, relativePath);
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="relativePath">The relative part of the path to convert.</param>
/// <param name="fileName">The file name of the path to convert.</param>
/// <returns>The absolute path.</returns>
public static string GetAbsolutePath(string relativePath, string fileName) => GetAbsolutePath(null, relativePath, fileName);
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="sender">The requester of this path. (Used for better control when using the event to override this behavior.)</param>
/// <param name="relativePath">The relative path to convert.</param>
/// <param name="fileName">The file name of the path to convert.</param>
/// <returns>The absolute path.</returns>
public static string GetAbsolutePath(object? sender, string relativePath, string fileName)
{
string relativePart = Path.Combine(relativePath, fileName);
string? assemblyLocation = Assembly.GetEntryAssembly()?.Location;
if (assemblyLocation == null) return relativePart;
string? directoryName = Path.GetDirectoryName(assemblyLocation);
string path = directoryName == null ? string.Empty : Path.Combine(directoryName, relativePart);
ResolvePathEventArgs args = new(relativePath, fileName, path);
ResolvingAbsolutePath?.Invoke(sender, args);
return args.FinalPath;
}
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="sender">The requester of this path. (Used for better control when using the event to override this behavior.)</param>
/// <param name="relativePath">The relative path to convert.</param>
/// <returns>The absolute path.</returns>
public static string GetAbsolutePath(object? sender, string relativePath)
{
string? assemblyLocation = Assembly.GetEntryAssembly()?.Location;
if (assemblyLocation == null) return relativePath;
string? directoryName = Path.GetDirectoryName(assemblyLocation);
string path = directoryName == null ? string.Empty : Path.Combine(directoryName, relativePath);
ResolvePathEventArgs args = new(relativePath, path);
ResolvingAbsolutePath?.Invoke(sender, args);
return args.FinalPath;
}
#endregion
}
}

View File

@ -9,7 +9,7 @@ namespace RGB.NET.Core
/// <summary>
/// Represents an angular rotation.
/// </summary>
[DebuggerDisplay("[{Degrees}°]")]
[DebuggerDisplay("[{" + nameof(Degrees) + "}°]")]
public readonly struct Rotation
{
#region Constants

View File

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using AuraServiceLib;
using RGB.NET.Core;
@ -37,7 +36,7 @@ namespace RGB.NET.Devices.Asus
/// <summary>
/// The <see cref="DeviceUpdateTrigger"/> used to trigger the updates for asus devices.
/// </summary>
public DeviceUpdateTrigger UpdateTrigger { get; private set; }
public DeviceUpdateTrigger UpdateTrigger { get; }
private IAuraSdk2? _sdk;
@ -58,11 +57,11 @@ namespace RGB.NET.Devices.Asus
}
#endregion
#region Methods
/// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{
IsInitialized = false;
@ -105,7 +104,7 @@ namespace RGB.NET.Devices.Asus
case AsusDeviceType.KEYBOARD_RGB:
case AsusDeviceType.NB_KB_RGB:
case AsusDeviceType.NB_KB_4ZONE_RGB:
rgbDevice = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device, CultureInfo.CurrentCulture));
rgbDevice = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device, AsusPhysicalKeyboardLayout.Default));
break;
case AsusDeviceType.MOUSE_RGB:
@ -144,19 +143,17 @@ namespace RGB.NET.Devices.Asus
return true;
}
/// <inheritdoc />
public void ResetDevices()
{
_sdk?.ReleaseControl(0);
_sdk?.SwitchMode();
}
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger?.Dispose(); }
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
Devices = Enumerable.Empty<IRGBDevice>();
try { _sdk?.ReleaseControl(0); }
catch { /* at least we tried */ }

View File

@ -1,15 +0,0 @@
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Global
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
namespace RGB.NET.Devices.Asus
{
/// <summary>
/// Contains list of available logical layouts for asus keyboards.
/// </summary>
public enum AsusLogicalKeyboardLayout
{
TODO
};
}

View File

@ -10,6 +10,6 @@ namespace RGB.NET.Devices.Asus
/// </summary>
public enum AsusPhysicalKeyboardLayout
{
TODO
Default
}
}

View File

@ -1,5 +1,4 @@
using System.Globalization;
using AuraServiceLib;
using AuraServiceLib;
using RGB.NET.Core;
namespace RGB.NET.Devices.Asus
@ -15,12 +14,7 @@ namespace RGB.NET.Devices.Asus
/// <summary>
/// Gets the physical layout of the keyboard.
/// </summary>
public AsusPhysicalKeyboardLayout PhysicalLayout { get; private set; }
/// <summary>
/// Gets the logical layout of the keyboard.
/// </summary>
public AsusLogicalKeyboardLayout LogicalLayout { get; private set; }
public AsusPhysicalKeyboardLayout PhysicalLayout { get; }
#endregion
@ -31,27 +25,10 @@ namespace RGB.NET.Devices.Asus
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Asus.AsusKeyboardRGBDeviceInfo" />.
/// </summary>
/// <param name="device">The <see cref="IAuraSyncDevice"/> backing this RGB.NET device.</param>
/// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> of the layout this keyboard is using.</param>
internal AsusKeyboardRGBDeviceInfo(IAuraSyncDevice device, CultureInfo culture)
internal AsusKeyboardRGBDeviceInfo(IAuraSyncDevice device, AsusPhysicalKeyboardLayout layout)
: base(RGBDeviceType.Keyboard, device, device.Name)
{
SetLayouts(culture.KeyboardLayoutId);
}
#endregion
#region Methods
private void SetLayouts(int keyboardLayoutId)
{
switch (keyboardLayoutId)
{
//TODO DarthAffe 07.10.2017: Implement
default:
PhysicalLayout = AsusPhysicalKeyboardLayout.TODO;
LogicalLayout = AsusLogicalKeyboardLayout.TODO;
break;
}
this.PhysicalLayout = layout;
}
#endregion

View File

@ -42,7 +42,7 @@ namespace RGB.NET.Devices.CoolerMaster
/// Indicates if the SDK is initialized and ready to use.
/// </summary>
public bool IsInitialized { get; private set; }
/// <inheritdoc />
public IEnumerable<IRGBDevice> Devices { get; private set; } = Enumerable.Empty<IRGBDevice>();
@ -72,7 +72,7 @@ namespace RGB.NET.Devices.CoolerMaster
#region Methods
/// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{
IsInitialized = false;
@ -140,38 +140,16 @@ namespace RGB.NET.Devices.CoolerMaster
return true;
}
/// <inheritdoc />
public void ResetDevices()
{
if (IsInitialized)
foreach (IRGBDevice device in Devices)
{
try
{
CoolerMasterRGBDeviceInfo deviceInfo = (CoolerMasterRGBDeviceInfo)device.DeviceInfo;
_CoolerMasterSDK.EnableLedControl(false, deviceInfo.DeviceIndex);
_CoolerMasterSDK.EnableLedControl(true, deviceInfo.DeviceIndex);
}
catch {/* shit happens */}
}
}
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger?.Dispose(); }
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
if (IsInitialized)
foreach (IRGBDevice device in Devices)
{
try
{
CoolerMasterRGBDeviceInfo deviceInfo = (CoolerMasterRGBDeviceInfo)device.DeviceInfo;
_CoolerMasterSDK.EnableLedControl(false, deviceInfo.DeviceIndex);
}
catch {/* shit happens */}
}
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
Devices = Enumerable.Empty<IRGBDevice>();
// DarthAffe 03.03.2020: Should be done but isn't possible due to an weird winodws-hook inside the sdk which corrupts the stack when unloading the dll
//try { _CoolerMasterSDK.UnloadCMSDK(); }

View File

@ -25,7 +25,6 @@ namespace RGB.NET.Devices.CoolerMaster
/// </summary>
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.</param>
/// <param name="physicalKeyboardLayout">The <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterPhysicalKeyboardLayout" /> of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.</param>
/// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> of the layout this keyboard is using</param>
internal CoolerMasterKeyboardRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex, CoolerMasterPhysicalKeyboardLayout physicalKeyboardLayout)
: base(RGBDeviceType.Keyboard, deviceIndex)
{

View File

@ -42,7 +42,7 @@ namespace RGB.NET.Devices.Corsair
/// Indicates if the SDK is initialized and ready to use.
/// </summary>
public bool IsInitialized { get; private set; }
/// <summary>
/// Gets the protocol details for the current SDK-connection.
/// </summary>
@ -84,7 +84,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(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{
IsInitialized = false;
@ -126,8 +126,7 @@ namespace RGB.NET.Devices.Corsair
{
if ((device == null) || !loadFilter.HasFlag(device.DeviceInfo.DeviceType)) continue;
if (deviceUpdateQueue == null)
deviceUpdateQueue = new CorsairDeviceUpdateQueue(UpdateTrigger, info.CorsairDeviceIndex);
deviceUpdateQueue ??= new CorsairDeviceUpdateQueue(UpdateTrigger, info.CorsairDeviceIndex);
device.Initialize(deviceUpdateQueue);
@ -231,28 +230,14 @@ namespace RGB.NET.Devices.Corsair
{
if (deviceType == CorsairDeviceType.Cooler)
return CorsairLedId.CustomLiquidCoolerChannel1Led1;
else
return channel switch
{
switch (channel)
{
case 0: return CorsairLedId.CustomDeviceChannel1Led1;
case 1: return CorsairLedId.CustomDeviceChannel2Led1;
case 2: return CorsairLedId.CustomDeviceChannel3Led1;
}
}
return CorsairLedId.Invalid;
}
/// <inheritdoc />
public void ResetDevices()
{
if (IsInitialized)
try
{
_CUESDK.Reload();
}
catch {/* shit happens */}
0 => CorsairLedId.CustomDeviceChannel1Led1,
1 => CorsairLedId.CustomDeviceChannel2Led1,
2 => CorsairLedId.CustomDeviceChannel3Led1,
_ => CorsairLedId.Invalid
};
}
private void Reset()
@ -265,9 +250,14 @@ namespace RGB.NET.Devices.Corsair
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger?.Dispose(); }
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
Devices = Enumerable.Empty<IRGBDevice>();
try { _CUESDK.UnloadCUESDK(); }
catch { /* at least we tried */ }
}

View File

@ -46,7 +46,7 @@ namespace RGB.NET.Devices.Corsair
}
}
protected override object? GetLedCustomData(LedId ledId) => _idMapping.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;
protected override object GetLedCustomData(LedId ledId) => _idMapping.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;
protected virtual LedId GetReferenceLed(RGBDeviceType deviceType)
{

View File

@ -55,7 +55,7 @@ namespace RGB.NET.Devices.Corsair
}
}
protected override object? GetLedCustomData(LedId ledId)
protected override object GetLedCustomData(LedId ledId)
{
if (string.Equals(DeviceInfo.Model, "GLAIVE RGB", StringComparison.OrdinalIgnoreCase))
return MouseIdMapping.GLAIVE.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;

View File

@ -67,7 +67,7 @@ namespace RGB.NET.Devices.DMX
public void AddDeviceDefinition(IDMXDeviceDefinition deviceDefinition) => DeviceDefinitions.Add(deviceDefinition);
/// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{
IsInitialized = false;
@ -108,15 +108,16 @@ namespace RGB.NET.Devices.DMX
return true;
}
/// <inheritdoc />
public void ResetDevices()
{ }
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger?.Dispose(); }
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
Devices = Enumerable.Empty<IRGBDevice>();
}
#endregion

View File

@ -52,7 +52,7 @@ namespace RGB.NET.Devices.DMX.E131
}
/// <inheritdoc />
protected override object? GetLedCustomData(LedId ledId) => new LedChannelMapping(_ledMappings[ledId]);
protected override object GetLedCustomData(LedId ledId) => new LedChannelMapping(_ledMappings[ledId]);
/// <inheritdoc />

View File

@ -1,5 +1,4 @@
using System;
using RGB.NET.Core;
using RGB.NET.Core;
namespace RGB.NET.Devices.Debug
{

View File

@ -39,7 +39,7 @@ namespace RGB.NET.Devices.Logitech
/// <inheritdoc />
public bool IsInitialized { get; private set; }
/// <inheritdoc />
public IEnumerable<IRGBDevice> Devices { get; private set; } = Enumerable.Empty<IRGBDevice>();
@ -76,7 +76,7 @@ namespace RGB.NET.Devices.Logitech
#region Methods
/// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{
try
{
@ -165,15 +165,17 @@ namespace RGB.NET.Devices.Logitech
return true;
}
/// <inheritdoc />
public void ResetDevices() => _LogitechGSDK.LogiLedRestoreLighting();
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger?.Dispose(); }
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
Devices = Enumerable.Empty<IRGBDevice>();
try { _LogitechGSDK.LogiLedRestoreLighting(); }
catch { /* at least we tried */ }

View File

@ -26,7 +26,7 @@ namespace RGB.NET.Devices.Logitech
#region Methods
/// <inheritdoc />
protected override object? GetLedCustomData(LedId ledId) => (ledId, PerKeyIdMapping.DEFAULT.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : LogitechLedId.Invalid);
protected override object GetLedCustomData(LedId ledId) => (ledId, PerKeyIdMapping.DEFAULT.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : LogitechLedId.Invalid);
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));

View File

@ -1,5 +1,4 @@
using System;
using RGB.NET.Core;
using RGB.NET.Core;
namespace RGB.NET.Devices.Msi
{

View File

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.Msi.Exceptions;
@ -73,7 +72,7 @@ namespace RGB.NET.Devices.Msi
#region Methods
/// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{
IsInitialized = false;
@ -150,18 +149,17 @@ namespace RGB.NET.Devices.Msi
private void ThrowMsiError(int errorCode) => throw new MysticLightException(errorCode, _MsiSDK.GetErrorMessage(errorCode));
/// <inheritdoc />
public void ResetDevices()
{
//TODO DarthAffe 11.11.2017: Implement
}
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger?.Dispose(); }
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
Devices = Enumerable.Empty<IRGBDevice>();
try { _MsiSDK.UnloadMsiSDK(); }
catch { /* at least we tried */ }
}

View File

@ -1,5 +1,4 @@
using System;
using RGB.NET.Core;
using RGB.NET.Core;
namespace RGB.NET.Devices.Novation
{

View File

@ -59,7 +59,7 @@ namespace RGB.NET.Devices.Novation
#region Methods
/// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{
IsInitialized = false;
@ -106,22 +106,17 @@ namespace RGB.NET.Devices.Novation
return true;
}
/// <inheritdoc />
public void ResetDevices()
{
foreach (IRGBDevice device in Devices)
{
NovationLaunchpadRGBDevice? novationDevice = device as NovationLaunchpadRGBDevice;
novationDevice?.Reset();
}
}
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
Devices = Enumerable.Empty<IRGBDevice>();
}
#endregion

View File

@ -20,7 +20,6 @@ namespace RGB.NET.Devices.Razer
/// </summary>
/// <param name="deviceId">The Id of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The model of the <see cref="IRGBDevice"/>.</param>
/// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> of the layout this keyboard is using.</param>
internal RazerKeyboardRGBDeviceInfo(Guid deviceId, string model)
: base(deviceId, RGBDeviceType.Keyboard, model)
{ }

View File

@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.Razer.Native;
@ -78,7 +77,7 @@ namespace RGB.NET.Devices.Razer
#region Methods
/// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{
if (IsInitialized)
TryUnInit();
@ -189,14 +188,7 @@ namespace RGB.NET.Devices.Razer
return true;
}
/// <inheritdoc />
public void ResetDevices()
{
foreach (IRGBDevice device in Devices)
((IRazerRGBDevice)device).Reset();
}
private void ThrowRazerError(RazerError errorCode) => throw new RazerException(errorCode);
private void TryUnInit()
@ -208,9 +200,14 @@ namespace RGB.NET.Devices.Razer
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger?.Dispose(); }
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
Devices = Enumerable.Empty<IRGBDevice>();
TryUnInit();
// DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit

View File

@ -57,7 +57,7 @@ namespace RGB.NET.Devices.SteelSeries
#region Methods
/// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{
try
{
@ -98,24 +98,18 @@ namespace RGB.NET.Devices.SteelSeries
return true;
}
/// <inheritdoc />
public void ResetDevices()
{
if (IsInitialized)
try
{
SteelSeriesSDK.ResetLeds();
}
catch {/* shit happens */}
}
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger?.Dispose(); }
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
Devices = Enumerable.Empty<IRGBDevice>();
try { SteelSeriesSDK.Dispose(); }
catch { /* shit happens */ }
}

View File

@ -74,7 +74,7 @@ namespace RGB.NET.Devices.WS281X.Arduino
/// <inheritdoc />
public override void Dispose()
{
try { UpdateQueue?.Dispose(); }
try { UpdateQueue.Dispose(); }
catch { /* at least we tried */ }
base.Dispose();

View File

@ -1,5 +1,4 @@
using System;
using RGB.NET.Core;
using RGB.NET.Core;
namespace RGB.NET.Devices.WS281X.Arduino
{

View File

@ -29,7 +29,7 @@ namespace RGB.NET.Devices.WS281X.Arduino
/// <summary>
/// Gets the baud-rate used by the serial-connection.
/// </summary>
public int BaudRate => SerialConnection?.BaudRate ?? 0;
public int BaudRate => SerialConnection.BaudRate;
/// <summary>
/// Gets or sets the name used by this device.

View File

@ -68,7 +68,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard
/// <inheritdoc />
public override void Dispose()
{
try { UpdateQueue?.Dispose(); }
try { UpdateQueue.Dispose(); }
catch { /* at least we tried */ }
base.Dispose();

View File

@ -1,5 +1,4 @@
using System;
using RGB.NET.Core;
using RGB.NET.Core;
namespace RGB.NET.Devices.WS281X.Bitwizard
{

View File

@ -74,7 +74,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
/// <inheritdoc />
public override void Dispose()
{
try { UpdateQueue?.Dispose(); }
try { UpdateQueue.Dispose(); }
catch { /* at least we tried */ }
base.Dispose();

View File

@ -1,5 +1,4 @@
using System;
using RGB.NET.Core;
using RGB.NET.Core;
namespace RGB.NET.Devices.WS281X.NodeMCU
{

View File

@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.WS281X.NodeMCU;
namespace RGB.NET.Devices.WS281X
{
@ -70,7 +69,7 @@ namespace RGB.NET.Devices.WS281X
public void AddDeviceDefinition(IWS281XDeviceDefinition deviceDefinition) => DeviceDefinitions.Add(deviceDefinition);
/// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.Unknown, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.Unknown, bool throwExceptions = false)
{
IsInitialized = false;
@ -101,21 +100,18 @@ namespace RGB.NET.Devices.WS281X
return true;
}
/// <inheritdoc />
public void ResetDevices()
{
foreach (IRGBDevice device in Devices)
if (device is NodeMCUWS2812USBDevice nodemcuDevice)
nodemcuDevice.UpdateQueue.ResetDevice();
}
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger?.Dispose(); }
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */}
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
Devices = Enumerable.Empty<IRGBDevice>();
DeviceDefinitions.Clear();
}

View File

@ -46,7 +46,7 @@ namespace RGB.NET.Devices.Wooting.Generic
this.DeviceType = deviceType;
this.DeviceIndex = deviceIndex;
Model = deviceIndex.GetDescription() ?? "Unknown";
Model = deviceIndex.GetDescription();
DeviceName = $"{Manufacturer} {Model}";
}

View File

@ -14,7 +14,7 @@ namespace RGB.NET.Devices.Wooting.Helper
/// </summary>
/// <param name="source">The enum value to get the description from.</param>
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="System.Enum.ToString()" /> result of the source.</returns>
internal static string? GetDescription(this System.Enum source)
internal static string GetDescription(this System.Enum source)
=> source.GetAttribute<DescriptionAttribute>()?.Description ?? source.ToString();
/// <summary>

View File

@ -1,5 +1,4 @@
using System.Globalization;
using RGB.NET.Core;
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum;
using RGB.NET.Devices.Wooting.Generic;

View File

@ -74,7 +74,7 @@ namespace RGB.NET.Devices.Wooting
/// <inheritdoc />
/// <exception cref="RGBDeviceException">Thrown if the SDK failed to initialize</exception>
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{
IsInitialized = false;
@ -113,17 +113,18 @@ namespace RGB.NET.Devices.Wooting
return true;
}
/// <inheritdoc />
public void ResetDevices()
{ }
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
foreach (IRGBDevice device in Devices)
try { device.Dispose(); }
catch { /* at least we tried */ }
Devices = Enumerable.Empty<IRGBDevice>();
try { _WootingSDK.Close(); }
catch { /* Unlucky.. */ }