From d60d4833ca111e3e2febf88cdd81f887ea163fa9 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 5 Feb 2023 07:36:50 +0100 Subject: [PATCH 01/96] Reduced some allocations mostly due to boxing --- .../Color/Behaviors/DefaultColorBehavior.cs | 27 ++++++++++------- .../Color/Behaviors/IColorBehavior.cs | 8 +++++ RGB.NET.Core/Color/Color.cs | 9 +++++- RGB.NET.Core/MVVM/AbstractBindable.cs | 5 ++-- RGB.NET.Core/Positioning/Placeable.cs | 14 ++++----- RGB.NET.Core/Positioning/Point.cs | 18 ++++++----- RGB.NET.Core/Positioning/Rectangle.cs | 30 +++++++------------ RGB.NET.Core/Positioning/Rotation.cs | 2 +- RGB.NET.Core/Positioning/Scale.cs | 5 ++-- RGB.NET.Core/Positioning/Size.cs | 30 ++++++++----------- .../Textures/Sampler/AverageColorSampler.cs | 2 +- 11 files changed, 80 insertions(+), 70 deletions(-) diff --git a/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs b/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs index 69423253..baa3515c 100644 --- a/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs +++ b/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Core; /// /// Represents the default-behavior for the work with colors. /// -public class DefaultColorBehavior : IColorBehavior +public sealed class DefaultColorBehavior : IColorBehavior { #region Methods @@ -14,7 +14,7 @@ public class DefaultColorBehavior : IColorBehavior /// Converts the individual byte values of this to a human-readable string. /// /// A string that contains the individual byte values of this . For example "[A: 255, R: 255, G: 0, B: 0]". - public virtual string ToString(in Color color) => $"[A: {color.GetA()}, R: {color.GetR()}, G: {color.GetG()}, B: {color.GetB()}]"; + public string ToString(in Color color) => $"[A: {color.GetA()}, R: {color.GetR()}, G: {color.GetG()}, B: {color.GetB()}]"; /// /// Tests whether the specified object is a and is equivalent to this . @@ -22,28 +22,35 @@ public class DefaultColorBehavior : IColorBehavior /// The color to test. /// The object to test. /// true if is a equivalent to this ; otherwise, false. - public virtual bool Equals(in Color color, object? obj) + public bool Equals(in Color color, object? obj) { if (obj is not Color color2) return false; - - return color.A.EqualsInTolerance(color2.A) - && color.R.EqualsInTolerance(color2.R) - && color.G.EqualsInTolerance(color2.G) - && color.B.EqualsInTolerance(color2.B); + return Equals(color, color2); } + /// + /// Tests whether the specified object is a and is equivalent to this . + /// + /// The first color to test. + /// The second color to test. + /// true if equivalent to this ; otherwise, false. + public bool Equals(in Color color, in Color color2) => color.A.EqualsInTolerance(color2.A) + && color.R.EqualsInTolerance(color2.R) + && color.G.EqualsInTolerance(color2.G) + && color.B.EqualsInTolerance(color2.B); + /// /// Returns a hash code for this . /// /// An integer value that specifies the hash code for this . - public virtual int GetHashCode(in Color color) => HashCode.Combine(color.A, color.R, color.G, color.B); + public int GetHashCode(in Color color) => HashCode.Combine(color.A, color.R, color.G, color.B); /// /// Blends a over this color. /// /// The to to blend over. /// The to blend. - public virtual Color Blend(in Color baseColor, in Color blendColor) + public Color Blend(in Color baseColor, in Color blendColor) { if (blendColor.A.EqualsInTolerance(0)) return baseColor; diff --git a/RGB.NET.Core/Color/Behaviors/IColorBehavior.cs b/RGB.NET.Core/Color/Behaviors/IColorBehavior.cs index 29b66147..f365f37e 100644 --- a/RGB.NET.Core/Color/Behaviors/IColorBehavior.cs +++ b/RGB.NET.Core/Color/Behaviors/IColorBehavior.cs @@ -20,6 +20,14 @@ public interface IColorBehavior /// true if is a equivalent to this ; otherwise, false. bool Equals(in Color color, object? obj); + /// + /// Tests whether the specified object is a and is equivalent to this . + /// + /// The first color to test. + /// The second color to test. + /// true if equivalent to this ; otherwise, false. + bool Equals(in Color color, in Color color2); + /// /// Returns a hash code for this . /// diff --git a/RGB.NET.Core/Color/Color.cs b/RGB.NET.Core/Color/Color.cs index ae775d37..c7865026 100644 --- a/RGB.NET.Core/Color/Color.cs +++ b/RGB.NET.Core/Color/Color.cs @@ -11,7 +11,7 @@ namespace RGB.NET.Core; /// Represents an ARGB (alpha, red, green, blue) color. /// [DebuggerDisplay("[A: {A}, R: {R}, G: {G}, B: {B}]")] -public readonly struct Color +public readonly struct Color : IEquatable { #region Constants @@ -196,6 +196,13 @@ public Color(in Color color) /// true if is a equivalent to this ; otherwise, false. public override bool Equals(object? obj) => Behavior.Equals(this, obj); + /// + /// Tests whether the specified is equivalent to this , as defined by the current . + /// + /// The color to test. + /// true if is equivalent to this ; otherwise, false. + public bool Equals(Color other) => Behavior.Equals(this, other); + /// /// Returns a hash code for this , as defined by the current . /// diff --git a/RGB.NET.Core/MVVM/AbstractBindable.cs b/RGB.NET.Core/MVVM/AbstractBindable.cs index c58c1aed..b12f302a 100644 --- a/RGB.NET.Core/MVVM/AbstractBindable.cs +++ b/RGB.NET.Core/MVVM/AbstractBindable.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System.Collections.Generic; +using System.ComponentModel; using System.Runtime.CompilerServices; namespace RGB.NET.Core; @@ -28,7 +29,7 @@ public abstract class AbstractBindable : IBindable /// Value to apply. /// true if the value needs to be updated; otherweise false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected virtual bool RequiresUpdate(ref T storage, T value) => !Equals(storage, value); + protected virtual bool RequiresUpdate(ref T storage, T value) => !EqualityComparer.Default.Equals(storage, value); /// /// Checks if the property already matches the desired value and updates it if not. diff --git a/RGB.NET.Core/Positioning/Placeable.cs b/RGB.NET.Core/Positioning/Placeable.cs index 29ca5518..81b6d82a 100644 --- a/RGB.NET.Core/Positioning/Placeable.cs +++ b/RGB.NET.Core/Positioning/Placeable.cs @@ -211,7 +211,7 @@ protected virtual void UpdateActualPlaceableData() /// protected virtual void OnLocationChanged() { - LocationChanged?.Invoke(this, new EventArgs()); + LocationChanged?.Invoke(this, EventArgs.Empty); UpdateActualPlaceableData(); } @@ -220,7 +220,7 @@ protected virtual void OnLocationChanged() /// protected virtual void OnSizeChanged() { - SizeChanged?.Invoke(this, new EventArgs()); + SizeChanged?.Invoke(this, EventArgs.Empty); UpdateActualPlaceableData(); } @@ -229,7 +229,7 @@ protected virtual void OnSizeChanged() /// protected virtual void OnScaleChanged() { - ScaleChanged?.Invoke(this, new EventArgs()); + ScaleChanged?.Invoke(this, EventArgs.Empty); UpdateActualPlaceableData(); } @@ -238,24 +238,24 @@ protected virtual void OnScaleChanged() /// protected virtual void OnRotationChanged() { - RotationChanged?.Invoke(this, new EventArgs()); + RotationChanged?.Invoke(this, EventArgs.Empty); UpdateActualPlaceableData(); } /// /// Called when the property was changed. /// - protected virtual void OnActualLocationChanged() => ActualLocationChanged?.Invoke(this, new EventArgs()); + protected virtual void OnActualLocationChanged() => ActualLocationChanged?.Invoke(this, EventArgs.Empty); /// /// Called when the property was changed. /// - protected virtual void OnActualSizeChanged() => ActualSizeChanged?.Invoke(this, new EventArgs()); + protected virtual void OnActualSizeChanged() => ActualSizeChanged?.Invoke(this, EventArgs.Empty); /// /// Called when the property was changed. /// - protected virtual void OnBoundaryChanged() => BoundaryChanged?.Invoke(this, new EventArgs()); + protected virtual void OnBoundaryChanged() => BoundaryChanged?.Invoke(this, EventArgs.Empty); #endregion } \ No newline at end of file diff --git a/RGB.NET.Core/Positioning/Point.cs b/RGB.NET.Core/Positioning/Point.cs index e2f3d97c..e92c65f3 100644 --- a/RGB.NET.Core/Positioning/Point.cs +++ b/RGB.NET.Core/Positioning/Point.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Core; /// Represents a point consisting of a X- and a Y-position. /// [DebuggerDisplay("[X: {X}, Y: {Y}]")] -public readonly struct Point +public readonly struct Point : IEquatable { #region Constants @@ -59,18 +59,20 @@ public Point(float x, float y) /// A string that contains the and of this . For example "[X: 100, Y: 20]". public override string ToString() => $"[X: {X}, Y: {Y}]"; + /// + /// Tests whether the specified is equivalent to this . + /// + /// The point to test. + /// true if is equivalent to this ; otherwise, false. + public bool Equals(Point other) => ((float.IsNaN(X) && float.IsNaN(other.X)) || X.EqualsInTolerance(other.X)) + && ((float.IsNaN(Y) && float.IsNaN(other.Y)) || Y.EqualsInTolerance(other.Y)); + /// /// Tests whether the specified object is a and is equivalent to this . /// /// The object to test. /// true if is a equivalent to this ; otherwise, false. - public override bool Equals(object? obj) - { - if (obj is not Point comparePoint) return false; - - return ((float.IsNaN(X) && float.IsNaN(comparePoint.X)) || X.EqualsInTolerance(comparePoint.X)) - && ((float.IsNaN(Y) && float.IsNaN(comparePoint.Y)) || Y.EqualsInTolerance(comparePoint.Y)); - } + public override bool Equals(object? obj) => obj is Point other && Equals(other); /// /// Returns a hash code for this . diff --git a/RGB.NET.Core/Positioning/Rectangle.cs b/RGB.NET.Core/Positioning/Rectangle.cs index a1789895..456a5684 100644 --- a/RGB.NET.Core/Positioning/Rectangle.cs +++ b/RGB.NET.Core/Positioning/Rectangle.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Core; /// Represents a rectangle defined by it's position and it's size. /// [DebuggerDisplay("[Location: {Location}, Size: {Size}]")] -public readonly struct Rectangle +public readonly struct Rectangle : IEquatable { #region Properties & Fields @@ -172,35 +172,25 @@ private static (Point location, Size size) InitializeFromPoints(in Point point1, /// A string that contains the and of this . For example "[Location: [X: 100, Y: 10], Size: [Width: 20, Height: [40]]". public override string ToString() => $"[Location: {Location}, Size: {Size}]"; + /// + /// Tests whether the specified is equivalent to this . + /// + /// The rectangle to test. + /// true if is equivalent to this ; otherwise, false. + public bool Equals(Rectangle other) => (Location == other.Location) && (Size == other.Size); + /// /// Tests whether the specified object is a and is equivalent to this . /// /// The object to test. /// true if is a equivalent to this ; otherwise, false. - public override bool Equals(object? obj) - { - if (obj is not Rectangle compareRect) - return false; - - if (GetType() != compareRect.GetType()) - return false; - - return (Location == compareRect.Location) && (Size == compareRect.Size); - } + public override bool Equals(object? obj) => obj is Rectangle other && Equals(other); /// /// Returns a hash code for this . /// /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - unchecked - { - int hashCode = Location.GetHashCode(); - hashCode = (hashCode * 397) ^ Size.GetHashCode(); - return hashCode; - } - } + public override int GetHashCode() => HashCode.Combine(Location, Size); #endregion diff --git a/RGB.NET.Core/Positioning/Rotation.cs b/RGB.NET.Core/Positioning/Rotation.cs index 58903b77..e204b757 100644 --- a/RGB.NET.Core/Positioning/Rotation.cs +++ b/RGB.NET.Core/Positioning/Rotation.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Core; /// Represents an angular rotation. /// [DebuggerDisplay("[{" + nameof(Degrees) + "}°]")] -public readonly struct Rotation +public readonly struct Rotation : IEquatable { #region Constants diff --git a/RGB.NET.Core/Positioning/Scale.cs b/RGB.NET.Core/Positioning/Scale.cs index 8c884069..973bf9cf 100644 --- a/RGB.NET.Core/Positioning/Scale.cs +++ b/RGB.NET.Core/Positioning/Scale.cs @@ -1,6 +1,7 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global +using System; using System.Diagnostics; namespace RGB.NET.Core; @@ -9,7 +10,7 @@ namespace RGB.NET.Core; /// Represents a scaling. /// [DebuggerDisplay("[Horizontal: {Horizontal}, Vertical: {Vertical}]")] -public readonly struct Scale +public readonly struct Scale : IEquatable { #region Properties & Fields @@ -67,7 +68,7 @@ public Scale(float horizontal, float vertical) /// Returns a hash code for this . /// /// An integer value that specifies the hash code for this . - public override int GetHashCode() { unchecked { return (Horizontal.GetHashCode() * 397) ^ Vertical.GetHashCode(); } } + public override int GetHashCode() => HashCode.Combine(Horizontal, Vertical); /// /// Deconstructs the scale into the horizontal and vertical value. diff --git a/RGB.NET.Core/Positioning/Size.cs b/RGB.NET.Core/Positioning/Size.cs index daba2ff1..1a9a6d63 100644 --- a/RGB.NET.Core/Positioning/Size.cs +++ b/RGB.NET.Core/Positioning/Size.cs @@ -1,6 +1,7 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global +using System; using System.Diagnostics; namespace RGB.NET.Core; @@ -9,7 +10,7 @@ namespace RGB.NET.Core; /// Represents a size consisting of a width and a height. /// [DebuggerDisplay("[Width: {Width}, Height: {Height}]")] -public readonly struct Size +public readonly struct Size : IEquatable { #region Constants @@ -67,33 +68,26 @@ public Size(float width, float height) /// A string that contains the and of this . For example "[Width: 100, Height: 20]". public override string ToString() => $"[Width: {Width}, Height: {Height}]"; + /// + /// Tests whether the specified is equivalent to this . + /// + /// The size to test. + /// true if is equivalent to this ; otherwise, false. + public bool Equals(Size other) => ((float.IsNaN(Width) && float.IsNaN(other.Width)) || Width.EqualsInTolerance(other.Width)) + && ((float.IsNaN(Height) && float.IsNaN(other.Height)) || Height.EqualsInTolerance(other.Height)); + /// /// Tests whether the specified object is a and is equivalent to this . /// /// The object to test. /// true if is a equivalent to this ; otherwise, false. - public override bool Equals(object? obj) - { - if (obj is not Size size) return false; - - (float width, float height) = size; - return ((float.IsNaN(Width) && float.IsNaN(width)) || Width.EqualsInTolerance(width)) - && ((float.IsNaN(Height) && float.IsNaN(height)) || Height.EqualsInTolerance(height)); - } + public override bool Equals(object? obj) => obj is Size other && Equals(other); /// /// Returns a hash code for this . /// /// An integer value that specifies the hash code for this . - public override int GetHashCode() - { - unchecked - { - int hashCode = Width.GetHashCode(); - hashCode = (hashCode * 397) ^ Height.GetHashCode(); - return hashCode; - } - } + public override int GetHashCode() => HashCode.Combine(Width, Height); /// /// Deconstructs the size into the width and height value. diff --git a/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs b/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs index f93d2120..d8fd0061 100644 --- a/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs +++ b/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Core; /// /// Averages all components (A, R, G, B) of the colors separately which isn't ideal in cases where multiple different colors are combined. /// -public class AverageColorSampler : ISampler +public sealed class AverageColorSampler : ISampler { #region Constants From 7c165f51af362a0c8ac08a4b58a68bafe5405d64 Mon Sep 17 00:00:00 2001 From: Markus Mohoritsch Date: Sun, 5 Feb 2023 12:29:40 +0100 Subject: [PATCH 02/96] Add new PID to list of known Lightspeed Receivers Logitech is using a new PID 0xC547 for some of it's Lightspeed receivers. --- RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs b/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs index a536a1ef..69cdce17 100644 --- a/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs +++ b/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs @@ -28,7 +28,8 @@ public class LightspeedHIDLoader : IEnumerable GetWirelessDevices(IReadOnlyDictionary Date: Mon, 6 Feb 2023 13:43:05 +1100 Subject: [PATCH 03/96] Update RazerDeviceProvider.cs Added: - Mouse: Razer Naga Pro - Headset: Razer Nari - Other: Razer Mouse Dock Changed: - Chroma Hardware Development Kit (HDK): This is a LED Controller - Addressable RGB Controller: This is a LED Controller --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 09f1a278..fd34e77f 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -164,6 +164,7 @@ public class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0084, RGBDeviceType.Mouse, "DeathAdder V2", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x008A, RGBDeviceType.Mouse, "Viper Mini", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x008D, RGBDeviceType.Mouse, "Naga Left Handed Edition", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x0090, RGBDeviceType.Mouse, "Naga Pro", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0091, RGBDeviceType.Mouse, "Viper 8khz", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0096, RGBDeviceType.Mouse, "Naga X", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0099, RGBDeviceType.Mouse, "Basilisk v3", LedMappings.Mouse, RazerEndpointType.Mouse }, @@ -182,6 +183,7 @@ public class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0506, RGBDeviceType.Headset, "Kraken 7.1", LedMappings.Headset, RazerEndpointType.Headset }, { 0x0510, RGBDeviceType.Headset, "Kraken 7.1 V2", LedMappings.Headset, RazerEndpointType.Headset }, { 0x051A, RGBDeviceType.Headset, "Nari Ultimate", LedMappings.Headset, RazerEndpointType.Headset }, + { 0x051C, RGBDeviceType.Headset, "Nari", LedMappings.Headset, RazerEndpointType.Headset }, { 0x0527, RGBDeviceType.Headset, "Kraken Ultimate", LedMappings.Headset, RazerEndpointType.Headset }, { 0x0F19, RGBDeviceType.Headset, "Kraken Kitty Edition", LedMappings.Headset, RazerEndpointType.Headset }, @@ -198,13 +200,15 @@ public class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0215, RGBDeviceType.GraphicsCard, "Core", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F08, RGBDeviceType.HeadsetStand, "Base Station Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, // DarthAffe 16.12.2022: Not tested but based on the V2 I assume this is also a mousepad { 0x0F20, RGBDeviceType.HeadsetStand, "Base Station V2 Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, // DarthAffe 16.12.2022: Not sure why, but it's handled as a mousepad + { 0x007E, RGBDeviceType.LedStripe, "Razer Mouse Dock Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, //roxaskeyheart 06.02.2023: Probably handled the same as a mousepad { 0x0517, RGBDeviceType.Speaker, "Nommo Chroma", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0518, RGBDeviceType.Speaker, "Nommo Pro", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F07, RGBDeviceType.Unknown, "Chroma Mug Holder", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, - { 0x0F09, RGBDeviceType.Unknown, "Chroma Hardware Development Kit (HDK)", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, + { 0x0F09, RGBDeviceType.LedController, "Chroma Hardware Development Kit (HDK)", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F13, RGBDeviceType.Unknown, "Lian Li O11", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F1D, RGBDeviceType.Unknown, "Mouse Bungee V3 Chroma", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, - { 0x0F1F, RGBDeviceType.Unknown, "Addressable RGB Controller", LedMappings.ChromaLink, RazerEndpointType.ChromaLink } + { 0x0F1F, RGBDeviceType.LedController, "Addressable RGB Controller", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, + }; #endregion From 43ecc7374e12219ee06b27545851e852efb295ad Mon Sep 17 00:00:00 2001 From: Danielle Date: Mon, 6 Feb 2023 13:47:34 +1100 Subject: [PATCH 04/96] Update RazerDeviceProvider.cs --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index fd34e77f..daeec434 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -164,7 +164,8 @@ public class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0084, RGBDeviceType.Mouse, "DeathAdder V2", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x008A, RGBDeviceType.Mouse, "Viper Mini", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x008D, RGBDeviceType.Mouse, "Naga Left Handed Edition", LedMappings.Mouse, RazerEndpointType.Mouse }, - { 0x0090, RGBDeviceType.Mouse, "Naga Pro", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x008F, RGBDeviceType.Mouse, "Naga Pro", LedMappings.Mouse, RazerEndpointType.Mouse }, //this is via usb connection + { 0x0090, RGBDeviceType.Mouse, "Naga Pro", LedMappings.Mouse, RazerEndpointType.Mouse }, //this is via bluetooth connection { 0x0091, RGBDeviceType.Mouse, "Viper 8khz", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0096, RGBDeviceType.Mouse, "Naga X", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0099, RGBDeviceType.Mouse, "Basilisk v3", LedMappings.Mouse, RazerEndpointType.Mouse }, From 180b0e45383007920e7a883a746916dc972b73eb Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Fri, 10 Feb 2023 19:23:34 +0100 Subject: [PATCH 05/96] Updated corsair SDK to iCUE SDK v4.0.48 --- RGB.NET.Core/Leds/LedMapping.cs | 6 + .../Cooler/CorsairCoolerRGBDevice.cs | 34 + .../Cooler/CorsairCoolerRGBDeviceInfo.cs | 28 + .../CorsairDeviceProvider.cs | 293 +-- .../Custom/CorsairCustomRGBDevice.cs | 74 - .../Custom/CorsairCustomRGBDeviceInfo.cs | 155 -- .../Enum/CorsairAccessLevel.cs | 30 + .../Enum/CorsairAccessMode.cs | 14 - .../Enum/CorsairChannelDeviceType.cs | 18 +- .../Enum/CorsairDataType.cs | 47 + .../Enum/CorsairDeviceCaps.cs | 28 - .../Enum/CorsairDevicePropertyId.cs | 77 + .../Enum/CorsairDeviceType.cs | 90 +- RGB.NET.Devices.Corsair/Enum/CorsairError.cs | 37 +- .../Enum/CorsairLedGroup.cs | 82 + RGB.NET.Devices.Corsair/Enum/CorsairLedId.cs | 1742 ----------------- .../Enum/CorsairLedIdKeyboard.cs | 142 ++ .../Enum/CorsairLogicalKeyboardLayout.cs | 4 +- .../Enum/CorsairPhysicalKeyboardLayout.cs | 28 +- .../Enum/CorsairPhysicalMouseLayout.cs | 107 - .../Enum/CorsairPropertyFlag.cs | 30 + .../Enum/CorsairSessionState.cs | 45 + .../Fan/CorsairFanRGBDevice.cs | 34 + .../Fan/CorsairFanRGBDeviceInfo.cs | 28 + .../Generic/CorsairDeviceUpdateQueue.cs | 46 +- .../Generic/CorsairLedId.cs | 54 + .../Generic/CorsairProtocolDetails.cs | 65 - .../Generic/CorsairRGBDevice.cs | 41 +- .../Generic/CorsairRGBDeviceInfo.cs | 36 +- .../Generic/LedMappings.cs | 476 ++--- .../CorsairGraphicsCardRGBDevice.cs | 9 +- .../CorsairGraphicsCardRGBDeviceInfo.cs | 9 +- .../Headset/CorsairHeadsetRGBDevice.cs | 9 +- .../Headset/CorsairHeadsetRGBDeviceInfo.cs | 9 +- .../CorsairHeadsetStandRGBDevice.cs | 9 +- .../CorsairHeadsetStandRGBDeviceInfo.cs | 9 +- .../Helper/NativeExtensions.cs | 26 +- .../Keyboard/CorsairKeyboardRGBDevice.cs | 9 +- .../Keyboard/CorsairKeyboardRGBDeviceInfo.cs | 9 +- .../LedStrip/CorsairLedStripGBDevice.cs | 34 + .../LedStrip/CorsairLedStripRGBDeviceInfo.cs | 28 + .../Mainboard/CorsairMainboardRGBDevice.cs | 9 +- .../CorsairMainboardRGBDeviceInfo.cs | 9 +- .../Memory/CorsairMemoryRGBDevice.cs | 9 +- .../Memory/CorsairMemoryRGBDeviceInfo.cs | 14 +- .../Mouse/CorsairMouseRGBDevice.cs | 9 +- .../Mouse/CorsairMouseRGBDeviceInfo.cs | 22 +- .../Mousepad/CorsairMousepadRGBDevice.cs | 9 +- .../Mousepad/CorsairMousepadRGBDeviceInfo.cs | 9 +- RGB.NET.Devices.Corsair/Native/_CUESDK.cs | 359 +++- .../Native/_CorsairChannelInfo.cs | 33 - .../Native/_CorsairDataValue.cs | 140 ++ ...hannelsInfo.cs => _CorsairDeviceFilter.cs} | 30 +- .../Native/_CorsairDeviceInfo.cs | 39 +- .../Native/_CorsairLedColor.cs | 44 +- .../Native/_CorsairLedPosition.cs | 30 +- .../Native/_CorsairLedPositions.cs | 26 - ...annelDeviceInfo.cs => _CorsairProperty.cs} | 19 +- .../Native/_CorsairProtocolDetails.cs | 43 - .../Native/_CorsairSessionDetails.cs | 32 + .../Native/_CorsairSessionStateChanged.cs | 27 + .../Native/_CorsairVersion.cs | 31 + RGB.NET.Devices.Corsair/README.md | 6 +- ...RGB.NET.Devices.Corsair.csproj.DotSettings | 5 + .../Touchbar/CorsairTouchbarRGBDevice.cs | 11 +- .../Touchbar/CorsairTouchbarRGBDeviceInfo.cs | 9 +- .../Unknown/CorsairUnknownRGBDevice.cs | 34 + .../Unknown/CorsairUnknownRGBDeviceInfo.cs | 23 + 68 files changed, 1999 insertions(+), 3083 deletions(-) create mode 100644 RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDeviceInfo.cs delete mode 100644 RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs delete mode 100644 RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairAccessLevel.cs delete mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairAccessMode.cs create mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairDataType.cs delete mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairDeviceCaps.cs create mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairDevicePropertyId.cs create mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs delete mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairLedId.cs create mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairLedIdKeyboard.cs delete mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairPhysicalMouseLayout.cs create mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairPropertyFlag.cs create mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairSessionState.cs create mode 100644 RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair/Generic/CorsairLedId.cs delete mode 100644 RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs create mode 100644 RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripRGBDeviceInfo.cs delete mode 100644 RGB.NET.Devices.Corsair/Native/_CorsairChannelInfo.cs create mode 100644 RGB.NET.Devices.Corsair/Native/_CorsairDataValue.cs rename RGB.NET.Devices.Corsair/Native/{_CorsairChannelsInfo.cs => _CorsairDeviceFilter.cs} (50%) delete mode 100644 RGB.NET.Devices.Corsair/Native/_CorsairLedPositions.cs rename RGB.NET.Devices.Corsair/Native/{_CorsairChannelDeviceInfo.cs => _CorsairProperty.cs} (60%) delete mode 100644 RGB.NET.Devices.Corsair/Native/_CorsairProtocolDetails.cs create mode 100644 RGB.NET.Devices.Corsair/Native/_CorsairSessionDetails.cs create mode 100644 RGB.NET.Devices.Corsair/Native/_CorsairSessionStateChanged.cs create mode 100644 RGB.NET.Devices.Corsair/Native/_CorsairVersion.cs create mode 100644 RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDeviceInfo.cs diff --git a/RGB.NET.Core/Leds/LedMapping.cs b/RGB.NET.Core/Leds/LedMapping.cs index e2866d39..05a10ec3 100644 --- a/RGB.NET.Core/Leds/LedMapping.cs +++ b/RGB.NET.Core/Leds/LedMapping.cs @@ -11,6 +11,12 @@ namespace RGB.NET.Core; public class LedMapping : IEnumerable<(LedId ledId, T mapping)> where T : notnull { + #region Constants + + public static LedMapping Empty { get; } = new(); + + #endregion + #region Properties & Fields private readonly Dictionary _mapping = new(); diff --git a/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDevice.cs b/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDevice.cs new file mode 100644 index 00000000..fd5b89b8 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDevice.cs @@ -0,0 +1,34 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using System.Collections.Generic; + +namespace RGB.NET.Devices.Corsair; + +/// +/// +/// Represents a corsair cooler. +/// +public class CorsairCoolerRGBDevice : CorsairRGBDevice, ICooler +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the cooler. + /// The queue used to update this device. + internal CorsairCoolerRGBDevice(CorsairCoolerRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, updateQueue) + { } + + #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateCoolerMapping(ids); + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDeviceInfo.cs new file mode 100644 index 00000000..958f129f --- /dev/null +++ b/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDeviceInfo.cs @@ -0,0 +1,28 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using RGB.NET.Devices.Corsair.Native; + +namespace RGB.NET.Devices.Corsair; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairCoolerRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + internal CorsairCoolerRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.Cooler, nativeInfo, ledCount, ledOffset) + { } + + /// + internal CorsairCoolerRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset, string modelName) + : base(RGBDeviceType.Cooler, nativeInfo, ledCount, ledOffset, modelName) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 7acd75e4..7a1abe0e 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -3,8 +3,7 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; +using System.Threading; using RGB.NET.Core; using RGB.NET.Devices.Corsair.Native; @@ -28,23 +27,23 @@ public class CorsairDeviceProvider : AbstractRGBDeviceProvider /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/CUESDK.dll", "x86/CUESDK_2019.dll", "x86/CUESDK_2017.dll", "x86/CUESDK_2015.dll", "x86/CUESDK_2013.dll" }; + public static List PossibleX86NativePaths { get; } = new() { "x86/iCUESDK.dll", "x86/CUESDK_2019.dll" }; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll", "x64/CUESDK.x64_2017.dll", "x64/CUESDK_2019.dll", "x64/CUESDK_2017.dll", "x64/CUESDK_2015.dll", "x64/CUESDK_2013.dll" }; + public static List PossibleX64NativePaths { get; } = new() { "x64/iCUESDK.dll", "x64/iCUESDK.x64_2019.dll", "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll" }; /// - /// Gets the protocol details for the current SDK-connection. + /// Gets or sets the timeout used when connecting to the SDK. /// - public CorsairProtocolDetails? ProtocolDetails { get; private set; } + public static TimeSpan ConnectionTimeout { get; set; } = TimeSpan.FromMilliseconds(500); /// - /// Gets the last error documented by CUE. + /// Gets or sets a bool indicating if exclusive request should be requested through the iCUE-SDK. /// - public static CorsairError LastError => _CUESDK.CorsairGetLastError(); + public static bool ExclusiveAccess { get; set; } = false; #endregion @@ -64,25 +63,35 @@ public CorsairDeviceProvider() #region Methods - /// protected override void InitializeSDK() { _CUESDK.Reload(); - ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake()); + using ManualResetEventSlim waitEvent = new(false); - CorsairError error = LastError; - if (error != CorsairError.Success) - Throw(new CUEException(error), true); + void OnSessionStateChanged(object? sender, CorsairSessionState state) + { + if (state == CorsairSessionState.Connected) + // ReSharper disable once AccessToDisposedClosure + waitEvent.Set(); + } - if (ProtocolDetails.BreakingChanges) - Throw(new RGBDeviceException("The SDK currently used isn't compatible with the installed version of CUE.\r\n" - + $"CUE-Version: {ProtocolDetails.ServerVersion} (Protocol {ProtocolDetails.ServerProtocolVersion})\r\n" - + $"SDK-Version: {ProtocolDetails.SdkVersion} (Protocol {ProtocolDetails.SdkProtocolVersion})"), true); + try + { + _CUESDK.SessionStateChanged += OnSessionStateChanged; + + CorsairError errorCode = _CUESDK.CorsairConnect(); - // DarthAffe 02.02.2021: 127 is iCUE - if (!_CUESDK.CorsairSetLayerPriority(128)) - Throw(new CUEException(LastError)); + if (errorCode != CorsairError.Success) + Throw(new RGBDeviceException($"Failed to initialized Corsair-SDK. (ErrorCode: {errorCode})")); + + if (!waitEvent.Wait(ConnectionTimeout)) + Throw(new RGBDeviceException($"Failed to initialized Corsair-SDK. (Timeout - Current connection state: {_CUESDK.SesionState})")); + } + finally + { + _CUESDK.SessionStateChanged -= OnSessionStateChanged; + } } /// @@ -97,107 +106,165 @@ protected override IEnumerable LoadDevices() private IEnumerable LoadCorsairDevices() { - int deviceCount = _CUESDK.CorsairGetDeviceCount(); - for (int i = 0; i < deviceCount; i++) - { - _CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo))!; - if (!((CorsairDeviceCaps)nativeDeviceInfo.capsMask).HasFlag(CorsairDeviceCaps.Lighting)) - continue; // Everything that doesn't support lighting control is useless + CorsairError error = _CUESDK.CorsairGetDevices(new _CorsairDeviceFilter(CorsairDeviceType.All), out _CorsairDeviceInfo[] devices); + if (error != CorsairError.Success) + Throw(new RGBDeviceException($"Failed to load devices. (ErrorCode: {error})")); - CorsairDeviceUpdateQueue updateQueue = new(GetUpdateTrigger(), i); - switch (nativeDeviceInfo.type) - { - case CorsairDeviceType.Keyboard: - yield return new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); - break; - - case CorsairDeviceType.Mouse: - yield return new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); - break; - - case CorsairDeviceType.Headset: - yield return new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); - break; - - case CorsairDeviceType.Mousepad: - yield return new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); - break; - - case CorsairDeviceType.HeadsetStand: - yield return new CorsairHeadsetStandRGBDevice(new CorsairHeadsetStandRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); - break; - - case CorsairDeviceType.MemoryModule: - yield return new CorsairMemoryRGBDevice(new CorsairMemoryRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); - break; - - case CorsairDeviceType.Mainboard: - yield return new CorsairMainboardRGBDevice(new CorsairMainboardRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); - break; - - case CorsairDeviceType.GraphicsCard: - yield return new CorsairGraphicsCardRGBDevice(new CorsairGraphicsCardRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); - break; - - case CorsairDeviceType.Touchbar: - yield return new CorsairTouchbarRGBDevice(new CorsairTouchbarRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); - break; - - case CorsairDeviceType.Cooler: - case CorsairDeviceType.CommanderPro: - case CorsairDeviceType.LightningNodePro: - List<_CorsairChannelInfo> channels = GetChannels(nativeDeviceInfo).ToList(); - int channelsLedCount = channels.Sum(x => x.totalLedsCount); - int deviceLedCount = nativeDeviceInfo.ledsCount - channelsLedCount; - - if (deviceLedCount > 0) - yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(i, nativeDeviceInfo, deviceLedCount), updateQueue); - - int ledOffset = deviceLedCount; - foreach (_CorsairChannelInfo channelInfo in channels) - { - int channelDeviceInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelDeviceInfo)); - IntPtr channelDeviceInfoPtr = channelInfo.devices; - for (int device = 0; (device < channelInfo.devicesCount) && (ledOffset < nativeDeviceInfo.ledsCount); device++) - { - _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo))!; + foreach (_CorsairDeviceInfo device in devices) + { + if (string.IsNullOrWhiteSpace(device.id)) continue; - yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(i, nativeDeviceInfo, channelDeviceInfo, ledOffset), updateQueue); + error = _CUESDK.CorsairRequestControl(device.id, ExclusiveAccess ? CorsairAccessLevel.ExclusiveLightingControl : CorsairAccessLevel.Shared); + if (error != CorsairError.Success) + Throw(new RGBDeviceException($"Failed to take control of device '{device.id}'. (ErrorCode: {error})")); - ledOffset += channelDeviceInfo.deviceLedCount; - channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize); - } - } - break; + CorsairDeviceUpdateQueue updateQueue = new(GetUpdateTrigger(), device); - default: - Throw(new RGBDeviceException("Unknown Device-Type")); - break; + Console.WriteLine("Loading " + device.model); + int channelLedCount = 0; + for (int i = 0; i < device.channelCount; i++) + { + Console.WriteLine($"Channel {i}/{device.channelCount}"); + channelLedCount += _CUESDK.ReadDevicePropertySimpleInt32(device.id!, CorsairDevicePropertyId.ChannelLedCount, (uint)i); } - } - } - private static IEnumerable<_CorsairChannelInfo> GetChannels(_CorsairDeviceInfo deviceInfo) - { - _CorsairChannelsInfo? channelsInfo = deviceInfo.channels; - if (channelsInfo == null) yield break; + int deviceLedCount = device.ledCount - channelLedCount; + if (deviceLedCount > 0) + switch (device.type) + { + case CorsairDeviceType.Keyboard: + yield return new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + + case CorsairDeviceType.Mouse: + yield return new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + + case CorsairDeviceType.Headset: + yield return new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + + case CorsairDeviceType.Mousemat: + yield return new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + + case CorsairDeviceType.HeadsetStand: + yield return new CorsairHeadsetStandRGBDevice(new CorsairHeadsetStandRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + + case CorsairDeviceType.MemoryModule: + yield return new CorsairMemoryRGBDevice(new CorsairMemoryRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + + case CorsairDeviceType.Motherboard: + yield return new CorsairMainboardRGBDevice(new CorsairMainboardRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + + case CorsairDeviceType.GraphicsCard: + yield return new CorsairGraphicsCardRGBDevice(new CorsairGraphicsCardRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + + case CorsairDeviceType.Touchbar: + yield return new CorsairTouchbarRGBDevice(new CorsairTouchbarRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + + case CorsairDeviceType.Cooler: + yield return new CorsairCoolerRGBDevice(new CorsairCoolerRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + + case CorsairDeviceType.FanLedController: + case CorsairDeviceType.LedController: + case CorsairDeviceType.Unknown: + yield return new CorsairUnknownRGBDevice(new CorsairUnknownRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + + default: + Throw(new RGBDeviceException("Unknown Device-Type")); + break; + } + + int offset = deviceLedCount; + for (int i = 0; i < device.channelCount; i++) + { + int deviceCount = _CUESDK.ReadDevicePropertySimpleInt32(device.id!, CorsairDevicePropertyId.ChannelDeviceCount, (uint)i); + if (deviceCount <= 0) continue; // DarthAffe 10.02.2023: There seem to be an issue in the SDK where it reports empty channels and fails when getting ledCounts and device types from them - IntPtr channelInfoPtr = channelsInfo.channels; - for (int channel = 0; channel < channelsInfo.channelsCount; channel++) - { - yield return (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo))!; + int[] ledCounts = _CUESDK.ReadDevicePropertySimpleInt32Array(device.id!, CorsairDevicePropertyId.ChannelDeviceLedCountArray, (uint)i); + int[] deviceTypes = _CUESDK.ReadDevicePropertySimpleInt32Array(device.id!, CorsairDevicePropertyId.ChannelDeviceTypeArray, (uint)i); - int channelInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelInfo)); - channelInfoPtr = new IntPtr(channelInfoPtr.ToInt64() + channelInfoStructSize); - } - } + for (int j = 0; j < deviceCount; j++) + { + CorsairChannelDeviceType deviceType = (CorsairChannelDeviceType)deviceTypes[j]; + int ledCount = ledCounts[j]; - /// - protected override void Reset() - { - ProtocolDetails = null; + switch (deviceType) + { + case CorsairChannelDeviceType.FanHD: + yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "HD Fan"), updateQueue); + break; + + case CorsairChannelDeviceType.FanSP: + yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "SP Fan"), updateQueue); + break; + + case CorsairChannelDeviceType.FanLL: + yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "LL Fan"), updateQueue); + break; + + case CorsairChannelDeviceType.FanML: + yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "ML Fan"), updateQueue); + break; + + case CorsairChannelDeviceType.FanQL: + yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "QL Fan"), updateQueue); + break; + + case CorsairChannelDeviceType.EightLedSeriesFan: + yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "8-Led-Series Fan Fan"), updateQueue); + break; + + case CorsairChannelDeviceType.DAP: + yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "DAP Fan"), updateQueue); + break; + + case CorsairChannelDeviceType.Pump: + yield return new CorsairCoolerRGBDevice(new CorsairCoolerRGBDeviceInfo(device, ledCount, offset, "Pump"), updateQueue); + break; + + case CorsairChannelDeviceType.WaterBlock: + yield return new CorsairCoolerRGBDevice(new CorsairCoolerRGBDeviceInfo(device, ledCount, offset, "Water Block"), updateQueue); + break; + + case CorsairChannelDeviceType.Strip: + string modelName = "LED Strip"; + + // LS100 Led Strips are reported as one big strip if configured in monitor mode in iCUE, 138 LEDs for dual monitor, 84 for single + if ((device.model == "LS100 Starter Kit") && (ledCount == 138)) + modelName = "LS100 LED Strip (dual monitor)"; + else if ((device.model == "LS100 Starter Kit") && (ledCount == 84)) + modelName = "LS100 LED Strip (single monitor)"; + // Any other value means an "External LED Strip" in iCUE, these are reported per-strip, 15 for short strips, 27 for long + else if ((device.model == "LS100 Starter Kit") && (ledCount == 15)) + modelName = "LS100 LED Strip (short)"; + else if ((device.model == "LS100 Starter Kit") && (ledCount == 27)) + modelName = "LS100 LED Strip (long)"; + + yield return new CorsairLedStripRGBDevice(new CorsairLedStripRGBDeviceInfo(device, ledCount, offset, modelName), updateQueue); + break; + + case CorsairChannelDeviceType.DRAM: + yield return new CorsairMemoryRGBDevice(new CorsairMemoryRGBDeviceInfo(device, ledCount, offset, "DRAM"), updateQueue); + break; + + default: + Throw(new RGBDeviceException("Unknown Device-Type")); + break; + } - base.Reset(); + offset += ledCount; + } + } + } } /// @@ -205,8 +272,8 @@ public override void Dispose() { base.Dispose(); - try { _CUESDK.UnloadCUESDK(); } - catch { /* at least we tried */ } + try { _CUESDK.CorsairDisconnect(); } catch { /* at least we tried */ } + try { _CUESDK.UnloadCUESDK(); } catch { /* at least we tried */ } GC.SuppressFinalize(this); } diff --git a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs deleted file mode 100644 index 1bc3b6e8..00000000 --- a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs +++ /dev/null @@ -1,74 +0,0 @@ -// ReSharper disable MemberCanBePrivate.Global -// ReSharper disable UnusedMember.Global - -using System; -using System.Runtime.InteropServices; -using RGB.NET.Core; -using RGB.NET.Devices.Corsair.Native; - -namespace RGB.NET.Devices.Corsair; - -/// -/// -/// Represents a corsair custom. -/// -public class CorsairCustomRGBDevice : CorsairRGBDevice, IUnknownDevice -{ - #region Constructors - - /// - /// - /// Initializes a new instance of the class. - /// - /// The specific information provided by CUE for the custom-device. - /// The queue used to update this device. - internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, new LedMapping(), updateQueue) - { } - - #endregion - - #region Methods - - /// - protected override void InitializeLayout() - { - Mapping.Clear(); - - _CorsairLedPositions? nativeLedPositions = (_CorsairLedPositions?)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex), typeof(_CorsairLedPositions)); - if (nativeLedPositions == null) return; - - int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); - IntPtr ptr = new(nativeLedPositions.pLedPosition.ToInt64() + (structSize * DeviceInfo.LedOffset)); - - LedId referenceLedId = GetReferenceLed(DeviceInfo.DeviceType); - for (int i = 0; i < DeviceInfo.LedCount; i++) - { - LedId ledId = referenceLedId + i; - _CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition)); - if (ledPosition == null) - { - ptr = new IntPtr(ptr.ToInt64() + structSize); - continue; - } - - Mapping.Add(ledId, ledPosition.LedId); - - Rectangle rectangle = ledPosition.ToRectangle(); - AddLed(ledId, rectangle.Location, rectangle.Size); - - ptr = new IntPtr(ptr.ToInt64() + structSize); - } - } - - private static LedId GetReferenceLed(RGBDeviceType deviceType) - => deviceType switch - { - RGBDeviceType.LedStripe => LedId.LedStripe1, - RGBDeviceType.Fan => LedId.Fan1, - RGBDeviceType.Cooler => LedId.Cooler1, - _ => LedId.Custom1 - }; - - #endregion -} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs deleted file mode 100644 index 5d0858a8..00000000 --- a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs +++ /dev/null @@ -1,155 +0,0 @@ -// ReSharper disable MemberCanBePrivate.Global -// ReSharper disable UnusedMember.Global - -using System; -using System.Runtime.InteropServices; -using System.Text.RegularExpressions; -using RGB.NET.Core; -using RGB.NET.Devices.Corsair.Native; - -namespace RGB.NET.Devices.Corsair; - -/// -/// -/// Represents a generic information for a . -/// -public class CorsairCustomRGBDeviceInfo : CorsairRGBDeviceInfo -{ - #region Properties & Fields - - /// - /// Gets the amount of LEDs this device contains. - /// - public int LedCount { get; } - - /// - /// Gets the offset used to access the LEDs of this device. - /// - internal int LedOffset { get; } - - #endregion - - #region Constructors - - /// - /// - /// Internal constructor of managed . - /// - /// The index of the . - /// The native -struct - /// The native representing this device. - /// The offset used to find the LEDs of this device. - internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, int ledOffset) - : base(deviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo, - GetModelName(nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase), channelDeviceInfo)) - { - this.LedOffset = ledOffset; - - LedCount = channelDeviceInfo.deviceLedCount; - } - - internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, int ledCount) - : base(deviceIndex, GetDeviceType(nativeInfo.type), nativeInfo) - { - this.LedCount = ledCount; - - LedOffset = 0; - } - - #endregion - - #region Methods - - private static RGBDeviceType GetDeviceType(CorsairChannelDeviceType deviceType) - => deviceType switch - { - CorsairChannelDeviceType.Invalid => RGBDeviceType.Unknown, - CorsairChannelDeviceType.FanHD => RGBDeviceType.Fan, - CorsairChannelDeviceType.FanSP => RGBDeviceType.Fan, - CorsairChannelDeviceType.FanLL => RGBDeviceType.Fan, - CorsairChannelDeviceType.FanML => RGBDeviceType.Fan, - CorsairChannelDeviceType.DAP => RGBDeviceType.Fan, - CorsairChannelDeviceType.FanQL => RGBDeviceType.Fan, - CorsairChannelDeviceType.EightLedSeriesFan => RGBDeviceType.Fan, - CorsairChannelDeviceType.Strip => RGBDeviceType.LedStripe, - CorsairChannelDeviceType.Pump => RGBDeviceType.Cooler, - CorsairChannelDeviceType.WaterBlock => RGBDeviceType.Cooler, - _ => throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null) - }; - - private static RGBDeviceType GetDeviceType(CorsairDeviceType deviceType) - => deviceType switch - { - CorsairDeviceType.Unknown => RGBDeviceType.Unknown, - CorsairDeviceType.Mouse => RGBDeviceType.Mouse, - CorsairDeviceType.Keyboard => RGBDeviceType.Keyboard, - CorsairDeviceType.Headset => RGBDeviceType.Headset, - CorsairDeviceType.Mousepad => RGBDeviceType.Mousepad, - CorsairDeviceType.HeadsetStand => RGBDeviceType.HeadsetStand, - CorsairDeviceType.CommanderPro => RGBDeviceType.LedController, - CorsairDeviceType.LightningNodePro => RGBDeviceType.LedController, - CorsairDeviceType.MemoryModule => RGBDeviceType.DRAM, - CorsairDeviceType.Cooler => RGBDeviceType.Cooler, - CorsairDeviceType.Mainboard => RGBDeviceType.Mainboard, - CorsairDeviceType.GraphicsCard => RGBDeviceType.GraphicsCard, - _ => throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null) - }; - - private static string GetModelName(string model, _CorsairChannelDeviceInfo channelDeviceInfo) - { - switch (channelDeviceInfo.type) - { - case CorsairChannelDeviceType.Invalid: - return model; - - case CorsairChannelDeviceType.FanHD: - return "HD Fan"; - - case CorsairChannelDeviceType.FanSP: - return "SP Fan"; - - case CorsairChannelDeviceType.FanLL: - return "LL Fan"; - - case CorsairChannelDeviceType.FanML: - return "ML Fan"; - - case CorsairChannelDeviceType.FanQL: - return "QL Fan"; - - case CorsairChannelDeviceType.EightLedSeriesFan: - return "8-Led-Series Fan Fan"; - - case CorsairChannelDeviceType.Strip: - // LS100 Led Strips are reported as one big strip if configured in monitor mode in iCUE, 138 LEDs for dual monitor, 84 for single - if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 138)) - return "LS100 LED Strip (dual monitor)"; - else if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 84)) - return "LS100 LED Strip (single monitor)"; - // Any other value means an "External LED Strip" in iCUE, these are reported per-strip, 15 for short strips, 27 for long - else if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 15)) - return "LS100 LED Strip (short)"; - else if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 27)) - return "LS100 LED Strip (long)"; - // Device model is "Commander Pro" for regular LED strips - else - return "LED Strip"; - - case CorsairChannelDeviceType.DAP: - return "DAP Fan"; - - case CorsairChannelDeviceType.WaterBlock: - return "Water Block"; - - case CorsairChannelDeviceType.Pump: - return "Pump"; - - default: -#pragma warning disable CA2208 // Instantiate argument exceptions correctly - throw new ArgumentOutOfRangeException($"{nameof(channelDeviceInfo)}.{nameof(channelDeviceInfo.type)}", channelDeviceInfo.type, null); -#pragma warning restore CA2208 // Instantiate argument exceptions correctly - } - } - - #endregion -} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairAccessLevel.cs b/RGB.NET.Devices.Corsair/Enum/CorsairAccessLevel.cs new file mode 100644 index 00000000..33a87e03 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Enum/CorsairAccessLevel.cs @@ -0,0 +1,30 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global + +namespace RGB.NET.Devices.Corsair; + +/// +/// iCUE-SDK: Represents an SDK access level. +/// +public enum CorsairAccessLevel +{ + /// + /// iCUE-SDK: shared mode (default) + /// + Shared = 0, + + /// + /// iCUE-SDK: exclusive lightings, but shared events + /// + ExclusiveLightingControl = 1, + + /// + /// iCUE-SDK: exclusive key events, but shared lightings + /// + ExclusiveKeyEventsListening = 2, + + /// + /// iCUE-SDK: exclusive mode + /// + ExclusiveLightingControlAndKeyEventsListening = 3 +}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairAccessMode.cs b/RGB.NET.Devices.Corsair/Enum/CorsairAccessMode.cs deleted file mode 100644 index 1ecdda4b..00000000 --- a/RGB.NET.Devices.Corsair/Enum/CorsairAccessMode.cs +++ /dev/null @@ -1,14 +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.Corsair; - -/// -/// Represents an SDK access mode. -/// -public enum CorsairAccessMode -{ - ExclusiveLightingControl = 0 -}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs b/RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs index 8c89470c..65a38fad 100644 --- a/RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs +++ b/RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs @@ -1,13 +1,10 @@ // ReSharper disable InconsistentNaming // ReSharper disable UnusedMember.Global - -#pragma warning disable 1591 // Missing XML comment for publicly visible type or member - namespace RGB.NET.Devices.Corsair; /// -/// Contains a list of available corsair channel device types. +/// iCUE-SDK: Contains a list of available corsair channel device types. /// public enum CorsairChannelDeviceType { @@ -16,10 +13,11 @@ public enum CorsairChannelDeviceType FanSP = 2, FanLL = 3, FanML = 4, - Strip = 5, - DAP = 6, - Pump = 7, - FanQL = 8, - WaterBlock = 9, - EightLedSeriesFan = 10 // Previously called FanSPPRO + FanQL = 5, + EightLedSeriesFan = 6, + Strip = 7, + DAP = 8, + Pump = 9, + DRAM = 10, + WaterBlock = 11, }; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairDataType.cs b/RGB.NET.Devices.Corsair/Enum/CorsairDataType.cs new file mode 100644 index 00000000..e9bf894d --- /dev/null +++ b/RGB.NET.Devices.Corsair/Enum/CorsairDataType.cs @@ -0,0 +1,47 @@ +namespace RGB.NET.Devices.Corsair; + +/// +/// iCUE-SDK: contains list of available property types +/// +public enum CorsairDataType +{ + /// + /// iCUE-SDK: for property of type Boolean + /// + Boolean = 0, + + /// + /// iCUE-SDK: for property of type Int32 or Enumeration + /// + Int32 = 1, + + /// + /// iCUE-SDK: for property of type Float64 + /// + Float64 = 2, + + /// + /// iCUE-SDK: for property of type String + /// + String = 3, + + /// + /// iCUE-SDK: for array of Boolean + /// + BooleanArray = 16, + + /// + /// iCUE-SDK: for array of Int32 + /// + Int32Array = 17, + + /// + /// iCUE-SDK: for array of Float64 + /// + Float64Array = 18, + + /// + /// iCUE-SDK: for array of String + /// + StringArray = 19 +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairDeviceCaps.cs b/RGB.NET.Devices.Corsair/Enum/CorsairDeviceCaps.cs deleted file mode 100644 index c92807bd..00000000 --- a/RGB.NET.Devices.Corsair/Enum/CorsairDeviceCaps.cs +++ /dev/null @@ -1,28 +0,0 @@ -// ReSharper disable InconsistentNaming -// ReSharper disable UnusedMember.Global - -using System; - -namespace RGB.NET.Devices.Corsair; - -/// -/// Contains a list of corsair device capabilities. -/// -[Flags] -public enum CorsairDeviceCaps -{ - /// - /// For devices that do not support any SDK functions. - /// - None = 0, - - /// - /// For devices that has controlled lighting. - /// - Lighting = 1, - - /// - /// For devices that provide current state through set of properties. - /// - PropertyLookup = 2 -}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairDevicePropertyId.cs b/RGB.NET.Devices.Corsair/Enum/CorsairDevicePropertyId.cs new file mode 100644 index 00000000..0646355c --- /dev/null +++ b/RGB.NET.Devices.Corsair/Enum/CorsairDevicePropertyId.cs @@ -0,0 +1,77 @@ +namespace RGB.NET.Devices.Corsair; + +/// +/// iCUE-SDK: contains list of properties identifiers which can be read from device +/// +public enum CorsairDevicePropertyId +{ + /// + /// iCUE-SDK: dummy value + /// + Invalid = 0, + + /// + /// iCUE-SDK: array of CorsairDevicePropertyId members supported by device + /// + PropertyArray = 1, + + /// + /// iCUE-SDK: indicates Mic state (On or Off); used for headset, headset stand + /// + MicEnabled = 2, + + /// + /// iCUE-SDK: indicates Surround Sound state (On or Off); used for headset, headset stand + /// + SurroundSoundEnabled = 3, + + /// + /// iCUE-SDK: indicates Sidetone state (On or Off); used for headset (where applicable) + /// + SidetoneEnabled = 4, + + /// + /// iCUE-SDK: the number of active equalizer preset (integer, 1 - 5); used for headset, headset stand + /// + EqualizerPreset = 5, + + /// + /// iCUE-SDK: keyboard physical layout (see CorsairPhysicalLayout for valid values); used for keyboard + /// + PhysicalLayout = 6, + + /// + /// iCUE-SDK: keyboard logical layout (see CorsairLogicalLayout for valid values); used for keyboard + /// + LogicalLayout = 7, + + /// + /// iCUE-SDK: array of programmable G, M or S keys on device + /// + MacroKeyArray = 8, + + /// + /// iCUE-SDK: battery level (0 - 100); used for wireless devices + /// + BatteryLevel = 9, + + /// + /// iCUE-SDK: total number of LEDs connected to the channel + /// + ChannelLedCount = 10, + + /// + /// iCUE-SDK: number of LED-devices (fans, strips, etc.) connected to the channel which is controlled by the DIY device + /// + ChannelDeviceCount = 11, + + /// + /// iCUE-SDK: array of integers, each element describes the number of LEDs controlled by the channel device + /// + ChannelDeviceLedCountArray = 12, + + /// + /// iCUE-SDK: array of CorsairChannelDeviceType members, each element describes the type of the channel device + /// + ChannelDeviceTypeArray = 13 +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs b/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs index a409c5d5..b41be141 100644 --- a/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs +++ b/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs @@ -1,27 +1,83 @@ // ReSharper disable InconsistentNaming // ReSharper disable UnusedMember.Global - -#pragma warning disable 1591 // Missing XML comment for publicly visible type or member +using System; namespace RGB.NET.Devices.Corsair; /// -/// Contains a list of available corsair device types. +/// iCUE-SDK: Contains a list of available corsair device types. /// -public enum CorsairDeviceType +[Flags] +public enum CorsairDeviceType : uint { - Unknown = 0, - Mouse = 1, - Keyboard = 2, - Headset = 3, - Mousepad = 4, - HeadsetStand = 5, - CommanderPro = 6, - LightningNodePro = 7, - MemoryModule = 8, - Cooler = 9, - Mainboard = 10, - GraphicsCard = 11, - Touchbar = 12 + /// + /// iCUE-SDK: for unknown/invalid devices + /// + Unknown = 0x0000, + + /// + /// iCUE-SDK: for keyboards + /// + Keyboard = 0x0001, + + /// + /// iCUE-SDK: for mice + /// + Mouse = 0x0002, + + /// + /// iCUE-SDK: for mousemats + /// + Mousemat = 0x0004, + + /// + /// iCUE-SDK: for headsets + /// + Headset = 0x0008, + + /// + /// iCUE-SDK: for headset stands + /// + HeadsetStand = 0x0010, + + /// + /// iCUE-SDK: for DIY-devices like Commander PRO + /// + FanLedController = 0x0020, + + /// + /// iCUE-SDK: for DIY-devices like Lighting Node PRO + /// + LedController = 0x0040, + + /// + /// iCUE-SDK: for memory modules + /// + MemoryModule = 0x0080, + + /// + /// iCUE-SDK: for coolers + /// + Cooler = 0x0100, + + /// + /// iCUE-SDK: for motherboards + /// + Motherboard = 0x0200, + + /// + /// iCUE-SDK: for graphics cards + /// + GraphicsCard = 0x0400, + + /// + /// iCUE-SDK: for touchbars + /// + Touchbar = 0x0800, + + /// + /// iCUE-SDK: for all devices + /// + All = 0xFFFFFFFF }; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairError.cs b/RGB.NET.Devices.Corsair/Enum/CorsairError.cs index 977c2cf5..d2fb6727 100644 --- a/RGB.NET.Devices.Corsair/Enum/CorsairError.cs +++ b/RGB.NET.Devices.Corsair/Enum/CorsairError.cs @@ -4,38 +4,47 @@ namespace RGB.NET.Devices.Corsair; /// -/// Shared list of all errors which could happen during calling of Corsair* functions. +/// iCUE-SDK: Shared list of all errors which could happen during calling of Corsair* functions. /// public enum CorsairError { /// - /// If previously called function completed successfully. + /// iCUE-SDK: if previously called function completed successfully /// - Success, + Success = 0, /// - /// CUE is not running or was shut down or third-party control is disabled in CUE settings. (runtime error) + /// iCUE-SDK: if iCUE is not running or was shut down or third-party control is disabled in iCUE settings (runtime error), or if developer did not call CorsairConnect after calling CorsairDisconnect or on app start (developer error) /// - ServerNotFound, + NotConnected = 1, /// - /// If some other client has or took over exclusive control. (runtime error) + /// iCUE-SDK: if some other client has or took over exclusive control (runtime error) /// - NoControl, + NoControl = 2, /// - /// If developer did not perform protocol handshake. (developer error) + /// iCUE-SDK: if developer is calling the function that is not supported by the server (either because protocol has broken by server or client or because the function is new and server is too old. Check CorsairSessionDetails for details) (developer error) /// - ProtocolHandshakeMissing, + IncompatibleProtocol = 3, /// - /// If developer is calling the function that is not supported by the server (either because protocol has broken by server or client or because the function is new and server is too old. - /// Check CorsairProtocolDetails for details). (developer error) + /// iCUE-SDK: if developer supplied invalid arguments to the function (for specifics look at function descriptions) (developer error) /// - IncompatibleProtocol, + InvalidArguments = 4, /// - /// If developer supplied invalid arguments to the function (for specifics look at function descriptions). (developer error) + /// iCUE-SDK: if developer is calling the function that is not allowed due to current state (reading improper properties from device, or setting callback when it has already been set) (developer error) /// - InvalidArguments + InvalidOperation = 5, + + /// + /// iCUE-SDK: if invalid device id has been supplied as an argument to the function (when device id refers to disconnected device) (runtime error) + /// + DeviceNotFound = 6, + + /// + /// iCUE-SDK: if specific functionality (key interception) is disabled in iCUE settings (runtime error) + /// + NotAllowed = 7 }; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs b/RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs new file mode 100644 index 00000000..72813238 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs @@ -0,0 +1,82 @@ +namespace RGB.NET.Devices.Corsair; + +/// +/// iCUE-SDK: contains a list of led groups. Led group is used as a part of led identifier +/// +public enum CorsairLedGroup +{ + /// + /// iCUE-SDK: for keyboard leds + /// + Keyboard = 0, + + /// + /// iCUE-SDK: for keyboard leds on G keys + /// + KeyboardGKeys = 1, + + /// + /// iCUE-SDK: for keyboard lighting pipe leds + /// + KeyboardEdge = 2, + + /// + /// iCUE-SDK: for vendor specific keyboard leds (ProfileSwitch, DialRing, etc.) + /// + KeyboardOem = 3, + + /// + /// iCUE-SDK: for mouse leds + /// + Mouse = 4, + + /// + /// iCUE-SDK: for mousemat leds + /// + Mousemat = 5, + + /// + /// iCUE-SDK: for headset leds + /// + Headset = 6, + + /// + /// iCUE-SDK: for headset stand leds + /// + HeadsetStand = 7, + + /// + /// iCUE-SDK: for memory module leds + /// + MemoryModule = 8, + + /// + /// iCUE-SDK: for motherboard leds + /// + Motherboard = 9, + + /// + /// iCUE-SDK: for graphics card leds + /// + GraphicsCard = 10, + + /// + /// iCUE-SDK: for leds on the first channel of DIY devices and coolers + /// + DIY_Channel1 = 11, + + /// + /// iCUE-SDK: for leds on the second channel of DIY devices and coolers + /// + DIY_Channel2 = 12, + + /// + /// iCUE-SDK: for leds on the third channel of DIY devices and coolers + /// + DIY_Channel3 = 13, + + /// + /// iCUE-SDK: for touchbar leds + /// + Touchbar = 14 +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairLedId.cs b/RGB.NET.Devices.Corsair/Enum/CorsairLedId.cs deleted file mode 100644 index a0cfeab9..00000000 --- a/RGB.NET.Devices.Corsair/Enum/CorsairLedId.cs +++ /dev/null @@ -1,1742 +0,0 @@ -// ReSharper disable InconsistentNaming -// ReSharper disable UnusedMember.Global -#pragma warning disable 1591 - -namespace RGB.NET.Devices.Corsair; - -/// -/// Contains a list of all LEDs available for all corsair devices. -/// -public enum CorsairLedId -{ - Invalid = 0, - Escape = 1, - F1 = 2, - F2 = 3, - F3 = 4, - F4 = 5, - F5 = 6, - F6 = 7, - F7 = 8, - F8 = 9, - F9 = 10, - F10 = 11, - F11 = 12, - GraveAccentAndTilde = 13, - D1 = 14, - D2 = 15, - D3 = 16, - D4 = 17, - D5 = 18, - D6 = 19, - D7 = 20, - D8 = 21, - D9 = 22, - D0 = 23, - MinusAndUnderscore = 24, - Tab = 25, - Q = 26, - W = 27, - E = 28, - R = 29, - T = 30, - Y = 31, - U = 32, - I = 33, - O = 34, - P = 35, - BracketLeft = 36, - CapsLock = 37, - A = 38, - S = 39, - D = 40, - F = 41, - G = 42, - H = 43, - J = 44, - K = 45, - L = 46, - SemicolonAndColon = 47, - ApostropheAndDoubleQuote = 48, - LeftShift = 49, - NonUsBackslash = 50, - Z = 51, - X = 52, - C = 53, - V = 54, - B = 55, - N = 56, - M = 57, - CommaAndLessThan = 58, - PeriodAndBiggerThan = 59, - SlashAndQuestionMark = 60, - LeftCtrl = 61, - LeftGui = 62, - LeftAlt = 63, - Lang2 = 64, - Space = 65, - Lang1 = 66, - International2 = 67, - RightAlt = 68, - RightGui = 69, - Application = 70, - LedProgramming = 71, - Brightness = 72, - F12 = 73, - PrintScreen = 74, - ScrollLock = 75, - PauseBreak = 76, - Insert = 77, - Home = 78, - PageUp = 79, - BracketRight = 80, - Backslash = 81, - NonUsTilde = 82, - Enter = 83, - International1 = 84, - EqualsAndPlus = 85, - International3 = 86, - Backspace = 87, - Delete = 88, - End = 89, - PageDown = 90, - RightShift = 91, - RightCtrl = 92, - UpArrow = 93, - LeftArrow = 94, - DownArrow = 95, - RightArrow = 96, - WinLock = 97, - Mute = 98, - Stop = 99, - ScanPreviousTrack = 100, - PlayPause = 101, - ScanNextTrack = 102, - NumLock = 103, - KeypadSlash = 104, - KeypadAsterisk = 105, - KeypadMinus = 106, - KeypadPlus = 107, - KeypadEnter = 108, - Keypad7 = 109, - Keypad8 = 110, - Keypad9 = 111, - KeypadComma = 112, - Keypad4 = 113, - Keypad5 = 114, - Keypad6 = 115, - Keypad1 = 116, - Keypad2 = 117, - Keypad3 = 118, - Keypad0 = 119, - KeypadPeriodAndDelete = 120, - G1 = 121, - G2 = 122, - G3 = 123, - G4 = 124, - G5 = 125, - G6 = 126, - G7 = 127, - G8 = 128, - G9 = 129, - G10 = 130, - VolumeUp = 131, - VolumeDown = 132, - MR = 133, - M1 = 134, - M2 = 135, - M3 = 136, - G11 = 137, - G12 = 138, - G13 = 139, - G14 = 140, - G15 = 141, - G16 = 142, - G17 = 143, - G18 = 144, - International5 = 145, - International4 = 146, - Fn = 147, - - B1 = 148, - B2 = 149, - B3 = 150, - B4 = 151, - - LeftLogo = 152, - RightLogo = 153, - - Logo = 154, - - Zone1 = 155, - Zone2 = 156, - Zone3 = 157, - Zone4 = 158, - Zone5 = 159, - Zone6 = 160, - Zone7 = 161, - Zone8 = 162, - Zone9 = 163, - Zone10 = 164, - Zone11 = 165, - Zone12 = 166, - Zone13 = 167, - Zone14 = 168, - Zone15 = 169, - - Lightbar1 = 170, - Lightbar2 = 171, - Lightbar3 = 172, - Lightbar4 = 173, - Lightbar5 = 174, - Lightbar6 = 175, - Lightbar7 = 176, - Lightbar8 = 177, - Lightbar9 = 178, - Lightbar10 = 179, - Lightbar11 = 180, - Lightbar12 = 181, - Lightbar13 = 182, - Lightbar14 = 183, - Lightbar15 = 184, - Lightbar16 = 185, - Lightbar17 = 186, - Lightbar18 = 187, - Lightbar19 = 188, - - B5 = 189, - B6 = 190, - - HeadsetStandZone1 = 191, - HeadsetStandZone2 = 192, - HeadsetStandZone3 = 193, - HeadsetStandZone4 = 194, - HeadsetStandZone5 = 195, - HeadsetStandZone6 = 196, - HeadsetStandZone7 = 197, - HeadsetStandZone8 = 198, - HeadsetStandZone9 = 199, - - CustomDeviceChannel1Led1 = 200, - CustomDeviceChannel1Led2 = 201, - CustomDeviceChannel1Led3 = 202, - CustomDeviceChannel1Led4 = 203, - CustomDeviceChannel1Led5 = 204, - CustomDeviceChannel1Led6 = 205, - CustomDeviceChannel1Led7 = 206, - CustomDeviceChannel1Led8 = 207, - CustomDeviceChannel1Led9 = 208, - CustomDeviceChannel1Led10 = 209, - CustomDeviceChannel1Led11 = 210, - CustomDeviceChannel1Led12 = 211, - CustomDeviceChannel1Led13 = 212, - CustomDeviceChannel1Led14 = 213, - CustomDeviceChannel1Led15 = 214, - CustomDeviceChannel1Led16 = 215, - CustomDeviceChannel1Led17 = 216, - CustomDeviceChannel1Led18 = 217, - CustomDeviceChannel1Led19 = 218, - CustomDeviceChannel1Led20 = 219, - CustomDeviceChannel1Led21 = 220, - CustomDeviceChannel1Led22 = 221, - CustomDeviceChannel1Led23 = 222, - CustomDeviceChannel1Led24 = 223, - CustomDeviceChannel1Led25 = 224, - CustomDeviceChannel1Led26 = 225, - CustomDeviceChannel1Led27 = 226, - CustomDeviceChannel1Led28 = 227, - CustomDeviceChannel1Led29 = 228, - CustomDeviceChannel1Led30 = 229, - CustomDeviceChannel1Led31 = 230, - CustomDeviceChannel1Led32 = 231, - CustomDeviceChannel1Led33 = 232, - CustomDeviceChannel1Led34 = 233, - CustomDeviceChannel1Led35 = 234, - CustomDeviceChannel1Led36 = 235, - CustomDeviceChannel1Led37 = 236, - CustomDeviceChannel1Led38 = 237, - CustomDeviceChannel1Led39 = 238, - CustomDeviceChannel1Led40 = 239, - CustomDeviceChannel1Led41 = 240, - CustomDeviceChannel1Led42 = 241, - CustomDeviceChannel1Led43 = 242, - CustomDeviceChannel1Led44 = 243, - CustomDeviceChannel1Led45 = 244, - CustomDeviceChannel1Led46 = 245, - CustomDeviceChannel1Led47 = 246, - CustomDeviceChannel1Led48 = 247, - CustomDeviceChannel1Led49 = 248, - CustomDeviceChannel1Led50 = 249, - CustomDeviceChannel1Led51 = 250, - CustomDeviceChannel1Led52 = 251, - CustomDeviceChannel1Led53 = 252, - CustomDeviceChannel1Led54 = 253, - CustomDeviceChannel1Led55 = 254, - CustomDeviceChannel1Led56 = 255, - CustomDeviceChannel1Led57 = 256, - CustomDeviceChannel1Led58 = 257, - CustomDeviceChannel1Led59 = 258, - CustomDeviceChannel1Led60 = 259, - CustomDeviceChannel1Led61 = 260, - CustomDeviceChannel1Led62 = 261, - CustomDeviceChannel1Led63 = 262, - CustomDeviceChannel1Led64 = 263, - CustomDeviceChannel1Led65 = 264, - CustomDeviceChannel1Led66 = 265, - CustomDeviceChannel1Led67 = 266, - CustomDeviceChannel1Led68 = 267, - CustomDeviceChannel1Led69 = 268, - CustomDeviceChannel1Led70 = 269, - CustomDeviceChannel1Led71 = 270, - CustomDeviceChannel1Led72 = 271, - CustomDeviceChannel1Led73 = 272, - CustomDeviceChannel1Led74 = 273, - CustomDeviceChannel1Led75 = 274, - CustomDeviceChannel1Led76 = 275, - CustomDeviceChannel1Led77 = 276, - CustomDeviceChannel1Led78 = 277, - CustomDeviceChannel1Led79 = 278, - CustomDeviceChannel1Led80 = 279, - CustomDeviceChannel1Led81 = 280, - CustomDeviceChannel1Led82 = 281, - CustomDeviceChannel1Led83 = 282, - CustomDeviceChannel1Led84 = 283, - CustomDeviceChannel1Led85 = 284, - CustomDeviceChannel1Led86 = 285, - CustomDeviceChannel1Led87 = 286, - CustomDeviceChannel1Led88 = 287, - CustomDeviceChannel1Led89 = 288, - CustomDeviceChannel1Led90 = 289, - CustomDeviceChannel1Led91 = 290, - CustomDeviceChannel1Led92 = 291, - CustomDeviceChannel1Led93 = 292, - CustomDeviceChannel1Led94 = 293, - CustomDeviceChannel1Led95 = 294, - CustomDeviceChannel1Led96 = 295, - CustomDeviceChannel1Led97 = 296, - CustomDeviceChannel1Led98 = 297, - CustomDeviceChannel1Led99 = 298, - CustomDeviceChannel1Led100 = 299, - CustomDeviceChannel1Led101 = 300, - CustomDeviceChannel1Led102 = 301, - CustomDeviceChannel1Led103 = 302, - CustomDeviceChannel1Led104 = 303, - CustomDeviceChannel1Led105 = 304, - CustomDeviceChannel1Led106 = 305, - CustomDeviceChannel1Led107 = 306, - CustomDeviceChannel1Led108 = 307, - CustomDeviceChannel1Led109 = 308, - CustomDeviceChannel1Led110 = 309, - CustomDeviceChannel1Led111 = 310, - CustomDeviceChannel1Led112 = 311, - CustomDeviceChannel1Led113 = 312, - CustomDeviceChannel1Led114 = 313, - CustomDeviceChannel1Led115 = 314, - CustomDeviceChannel1Led116 = 315, - CustomDeviceChannel1Led117 = 316, - CustomDeviceChannel1Led118 = 317, - CustomDeviceChannel1Led119 = 318, - CustomDeviceChannel1Led120 = 319, - CustomDeviceChannel1Led121 = 320, - CustomDeviceChannel1Led122 = 321, - CustomDeviceChannel1Led123 = 322, - CustomDeviceChannel1Led124 = 323, - CustomDeviceChannel1Led125 = 324, - CustomDeviceChannel1Led126 = 325, - CustomDeviceChannel1Led127 = 326, - CustomDeviceChannel1Led128 = 327, - CustomDeviceChannel1Led129 = 328, - CustomDeviceChannel1Led130 = 329, - CustomDeviceChannel1Led131 = 330, - CustomDeviceChannel1Led132 = 331, - CustomDeviceChannel1Led133 = 332, - CustomDeviceChannel1Led134 = 333, - CustomDeviceChannel1Led135 = 334, - CustomDeviceChannel1Led136 = 335, - CustomDeviceChannel1Led137 = 336, - CustomDeviceChannel1Led138 = 337, - CustomDeviceChannel1Led139 = 338, - CustomDeviceChannel1Led140 = 339, - CustomDeviceChannel1Led141 = 340, - CustomDeviceChannel1Led142 = 341, - CustomDeviceChannel1Led143 = 342, - CustomDeviceChannel1Led144 = 343, - CustomDeviceChannel1Led145 = 344, - CustomDeviceChannel1Led146 = 345, - CustomDeviceChannel1Led147 = 346, - CustomDeviceChannel1Led148 = 347, - CustomDeviceChannel1Led149 = 348, - CustomDeviceChannel1Led150 = 349, - - CustomDeviceChannel2Led1 = 350, - CustomDeviceChannel2Led2 = 351, - CustomDeviceChannel2Led3 = 352, - CustomDeviceChannel2Led4 = 353, - CustomDeviceChannel2Led5 = 354, - CustomDeviceChannel2Led6 = 355, - CustomDeviceChannel2Led7 = 356, - CustomDeviceChannel2Led8 = 357, - CustomDeviceChannel2Led9 = 358, - CustomDeviceChannel2Led10 = 359, - CustomDeviceChannel2Led11 = 360, - CustomDeviceChannel2Led12 = 361, - CustomDeviceChannel2Led13 = 362, - CustomDeviceChannel2Led14 = 363, - CustomDeviceChannel2Led15 = 364, - CustomDeviceChannel2Led16 = 365, - CustomDeviceChannel2Led17 = 366, - CustomDeviceChannel2Led18 = 367, - CustomDeviceChannel2Led19 = 368, - CustomDeviceChannel2Led20 = 369, - CustomDeviceChannel2Led21 = 370, - CustomDeviceChannel2Led22 = 371, - CustomDeviceChannel2Led23 = 372, - CustomDeviceChannel2Led24 = 373, - CustomDeviceChannel2Led25 = 374, - CustomDeviceChannel2Led26 = 375, - CustomDeviceChannel2Led27 = 376, - CustomDeviceChannel2Led28 = 377, - CustomDeviceChannel2Led29 = 378, - CustomDeviceChannel2Led30 = 379, - CustomDeviceChannel2Led31 = 380, - CustomDeviceChannel2Led32 = 381, - CustomDeviceChannel2Led33 = 382, - CustomDeviceChannel2Led34 = 383, - CustomDeviceChannel2Led35 = 384, - CustomDeviceChannel2Led36 = 385, - CustomDeviceChannel2Led37 = 386, - CustomDeviceChannel2Led38 = 387, - CustomDeviceChannel2Led39 = 388, - CustomDeviceChannel2Led40 = 389, - CustomDeviceChannel2Led41 = 390, - CustomDeviceChannel2Led42 = 391, - CustomDeviceChannel2Led43 = 392, - CustomDeviceChannel2Led44 = 393, - CustomDeviceChannel2Led45 = 394, - CustomDeviceChannel2Led46 = 395, - CustomDeviceChannel2Led47 = 396, - CustomDeviceChannel2Led48 = 397, - CustomDeviceChannel2Led49 = 398, - CustomDeviceChannel2Led50 = 399, - CustomDeviceChannel2Led51 = 400, - CustomDeviceChannel2Led52 = 401, - CustomDeviceChannel2Led53 = 402, - CustomDeviceChannel2Led54 = 403, - CustomDeviceChannel2Led55 = 404, - CustomDeviceChannel2Led56 = 405, - CustomDeviceChannel2Led57 = 406, - CustomDeviceChannel2Led58 = 407, - CustomDeviceChannel2Led59 = 408, - CustomDeviceChannel2Led60 = 409, - CustomDeviceChannel2Led61 = 410, - CustomDeviceChannel2Led62 = 411, - CustomDeviceChannel2Led63 = 412, - CustomDeviceChannel2Led64 = 413, - CustomDeviceChannel2Led65 = 414, - CustomDeviceChannel2Led66 = 415, - CustomDeviceChannel2Led67 = 416, - CustomDeviceChannel2Led68 = 417, - CustomDeviceChannel2Led69 = 418, - CustomDeviceChannel2Led70 = 419, - CustomDeviceChannel2Led71 = 420, - CustomDeviceChannel2Led72 = 421, - CustomDeviceChannel2Led73 = 422, - CustomDeviceChannel2Led74 = 423, - CustomDeviceChannel2Led75 = 424, - CustomDeviceChannel2Led76 = 425, - CustomDeviceChannel2Led77 = 426, - CustomDeviceChannel2Led78 = 427, - CustomDeviceChannel2Led79 = 428, - CustomDeviceChannel2Led80 = 429, - CustomDeviceChannel2Led81 = 430, - CustomDeviceChannel2Led82 = 431, - CustomDeviceChannel2Led83 = 432, - CustomDeviceChannel2Led84 = 433, - CustomDeviceChannel2Led85 = 434, - CustomDeviceChannel2Led86 = 435, - CustomDeviceChannel2Led87 = 436, - CustomDeviceChannel2Led88 = 437, - CustomDeviceChannel2Led89 = 438, - CustomDeviceChannel2Led90 = 439, - CustomDeviceChannel2Led91 = 440, - CustomDeviceChannel2Led92 = 441, - CustomDeviceChannel2Led93 = 442, - CustomDeviceChannel2Led94 = 443, - CustomDeviceChannel2Led95 = 444, - CustomDeviceChannel2Led96 = 445, - CustomDeviceChannel2Led97 = 446, - CustomDeviceChannel2Led98 = 447, - CustomDeviceChannel2Led99 = 448, - CustomDeviceChannel2Led100 = 449, - CustomDeviceChannel2Led101 = 450, - CustomDeviceChannel2Led102 = 451, - CustomDeviceChannel2Led103 = 452, - CustomDeviceChannel2Led104 = 453, - CustomDeviceChannel2Led105 = 454, - CustomDeviceChannel2Led106 = 455, - CustomDeviceChannel2Led107 = 456, - CustomDeviceChannel2Led108 = 457, - CustomDeviceChannel2Led109 = 458, - CustomDeviceChannel2Led110 = 459, - CustomDeviceChannel2Led111 = 460, - CustomDeviceChannel2Led112 = 461, - CustomDeviceChannel2Led113 = 462, - CustomDeviceChannel2Led114 = 463, - CustomDeviceChannel2Led115 = 464, - CustomDeviceChannel2Led116 = 465, - CustomDeviceChannel2Led117 = 466, - CustomDeviceChannel2Led118 = 467, - CustomDeviceChannel2Led119 = 468, - CustomDeviceChannel2Led120 = 469, - CustomDeviceChannel2Led121 = 470, - CustomDeviceChannel2Led122 = 471, - CustomDeviceChannel2Led123 = 472, - CustomDeviceChannel2Led124 = 473, - CustomDeviceChannel2Led125 = 474, - CustomDeviceChannel2Led126 = 475, - CustomDeviceChannel2Led127 = 476, - CustomDeviceChannel2Led128 = 477, - CustomDeviceChannel2Led129 = 478, - CustomDeviceChannel2Led130 = 479, - CustomDeviceChannel2Led131 = 480, - CustomDeviceChannel2Led132 = 481, - CustomDeviceChannel2Led133 = 482, - CustomDeviceChannel2Led134 = 483, - CustomDeviceChannel2Led135 = 484, - CustomDeviceChannel2Led136 = 485, - CustomDeviceChannel2Led137 = 486, - CustomDeviceChannel2Led138 = 487, - CustomDeviceChannel2Led139 = 488, - CustomDeviceChannel2Led140 = 489, - CustomDeviceChannel2Led141 = 490, - CustomDeviceChannel2Led142 = 491, - CustomDeviceChannel2Led143 = 492, - CustomDeviceChannel2Led144 = 493, - CustomDeviceChannel2Led145 = 494, - CustomDeviceChannel2Led146 = 495, - CustomDeviceChannel2Led147 = 496, - CustomDeviceChannel2Led148 = 497, - CustomDeviceChannel2Led149 = 498, - CustomDeviceChannel2Led150 = 499, - - OemLed1 = 500, - OemLed2 = 501, - OemLed3 = 502, - OemLed4 = 503, - OemLed5 = 504, - OemLed6 = 505, - OemLed7 = 506, - OemLed8 = 507, - OemLed9 = 508, - OemLed10 = 509, - OemLed11 = 510, - OemLed12 = 511, - OemLed13 = 512, - OemLed14 = 513, - OemLed15 = 514, - OemLed16 = 515, - OemLed17 = 516, - OemLed18 = 517, - OemLed19 = 518, - OemLed20 = 519, - OemLed21 = 520, - OemLed22 = 521, - OemLed23 = 522, - OemLed24 = 523, - OemLed25 = 524, - OemLed26 = 525, - OemLed27 = 526, - OemLed28 = 527, - OemLed29 = 528, - OemLed30 = 529, - OemLed31 = 530, - OemLed32 = 531, - OemLed33 = 532, - OemLed34 = 533, - OemLed35 = 534, - OemLed36 = 535, - OemLed37 = 536, - OemLed38 = 537, - OemLed39 = 538, - OemLed40 = 539, - OemLed41 = 540, - OemLed42 = 541, - OemLed43 = 542, - OemLed44 = 543, - OemLed45 = 544, - OemLed46 = 545, - OemLed47 = 546, - OemLed48 = 547, - OemLed49 = 548, - OemLed50 = 549, - OemLed51 = 550, - OemLed52 = 551, - OemLed53 = 552, - OemLed54 = 553, - OemLed55 = 554, - OemLed56 = 555, - OemLed57 = 556, - OemLed58 = 557, - OemLed59 = 558, - OemLed60 = 559, - OemLed61 = 560, - OemLed62 = 561, - OemLed63 = 562, - OemLed64 = 563, - OemLed65 = 564, - OemLed66 = 565, - OemLed67 = 566, - OemLed68 = 567, - OemLed69 = 568, - OemLed70 = 569, - OemLed71 = 570, - OemLed72 = 571, - OemLed73 = 572, - OemLed74 = 573, - OemLed75 = 574, - OemLed76 = 575, - OemLed77 = 576, - OemLed78 = 577, - OemLed79 = 578, - OemLed80 = 579, - OemLed81 = 580, - OemLed82 = 581, - OemLed83 = 582, - OemLed84 = 583, - OemLed85 = 584, - OemLed86 = 585, - OemLed87 = 586, - OemLed88 = 587, - OemLed89 = 588, - OemLed90 = 589, - OemLed91 = 590, - OemLed92 = 591, - OemLed93 = 592, - OemLed94 = 593, - OemLed95 = 594, - OemLed96 = 595, - OemLed97 = 596, - OemLed98 = 597, - OemLed99 = 598, - OemLed100 = 599, - - DRAM1 = 600, - DRAM2 = 601, - DRAM3 = 602, - DRAM4 = 603, - DRAM5 = 604, - DRAM6 = 605, - DRAM7 = 606, - DRAM8 = 607, - DRAM9 = 608, - DRAM10 = 609, - DRAM11 = 610, - DRAM12 = 611, - - CustomDeviceChannel3Led1 = 612, - CustomDeviceChannel3Led2 = 613, - CustomDeviceChannel3Led3 = 614, - CustomDeviceChannel3Led4 = 615, - CustomDeviceChannel3Led5 = 616, - CustomDeviceChannel3Led6 = 617, - CustomDeviceChannel3Led7 = 618, - CustomDeviceChannel3Led8 = 619, - CustomDeviceChannel3Led9 = 620, - CustomDeviceChannel3Led10 = 621, - CustomDeviceChannel3Led11 = 622, - CustomDeviceChannel3Led12 = 623, - CustomDeviceChannel3Led13 = 624, - CustomDeviceChannel3Led14 = 625, - CustomDeviceChannel3Led15 = 626, - CustomDeviceChannel3Led16 = 627, - CustomDeviceChannel3Led17 = 628, - CustomDeviceChannel3Led18 = 629, - CustomDeviceChannel3Led19 = 630, - CustomDeviceChannel3Led20 = 631, - CustomDeviceChannel3Led21 = 632, - CustomDeviceChannel3Led22 = 633, - CustomDeviceChannel3Led23 = 634, - CustomDeviceChannel3Led24 = 635, - CustomDeviceChannel3Led25 = 636, - CustomDeviceChannel3Led26 = 637, - CustomDeviceChannel3Led27 = 638, - CustomDeviceChannel3Led28 = 639, - CustomDeviceChannel3Led29 = 640, - CustomDeviceChannel3Led30 = 641, - CustomDeviceChannel3Led31 = 642, - CustomDeviceChannel3Led32 = 643, - CustomDeviceChannel3Led33 = 644, - CustomDeviceChannel3Led34 = 645, - CustomDeviceChannel3Led35 = 646, - CustomDeviceChannel3Led36 = 647, - CustomDeviceChannel3Led37 = 648, - CustomDeviceChannel3Led38 = 649, - CustomDeviceChannel3Led39 = 650, - CustomDeviceChannel3Led40 = 651, - CustomDeviceChannel3Led41 = 652, - CustomDeviceChannel3Led42 = 653, - CustomDeviceChannel3Led43 = 654, - CustomDeviceChannel3Led44 = 655, - CustomDeviceChannel3Led45 = 656, - CustomDeviceChannel3Led46 = 657, - CustomDeviceChannel3Led47 = 658, - CustomDeviceChannel3Led48 = 659, - CustomDeviceChannel3Led49 = 660, - CustomDeviceChannel3Led50 = 661, - CustomDeviceChannel3Led51 = 662, - CustomDeviceChannel3Led52 = 663, - CustomDeviceChannel3Led53 = 664, - CustomDeviceChannel3Led54 = 665, - CustomDeviceChannel3Led55 = 666, - CustomDeviceChannel3Led56 = 667, - CustomDeviceChannel3Led57 = 668, - CustomDeviceChannel3Led58 = 669, - CustomDeviceChannel3Led59 = 670, - CustomDeviceChannel3Led60 = 671, - CustomDeviceChannel3Led61 = 672, - CustomDeviceChannel3Led62 = 673, - CustomDeviceChannel3Led63 = 674, - CustomDeviceChannel3Led64 = 675, - CustomDeviceChannel3Led65 = 676, - CustomDeviceChannel3Led66 = 677, - CustomDeviceChannel3Led67 = 678, - CustomDeviceChannel3Led68 = 679, - CustomDeviceChannel3Led69 = 680, - CustomDeviceChannel3Led70 = 681, - CustomDeviceChannel3Led71 = 682, - CustomDeviceChannel3Led72 = 683, - CustomDeviceChannel3Led73 = 684, - CustomDeviceChannel3Led74 = 685, - CustomDeviceChannel3Led75 = 686, - CustomDeviceChannel3Led76 = 687, - CustomDeviceChannel3Led77 = 688, - CustomDeviceChannel3Led78 = 689, - CustomDeviceChannel3Led79 = 690, - CustomDeviceChannel3Led80 = 691, - CustomDeviceChannel3Led81 = 692, - CustomDeviceChannel3Led82 = 693, - CustomDeviceChannel3Led83 = 694, - CustomDeviceChannel3Led84 = 695, - CustomDeviceChannel3Led85 = 696, - CustomDeviceChannel3Led86 = 697, - CustomDeviceChannel3Led87 = 698, - CustomDeviceChannel3Led88 = 699, - CustomDeviceChannel3Led89 = 700, - CustomDeviceChannel3Led90 = 701, - CustomDeviceChannel3Led91 = 702, - CustomDeviceChannel3Led92 = 703, - CustomDeviceChannel3Led93 = 704, - CustomDeviceChannel3Led94 = 705, - CustomDeviceChannel3Led95 = 706, - CustomDeviceChannel3Led96 = 707, - CustomDeviceChannel3Led97 = 708, - CustomDeviceChannel3Led98 = 709, - CustomDeviceChannel3Led99 = 710, - CustomDeviceChannel3Led100 = 711, - CustomDeviceChannel3Led101 = 712, - CustomDeviceChannel3Led102 = 713, - CustomDeviceChannel3Led103 = 714, - CustomDeviceChannel3Led104 = 715, - CustomDeviceChannel3Led105 = 716, - CustomDeviceChannel3Led106 = 717, - CustomDeviceChannel3Led107 = 718, - CustomDeviceChannel3Led108 = 719, - CustomDeviceChannel3Led109 = 720, - CustomDeviceChannel3Led110 = 721, - CustomDeviceChannel3Led111 = 722, - CustomDeviceChannel3Led112 = 723, - CustomDeviceChannel3Led113 = 724, - CustomDeviceChannel3Led114 = 725, - CustomDeviceChannel3Led115 = 726, - CustomDeviceChannel3Led116 = 727, - CustomDeviceChannel3Led117 = 728, - CustomDeviceChannel3Led118 = 729, - CustomDeviceChannel3Led119 = 730, - CustomDeviceChannel3Led120 = 731, - CustomDeviceChannel3Led121 = 732, - CustomDeviceChannel3Led122 = 733, - CustomDeviceChannel3Led123 = 734, - CustomDeviceChannel3Led124 = 735, - CustomDeviceChannel3Led125 = 736, - CustomDeviceChannel3Led126 = 737, - CustomDeviceChannel3Led127 = 738, - CustomDeviceChannel3Led128 = 739, - CustomDeviceChannel3Led129 = 740, - CustomDeviceChannel3Led130 = 741, - CustomDeviceChannel3Led131 = 742, - CustomDeviceChannel3Led132 = 743, - CustomDeviceChannel3Led133 = 744, - CustomDeviceChannel3Led134 = 745, - CustomDeviceChannel3Led135 = 746, - CustomDeviceChannel3Led136 = 747, - CustomDeviceChannel3Led137 = 748, - CustomDeviceChannel3Led138 = 749, - CustomDeviceChannel3Led139 = 750, - CustomDeviceChannel3Led140 = 751, - CustomDeviceChannel3Led141 = 752, - CustomDeviceChannel3Led142 = 753, - CustomDeviceChannel3Led143 = 754, - CustomDeviceChannel3Led144 = 755, - CustomDeviceChannel3Led145 = 756, - CustomDeviceChannel3Led146 = 757, - CustomDeviceChannel3Led147 = 758, - CustomDeviceChannel3Led148 = 759, - CustomDeviceChannel3Led149 = 760, - CustomDeviceChannel3Led150 = 761, - - CustomLiquidCoolerChannel1Led1 = 762, - CustomLiquidCoolerChannel1Led2 = 763, - CustomLiquidCoolerChannel1Led3 = 764, - CustomLiquidCoolerChannel1Led4 = 765, - CustomLiquidCoolerChannel1Led5 = 766, - CustomLiquidCoolerChannel1Led6 = 767, - CustomLiquidCoolerChannel1Led7 = 768, - CustomLiquidCoolerChannel1Led8 = 769, - CustomLiquidCoolerChannel1Led9 = 770, - CustomLiquidCoolerChannel1Led10 = 771, - CustomLiquidCoolerChannel1Led11 = 772, - CustomLiquidCoolerChannel1Led12 = 773, - CustomLiquidCoolerChannel1Led13 = 774, - CustomLiquidCoolerChannel1Led14 = 775, - CustomLiquidCoolerChannel1Led15 = 776, - CustomLiquidCoolerChannel1Led16 = 777, - CustomLiquidCoolerChannel1Led17 = 778, - CustomLiquidCoolerChannel1Led18 = 779, - CustomLiquidCoolerChannel1Led19 = 780, - CustomLiquidCoolerChannel1Led20 = 781, - CustomLiquidCoolerChannel1Led21 = 782, - CustomLiquidCoolerChannel1Led22 = 783, - CustomLiquidCoolerChannel1Led23 = 784, - CustomLiquidCoolerChannel1Led24 = 785, - CustomLiquidCoolerChannel1Led25 = 786, - CustomLiquidCoolerChannel1Led26 = 787, - CustomLiquidCoolerChannel1Led27 = 788, - CustomLiquidCoolerChannel1Led28 = 789, - CustomLiquidCoolerChannel1Led29 = 790, - CustomLiquidCoolerChannel1Led30 = 791, - CustomLiquidCoolerChannel1Led31 = 792, - CustomLiquidCoolerChannel1Led32 = 793, - CustomLiquidCoolerChannel1Led33 = 794, - CustomLiquidCoolerChannel1Led34 = 795, - CustomLiquidCoolerChannel1Led35 = 796, - CustomLiquidCoolerChannel1Led36 = 797, - CustomLiquidCoolerChannel1Led37 = 798, - CustomLiquidCoolerChannel1Led38 = 799, - CustomLiquidCoolerChannel1Led39 = 800, - CustomLiquidCoolerChannel1Led40 = 801, - CustomLiquidCoolerChannel1Led41 = 802, - CustomLiquidCoolerChannel1Led42 = 803, - CustomLiquidCoolerChannel1Led43 = 804, - CustomLiquidCoolerChannel1Led44 = 805, - CustomLiquidCoolerChannel1Led45 = 806, - CustomLiquidCoolerChannel1Led46 = 807, - CustomLiquidCoolerChannel1Led47 = 808, - CustomLiquidCoolerChannel1Led48 = 809, - CustomLiquidCoolerChannel1Led49 = 810, - CustomLiquidCoolerChannel1Led50 = 811, - CustomLiquidCoolerChannel1Led51 = 812, - CustomLiquidCoolerChannel1Led52 = 813, - CustomLiquidCoolerChannel1Led53 = 814, - CustomLiquidCoolerChannel1Led54 = 815, - CustomLiquidCoolerChannel1Led55 = 816, - CustomLiquidCoolerChannel1Led56 = 817, - CustomLiquidCoolerChannel1Led57 = 818, - CustomLiquidCoolerChannel1Led58 = 819, - CustomLiquidCoolerChannel1Led59 = 820, - CustomLiquidCoolerChannel1Led60 = 821, - CustomLiquidCoolerChannel1Led61 = 822, - CustomLiquidCoolerChannel1Led62 = 823, - CustomLiquidCoolerChannel1Led63 = 824, - CustomLiquidCoolerChannel1Led64 = 825, - CustomLiquidCoolerChannel1Led65 = 826, - CustomLiquidCoolerChannel1Led66 = 827, - CustomLiquidCoolerChannel1Led67 = 828, - CustomLiquidCoolerChannel1Led68 = 829, - CustomLiquidCoolerChannel1Led69 = 830, - CustomLiquidCoolerChannel1Led70 = 831, - CustomLiquidCoolerChannel1Led71 = 832, - CustomLiquidCoolerChannel1Led72 = 833, - CustomLiquidCoolerChannel1Led73 = 834, - CustomLiquidCoolerChannel1Led74 = 835, - CustomLiquidCoolerChannel1Led75 = 836, - CustomLiquidCoolerChannel1Led76 = 837, - CustomLiquidCoolerChannel1Led77 = 838, - CustomLiquidCoolerChannel1Led78 = 839, - CustomLiquidCoolerChannel1Led79 = 840, - CustomLiquidCoolerChannel1Led80 = 841, - CustomLiquidCoolerChannel1Led81 = 842, - CustomLiquidCoolerChannel1Led82 = 843, - CustomLiquidCoolerChannel1Led83 = 844, - CustomLiquidCoolerChannel1Led84 = 845, - CustomLiquidCoolerChannel1Led85 = 846, - CustomLiquidCoolerChannel1Led86 = 847, - CustomLiquidCoolerChannel1Led87 = 848, - CustomLiquidCoolerChannel1Led88 = 849, - CustomLiquidCoolerChannel1Led89 = 850, - CustomLiquidCoolerChannel1Led90 = 851, - CustomLiquidCoolerChannel1Led91 = 852, - CustomLiquidCoolerChannel1Led92 = 853, - CustomLiquidCoolerChannel1Led93 = 854, - CustomLiquidCoolerChannel1Led94 = 855, - CustomLiquidCoolerChannel1Led95 = 856, - CustomLiquidCoolerChannel1Led96 = 857, - CustomLiquidCoolerChannel1Led97 = 858, - CustomLiquidCoolerChannel1Led98 = 859, - CustomLiquidCoolerChannel1Led99 = 860, - CustomLiquidCoolerChannel1Led100 = 861, - CustomLiquidCoolerChannel1Led101 = 862, - CustomLiquidCoolerChannel1Led102 = 863, - CustomLiquidCoolerChannel1Led103 = 864, - CustomLiquidCoolerChannel1Led104 = 865, - CustomLiquidCoolerChannel1Led105 = 866, - CustomLiquidCoolerChannel1Led106 = 867, - CustomLiquidCoolerChannel1Led107 = 868, - CustomLiquidCoolerChannel1Led108 = 869, - CustomLiquidCoolerChannel1Led109 = 870, - CustomLiquidCoolerChannel1Led110 = 871, - CustomLiquidCoolerChannel1Led111 = 872, - CustomLiquidCoolerChannel1Led112 = 873, - CustomLiquidCoolerChannel1Led113 = 874, - CustomLiquidCoolerChannel1Led114 = 875, - CustomLiquidCoolerChannel1Led115 = 876, - CustomLiquidCoolerChannel1Led116 = 877, - CustomLiquidCoolerChannel1Led117 = 878, - CustomLiquidCoolerChannel1Led118 = 879, - CustomLiquidCoolerChannel1Led119 = 880, - CustomLiquidCoolerChannel1Led120 = 881, - CustomLiquidCoolerChannel1Led121 = 882, - CustomLiquidCoolerChannel1Led122 = 883, - CustomLiquidCoolerChannel1Led123 = 884, - CustomLiquidCoolerChannel1Led124 = 885, - CustomLiquidCoolerChannel1Led125 = 886, - CustomLiquidCoolerChannel1Led126 = 887, - CustomLiquidCoolerChannel1Led127 = 888, - CustomLiquidCoolerChannel1Led128 = 889, - CustomLiquidCoolerChannel1Led129 = 890, - CustomLiquidCoolerChannel1Led130 = 891, - CustomLiquidCoolerChannel1Led131 = 892, - CustomLiquidCoolerChannel1Led132 = 893, - CustomLiquidCoolerChannel1Led133 = 894, - CustomLiquidCoolerChannel1Led134 = 895, - CustomLiquidCoolerChannel1Led135 = 896, - CustomLiquidCoolerChannel1Led136 = 897, - CustomLiquidCoolerChannel1Led137 = 898, - CustomLiquidCoolerChannel1Led138 = 899, - CustomLiquidCoolerChannel1Led139 = 900, - CustomLiquidCoolerChannel1Led140 = 901, - CustomLiquidCoolerChannel1Led141 = 902, - CustomLiquidCoolerChannel1Led142 = 903, - CustomLiquidCoolerChannel1Led143 = 904, - CustomLiquidCoolerChannel1Led144 = 905, - CustomLiquidCoolerChannel1Led145 = 906, - CustomLiquidCoolerChannel1Led146 = 907, - CustomLiquidCoolerChannel1Led147 = 908, - CustomLiquidCoolerChannel1Led148 = 909, - CustomLiquidCoolerChannel1Led149 = 910, - CustomLiquidCoolerChannel1Led150 = 911, - - CustomDeviceChannel1Led151 = 912, - CustomDeviceChannel1Led152 = 913, - CustomDeviceChannel1Led153 = 914, - CustomDeviceChannel1Led154 = 915, - CustomDeviceChannel1Led155 = 916, - CustomDeviceChannel1Led156 = 917, - CustomDeviceChannel1Led157 = 918, - CustomDeviceChannel1Led158 = 919, - CustomDeviceChannel1Led159 = 920, - CustomDeviceChannel1Led160 = 921, - CustomDeviceChannel1Led161 = 922, - CustomDeviceChannel1Led162 = 923, - CustomDeviceChannel1Led163 = 924, - CustomDeviceChannel1Led164 = 925, - CustomDeviceChannel1Led165 = 926, - CustomDeviceChannel1Led166 = 927, - CustomDeviceChannel1Led167 = 928, - CustomDeviceChannel1Led168 = 929, - CustomDeviceChannel1Led169 = 930, - CustomDeviceChannel1Led170 = 931, - CustomDeviceChannel1Led171 = 932, - CustomDeviceChannel1Led172 = 933, - CustomDeviceChannel1Led173 = 934, - CustomDeviceChannel1Led174 = 935, - CustomDeviceChannel1Led175 = 936, - CustomDeviceChannel1Led176 = 937, - CustomDeviceChannel1Led177 = 938, - CustomDeviceChannel1Led178 = 939, - CustomDeviceChannel1Led179 = 940, - CustomDeviceChannel1Led180 = 941, - CustomDeviceChannel1Led181 = 942, - CustomDeviceChannel1Led182 = 943, - CustomDeviceChannel1Led183 = 944, - CustomDeviceChannel1Led184 = 945, - CustomDeviceChannel1Led185 = 946, - CustomDeviceChannel1Led186 = 947, - CustomDeviceChannel1Led187 = 948, - CustomDeviceChannel1Led188 = 949, - CustomDeviceChannel1Led189 = 950, - CustomDeviceChannel1Led190 = 951, - CustomDeviceChannel1Led191 = 952, - CustomDeviceChannel1Led192 = 953, - CustomDeviceChannel1Led193 = 954, - CustomDeviceChannel1Led194 = 955, - CustomDeviceChannel1Led195 = 956, - CustomDeviceChannel1Led196 = 957, - CustomDeviceChannel1Led197 = 958, - CustomDeviceChannel1Led198 = 959, - CustomDeviceChannel1Led199 = 960, - CustomDeviceChannel1Led200 = 961, - CustomDeviceChannel1Led201 = 962, - CustomDeviceChannel1Led202 = 963, - CustomDeviceChannel1Led203 = 964, - CustomDeviceChannel1Led204 = 965, - CustomDeviceChannel1Led205 = 966, - CustomDeviceChannel1Led206 = 967, - CustomDeviceChannel1Led207 = 968, - CustomDeviceChannel1Led208 = 969, - CustomDeviceChannel1Led209 = 970, - CustomDeviceChannel1Led210 = 971, - CustomDeviceChannel1Led211 = 972, - CustomDeviceChannel1Led212 = 973, - CustomDeviceChannel1Led213 = 974, - CustomDeviceChannel1Led214 = 975, - CustomDeviceChannel1Led215 = 976, - CustomDeviceChannel1Led216 = 977, - CustomDeviceChannel1Led217 = 978, - CustomDeviceChannel1Led218 = 979, - CustomDeviceChannel1Led219 = 980, - CustomDeviceChannel1Led220 = 981, - CustomDeviceChannel1Led221 = 982, - CustomDeviceChannel1Led222 = 983, - CustomDeviceChannel1Led223 = 984, - CustomDeviceChannel1Led224 = 985, - CustomDeviceChannel1Led225 = 986, - CustomDeviceChannel1Led226 = 987, - CustomDeviceChannel1Led227 = 988, - CustomDeviceChannel1Led228 = 989, - CustomDeviceChannel1Led229 = 990, - CustomDeviceChannel1Led230 = 991, - CustomDeviceChannel1Led231 = 992, - CustomDeviceChannel1Led232 = 993, - CustomDeviceChannel1Led233 = 994, - CustomDeviceChannel1Led234 = 995, - CustomDeviceChannel1Led235 = 996, - CustomDeviceChannel1Led236 = 997, - CustomDeviceChannel1Led237 = 998, - CustomDeviceChannel1Led238 = 999, - CustomDeviceChannel1Led239 = 1000, - CustomDeviceChannel1Led240 = 1001, - CustomDeviceChannel1Led241 = 1002, - CustomDeviceChannel1Led242 = 1003, - CustomDeviceChannel1Led243 = 1004, - CustomDeviceChannel1Led244 = 1005, - CustomDeviceChannel1Led245 = 1006, - CustomDeviceChannel1Led246 = 1007, - CustomDeviceChannel1Led247 = 1008, - CustomDeviceChannel1Led248 = 1009, - CustomDeviceChannel1Led249 = 1010, - CustomDeviceChannel1Led250 = 1011, - CustomDeviceChannel1Led251 = 1012, - CustomDeviceChannel1Led252 = 1013, - CustomDeviceChannel1Led253 = 1014, - CustomDeviceChannel1Led254 = 1015, - CustomDeviceChannel1Led255 = 1016, - CustomDeviceChannel1Led256 = 1017, - CustomDeviceChannel1Led257 = 1018, - CustomDeviceChannel1Led258 = 1019, - CustomDeviceChannel1Led259 = 1020, - CustomDeviceChannel1Led260 = 1021, - CustomDeviceChannel1Led261 = 1022, - CustomDeviceChannel1Led262 = 1023, - CustomDeviceChannel1Led263 = 1024, - CustomDeviceChannel1Led264 = 1025, - CustomDeviceChannel1Led265 = 1026, - CustomDeviceChannel1Led266 = 1027, - CustomDeviceChannel1Led267 = 1028, - CustomDeviceChannel1Led268 = 1029, - CustomDeviceChannel1Led269 = 1030, - CustomDeviceChannel1Led270 = 1031, - CustomDeviceChannel1Led271 = 1032, - CustomDeviceChannel1Led272 = 1033, - CustomDeviceChannel1Led273 = 1034, - CustomDeviceChannel1Led274 = 1035, - CustomDeviceChannel1Led275 = 1036, - CustomDeviceChannel1Led276 = 1037, - CustomDeviceChannel1Led277 = 1038, - CustomDeviceChannel1Led278 = 1039, - CustomDeviceChannel1Led279 = 1040, - CustomDeviceChannel1Led280 = 1041, - CustomDeviceChannel1Led281 = 1042, - CustomDeviceChannel1Led282 = 1043, - CustomDeviceChannel1Led283 = 1044, - CustomDeviceChannel1Led284 = 1045, - CustomDeviceChannel1Led285 = 1046, - CustomDeviceChannel1Led286 = 1047, - CustomDeviceChannel1Led287 = 1048, - CustomDeviceChannel1Led288 = 1049, - CustomDeviceChannel1Led289 = 1050, - CustomDeviceChannel1Led290 = 1051, - CustomDeviceChannel1Led291 = 1052, - CustomDeviceChannel1Led292 = 1053, - CustomDeviceChannel1Led293 = 1054, - CustomDeviceChannel1Led294 = 1055, - CustomDeviceChannel1Led295 = 1056, - CustomDeviceChannel1Led296 = 1057, - CustomDeviceChannel1Led297 = 1058, - CustomDeviceChannel1Led298 = 1059, - CustomDeviceChannel1Led299 = 1060, - CustomDeviceChannel1Led300 = 1061, - - CustomDeviceChannel2Led151 = 1062, - CustomDeviceChannel2Led152 = 1063, - CustomDeviceChannel2Led153 = 1064, - CustomDeviceChannel2Led154 = 1065, - CustomDeviceChannel2Led155 = 1066, - CustomDeviceChannel2Led156 = 1067, - CustomDeviceChannel2Led157 = 1068, - CustomDeviceChannel2Led158 = 1069, - CustomDeviceChannel2Led159 = 1070, - CustomDeviceChannel2Led160 = 1071, - CustomDeviceChannel2Led161 = 1072, - CustomDeviceChannel2Led162 = 1073, - CustomDeviceChannel2Led163 = 1074, - CustomDeviceChannel2Led164 = 1075, - CustomDeviceChannel2Led165 = 1076, - CustomDeviceChannel2Led166 = 1077, - CustomDeviceChannel2Led167 = 1078, - CustomDeviceChannel2Led168 = 1079, - CustomDeviceChannel2Led169 = 1080, - CustomDeviceChannel2Led170 = 1081, - CustomDeviceChannel2Led171 = 1082, - CustomDeviceChannel2Led172 = 1083, - CustomDeviceChannel2Led173 = 1084, - CustomDeviceChannel2Led174 = 1085, - CustomDeviceChannel2Led175 = 1086, - CustomDeviceChannel2Led176 = 1087, - CustomDeviceChannel2Led177 = 1088, - CustomDeviceChannel2Led178 = 1089, - CustomDeviceChannel2Led179 = 1090, - CustomDeviceChannel2Led180 = 1091, - CustomDeviceChannel2Led181 = 1092, - CustomDeviceChannel2Led182 = 1093, - CustomDeviceChannel2Led183 = 1094, - CustomDeviceChannel2Led184 = 1095, - CustomDeviceChannel2Led185 = 1096, - CustomDeviceChannel2Led186 = 1097, - CustomDeviceChannel2Led187 = 1098, - CustomDeviceChannel2Led188 = 1099, - CustomDeviceChannel2Led189 = 1100, - CustomDeviceChannel2Led190 = 1101, - CustomDeviceChannel2Led191 = 1102, - CustomDeviceChannel2Led192 = 1103, - CustomDeviceChannel2Led193 = 1104, - CustomDeviceChannel2Led194 = 1105, - CustomDeviceChannel2Led195 = 1106, - CustomDeviceChannel2Led196 = 1107, - CustomDeviceChannel2Led197 = 1108, - CustomDeviceChannel2Led198 = 1109, - CustomDeviceChannel2Led199 = 1110, - CustomDeviceChannel2Led200 = 1111, - CustomDeviceChannel2Led201 = 1112, - CustomDeviceChannel2Led202 = 1113, - CustomDeviceChannel2Led203 = 1114, - CustomDeviceChannel2Led204 = 1115, - CustomDeviceChannel2Led205 = 1116, - CustomDeviceChannel2Led206 = 1117, - CustomDeviceChannel2Led207 = 1118, - CustomDeviceChannel2Led208 = 1119, - CustomDeviceChannel2Led209 = 1120, - CustomDeviceChannel2Led210 = 1121, - CustomDeviceChannel2Led211 = 1122, - CustomDeviceChannel2Led212 = 1123, - CustomDeviceChannel2Led213 = 1124, - CustomDeviceChannel2Led214 = 1125, - CustomDeviceChannel2Led215 = 1126, - CustomDeviceChannel2Led216 = 1127, - CustomDeviceChannel2Led217 = 1128, - CustomDeviceChannel2Led218 = 1129, - CustomDeviceChannel2Led219 = 1130, - CustomDeviceChannel2Led220 = 1131, - CustomDeviceChannel2Led221 = 1132, - CustomDeviceChannel2Led222 = 1133, - CustomDeviceChannel2Led223 = 1134, - CustomDeviceChannel2Led224 = 1135, - CustomDeviceChannel2Led225 = 1136, - CustomDeviceChannel2Led226 = 1137, - CustomDeviceChannel2Led227 = 1138, - CustomDeviceChannel2Led228 = 1139, - CustomDeviceChannel2Led229 = 1140, - CustomDeviceChannel2Led230 = 1141, - CustomDeviceChannel2Led231 = 1142, - CustomDeviceChannel2Led232 = 1143, - CustomDeviceChannel2Led233 = 1144, - CustomDeviceChannel2Led234 = 1145, - CustomDeviceChannel2Led235 = 1146, - CustomDeviceChannel2Led236 = 1147, - CustomDeviceChannel2Led237 = 1148, - CustomDeviceChannel2Led238 = 1149, - CustomDeviceChannel2Led239 = 1150, - CustomDeviceChannel2Led240 = 1151, - CustomDeviceChannel2Led241 = 1152, - CustomDeviceChannel2Led242 = 1153, - CustomDeviceChannel2Led243 = 1154, - CustomDeviceChannel2Led244 = 1155, - CustomDeviceChannel2Led245 = 1156, - CustomDeviceChannel2Led246 = 1157, - CustomDeviceChannel2Led247 = 1158, - CustomDeviceChannel2Led248 = 1159, - CustomDeviceChannel2Led249 = 1160, - CustomDeviceChannel2Led250 = 1161, - CustomDeviceChannel2Led251 = 1162, - CustomDeviceChannel2Led252 = 1163, - CustomDeviceChannel2Led253 = 1164, - CustomDeviceChannel2Led254 = 1165, - CustomDeviceChannel2Led255 = 1166, - CustomDeviceChannel2Led256 = 1167, - CustomDeviceChannel2Led257 = 1168, - CustomDeviceChannel2Led258 = 1169, - CustomDeviceChannel2Led259 = 1170, - CustomDeviceChannel2Led260 = 1171, - CustomDeviceChannel2Led261 = 1172, - CustomDeviceChannel2Led262 = 1173, - CustomDeviceChannel2Led263 = 1174, - CustomDeviceChannel2Led264 = 1175, - CustomDeviceChannel2Led265 = 1176, - CustomDeviceChannel2Led266 = 1177, - CustomDeviceChannel2Led267 = 1178, - CustomDeviceChannel2Led268 = 1179, - CustomDeviceChannel2Led269 = 1180, - CustomDeviceChannel2Led270 = 1181, - CustomDeviceChannel2Led271 = 1182, - CustomDeviceChannel2Led272 = 1183, - CustomDeviceChannel2Led273 = 1184, - CustomDeviceChannel2Led274 = 1185, - CustomDeviceChannel2Led275 = 1186, - CustomDeviceChannel2Led276 = 1187, - CustomDeviceChannel2Led277 = 1188, - CustomDeviceChannel2Led278 = 1189, - CustomDeviceChannel2Led279 = 1190, - CustomDeviceChannel2Led280 = 1191, - CustomDeviceChannel2Led281 = 1192, - CustomDeviceChannel2Led282 = 1193, - CustomDeviceChannel2Led283 = 1194, - CustomDeviceChannel2Led284 = 1195, - CustomDeviceChannel2Led285 = 1196, - CustomDeviceChannel2Led286 = 1197, - CustomDeviceChannel2Led287 = 1198, - CustomDeviceChannel2Led288 = 1199, - CustomDeviceChannel2Led289 = 1200, - CustomDeviceChannel2Led290 = 1201, - CustomDeviceChannel2Led291 = 1202, - CustomDeviceChannel2Led292 = 1203, - CustomDeviceChannel2Led293 = 1204, - CustomDeviceChannel2Led294 = 1205, - CustomDeviceChannel2Led295 = 1206, - CustomDeviceChannel2Led296 = 1207, - CustomDeviceChannel2Led297 = 1208, - CustomDeviceChannel2Led298 = 1209, - CustomDeviceChannel2Led299 = 1210, - CustomDeviceChannel2Led300 = 1211, - - CustomDeviceChannel3Led151 = 1212, - CustomDeviceChannel3Led152 = 1213, - CustomDeviceChannel3Led153 = 1214, - CustomDeviceChannel3Led154 = 1215, - CustomDeviceChannel3Led155 = 1216, - CustomDeviceChannel3Led156 = 1217, - CustomDeviceChannel3Led157 = 1218, - CustomDeviceChannel3Led158 = 1219, - CustomDeviceChannel3Led159 = 1220, - CustomDeviceChannel3Led160 = 1221, - CustomDeviceChannel3Led161 = 1222, - CustomDeviceChannel3Led162 = 1223, - CustomDeviceChannel3Led163 = 1224, - CustomDeviceChannel3Led164 = 1225, - CustomDeviceChannel3Led165 = 1226, - CustomDeviceChannel3Led166 = 1227, - CustomDeviceChannel3Led167 = 1228, - CustomDeviceChannel3Led168 = 1229, - CustomDeviceChannel3Led169 = 1230, - CustomDeviceChannel3Led170 = 1231, - CustomDeviceChannel3Led171 = 1232, - CustomDeviceChannel3Led172 = 1233, - CustomDeviceChannel3Led173 = 1234, - CustomDeviceChannel3Led174 = 1235, - CustomDeviceChannel3Led175 = 1236, - CustomDeviceChannel3Led176 = 1237, - CustomDeviceChannel3Led177 = 1238, - CustomDeviceChannel3Led178 = 1239, - CustomDeviceChannel3Led179 = 1240, - CustomDeviceChannel3Led180 = 1241, - CustomDeviceChannel3Led181 = 1242, - CustomDeviceChannel3Led182 = 1243, - CustomDeviceChannel3Led183 = 1244, - CustomDeviceChannel3Led184 = 1245, - CustomDeviceChannel3Led185 = 1246, - CustomDeviceChannel3Led186 = 1247, - CustomDeviceChannel3Led187 = 1248, - CustomDeviceChannel3Led188 = 1249, - CustomDeviceChannel3Led189 = 1250, - CustomDeviceChannel3Led190 = 1251, - CustomDeviceChannel3Led191 = 1252, - CustomDeviceChannel3Led192 = 1253, - CustomDeviceChannel3Led193 = 1254, - CustomDeviceChannel3Led194 = 1255, - CustomDeviceChannel3Led195 = 1256, - CustomDeviceChannel3Led196 = 1257, - CustomDeviceChannel3Led197 = 1258, - CustomDeviceChannel3Led198 = 1259, - CustomDeviceChannel3Led199 = 1260, - CustomDeviceChannel3Led200 = 1261, - CustomDeviceChannel3Led201 = 1262, - CustomDeviceChannel3Led202 = 1263, - CustomDeviceChannel3Led203 = 1264, - CustomDeviceChannel3Led204 = 1265, - CustomDeviceChannel3Led205 = 1266, - CustomDeviceChannel3Led206 = 1267, - CustomDeviceChannel3Led207 = 1268, - CustomDeviceChannel3Led208 = 1269, - CustomDeviceChannel3Led209 = 1270, - CustomDeviceChannel3Led210 = 1271, - CustomDeviceChannel3Led211 = 1272, - CustomDeviceChannel3Led212 = 1273, - CustomDeviceChannel3Led213 = 1274, - CustomDeviceChannel3Led214 = 1275, - CustomDeviceChannel3Led215 = 1276, - CustomDeviceChannel3Led216 = 1277, - CustomDeviceChannel3Led217 = 1278, - CustomDeviceChannel3Led218 = 1279, - CustomDeviceChannel3Led219 = 1280, - CustomDeviceChannel3Led220 = 1281, - CustomDeviceChannel3Led221 = 1282, - CustomDeviceChannel3Led222 = 1283, - CustomDeviceChannel3Led223 = 1284, - CustomDeviceChannel3Led224 = 1285, - CustomDeviceChannel3Led225 = 1286, - CustomDeviceChannel3Led226 = 1287, - CustomDeviceChannel3Led227 = 1288, - CustomDeviceChannel3Led228 = 1289, - CustomDeviceChannel3Led229 = 1290, - CustomDeviceChannel3Led230 = 1291, - CustomDeviceChannel3Led231 = 1292, - CustomDeviceChannel3Led232 = 1293, - CustomDeviceChannel3Led233 = 1294, - CustomDeviceChannel3Led234 = 1295, - CustomDeviceChannel3Led235 = 1296, - CustomDeviceChannel3Led236 = 1297, - CustomDeviceChannel3Led237 = 1298, - CustomDeviceChannel3Led238 = 1299, - CustomDeviceChannel3Led239 = 1300, - CustomDeviceChannel3Led240 = 1301, - CustomDeviceChannel3Led241 = 1302, - CustomDeviceChannel3Led242 = 1303, - CustomDeviceChannel3Led243 = 1304, - CustomDeviceChannel3Led244 = 1305, - CustomDeviceChannel3Led245 = 1306, - CustomDeviceChannel3Led246 = 1307, - CustomDeviceChannel3Led247 = 1308, - CustomDeviceChannel3Led248 = 1309, - CustomDeviceChannel3Led249 = 1310, - CustomDeviceChannel3Led250 = 1311, - CustomDeviceChannel3Led251 = 1312, - CustomDeviceChannel3Led252 = 1313, - CustomDeviceChannel3Led253 = 1314, - CustomDeviceChannel3Led254 = 1315, - CustomDeviceChannel3Led255 = 1316, - CustomDeviceChannel3Led256 = 1317, - CustomDeviceChannel3Led257 = 1318, - CustomDeviceChannel3Led258 = 1319, - CustomDeviceChannel3Led259 = 1320, - CustomDeviceChannel3Led260 = 1321, - CustomDeviceChannel3Led261 = 1322, - CustomDeviceChannel3Led262 = 1323, - CustomDeviceChannel3Led263 = 1324, - CustomDeviceChannel3Led264 = 1325, - CustomDeviceChannel3Led265 = 1326, - CustomDeviceChannel3Led266 = 1327, - CustomDeviceChannel3Led267 = 1328, - CustomDeviceChannel3Led268 = 1329, - CustomDeviceChannel3Led269 = 1330, - CustomDeviceChannel3Led270 = 1331, - CustomDeviceChannel3Led271 = 1332, - CustomDeviceChannel3Led272 = 1333, - CustomDeviceChannel3Led273 = 1334, - CustomDeviceChannel3Led274 = 1335, - CustomDeviceChannel3Led275 = 1336, - CustomDeviceChannel3Led276 = 1337, - CustomDeviceChannel3Led277 = 1338, - CustomDeviceChannel3Led278 = 1339, - CustomDeviceChannel3Led279 = 1340, - CustomDeviceChannel3Led280 = 1341, - CustomDeviceChannel3Led281 = 1342, - CustomDeviceChannel3Led282 = 1343, - CustomDeviceChannel3Led283 = 1344, - CustomDeviceChannel3Led284 = 1345, - CustomDeviceChannel3Led285 = 1346, - CustomDeviceChannel3Led286 = 1347, - CustomDeviceChannel3Led287 = 1348, - CustomDeviceChannel3Led288 = 1349, - CustomDeviceChannel3Led289 = 1350, - CustomDeviceChannel3Led290 = 1351, - CustomDeviceChannel3Led291 = 1352, - CustomDeviceChannel3Led292 = 1353, - CustomDeviceChannel3Led293 = 1354, - CustomDeviceChannel3Led294 = 1355, - CustomDeviceChannel3Led295 = 1356, - CustomDeviceChannel3Led296 = 1357, - CustomDeviceChannel3Led297 = 1358, - CustomDeviceChannel3Led298 = 1359, - CustomDeviceChannel3Led299 = 1360, - CustomDeviceChannel3Led300 = 1361, - - Mainboard1 = 1362, - Mainboard2 = 1363, - Mainboard3 = 1364, - Mainboard4 = 1365, - Mainboard5 = 1366, - Mainboard6 = 1367, - Mainboard7 = 1368, - Mainboard8 = 1369, - Mainboard9 = 1370, - Mainboard10 = 1371, - Mainboard11 = 1372, - Mainboard12 = 1373, - Mainboard13 = 1374, - Mainboard14 = 1375, - Mainboard15 = 1376, - Mainboard16 = 1377, - Mainboard17 = 1378, - Mainboard18 = 1379, - Mainboard19 = 1380, - Mainboard20 = 1381, - Mainboard21 = 1382, - Mainboard22 = 1383, - Mainboard23 = 1384, - Mainboard24 = 1385, - Mainboard25 = 1386, - Mainboard26 = 1387, - Mainboard27 = 1388, - Mainboard28 = 1389, - Mainboard29 = 1390, - Mainboard30 = 1391, - Mainboard31 = 1392, - Mainboard32 = 1393, - Mainboard33 = 1394, - Mainboard34 = 1395, - Mainboard35 = 1396, - Mainboard36 = 1397, - Mainboard37 = 1398, - Mainboard38 = 1399, - Mainboard39 = 1400, - Mainboard40 = 1401, - Mainboard41 = 1402, - Mainboard42 = 1403, - Mainboard43 = 1404, - Mainboard44 = 1405, - Mainboard45 = 1406, - Mainboard46 = 1407, - Mainboard47 = 1408, - Mainboard48 = 1409, - Mainboard49 = 1410, - Mainboard50 = 1411, - Mainboard51 = 1412, - Mainboard52 = 1413, - Mainboard53 = 1414, - Mainboard54 = 1415, - Mainboard55 = 1416, - Mainboard56 = 1417, - Mainboard57 = 1418, - Mainboard58 = 1419, - Mainboard59 = 1420, - Mainboard60 = 1421, - Mainboard61 = 1422, - Mainboard62 = 1423, - Mainboard63 = 1424, - Mainboard64 = 1425, - Mainboard65 = 1426, - Mainboard66 = 1427, - Mainboard67 = 1428, - Mainboard68 = 1429, - Mainboard69 = 1430, - Mainboard70 = 1431, - Mainboard71 = 1432, - Mainboard72 = 1433, - Mainboard73 = 1434, - Mainboard74 = 1435, - Mainboard75 = 1436, - Mainboard76 = 1437, - Mainboard77 = 1438, - Mainboard78 = 1439, - Mainboard79 = 1440, - Mainboard80 = 1441, - Mainboard81 = 1442, - Mainboard82 = 1443, - Mainboard83 = 1444, - Mainboard84 = 1445, - Mainboard85 = 1446, - Mainboard86 = 1447, - Mainboard87 = 1448, - Mainboard88 = 1449, - Mainboard89 = 1450, - Mainboard90 = 1451, - Mainboard91 = 1452, - Mainboard92 = 1453, - Mainboard93 = 1454, - Mainboard94 = 1455, - Mainboard95 = 1456, - Mainboard96 = 1457, - Mainboard97 = 1458, - Mainboard98 = 1459, - Mainboard99 = 1460, - Mainboard100 = 1461, - - GPU1 = 1462, - GPU2 = 1463, - GPU3 = 1464, - GPU4 = 1465, - GPU5 = 1466, - GPU6 = 1467, - GPU7 = 1468, - GPU8 = 1469, - GPU9 = 1470, - GPU10 = 1471, - GPU11 = 1472, - GPU12 = 1473, - GPU13 = 1474, - GPU14 = 1475, - GPU15 = 1476, - GPU16 = 1477, - GPU17 = 1478, - GPU18 = 1479, - GPU19 = 1480, - GPU20 = 1481, - GPU21 = 1482, - GPU22 = 1483, - GPU23 = 1484, - GPU24 = 1485, - GPU25 = 1486, - GPU26 = 1487, - GPU27 = 1488, - GPU28 = 1489, - GPU29 = 1490, - GPU30 = 1491, - GPU31 = 1492, - GPU32 = 1493, - GPU33 = 1494, - GPU34 = 1495, - GPU35 = 1496, - GPU36 = 1497, - GPU37 = 1498, - GPU38 = 1499, - GPU39 = 1500, - GPU40 = 1501, - GPU41 = 1502, - GPU42 = 1503, - GPU43 = 1504, - GPU44 = 1505, - GPU45 = 1506, - GPU46 = 1507, - GPU47 = 1508, - GPU48 = 1509, - GPU49 = 1510, - GPU50 = 1511, - - Lightbar20 = 1512, - Lightbar21 = 1513, - Lightbar22 = 1514, - Lightbar23 = 1515, - Lightbar24 = 1516, - Lightbar25 = 1517, - Lightbar26 = 1518, - Lightbar27 = 1519, - Lightbar28 = 1520, - Lightbar29 = 1521, - Lightbar30 = 1522, - Lightbar31 = 1523, - Lightbar32 = 1524, - Lightbar33 = 1525, - Lightbar34 = 1526, - Lightbar35 = 1527, - Lightbar36 = 1528, - Lightbar37 = 1529, - Lightbar38 = 1530, - Lightbar39 = 1531, - Lightbar40 = 1532, - Lightbar41 = 1533, - Lightbar42 = 1534, - Lightbar43 = 1535, - Lightbar44 = 1536, - Lightbar45 = 1537, - Lightbar46 = 1538, - Lightbar47 = 1539, - Lightbar48 = 1540, - Lightbar49 = 1541, - Lightbar50 = 1542, - - Profile = 1543, - - OemLed101 = 1544, - OemLed102 = 1545, - OemLed103 = 1546, - OemLed104 = 1547, - OemLed105 = 1548, - OemLed106 = 1549, - OemLed107 = 1550, - OemLed108 = 1551, - OemLed109 = 1552, - OemLed110 = 1553, - OemLed111 = 1554, - OemLed112 = 1555, - OemLed113 = 1556, - OemLed114 = 1557, - OemLed115 = 1558, - OemLed116 = 1559, - OemLed117 = 1560, - OemLed118 = 1561, - OemLed119 = 1562, - OemLed120 = 1563, - OemLed121 = 1564, - OemLed122 = 1565, - OemLed123 = 1566, - OemLed124 = 1567, - OemLed125 = 1568, - OemLed126 = 1569, - OemLed127 = 1570, - OemLed128 = 1571, - OemLed129 = 1572, - OemLed130 = 1573, - OemLed131 = 1574, - OemLed132 = 1575, - OemLed133 = 1576, - OemLed134 = 1577, - OemLed135 = 1578, - OemLed136 = 1579, - OemLed137 = 1580, - OemLed138 = 1581, - OemLed139 = 1582, - OemLed140 = 1583, - OemLed141 = 1584, - OemLed142 = 1585, - OemLed143 = 1586, - OemLed144 = 1587, - OemLed145 = 1588, - OemLed146 = 1589, - OemLed147 = 1590, - OemLed148 = 1591, - OemLed149 = 1592, - OemLed150 = 1593, - OemLed151 = 1594, - OemLed152 = 1595, - OemLed153 = 1596, - OemLed154 = 1597, - OemLed155 = 1598, - OemLed156 = 1599, - OemLed157 = 1600, - OemLed158 = 1601, - OemLed159 = 1602, - OemLed160 = 1603, - OemLed161 = 1604, - OemLed162 = 1605, - OemLed163 = 1606, - OemLed164 = 1607, - OemLed165 = 1608, - OemLed166 = 1609, - OemLed167 = 1610, - OemLed168 = 1611, - OemLed169 = 1612, - OemLed170 = 1613, - OemLed171 = 1614, - OemLed172 = 1615, - OemLed173 = 1616, - OemLed174 = 1617, - OemLed175 = 1618, - OemLed176 = 1619, - OemLed177 = 1620, - OemLed178 = 1621, - OemLed179 = 1622, - OemLed180 = 1623, - OemLed181 = 1624, - OemLed182 = 1625, - OemLed183 = 1626, - OemLed184 = 1627, - OemLed185 = 1628, - OemLed186 = 1629, - OemLed187 = 1630, - OemLed188 = 1631, - OemLed189 = 1632, - OemLed190 = 1633, - OemLed191 = 1634, - OemLed192 = 1635, - OemLed193 = 1636, - OemLed194 = 1637, - OemLed195 = 1638, - OemLed196 = 1639, - OemLed197 = 1640, - OemLed198 = 1641, - OemLed199 = 1642, - OemLed200 = 1643, - OemLed201 = 1644, - OemLed202 = 1645, - OemLed203 = 1646, - OemLed204 = 1647, - OemLed205 = 1648, - OemLed206 = 1649, - OemLed207 = 1650, - OemLed208 = 1651, - OemLed209 = 1652, - OemLed210 = 1653, - OemLed211 = 1654, - OemLed212 = 1655, - OemLed213 = 1656, - OemLed214 = 1657, - OemLed215 = 1658, - OemLed216 = 1659, - OemLed217 = 1660, - OemLed218 = 1661, - OemLed219 = 1662, - OemLed220 = 1663, - OemLed221 = 1664, - OemLed222 = 1665, - OemLed223 = 1666, - OemLed224 = 1667, - OemLed225 = 1668, - OemLed226 = 1669, - OemLed227 = 1670, - OemLed228 = 1671, - OemLed229 = 1672, - OemLed230 = 1673, - OemLed231 = 1674, - OemLed232 = 1675, - OemLed233 = 1676, - OemLed234 = 1677, - OemLed235 = 1678, - OemLed236 = 1679, - OemLed237 = 1680, - OemLed238 = 1681, - OemLed239 = 1682, - OemLed240 = 1683, - OemLed241 = 1684, - OemLed242 = 1685, - OemLed243 = 1686, - OemLed244 = 1687, - OemLed245 = 1688, - OemLed246 = 1689, - OemLed247 = 1690, - OemLed248 = 1691, - OemLed249 = 1692, - OemLed250 = 1693, - - B7 = 1694, - B8 = 1695, - B9 = 1696, - B10 = 1697, - B11 = 1698, - B12 = 1699, - B13 = 1700, - B14 = 1701, - B15 = 1702, - B16 = 1703, - B17 = 1704, - B18 = 1705, - B19 = 1706, - B20 = 1707, -} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairLedIdKeyboard.cs b/RGB.NET.Devices.Corsair/Enum/CorsairLedIdKeyboard.cs new file mode 100644 index 00000000..3b5ad52e --- /dev/null +++ b/RGB.NET.Devices.Corsair/Enum/CorsairLedIdKeyboard.cs @@ -0,0 +1,142 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global +#pragma warning disable 1591 + +namespace RGB.NET.Devices.Corsair; + +/// +/// iCUE-SDK: contains a list of keyboard leds that belong to CLG_Keyboard group +/// +public enum CorsairLedIdKeyboard +{ + Invalid = 0, + Escape = 1, + F1 = 2, + F2 = 3, + F3 = 4, + F4 = 5, + F5 = 6, + F6 = 7, + F7 = 8, + F8 = 9, + F9 = 10, + F10 = 11, + F11 = 12, + F12 = 13, + GraveAccentAndTilde = 14, + One = 15, + Two = 16, + Three = 17, + Four = 18, + Five = 19, + Six = 20, + Seven = 21, + Eight = 22, + Nine = 23, + Zero = 24, + MinusAndUnderscore = 25, + EqualsAndPlus = 26, + Backspace = 27, + Tab = 28, + Q = 29, + W = 30, + E = 31, + R = 32, + T = 33, + Y = 34, + U = 35, + I = 36, + O = 37, + P = 38, + BracketLeft = 39, + BracketRight = 40, + CapsLock = 41, + A = 42, + S = 43, + D = 44, + F = 45, + G = 46, + H = 47, + J = 48, + K = 49, + L = 50, + SemicolonAndColon = 51, + ApostropheAndDoubleQuote = 52, + Backslash = 53, + Enter = 54, + LeftShift = 55, + NonUsBackslash = 56, + Z = 57, + X = 58, + C = 59, + V = 60, + B = 61, + N = 62, + M = 63, + CommaAndLessThan = 64, + PeriodAndBiggerThan = 65, + SlashAndQuestionMark = 66, + RightShift = 67, + LeftCtrl = 68, + LeftGui = 69, + LeftAlt = 70, + Space = 71, + RightAlt = 72, + RightGui = 73, + Application = 74, + RightCtrl = 75, + LedProgramming = 76, + Lang1 = 77, + Lang2 = 78, + International1 = 79, + International2 = 80, + International3 = 81, + International4 = 82, + International5 = 83, + PrintScreen = 84, + ScrollLock = 85, + PauseBreak = 86, + Insert = 87, + Home = 88, + PageUp = 89, + Delete = 90, + End = 91, + PageDown = 92, + UpArrow = 93, + LeftArrow = 94, + DownArrow = 95, + RightArrow = 96, + NonUsTilde = 97, + Brightness = 98, + WinLock = 99, + Mute = 100, + Stop = 101, + ScanPreviousTrack = 102, + PlayPause = 103, + ScanNextTrack = 104, + NumLock = 105, + KeypadSlash = 106, + KeypadAsterisk = 107, + KeypadMinus = 108, + Keypad7 = 109, + Keypad8 = 110, + Keypad9 = 111, + KeypadPlus = 112, + Keypad4 = 113, + Keypad5 = 114, + Keypad6 = 115, + Keypad1 = 116, + Keypad2 = 117, + Keypad3 = 118, + KeypadComma = 119, + KeypadEnter = 120, + Keypad0 = 121, + KeypadPeriodAndDelete = 122, + VolumeUp = 123, + VolumeDown = 124, + MR = 125, + M1 = 126, + M2 = 127, + M3 = 128, + Fn = 129 +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairLogicalKeyboardLayout.cs b/RGB.NET.Devices.Corsair/Enum/CorsairLogicalKeyboardLayout.cs index ebc4e1b8..d5325bb0 100644 --- a/RGB.NET.Devices.Corsair/Enum/CorsairLogicalKeyboardLayout.cs +++ b/RGB.NET.Devices.Corsair/Enum/CorsairLogicalKeyboardLayout.cs @@ -1,14 +1,14 @@ // ReSharper disable InconsistentNaming // ReSharper disable UnusedMember.Global -#pragma warning disable 1591 namespace RGB.NET.Devices.Corsair; /// -/// Contains a list of available logical layouts for corsair keyboards. +/// iCUE-SDK: Contains a list of available logical layouts for corsair keyboards. /// public enum CorsairLogicalKeyboardLayout { + Invalid = 0, US_Int = 1, NA = 2, EU = 3, diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairPhysicalKeyboardLayout.cs b/RGB.NET.Devices.Corsair/Enum/CorsairPhysicalKeyboardLayout.cs index 9f5c1c37..f02cd6c2 100644 --- a/RGB.NET.Devices.Corsair/Enum/CorsairPhysicalKeyboardLayout.cs +++ b/RGB.NET.Devices.Corsair/Enum/CorsairPhysicalKeyboardLayout.cs @@ -4,32 +4,14 @@ namespace RGB.NET.Devices.Corsair; /// -/// Contains a list of available physical layouts for corsair keyboards. +/// iCUE-SDK: Contains a list of available physical layouts for corsair keyboards. /// public enum CorsairPhysicalKeyboardLayout { - /// - /// US-Keyboard - /// + Invalid = 0, US = 1, - - /// - /// UK-Keyboard - /// UK = 2, - - /// - /// BR-Keyboard - /// - BR = 3, - - /// - /// JP-Keyboard - /// - JP = 4, - - /// - /// KR-Keyboard - /// - KR = 5 + JP = 3, + KR = 4, + BR = 5 } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairPhysicalMouseLayout.cs b/RGB.NET.Devices.Corsair/Enum/CorsairPhysicalMouseLayout.cs deleted file mode 100644 index 33c317c3..00000000 --- a/RGB.NET.Devices.Corsair/Enum/CorsairPhysicalMouseLayout.cs +++ /dev/null @@ -1,107 +0,0 @@ -namespace RGB.NET.Devices.Corsair; - -/// -/// Contains a list of available physical layouts for mice. -/// -public enum CorsairPhysicalMouseLayout -{ - /// - /// Zone1-Mouse - /// - Zones1 = 6, - - /// - /// Zone2-Mouse - /// - Zones2 = 7, - - /// - /// Zone3-Mouse - /// - Zones3 = 8, - - /// - /// Zone4-Mouse - /// - Zones4 = 9, - - /// - /// Zone5-Mouse - /// - Zones5 = 101, - - /// - /// Zone6-Mouse - /// - Zones6 = 11, - - /// - /// Zone7-Mouse - /// - Zones7 = 12, - - /// - /// Zone8-Mouse - /// - Zones8 = 13, - - /// - /// Zone9-Mouse - /// - Zones9 = 14, - - /// - /// Zone10-Mouse - /// - Zones10 = 15, - - /// - /// Zone11-Mouse - /// - Zones11 = 16, - - /// - /// Zone12-Mouse - /// - Zones12 = 17, - - /// - /// Zone13-Mouse - /// - Zones13 = 18, - - /// - /// Zone14-Mouse - /// - Zones14 = 19, - - /// - /// Zone15-Mouse - /// - Zones15 = 20, - - /// - /// Zone16-Mouse - /// - Zones16 = 21, - - /// - /// Zone17-Mouse - /// - Zones17 = 22, - - /// - /// Zone18-Mouse - /// - Zones18 = 23, - - /// - /// Zone19-Mouse - /// - Zones19 = 24, - - /// - /// Zone20-Mouse - /// - Zones20 = 25 -} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairPropertyFlag.cs b/RGB.NET.Devices.Corsair/Enum/CorsairPropertyFlag.cs new file mode 100644 index 00000000..f0e45068 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Enum/CorsairPropertyFlag.cs @@ -0,0 +1,30 @@ +using System; + +namespace RGB.NET.Devices.Corsair; + +/// +/// iCUE-SDK: contains list of operations that can be applied to the property +/// +[Flags] +public enum CorsairPropertyFlag +{ + /// + /// - + /// + None = 0x00, + + /// + /// iCUE-SDK: describes readable property + /// + CanRead = 0x01, + + /// + /// iCUE-SDK: describes writable property + /// + CanWrite = 0x02, + + /// + /// iCUE-SDK: if flag is set, then index should be used to read/write multiple properties that share the same property identifier + /// + Indexed = 0x04 +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairSessionState.cs b/RGB.NET.Devices.Corsair/Enum/CorsairSessionState.cs new file mode 100644 index 00000000..c78dce18 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Enum/CorsairSessionState.cs @@ -0,0 +1,45 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global + +namespace RGB.NET.Devices.Corsair; + +/// +/// iCUE-SDK: contains a list of all possible session states +/// +public enum CorsairSessionState +{ + /// + /// iCUE-SDK: dummy value + /// + Invalid = 0, + + /// + /// iCUE-SDK: client not initialized or client closed connection (initial state) + /// + Closed = 1, + + /// + /// iCUE-SDK: client initiated connection but not connected yet + /// + Connecting = 2, + + /// + /// iCUE-SDK: server did not respond, sdk will try again + /// + Timeout = 3, + + /// + /// iCUE-SDK: server did not allow connection + /// + ConnectionRefused = 4, + + /// + /// iCUE-SDK: server closed connection + /// + ConnectionLost = 5, + + /// + /// iCUE-SDK: successfully connected + /// + Connected = 6 +}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDevice.cs b/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDevice.cs new file mode 100644 index 00000000..65200818 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDevice.cs @@ -0,0 +1,34 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using System.Collections.Generic; + +namespace RGB.NET.Devices.Corsair; + +/// +/// +/// Represents a corsair fan. +/// +public class CorsairFanRGBDevice : CorsairRGBDevice, IFan +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the fan. + /// The queue used to update this device. + internal CorsairFanRGBDevice(CorsairFanRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, updateQueue) + { } + + #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateFanMapping(ids); + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDeviceInfo.cs new file mode 100644 index 00000000..f4973c57 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDeviceInfo.cs @@ -0,0 +1,28 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using RGB.NET.Devices.Corsair.Native; + +namespace RGB.NET.Devices.Corsair; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairFanRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + internal CorsairFanRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.Fan, nativeInfo, ledCount, ledOffset) + { } + + /// + internal CorsairFanRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset, string modelName) + : base(RGBDeviceType.Fan, nativeInfo, ledCount, ledOffset, modelName) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs index 408e907b..1d42dc2e 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs @@ -13,7 +13,8 @@ public class CorsairDeviceUpdateQueue : UpdateQueue { #region Properties & Fields - private int _deviceIndex; + private readonly _CorsairDeviceInfo _device; + private readonly nint _colorPtr; #endregion @@ -24,10 +25,12 @@ public class CorsairDeviceUpdateQueue : UpdateQueue /// /// The update trigger used by this queue. /// The index used to identify the device. - public CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceIndex) + internal CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, _CorsairDeviceInfo device) : base(updateTrigger) { - this._deviceIndex = deviceIndex; + this._device = device; + + _colorPtr = Marshal.AllocHGlobal(Marshal.SizeOf<_CorsairLedColor>() * device.ledCount); } #endregion @@ -35,28 +38,29 @@ public CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceIn #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override unsafe void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - int structSize = Marshal.SizeOf(typeof(_CorsairLedColor)); - IntPtr ptr = Marshal.AllocHGlobal(structSize * dataSet.Length); - IntPtr addPtr = new(ptr.ToInt64()); - foreach ((object key, Color color) in dataSet) + Span<_CorsairLedColor> colors = new((void*)_colorPtr, dataSet.Length); + for (int i = 0; i < colors.Length; i++) { - _CorsairLedColor corsairColor = new() - { - ledId = (int)key, - r = color.GetR(), - g = color.GetG(), - b = color.GetB() - }; - - Marshal.StructureToPtr(corsairColor, addPtr, false); - addPtr = new IntPtr(addPtr.ToInt64() + structSize); + (object id, Color color) = dataSet[i]; + (byte a, byte r, byte g, byte b) = color.GetRGBBytes(); + colors[i] = new _CorsairLedColor((CorsairLedId)id, r, g, b, a); } - _CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Length, ptr); - _CUESDK.CorsairSetLedsColorsFlushBuffer(); - Marshal.FreeHGlobal(ptr); + CorsairError error = _CUESDK.CorsairSetLedColors(_device.id!, dataSet.Length, _colorPtr); + if (error != CorsairError.Success) + throw new RGBDeviceException($"Failed to update device '{_device.id}'. (ErrorCode: {error})"); + } + + /// + public override void Dispose() + { + base.Dispose(); + + Marshal.FreeHGlobal(_colorPtr); + + GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairLedId.cs b/RGB.NET.Devices.Corsair/Generic/CorsairLedId.cs new file mode 100644 index 00000000..e8c5c5bb --- /dev/null +++ b/RGB.NET.Devices.Corsair/Generic/CorsairLedId.cs @@ -0,0 +1,54 @@ +using System; +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.Corsair; + +[StructLayout(LayoutKind.Sequential)] +public readonly struct CorsairLedId : IComparable, IEquatable +{ + #region Properties & Fields + + public readonly uint Id; + + public CorsairLedGroup Group => (CorsairLedGroup)(Id >> 16); + public uint Index => Id & 0x0000FFFF; + + #endregion + + #region Constructors + + public CorsairLedId(uint id) + { + this.Id = id; + } + + public CorsairLedId(CorsairLedGroup group, CorsairLedIdKeyboard id) + : this(group, (int)id) + { } + + public CorsairLedId(CorsairLedGroup group, int index) + { + Id = (((uint)group) << 16) | (uint)index; + } + + #endregion + + #region Methods + + public int CompareTo(CorsairLedId other) => Id.CompareTo(other.Id); + + public bool Equals(CorsairLedId other) => Id == other.Id; + + public override bool Equals(object? obj) => obj is CorsairLedId other && Equals(other); + + public override int GetHashCode() => Id.GetHashCode(); + + public static bool operator ==(CorsairLedId left, CorsairLedId right) => left.Id == right.Id; + public static bool operator !=(CorsairLedId left, CorsairLedId right) => !(left == right); + public static bool operator <(CorsairLedId left, CorsairLedId right) => left.Id < right.Id; + public static bool operator <=(CorsairLedId left, CorsairLedId right) => left.Id <= right.Id; + public static bool operator >(CorsairLedId left, CorsairLedId right) => left.Id > right.Id; + public static bool operator >=(CorsairLedId left, CorsairLedId right) => left.Id >= right.Id; + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs b/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs deleted file mode 100644 index e764e082..00000000 --- a/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs +++ /dev/null @@ -1,65 +0,0 @@ -// ReSharper disable MemberCanBePrivate.Global -// ReSharper disable UnusedAutoPropertyAccessor.Global - -using System; -using System.Runtime.InteropServices; -using RGB.NET.Devices.Corsair.Native; - -namespace RGB.NET.Devices.Corsair; - -/// -/// Managed wrapper for CorsairProtocolDetails. -/// -public class CorsairProtocolDetails -{ - #region Properties & Fields - - /// - /// String containing version of SDK(like "1.0.0.1"). - /// Always contains valid value even if there was no CUE found. - /// - public string? SdkVersion { get; } - - /// - /// String containing version of CUE(like "1.0.0.1") or NULL if CUE was not found. - /// - public string? ServerVersion { get; } - - /// - /// Integer that specifies version of protocol that is implemented by current SDK. - /// Numbering starts from 1. - /// Always contains valid value even if there was no CUE found. - /// - public int SdkProtocolVersion { get; } - - /// - /// Integer that specifies version of protocol that is implemented by CUE. - /// Numbering starts from 1. - /// If CUE was not found then this value will be 0. - /// - public int ServerProtocolVersion { get; } - - /// - /// Boolean that specifies if there were breaking changes between version of protocol implemented by server and client. - /// - public bool BreakingChanges { get; } - - #endregion - - #region Constructors - - /// - /// Internal constructor of managed CorsairProtocolDetails. - /// - /// The native CorsairProtocolDetails-struct - internal CorsairProtocolDetails(_CorsairProtocolDetails nativeDetails) - { - this.SdkVersion = nativeDetails.sdkVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.sdkVersion); - this.ServerVersion = nativeDetails.serverVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.serverVersion); - this.SdkProtocolVersion = nativeDetails.sdkProtocolVersion; - this.ServerProtocolVersion = nativeDetails.serverProtocolVersion; - this.BreakingChanges = nativeDetails.breakingChanges != 0; - } - - #endregion -} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs index 57912a52..94fd49c1 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs @@ -1,5 +1,5 @@ -using System; -using System.Runtime.InteropServices; +using System.Collections.Generic; +using System.Linq; using RGB.NET.Core; using RGB.NET.Devices.Corsair.Native; @@ -17,7 +17,7 @@ public abstract class CorsairRGBDevice : AbstractRGBDevice /// Gets the mapping of to used to update the LEDs of this device. /// - protected LedMapping Mapping { get; } + protected LedMapping Mapping { get; private set; } = LedMapping.Empty; #endregion @@ -29,48 +29,41 @@ public abstract class CorsairRGBDevice : AbstractRGBDeviceThe generic information provided by CUE for the device. /// The mapping to used to update the LEDs of this device. /// The queue used to update this device. - protected CorsairRGBDevice(TDeviceInfo info, LedMapping mapping, CorsairDeviceUpdateQueue updateQueue) + protected CorsairRGBDevice(TDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) : base(info, updateQueue) - { - this.Mapping = mapping; - } + { } #endregion #region Methods void ICorsairRGBDevice.Initialize() => InitializeLayout(); - + /// /// Initializes the LEDs of the device based on the data provided by the SDK. /// protected virtual void InitializeLayout() { - _CorsairLedPositions? nativeLedPositions = (_CorsairLedPositions?)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex), typeof(_CorsairLedPositions)); - if (nativeLedPositions == null) return; + CorsairError error = _CUESDK.CorsairGetLedPositions(DeviceInfo.DeviceId, out _CorsairLedPosition[] ledPositions); + if (error != CorsairError.Success) + throw new RGBDeviceException($"Failed to load device '{DeviceInfo.DeviceId}'. (ErrorCode: {error})"); - int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); - IntPtr ptr = nativeLedPositions.pLedPosition; + List<_CorsairLedPosition> deviceLeds = ledPositions.Skip(DeviceInfo.LedOffset).Take(DeviceInfo.LedCount).ToList(); - for (int i = 0; i < nativeLedPositions.numberOfLed; i++) + Mapping = CreateMapping(deviceLeds.Select(x => new CorsairLedId(x.id))); + + foreach (_CorsairLedPosition ledPosition in deviceLeds) { - _CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition)); - if (ledPosition == null) - { - ptr = new IntPtr(ptr.ToInt64() + structSize); - continue; - } - - LedId ledId = Mapping.TryGetValue(ledPosition.LedId, out LedId id) ? id : LedId.Invalid; + LedId ledId = Mapping.TryGetValue(new CorsairLedId(ledPosition.id), out LedId id) ? id : LedId.Invalid; Rectangle rectangle = ledPosition.ToRectangle(); AddLed(ledId, rectangle.Location, rectangle.Size); - - ptr = new IntPtr(ptr.ToInt64() + structSize); } } + protected abstract LedMapping CreateMapping(IEnumerable ids); + /// - protected override object GetLedCustomData(LedId ledId) => Mapping.TryGetValue(ledId, out CorsairLedId corsairLedId) ? corsairLedId : CorsairLedId.Invalid; + protected override object GetLedCustomData(LedId ledId) => Mapping.TryGetValue(ledId, out CorsairLedId corsairLedId) ? corsairLedId : new CorsairLedId(0); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs index 27c882d4..6137b95a 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs @@ -1,6 +1,4 @@ -using System; -using System.Runtime.InteropServices; -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; using RGB.NET.Core; using RGB.NET.Devices.Corsair.Native; @@ -19,11 +17,6 @@ public class CorsairRGBDeviceInfo : IRGBDeviceInfo /// public CorsairDeviceType CorsairDeviceType { get; } - /// - /// Gets the index of the . - /// - public int CorsairDeviceIndex { get; } - /// public RGBDeviceType DeviceType { get; } @@ -44,11 +37,16 @@ public class CorsairRGBDeviceInfo : IRGBDeviceInfo /// public object? LayoutMetadata { get; set; } + + /// + /// Gets the amount of LEDs this device contains. + /// + public int LedCount { get; } /// - /// Gets a flag that describes device capabilities. () + /// Gets the offset used to access the LEDs of this device. /// - public CorsairDeviceCaps CapsMask { get; } + internal int LedOffset { get; } #endregion @@ -60,14 +58,14 @@ public class CorsairRGBDeviceInfo : IRGBDeviceInfo /// The index of the . /// The type of the . /// The native -struct - internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo) + internal CorsairRGBDeviceInfo(RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) { - this.CorsairDeviceIndex = deviceIndex; this.DeviceType = deviceType; this.CorsairDeviceType = nativeInfo.type; - this.Model = nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase); - this.DeviceId = nativeInfo.deviceId ?? string.Empty; - this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask; + this.Model = nativeInfo.model == null ? string.Empty : Regex.Replace(nativeInfo.model ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase); + this.DeviceId = nativeInfo.id ?? string.Empty; + this.LedCount = ledCount; + this.LedOffset = ledOffset; DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model); } @@ -79,14 +77,14 @@ internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _Corsai /// The type of the . /// The native -struct /// The name of the device-model (overwrites the one provided with the device info). - internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo, string modelName) + internal CorsairRGBDeviceInfo(RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset, string modelName) { - this.CorsairDeviceIndex = deviceIndex; this.DeviceType = deviceType; this.CorsairDeviceType = nativeInfo.type; this.Model = modelName; - this.DeviceId = nativeInfo.deviceId ?? string.Empty; - this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask; + this.DeviceId = nativeInfo.id ?? string.Empty; + this.LedCount = ledCount; + this.LedOffset = ledOffset; DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model); } diff --git a/RGB.NET.Devices.Corsair/Generic/LedMappings.cs b/RGB.NET.Devices.Corsair/Generic/LedMappings.cs index 911e58f7..81660705 100644 --- a/RGB.NET.Devices.Corsair/Generic/LedMappings.cs +++ b/RGB.NET.Devices.Corsair/Generic/LedMappings.cs @@ -1,302 +1,210 @@ -using RGB.NET.Core; +using System.Collections.Generic; +using System.Linq; +using RGB.NET.Core; namespace RGB.NET.Devices.Corsair; /// /// Contains mappings for to . /// -public static class LedMappings +internal static class LedMappings { - static LedMappings() - { - for (int i = 0; i <= (CorsairLedId.GPU50 - CorsairLedId.GPU1); i++) - GraphicsCard.Add(LedId.GraphicsCard1 + i, CorsairLedId.GPU1 + i); - - for (int i = 0; i <= (CorsairLedId.HeadsetStandZone9 - CorsairLedId.HeadsetStandZone1); i++) - HeadsetStand.Add(LedId.HeadsetStand1 + i, CorsairLedId.HeadsetStandZone1 + i); - - for (int i = 0; i <= (CorsairLedId.Mainboard100 - CorsairLedId.Mainboard1); i++) - Mainboard.Add(LedId.Mainboard1 + i, CorsairLedId.Mainboard1 + i); - - for (int i = 0; i <= (CorsairLedId.DRAM12 - CorsairLedId.DRAM1); i++) - Memory.Add(LedId.DRAM1 + i, CorsairLedId.DRAM1 + i); - - for (int i = 0; i <= (CorsairLedId.Zone15 - CorsairLedId.Zone1); i++) - Mousepad.Add(LedId.Mousepad1 + i, CorsairLedId.Zone1 + i); - - for (int i = 0; i <= (CorsairLedId.OemLed100 - CorsairLedId.OemLed1); i++) - Keyboard.Add(LedId.Custom1 + i, CorsairLedId.OemLed1 + i); - - for (int i = 0; i <= (CorsairLedId.OemLed250 - CorsairLedId.OemLed101); i++) - Keyboard.Add(LedId.Custom101 + i, CorsairLedId.OemLed101 + i); - } - - /// - /// Gets the mapping for graphics cards. - /// - public static LedMapping GraphicsCard { get; } = new(); + #region Constants - /// - /// Gets the mapping for headsets. - /// - public static LedMapping HeadsetStand { get; } = new(); + private static LedMapping KEYBOARD_MAPPING => new() + { + { LedId.Invalid, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Invalid) }, + { LedId.Keyboard_Escape, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Escape) }, + { LedId.Keyboard_F1, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F1) }, + { LedId.Keyboard_F2, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F2) }, + { LedId.Keyboard_F3, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F3) }, + { LedId.Keyboard_F4, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F4) }, + { LedId.Keyboard_F5, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F5) }, + { LedId.Keyboard_F6, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F6) }, + { LedId.Keyboard_F7, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F7) }, + { LedId.Keyboard_F8, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F8) }, + { LedId.Keyboard_F9, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F9) }, + { LedId.Keyboard_F10, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F10) }, + { LedId.Keyboard_F11, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F11) }, + { LedId.Keyboard_GraveAccentAndTilde, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.GraveAccentAndTilde) }, + { LedId.Keyboard_1, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.One) }, + { LedId.Keyboard_2, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Two) }, + { LedId.Keyboard_3, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Three) }, + { LedId.Keyboard_4, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Four) }, + { LedId.Keyboard_5, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Five) }, + { LedId.Keyboard_6, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Six) }, + { LedId.Keyboard_7, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Seven) }, + { LedId.Keyboard_8, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Eight) }, + { LedId.Keyboard_9, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Nine) }, + { LedId.Keyboard_0, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Zero) }, + { LedId.Keyboard_MinusAndUnderscore, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.MinusAndUnderscore) }, + { LedId.Keyboard_Tab, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Tab) }, + { LedId.Keyboard_Q, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Q) }, + { LedId.Keyboard_W, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.W) }, + { LedId.Keyboard_E, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.E) }, + { LedId.Keyboard_R, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.R) }, + { LedId.Keyboard_T, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.T) }, + { LedId.Keyboard_Y, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Y) }, + { LedId.Keyboard_U, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.U) }, + { LedId.Keyboard_I, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.I) }, + { LedId.Keyboard_O, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.O) }, + { LedId.Keyboard_P, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.P) }, + { LedId.Keyboard_BracketLeft, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.BracketLeft) }, + { LedId.Keyboard_CapsLock, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.CapsLock) }, + { LedId.Keyboard_A, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.A) }, + { LedId.Keyboard_S, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.S) }, + { LedId.Keyboard_D, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.D) }, + { LedId.Keyboard_F, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F) }, + { LedId.Keyboard_G, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.G) }, + { LedId.Keyboard_H, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.H) }, + { LedId.Keyboard_J, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.J) }, + { LedId.Keyboard_K, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.K) }, + { LedId.Keyboard_L, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.L) }, + { LedId.Keyboard_SemicolonAndColon, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.SemicolonAndColon) }, + { LedId.Keyboard_ApostropheAndDoubleQuote, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.ApostropheAndDoubleQuote) }, + { LedId.Keyboard_LeftShift, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.LeftShift) }, + { LedId.Keyboard_NonUsBackslash, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.NonUsBackslash) }, + { LedId.Keyboard_Z, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Z) }, + { LedId.Keyboard_X, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.X) }, + { LedId.Keyboard_C, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.C) }, + { LedId.Keyboard_V, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.V) }, + { LedId.Keyboard_B, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.B) }, + { LedId.Keyboard_N, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.N) }, + { LedId.Keyboard_M, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.M) }, + { LedId.Keyboard_CommaAndLessThan, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.CommaAndLessThan) }, + { LedId.Keyboard_PeriodAndBiggerThan, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.PeriodAndBiggerThan) }, + { LedId.Keyboard_SlashAndQuestionMark, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.SlashAndQuestionMark) }, + { LedId.Keyboard_LeftCtrl, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.LeftCtrl) }, + { LedId.Keyboard_LeftGui, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.LeftGui) }, + { LedId.Keyboard_LeftAlt, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.LeftAlt) }, + { LedId.Keyboard_Lang2, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Lang2) }, + { LedId.Keyboard_Space, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Space) }, + { LedId.Keyboard_Lang1, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Lang1) }, + { LedId.Keyboard_International2, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.International2) }, + { LedId.Keyboard_RightAlt, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.RightAlt) }, + { LedId.Keyboard_RightGui, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.RightGui) }, + { LedId.Keyboard_Application, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Application) }, + { LedId.Keyboard_Brightness, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Brightness) }, + { LedId.Keyboard_F12, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.F12) }, + { LedId.Keyboard_PrintScreen, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.PrintScreen) }, + { LedId.Keyboard_ScrollLock, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.ScrollLock) }, + { LedId.Keyboard_PauseBreak, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.PauseBreak) }, + { LedId.Keyboard_Insert, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Insert) }, + { LedId.Keyboard_Home, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Home) }, + { LedId.Keyboard_PageUp, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.PageUp) }, + { LedId.Keyboard_BracketRight, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.BracketRight) }, + { LedId.Keyboard_Backslash, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Backslash) }, + { LedId.Keyboard_NonUsTilde, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.NonUsTilde) }, + { LedId.Keyboard_Enter, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Enter) }, + { LedId.Keyboard_International1, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.International1) }, + { LedId.Keyboard_EqualsAndPlus, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.EqualsAndPlus) }, + { LedId.Keyboard_International3, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.International3) }, + { LedId.Keyboard_Backspace, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Backspace) }, + { LedId.Keyboard_Delete, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Delete) }, + { LedId.Keyboard_End, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.End) }, + { LedId.Keyboard_PageDown, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.PageDown) }, + { LedId.Keyboard_RightShift, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.RightShift) }, + { LedId.Keyboard_RightCtrl, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.RightCtrl) }, + { LedId.Keyboard_ArrowUp, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.UpArrow) }, + { LedId.Keyboard_ArrowLeft, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.LeftArrow) }, + { LedId.Keyboard_ArrowDown, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.DownArrow) }, + { LedId.Keyboard_ArrowRight, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.RightArrow) }, + { LedId.Keyboard_WinLock, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.WinLock) }, + { LedId.Keyboard_MediaMute, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Mute) }, + { LedId.Keyboard_MediaStop, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Stop) }, + { LedId.Keyboard_MediaPreviousTrack, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.ScanPreviousTrack) }, + { LedId.Keyboard_MediaPlay, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.PlayPause) }, + { LedId.Keyboard_MediaNextTrack, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.ScanNextTrack) }, + { LedId.Keyboard_NumLock, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.NumLock) }, + { LedId.Keyboard_NumSlash, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.KeypadSlash) }, + { LedId.Keyboard_NumAsterisk, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.KeypadAsterisk) }, + { LedId.Keyboard_NumMinus, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.KeypadMinus) }, + { LedId.Keyboard_NumPlus, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.KeypadPlus) }, + { LedId.Keyboard_NumEnter, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.KeypadEnter) }, + { LedId.Keyboard_Num7, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Keypad7) }, + { LedId.Keyboard_Num8, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Keypad8) }, + { LedId.Keyboard_Num9, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Keypad9) }, + { LedId.Keyboard_NumComma, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.KeypadComma) }, + { LedId.Keyboard_Num4, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Keypad4) }, + { LedId.Keyboard_Num5, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Keypad5) }, + { LedId.Keyboard_Num6, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Keypad6) }, + { LedId.Keyboard_Num1, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Keypad1) }, + { LedId.Keyboard_Num2, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Keypad2) }, + { LedId.Keyboard_Num3, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Keypad3) }, + { LedId.Keyboard_Num0, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Keypad0) }, + { LedId.Keyboard_NumPeriodAndDelete, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.KeypadPeriodAndDelete) }, + { LedId.Keyboard_MediaVolumeUp, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.VolumeUp) }, + { LedId.Keyboard_MediaVolumeDown, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.VolumeDown) }, + { LedId.Keyboard_MacroRecording, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.MR) }, + { LedId.Keyboard_Macro1, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.M1) }, + { LedId.Keyboard_Macro2, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.M2) }, + { LedId.Keyboard_Macro3, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.M3) }, + { LedId.Keyboard_International5, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.International5) }, + { LedId.Keyboard_International4, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.International4) }, + { LedId.Keyboard_LedProgramming, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.LedProgramming) }, + { LedId.Keyboard_Function, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Fn) } + }; - /// - /// Gets the mapping for mainboards. - /// - public static LedMapping Mainboard { get; } = new(); + #endregion - /// - /// Gets the mapping for memory. - /// - public static LedMapping Memory { get; } = new(); + #region Methods - /// - /// Gets the mapping for mousepads. - /// - public static LedMapping Mousepad { get; } = new(); + internal static LedMapping CreateFanMapping(IEnumerable ids) => CreateMapping(ids, LedId.Fan1); + internal static LedMapping CreateCoolerMapping(IEnumerable ids) => CreateMapping(ids, LedId.Cooler1); + internal static LedMapping CreateLedStripMapping(IEnumerable ids) => CreateMapping(ids, LedId.LedStripe1); + internal static LedMapping CreateGraphicsCardMapping(IEnumerable ids) => CreateMapping(ids, LedId.GraphicsCard1); + internal static LedMapping CreateHeadsetStandMapping(IEnumerable ids) => CreateMapping(ids, LedId.HeadsetStand1); + internal static LedMapping CreateMainboardMapping(IEnumerable ids) => CreateMapping(ids, LedId.Mainboard1); + internal static LedMapping CreateMemoryMapping(IEnumerable ids) => CreateMapping(ids, LedId.DRAM1); + internal static LedMapping CreateMousepadMapping(IEnumerable ids) => CreateMapping(ids, LedId.Mousepad1); + internal static LedMapping CreateHeadsetMapping(IEnumerable ids) => CreateMapping(ids, LedId.Headset1); + internal static LedMapping CreateMouseMapping(IEnumerable ids) => CreateMapping(ids, LedId.Mouse1); + internal static LedMapping CreateUnknownMapping(IEnumerable ids) => CreateMapping(ids, LedId.Unknown1); - /// - /// Gets the mapping for headsets. - /// - public static LedMapping Headset { get; } = new() + internal static LedMapping CreateMapping(IEnumerable ids, LedId referenceId) { - { LedId.Headset1, CorsairLedId.LeftLogo }, - { LedId.Headset2, CorsairLedId.RightLogo }, - }; + LedMapping mapping = new(); + int counter = 0; + foreach (CorsairLedId corsairLedId in ids.OrderBy(x => x)) + mapping.Add(referenceId + counter++, corsairLedId); - /// - /// Gets the mapping for mice. - /// - public static LedMapping Mouse { get; } = new() - { - { LedId.Mouse1, CorsairLedId.B1 }, - { LedId.Mouse2, CorsairLedId.B2 }, - { LedId.Mouse3, CorsairLedId.B3 }, - { LedId.Mouse4, CorsairLedId.B4 }, - { LedId.Mouse5, CorsairLedId.B5 }, - { LedId.Mouse6, CorsairLedId.B6 }, - { LedId.Mouse7, CorsairLedId.B7 }, - { LedId.Mouse8, CorsairLedId.B8 }, - { LedId.Mouse9, CorsairLedId.B9 }, - { LedId.Mouse10, CorsairLedId.B10 }, - { LedId.Mouse11, CorsairLedId.B11 }, - { LedId.Mouse12, CorsairLedId.B12 }, - { LedId.Mouse13, CorsairLedId.B13 }, - { LedId.Mouse14, CorsairLedId.B14 }, - { LedId.Mouse15, CorsairLedId.B15 }, - { LedId.Mouse16, CorsairLedId.B16 }, - { LedId.Mouse17, CorsairLedId.B17 }, - { LedId.Mouse18, CorsairLedId.B18 }, - { LedId.Mouse19, CorsairLedId.B19 }, - { LedId.Mouse20, CorsairLedId.B20 }, - }; + return mapping; + } - /// - /// Gets the mapping for keyboards. - /// - public static LedMapping Keyboard { get; } = new() + internal static LedMapping CreateKeyboardMapping(IEnumerable ids) { - { LedId.Invalid, CorsairLedId.Invalid }, - { LedId.Logo, CorsairLedId.Logo }, - { LedId.Keyboard_Escape, CorsairLedId.Escape }, - { LedId.Keyboard_F1, CorsairLedId.F1 }, - { LedId.Keyboard_F2, CorsairLedId.F2 }, - { LedId.Keyboard_F3, CorsairLedId.F3 }, - { LedId.Keyboard_F4, CorsairLedId.F4 }, - { LedId.Keyboard_F5, CorsairLedId.F5 }, - { LedId.Keyboard_F6, CorsairLedId.F6 }, - { LedId.Keyboard_F7, CorsairLedId.F7 }, - { LedId.Keyboard_F8, CorsairLedId.F8 }, - { LedId.Keyboard_F9, CorsairLedId.F9 }, - { LedId.Keyboard_F10, CorsairLedId.F10 }, - { LedId.Keyboard_F11, CorsairLedId.F11 }, - { LedId.Keyboard_GraveAccentAndTilde, CorsairLedId.GraveAccentAndTilde }, - { LedId.Keyboard_1, CorsairLedId.D1 }, - { LedId.Keyboard_2, CorsairLedId.D2 }, - { LedId.Keyboard_3, CorsairLedId.D3 }, - { LedId.Keyboard_4, CorsairLedId.D4 }, - { LedId.Keyboard_5, CorsairLedId.D5 }, - { LedId.Keyboard_6, CorsairLedId.D6 }, - { LedId.Keyboard_7, CorsairLedId.D7 }, - { LedId.Keyboard_8, CorsairLedId.D8 }, - { LedId.Keyboard_9, CorsairLedId.D9 }, - { LedId.Keyboard_0, CorsairLedId.D0 }, - { LedId.Keyboard_MinusAndUnderscore, CorsairLedId.MinusAndUnderscore }, - { LedId.Keyboard_Tab, CorsairLedId.Tab }, - { LedId.Keyboard_Q, CorsairLedId.Q }, - { LedId.Keyboard_W, CorsairLedId.W }, - { LedId.Keyboard_E, CorsairLedId.E }, - { LedId.Keyboard_R, CorsairLedId.R }, - { LedId.Keyboard_T, CorsairLedId.T }, - { LedId.Keyboard_Y, CorsairLedId.Y }, - { LedId.Keyboard_U, CorsairLedId.U }, - { LedId.Keyboard_I, CorsairLedId.I }, - { LedId.Keyboard_O, CorsairLedId.O }, - { LedId.Keyboard_P, CorsairLedId.P }, - { LedId.Keyboard_BracketLeft, CorsairLedId.BracketLeft }, - { LedId.Keyboard_CapsLock, CorsairLedId.CapsLock }, - { LedId.Keyboard_A, CorsairLedId.A }, - { LedId.Keyboard_S, CorsairLedId.S }, - { LedId.Keyboard_D, CorsairLedId.D }, - { LedId.Keyboard_F, CorsairLedId.F }, - { LedId.Keyboard_G, CorsairLedId.G }, - { LedId.Keyboard_H, CorsairLedId.H }, - { LedId.Keyboard_J, CorsairLedId.J }, - { LedId.Keyboard_K, CorsairLedId.K }, - { LedId.Keyboard_L, CorsairLedId.L }, - { LedId.Keyboard_SemicolonAndColon, CorsairLedId.SemicolonAndColon }, - { LedId.Keyboard_ApostropheAndDoubleQuote, CorsairLedId.ApostropheAndDoubleQuote }, - { LedId.Keyboard_LeftShift, CorsairLedId.LeftShift }, - { LedId.Keyboard_NonUsBackslash, CorsairLedId.NonUsBackslash }, - { LedId.Keyboard_Z, CorsairLedId.Z }, - { LedId.Keyboard_X, CorsairLedId.X }, - { LedId.Keyboard_C, CorsairLedId.C }, - { LedId.Keyboard_V, CorsairLedId.V }, - { LedId.Keyboard_B, CorsairLedId.B }, - { LedId.Keyboard_N, CorsairLedId.N }, - { LedId.Keyboard_M, CorsairLedId.M }, - { LedId.Keyboard_CommaAndLessThan, CorsairLedId.CommaAndLessThan }, - { LedId.Keyboard_PeriodAndBiggerThan, CorsairLedId.PeriodAndBiggerThan }, - { LedId.Keyboard_SlashAndQuestionMark, CorsairLedId.SlashAndQuestionMark }, - { LedId.Keyboard_LeftCtrl, CorsairLedId.LeftCtrl }, - { LedId.Keyboard_LeftGui, CorsairLedId.LeftGui }, - { LedId.Keyboard_LeftAlt, CorsairLedId.LeftAlt }, - { LedId.Keyboard_Lang2, CorsairLedId.Lang2 }, - { LedId.Keyboard_Space, CorsairLedId.Space }, - { LedId.Keyboard_Lang1, CorsairLedId.Lang1 }, - { LedId.Keyboard_International2, CorsairLedId.International2 }, - { LedId.Keyboard_RightAlt, CorsairLedId.RightAlt }, - { LedId.Keyboard_RightGui, CorsairLedId.RightGui }, - { LedId.Keyboard_Application, CorsairLedId.Application }, - { LedId.Keyboard_Brightness, CorsairLedId.Brightness }, - { LedId.Keyboard_F12, CorsairLedId.F12 }, - { LedId.Keyboard_PrintScreen, CorsairLedId.PrintScreen }, - { LedId.Keyboard_ScrollLock, CorsairLedId.ScrollLock }, - { LedId.Keyboard_PauseBreak, CorsairLedId.PauseBreak }, - { LedId.Keyboard_Insert, CorsairLedId.Insert }, - { LedId.Keyboard_Home, CorsairLedId.Home }, - { LedId.Keyboard_PageUp, CorsairLedId.PageUp }, - { LedId.Keyboard_BracketRight, CorsairLedId.BracketRight }, - { LedId.Keyboard_Backslash, CorsairLedId.Backslash }, - { LedId.Keyboard_NonUsTilde, CorsairLedId.NonUsTilde }, - { LedId.Keyboard_Enter, CorsairLedId.Enter }, - { LedId.Keyboard_International1, CorsairLedId.International1 }, - { LedId.Keyboard_EqualsAndPlus, CorsairLedId.EqualsAndPlus }, - { LedId.Keyboard_International3, CorsairLedId.International3 }, - { LedId.Keyboard_Backspace, CorsairLedId.Backspace }, - { LedId.Keyboard_Delete, CorsairLedId.Delete }, - { LedId.Keyboard_End, CorsairLedId.End }, - { LedId.Keyboard_PageDown, CorsairLedId.PageDown }, - { LedId.Keyboard_RightShift, CorsairLedId.RightShift }, - { LedId.Keyboard_RightCtrl, CorsairLedId.RightCtrl }, - { LedId.Keyboard_ArrowUp, CorsairLedId.UpArrow }, - { LedId.Keyboard_ArrowLeft, CorsairLedId.LeftArrow }, - { LedId.Keyboard_ArrowDown, CorsairLedId.DownArrow }, - { LedId.Keyboard_ArrowRight, CorsairLedId.RightArrow }, - { LedId.Keyboard_WinLock, CorsairLedId.WinLock }, - { LedId.Keyboard_MediaMute, CorsairLedId.Mute }, - { LedId.Keyboard_MediaStop, CorsairLedId.Stop }, - { LedId.Keyboard_MediaPreviousTrack, CorsairLedId.ScanPreviousTrack }, - { LedId.Keyboard_MediaPlay, CorsairLedId.PlayPause }, - { LedId.Keyboard_MediaNextTrack, CorsairLedId.ScanNextTrack }, - { LedId.Keyboard_NumLock, CorsairLedId.NumLock }, - { LedId.Keyboard_NumSlash, CorsairLedId.KeypadSlash }, - { LedId.Keyboard_NumAsterisk, CorsairLedId.KeypadAsterisk }, - { LedId.Keyboard_NumMinus, CorsairLedId.KeypadMinus }, - { LedId.Keyboard_NumPlus, CorsairLedId.KeypadPlus }, - { LedId.Keyboard_NumEnter, CorsairLedId.KeypadEnter }, - { LedId.Keyboard_Num7, CorsairLedId.Keypad7 }, - { LedId.Keyboard_Num8, CorsairLedId.Keypad8 }, - { LedId.Keyboard_Num9, CorsairLedId.Keypad9 }, - { LedId.Keyboard_NumComma, CorsairLedId.KeypadComma }, - { LedId.Keyboard_Num4, CorsairLedId.Keypad4 }, - { LedId.Keyboard_Num5, CorsairLedId.Keypad5 }, - { LedId.Keyboard_Num6, CorsairLedId.Keypad6 }, - { LedId.Keyboard_Num1, CorsairLedId.Keypad1 }, - { LedId.Keyboard_Num2, CorsairLedId.Keypad2 }, - { LedId.Keyboard_Num3, CorsairLedId.Keypad3 }, - { LedId.Keyboard_Num0, CorsairLedId.Keypad0 }, - { LedId.Keyboard_NumPeriodAndDelete, CorsairLedId.KeypadPeriodAndDelete }, - { LedId.Keyboard_Programmable1, CorsairLedId.G1 }, - { LedId.Keyboard_Programmable2, CorsairLedId.G2 }, - { LedId.Keyboard_Programmable3, CorsairLedId.G3 }, - { LedId.Keyboard_Programmable4, CorsairLedId.G4 }, - { LedId.Keyboard_Programmable5, CorsairLedId.G5 }, - { LedId.Keyboard_Programmable6, CorsairLedId.G6 }, - { LedId.Keyboard_Programmable7, CorsairLedId.G7 }, - { LedId.Keyboard_Programmable8, CorsairLedId.G8 }, - { LedId.Keyboard_Programmable9, CorsairLedId.G9 }, - { LedId.Keyboard_Programmable10, CorsairLedId.G10 }, - { LedId.Keyboard_MediaVolumeUp, CorsairLedId.VolumeUp }, - { LedId.Keyboard_MediaVolumeDown, CorsairLedId.VolumeDown }, - { LedId.Keyboard_MacroRecording, CorsairLedId.MR }, - { LedId.Keyboard_Macro1, CorsairLedId.M1 }, - { LedId.Keyboard_Macro2, CorsairLedId.M2 }, - { LedId.Keyboard_Macro3, CorsairLedId.M3 }, - { LedId.Keyboard_Programmable11, CorsairLedId.G11 }, - { LedId.Keyboard_Programmable12, CorsairLedId.G12 }, - { LedId.Keyboard_Programmable13, CorsairLedId.G13 }, - { LedId.Keyboard_Programmable14, CorsairLedId.G14 }, - { LedId.Keyboard_Programmable15, CorsairLedId.G15 }, - { LedId.Keyboard_Programmable16, CorsairLedId.G16 }, - { LedId.Keyboard_Programmable17, CorsairLedId.G17 }, - { LedId.Keyboard_Programmable18, CorsairLedId.G18 }, - { LedId.Keyboard_International5, CorsairLedId.International5 }, - { LedId.Keyboard_International4, CorsairLedId.International4 }, - { LedId.Keyboard_Profile, CorsairLedId.Profile }, - { LedId.Keyboard_LedProgramming, CorsairLedId.LedProgramming }, - { LedId.Keyboard_Function, CorsairLedId.Fn }, + Dictionary groupCounter = new() + { + [CorsairLedGroup.KeyboardOem] = 0, + [CorsairLedGroup.KeyboardGKeys] = 0, + [CorsairLedGroup.KeyboardEdge] = 0, + [CorsairLedGroup.Keyboard] = 0 // Workaround for unknown keys + }; + + LedMapping mapping = KEYBOARD_MAPPING; + + foreach (CorsairLedId corsairLedId in ids.OrderBy(x => x).Where(x => x.Group != CorsairLedGroup.Keyboard)) + switch (corsairLedId.Group) + { + case CorsairLedGroup.KeyboardOem: + mapping.Add(LedId.Keyboard_Custom1 + groupCounter[CorsairLedGroup.KeyboardOem]++, corsairLedId); + break; + + case CorsairLedGroup.KeyboardGKeys: + mapping.Add(LedId.Keyboard_Programmable1 + groupCounter[CorsairLedGroup.KeyboardGKeys]++, corsairLedId); + break; + + case CorsairLedGroup.KeyboardEdge: + mapping.Add(LedId.LedStripe1 + groupCounter[CorsairLedGroup.KeyboardEdge]++, corsairLedId); + break; + + default: + mapping.Add(LedId.Unknown1 + groupCounter[CorsairLedGroup.Keyboard]++, corsairLedId); + break; + } + + return mapping; + } - { LedId.LedStripe1, CorsairLedId.Lightbar1 }, - { LedId.LedStripe2, CorsairLedId.Lightbar2 }, - { LedId.LedStripe3, CorsairLedId.Lightbar3 }, - { LedId.LedStripe4, CorsairLedId.Lightbar4 }, - { LedId.LedStripe5, CorsairLedId.Lightbar5 }, - { LedId.LedStripe6, CorsairLedId.Lightbar6 }, - { LedId.LedStripe7, CorsairLedId.Lightbar7 }, - { LedId.LedStripe8, CorsairLedId.Lightbar8 }, - { LedId.LedStripe9, CorsairLedId.Lightbar9 }, - { LedId.LedStripe10, CorsairLedId.Lightbar10 }, - { LedId.LedStripe11, CorsairLedId.Lightbar11 }, - { LedId.LedStripe12, CorsairLedId.Lightbar12 }, - { LedId.LedStripe13, CorsairLedId.Lightbar13 }, - { LedId.LedStripe14, CorsairLedId.Lightbar14 }, - { LedId.LedStripe15, CorsairLedId.Lightbar15 }, - { LedId.LedStripe16, CorsairLedId.Lightbar16 }, - { LedId.LedStripe17, CorsairLedId.Lightbar17 }, - { LedId.LedStripe18, CorsairLedId.Lightbar18 }, - { LedId.LedStripe19, CorsairLedId.Lightbar19 }, - { LedId.LedStripe20, CorsairLedId.Lightbar20 }, - { LedId.LedStripe21, CorsairLedId.Lightbar21 }, - { LedId.LedStripe22, CorsairLedId.Lightbar22 }, - { LedId.LedStripe23, CorsairLedId.Lightbar23 }, - { LedId.LedStripe24, CorsairLedId.Lightbar24 }, - { LedId.LedStripe25, CorsairLedId.Lightbar25 }, - { LedId.LedStripe26, CorsairLedId.Lightbar26 }, - { LedId.LedStripe27, CorsairLedId.Lightbar27 }, - { LedId.LedStripe28, CorsairLedId.Lightbar28 }, - { LedId.LedStripe29, CorsairLedId.Lightbar29 }, - { LedId.LedStripe30, CorsairLedId.Lightbar30 }, - { LedId.LedStripe31, CorsairLedId.Lightbar31 }, - { LedId.LedStripe32, CorsairLedId.Lightbar32 }, - { LedId.LedStripe33, CorsairLedId.Lightbar33 }, - { LedId.LedStripe34, CorsairLedId.Lightbar34 }, - { LedId.LedStripe35, CorsairLedId.Lightbar35 }, - { LedId.LedStripe36, CorsairLedId.Lightbar36 }, - { LedId.LedStripe37, CorsairLedId.Lightbar37 }, - { LedId.LedStripe38, CorsairLedId.Lightbar38 }, - { LedId.LedStripe39, CorsairLedId.Lightbar39 }, - { LedId.LedStripe40, CorsairLedId.Lightbar40 }, - { LedId.LedStripe41, CorsairLedId.Lightbar41 }, - { LedId.LedStripe42, CorsairLedId.Lightbar42 }, - { LedId.LedStripe43, CorsairLedId.Lightbar43 }, - { LedId.LedStripe44, CorsairLedId.Lightbar44 }, - { LedId.LedStripe45, CorsairLedId.Lightbar45 }, - { LedId.LedStripe46, CorsairLedId.Lightbar46 }, - { LedId.LedStripe47, CorsairLedId.Lightbar47 }, - { LedId.LedStripe48, CorsairLedId.Lightbar48 }, - { LedId.LedStripe49, CorsairLedId.Lightbar49 }, - { LedId.LedStripe50, CorsairLedId.Lightbar50 }, - }; + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDevice.cs index b1238c1b..ce7fb8c0 100644 --- a/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDevice.cs @@ -1,6 +1,7 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global +using System.Collections.Generic; using RGB.NET.Core; namespace RGB.NET.Devices.Corsair; @@ -20,8 +21,14 @@ public class CorsairGraphicsCardRGBDevice : CorsairRGBDeviceThe specific information provided by CUE for the graphics card. /// The queue used to update this device. internal CorsairGraphicsCardRGBDevice(CorsairGraphicsCardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, LedMappings.GraphicsCard, updateQueue) + : base(info, updateQueue) { } #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateGraphicsCardMapping(ids); + + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs index d58120c1..ec5b4365 100644 --- a/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs @@ -15,13 +15,8 @@ public class CorsairGraphicsCardRGBDeviceInfo : CorsairRGBDeviceInfo #region Constructors /// - /// - /// Internal constructor of managed . - /// - /// The index of the . - /// The native -struct - internal CorsairGraphicsCardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) - : base(deviceIndex, RGBDeviceType.GraphicsCard, nativeInfo) + internal CorsairGraphicsCardRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.GraphicsCard, nativeInfo, ledCount, ledOffset) { } #endregion diff --git a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs index f52d5480..c2336d60 100644 --- a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedMember.Global using RGB.NET.Core; +using System.Collections.Generic; namespace RGB.NET.Devices.Corsair; @@ -20,8 +21,14 @@ public class CorsairHeadsetRGBDevice : CorsairRGBDeviceThe specific information provided by CUE for the headset /// The queue used to update this device. internal CorsairHeadsetRGBDevice(CorsairHeadsetRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, LedMappings.Headset, updateQueue) + : base(info, updateQueue) { } #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateHeadsetMapping(ids); + + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs index fb3e6962..5bac705d 100644 --- a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs @@ -12,13 +12,8 @@ public class CorsairHeadsetRGBDeviceInfo : CorsairRGBDeviceInfo #region Constructors /// - /// - /// Internal constructor of managed . - /// - /// The index of the . - /// The native -struct - internal CorsairHeadsetRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) - : base(deviceIndex, RGBDeviceType.Headset, nativeInfo) + internal CorsairHeadsetRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.Headset, nativeInfo, ledCount, ledOffset) { } #endregion diff --git a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs index def410df..7103b76a 100644 --- a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedMember.Global using RGB.NET.Core; +using System.Collections.Generic; namespace RGB.NET.Devices.Corsair; @@ -20,8 +21,14 @@ public class CorsairHeadsetStandRGBDevice : CorsairRGBDeviceThe specific information provided by CUE for the headset stand /// The queue used to update this device. internal CorsairHeadsetStandRGBDevice(CorsairHeadsetStandRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, LedMappings.HeadsetStand, updateQueue) + : base(info, updateQueue) { } #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateHeadsetStandMapping(ids); + + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs index b880a6c0..cc6b2742 100644 --- a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs @@ -12,13 +12,8 @@ public class CorsairHeadsetStandRGBDeviceInfo : CorsairRGBDeviceInfo #region Constructors /// - /// - /// Internal constructor of managed . - /// - /// The index of the . - /// The native -struct - internal CorsairHeadsetStandRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) - : base(deviceIndex, RGBDeviceType.HeadsetStand, nativeInfo) + internal CorsairHeadsetStandRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.HeadsetStand, nativeInfo, ledCount, ledOffset) { } #endregion diff --git a/RGB.NET.Devices.Corsair/Helper/NativeExtensions.cs b/RGB.NET.Devices.Corsair/Helper/NativeExtensions.cs index b78851b7..e60424e0 100644 --- a/RGB.NET.Devices.Corsair/Helper/NativeExtensions.cs +++ b/RGB.NET.Devices.Corsair/Helper/NativeExtensions.cs @@ -1,5 +1,6 @@ using RGB.NET.Core; using RGB.NET.Devices.Corsair.Native; +using System.Runtime.InteropServices; namespace RGB.NET.Devices.Corsair; @@ -7,12 +8,25 @@ internal static class NativeExtensions { internal static Rectangle ToRectangle(this _CorsairLedPosition position) { - //HACK DarthAffe 08.07.2018: It seems like corsair introduced a bug here - it's always 0. - float width = position.width < 0.5f ? 10 : (float)position.width; - float height = position.height < 0.5f ? 10 : (float)position.height; - float posX = (float)position.left; - float posY = (float)position.top; + const float WIDTH = 10; + const float HEIGHT = 10; + float posX = (float)position.cx; + float posY = (float)position.cy; - return new Rectangle(posX, posY, width, height); + return new Rectangle(posX, posY, WIDTH, HEIGHT); + } + + internal static T[] ToArray(this nint ptr, int size) + { + int tSize = Marshal.SizeOf(); + T[] array = new T[size]; + nint loopPtr = ptr; + for (int i = 0; i < size; i++) + { + array[i] = Marshal.PtrToStructure(loopPtr)!; + loopPtr += tSize; + } + + return array; } } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs index bdc9425b..d1fa9317 100644 --- a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedMember.Global using RGB.NET.Core; +using System.Collections.Generic; namespace RGB.NET.Devices.Corsair; @@ -26,8 +27,14 @@ public class CorsairKeyboardRGBDevice : CorsairRGBDeviceThe specific information provided by CUE for the keyboard. /// The queue used to update this device. internal CorsairKeyboardRGBDevice(CorsairKeyboardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, LedMappings.Keyboard, updateQueue) + : base(info, updateQueue) { } #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateKeyboardMapping(ids); + + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs index efa40a82..dcab0880 100644 --- a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs @@ -36,11 +36,12 @@ public class CorsairKeyboardRGBDeviceInfo : CorsairRGBDeviceInfo, IKeyboardDevic /// /// The index of the . /// The native -struct - internal CorsairKeyboardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) - : base(deviceIndex, RGBDeviceType.Keyboard, nativeInfo) + internal CorsairKeyboardRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.Keyboard, nativeInfo, ledCount, ledOffset) { - this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout; - this.LogicalLayout = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout; + PhysicalLayout = (CorsairPhysicalKeyboardLayout)_CUESDK.ReadDevicePropertySimpleInt32(nativeInfo.id!, CorsairDevicePropertyId.PhysicalLayout); + LogicalLayout = (CorsairLogicalKeyboardLayout)_CUESDK.ReadDevicePropertySimpleInt32(nativeInfo.id!, CorsairDevicePropertyId.LogicalLayout); + this.Layout = PhysicalLayout switch { CorsairPhysicalKeyboardLayout.US => KeyboardLayoutType.ANSI, diff --git a/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripGBDevice.cs b/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripGBDevice.cs new file mode 100644 index 00000000..53eb5b05 --- /dev/null +++ b/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripGBDevice.cs @@ -0,0 +1,34 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using System.Collections.Generic; + +namespace RGB.NET.Devices.Corsair; + +/// +/// +/// Represents a corsair ledStrip. +/// +public class CorsairLedStripRGBDevice : CorsairRGBDevice, ILedStripe +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the ledStrip. + /// The queue used to update this device. + internal CorsairLedStripRGBDevice(CorsairLedStripRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, updateQueue) + { } + + #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateLedStripMapping(ids); + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripRGBDeviceInfo.cs new file mode 100644 index 00000000..35006b87 --- /dev/null +++ b/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripRGBDeviceInfo.cs @@ -0,0 +1,28 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using RGB.NET.Devices.Corsair.Native; + +namespace RGB.NET.Devices.Corsair; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairLedStripRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + internal CorsairLedStripRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.LedStripe, nativeInfo, ledCount, ledOffset) + { } + + /// + internal CorsairLedStripRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset, string modelName) + : base(RGBDeviceType.LedStripe, nativeInfo, ledCount, ledOffset, modelName) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDevice.cs b/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDevice.cs index fc23e184..55ab92c2 100644 --- a/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDevice.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedMember.Global using RGB.NET.Core; +using System.Collections.Generic; namespace RGB.NET.Devices.Corsair; @@ -20,8 +21,14 @@ public class CorsairMainboardRGBDevice : CorsairRGBDeviceThe specific information provided by CUE for the memory. /// The queue used to update this device. internal CorsairMainboardRGBDevice(CorsairMainboardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, LedMappings.Mainboard, updateQueue) + : base(info, updateQueue) { } #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateMainboardMapping(ids); + + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDeviceInfo.cs index 94d836cc..4058d108 100644 --- a/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDeviceInfo.cs @@ -15,13 +15,8 @@ public class CorsairMainboardRGBDeviceInfo : CorsairRGBDeviceInfo #region Constructors /// - /// - /// Internal constructor of managed . - /// - /// The index of the . - /// The native -struct - internal CorsairMainboardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) - : base(deviceIndex, RGBDeviceType.Mainboard, nativeInfo) + internal CorsairMainboardRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.Mainboard, nativeInfo, ledCount, ledOffset) { } #endregion diff --git a/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs b/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs index f44d7eea..48b2eb37 100644 --- a/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedMember.Global using RGB.NET.Core; +using System.Collections.Generic; namespace RGB.NET.Devices.Corsair; @@ -20,8 +21,14 @@ public class CorsairMemoryRGBDevice : CorsairRGBDeviceThe specific information provided by CUE for the memory. /// The queue used to update this device. internal CorsairMemoryRGBDevice(CorsairMemoryRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, LedMappings.Memory, updateQueue) + : base(info, updateQueue) { } #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateMemoryMapping(ids); + + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDeviceInfo.cs index afd88433..8d779f78 100644 --- a/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDeviceInfo.cs @@ -15,13 +15,13 @@ public class CorsairMemoryRGBDeviceInfo : CorsairRGBDeviceInfo #region Constructors /// - /// - /// Internal constructor of managed . - /// - /// The index of the . - /// The native -struct - internal CorsairMemoryRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) - : base(deviceIndex, RGBDeviceType.DRAM, nativeInfo) + internal CorsairMemoryRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.DRAM, nativeInfo, ledCount, ledOffset) + { } + + /// + internal CorsairMemoryRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset, string modelName) + : base(RGBDeviceType.DRAM, nativeInfo, ledCount, ledOffset, modelName) { } #endregion diff --git a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs index 5c81249d..89f25c46 100644 --- a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedMember.Global using RGB.NET.Core; +using System.Collections.Generic; namespace RGB.NET.Devices.Corsair; @@ -20,8 +21,14 @@ public class CorsairMouseRGBDevice : CorsairRGBDevice /// The specific information provided by CUE for the mouse /// The queue used to update this device. internal CorsairMouseRGBDevice(CorsairMouseRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, LedMappings.Mouse, updateQueue) + : base(info, updateQueue) { } #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateMouseMapping(ids); + + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs index a5014669..422b18a2 100644 --- a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs @@ -9,28 +9,12 @@ namespace RGB.NET.Devices.Corsair; /// public class CorsairMouseRGBDeviceInfo : CorsairRGBDeviceInfo { - #region Properties & Fields - - /// - /// Gets the physical layout of the mouse. - /// - public CorsairPhysicalMouseLayout PhysicalLayout { get; } - - #endregion - #region Constructors /// - /// - /// Internal constructor of managed . - /// - /// The index of the . - /// The native -struct - internal CorsairMouseRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) - : base(deviceIndex, RGBDeviceType.Mouse, nativeInfo) - { - this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout; - } + internal CorsairMouseRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.Mouse, nativeInfo, ledCount, ledOffset) + { } #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs index 65c0f009..ac7a9b39 100644 --- a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedMember.Global using RGB.NET.Core; +using System.Collections.Generic; namespace RGB.NET.Devices.Corsair; @@ -20,8 +21,14 @@ public class CorsairMousepadRGBDevice : CorsairRGBDeviceThe specific information provided by CUE for the mousepad /// The queue used to update this device. internal CorsairMousepadRGBDevice(CorsairMousepadRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, LedMappings.Mousepad, updateQueue) + : base(info, updateQueue) { } #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateMousepadMapping(ids); + + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDeviceInfo.cs index 8c5d62c3..6b469c0a 100644 --- a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDeviceInfo.cs @@ -12,13 +12,8 @@ public class CorsairMousepadRGBDeviceInfo : CorsairRGBDeviceInfo #region Constructors /// - /// - /// Internal constructor of managed . - /// - /// The index if the . - /// The native -struct - internal CorsairMousepadRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) - : base(deviceIndex, RGBDeviceType.Mousepad, nativeInfo) + internal CorsairMousepadRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.Mousepad, nativeInfo, ledCount, ledOffset) { } #endregion diff --git a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs index 9455cb32..d3593ee9 100644 --- a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs +++ b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs @@ -11,12 +11,66 @@ namespace RGB.NET.Devices.Corsair.Native; +internal delegate void CorsairSessionStateChangedHandler(nint context, _CorsairSessionStateChanged eventData); + // ReSharper disable once InconsistentNaming -internal static class _CUESDK +internal static unsafe class _CUESDK { + #region Constants + + /// + /// iCUE-SDK: small string length + /// + internal const int CORSAIR_STRING_SIZE_S = 64; + + /// + /// iCUE-SDK: medium string length + /// + internal const int CORSAIR_STRING_SIZE_M = 128; + + /// + /// iCUE-SDK: maximum level of layer’s priority that can be used in CorsairSetLayerPriority + /// + internal const int CORSAIR_LAYER_PRIORITY_MAX = 255; + + /// + /// iCUE-SDK: maximum number of devices to be discovered + /// + internal const int CORSAIR_DEVICE_COUNT_MAX = 64; + + /// + /// iCUE-SDK: maximum number of LEDs controlled by device + /// + internal const int CORSAIR_DEVICE_LEDCOUNT_MAX = 512; + + #endregion + + #region Properties & Fields + + internal static bool IsConnected => SesionState == CorsairSessionState.Connected; + internal static CorsairSessionState SesionState { get; private set; } + + #endregion + + #region Events + + internal static event EventHandler? SessionStateChanged; + + #endregion + + #region Methods + + private static void CorsairSessionStateChangedCallback(nint context, _CorsairSessionStateChanged eventdata) + { + SesionState = eventdata.state; + SessionStateChanged?.Invoke(null, eventdata.state); + } + + #endregion + #region Libary Management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; /// /// Reloads the SDK. @@ -29,7 +83,7 @@ internal static void Reload() private static void LoadCUESDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; List possiblePathList = GetPossibleLibraryPaths().ToList(); @@ -37,24 +91,31 @@ private static void LoadCUESDK() if (dllPath == null) throw new RGBDeviceException($"Can't find the CUE-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'"); if (!NativeLibrary.TryLoad(dllPath, out _handle)) -#if NET6_0 +#if NET6_0_OR_GREATER throw new RGBDeviceException($"Corsair LoadLibrary failed with error code {Marshal.GetLastPInvokeError()}"); #else throw new RGBDeviceException($"Corsair LoadLibrary failed with error code {Marshal.GetLastWin32Error()}"); #endif - if (!NativeLibrary.TryGetExport(_handle, "CorsairSetLedsColorsBufferByDeviceIndex", out _corsairSetLedsColorsBufferByDeviceIndexPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairSetLedsColorsBufferByDeviceIndex'"); - if (!NativeLibrary.TryGetExport(_handle, "CorsairSetLedsColorsFlushBuffer", out _corsairSetLedsColorsFlushBufferPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairSetLedsColorsFlushBuffer'"); - if (!NativeLibrary.TryGetExport(_handle, "CorsairGetLedsColorsByDeviceIndex", out _corsairGetLedsColorsByDeviceIndexPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetLedsColorsByDeviceIndex'"); - if (!NativeLibrary.TryGetExport(_handle, "CorsairSetLayerPriority", out _corsairSetLayerPriorityPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairSetLayerPriority'"); - if (!NativeLibrary.TryGetExport(_handle, "CorsairGetDeviceCount", out _corsairGetDeviceCountPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetDeviceCount'"); - if (!NativeLibrary.TryGetExport(_handle, "CorsairGetDeviceInfo", out _corsairGetDeviceInfoPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetDeviceInfo'"); - if (!NativeLibrary.TryGetExport(_handle, "CorsairGetLedIdForKeyName", out _corsairGetLedIdForKeyNamePointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetLedIdForKeyName'"); - if (!NativeLibrary.TryGetExport(_handle, "CorsairGetLedPositionsByDeviceIndex", out _corsairGetLedPositionsByDeviceIndexPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetLedPositionsByDeviceIndex'"); - if (!NativeLibrary.TryGetExport(_handle, "CorsairRequestControl", out _corsairRequestControlPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairRequestControl'"); - if (!NativeLibrary.TryGetExport(_handle, "CorsairReleaseControl", out _corsairReleaseControlPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairReleaseControl'"); - if (!NativeLibrary.TryGetExport(_handle, "CorsairPerformProtocolHandshake", out _corsairPerformProtocolHandshakePointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairPerformProtocolHandshake'"); - if (!NativeLibrary.TryGetExport(_handle, "CorsairGetLastError", out _corsairGetLastErrorPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetLastError'"); + _corsairConnectPtr = (delegate* unmanaged[Cdecl])LoadFunction("CorsairConnect"); + _corsairGetSessionDetails = (delegate* unmanaged[Cdecl])LoadFunction("CorsairGetSessionDetails"); + _corsairDisconnect = (delegate* unmanaged[Cdecl])LoadFunction("CorsairDisconnect"); + _corsairGetDevices = (delegate* unmanaged[Cdecl]<_CorsairDeviceFilter, int, nint, out int, CorsairError>)LoadFunction("CorsairGetDevices"); + _corsairGetDeviceInfo = (delegate* unmanaged[Cdecl])LoadFunction("CorsairGetDeviceInfo"); + _corsairGetLedPositions = (delegate* unmanaged[Cdecl])LoadFunction("CorsairGetLedPositions"); + _corsairSetLedColors = (delegate* unmanaged[Cdecl])LoadFunction("CorsairSetLedColors"); + _corsairSetLayerPriority = (delegate* unmanaged[Cdecl])LoadFunction("CorsairSetLayerPriority"); + _corsairGetLedLuidForKeyName = (delegate* unmanaged[Cdecl])LoadFunction("CorsairGetLedLuidForKeyName"); + _corsairRequestControl = (delegate* unmanaged[Cdecl])LoadFunction("CorsairRequestControl"); + _corsairReleaseControl = (delegate* unmanaged[Cdecl])LoadFunction("CorsairReleaseControl"); + _getDevicePropertyInfo = (delegate* unmanaged[Cdecl])LoadFunction("CorsairGetDevicePropertyInfo"); + _readDeviceProperty = (delegate* unmanaged[Cdecl])LoadFunction("CorsairReadDeviceProperty"); + } + + private static nint LoadFunction(string function) + { + if (!NativeLibrary.TryGetExport(_handle, function, out nint ptr)) throw new RGBDeviceException($"Failed to load Corsair function '{function}'"); + return ptr; } private static IEnumerable GetPossibleLibraryPaths() @@ -71,23 +132,24 @@ private static IEnumerable GetPossibleLibraryPaths() internal static void UnloadCUESDK() { - if (_handle == IntPtr.Zero) return; - - _corsairSetLedsColorsBufferByDeviceIndexPointer = IntPtr.Zero; - _corsairSetLedsColorsFlushBufferPointer = IntPtr.Zero; - _corsairGetLedsColorsByDeviceIndexPointer = IntPtr.Zero; - _corsairSetLayerPriorityPointer = IntPtr.Zero; - _corsairGetDeviceCountPointer = IntPtr.Zero; - _corsairGetDeviceInfoPointer = IntPtr.Zero; - _corsairGetLedIdForKeyNamePointer = IntPtr.Zero; - _corsairGetLedPositionsByDeviceIndexPointer = IntPtr.Zero; - _corsairRequestControlPointer = IntPtr.Zero; - _corsairReleaseControlPointer = IntPtr.Zero; - _corsairPerformProtocolHandshakePointer = IntPtr.Zero; - _corsairGetLastErrorPointer = IntPtr.Zero; + if (_handle == 0) return; + + _corsairConnectPtr = null; + _corsairGetSessionDetails = null; + _corsairDisconnect = null; + _corsairGetDevices = null; + _corsairGetDeviceInfo = null; + _corsairGetLedPositions = null; + _corsairSetLedColors = null; + _corsairSetLayerPriority = null; + _corsairGetLedLuidForKeyName = null; + _corsairRequestControl = null; + _corsairReleaseControl = null; + _getDevicePropertyInfo = null; + _readDeviceProperty = null; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } #endregion @@ -96,97 +158,182 @@ internal static void UnloadCUESDK() #region Pointers - private static IntPtr _corsairSetLedsColorsBufferByDeviceIndexPointer; - private static IntPtr _corsairSetLedsColorsFlushBufferPointer; - private static IntPtr _corsairGetLedsColorsByDeviceIndexPointer; - private static IntPtr _corsairSetLayerPriorityPointer; - private static IntPtr _corsairGetDeviceCountPointer; - private static IntPtr _corsairGetDeviceInfoPointer; - private static IntPtr _corsairGetLedIdForKeyNamePointer; - private static IntPtr _corsairGetLedPositionsByDeviceIndexPointer; - private static IntPtr _corsairRequestControlPointer; - private static IntPtr _corsairReleaseControlPointer; - private static IntPtr _corsairPerformProtocolHandshakePointer; - private static IntPtr _corsairGetLastErrorPointer; + private static delegate* unmanaged[Cdecl] _corsairConnectPtr; + private static delegate* unmanaged[Cdecl] _corsairGetSessionDetails; + private static delegate* unmanaged[Cdecl] _corsairDisconnect; + private static delegate* unmanaged[Cdecl]<_CorsairDeviceFilter, int, nint, out int, CorsairError> _corsairGetDevices; + private static delegate* unmanaged[Cdecl] _corsairGetDeviceInfo; + private static delegate* unmanaged[Cdecl] _corsairGetLedPositions; + private static delegate* unmanaged[Cdecl] _corsairSetLedColors; + private static delegate* unmanaged[Cdecl] _corsairSetLayerPriority; + private static delegate* unmanaged[Cdecl] _corsairGetLedLuidForKeyName; + private static delegate* unmanaged[Cdecl] _corsairRequestControl; + private static delegate* unmanaged[Cdecl] _corsairReleaseControl; + private static delegate* unmanaged[Cdecl] _getDevicePropertyInfo; + private static delegate* unmanaged[Cdecl] _readDeviceProperty; #endregion - /// - /// CUE-SDK: set specified LEDs to some colors. - /// This function set LEDs colors in the buffer which is written to the devices via CorsairSetLedsColorsFlushBuffer or CorsairSetLedsColorsFlushBufferAsync. - /// Typical usecase is next: CorsairSetLedsColorsFlushBuffer or CorsairSetLedsColorsFlushBufferAsync is called to write LEDs colors to the device - /// and follows after one or more calls of CorsairSetLedsColorsBufferByDeviceIndex to set the LEDs buffer. - /// This function does not take logical layout into account. - /// - internal static unsafe bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairSetLedsColorsBufferByDeviceIndexPointer))(deviceIndex, size, ledsColors); + internal static CorsairError CorsairConnect() + { + if (_corsairConnectPtr == null) throw new RGBDeviceException("The Corsair-SDK is not initialized."); + if (IsConnected) throw new RGBDeviceException("The Corsair-SDK is already connected."); + return _corsairConnectPtr(CorsairSessionStateChangedCallback, 0); + } - /// - /// CUE-SDK: writes to the devices LEDs colors buffer which is previously filled by the CorsairSetLedsColorsBufferByDeviceIndex function. - /// This function executes synchronously, if you are concerned about delays consider using CorsairSetLedsColorsFlushBufferAsync - /// - internal static unsafe bool CorsairSetLedsColorsFlushBuffer() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairSetLedsColorsFlushBufferPointer))(); + internal static CorsairError CorsairGetSessionDetails(out _CorsairSessionDetails? details) + { + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + + nint sessionDetailPtr = Marshal.AllocHGlobal(Marshal.SizeOf<_CorsairSessionDetails>()); + try + { + CorsairError error = _corsairGetSessionDetails(sessionDetailPtr); + details = Marshal.PtrToStructure<_CorsairSessionDetails>(sessionDetailPtr); + + return error; + } + finally + { + Marshal.FreeHGlobal(sessionDetailPtr); + } + } - /// - /// CUE-SDK: get current color for the list of requested LEDs. - /// The color should represent the actual state of the hardware LED, which could be a combination of SDK and/or CUE input. - /// This function works for keyboard, mouse, mousemat, headset, headset stand and DIY-devices. - /// - internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedsColorsByDeviceIndexPointer))(deviceIndex, size, ledsColors); + internal static CorsairError CorsairDisconnect() + { + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + return _corsairDisconnect(); + } - /// - /// CUE-SDK: set layer priority for this shared client. - /// By default CUE has priority of 127 and all shared clients have priority of 128 if they don’t call this function. - /// Layers with higher priority value are shown on top of layers with lower priority. - /// - internal static unsafe bool CorsairSetLayerPriority(int priority) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairSetLayerPriorityPointer))(priority); + internal static CorsairError CorsairGetDevices(_CorsairDeviceFilter filter, out _CorsairDeviceInfo[] devices) + { + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + + int structSize = Marshal.SizeOf<_CorsairDeviceInfo>(); + nint devicePtr = Marshal.AllocHGlobal(structSize * CORSAIR_DEVICE_COUNT_MAX); + try + { + CorsairError error = _corsairGetDevices(filter, CORSAIR_DEVICE_COUNT_MAX, devicePtr, out int size); + devices = devicePtr.ToArray<_CorsairDeviceInfo>(size); + + return error; + } + finally + { + Marshal.FreeHGlobal(devicePtr); + } + } - /// - /// CUE-SDK: returns number of connected Corsair devices that support lighting control. - /// - internal static unsafe int CorsairGetDeviceCount() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetDeviceCountPointer))(); + internal static CorsairError CorsairGetDeviceInfo(string deviceId, _CorsairDeviceInfo deviceInfo) + { + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + return _corsairGetDeviceInfo(deviceId, deviceInfo); + } - /// - /// CUE-SDK: returns information about device at provided index. - /// - internal static unsafe IntPtr CorsairGetDeviceInfo(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetDeviceInfoPointer))(deviceIndex); + internal static CorsairError CorsairGetLedPositions(string deviceId, out _CorsairLedPosition[] ledPositions) + { + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + + int structSize = Marshal.SizeOf<_CorsairLedPosition>(); + nint ledPositionsPtr = Marshal.AllocHGlobal(structSize * CORSAIR_DEVICE_LEDCOUNT_MAX); + try + { + CorsairError error = _corsairGetLedPositions(deviceId, CORSAIR_DEVICE_LEDCOUNT_MAX, ledPositionsPtr, out int size); + ledPositions = ledPositionsPtr.ToArray<_CorsairLedPosition>(size); + + return error; + } + finally + { + Marshal.FreeHGlobal(ledPositionsPtr); + } + } - /// - /// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions. - /// - internal static unsafe IntPtr CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedPositionsByDeviceIndexPointer))(deviceIndex); + internal static CorsairError CorsairSetLedColors(string deviceId, int ledCount, nint ledColorsPtr) + { + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + return _corsairSetLedColors(deviceId, ledCount, ledColorsPtr); + } - /// - /// CUE-SDK: retrieves led id for key name taking logical layout into account. - /// - internal static unsafe CorsairLedId CorsairGetLedIdForKeyName(char keyName) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedIdForKeyNamePointer))(keyName); + internal static CorsairError CorsairSetLayerPriority(uint priority) + { + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + return _corsairSetLayerPriority(priority); + } - /// - /// CUE-SDK: requestes control using specified access mode. - /// By default client has shared control over lighting so there is no need to call CorsairRequestControl unless client requires exclusive control. - /// - internal static unsafe bool CorsairRequestControl(CorsairAccessMode accessMode) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairRequestControlPointer))(accessMode); + internal static CorsairError CorsairGetLedLuidForKeyName(string deviceId, char keyName, out uint ledId) + { + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + return _corsairGetLedLuidForKeyName(deviceId, keyName, out ledId); + } - /// - /// CUE-SDK: releases previously requested control for specified access mode. - /// - internal static unsafe bool CorsairReleaseControl(CorsairAccessMode accessMode) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairReleaseControlPointer))(accessMode); + internal static CorsairError CorsairRequestControl(string deviceId, CorsairAccessLevel accessLevel) + { + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + return _corsairRequestControl(deviceId, accessLevel); + } - /// - /// CUE-SDK: checks file and protocol version of CUE to understand which of SDK functions can be used with this version of CUE. - /// - internal static unsafe _CorsairProtocolDetails CorsairPerformProtocolHandshake() => ((delegate* unmanaged[Cdecl]<_CorsairProtocolDetails>)ThrowIfZero(_corsairPerformProtocolHandshakePointer))(); + internal static CorsairError CorsairReleaseControl(string deviceId) + { + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + return _corsairReleaseControl(deviceId); + } - /// - /// CUE-SDK: returns last error that occured while using any of Corsair* functions. - /// - internal static unsafe CorsairError CorsairGetLastError() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLastErrorPointer))(); + internal static CorsairError GetDevicePropertyInfo(string deviceId, CorsairDevicePropertyId propertyId, uint index, out CorsairDataType dataType, out CorsairPropertyFlag flags) + { + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + return _getDevicePropertyInfo(deviceId, propertyId, index, out dataType, out flags); + } - private static IntPtr ThrowIfZero(IntPtr ptr) + internal static CorsairError ReadDeviceProperty(string deviceId, CorsairDevicePropertyId propertyId, uint index, out _CorsairProperty? property) { - if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Corsair-SDK is not initialized."); - return ptr; + if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected."); + + nint propertyPtr = Marshal.AllocHGlobal(Marshal.SizeOf<_CorsairProperty>()); + try + { + CorsairError error = _readDeviceProperty(deviceId, propertyId, index, propertyPtr); + property = Marshal.PtrToStructure<_CorsairProperty>(propertyPtr); + + return error; + } + finally + { + Marshal.FreeHGlobal(propertyPtr); + } + } + + internal static int ReadDevicePropertySimpleInt32(string deviceId, CorsairDevicePropertyId propertyId, uint index = 0) => ReadDevicePropertySimple(deviceId, propertyId, CorsairDataType.Int32, index).int32; + + internal static int[] ReadDevicePropertySimpleInt32Array(string deviceId, CorsairDevicePropertyId propertyId, uint index = 0) + { + _CorsairDataValue dataValue = ReadDevicePropertySimple(deviceId, propertyId, CorsairDataType.Int32Array, index); + return dataValue.int32Array.items.ToArray((int)dataValue.int32Array.count); + } + + internal static _CorsairDataValue ReadDevicePropertySimple(string deviceId, CorsairDevicePropertyId propertyId, CorsairDataType expectedDataType, uint index = 0) + { + CorsairError errorCode = GetDevicePropertyInfo(deviceId, propertyId, index, out CorsairDataType dataType, out CorsairPropertyFlag flags); + if (errorCode != CorsairError.Success) + throw new RGBDeviceException($"Failed to read device-property-info '{propertyId}' for corsair device '{deviceId}'. (ErrorCode: {errorCode})"); + + if (dataType != expectedDataType) + throw new RGBDeviceException($"Failed to read device-property-info '{propertyId}' for corsair device '{deviceId}'. (Wrong data-type '{dataType}', expected: '{expectedDataType}')"); + + if (!flags.HasFlag(CorsairPropertyFlag.CanRead)) + throw new RGBDeviceException($"Failed to read device-property-info '{propertyId}' for corsair device '{deviceId}'. (Not readable)"); + + errorCode = ReadDeviceProperty(deviceId, propertyId, index, out _CorsairProperty? property); + if (errorCode != CorsairError.Success) + throw new RGBDeviceException($"Failed to read device-property '{propertyId}' for corsair device '{deviceId}'. (ErrorCode: {errorCode})"); + + if (property == null) + throw new RGBDeviceException($"Failed to read device-property '{propertyId}' for corsair device '{deviceId}'. (Invalid return value)"); + + if (property.Value.type != expectedDataType) + throw new RGBDeviceException($"Failed to read device-property '{propertyId}' for corsair device '{deviceId}'. (Wrong data-type '{dataType}', expected: '{expectedDataType}')"); + + return property.Value.value; } #endregion diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairChannelInfo.cs b/RGB.NET.Devices.Corsair/Native/_CorsairChannelInfo.cs deleted file mode 100644 index 3190b878..00000000 --- a/RGB.NET.Devices.Corsair/Native/_CorsairChannelInfo.cs +++ /dev/null @@ -1,33 +0,0 @@ -#pragma warning disable 169 // Field 'x' is never used -#pragma warning disable 414 // Field 'x' is assigned but its value never used -#pragma warning disable 649 // Field 'x' is never assigned -#pragma warning disable IDE1006 // Naming Styles - -using System; -using System.Runtime.InteropServices; - -namespace RGB.NET.Devices.Corsair.Native; - -// ReSharper disable once InconsistentNaming -/// -/// CUE-SDK: contains information about separate channel of the DIY-device. -/// -[StructLayout(LayoutKind.Sequential)] -internal class _CorsairChannelInfo -{ - /// - /// CUE-SDK: total number of LEDs connected to the channel; - /// - internal int totalLedsCount; - - /// - /// CUE-SDK: number of LED-devices (fans, strips, etc.) connected to the channel which is controlled by the DIY device - /// - internal int devicesCount; - - /// - /// CUE-SDK: array containing information about each separate LED-device connected to the channel controlled by the DIY device. - /// Index of the LED-device in array is same as the index of the LED-device connected to the DIY-device. - /// - internal IntPtr devices; -} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairDataValue.cs b/RGB.NET.Devices.Corsair/Native/_CorsairDataValue.cs new file mode 100644 index 00000000..bfb5e3d5 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Native/_CorsairDataValue.cs @@ -0,0 +1,140 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned +#pragma warning disable IDE1006 // Naming Styles + +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.Corsair.Native; + +// ReSharper disable once InconsistentNaming +/// +/// iCUE-SDK: a union of all property data types +/// +[StructLayout(LayoutKind.Explicit)] +internal struct _CorsairDataValue +{ + #region Properties & Fields + + /// + /// iCUE-SDK: actual property value if it’s type is CPDT_Boolean + /// + [FieldOffset(0)] + internal bool boolean; + + /// + /// iCUE-SDK: actual property value if it’s type is CPDT_Int32 + /// + [FieldOffset(0)] + internal int int32; + + /// + /// iCUE-SDK: actual property value if it’s type is CPDT_Float64 + /// + [FieldOffset(0)] + internal double float64; + + /// + /// iCUE-SDK: actual property value if it’s type is CPDT_String + /// + [FieldOffset(0)] + internal nint @string; + + /// + /// iCUE-SDK: actual property value if it’s type is CPDT_Boolean_Array + /// + [FieldOffset(0)] + internal CorsairDataTypeBooleanArray booleanArray; + + /// + /// iCUE-SDK: actual property value if it’s type is CPDT_Int32_Array + /// + [FieldOffset(0)] + internal CorsairDataTypeInt32Array int32Array; + + /// + /// iCUE-SDK: actual property value if it’s type is CPDT_Float64_Array + /// + [FieldOffset(0)] + internal CorsairDataTypeFloat64Array float64Array; + + /// + /// iCUE-SDK: actual property value if it’s type is CPDT_String_Array + /// + [FieldOffset(0)] + internal CorsairDataTypeStringArray stringArray; + + #endregion + + #region Data Types + + /// + /// iCUE: represents an array of boolean values + /// + [StructLayout(LayoutKind.Sequential)] + internal struct CorsairDataTypeBooleanArray + { + /// + /// iCUE: an array of boolean values + /// + internal nint items; + + /// + /// iCUE: number of items array elements + /// + internal uint count; + }; + + /// + /// iCUE: represents an array of integer values + /// + [StructLayout(LayoutKind.Sequential)] + internal struct CorsairDataTypeInt32Array + { + /// + /// iCUE: an array of integer values + /// + internal nint items; + + /// + /// iCUE: number of items array elements + /// + internal uint count; + }; + + /// + /// iCUE: represents an array of double values + /// + [StructLayout(LayoutKind.Sequential)] + internal struct CorsairDataTypeFloat64Array + { + /// + /// iCUE: an array of double values + /// + internal nint items; + + /// + /// iCUE: number of items array elements + /// + internal uint count; + }; + + /// + /// iCUE: represents an array of pointers to null terminated strings + /// + [StructLayout(LayoutKind.Sequential)] + internal struct CorsairDataTypeStringArray + { + /// + /// iCUE: an array of pointers to null terminated strings + /// + internal nint items; + + /// + /// iCUE: number of items array elements + /// + internal uint count; + }; + + #endregion +} diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairChannelsInfo.cs b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs similarity index 50% rename from RGB.NET.Devices.Corsair/Native/_CorsairChannelsInfo.cs rename to RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs index e2a5a12b..76f179da 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairChannelsInfo.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs @@ -3,26 +3,34 @@ #pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable IDE1006 // Naming Styles -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.Corsair.Native; // ReSharper disable once InconsistentNaming /// -/// CUE-SDK: contains information about channels of the DIY-devices. +/// iCUE-SDK: contains device search filter /// [StructLayout(LayoutKind.Sequential)] -internal class _CorsairChannelsInfo +internal class _CorsairDeviceFilter { - /// - /// CUE-SDK: number of channels controlled by the device - /// - internal int channelsCount; + #region Properties & Fields /// - /// CUE-SDK: array containing information about each separate channel of the DIY-device. - /// Index of the channel in the array is same as index of the channel on the DIY-device. + /// iCUE-SDK: mask that describes device types, formed as logical “or” of CorsairDeviceType enum values /// - internal IntPtr channels; -} \ No newline at end of file + internal CorsairDeviceType deviceTypeMask; + + #endregion + + #region Constructors + + public _CorsairDeviceFilter() { } + + public _CorsairDeviceFilter(CorsairDeviceType filter) + { + this.deviceTypeMask = filter; + } + + #endregion +} diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs index 799fc5ac..f1228791 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs @@ -3,56 +3,47 @@ #pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable IDE1006 // Naming Styles -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.Corsair.Native; // ReSharper disable once InconsistentNaming /// -/// CUE-SDK: contains information about device +/// iCUE-SDK: contains information about device /// [StructLayout(LayoutKind.Sequential)] internal class _CorsairDeviceInfo { /// - /// CUE-SDK: enum describing device type + /// iCUE-SDK: enum describing device type /// internal CorsairDeviceType type; /// - /// CUE-SDK: null - terminated device model(like “K95RGB”) + /// iCUE-SDK: null terminated Unicode string that contains unique device identifier serial number. Can be empty, if serial number is not available for the device /// - internal IntPtr model; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = _CUESDK.CORSAIR_STRING_SIZE_M)] + internal string? id; /// - /// CUE-SDK: enum describing physical layout of the keyboard or mouse + /// iCUE-SDK: null terminated Unicode string that contains device serial number. Can be empty, if serial number is not available for the device /// - internal int physicalLayout; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = _CUESDK.CORSAIR_STRING_SIZE_M)] + internal string? serial; /// - /// CUE-SDK: enum describing logical layout of the keyboard as set in CUE settings + /// iCUE-SDK: null terminated Unicode string that contains device model (like “K95RGB”) /// - internal int logicalLayout; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = _CUESDK.CORSAIR_STRING_SIZE_M)] + internal string? model; /// - /// CUE-SDK: mask that describes device capabilities, formed as logical “or” of CorsairDeviceCaps enum values + /// iCUE-SDK: number of controllable LEDs on the device /// - internal int capsMask; + internal int ledCount; /// - /// CUE-SDK: number of controllable LEDs on the device + /// iCUE-SDK: number of channels controlled by the device /// - internal int ledsCount; - - /// - /// CUE-SDK: structure that describes channels of the DIY-devices - /// - internal _CorsairChannelsInfo? channels; - - /// - /// CUE-SDK: null-terminated string that contains unique device identifier that uniquely identifies device at least within session - /// - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] - internal string? deviceId; + internal int channelCount; } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairLedColor.cs b/RGB.NET.Devices.Corsair/Native/_CorsairLedColor.cs index 004b36a7..60e64964 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairLedColor.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairLedColor.cs @@ -10,28 +10,52 @@ namespace RGB.NET.Devices.Corsair.Native; // ReSharper disable once InconsistentNaming /// -/// CUE-SDK: contains information about led and its color +/// iCUE-SDK: contains information about led and its color /// [StructLayout(LayoutKind.Sequential)] -internal class _CorsairLedColor +internal struct _CorsairLedColor { + #region Properties & Fields + /// - /// CUE-SDK: identifier of LED to set + /// iCUE-SDK: identifier of LED to set /// - internal int ledId; + internal CorsairLedId ledId; /// - /// CUE-SDK: red brightness[0..255] + /// iCUE-SDK: red brightness[0..255] /// - internal int r; + internal byte r; /// - /// CUE-SDK: green brightness[0..255] + /// iCUE-SDK: green brightness[0..255] /// - internal int g; + internal byte g; /// - /// CUE-SDK: blue brightness[0..255] + /// iCUE-SDK: blue brightness[0..255] /// - internal int b; + internal byte b; + + /// + /// iCUE-SDK: alpha channel [0..255]. The opacity of the color from 0 for completely translucent to 255 for opaque + /// + internal byte a; + + #endregion + + #region Constructors + + public _CorsairLedColor() { } + + public _CorsairLedColor(CorsairLedId ledId, byte r, byte g, byte b, byte a) + { + this.ledId = ledId; + this.r = r; + this.g = g; + this.b = b; + this.a = a; + } + + #endregion }; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairLedPosition.cs b/RGB.NET.Devices.Corsair/Native/_CorsairLedPosition.cs index 34f4108f..b2ff0fee 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairLedPosition.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairLedPosition.cs @@ -2,41 +2,31 @@ #pragma warning disable 414 // Field 'x' is assigned but its value never used #pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable IDE1006 // Naming Styles +// ReSharper disable NotAccessedField.Global using System.Runtime.InteropServices; namespace RGB.NET.Devices.Corsair.Native; -// ReSharper disable once InconsistentNaming +// ReSharper disable once InconsistentNaming /// -/// CUE-SDK: contains led id and position of led rectangle.Most of the keys are rectangular. -/// In case if key is not rectangular(like Enter in ISO / UK layout) it returns the smallest rectangle that fully contains the key +/// iCUE-SDK: contains led id and position of led /// [StructLayout(LayoutKind.Sequential)] internal class _CorsairLedPosition { /// - /// CUE-SDK: identifier of led + /// iCUE-SDK: unique identifier of led /// - internal CorsairLedId LedId; + internal uint id; /// - /// CUE-SDK: values in mm + /// iCUE-SDK: for keyboards, mice, mousemats, headset stands and memory modules values are /// - internal double top; + internal double cx; /// - /// CUE-SDK: values in mm + /// iCUE-SDK: in mm, for DIY-devices, headsets and coolers values are in logical units /// - internal double left; - - /// - /// CUE-SDK: values in mm - /// - internal double height; - - /// - /// CUE-SDK: values in mm - /// - internal double width; -} \ No newline at end of file + internal double cy; +}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairLedPositions.cs b/RGB.NET.Devices.Corsair/Native/_CorsairLedPositions.cs deleted file mode 100644 index c3186d35..00000000 --- a/RGB.NET.Devices.Corsair/Native/_CorsairLedPositions.cs +++ /dev/null @@ -1,26 +0,0 @@ -#pragma warning disable 169 // Field 'x' is never used -#pragma warning disable 414 // Field 'x' is assigned but its value never used -#pragma warning disable 649 // Field 'x' is never assigned - -using System; -using System.Runtime.InteropServices; - -namespace RGB.NET.Devices.Corsair.Native; - -// ReSharper disable once InconsistentNaming -/// -/// CUE-SDK: contains number of leds and arrays with their positions -/// -[StructLayout(LayoutKind.Sequential)] -internal class _CorsairLedPositions -{ - /// - /// CUE-SDK: integer value.Number of elements in following array - /// - internal int numberOfLed; - - /// - /// CUE-SDK: array of led positions - /// - internal IntPtr pLedPosition; -} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairChannelDeviceInfo.cs b/RGB.NET.Devices.Corsair/Native/_CorsairProperty.cs similarity index 60% rename from RGB.NET.Devices.Corsair/Native/_CorsairChannelDeviceInfo.cs rename to RGB.NET.Devices.Corsair/Native/_CorsairProperty.cs index 3f44c7ae..4a275b23 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairChannelDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairProperty.cs @@ -9,19 +9,22 @@ namespace RGB.NET.Devices.Corsair.Native; // ReSharper disable once InconsistentNaming /// -/// CUE-SDK: contains information about separate LED-device connected to the channel controlled by the DIY-device. +/// iCUE-SDK: contains information about device property type and value /// [StructLayout(LayoutKind.Sequential)] - -internal class _CorsairChannelDeviceInfo +internal struct _CorsairProperty { + #region Properties & Fields + /// - /// CUE-SDK: type of the LED-device + /// iCUE-SDK: type of property /// - internal CorsairChannelDeviceType type; + internal CorsairDataType type; /// - /// CUE-SDK: number of LEDs controlled by LED-device. + /// iCUE-SDK: property value /// - internal int deviceLedCount; -} \ No newline at end of file + internal _CorsairDataValue value; + + #endregion +} diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairProtocolDetails.cs b/RGB.NET.Devices.Corsair/Native/_CorsairProtocolDetails.cs deleted file mode 100644 index cd6bf6e4..00000000 --- a/RGB.NET.Devices.Corsair/Native/_CorsairProtocolDetails.cs +++ /dev/null @@ -1,43 +0,0 @@ -#pragma warning disable 169 // Field 'x' is never used -#pragma warning disable 414 // Field 'x' is assigned but its value never used -#pragma warning disable 649 // Field 'x' is never assigned - -using System; -using System.Runtime.InteropServices; - -namespace RGB.NET.Devices.Corsair.Native; - -// ReSharper disable once InconsistentNaming -/// -/// CUE-SDK: contains information about SDK and CUE versions -/// -[StructLayout(LayoutKind.Sequential)] -internal struct _CorsairProtocolDetails -{ - /// - /// CUE-SDK: null - terminated string containing version of SDK(like “1.0.0.1”). Always contains valid value even if there was no CUE found - /// - internal IntPtr sdkVersion; - - /// - /// CUE-SDK: null - terminated string containing version of CUE(like “1.0.0.1”) or NULL if CUE was not found. - /// - internal IntPtr serverVersion; - - /// - /// CUE-SDK: integer number that specifies version of protocol that is implemented by current SDK. - /// Numbering starts from 1. Always contains valid value even if there was no CUE found - /// - internal int sdkProtocolVersion; - - /// - /// CUE-SDK: integer number that specifies version of protocol that is implemented by CUE. - /// Numbering starts from 1. If CUE was not found then this value will be 0 - /// - internal int serverProtocolVersion; - - /// - /// CUE-SDK: boolean value that specifies if there were breaking changes between version of protocol implemented by server and client - /// - internal byte breakingChanges; -}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairSessionDetails.cs b/RGB.NET.Devices.Corsair/Native/_CorsairSessionDetails.cs new file mode 100644 index 00000000..392a30b7 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Native/_CorsairSessionDetails.cs @@ -0,0 +1,32 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned +#pragma warning disable IDE1006 // Naming Styles +// ReSharper disable NotAccessedField.Global + +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.Corsair.Native; + +// ReSharper disable once InconsistentNaming +/// +/// iCUE-SDK: contains information about SDK and iCUE versions +/// +[StructLayout(LayoutKind.Sequential)] +internal class _CorsairSessionDetails +{ + /// + /// iCUE-SDK: version of SDK client (like {4,0,1}). Always contains valid value even if there was no iCUE found. Must comply with the semantic versioning rules. + /// + internal _CorsairVersion clientVersion = new(); + + /// + /// iCUE-SDK: version of SDK server (like {4,0,1}) or empty struct ({0,0,0}) if the iCUE was not found. Must comply with the semantic versioning rules. + /// + internal _CorsairVersion serverVersion = new(); + + /// + /// iCUE-SDK: version of iCUE (like {3,33,100}) or empty struct ({0,0,0}) if the iCUE was not found. + /// + internal _CorsairVersion serverHostVersion = new(); +}; diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairSessionStateChanged.cs b/RGB.NET.Devices.Corsair/Native/_CorsairSessionStateChanged.cs new file mode 100644 index 00000000..99aa8fd5 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Native/_CorsairSessionStateChanged.cs @@ -0,0 +1,27 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned +#pragma warning disable IDE1006 // Naming Styles +// ReSharper disable NotAccessedField.Global + +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.Corsair.Native; + +// ReSharper disable once InconsistentNaming +/// +/// iCUE-SDK: contains information about session state and client/server versions +/// +[StructLayout(LayoutKind.Sequential)] +internal class _CorsairSessionStateChanged +{ + /// + /// iCUE-SDK: new session state which SDK client has been transitioned to + /// + internal CorsairSessionState state; + + /// + /// iCUE-SDK: information about client/server versions + /// + internal _CorsairSessionDetails details = new(); +}; diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairVersion.cs b/RGB.NET.Devices.Corsair/Native/_CorsairVersion.cs new file mode 100644 index 00000000..790226ec --- /dev/null +++ b/RGB.NET.Devices.Corsair/Native/_CorsairVersion.cs @@ -0,0 +1,31 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned +#pragma warning disable IDE1006 // Naming Styles +// ReSharper disable NotAccessedField.Global + +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.Corsair.Native; + +// ReSharper disable once InconsistentNaming +/// +/// iCUE-SDK: contains information about version that consists of three components +/// +[StructLayout(LayoutKind.Sequential)] +internal class _CorsairVersion +{ + #region Properties & Fields + + internal int major; + internal int minor; + internal int patch; + + #endregion + + #region Methods + + public override string ToString() => $"{major}.{minor}.{patch}"; + + #endregion +}; diff --git a/RGB.NET.Devices.Corsair/README.md b/RGB.NET.Devices.Corsair/README.md index dd30377f..c6c1803d 100644 --- a/RGB.NET.Devices.Corsair/README.md +++ b/RGB.NET.Devices.Corsair/README.md @@ -11,14 +11,16 @@ surface.Load(CorsairDeviceProvider.Instance); This providers requires native SDK-dlls. You can get them directly from Corsair at [https://github.com/CorsairOfficial/cue-sdk/releases](https://github.com/CorsairOfficial/cue-sdk/releases) +(Developed and tested with iCUE SDK v4.0.48) + Since the SDK-dlls are native it's important to use the correct architecture you're building your application for. (If in doubt you can always include both.) ### x64 -`redist\x64\CUESDK.x64_2019.dll` from the SDK-zip needs to be distributed as `\x64\CUESDK.x64_2019.dll` (or simply named `CUESDK.dll`) +`redist\x64\iCUESDK.x64_2019.dll` from the SDK-zip needs to be distributed as `\x64\iCUESDK.x64_2019.dll` (or simply named `iCUESDK.dll`) You can use other, custom paths by adding them to `CorsairDeviceProvider.PossibleX64NativePaths`. ### x86 -`redist\i386\CUESDK_2019.dll` from the SDK-zip needs to be distributed as `\x86\CUESDK_2019.dll` (or simply named `CUESDK.dll`) +`redist\i386\iCUESDK_2019.dll` from the SDK-zip needs to be distributed as `\x86\iCUESDK_2019.dll` (or simply named `iCUESDK.dll`) You can use other, custom paths by adding them to `CorsairDeviceProvider.PossibleX86NativePaths`. diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings index eeca9716..16defe6e 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings @@ -1,8 +1,12 @@  + True + True True True True True + True + True True True True @@ -19,4 +23,5 @@ True True True + True \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDevice.cs b/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDevice.cs index 092e84c0..d704343a 100644 --- a/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDevice.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedMember.Global using RGB.NET.Core; +using System.Collections.Generic; namespace RGB.NET.Devices.Corsair; @@ -9,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair touchbar. /// -public class CorsairTouchbarRGBDevice : CorsairRGBDevice, IDRAM +public class CorsairTouchbarRGBDevice : CorsairRGBDevice, ILedStripe { #region Constructors @@ -20,8 +21,14 @@ public class CorsairTouchbarRGBDevice : CorsairRGBDeviceThe specific information provided by CUE for the touchbar. /// The queue used to update this device. internal CorsairTouchbarRGBDevice(CorsairTouchbarRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, LedMappings.Keyboard, updateQueue) //TODO DarthAffe 17.07.2022: Find someone with such a device and check which LedIds are actually used + : base(info, updateQueue) { } #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateLedStripMapping(ids); + + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDeviceInfo.cs index 9ee690c1..68ea4f0c 100644 --- a/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDeviceInfo.cs @@ -15,13 +15,8 @@ public class CorsairTouchbarRGBDeviceInfo : CorsairRGBDeviceInfo #region Constructors /// - /// - /// Internal constructor of managed . - /// - /// The index of the . - /// The native -struct - internal CorsairTouchbarRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) - : base(deviceIndex, RGBDeviceType.Keypad, nativeInfo) + internal CorsairTouchbarRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.LedStripe, nativeInfo, ledCount, ledOffset) { } #endregion diff --git a/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDevice.cs b/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDevice.cs new file mode 100644 index 00000000..d8603365 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDevice.cs @@ -0,0 +1,34 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using System.Collections.Generic; + +namespace RGB.NET.Devices.Corsair; + +/// +/// +/// Represents a unknown corsair device. +/// +public class CorsairUnknownRGBDevice : CorsairRGBDevice, IUnknownDevice +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the unknown device. + /// The queue used to update this device. + internal CorsairUnknownRGBDevice(CorsairUnknownRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, updateQueue) + { } + + #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateUnknownMapping(ids); + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDeviceInfo.cs new file mode 100644 index 00000000..e9b6da56 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDeviceInfo.cs @@ -0,0 +1,23 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using RGB.NET.Devices.Corsair.Native; + +namespace RGB.NET.Devices.Corsair; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairUnknownRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + internal CorsairUnknownRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.Unknown, nativeInfo, ledCount, ledOffset) + { } + + #endregion +} \ No newline at end of file From d6aed5c5a20f31bc327d9ba306ecee54dc02b874 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Fri, 10 Feb 2023 19:23:48 +0100 Subject: [PATCH 06/96] Fixed some code issues (dispose finalizers) --- RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs | 6 +----- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 3 +++ RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs | 8 +++++++- .../CoolerMasterDeviceProvider.cs | 2 ++ .../Generic/CoolerMasterRGBDevice.cs | 2 ++ RGB.NET.Devices.Debug/DebugDeviceProvider.cs | 2 ++ RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 2 ++ RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj | 1 + RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs | 2 ++ RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs | 4 +++- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 2 ++ .../SteelSeriesDeviceProvider.cs | 2 ++ RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs | 10 ++++++++-- .../NodeMCU/NodeMCUWS2812USBUpdateQueue.cs | 2 ++ RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs | 2 ++ .../Keyboard/WootingKeyboardRGBDevice.cs | 5 ++++- RGB.NET.Devices.Wooting/WootingDeviceProvider.cs | 2 ++ 17 files changed, 47 insertions(+), 10 deletions(-) diff --git a/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs b/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs index baa3515c..c1859c2f 100644 --- a/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs +++ b/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs @@ -22,11 +22,7 @@ public sealed class DefaultColorBehavior : IColorBehavior /// The color to test. /// The object to test. /// true if is a equivalent to this ; otherwise, false. - public bool Equals(in Color color, object? obj) - { - if (obj is not Color color2) return false; - return Equals(color, color2); - } + public bool Equals(in Color color, object? obj) => obj is Color color2 && Equals(color, color2); /// /// Tests whether the specified object is a and is equivalent to this . diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index 1457e0a0..ca6a5b27 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedMember.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -160,6 +161,8 @@ public virtual void Dispose() try { LedMapping.Clear(); } catch { /* this really shouldn't happen */ } IdGenerator.ResetCounter(GetType().Assembly); + + GC.SuppressFinalize(this); } /// diff --git a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs index 5d357b6a..db22aa4f 100644 --- a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs +++ b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs @@ -1,5 +1,6 @@ // ReSharper disable MemberCanBePrivate.Global +using System; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; @@ -178,7 +179,12 @@ private void UpdateUpdateFrequency() } /// - public override void Dispose() => Stop(); + public override void Dispose() + { + Stop(); + + GC.SuppressFinalize(this); + } #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index 280e5204..e51ed8a2 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -100,6 +100,8 @@ public override void Dispose() try { _CoolerMasterSDK.Reload(); } catch { /* Unlucky.. */ } + + GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs index b44a90c8..f5d2fad2 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs @@ -33,6 +33,8 @@ public override void Dispose() _CoolerMasterSDK.EnableLedControl(false, DeviceInfo.DeviceIndex); base.Dispose(); + + GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs index 6ec81424..d396bc06 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs @@ -71,6 +71,8 @@ public override void Dispose() base.Dispose(); _fakeDeviceDefinitions.Clear(); + + GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index 3d1591ae..fb188272 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -104,6 +104,8 @@ public override void Dispose() try { _MsiSDK.UnloadMsiSDK(); } catch { /* at least we tried */ } + + GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj index c565c945..5e3c5358 100644 --- a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj +++ b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj @@ -53,6 +53,7 @@ + diff --git a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs index 5480370f..b64c72a6 100644 --- a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs +++ b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs @@ -49,6 +49,8 @@ public override void Dispose() Reset(); base.Dispose(); + + GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs index b912cded..0f2b44b9 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs @@ -35,7 +35,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider public bool ForceAddAllDevices { get; set; } = false; /// - /// Defines which device types will be separated by zones. Defaults to | . + /// Defines which device types will be separated by zones. Defaults to | | . /// public RGBDeviceType PerZoneDeviceFlag { get; } = RGBDeviceType.LedStripe | RGBDeviceType.Mainboard | RGBDeviceType.Speaker; @@ -141,6 +141,8 @@ public override void Dispose() _clients.Clear(); DeviceDefinitions.Clear(); Devices = Enumerable.Empty(); + + GC.SuppressFinalize(this); } #endregion } diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 09f1a278..77c5bd2b 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -301,6 +301,8 @@ public override void Dispose() // DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit //try { _RazerSDK.UnloadRazerSDK(); } //catch { /* at least we tried */ } + + GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs index 7144da60..ee155334 100644 --- a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs +++ b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs @@ -137,6 +137,8 @@ public override void Dispose() try { SteelSeriesSDK.Dispose(); } catch { /* shit happens */ } + + GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs b/RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs index 7d4ea4db..f581e3f3 100644 --- a/RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs +++ b/RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs @@ -1,4 +1,5 @@ -using System.IO.Ports; +using System; +using System.IO.Ports; namespace RGB.NET.Devices.WS281X; @@ -61,7 +62,12 @@ public SerialPortConnection(string port, int baudRate) public void WriteLine(string line) => SerialPort.WriteLine(line); /// - public void Dispose() => SerialPort.Dispose(); + public void Dispose() + { + SerialPort.Dispose(); + + GC.SuppressFinalize(this); + } #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs index 0e7a9b72..a3619e2f 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs @@ -171,6 +171,8 @@ public override void Dispose() ResetDevice(); _httpClient.Dispose(); } + + GC.SuppressFinalize(this); } private string GetUrl(string path) => $"http://{_hostname}/{path}"; diff --git a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs index e2adc455..6a5c49d8 100644 --- a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs +++ b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs @@ -75,6 +75,8 @@ public override void Dispose() base.Dispose(); DeviceDefinitions.Clear(); + + GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs index 502927ad..eb0cc753 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using RGB.NET.Core; using RGB.NET.Devices.Wooting.Generic; using RGB.NET.Devices.Wooting.Native; @@ -55,6 +56,8 @@ public override void Dispose() _WootingSDK.Reset(); base.Dispose(); + + GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 5ddf6cca..57d99c1d 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -102,6 +102,8 @@ public override void Dispose() try { _WootingSDK.UnloadWootingSDK(); } catch { /* at least we tried */ } } + + GC.SuppressFinalize(this); } #endregion From 2ff7a65519cac1f0490916b3de6492780e98dc92 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Fri, 10 Feb 2023 19:25:18 +0100 Subject: [PATCH 07/96] Removed editorconfig --- RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj index 5e3c5358..c565c945 100644 --- a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj +++ b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj @@ -53,7 +53,6 @@ - From 8431a8cb5e24243ed58223538fa959b64b4efcf8 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 11 Feb 2023 22:36:59 +0100 Subject: [PATCH 08/96] (MAJOR) Optimized surface-updating to reduce the amount of allocations --- RGB.NET.Core/Events/UpdatingEventArgs.cs | 4 +- RGB.NET.Core/Groups/AbstractLedGroup.cs | 4 ++ RGB.NET.Core/Groups/ILedGroup.cs | 6 +++ RGB.NET.Core/Groups/ListLedGroup.cs | 9 +++- RGB.NET.Core/Positioning/Rectangle.cs | 33 ++++++++++-- RGB.NET.Core/RGBSurface.cs | 28 ++++++---- RGB.NET.Core/Update/CustomUpdateData.cs | 60 +++++++++++++++++++-- RGB.NET.Presets/Groups/RectangleLedGroup.cs | 9 +++- 8 files changed, 129 insertions(+), 24 deletions(-) diff --git a/RGB.NET.Core/Events/UpdatingEventArgs.cs b/RGB.NET.Core/Events/UpdatingEventArgs.cs index 47df4af4..d39ea74e 100644 --- a/RGB.NET.Core/Events/UpdatingEventArgs.cs +++ b/RGB.NET.Core/Events/UpdatingEventArgs.cs @@ -26,7 +26,7 @@ public class UpdatingEventArgs : EventArgs /// /// Gets the custom-data provided by the trigger for this update. /// - public CustomUpdateData CustomData { get; } + public ICustomUpdateData CustomData { get; } #endregion @@ -39,7 +39,7 @@ public class UpdatingEventArgs : EventArgs /// The elapsed time (in seconds) since the last update. /// The trigger causing this update. /// The custom-data provided by the trigger for this update. - public UpdatingEventArgs(double deltaTime, IUpdateTrigger? trigger, CustomUpdateData customData) + public UpdatingEventArgs(double deltaTime, IUpdateTrigger? trigger, ICustomUpdateData customData) { this.DeltaTime = deltaTime; this.Trigger = trigger; diff --git a/RGB.NET.Core/Groups/AbstractLedGroup.cs b/RGB.NET.Core/Groups/AbstractLedGroup.cs index 6569dac9..86659afe 100644 --- a/RGB.NET.Core/Groups/AbstractLedGroup.cs +++ b/RGB.NET.Core/Groups/AbstractLedGroup.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.Linq; namespace RGB.NET.Core; @@ -51,6 +52,9 @@ public virtual void OnAttach() { } /// public virtual void OnDetach() { } + /// + public virtual IList ToList() => GetLeds().ToList(); + /// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/RGB.NET.Core/Groups/ILedGroup.cs b/RGB.NET.Core/Groups/ILedGroup.cs index 88b5b976..97ed8b2a 100644 --- a/RGB.NET.Core/Groups/ILedGroup.cs +++ b/RGB.NET.Core/Groups/ILedGroup.cs @@ -39,4 +39,10 @@ public interface ILedGroup : IDecoratable, IEnumerable /// Called when the is detached from the . /// void OnDetach(); + + /// + /// Returns a list containing all in this group. + /// + /// A list containing all in this group. + IList ToList(); } \ No newline at end of file diff --git a/RGB.NET.Core/Groups/ListLedGroup.cs b/RGB.NET.Core/Groups/ListLedGroup.cs index a33fc56e..9c519061 100644 --- a/RGB.NET.Core/Groups/ListLedGroup.cs +++ b/RGB.NET.Core/Groups/ListLedGroup.cs @@ -122,7 +122,14 @@ public void MergeLeds(ILedGroup groupToMerge) /// Gets a list containing the from this group. /// /// The list containing the . - protected override IEnumerable GetLeds() + protected override IEnumerable GetLeds() => ToList(); + + /// + /// + /// Gets a list containing the from this group. + /// + /// The list containing the . + public override IList ToList() { lock (GroupLeds) return new List(GroupLeds); diff --git a/RGB.NET.Core/Positioning/Rectangle.cs b/RGB.NET.Core/Positioning/Rectangle.cs index 456a5684..095a210e 100644 --- a/RGB.NET.Core/Positioning/Rectangle.cs +++ b/RGB.NET.Core/Positioning/Rectangle.cs @@ -57,7 +57,8 @@ public Rectangle(float x, float y, float width, float height) /// Initializes a new instance of the class using the (0,0) and the specified . /// /// The size of of this . - public Rectangle(Size size) : this(new Point(), size) + public Rectangle(Size size) + : this(new Point(), size) { } /// @@ -120,15 +121,13 @@ public Rectangle(IEnumerable rectangles) public Rectangle(params Point[] points) : this(points.AsEnumerable()) { } - - /// + /// /// Initializes a new instance of the class using the specified list of . /// The and is calculated to contain all points provided as parameters. /// /// The list of used to calculate the and . public Rectangle(IEnumerable points) - : this() { bool hasPoint = false; float posX = float.MaxValue; @@ -145,8 +144,32 @@ public Rectangle(IEnumerable points) posY2 = Math.Max(posY2, point.Y); } - (Point location, Size size) = hasPoint ? InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2)) : InitializeFromPoints(new Point(0, 0), new Point(0, 0)); + (Point location, Size size) = hasPoint ? InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2)) + : InitializeFromPoints(new Point(0, 0), new Point(0, 0)); + + Location = location; + Size = size; + Center = new Point(Location.X + (Size.Width / 2.0f), Location.Y + (Size.Height / 2.0f)); + } + + internal Rectangle(IList leds) + { + float posX = float.MaxValue; + float posY = float.MaxValue; + float posX2 = float.MinValue; + float posY2 = float.MinValue; + + // ReSharper disable once ForCanBeConvertedToForeach + for (int i = 0; i < leds.Count; i++) + { + Rectangle rectangle = leds[i].AbsoluteBoundary; + posX = Math.Min(posX, rectangle.Location.X); + posY = Math.Min(posY, rectangle.Location.Y); + posX2 = Math.Max(posX2, rectangle.Location.X + rectangle.Size.Width); + posY2 = Math.Max(posY2, rectangle.Location.Y + rectangle.Size.Height); + } + (Point location, Size size) = leds.Count > 0 ? InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2)) : InitializeFromPoints(new Point(0, 0), new Point(0, 0)); Location = location; Size = size; Center = new Point(Location.X + (Size.Width / 2.0f), Location.Y + (Size.Height / 2.0f)); diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index f8ec4378..fc8003f3 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -132,11 +132,12 @@ public RGBSurface() /// Perform a full update for all devices. Updates only dirty by default, or all , if flushLeds is set to true. /// /// Specifies whether all , (including clean ones) should be updated. - public void Update(bool flushLeds = false) => Update(null, new CustomUpdateData((CustomUpdateDataIndex.FLUSH_LEDS, flushLeds))); + //public void Update(bool flushLeds = false) => Update(null, new CustomUpdateData((CustomUpdateDataIndex.FLUSH_LEDS, flushLeds))); + public void Update(bool flushLeds = false) => Update(null, flushLeds ? DefaultCustomUpdateData.FLUSH : DefaultCustomUpdateData.NO_FLUSH); - private void Update(object? updateTrigger, CustomUpdateData customData) => Update(updateTrigger as IUpdateTrigger, customData); + private void Update(object? updateTrigger, ICustomUpdateData customData) => Update(updateTrigger as IUpdateTrigger, customData); - private void Update(IUpdateTrigger? updateTrigger, CustomUpdateData customData) + private void Update(IUpdateTrigger? updateTrigger, ICustomUpdateData customData) { try { @@ -149,19 +150,25 @@ private void Update(IUpdateTrigger? updateTrigger, CustomUpdateData customData) { OnUpdating(updateTrigger, customData); + // ReSharper disable ForCanBeConvertedToForeach - 'for' has a performance benefit (no enumerator allocation) here and since 'Update' is considered a hot path it's optimized if (render) lock (_ledGroups) { // Render brushes - foreach (ILedGroup ledGroup in _ledGroups) - try { Render(ledGroup); } + for (int i = 0; i < _ledGroups.Count; i++) + { + try { Render(_ledGroups[i]); } catch (Exception ex) { OnException(ex); } + } } if (updateDevices) - foreach (IRGBDevice device in _devices) - try { device.Update(flushLeds); } + for (int i = 0; i < _devices.Count; i++) + { + try { _devices[i].Update(flushLeds); } catch (Exception ex) { OnException(ex); } + } + // ReSharper restore ForCanBeConvertedToForeach OnUpdated(); } @@ -197,16 +204,17 @@ public void Dispose() /// Thrown if the of the Brush is not valid. private void Render(ILedGroup ledGroup) { - IList leds = ledGroup.ToList(); IBrush? brush = ledGroup.Brush; if ((brush == null) || !brush.IsEnabled) return; + IList leds = ledGroup.ToList(); + IEnumerable<(RenderTarget renderTarget, Color color)> render; switch (brush.CalculationMode) { case RenderMode.Relative: - Rectangle brushRectangle = new(leds.Select(led => led.AbsoluteBoundary)); + Rectangle brushRectangle = new(leds); Point offset = new(-brushRectangle.Location.X, -brushRectangle.Location.Y); brushRectangle = brushRectangle.SetLocation(new Point(0, 0)); render = brush.Render(brushRectangle, leds.Select(led => new RenderTarget(led, led.AbsoluteBoundary.Translate(offset)))); @@ -358,7 +366,7 @@ private void OnException(Exception ex) /// /// Handles the needed event-calls before updating. /// - private void OnUpdating(IUpdateTrigger? trigger, CustomUpdateData customData) + private void OnUpdating(IUpdateTrigger? trigger, ICustomUpdateData customData) { try { diff --git a/RGB.NET.Core/Update/CustomUpdateData.cs b/RGB.NET.Core/Update/CustomUpdateData.cs index 88f734aa..a657e96d 100644 --- a/RGB.NET.Core/Update/CustomUpdateData.cs +++ b/RGB.NET.Core/Update/CustomUpdateData.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace RGB.NET.Core; @@ -34,11 +35,24 @@ public static class CustomUpdateDataIndex /// /// Represents a set of custom data, each indexed by a string-key. /// -public class CustomUpdateData +public interface ICustomUpdateData +{ + /// + /// Gets the value for a specific key. + /// + /// The key of the value. + /// The value represented by the specified key. + object? this[string key] { get; } +} + +/// +/// Represents a set of custom data, each indexed by a string-key. +/// +public class CustomUpdateData : ICustomUpdateData { #region Properties & Fields - private Dictionary _data = new(); + private readonly Dictionary _data = new(); #endregion @@ -51,8 +65,8 @@ public class CustomUpdateData /// The value represented by the specified key. public object? this[string key] { - get => _data.TryGetValue(key.ToUpperInvariant(), out object? data) ? data : default; - set => _data[key.ToUpperInvariant()] = value; + get => _data.TryGetValue(key, out object? data) ? data : default; + set => _data[key] = value; } #endregion @@ -77,3 +91,39 @@ public CustomUpdateData(params (string key, object value)[] values) #endregion } + +internal class DefaultCustomUpdateData : ICustomUpdateData +{ + #region Constants + + public static readonly DefaultCustomUpdateData FLUSH = new(true); + public static readonly DefaultCustomUpdateData NO_FLUSH = new(false); + + #endregion + + #region Properties & Fields + + private readonly bool _flushLeds; + + public object? this[string key] + { + get + { + if (string.Equals(key, CustomUpdateDataIndex.FLUSH_LEDS, StringComparison.Ordinal)) + return _flushLeds; + + return null; + } + } + + #endregion + + #region Constructors + + public DefaultCustomUpdateData(bool flushLeds) + { + this._flushLeds = flushLeds; + } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Presets/Groups/RectangleLedGroup.cs b/RGB.NET.Presets/Groups/RectangleLedGroup.cs index 9547476f..d6cb6502 100644 --- a/RGB.NET.Presets/Groups/RectangleLedGroup.cs +++ b/RGB.NET.Presets/Groups/RectangleLedGroup.cs @@ -114,7 +114,14 @@ public override void OnDetach() /// Gets a list containing all of this . /// /// The list containing all of this . - protected override IEnumerable GetLeds() => _ledCache ??= (Surface?.Leds.Where(led => led.AbsoluteBoundary.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList() ?? new List()); + protected override IEnumerable GetLeds() => ToList(); + + /// + /// + /// Gets a list containing all of this . + /// + /// The list containing all of this . + public override IList ToList() => _ledCache ??= (Surface?.Leds.Where(led => led.AbsoluteBoundary.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList() ?? new List()); private void InvalidateCache() => _ledCache = null; From 38840ef6f4b1af296cd40612da959176e53e9851 Mon Sep 17 00:00:00 2001 From: Danielle Date: Sun, 12 Feb 2023 11:41:18 +1100 Subject: [PATCH 09/96] Asus dev --- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 42 +++++++++++++++++++++ RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs | 3 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index 2e09b528..a9413a7e 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -3,6 +3,9 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Reflection.Metadata; using AuraServiceLib; using RGB.NET.Core; @@ -52,6 +55,7 @@ protected override void InitializeSDK() } /// + protected override IEnumerable LoadDevices() { if (_sdk == null) yield break; @@ -75,6 +79,44 @@ protected override IEnumerable LoadDevices() }; } } + /* + protected override IEnumerable LoadDevices() + { + if (_sdk == null) { + throw new InvalidOperationException($"Asus Library not yet loaded."); + yield break; + } + + var enviroment = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName; + var filePath = $"{enviroment}/ASUSDEBUG.txt"; + var content = ""; + + _devices = _sdk.Enumerate(0); + for (int i = 0; i < _devices.Count; i++) + { + IAuraSyncDevice device = _devices[i]; + + content += $"Name: {device.Name} Type: {device.Type} Type Hex: {device.Type:X} LEDs: {device.Lights.Count} \n\n"; + + yield return (AsusDeviceType)device.Type switch + { + AsusDeviceType.MB_RGB => new AsusMainboardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mainboard, device, WMIHelper.GetMainboardInfo()?.model ?? device.Name), GetUpdateTrigger()), + AsusDeviceType.MB_ADDRESABLE => new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.LedStripe, device), LedId.LedStripe1, GetUpdateTrigger()), + AsusDeviceType.VGA_RGB => new AsusGraphicsCardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.GraphicsCard, device), GetUpdateTrigger()), + AsusDeviceType.HEADSET_RGB => new AsusHeadsetRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Headset, device), GetUpdateTrigger()), + AsusDeviceType.DRAM_RGB => new AsusDramRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.DRAM, device), GetUpdateTrigger()), + AsusDeviceType.KEYBOARD_RGB => new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device), LedMappings.KeyboardMapping, GetUpdateTrigger()), + AsusDeviceType.NB_KB_RGB => new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device), LedMappings.KeyboardMapping, GetUpdateTrigger()), + AsusDeviceType.NB_KB_4ZONE_RGB => new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device), null, GetUpdateTrigger()), + AsusDeviceType.MOUSE_RGB => new AsusMouseRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mouse, device), GetUpdateTrigger()), + AsusDeviceType.TERMINAL_RGB => new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.LedController, device), LedId.Custom1, GetUpdateTrigger()), + _ => new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Unknown, device), LedId.Custom1, GetUpdateTrigger()) + }; + } + + System.IO.File.WriteAllText(filePath, content); + } + */ /// public override void Dispose() diff --git a/RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs b/RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs index ad529ed2..bb5f16f2 100644 --- a/RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs +++ b/RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs @@ -20,5 +20,6 @@ internal enum AsusDeviceType : uint NB_KB_4ZONE_RGB = 0x81001, MOUSE_RGB = 0x90000, CHASSIS_RGB = 0xB0000, - PROJECTOR_RGB = 0xC0000 + PROJECTOR_RGB = 0xC0000, + TERMINAL_RGB = 0xE0000 } \ No newline at end of file From df2f5620eefe08d111cd5414dd9cd7c91f33fe15 Mon Sep 17 00:00:00 2001 From: Danielle Date: Sun, 12 Feb 2023 12:44:39 +1100 Subject: [PATCH 10/96] Update AsusDeviceProvider.cs --- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 40 ++-------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index a9413a7e..494adc02 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -3,9 +3,6 @@ using System; using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Reflection.Metadata; using AuraServiceLib; using RGB.NET.Core; @@ -58,46 +55,16 @@ protected override void InitializeSDK() protected override IEnumerable LoadDevices() { - if (_sdk == null) yield break; - - _devices = _sdk.Enumerate(0); - for (int i = 0; i < _devices.Count; i++) - { - IAuraSyncDevice device = _devices[i]; - yield return (AsusDeviceType)device.Type switch - { - AsusDeviceType.MB_RGB => new AsusMainboardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mainboard, device, WMIHelper.GetMainboardInfo()?.model ?? device.Name), GetUpdateTrigger()), - AsusDeviceType.MB_ADDRESABLE => new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.LedStripe, device), LedId.LedStripe1, GetUpdateTrigger()), - AsusDeviceType.VGA_RGB => new AsusGraphicsCardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.GraphicsCard, device), GetUpdateTrigger()), - AsusDeviceType.HEADSET_RGB => new AsusHeadsetRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Headset, device), GetUpdateTrigger()), - AsusDeviceType.DRAM_RGB => new AsusDramRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.DRAM, device), GetUpdateTrigger()), - AsusDeviceType.KEYBOARD_RGB => new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device), LedMappings.KeyboardMapping, GetUpdateTrigger()), - AsusDeviceType.NB_KB_RGB => new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device), LedMappings.KeyboardMapping, GetUpdateTrigger()), - AsusDeviceType.NB_KB_4ZONE_RGB => new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device), null, GetUpdateTrigger()), - AsusDeviceType.MOUSE_RGB => new AsusMouseRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mouse, device), GetUpdateTrigger()), - _ => new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Unknown, device), LedId.Custom1, GetUpdateTrigger()) - }; - } - } - /* - protected override IEnumerable LoadDevices() - { - if (_sdk == null) { - throw new InvalidOperationException($"Asus Library not yet loaded."); + if (_sdk == null) { yield break; } - var enviroment = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName; - var filePath = $"{enviroment}/ASUSDEBUG.txt"; - var content = ""; _devices = _sdk.Enumerate(0); for (int i = 0; i < _devices.Count; i++) { IAuraSyncDevice device = _devices[i]; - content += $"Name: {device.Name} Type: {device.Type} Type Hex: {device.Type:X} LEDs: {device.Lights.Count} \n\n"; - yield return (AsusDeviceType)device.Type switch { AsusDeviceType.MB_RGB => new AsusMainboardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mainboard, device, WMIHelper.GetMainboardInfo()?.model ?? device.Name), GetUpdateTrigger()), @@ -110,13 +77,10 @@ protected override IEnumerable LoadDevices() AsusDeviceType.NB_KB_4ZONE_RGB => new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device), null, GetUpdateTrigger()), AsusDeviceType.MOUSE_RGB => new AsusMouseRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mouse, device), GetUpdateTrigger()), AsusDeviceType.TERMINAL_RGB => new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.LedController, device), LedId.Custom1, GetUpdateTrigger()), - _ => new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Unknown, device), LedId.Custom1, GetUpdateTrigger()) + _ => new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Unknown, device), LedId.Unknown1, GetUpdateTrigger()) }; } - - System.IO.File.WriteAllText(filePath, content); } - */ /// public override void Dispose() From 914bd8c0a1c591ddd20943bec09a2b40c182567b Mon Sep 17 00:00:00 2001 From: Danielle Date: Sun, 12 Feb 2023 12:45:30 +1100 Subject: [PATCH 11/96] Update AsusDeviceProvider.cs Code cleanup --- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index 494adc02..0dfddb7b 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -55,10 +55,7 @@ protected override void InitializeSDK() protected override IEnumerable LoadDevices() { - if (_sdk == null) { - yield break; - } - + if (_sdk == null) yield break; _devices = _sdk.Enumerate(0); for (int i = 0; i < _devices.Count; i++) From b67294eb3c4d8d0588fe25d25ecf6c790edcefc9 Mon Sep 17 00:00:00 2001 From: Markus Mohoritsch Date: Sun, 12 Feb 2023 10:06:38 +0100 Subject: [PATCH 12/96] Added missing G915 TKL PID --- RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs index 1180ff5d..4ebd163f 100644 --- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs +++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs @@ -73,6 +73,7 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider { { 0x407C, RGBDeviceType.Keyboard, "G915", LedMappings.PerKey, 0 }, { 0x408E, RGBDeviceType.Keyboard, "G915 TKL", LedMappings.PerKey, 0 }, + { 0xC232, RGBDeviceType.Keyboard, "G915 TKL", LedMappings.PerKey, 0 }, }; /// From db2f16d371780bf6b911d0b2515494ab08bbaa4a Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Sun, 12 Feb 2023 13:48:01 +0100 Subject: [PATCH 13/96] Update RGB.NET.Devices.Asus/AsusDeviceProvider.cs --- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index 0dfddb7b..f9af5b39 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -52,7 +52,6 @@ protected override void InitializeSDK() } /// - protected override IEnumerable LoadDevices() { if (_sdk == null) yield break; From cc652a08a61c4acb54755677cba9e2b1dded61b0 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 12 Feb 2023 16:19:00 +0100 Subject: [PATCH 14/96] Added corsair session details --- .../CorsairDeviceProvider.cs | 12 +++++- .../Generic/CorsairProtocolDetails.cs | 37 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 7a1abe0e..d4cd1160 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -45,6 +45,11 @@ public class CorsairDeviceProvider : AbstractRGBDeviceProvider /// public static bool ExclusiveAccess { get; set; } = false; + /// + /// Gets the details for the current SDK-session. + /// + public CorsairSessionDetails SessionDetails { get; private set; } = new(); + #endregion #region Constructors @@ -81,12 +86,17 @@ void OnSessionStateChanged(object? sender, CorsairSessionState state) _CUESDK.SessionStateChanged += OnSessionStateChanged; CorsairError errorCode = _CUESDK.CorsairConnect(); - if (errorCode != CorsairError.Success) Throw(new RGBDeviceException($"Failed to initialized Corsair-SDK. (ErrorCode: {errorCode})")); if (!waitEvent.Wait(ConnectionTimeout)) Throw(new RGBDeviceException($"Failed to initialized Corsair-SDK. (Timeout - Current connection state: {_CUESDK.SesionState})")); + + _CUESDK.CorsairGetSessionDetails(out _CorsairSessionDetails? details); + if (errorCode != CorsairError.Success) + Throw(new RGBDeviceException($"Failed to get session details. (ErrorCode: {errorCode})")); + + SessionDetails = new CorsairSessionDetails(details!); } finally { diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs b/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs new file mode 100644 index 00000000..70697761 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs @@ -0,0 +1,37 @@ +// ReSharper disable MemberCanBePrivate.Global + +using RGB.NET.Devices.Corsair.Native; + +namespace RGB.NET.Devices.Corsair; + +/// +/// Represents version information for the Corsair-SDK +/// +public class CorsairSessionDetails +{ + #region Properties & Fields + + public string ClientVersion { get; } + public string ServerVersion { get; } + public string ServerHostVersion { get; } + + #endregion + + #region Constructors + + internal CorsairSessionDetails() + { + ClientVersion = string.Empty; + ServerVersion = string.Empty; + ServerHostVersion = string.Empty; + } + + internal CorsairSessionDetails(_CorsairSessionDetails nativeDetails) + { + this.ClientVersion = nativeDetails.clientVersion.ToString(); + this.ServerVersion = nativeDetails.serverVersion.ToString(); + this.ServerHostVersion = nativeDetails.serverHostVersion.ToString(); + } + + #endregion +} \ No newline at end of file From bb3b74b9195a68d91396d66b0fb96d8d114cda17 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 12 Feb 2023 16:23:27 +0100 Subject: [PATCH 15/96] Removed debug output --- RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index d4cd1160..08f692a5 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -129,8 +129,7 @@ private IEnumerable LoadCorsairDevices() Throw(new RGBDeviceException($"Failed to take control of device '{device.id}'. (ErrorCode: {error})")); CorsairDeviceUpdateQueue updateQueue = new(GetUpdateTrigger(), device); - - Console.WriteLine("Loading " + device.model); + int channelLedCount = 0; for (int i = 0; i < device.channelCount; i++) { From 37e495458346c2294754f23cdc827eb6e7a6edec Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 5 Mar 2023 16:34:01 +0100 Subject: [PATCH 16/96] Added exception-handling to all UpdateQueues --- .../Devices/AbstractRGBDeviceProvider.cs | 2 +- RGB.NET.Core/Devices/IRGBDeviceProvider.cs | 4 +++ .../Generic/AsusUpdateQueue.cs | 5 +-- .../Generic/CoolerMasterUpdateQueue.cs | 17 +++++++--- .../CorsairDeviceProvider.cs | 29 +++++++++++++++-- .../Generic/CorsairDeviceUpdateQueue.cs | 25 +++++++++------ RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs | 21 ++++++++----- .../PerDevice/LogitechPerDeviceUpdateQueue.cs | 19 ++++++++---- .../PerKey/LogitechPerKeyUpdateQueue.cs | 25 +++++++++------ .../Generic/MsiDeviceUpdateQueue.cs | 11 +++++-- .../Generic/MidiUpdateQueue.cs | 11 +++++-- .../Generic/OpenRGBUpdateQueue.cs | 13 ++++++-- .../PicoPi/PicoPiBulkUpdateQueue.cs | 29 ++++++++++------- .../PicoPi/PicoPiHIDUpdateQueue.cs | 31 ++++++++++++------- .../Generic/RazerUpdateQueue.cs | 26 ++++++++++------ .../Generic/SteelSeriesDeviceUpdateQueue.cs | 15 ++++++--- .../Generic/SerialPortUpdateQueue.cs | 13 ++++++-- .../Generic/WootingUpdateQueue.cs | 25 +++++++++------ 18 files changed, 223 insertions(+), 98 deletions(-) diff --git a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs index ae66ca00..d61fcbb9 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs @@ -178,7 +178,7 @@ protected virtual void Reset() /// /// The exception to throw. /// Indicates if the exception is critical for device provider to work correctly. - protected virtual void Throw(Exception ex, bool isCritical = false) + public virtual void Throw(Exception ex, bool isCritical = false) { ExceptionEventArgs args = new(ex, isCritical, ThrowsExceptions); try { OnException(args); } catch { /* we don't want to throw due to bad event handlers */ } diff --git a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs index 48edc4d2..86f41e13 100644 --- a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs +++ b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs @@ -20,6 +20,10 @@ public interface IRGBDeviceProvider : IDisposable /// /// Indicates if exceptions in the device provider are thrown or silently ignored. /// + /// + /// This should only be set to true for debugging/development purposes. + /// Production code should use the -Event to handle exceptions. + /// bool ThrowsExceptions { get; } /// diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs index 6de33faa..27f4f5b1 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs @@ -89,8 +89,9 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe Device.Apply(); } - catch - { /* "The server threw an exception." seems to be a thing here ... */ + catch (Exception ex) + { + AsusDeviceProvider.Instance.Throw(ex, true); } } diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs index 6631eb1b..07df7cc5 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs @@ -39,13 +39,20 @@ public CoolerMasterUpdateQueue(IDeviceUpdateTrigger updateTrigger, CoolerMasterD /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - foreach ((object key, Color color) in dataSet) + try { - (int row, int column) = ((int, int))key; - _deviceMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(color.GetR(), color.GetG(), color.GetB()); - } + foreach ((object key, Color color) in dataSet) + { + (int row, int column) = ((int, int))key; + _deviceMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(color.GetR(), color.GetG(), color.GetB()); + } - _CoolerMasterSDK.SetAllLedColor(_deviceMatrix, _deviceIndex); + _CoolerMasterSDK.SetAllLedColor(_deviceMatrix, _deviceIndex); + } + catch (Exception ex) + { + CoolerMasterDeviceProvider.Instance.Throw(ex, true); + } } #endregion diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 08f692a5..ac363b96 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -50,6 +50,26 @@ public class CorsairDeviceProvider : AbstractRGBDeviceProvider /// public CorsairSessionDetails SessionDetails { get; private set; } = new(); + private CorsairSessionState _sessionState = CorsairSessionState.Invalid; + public CorsairSessionState SessionState + { + get => _sessionState; + private set + { + _sessionState = value; + + try { SessionStateChanged?.Invoke(this, SessionState); } + catch { /* catch faulty event-handlers*/ } + } + } + + #endregion + + #region Events + + // ReSharper disable once UnassignedField.Global + public EventHandler? SessionStateChanged; + #endregion #region Constructors @@ -74,7 +94,7 @@ protected override void InitializeSDK() using ManualResetEventSlim waitEvent = new(false); - void OnSessionStateChanged(object? sender, CorsairSessionState state) + void OnInitializeSessionStateChanged(object? sender, CorsairSessionState state) { if (state == CorsairSessionState.Connected) // ReSharper disable once AccessToDisposedClosure @@ -84,6 +104,7 @@ void OnSessionStateChanged(object? sender, CorsairSessionState state) try { _CUESDK.SessionStateChanged += OnSessionStateChanged; + _CUESDK.SessionStateChanged += OnInitializeSessionStateChanged; CorsairError errorCode = _CUESDK.CorsairConnect(); if (errorCode != CorsairError.Success) @@ -100,10 +121,12 @@ void OnSessionStateChanged(object? sender, CorsairSessionState state) } finally { - _CUESDK.SessionStateChanged -= OnSessionStateChanged; + _CUESDK.SessionStateChanged -= OnInitializeSessionStateChanged; } } + private void OnSessionStateChanged(object? sender, CorsairSessionState state) => SessionState = state; + /// protected override IEnumerable LoadDevices() { @@ -129,7 +152,7 @@ private IEnumerable LoadCorsairDevices() Throw(new RGBDeviceException($"Failed to take control of device '{device.id}'. (ErrorCode: {error})")); CorsairDeviceUpdateQueue updateQueue = new(GetUpdateTrigger(), device); - + int channelLedCount = 0; for (int i = 0; i < device.channelCount; i++) { diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs index 1d42dc2e..2cc6b88d 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs @@ -40,17 +40,24 @@ internal CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, _CorsairDe /// protected override unsafe void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - Span<_CorsairLedColor> colors = new((void*)_colorPtr, dataSet.Length); - for (int i = 0; i < colors.Length; i++) + try { - (object id, Color color) = dataSet[i]; - (byte a, byte r, byte g, byte b) = color.GetRGBBytes(); - colors[i] = new _CorsairLedColor((CorsairLedId)id, r, g, b, a); - } + Span<_CorsairLedColor> colors = new((void*)_colorPtr, dataSet.Length); + for (int i = 0; i < colors.Length; i++) + { + (object id, Color color) = dataSet[i]; + (byte a, byte r, byte g, byte b) = color.GetRGBBytes(); + colors[i] = new _CorsairLedColor((CorsairLedId)id, r, g, b, a); + } - CorsairError error = _CUESDK.CorsairSetLedColors(_device.id!, dataSet.Length, _colorPtr); - if (error != CorsairError.Success) - throw new RGBDeviceException($"Failed to update device '{_device.id}'. (ErrorCode: {error})"); + CorsairError error = _CUESDK.CorsairSetLedColors(_device.id!, dataSet.Length, _colorPtr); + if (error != CorsairError.Success) + throw new RGBDeviceException($"Failed to update device '{_device.id}'. (ErrorCode: {error})"); + } + catch (Exception ex) + { + CorsairDeviceProvider.Instance.Throw(ex, true); + } } /// diff --git a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs index b1bffdb3..4fc62e9e 100644 --- a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs +++ b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs @@ -61,16 +61,23 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData) /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - DataPacket.SetSequenceNumber(GetNextSequenceNumber()); + try + { + DataPacket.SetSequenceNumber(GetNextSequenceNumber()); + + foreach ((object key, Color color) in dataSet) + { + LedChannelMapping mapping = (LedChannelMapping)key; + foreach ((int channel, Func getValue) in mapping) + DataPacket.SetChannel(channel, getValue(color)); + } - foreach ((object key, Color color) in dataSet) + _socket.Send(DataPacket, DataPacket.Length); + } + catch (Exception ex) { - LedChannelMapping mapping = (LedChannelMapping)key; - foreach ((int channel, Func getValue) in mapping) - DataPacket.SetChannel(channel, getValue(color)); + DMXDeviceProvider.Instance.Throw(ex, true); } - - _socket.Send(DataPacket, DataPacket.Length); } /// diff --git a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs index a3e88017..eede5371 100644 --- a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs @@ -27,12 +27,19 @@ public LogitechPerDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger) /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - Color color = dataSet[0].color; - - _LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.DeviceRGB); - _LogitechGSDK.LogiLedSetLighting((int)Math.Round(color.R * 100), - (int)Math.Round(color.G * 100), - (int)Math.Round(color.B * 100)); + try + { + Color color = dataSet[0].color; + + _LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.DeviceRGB); + _LogitechGSDK.LogiLedSetLighting((int)Math.Round(color.R * 100), + (int)Math.Round(color.G * 100), + (int)Math.Round(color.B * 100)); + } + catch (Exception ex) + { + LogitechDeviceProvider.Instance.Throw(ex, true); + } } #endregion diff --git a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs index 3b75a3b0..5c4efbbd 100644 --- a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs @@ -27,16 +27,23 @@ public LogitechPerKeyUpdateQueue(IDeviceUpdateTrigger updateTrigger) /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - _LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB); - - foreach ((object key, Color color) in dataSet) + try + { + _LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB); + + foreach ((object key, Color color) in dataSet) + { + // These will be LogitechLedId but the SDK expects an int and doesn't care about invalid values + int keyName = (int)key; + _LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(keyName, + (int)MathF.Round(color.R * 100), + (int)MathF.Round(color.G * 100), + (int)MathF.Round(color.B * 100)); + } + } + catch (Exception ex) { - // These will be LogitechLedId but the SDK expects an int and doesn't care about invalid values - int keyName = (int)key; - _LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(keyName, - (int)MathF.Round(color.R * 100), - (int)MathF.Round(color.G * 100), - (int)MathF.Round(color.B * 100)); + LogitechDeviceProvider.Instance.Throw(ex, true); } } diff --git a/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs b/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs index d503148c..4a9acd50 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs @@ -36,8 +36,15 @@ public MsiDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, string deviceTyp /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - foreach ((object key, Color color) in dataSet) - _MsiSDK.SetLedColor(_deviceType, (int)key, color.GetR(), color.GetG(), color.GetB()); + try + { + foreach ((object key, Color color) in dataSet) + _MsiSDK.SetLedColor(_deviceType, (int)key, color.GetR(), color.GetG(), color.GetB()); + } + catch (Exception ex) + { + MsiDeviceProvider.Instance.Throw(ex, true); + } } #endregion diff --git a/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs index dc21766e..9a1af350 100644 --- a/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs +++ b/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs @@ -37,8 +37,15 @@ protected MidiUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId) /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - foreach ((object key, Color color) in dataSet) - SendMessage(CreateMessage(key, color)); + try + { + foreach ((object key, Color color) in dataSet) + SendMessage(CreateMessage(key, color)); + } + catch (Exception ex) + { + NovationDeviceProvider.Instance.Throw(ex, true); + } } /// diff --git a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs index aab78d42..b6c91b8c 100644 --- a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs +++ b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs @@ -51,10 +51,17 @@ public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceid, Open /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - foreach ((object key, Color color) in dataSet) - _colors[(int)key] = new OpenRGBColor(color.GetR(), color.GetG(), color.GetB()); + try + { + foreach ((object key, Color color) in dataSet) + _colors[(int)key] = new OpenRGBColor(color.GetR(), color.GetG(), color.GetB()); - _openRGB.UpdateLeds(_deviceid, _colors); + _openRGB.UpdateLeds(_deviceid, _colors); + } + catch (Exception ex) + { + OpenRGBDeviceProvider.Instance.Throw(ex, true); + } } #endregion diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs index fa328933..4e0a096b 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs @@ -46,20 +46,27 @@ public PicoPiBulkUpdateQueue(IDeviceUpdateTrigger updateTrigger, PicoPiSDK sdk, /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - Span buffer = _dataBuffer; - foreach ((object key, Color color) in dataSet) + try { - int index = key as int? ?? -1; - if (index < 0) continue; + Span buffer = _dataBuffer; + foreach ((object key, Color color) in dataSet) + { + int index = key as int? ?? -1; + if (index < 0) continue; - (byte _, byte r, byte g, byte b) = color.GetRGBBytes(); - int offset = index * 3; - buffer[offset] = r; - buffer[offset + 1] = g; - buffer[offset + 2] = b; - } + (byte _, byte r, byte g, byte b) = color.GetRGBBytes(); + int offset = index * 3; + buffer[offset] = r; + buffer[offset + 1] = g; + buffer[offset + 2] = b; + } - _sdk.SendBulkUpdate(buffer, _channel); + _sdk.SendBulkUpdate(buffer, _channel); + } + catch (Exception ex) + { + PicoPiDeviceProvider.Instance.Throw(ex, true); + } } #endregion diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs index 8ee06a23..381d3820 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs @@ -43,20 +43,27 @@ public PicoPiHIDUpdateQueue(IDeviceUpdateTrigger updateTrigger, PicoPiSDK sdk, i /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - Span buffer = _dataBuffer; - foreach ((object key, Color color) in dataSet) + try { - int index = key as int? ?? -1; - if (index < 0) continue; - - (byte _, byte r, byte g, byte b) = color.GetRGBBytes(); - int offset = index * 3; - buffer[offset] = r; - buffer[offset + 1] = g; - buffer[offset + 2] = b; - } + Span buffer = _dataBuffer; + foreach ((object key, Color color) in dataSet) + { + int index = key as int? ?? -1; + if (index < 0) continue; + + (byte _, byte r, byte g, byte b) = color.GetRGBBytes(); + int offset = index * 3; + buffer[offset] = r; + buffer[offset + 1] = g; + buffer[offset + 2] = b; + } - _sdk.SendHidUpdate(buffer, _channel); + _sdk.SendHidUpdate(buffer, _channel); + } + catch (Exception ex) + { + PicoPiDeviceProvider.Instance.Throw(ex, true); + } } #endregion diff --git a/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs b/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs index cc8fedcc..33f8d320 100644 --- a/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Razer; public abstract class RazerUpdateQueue : UpdateQueue { #region Properties & Fields - + private Guid? _lastEffect; #endregion @@ -23,8 +23,7 @@ public abstract class RazerUpdateQueue : UpdateQueue /// The update trigger used to update this queue. protected RazerUpdateQueue(IDeviceUpdateTrigger updateTrigger) : base(updateTrigger) - { - } + { } #endregion @@ -33,16 +32,23 @@ protected RazerUpdateQueue(IDeviceUpdateTrigger updateTrigger) /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - IntPtr effectParams = CreateEffectParams(dataSet); - Guid effectId = Guid.NewGuid(); - CreateEffect(effectParams, ref effectId); + try + { + IntPtr effectParams = CreateEffectParams(dataSet); + Guid effectId = Guid.NewGuid(); + CreateEffect(effectParams, ref effectId); - _RazerSDK.SetEffect(effectId); + _RazerSDK.SetEffect(effectId); - if (_lastEffect.HasValue) - _RazerSDK.DeleteEffect(_lastEffect.Value); + if (_lastEffect.HasValue) + _RazerSDK.DeleteEffect(_lastEffect.Value); - _lastEffect = effectId; + _lastEffect = effectId; + } + catch (Exception ex) + { + RazerDeviceProvider.Instance.Throw(ex, true); + } } /// diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs index 67c39a40..d5b0c2ad 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs @@ -37,10 +37,17 @@ public SteelSeriesDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, string d protected override void OnUpdate(object? sender, CustomUpdateData customData) { - if (customData[CustomUpdateDataIndex.HEARTBEAT] as bool? ?? false) - SteelSeriesSDK.SendHeartbeat(); - else - base.OnUpdate(sender, customData); + try + { + if (customData[CustomUpdateDataIndex.HEARTBEAT] as bool? ?? false) + SteelSeriesSDK.SendHeartbeat(); + else + base.OnUpdate(sender, customData); + } + catch (Exception ex) + { + SteelSeriesDeviceProvider.Instance.Throw(ex, true); + } } /// diff --git a/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs b/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs index cdd10759..78dab04c 100644 --- a/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs @@ -58,10 +58,17 @@ protected override void OnStartup(object? sender, CustomUpdateData customData) /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - foreach (TData command in GetCommands(dataSet.ToArray())) + try { - SerialConnection.ReadTo(Prompt); - SendCommand(command); + foreach (TData command in GetCommands(dataSet.ToArray())) + { + SerialConnection.ReadTo(Prompt); + SendCommand(command); + } + } + catch (Exception ex) + { + WS281XDeviceProvider.Instance.Throw(ex, true); } } diff --git a/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs b/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs index a9d6f547..7e6ae673 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs @@ -13,7 +13,7 @@ public class WootingUpdateQueue : UpdateQueue #region Properties & Fields private readonly byte _deviceid; #endregion - + #region Constructors /// @@ -33,17 +33,24 @@ public WootingUpdateQueue(IDeviceUpdateTrigger updateTrigger, byte deviceId) /// protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - lock (_WootingSDK.SdkLock) + try { - _WootingSDK.SelectDevice(_deviceid); - - foreach ((object key, Color color) in dataSet) + lock (_WootingSDK.SdkLock) { - (int row, int column) = ((int, int))key; - _WootingSDK.ArraySetSingle((byte)row, (byte)column, color.GetR(), color.GetG(), color.GetB()); - } + _WootingSDK.SelectDevice(_deviceid); + + foreach ((object key, Color color) in dataSet) + { + (int row, int column) = ((int, int))key; + _WootingSDK.ArraySetSingle((byte)row, (byte)column, color.GetR(), color.GetG(), color.GetB()); + } - _WootingSDK.ArrayUpdateKeyboard(); + _WootingSDK.ArrayUpdateKeyboard(); + } + } + catch (Exception ex) + { + WootingDeviceProvider.Instance.Throw(ex, true); } } From 30ccfdcd85c35f02b6ad845fb264cbac8fb61006 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 5 Mar 2023 18:04:50 +0100 Subject: [PATCH 17/96] (MAJOR) Added success-indication to device updates and forced flushes after nonsuccessful ones. Added exception handling the last missing queues. --- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 2 +- RGB.NET.Core/Update/Devices/IUpdateQueue.cs | 5 ++++ RGB.NET.Core/Update/Devices/UpdateQueue.cs | 6 ++-- .../Generic/AsusUpdateQueue.cs | 12 +++++--- .../Generic/CoolerMasterUpdateQueue.cs | 8 +++-- .../Generic/CorsairDeviceUpdateQueue.cs | 10 +++++-- RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs | 8 +++-- .../DebugDeviceUpdateQueue.cs | 2 +- .../PerDevice/LogitechPerDeviceUpdateQueue.cs | 8 +++-- .../PerKey/LogitechPerKeyUpdateQueue.cs | 8 +++-- .../Zone/LogitechZoneUpdateQueue.cs | 29 +++++++++++++------ .../Generic/MsiDeviceUpdateQueue.cs | 8 +++-- .../Generic/MidiUpdateQueue.cs | 8 +++-- .../Generic/OpenRGBUpdateQueue.cs | 8 +++-- .../PicoPi/PicoPiBulkUpdateQueue.cs | 8 +++-- .../PicoPi/PicoPiHIDUpdateQueue.cs | 8 +++-- .../Generic/RazerUpdateQueue.cs | 8 +++-- .../Generic/SteelSeriesDeviceUpdateQueue.cs | 19 ++++++++++-- .../Generic/SerialPortUpdateQueue.cs | 8 +++-- .../NodeMCU/NodeMCUWS2812USBUpdateQueue.cs | 20 ++++++++++--- .../Generic/WootingUpdateQueue.cs | 8 +++-- 21 files changed, 151 insertions(+), 50 deletions(-) diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index ca6a5b27..6ac90da2 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -111,7 +111,7 @@ public virtual void Update(bool flushLeds = false) /// /// Forces all LEDs to be treated as dirty. /// The collection LEDs to update. - protected virtual IEnumerable GetLedsToUpdate(bool flushLeds) => ((RequiresFlush || flushLeds) ? LedMapping.Values : LedMapping.Values.Where(x => x.IsDirty)).Where(led => led.RequestedColor?.A > 0); + protected virtual IEnumerable GetLedsToUpdate(bool flushLeds) => ((RequiresFlush || flushLeds || UpdateQueue.RequiresFlush) ? LedMapping.Values : LedMapping.Values.Where(x => x.IsDirty)).Where(led => led.RequestedColor?.A > 0); /// /// Gets an enumerable of a custom data and color tuple for the specified leds. diff --git a/RGB.NET.Core/Update/Devices/IUpdateQueue.cs b/RGB.NET.Core/Update/Devices/IUpdateQueue.cs index 3a0f63a5..348c16eb 100644 --- a/RGB.NET.Core/Update/Devices/IUpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/IUpdateQueue.cs @@ -11,6 +11,11 @@ namespace RGB.NET.Core; public interface IUpdateQueue : IDisposable where TIdentifier : notnull { + /// + /// Gets a bool indicating if the queue requires a flush of all data due to an internal error. + /// + bool RequiresFlush { get; } + /// /// Sets or merges the provided data set in the current dataset and notifies the trigger that there is new data available. /// diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index 4c169b7b..239b6893 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -19,6 +19,8 @@ public abstract class UpdateQueue : IUpdateQueue _currentDataSet = new(); + public bool RequiresFlush { get; private set; } + #endregion #region Constructors @@ -62,7 +64,7 @@ protected virtual void OnUpdate(object? sender, CustomUpdateData customData) _currentDataSet.Clear(); } - Update(data); + RequiresFlush = !Update(data); ArrayPool<(TIdentifier, TData)>.Shared.Return(dataSet); } @@ -78,7 +80,7 @@ protected virtual void OnStartup(object? sender, CustomUpdateData customData) { /// Performs the update this queue is responsible for. /// /// The set of data that needs to be updated. - protected abstract void Update(in ReadOnlySpan<(TIdentifier key, TData color)> dataSet); + protected abstract bool Update(in ReadOnlySpan<(TIdentifier key, TData color)> dataSet); /// /// Sets or merges the provided data set in the current dataset and notifies the trigger that there is new data available. diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs index 27f4f5b1..012ed7e6 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs @@ -43,14 +43,14 @@ public AsusUpdateQueue(IDeviceUpdateTrigger updateTrigger, IAuraSyncDevice devic #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { if ((Device.Type == (uint)AsusDeviceType.KEYBOARD_RGB) || (Device.Type == (uint)AsusDeviceType.NB_KB_RGB)) { if (Device is not IAuraSyncKeyboard keyboard) - return; + return true; foreach ((object customData, Color value) in dataSet) { @@ -88,12 +88,16 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe } Device.Apply(); + + return true; } catch (Exception ex) { - AsusDeviceProvider.Instance.Throw(ex, true); + AsusDeviceProvider.Instance.Throw(ex); } - } + return false; + } + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs index 07df7cc5..4121c4f7 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs @@ -37,7 +37,7 @@ public CoolerMasterUpdateQueue(IDeviceUpdateTrigger updateTrigger, CoolerMasterD #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { @@ -48,11 +48,15 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe } _CoolerMasterSDK.SetAllLedColor(_deviceMatrix, _deviceIndex); + + return true; } catch (Exception ex) { - CoolerMasterDeviceProvider.Instance.Throw(ex, true); + CoolerMasterDeviceProvider.Instance.Throw(ex); } + + return false; } #endregion diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs index 2cc6b88d..fa743e8d 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs @@ -38,10 +38,12 @@ internal CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, _CorsairDe #region Methods /// - protected override unsafe void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override unsafe bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { + if (!_CUESDK.IsConnected) return false; + Span<_CorsairLedColor> colors = new((void*)_colorPtr, dataSet.Length); for (int i = 0; i < colors.Length; i++) { @@ -53,11 +55,15 @@ protected override unsafe void Update(in ReadOnlySpan<(object key, Color color)> CorsairError error = _CUESDK.CorsairSetLedColors(_device.id!, dataSet.Length, _colorPtr); if (error != CorsairError.Success) throw new RGBDeviceException($"Failed to update device '{_device.id}'. (ErrorCode: {error})"); + + return true; } catch (Exception ex) { - CorsairDeviceProvider.Instance.Throw(ex, true); + CorsairDeviceProvider.Instance.Throw(ex); } + + return false; } /// diff --git a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs index 4fc62e9e..57159e93 100644 --- a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs +++ b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs @@ -59,7 +59,7 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData) } /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { @@ -73,11 +73,15 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe } _socket.Send(DataPacket, DataPacket.Length); + + return true; } catch (Exception ex) { - DMXDeviceProvider.Instance.Throw(ex, true); + DMXDeviceProvider.Instance.Throw(ex); } + + return false; } /// diff --git a/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs b/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs index ccd03447..1e00c42f 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs @@ -15,7 +15,7 @@ public DebugDeviceUpdateQueue() #region Methods - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) { } + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) => true; #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs index eede5371..c32f87d8 100644 --- a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs @@ -25,7 +25,7 @@ public LogitechPerDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { @@ -35,11 +35,15 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe _LogitechGSDK.LogiLedSetLighting((int)Math.Round(color.R * 100), (int)Math.Round(color.G * 100), (int)Math.Round(color.B * 100)); + + return true; } catch (Exception ex) { - LogitechDeviceProvider.Instance.Throw(ex, true); + LogitechDeviceProvider.Instance.Throw(ex); } + + return false; } #endregion diff --git a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs index 5c4efbbd..b0bdaf49 100644 --- a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs @@ -25,7 +25,7 @@ public LogitechPerKeyUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { @@ -40,11 +40,15 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe (int)MathF.Round(color.G * 100), (int)MathF.Round(color.B * 100)); } + + return true; } catch (Exception ex) { - LogitechDeviceProvider.Instance.Throw(ex, true); + LogitechDeviceProvider.Instance.Throw(ex); } + + return false; } #endregion diff --git a/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs b/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs index a76d5c50..eba7a2d9 100644 --- a/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs @@ -33,18 +33,29 @@ public LogitechZoneUpdateQueue(IDeviceUpdateTrigger updateTrigger, LogitechDevic #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - _LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.All); - - foreach ((object key, Color color) in dataSet) + try + { + _LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.All); + + foreach ((object key, Color color) in dataSet) + { + int zone = (int)key; + _LogitechGSDK.LogiLedSetLightingForTargetZone(_deviceType, zone, + (int)MathF.Round(color.R * 100), + (int)MathF.Round(color.G * 100), + (int)MathF.Round(color.B * 100)); + } + + return true; + } + catch (Exception ex) { - int zone = (int)key; - _LogitechGSDK.LogiLedSetLightingForTargetZone(_deviceType, zone, - (int)MathF.Round(color.R * 100), - (int)MathF.Round(color.G * 100), - (int)MathF.Round(color.B * 100)); + LogitechDeviceProvider.Instance.Throw(ex); } + + return false; } #endregion diff --git a/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs b/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs index 4a9acd50..8db204f5 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs @@ -34,17 +34,21 @@ public MsiDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, string deviceTyp #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { foreach ((object key, Color color) in dataSet) _MsiSDK.SetLedColor(_deviceType, (int)key, color.GetR(), color.GetG(), color.GetB()); + + return true; } catch (Exception ex) { - MsiDeviceProvider.Instance.Throw(ex, true); + MsiDeviceProvider.Instance.Throw(ex); } + + return false; } #endregion diff --git a/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs index 9a1af350..945c4ff5 100644 --- a/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs +++ b/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs @@ -35,17 +35,21 @@ protected MidiUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId) #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { foreach ((object key, Color color) in dataSet) SendMessage(CreateMessage(key, color)); + + return true; } catch (Exception ex) { - NovationDeviceProvider.Instance.Throw(ex, true); + NovationDeviceProvider.Instance.Throw(ex); } + + return false; } /// diff --git a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs index b6c91b8c..fa79e6e9 100644 --- a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs +++ b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs @@ -49,7 +49,7 @@ public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceid, Open #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { @@ -57,11 +57,15 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe _colors[(int)key] = new OpenRGBColor(color.GetR(), color.GetG(), color.GetB()); _openRGB.UpdateLeds(_deviceid, _colors); + + return true; } catch (Exception ex) { - OpenRGBDeviceProvider.Instance.Throw(ex, true); + OpenRGBDeviceProvider.Instance.Throw(ex); } + + return false; } #endregion diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs index 4e0a096b..8cd251dd 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs @@ -44,7 +44,7 @@ public PicoPiBulkUpdateQueue(IDeviceUpdateTrigger updateTrigger, PicoPiSDK sdk, #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { @@ -62,11 +62,15 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe } _sdk.SendBulkUpdate(buffer, _channel); + + return true; } catch (Exception ex) { - PicoPiDeviceProvider.Instance.Throw(ex, true); + PicoPiDeviceProvider.Instance.Throw(ex); } + + return false; } #endregion diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs index 381d3820..b3ff9565 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs @@ -41,7 +41,7 @@ public PicoPiHIDUpdateQueue(IDeviceUpdateTrigger updateTrigger, PicoPiSDK sdk, i #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { @@ -59,11 +59,15 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe } _sdk.SendHidUpdate(buffer, _channel); + + return true; } catch (Exception ex) { - PicoPiDeviceProvider.Instance.Throw(ex, true); + PicoPiDeviceProvider.Instance.Throw(ex); } + + return false; } #endregion diff --git a/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs b/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs index 33f8d320..105fee90 100644 --- a/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs @@ -30,7 +30,7 @@ protected RazerUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { @@ -44,11 +44,15 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe _RazerSDK.DeleteEffect(_lastEffect.Value); _lastEffect = effectId; + + return true; } catch (Exception ex) { - RazerDeviceProvider.Instance.Throw(ex, true); + RazerDeviceProvider.Instance.Throw(ex); } + + return false; } /// diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs index d5b0c2ad..26d744d9 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs @@ -46,13 +46,26 @@ protected override void OnUpdate(object? sender, CustomUpdateData customData) } catch (Exception ex) { - SteelSeriesDeviceProvider.Instance.Throw(ex, true); + SteelSeriesDeviceProvider.Instance.Throw(ex); } } /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) - => SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.ToArray().Select(x => (((SteelSeriesLedId)x.key).GetAPIName(), x.color.ToIntArray())).Where(x => x.Item1 != null).ToList()!); + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + { + try + { + SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.ToArray().Select(x => (((SteelSeriesLedId)x.key).GetAPIName(), x.color.ToIntArray())).Where(x => x.Item1 != null).ToList()!); + + return true; + } + catch (Exception ex) + { + SteelSeriesDeviceProvider.Instance.Throw(ex); + } + + return false; + } #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs b/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs index 78dab04c..f1aa16c8 100644 --- a/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs @@ -56,7 +56,7 @@ protected override void OnStartup(object? sender, CustomUpdateData customData) } /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { @@ -65,11 +65,15 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe SerialConnection.ReadTo(Prompt); SendCommand(command); } + + return true; } catch (Exception ex) { - WS281XDeviceProvider.Instance.Throw(ex, true); + WS281XDeviceProvider.Instance.Throw(ex); } + + return false; } /// diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs index a3619e2f..9e6d30ee 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs @@ -77,13 +77,25 @@ protected override void OnStartup(object? sender, CustomUpdateData customData) } /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { - foreach (IGrouping channelData in dataSet.ToArray().Select(x => (((int channel, int key))x.key, x.color)).GroupBy(x => x.Item1.channel)) + try { - byte[] buffer = GetBuffer(channelData); - _sendDataAction(buffer); + foreach (IGrouping channelData in dataSet.ToArray() + .Select(x => (((int channel, int key))x.key, x.color)).GroupBy(x => x.Item1.channel)) + { + byte[] buffer = GetBuffer(channelData); + _sendDataAction(buffer); + } + + return true; } + catch (Exception ex) + { + WS281XDeviceProvider.Instance.Throw(ex); + } + + return false; } private void SendHttp(byte[] buffer) diff --git a/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs b/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs index 7e6ae673..3791ba06 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs @@ -31,7 +31,7 @@ public WootingUpdateQueue(IDeviceUpdateTrigger updateTrigger, byte deviceId) #region Methods /// - protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) { try { @@ -47,11 +47,15 @@ protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSe _WootingSDK.ArrayUpdateKeyboard(); } + + return true; } catch (Exception ex) { - WootingDeviceProvider.Instance.Throw(ex, true); + WootingDeviceProvider.Instance.Throw(ex); } + + return false; } #endregion From 4a9bbb64dc5a029d44c5a6bf1fbf4b0f3ea3c508 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 5 Mar 2023 18:06:08 +0100 Subject: [PATCH 18/96] Added missing doc comment --- RGB.NET.Core/Update/Devices/UpdateQueue.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index 239b6893..1cc5eca7 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -19,6 +19,7 @@ public abstract class UpdateQueue : IUpdateQueue _currentDataSet = new(); + /// public bool RequiresFlush { get; private set; } #endregion From b6342ea57563746712c5e9c245e961c5a2e40cdd Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Thu, 9 Mar 2023 14:43:23 +0000 Subject: [PATCH 19/96] Wooting - Add macOS dylib --- .../Generic/WootingRGBDevice.cs | 1 - RGB.NET.Devices.Wooting/Native/_WootingSDK.cs | 6 ++++-- RGB.NET.Devices.Wooting/WootingDeviceProvider.cs | 14 +++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs b/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs index fc28728a..8697eb1c 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs @@ -20,7 +20,6 @@ public abstract class WootingRGBDevice : AbstractRGBDevice GetPossibleLibraryPaths() IEnumerable possibleLibraryPaths; if (OperatingSystem.IsWindows()) - possibleLibraryPaths = Environment.Is64BitProcess ? WootingDeviceProvider.PossibleX64NativePaths : WootingDeviceProvider.PossibleX86NativePaths; + possibleLibraryPaths = Environment.Is64BitProcess ? WootingDeviceProvider.PossibleX64NativePathsWindows : WootingDeviceProvider.PossibleX86NativePathsWindows; else if (OperatingSystem.IsLinux()) - possibleLibraryPaths = Environment.Is64BitProcess ? WootingDeviceProvider.PossibleX64NativePathsLinux : WootingDeviceProvider.PossibleX86NativePathsLinux; + possibleLibraryPaths = WootingDeviceProvider.PossibleNativePathsLinux; + else if (OperatingSystem.IsMacOS()) + possibleLibraryPaths = WootingDeviceProvider.PossibleNativePathsMacOS; else possibleLibraryPaths = Enumerable.Empty(); diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 57d99c1d..c920ebb5 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -26,25 +26,25 @@ public class WootingDeviceProvider : AbstractRGBDeviceProvider /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/wooting-rgb-sdk.dll" }; + public static List PossibleX86NativePathsWindows { get; } = new() { "x86/wooting-rgb-sdk.dll" }; /// - /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 linux applications. + /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 windows applications. /// The first match will be used. /// - public static List PossibleX86NativePathsLinux { get; } = new() { "x86/wooting-rgb-sdk.so" }; + public static List PossibleX64NativePathsWindows { get; } = new() { "x64/wooting-rgb-sdk64.dll" }; /// - /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 windows applications. + /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 linux applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/wooting-rgb-sdk64.dll" }; + public static List PossibleNativePathsLinux { get; } = new() { "x64/libwooting-rgb-sdk.so" }; /// - /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 linux applications. + /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 MacOS applications. /// The first match will be used. /// - public static List PossibleX64NativePathsLinux { get; } = new() { "x64/wooting-rgb-sdk64.so" }; + public static List PossibleNativePathsMacOS { get; } = new() { "x64/libwooting-rgb-sdk.dylib" }; #endregion From 1793d26166fa98e5295ce74ce4f1a1179320556e Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Thu, 9 Mar 2023 15:33:37 +0000 Subject: [PATCH 20/96] OpenRgb - added segments --- .../Abstract/OpenRGBDeviceInfo.cs | 2 +- .../Generic/OpenRGBGenericDevice.cs | 12 ++-- .../Generic/OpenRGBUpdateQueue.cs | 21 ++++--- RGB.NET.Devices.OpenRGB/Helper.cs | 4 +- .../OpenRGBDeviceProvider.cs | 49 ++++++++++++----- .../PerZone/OpenRGBZoneDevice.cs | 11 ++-- .../RGB.NET.Devices.OpenRGB.csproj | 2 +- .../Segment/OpenRGBSegmentDevice.cs | 55 +++++++++++++++++++ 8 files changed, 115 insertions(+), 41 deletions(-) create mode 100644 RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs diff --git a/RGB.NET.Devices.OpenRGB/Abstract/OpenRGBDeviceInfo.cs b/RGB.NET.Devices.OpenRGB/Abstract/OpenRGBDeviceInfo.cs index 05afff3e..5d3cc1bb 100644 --- a/RGB.NET.Devices.OpenRGB/Abstract/OpenRGBDeviceInfo.cs +++ b/RGB.NET.Devices.OpenRGB/Abstract/OpenRGBDeviceInfo.cs @@ -1,5 +1,5 @@ using RGB.NET.Core; -using OpenRGBDevice = OpenRGB.NET.Models.Device; +using OpenRGBDevice = OpenRGB.NET.Device; namespace RGB.NET.Devices.OpenRGB; diff --git a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs index 8f19c5ae..618c3101 100644 --- a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs +++ b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs @@ -1,4 +1,4 @@ -using OpenRGB.NET.Enums; +using OpenRGB.NET; using RGB.NET.Core; namespace RGB.NET.Devices.OpenRGB; @@ -34,15 +34,15 @@ private void InitializeLayout() int zoneLedIndex = 0; const int LED_SPACING = 20; - foreach (global::OpenRGB.NET.Models.Zone? zone in DeviceInfo.OpenRGBDevice.Zones) + foreach (Zone? zone in DeviceInfo.OpenRGBDevice.Zones) { if (zone.Type == ZoneType.Matrix) { - for (int row = 0; row < zone.MatrixMap.Height; row++) + for (int row = 0; row < zone.MatrixMap!.Height; row++) { - for (int column = 0; column < zone.MatrixMap.Width; column++) + for (int column = 0; column < zone.MatrixMap!.Width; column++) { - uint index = zone.MatrixMap.Matrix[row, column]; + uint index = zone.MatrixMap!.Matrix[row, column]; //will be max value if the position does not have an associated key if (index == uint.MaxValue) @@ -59,7 +59,7 @@ private void InitializeLayout() ledId = initial++; } } - y += (int)(zone.MatrixMap.Height * LED_SPACING); + y += (int)(zone.MatrixMap!.Height * LED_SPACING); } else { diff --git a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs index fa79e6e9..ff4daa5f 100644 --- a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs +++ b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs @@ -2,8 +2,9 @@ using RGB.NET.Core; using System; using System.Linq; -using OpenRGBColor = OpenRGB.NET.Models.Color; -using OpenRGBDevice = OpenRGB.NET.Models.Device; +using Color = RGB.NET.Core.Color; +using OpenRGBColor = OpenRGB.NET.Color; +using OpenRGBDevice = OpenRGB.NET.Device; namespace RGB.NET.Devices.OpenRGB; @@ -15,10 +16,9 @@ public class OpenRGBUpdateQueue : UpdateQueue { #region Properties & Fields - private readonly int _deviceid; + private readonly int _deviceId; - private readonly OpenRGBClient _openRGB; - private readonly OpenRGBDevice _device; + private readonly OpenRgbClient _openRGB; private readonly OpenRGBColor[] _colors; #endregion @@ -29,17 +29,16 @@ public class OpenRGBUpdateQueue : UpdateQueue /// Initializes a new instance of the class. /// /// The update trigger used by this queue. - /// The index used to identify the device. + /// The index used to identify the device. /// The OpenRGB client used to send updates to the OpenRGB server. /// The OpenRGB Device containing device-specific information. - public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceid, OpenRGBClient client, OpenRGBDevice device) + public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId, OpenRgbClient client, OpenRGBDevice device) : base(updateTrigger) { - this._deviceid = deviceid; + this._deviceId = deviceId; this._openRGB = client; - this._device = device; - _colors = Enumerable.Range(0, _device.Colors.Length) + _colors = Enumerable.Range(0, device.Colors.Length) .Select(_ => new OpenRGBColor()) .ToArray(); } @@ -56,7 +55,7 @@ protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSe foreach ((object key, Color color) in dataSet) _colors[(int)key] = new OpenRGBColor(color.GetR(), color.GetG(), color.GetB()); - _openRGB.UpdateLeds(_deviceid, _colors); + _openRGB.UpdateLeds(_deviceId, _colors); return true; } diff --git a/RGB.NET.Devices.OpenRGB/Helper.cs b/RGB.NET.Devices.OpenRGB/Helper.cs index 639730e2..a79afffb 100644 --- a/RGB.NET.Devices.OpenRGB/Helper.cs +++ b/RGB.NET.Devices.OpenRGB/Helper.cs @@ -1,6 +1,6 @@ -using OpenRGB.NET.Enums; +using OpenRGB.NET; using RGB.NET.Core; -using OpenRGBDevice = OpenRGB.NET.Models.Device; +using OpenRGBDevice = OpenRGB.NET.Device; namespace RGB.NET.Devices.OpenRGB; diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs index 0f2b44b9..ccf41a3d 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs @@ -1,5 +1,4 @@ using OpenRGB.NET; -using OpenRGB.NET.Models; using RGB.NET.Core; using System; using System.Collections.Generic; @@ -15,7 +14,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields - private readonly List _clients = new(); + private readonly List _clients = new(); private static OpenRGBDeviceProvider? _instance; @@ -71,7 +70,7 @@ protected override void InitializeSDK() { try { - OpenRGBClient openRgb = new(ip: deviceDefinition.Ip, port: deviceDefinition.Port, name: deviceDefinition.ClientName, autoconnect: true); + OpenRgbClient openRgb = new(ip: deviceDefinition.Ip, port: deviceDefinition.Port, name: deviceDefinition.ClientName, autoConnect: true); _clients.Add(openRgb); deviceDefinition.Connected = true; } @@ -87,7 +86,7 @@ protected override void InitializeSDK() /// protected override IEnumerable LoadDevices() { - foreach (OpenRGBClient? openRgb in _clients) + foreach (OpenRgbClient? openRgb in _clients) { int deviceCount = openRgb.GetControllerCount(); @@ -99,7 +98,7 @@ protected override IEnumerable LoadDevices() if (directModeIndex != -1) { //set the device to direct mode if it has it - openRgb.SetMode(i, directModeIndex); + openRgb.UpdateMode(i, directModeIndex); } else if (!ForceAddAllDevices) { @@ -108,21 +107,43 @@ protected override IEnumerable LoadDevices() continue; } + if (device.Zones.Length == 0) + continue; + if (device.Zones.All(z => z.LedCount == 0)) + continue; + OpenRGBUpdateQueue? updateQueue = new(GetUpdateTrigger(), i, openRgb, device); + + bool anyZoneHasSegments = device.Zones.Any(z => z.Segments.Length > 0); + bool splitDeviceByZones = anyZoneHasSegments || PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type)); - if (PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type))) + if (!splitDeviceByZones) { - int totalLedCount = 0; + yield return new OpenRGBGenericDevice(new OpenRGBDeviceInfo(device), updateQueue); + continue; + } + + int totalLedCount = 0; - foreach (Zone zone in device.Zones) - if (zone.LedCount > 0) + foreach (Zone zone in device.Zones) + { + if (zone.LedCount <= 0) + continue; + + if (zone.Segments.Length <= 0) + { + yield return new OpenRGBZoneDevice(new OpenRGBDeviceInfo(device), totalLedCount, zone, updateQueue); + totalLedCount += (int)zone.LedCount; + } + else + { + foreach (Segment segment in zone.Segments) { - yield return new OpenRGBZoneDevice(new OpenRGBDeviceInfo(device), totalLedCount, zone, updateQueue); - totalLedCount += (int)zone.LedCount; + yield return new OpenRGBSegmentDevice(new OpenRGBDeviceInfo(device), totalLedCount, segment, updateQueue); + totalLedCount += (int)segment.LedCount; } + } } - else - yield return new OpenRGBGenericDevice(new OpenRGBDeviceInfo(device), updateQueue); } } } @@ -132,7 +153,7 @@ public override void Dispose() { base.Dispose(); - foreach (OpenRGBClient client in _clients) + foreach (OpenRgbClient client in _clients) { try { client.Dispose(); } catch { /* at least we tried */ } diff --git a/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs b/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs index 42ab4330..6def0927 100644 --- a/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs +++ b/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs @@ -1,5 +1,4 @@ -using OpenRGB.NET.Enums; -using OpenRGB.NET.Models; +using OpenRGB.NET; using RGB.NET.Core; namespace RGB.NET.Devices.OpenRGB; @@ -40,15 +39,15 @@ private void InitializeLayout() { Size ledSize = new(19); const int LED_SPACING = 20; - LedId initialId = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType) + _initialLed; + LedId initialId = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType); if (_zone.Type == ZoneType.Matrix) { - for (int row = 0; row < _zone.MatrixMap.Height; row++) + for (int row = 0; row < _zone.MatrixMap!.Height; row++) { - for (int column = 0; column < _zone.MatrixMap.Width; column++) + for (int column = 0; column < _zone.MatrixMap!.Width; column++) { - uint index = _zone.MatrixMap.Matrix[row, column]; + uint index = _zone.MatrixMap!.Matrix[row, column]; //will be max value if the position does not have an associated key if (index == uint.MaxValue) diff --git a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj index 9fd3eec9..9d4c0e86 100644 --- a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj +++ b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj @@ -57,7 +57,7 @@ - + diff --git a/RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs b/RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs new file mode 100644 index 00000000..9d8c6337 --- /dev/null +++ b/RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs @@ -0,0 +1,55 @@ +using OpenRGB.NET; +using RGB.NET.Core; + +namespace RGB.NET.Devices.OpenRGB; + +/// +public class OpenRGBSegmentDevice : AbstractOpenRGBDevice +{ + #region Properties & Fields + + private readonly int _initialLed; + private readonly Segment _segment; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The information provided by OpenRGB + /// The ledId of the first led in the device that belongs to this zone. + /// The Segment information provided by OpenRGB. + /// The queue used to update this zone. + public OpenRGBSegmentDevice(OpenRGBDeviceInfo info, int initialLed, Segment segment, IUpdateQueue updateQueue) + : base(info, updateQueue) + { + _initialLed = initialLed; + _segment = segment; + + InitializeLayout(); + } + + #endregion + + #region Methods + + private void InitializeLayout() + { + Size ledSize = new(19); + const int LED_SPACING = 20; + LedId initialId = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType); + + for (int i = 0; i < _segment.LedCount; i++) + { + LedId ledId = initialId++; + + // ReSharper disable once HeapView.BoxingAllocation + while (AddLed(ledId, new Point(LED_SPACING * i, 0), ledSize, _initialLed + i) == null) + ledId = initialId++; + } + } + + #endregion +} \ No newline at end of file From 5eb39b1a07d98175eb431ce54c3e66784730a371 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 14 Mar 2023 20:27:59 +0100 Subject: [PATCH 21/96] Added Pid for Razer BlackWidow V4 Fixes #305 --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index d967b363..f31174e5 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -107,6 +107,7 @@ public class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x025E, RGBDeviceType.Keyboard, "Cynosa V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0266, RGBDeviceType.Keyboard, "Huntsman V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x026C, RGBDeviceType.Keyboard, "Huntsman V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x028D, RGBDeviceType.Keyboard, "BlackWidow V4", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Mice { 0x0013, RGBDeviceType.Mouse, "Orochi 2011", LedMappings.Mouse, RazerEndpointType.Mouse }, From d054d16c100f5d099c38f79ce11f300edd37f26c Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 8 Apr 2023 00:53:15 +0200 Subject: [PATCH 22/96] Added reference counting to update queues to prevent premature disposes when used in multiple devices --- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 9 +++- .../Extensions/ReferenceCountingExtension.cs | 6 +++ .../Misc/AbstractReferenceCounting.cs | 41 +++++++++++++++++++ RGB.NET.Core/Misc/IReferenceCounting.cs | 21 ++++++++++ RGB.NET.Core/RGB.NET.Core.csproj.DotSettings | 1 + RGB.NET.Core/Update/Devices/IUpdateQueue.cs | 2 +- RGB.NET.Core/Update/Devices/UpdateQueue.cs | 8 +++- 7 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 RGB.NET.Core/Extensions/ReferenceCountingExtension.cs create mode 100644 RGB.NET.Core/Misc/AbstractReferenceCounting.cs create mode 100644 RGB.NET.Core/Misc/IReferenceCounting.cs diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index 6ac90da2..faaf1473 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -85,6 +85,8 @@ protected AbstractRGBDevice(TDeviceInfo deviceInfo, IUpdateQueue updateQueue) { this.DeviceInfo = deviceInfo; this.UpdateQueue = updateQueue; + + UpdateQueue.AddReferencingObject(this); } #endregion @@ -157,7 +159,12 @@ public virtual void Update(bool flushLeds = false) /// public virtual void Dispose() { - try { UpdateQueue.Dispose(); } catch { /* :( */ } + try + { + UpdateQueue.RemoveReferencingObject(this); + UpdateQueue.Dispose(); + } + catch { /* :( */ } try { LedMapping.Clear(); } catch { /* this really shouldn't happen */ } IdGenerator.ResetCounter(GetType().Assembly); diff --git a/RGB.NET.Core/Extensions/ReferenceCountingExtension.cs b/RGB.NET.Core/Extensions/ReferenceCountingExtension.cs new file mode 100644 index 00000000..58039eb3 --- /dev/null +++ b/RGB.NET.Core/Extensions/ReferenceCountingExtension.cs @@ -0,0 +1,6 @@ +namespace RGB.NET.Core; + +public static class ReferenceCountingExtension +{ + public static bool HasActiveReferences(this IReferenceCounting target) => target.ActiveReferenceCount > 0; +} \ No newline at end of file diff --git a/RGB.NET.Core/Misc/AbstractReferenceCounting.cs b/RGB.NET.Core/Misc/AbstractReferenceCounting.cs new file mode 100644 index 00000000..070138af --- /dev/null +++ b/RGB.NET.Core/Misc/AbstractReferenceCounting.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; + +namespace RGB.NET.Core; + +public abstract class AbstractReferenceCounting : IReferenceCounting +{ + #region Properties & Fields + + private readonly HashSet _referencingObjects = new(); + + /// + public int ActiveReferenceCount + { + get + { + lock (_referencingObjects) + return _referencingObjects.Count; + } + } + + #endregion + + #region Methods + + /// + public void AddReferencingObject(object obj) + { + lock (_referencingObjects) + if (!_referencingObjects.Contains(obj)) + _referencingObjects.Add(obj); + } + + /// + public void RemoveReferencingObject(object obj) + { + lock (_referencingObjects) + _referencingObjects.Remove(obj); + } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Core/Misc/IReferenceCounting.cs b/RGB.NET.Core/Misc/IReferenceCounting.cs new file mode 100644 index 00000000..d8bcb285 --- /dev/null +++ b/RGB.NET.Core/Misc/IReferenceCounting.cs @@ -0,0 +1,21 @@ +namespace RGB.NET.Core; + +public interface IReferenceCounting +{ + /// + /// Gets the amount of currently registered referencing objects. + /// + public int ActiveReferenceCount { get; } + + /// + /// Adds the given object to the list of referencing objects. + /// + /// The object to add. + public void AddReferencingObject(object obj); + + /// + /// Removes the given object from the list of referencing objects. + /// + /// The object to remove. + public void RemoveReferencingObject(object obj); +} \ No newline at end of file diff --git a/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings b/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings index bf7655f9..7f9a6e2a 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings +++ b/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings @@ -16,6 +16,7 @@ True True True + True True True True diff --git a/RGB.NET.Core/Update/Devices/IUpdateQueue.cs b/RGB.NET.Core/Update/Devices/IUpdateQueue.cs index 348c16eb..bf4011c7 100644 --- a/RGB.NET.Core/Update/Devices/IUpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/IUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Core; /// /// The identifier used to identify the data processed by this queue. /// The type of the data processed by this queue. -public interface IUpdateQueue : IDisposable +public interface IUpdateQueue : IReferenceCounting, IDisposable where TIdentifier : notnull { /// diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index 1cc5eca7..bdd08680 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Core; /// /// The type of the key used to identify some data. /// The type of the data. -public abstract class UpdateQueue : IUpdateQueue +public abstract class UpdateQueue : AbstractReferenceCounting, IUpdateQueue where TIdentifier : notnull { #region Properties & Fields @@ -112,8 +112,14 @@ public virtual void Reset() } /// + /// + /// Disposes this queue. + /// Checks if any referencing objects are registered and if so, will return without disposing! + /// public virtual void Dispose() { + if (this.HasActiveReferences()) return; + _updateTrigger.Starting -= OnStartup; _updateTrigger.Update -= OnUpdate; From 5b514ff9629d756c36c769bfa1055cbac0f8c079 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 8 Apr 2023 14:42:56 +0200 Subject: [PATCH 23/96] Moved reference check for UpdateQueue disposal to the caller to prevent issues with Dispose-overrides --- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 3 ++- RGB.NET.Core/Update/Devices/UpdateQueue.cs | 6 ------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index faaf1473..596625c6 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -162,7 +162,8 @@ public virtual void Dispose() try { UpdateQueue.RemoveReferencingObject(this); - UpdateQueue.Dispose(); + if (!UpdateQueue.HasActiveReferences()) + UpdateQueue.Dispose(); } catch { /* :( */ } try { LedMapping.Clear(); } catch { /* this really shouldn't happen */ } diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index bdd08680..72cec7e2 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -112,14 +112,8 @@ public virtual void Reset() } /// - /// - /// Disposes this queue. - /// Checks if any referencing objects are registered and if so, will return without disposing! - /// public virtual void Dispose() { - if (this.HasActiveReferences()) return; - _updateTrigger.Starting -= OnStartup; _updateTrigger.Update -= OnUpdate; From 818678fdf228a8dc08d9fc03092557ef189ddc09 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 8 Apr 2023 21:10:12 +0200 Subject: [PATCH 24/96] Added PID for Razer Ornata V3 fixes #309 --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index f31174e5..04edecc8 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -108,6 +108,7 @@ public class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0266, RGBDeviceType.Keyboard, "Huntsman V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x026C, RGBDeviceType.Keyboard, "Huntsman V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028D, RGBDeviceType.Keyboard, "BlackWidow V4", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Mice { 0x0013, RGBDeviceType.Mouse, "Orochi 2011", LedMappings.Mouse, RazerEndpointType.Mouse }, From 10183fb27014792062c0dfb10ffb9cc7b96064be Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 9 Apr 2023 16:36:27 +0200 Subject: [PATCH 25/96] Added dispose-check to corsairs update queue --- RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs index fa743e8d..8bea2eb6 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs @@ -13,6 +13,8 @@ public class CorsairDeviceUpdateQueue : UpdateQueue { #region Properties & Fields + private bool _isDisposed = false; + private readonly _CorsairDeviceInfo _device; private readonly nint _colorPtr; @@ -42,6 +44,7 @@ protected override unsafe bool Update(in ReadOnlySpan<(object key, Color color)> { try { + if (_isDisposed) throw new ObjectDisposedException(nameof(CorsairDeviceUpdateQueue)); if (!_CUESDK.IsConnected) return false; Span<_CorsairLedColor> colors = new((void*)_colorPtr, dataSet.Length); @@ -71,6 +74,7 @@ public override void Dispose() { base.Dispose(); + _isDisposed = true; Marshal.FreeHGlobal(_colorPtr); GC.SuppressFinalize(this); From aaabbc6a8df897e6df43544d1ee4b21fe332c8b9 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 11 Apr 2023 00:06:17 +0200 Subject: [PATCH 26/96] (MAJOR): Removed support for .NET 5; Updated nugets; Removed the not even working distribution of the Asus-SDK from the project; Fixed a warning in the OpenRGBServerDefinition --- RGB.NET.Core/RGB.NET.Core.csproj | 2 +- .../RGB.NET.Devices.Asus.csproj | 18 ++---------------- .../RGB.NET.Devices.CoolerMaster.csproj | 2 +- .../RGB.NET.Devices.Corsair.csproj | 2 +- RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj | 2 +- .../RGB.NET.Devices.Debug.csproj | 2 +- .../RGB.NET.Devices.Logitech.csproj | 2 +- RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj | 2 +- .../RGB.NET.Devices.Novation.csproj | 2 +- .../OpenRGBServerDefinition.cs | 4 ++-- .../RGB.NET.Devices.OpenRGB.csproj | 2 +- .../RGB.NET.Devices.PicoPi.csproj | 2 +- .../RGB.NET.Devices.Razer.csproj | 2 +- .../RGB.NET.Devices.SteelSeries.csproj | 2 +- .../RGB.NET.Devices.WS281X.csproj | 4 ++-- .../RGB.NET.Devices.Wooting.csproj | 2 +- RGB.NET.HID/RGB.NET.HID.csproj | 2 +- RGB.NET.Layout/RGB.NET.Layout.csproj | 2 +- RGB.NET.Presets/RGB.NET.Presets.csproj | 2 +- .../RGB.NET.Core.Tests.csproj | 6 +++--- .../RGB.NET.Presets.Tests.csproj | 6 +++--- 21 files changed, 28 insertions(+), 42 deletions(-) diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj index 63573888..ee87698f 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj +++ b/RGB.NET.Core/RGB.NET.Core.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj index b4ac280b..f7a9c4b3 100644 --- a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj +++ b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable @@ -57,21 +57,7 @@ - - - - - <_PackageFiles Include="$(OutputPath)\net6.0\Interop.AuraServiceLib.dll"> - None - lib\net6.0\ - - - - - <_PackageFiles Include="$(OutputPath)\net5.0\Interop.AuraServiceLib.dll"> - None - lib\net5.0\ - + diff --git a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj index d4812ed2..fad9d754 100644 --- a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj +++ b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj index 302d93df..13b8ead7 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj index d291aa09..6ddf0ea5 100644 --- a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj +++ b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj index f4edaaed..b2d53675 100644 --- a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj +++ b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj index 7ee22dd4..7b57ee4a 100644 --- a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj +++ b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj index c565c945..0d9a6474 100644 --- a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj +++ b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj index 12a79191..19a14648 100644 --- a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj +++ b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBServerDefinition.cs b/RGB.NET.Devices.OpenRGB/OpenRGBServerDefinition.cs index 860b6bc3..9de92463 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBServerDefinition.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBServerDefinition.cs @@ -8,12 +8,12 @@ public class OpenRGBServerDefinition /// /// The name of the client that will appear in the OpenRGB interface. /// - public string? ClientName { get; set; } = "RGB.NET"; + public string ClientName { get; set; } = "RGB.NET"; /// /// The ip address of the server. /// - public string? Ip { get; set; } = "127.0.0.1"; + public string Ip { get; set; } = "127.0.0.1"; /// /// The port of the server. diff --git a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj index 9d4c0e86..64744945 100644 --- a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj +++ b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj @@ -1,6 +1,6 @@ - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj b/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj index db64c4a1..d75e4791 100644 --- a/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj +++ b/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj index 32fcbe04..886ad44d 100644 --- a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj +++ b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj index d8b2ab6b..487711be 100644 --- a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj +++ b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj index 0e0e08f4..82435e53 100644 --- a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj +++ b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable @@ -57,7 +57,7 @@ - + diff --git a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj index ac158f03..532c5900 100644 --- a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj +++ b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.HID/RGB.NET.HID.csproj b/RGB.NET.HID/RGB.NET.HID.csproj index 54694389..2021184e 100644 --- a/RGB.NET.HID/RGB.NET.HID.csproj +++ b/RGB.NET.HID/RGB.NET.HID.csproj @@ -1,6 +1,6 @@ - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Layout/RGB.NET.Layout.csproj b/RGB.NET.Layout/RGB.NET.Layout.csproj index f6330ede..582fb71c 100644 --- a/RGB.NET.Layout/RGB.NET.Layout.csproj +++ b/RGB.NET.Layout/RGB.NET.Layout.csproj @@ -1,6 +1,6 @@ - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/RGB.NET.Presets/RGB.NET.Presets.csproj b/RGB.NET.Presets/RGB.NET.Presets.csproj index fc2d052c..f4da69c5 100644 --- a/RGB.NET.Presets/RGB.NET.Presets.csproj +++ b/RGB.NET.Presets/RGB.NET.Presets.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0;net5.0 + net7.0;net6.0 latest enable diff --git a/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj b/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj index 0279d53f..7e98ef54 100644 --- a/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj +++ b/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj @@ -7,9 +7,9 @@ - - - + + + diff --git a/Tests/RGB.NET.Presets.Tests/RGB.NET.Presets.Tests.csproj b/Tests/RGB.NET.Presets.Tests/RGB.NET.Presets.Tests.csproj index 57777390..ca572305 100644 --- a/Tests/RGB.NET.Presets.Tests/RGB.NET.Presets.Tests.csproj +++ b/Tests/RGB.NET.Presets.Tests/RGB.NET.Presets.Tests.csproj @@ -7,9 +7,9 @@ - - - + + + From 02235a3f7f3a10dd5be277ce085f971ea134e3cf Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 11 Apr 2023 00:15:27 +0200 Subject: [PATCH 27/96] Fixed some code-issues --- RGB.NET.Core/RGB.NET.Core.csproj | 4 ++-- RGB.NET.Devices.Asus/Helper/WMIHelper.cs | 6 +++--- .../RGB.NET.Devices.CoolerMaster.csproj | 4 ++-- RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs | 4 +++- RGB.NET.Devices.Corsair/Generic/LedMappings.cs | 1 + RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj | 4 ++-- RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj | 4 ++-- RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj | 4 ++-- RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj | 4 ++-- RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj | 4 ++-- RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj | 4 ++-- RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs | 4 ++-- RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj | 4 ++-- .../RGB.NET.Devices.OpenRGB.csproj.DotSettings | 3 ++- RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj | 4 ++-- RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj | 4 ++-- .../RGB.NET.Devices.SteelSeries.csproj | 4 ++-- RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj | 4 ++-- RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj | 4 ++-- RGB.NET.Devices.Wooting/WootingDeviceProvider.cs | 1 + RGB.NET.HID/RGB.NET.HID.csproj | 4 ++-- RGB.NET.Layout/RGB.NET.Layout.csproj | 4 ++-- RGB.NET.Presets/RGB.NET.Presets.csproj | 4 ++-- 23 files changed, 46 insertions(+), 41 deletions(-) diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj index ee87698f..8499b1ea 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj +++ b/RGB.NET.Core/RGB.NET.Core.csproj @@ -41,7 +41,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -49,7 +49,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.Asus/Helper/WMIHelper.cs b/RGB.NET.Devices.Asus/Helper/WMIHelper.cs index 5aa49c75..482f3a3c 100644 --- a/RGB.NET.Devices.Asus/Helper/WMIHelper.cs +++ b/RGB.NET.Devices.Asus/Helper/WMIHelper.cs @@ -43,7 +43,7 @@ static WMIHelper() if ((_systemModelInfo == null) && (_systemModelSearcher != null)) foreach (ManagementBaseObject managementBaseObject in _systemModelSearcher.Get()) { - _systemModelInfo = managementBaseObject["Model"]?.ToString(); + _systemModelInfo = managementBaseObject["Model"].ToString(); break; } @@ -57,7 +57,7 @@ internal static (string manufacturer, string model)? GetMainboardInfo() if (!_mainboardInfo.HasValue && (_mainboardSearcher != null)) foreach (ManagementBaseObject managementBaseObject in _mainboardSearcher.Get()) { - _mainboardInfo = (managementBaseObject["Manufacturer"]?.ToString() ?? string.Empty, managementBaseObject["Product"]?.ToString() ?? string.Empty); + _mainboardInfo = (managementBaseObject["Manufacturer"].ToString() ?? string.Empty, managementBaseObject["Product"].ToString() ?? string.Empty); break; } @@ -71,7 +71,7 @@ internal static (string manufacturer, string model)? GetMainboardInfo() if ((_graphicsCardInfo == null) && (_graphicsCardSearcher != null)) foreach (ManagementBaseObject managementBaseObject in _graphicsCardSearcher.Get()) { - _graphicsCardInfo = managementBaseObject["Name"]?.ToString(); + _graphicsCardInfo = managementBaseObject["Name"].ToString(); break; } diff --git a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj index fad9d754..2adfaa53 100644 --- a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj +++ b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs b/RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs index 72813238..3ec299da 100644 --- a/RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs +++ b/RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs @@ -1,4 +1,6 @@ -namespace RGB.NET.Devices.Corsair; +// ReSharper disable InconsistentNaming + +namespace RGB.NET.Devices.Corsair; /// /// iCUE-SDK: contains a list of led groups. Led group is used as a part of led identifier diff --git a/RGB.NET.Devices.Corsair/Generic/LedMappings.cs b/RGB.NET.Devices.Corsair/Generic/LedMappings.cs index 81660705..ffbfa0ff 100644 --- a/RGB.NET.Devices.Corsair/Generic/LedMappings.cs +++ b/RGB.NET.Devices.Corsair/Generic/LedMappings.cs @@ -11,6 +11,7 @@ internal static class LedMappings { #region Constants + // ReSharper disable once InconsistentNaming private static LedMapping KEYBOARD_MAPPING => new() { { LedId.Invalid, new CorsairLedId(CorsairLedGroup.Keyboard, CorsairLedIdKeyboard.Invalid) }, diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj index 13b8ead7..ccb143e7 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj @@ -41,7 +41,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -49,7 +49,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj index 6ddf0ea5..e6e876ee 100644 --- a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj +++ b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj index b2d53675..980153ce 100644 --- a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj +++ b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj index 7b57ee4a..fd412e77 100644 --- a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj +++ b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj @@ -41,7 +41,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -49,7 +49,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj index 0d9a6474..7d604a67 100644 --- a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj +++ b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj index 19a14648..cda9c5e4 100644 --- a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj +++ b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs index ccf41a3d..c9d3cbc4 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs @@ -92,7 +92,7 @@ protected override IEnumerable LoadDevices() for (int i = 0; i < deviceCount; i++) { - Device? device = openRgb.GetControllerData(i); + Device device = openRgb.GetControllerData(i); int directModeIndex = Array.FindIndex(device.Modes, d => d.Name == "Direct"); if (directModeIndex != -1) @@ -112,7 +112,7 @@ protected override IEnumerable LoadDevices() if (device.Zones.All(z => z.LedCount == 0)) continue; - OpenRGBUpdateQueue? updateQueue = new(GetUpdateTrigger(), i, openRgb, device); + OpenRGBUpdateQueue updateQueue = new(GetUpdateTrigger(), i, openRgb, device); bool anyZoneHasSegments = device.Zones.Any(z => z.Segments.Length > 0); bool splitDeviceByZones = anyZoneHasSegments || PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type)); diff --git a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj index 64744945..94ce6047 100644 --- a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj +++ b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj.DotSettings b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj.DotSettings index f79e29d7..7e8e95fd 100644 --- a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj.DotSettings +++ b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj.DotSettings @@ -1,4 +1,5 @@  True True - True \ No newline at end of file + True + True \ No newline at end of file diff --git a/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj b/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj index d75e4791..6cf8a2c9 100644 --- a/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj +++ b/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj index 886ad44d..27f72612 100644 --- a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj +++ b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj @@ -41,7 +41,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -49,7 +49,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj index 487711be..f75e2d85 100644 --- a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj +++ b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj index 82435e53..5487a8e6 100644 --- a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj +++ b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj index 532c5900..8a34dcde 100644 --- a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj +++ b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj @@ -41,7 +41,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -49,7 +49,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index c920ebb5..aebe9c05 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -44,6 +44,7 @@ public class WootingDeviceProvider : AbstractRGBDeviceProvider /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 MacOS applications. /// The first match will be used. /// + // ReSharper disable once InconsistentNaming public static List PossibleNativePathsMacOS { get; } = new() { "x64/libwooting-rgb-sdk.dylib" }; #endregion diff --git a/RGB.NET.HID/RGB.NET.HID.csproj b/RGB.NET.HID/RGB.NET.HID.csproj index 2021184e..7bf502b1 100644 --- a/RGB.NET.HID/RGB.NET.HID.csproj +++ b/RGB.NET.HID/RGB.NET.HID.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Layout/RGB.NET.Layout.csproj b/RGB.NET.Layout/RGB.NET.Layout.csproj index 582fb71c..3c901858 100644 --- a/RGB.NET.Layout/RGB.NET.Layout.csproj +++ b/RGB.NET.Layout/RGB.NET.Layout.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Presets/RGB.NET.Presets.csproj b/RGB.NET.Presets/RGB.NET.Presets.csproj index f4da69c5..048087ae 100644 --- a/RGB.NET.Presets/RGB.NET.Presets.csproj +++ b/RGB.NET.Presets/RGB.NET.Presets.csproj @@ -41,7 +41,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -49,7 +49,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE From 82050b8d5a85feaca675cc67837a386cbaa9ca78 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 11 Apr 2023 00:26:46 +0200 Subject: [PATCH 28/96] Fixed some code issues --- RGB.NET.Core/Ids/IdGenerator.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RGB.NET.Core/Ids/IdGenerator.cs b/RGB.NET.Core/Ids/IdGenerator.cs index 99beaa68..c6270e7c 100644 --- a/RGB.NET.Core/Ids/IdGenerator.cs +++ b/RGB.NET.Core/Ids/IdGenerator.cs @@ -50,8 +50,7 @@ internal static string MakeUnique(Assembly callingAssembly, string id) idMapping.Add(id, mappedId); } - if (!counterMapping.ContainsKey(mappedId)) - counterMapping.Add(mappedId, 0); + counterMapping.TryAdd(mappedId, 0); int counter = ++counterMapping[mappedId]; return counter <= 1 ? mappedId : $"{mappedId} ({counter})"; From 4216dacf4fb37f912278c0afa8ce16a311eeae4f Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 11 Apr 2023 00:29:01 +0200 Subject: [PATCH 29/96] Removed unnecessary contains check in AbstractReferenceCounting --- RGB.NET.Core/Misc/AbstractReferenceCounting.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RGB.NET.Core/Misc/AbstractReferenceCounting.cs b/RGB.NET.Core/Misc/AbstractReferenceCounting.cs index 070138af..09d64ef4 100644 --- a/RGB.NET.Core/Misc/AbstractReferenceCounting.cs +++ b/RGB.NET.Core/Misc/AbstractReferenceCounting.cs @@ -26,8 +26,7 @@ public int ActiveReferenceCount public void AddReferencingObject(object obj) { lock (_referencingObjects) - if (!_referencingObjects.Contains(obj)) - _referencingObjects.Add(obj); + _referencingObjects.Add(obj); } /// From 764fcd1b1dc309a3ef9accfb613177912bec8137 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 12 Apr 2023 22:25:24 +0200 Subject: [PATCH 30/96] (MAJOR) Improved update performance of devices --- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 55 +++++++++---------- RGB.NET.Core/Update/Devices/IUpdateQueue.cs | 3 +- RGB.NET.Core/Update/Devices/UpdateQueue.cs | 6 +- .../PerDevice/LogitechPerDeviceRGBDevice.cs | 7 +-- .../PerKey/LogitechPerKeyRGBDevice.cs | 8 +-- .../Zone/LogitechZoneRGBDevice.cs | 6 +- .../Generic/NovationRGBDevice.cs | 4 -- .../Generic/RazerRGBDevice.cs | 6 +- .../Generic/SteelSeriesRGBDevice.cs | 6 +- .../Arduino/ArduinoWS2812USBDevice.cs | 5 +- .../Bitwizard/BitwizardWS2812USBDevice.cs | 6 +- .../NodeMCU/NodeMCUWS2812USBDevice.cs | 5 +- .../Keyboard/WootingKeyboardRGBDevice.cs | 3 - 13 files changed, 38 insertions(+), 82 deletions(-) diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index 596625c6..fc18794a 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -3,6 +3,7 @@ // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -100,12 +101,7 @@ public virtual void Update(bool flushLeds = false) DeviceUpdate(); // Send LEDs to SDK - List ledsToUpdate = GetLedsToUpdate(flushLeds).ToList(); - - foreach (Led led in ledsToUpdate) - led.Update(); - - UpdateLeds(ledsToUpdate); + UpdateLeds(GetLedsToUpdate(flushLeds)); } /// @@ -124,37 +120,38 @@ public virtual void Update(bool flushLeds = false) /// /// The enumerable of leds to convert. /// The enumerable of custom data and color tuples for the specified leds. - protected virtual IEnumerable<(object key, Color color)> GetUpdateData(IEnumerable leds) + protected (object key, Color color) GetUpdateData(Led led) { - if (ColorCorrections.Count > 0) - { - foreach (Led led in leds) - { - Color color = led.Color; - object key = led.CustomData ?? led.Id; + Color color = led.Color; + object key = led.CustomData ?? led.Id; - foreach (IColorCorrection colorCorrection in ColorCorrections) - colorCorrection.ApplyTo(ref color); + // ReSharper disable once ForCanBeConvertedToForeach - This causes an allocation that's not really needed here + for (int i = 0; i < ColorCorrections.Count; i++) + ColorCorrections[i].ApplyTo(ref color); - yield return (key, color); - } - } - else - { - foreach (Led led in leds) - { - Color color = led.Color; - object key = led.CustomData ?? led.Id; - - yield return (key, color); - } - } + return (key, color); } /// /// Sends all the updated to the device. /// - protected virtual void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); + protected virtual void UpdateLeds(IEnumerable ledsToUpdate) + { + (object key, Color color)[] buffer = ArrayPool<(object, Color)>.Shared.Rent(LedMapping.Count); + + int counter = 0; + foreach (Led led in ledsToUpdate) + { + led.Update(); + + buffer[counter] = GetUpdateData(led); + ++counter; + } + + UpdateQueue.SetData(new ReadOnlySpan<(object, Color)>(buffer)[..counter]); + + ArrayPool<(object, Color)>.Shared.Return(buffer); + } /// public virtual void Dispose() diff --git a/RGB.NET.Core/Update/Devices/IUpdateQueue.cs b/RGB.NET.Core/Update/Devices/IUpdateQueue.cs index bf4011c7..29433790 100644 --- a/RGB.NET.Core/Update/Devices/IUpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/IUpdateQueue.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; namespace RGB.NET.Core; @@ -21,7 +20,7 @@ public interface IUpdateQueue : IReferenceCounting, IDisposa /// /// The set of data. // ReSharper disable once MemberCanBeProtected.Global - void SetData(IEnumerable<(TIdentifier, TData)> dataSet); + void SetData(ReadOnlySpan<(TIdentifier, TData)> dataSet); /// /// Resets the current data set. diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index 72cec7e2..c17e3a9f 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -1,7 +1,6 @@ using System; using System.Buffers; using System.Collections.Generic; -using System.Linq; namespace RGB.NET.Core; @@ -88,10 +87,9 @@ protected virtual void OnStartup(object? sender, CustomUpdateData customData) { /// /// The set of data. // ReSharper disable once MemberCanBeProtected.Global - public virtual void SetData(IEnumerable<(TIdentifier, TData)> dataSet) + public virtual void SetData(ReadOnlySpan<(TIdentifier, TData)> data) { - IList<(TIdentifier, TData)> data = dataSet.ToList(); - if (data.Count == 0) return; + if (data.Length == 0) return; lock (_dataLock) { diff --git a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs index 9fdbc79b..7727006e 100644 --- a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Linq; -using RGB.NET.Core; +using RGB.NET.Core; namespace RGB.NET.Devices.Logitech; @@ -42,8 +40,5 @@ private void InitializeLayout() /// protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId]; - /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate.Take(1))); - #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs index 933603ff..715079e3 100644 --- a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using RGB.NET.Core; +using RGB.NET.Core; namespace RGB.NET.Devices.Logitech; @@ -33,9 +32,6 @@ internal LogitechPerKeyRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue update /// protected override object GetLedCustomData(LedId ledId) => _ledMapping.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : -1; - - /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); - + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs b/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs index 88208349..4909dcc6 100644 --- a/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using RGB.NET.Core; +using RGB.NET.Core; namespace RGB.NET.Devices.Logitech; @@ -41,8 +40,5 @@ private void InitializeLayout() /// protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId]; - /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); - #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs index b64c72a6..7a8f2ebf 100644 --- a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs +++ b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using RGB.NET.Core; namespace RGB.NET.Devices.Novation; @@ -34,9 +33,6 @@ private static UpdateQueue GetUpdateQueue(IDeviceUpdateTrigger updateTrigger, TD _ => throw new ArgumentOutOfRangeException() }; - /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); - /// /// Resets the back to default. /// diff --git a/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs b/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs index 1a365955..c468948a 100644 --- a/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using RGB.NET.Core; namespace RGB.NET.Devices.Razer; @@ -27,10 +26,7 @@ protected RazerRGBDevice(RazerRGBDeviceInfo info, IUpdateQueue updateQueue) #endregion #region Methods - - /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); - + /// public override void Dispose() { diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs index debe441c..f85213bf 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using RGB.NET.Core; +using RGB.NET.Core; namespace RGB.NET.Devices.SteelSeries; @@ -43,8 +42,5 @@ private void InitializeLayout() /// protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId]; - /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); - #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs index 8d3d2909..4f2bf090 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs @@ -53,9 +53,6 @@ private void InitializeLayout(int ledCount) /// protected override IEnumerable GetLedsToUpdate(bool flushLeds) => (flushLeds || LedMapping.Values.Any(x => x.IsDirty)) ? LedMapping.Values : Enumerable.Empty(); - - /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); - + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs index a1021262..1dc38cd7 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs @@ -1,7 +1,6 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global -using System.Collections.Generic; using RGB.NET.Core; namespace RGB.NET.Devices.WS281X.Bitwizard; @@ -47,9 +46,6 @@ private void InitializeLayout(int ledCount) /// protected override object GetLedCustomData(LedId ledId) => _ledOffset + ((int)ledId - (int)LedId.LedStripe1); - - /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); - + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs index d1a5b980..8c55f6b0 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs @@ -55,9 +55,6 @@ private void InitializeLayout(int ledCount) /// protected override IEnumerable GetLedsToUpdate(bool flushLeds) => (flushLeds || LedMapping.Values.Any(x => x.IsDirty)) ? LedMapping.Values : Enumerable.Empty(); - - /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); - + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs index eb0cc753..0f5882ca 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs @@ -47,9 +47,6 @@ private void InitializeLayout() /// protected override object GetLedCustomData(LedId ledId) => WootingKeyboardLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId]; - /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); - public override void Dispose() { _WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex); From 0cf4f39ccf8e4d46a2b1aa09c87ece8495919c57 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 13 Apr 2023 00:21:20 +0200 Subject: [PATCH 31/96] Reduced allocations when a ListLedGroup is used --- RGB.NET.Core/Groups/AbstractLedGroup.cs | 12 +++++++- RGB.NET.Core/Groups/ILedGroup.cs | 3 ++ RGB.NET.Core/Groups/ListLedGroup.cs | 9 ++++++ RGB.NET.Core/Misc/ActionDisposable.cs | 27 ++++++++++++++++++ RGB.NET.Core/RGBSurface.cs | 38 +++++++++++++------------ 5 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 RGB.NET.Core/Misc/ActionDisposable.cs diff --git a/RGB.NET.Core/Groups/AbstractLedGroup.cs b/RGB.NET.Core/Groups/AbstractLedGroup.cs index 86659afe..7135a21e 100644 --- a/RGB.NET.Core/Groups/AbstractLedGroup.cs +++ b/RGB.NET.Core/Groups/AbstractLedGroup.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using System.Linq; @@ -61,5 +62,14 @@ public virtual void OnDetach() { } /// public IEnumerator GetEnumerator() => GetLeds().GetEnumerator(); + /// + IDisposable? ILedGroup.ToListUnsafe(out IList leds) => ToListUnsafe(out leds); + + protected virtual IDisposable? ToListUnsafe(out IList leds) + { + leds = ToList(); + return null; + } + #endregion } \ No newline at end of file diff --git a/RGB.NET.Core/Groups/ILedGroup.cs b/RGB.NET.Core/Groups/ILedGroup.cs index 97ed8b2a..1970afc2 100644 --- a/RGB.NET.Core/Groups/ILedGroup.cs +++ b/RGB.NET.Core/Groups/ILedGroup.cs @@ -1,6 +1,7 @@ // ReSharper disable UnusedMemberInSuper.Global // ReSharper disable UnusedMember.Global +using System; using System.Collections.Generic; namespace RGB.NET.Core; @@ -45,4 +46,6 @@ public interface ILedGroup : IDecoratable, IEnumerable /// /// A list containing all in this group. IList ToList(); + + internal IDisposable? ToListUnsafe(out IList leds); } \ No newline at end of file diff --git a/RGB.NET.Core/Groups/ListLedGroup.cs b/RGB.NET.Core/Groups/ListLedGroup.cs index 9c519061..c6f7d543 100644 --- a/RGB.NET.Core/Groups/ListLedGroup.cs +++ b/RGB.NET.Core/Groups/ListLedGroup.cs @@ -1,7 +1,9 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global +using System; using System.Collections.Generic; +using System.Threading; namespace RGB.NET.Core; @@ -135,5 +137,12 @@ public override IList ToList() return new List(GroupLeds); } + protected override IDisposable ToListUnsafe(out IList leds) + { + Monitor.Enter(GroupLeds); + leds = GroupLeds; + return new ActionDisposable(() => Monitor.Exit(GroupLeds)); + } + #endregion } \ No newline at end of file diff --git a/RGB.NET.Core/Misc/ActionDisposable.cs b/RGB.NET.Core/Misc/ActionDisposable.cs new file mode 100644 index 00000000..843605e0 --- /dev/null +++ b/RGB.NET.Core/Misc/ActionDisposable.cs @@ -0,0 +1,27 @@ +using System; + +namespace RGB.NET.Core; + +public sealed class ActionDisposable : IDisposable +{ + #region Properties & Fields + + private readonly Action _onDispose; + + #endregion + + #region Constructors + + public ActionDisposable(Action onDispose) + { + this._onDispose = onDispose; + } + + #endregion + + #region Methods + + public void Dispose() => _onDispose(); + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index fc8003f3..5e022edb 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -208,26 +208,28 @@ private void Render(ILedGroup ledGroup) if ((brush == null) || !brush.IsEnabled) return; - IList leds = ledGroup.ToList(); - - IEnumerable<(RenderTarget renderTarget, Color color)> render; - switch (brush.CalculationMode) + using (ledGroup.ToListUnsafe(out IList leds)) { - case RenderMode.Relative: - Rectangle brushRectangle = new(leds); - Point offset = new(-brushRectangle.Location.X, -brushRectangle.Location.Y); - brushRectangle = brushRectangle.SetLocation(new Point(0, 0)); - render = brush.Render(brushRectangle, leds.Select(led => new RenderTarget(led, led.AbsoluteBoundary.Translate(offset)))); - break; - case RenderMode.Absolute: - render = brush.Render(Boundary, leds.Select(led => new RenderTarget(led, led.AbsoluteBoundary))); - break; - default: - throw new ArgumentException($"The CalculationMode '{brush.CalculationMode}' is not valid."); + IEnumerable<(RenderTarget renderTarget, Color color)> render; + switch (brush.CalculationMode) + { + case RenderMode.Relative: + Rectangle brushRectangle = new(leds); + Point offset = new(-brushRectangle.Location.X, -brushRectangle.Location.Y); + brushRectangle = brushRectangle.SetLocation(new Point(0, 0)); + render = brush.Render(brushRectangle, + leds.Select(led => new RenderTarget(led, led.AbsoluteBoundary.Translate(offset)))); + break; + case RenderMode.Absolute: + render = brush.Render(Boundary, leds.Select(led => new RenderTarget(led, led.AbsoluteBoundary))); + break; + default: + throw new ArgumentException($"The CalculationMode '{brush.CalculationMode}' is not valid."); + } + + foreach ((RenderTarget renderTarget, Color c) in render) + renderTarget.Led.Color = c; } - - foreach ((RenderTarget renderTarget, Color c) in render) - renderTarget.Led.Color = c; } /// From 70ccc4d5754ec86989e8cb3b83905f302f5740b2 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 13 Apr 2023 00:49:29 +0200 Subject: [PATCH 32/96] Reduced some more allocations --- RGB.NET.Core/Groups/ListLedGroup.cs | 14 ++++++++++++-- RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs | 4 +++- RGB.NET.Core/Update/ManualUpdateTrigger.cs | 6 +++--- RGB.NET.Core/Update/TimerUpdateTrigger.cs | 5 +++-- RGB.NET.Presets/Groups/RectangleLedGroup.cs | 3 ++- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/RGB.NET.Core/Groups/ListLedGroup.cs b/RGB.NET.Core/Groups/ListLedGroup.cs index c6f7d543..a97b6ecc 100644 --- a/RGB.NET.Core/Groups/ListLedGroup.cs +++ b/RGB.NET.Core/Groups/ListLedGroup.cs @@ -15,6 +15,8 @@ public class ListLedGroup : AbstractLedGroup { #region Properties & Fields + private readonly ActionDisposable _unlockDisposable; + /// /// Gets the list containing the of this . /// @@ -31,7 +33,9 @@ public class ListLedGroup : AbstractLedGroup /// Specifies the surface to attach this group to or null if the group should not be attached on creation. public ListLedGroup(RGBSurface? surface) : base(surface) - { } + { + _unlockDisposable = new ActionDisposable(Unlock); + } /// /// @@ -42,6 +46,8 @@ public ListLedGroup(RGBSurface? surface) public ListLedGroup(RGBSurface? surface, IEnumerable leds) : base(surface) { + _unlockDisposable = new ActionDisposable(Unlock); + AddLeds(leds); } @@ -54,6 +60,8 @@ public ListLedGroup(RGBSurface? surface, IEnumerable leds) public ListLedGroup(RGBSurface? surface, params Led[] leds) : base(surface) { + _unlockDisposable = new ActionDisposable(Unlock); + AddLeds(leds); } @@ -141,8 +149,10 @@ protected override IDisposable ToListUnsafe(out IList leds) { Monitor.Enter(GroupLeds); leds = GroupLeds; - return new ActionDisposable(() => Monitor.Exit(GroupLeds)); + return _unlockDisposable; } + private void Unlock() => Monitor.Exit(GroupLeds); + #endregion } \ No newline at end of file diff --git a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs index db22aa4f..00abcc79 100644 --- a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs +++ b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs @@ -157,11 +157,13 @@ protected virtual void UpdateLoop() using (TimerHelper.RequestHighResolutionTimer()) while (!UpdateToken.IsCancellationRequested) if (HasDataEvent.WaitOne(Timeout)) - LastUpdateTime = TimerHelper.Execute(() => OnUpdate(), UpdateFrequency * 1000); + LastUpdateTime = TimerHelper.Execute(TimerExecute, UpdateFrequency * 1000); else if ((HeartbeatTimer > 0) && (LastUpdateTimestamp > 0) && (TimerHelper.GetElapsedTime(LastUpdateTimestamp) > HeartbeatTimer)) OnUpdate(new CustomUpdateData().Heartbeat()); } + private void TimerExecute() => OnUpdate(); + protected override void OnUpdate(CustomUpdateData? updateData = null) { base.OnUpdate(updateData); diff --git a/RGB.NET.Core/Update/ManualUpdateTrigger.cs b/RGB.NET.Core/Update/ManualUpdateTrigger.cs index 67e8ca4c..5cd42351 100644 --- a/RGB.NET.Core/Update/ManualUpdateTrigger.cs +++ b/RGB.NET.Core/Update/ManualUpdateTrigger.cs @@ -83,12 +83,12 @@ private void UpdateLoop() OnStartup(); while (!UpdateToken.IsCancellationRequested) - { if (_mutex.WaitOne(100)) - LastUpdateTime = TimerHelper.Execute(() => OnUpdate(_customUpdateData)); - } + LastUpdateTime = TimerHelper.Execute(TimerExecute); } + private void TimerExecute() => OnUpdate(_customUpdateData); + /// public override void Dispose() => Stop(); diff --git a/RGB.NET.Core/Update/TimerUpdateTrigger.cs b/RGB.NET.Core/Update/TimerUpdateTrigger.cs index 14a7e9ff..9f2b2b60 100644 --- a/RGB.NET.Core/Update/TimerUpdateTrigger.cs +++ b/RGB.NET.Core/Update/TimerUpdateTrigger.cs @@ -131,10 +131,11 @@ private void UpdateLoop() using (TimerHelper.RequestHighResolutionTimer()) while (!UpdateToken.IsCancellationRequested) - LastUpdateTime = TimerHelper.Execute(() => OnUpdate(_customUpdateData), UpdateFrequency * 1000); - + LastUpdateTime = TimerHelper.Execute(TimerExecute, UpdateFrequency * 1000); } + private void TimerExecute() => OnUpdate(_customUpdateData); + /// public override void Dispose() { diff --git a/RGB.NET.Presets/Groups/RectangleLedGroup.cs b/RGB.NET.Presets/Groups/RectangleLedGroup.cs index d6cb6502..cf668483 100644 --- a/RGB.NET.Presets/Groups/RectangleLedGroup.cs +++ b/RGB.NET.Presets/Groups/RectangleLedGroup.cs @@ -2,6 +2,7 @@ // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global // ReSharper disable UnusedMember.Global +using System; using System.Collections.Generic; using System.Linq; using RGB.NET.Core; @@ -121,7 +122,7 @@ public override void OnDetach() /// Gets a list containing all of this . /// /// The list containing all of this . - public override IList ToList() => _ledCache ??= (Surface?.Leds.Where(led => led.AbsoluteBoundary.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList() ?? new List()); + public override IList ToList() => _ledCache ??= ((IList?)Surface?.Leds.Where(led => led.AbsoluteBoundary.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList() ?? Array.Empty()); private void InvalidateCache() => _ledCache = null; From 4ee55c6725367e2c754b76df61aa0cfc8faeeb30 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 13 Apr 2023 01:24:53 +0200 Subject: [PATCH 33/96] Small fixes --- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 2 ++ RGB.NET.Core/RGBSurface.cs | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index fc18794a..a03bfa23 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -7,6 +7,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; namespace RGB.NET.Core; @@ -120,6 +121,7 @@ public virtual void Update(bool flushLeds = false) /// /// The enumerable of leds to convert. /// The enumerable of custom data and color tuples for the specified leds. + [MethodImpl(MethodImplOptions.AggressiveInlining)] protected (object key, Color color) GetUpdateData(Led led) { Color color = led.Color; diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index 5e022edb..8219191b 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -217,8 +217,7 @@ private void Render(ILedGroup ledGroup) Rectangle brushRectangle = new(leds); Point offset = new(-brushRectangle.Location.X, -brushRectangle.Location.Y); brushRectangle = brushRectangle.SetLocation(new Point(0, 0)); - render = brush.Render(brushRectangle, - leds.Select(led => new RenderTarget(led, led.AbsoluteBoundary.Translate(offset)))); + render = brush.Render(brushRectangle, leds.Select(led => new RenderTarget(led, led.AbsoluteBoundary.Translate(offset)))); break; case RenderMode.Absolute: render = brush.Render(Boundary, leds.Select(led => new RenderTarget(led, led.AbsoluteBoundary))); From 260a820b80379f172fbaedf4d0d61a408da7ab0a Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 13 Apr 2023 02:03:13 +0200 Subject: [PATCH 34/96] Added SkipLocalsInitAttribute to Sample-Methods --- RGB.NET.Core/Rendering/Textures/PixelTexture.cs | 1 + RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs | 2 ++ RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs | 2 ++ 3 files changed, 5 insertions(+) diff --git a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs index 3672e2ce..4ea5f064 100644 --- a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs +++ b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs @@ -76,6 +76,7 @@ public virtual Color this[in Rectangle rectangle] /// The with of the region. /// The height of the region. /// The sampled color. + [SkipLocalsInit] public virtual Color this[int x, int y, int width, int height] { get diff --git a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs index 8d5b8b6d..0486c5ad 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs @@ -1,5 +1,6 @@ using System; using System.Numerics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using RGB.NET.Core; @@ -19,6 +20,7 @@ public class AverageByteSampler : ISampler #region Methods /// + [SkipLocalsInit] public unsafe void Sample(in SamplerInfo info, in Span pixelData) { int count = info.Width * info.Height; diff --git a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs index 50e95638..b0477739 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs @@ -1,5 +1,6 @@ using System; using System.Numerics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using RGB.NET.Core; @@ -13,6 +14,7 @@ public class AverageFloatSampler : ISampler #region Methods /// + [SkipLocalsInit] public unsafe void Sample(in SamplerInfo info, in Span pixelData) { int count = info.Width * info.Height; From ad757076458eb5fc9bcfc818bd13d0ccc248098b Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 13 Apr 2023 11:29:22 +0200 Subject: [PATCH 35/96] Removed SkipLocalInit-Attributes - they're causing issues and are not worth the effort for now --- RGB.NET.Core/Rendering/Textures/PixelTexture.cs | 1 - RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs | 2 -- RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs | 2 -- 3 files changed, 5 deletions(-) diff --git a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs index 4ea5f064..3672e2ce 100644 --- a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs +++ b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs @@ -76,7 +76,6 @@ public virtual Color this[in Rectangle rectangle] /// The with of the region. /// The height of the region. /// The sampled color. - [SkipLocalsInit] public virtual Color this[int x, int y, int width, int height] { get diff --git a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs index 0486c5ad..8d5b8b6d 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs @@ -1,6 +1,5 @@ using System; using System.Numerics; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using RGB.NET.Core; @@ -20,7 +19,6 @@ public class AverageByteSampler : ISampler #region Methods /// - [SkipLocalsInit] public unsafe void Sample(in SamplerInfo info, in Span pixelData) { int count = info.Width * info.Height; diff --git a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs index b0477739..50e95638 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs @@ -1,6 +1,5 @@ using System; using System.Numerics; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using RGB.NET.Core; @@ -14,7 +13,6 @@ public class AverageFloatSampler : ISampler #region Methods /// - [SkipLocalsInit] public unsafe void Sample(in SamplerInfo info, in Span pixelData) { int count = info.Width * info.Height; From d9c244a044f2bd576f2670348352b843392975a7 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 19 Apr 2023 20:11:30 +0200 Subject: [PATCH 36/96] Small fixes --- RGB.NET.Core/MVVM/IBindable.cs | 3 +-- RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj | 4 ++-- RGB.NET.Devices.Corsair/Native/_CUESDK.cs | 4 ---- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/RGB.NET.Core/MVVM/IBindable.cs b/RGB.NET.Core/MVVM/IBindable.cs index 34a861d5..24d1fa52 100644 --- a/RGB.NET.Core/MVVM/IBindable.cs +++ b/RGB.NET.Core/MVVM/IBindable.cs @@ -6,5 +6,4 @@ namespace RGB.NET.Core; /// Represents a basic bindable class which notifies when a property value changes. /// public interface IBindable : INotifyPropertyChanged -{ -} \ No newline at end of file +{ } \ No newline at end of file diff --git a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj index f7a9c4b3..dc67689c 100644 --- a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj +++ b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj @@ -40,7 +40,7 @@ - $(DefineConstants);TRACE;DEBUG + TRACE;DEBUG true false @@ -48,7 +48,7 @@ true $(NoWarn);CS1591;CS1572;CS1573 - $(DefineConstants);RELEASE + RELEASE diff --git a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs index d3593ee9..00d9f922 100644 --- a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs +++ b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs @@ -91,11 +91,7 @@ private static void LoadCUESDK() if (dllPath == null) throw new RGBDeviceException($"Can't find the CUE-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'"); if (!NativeLibrary.TryLoad(dllPath, out _handle)) -#if NET6_0_OR_GREATER throw new RGBDeviceException($"Corsair LoadLibrary failed with error code {Marshal.GetLastPInvokeError()}"); -#else - throw new RGBDeviceException($"Corsair LoadLibrary failed with error code {Marshal.GetLastWin32Error()}"); -#endif _corsairConnectPtr = (delegate* unmanaged[Cdecl])LoadFunction("CorsairConnect"); _corsairGetSessionDetails = (delegate* unmanaged[Cdecl])LoadFunction("CorsairGetSessionDetails"); From 20209922499fa885cd7d6c66b75784081f1bbc69 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 19 Apr 2023 21:19:05 +0200 Subject: [PATCH 37/96] Sealed a lot of classes that are not meant to be inherited --- RGB.NET.Core/Groups/ListLedGroup.cs | 32 ++++----- RGB.NET.Core/Leds/Led.cs | 2 +- RGB.NET.Core/Leds/LedMapping.cs | 2 +- .../Rendering/Brushes/SolidColorBrush.cs | 2 +- .../Rendering/Brushes/TextureBrush.cs | 2 +- .../Rendering/Textures/EmptyTexture.cs | 2 +- RGB.NET.Core/Update/CustomUpdateData.cs | 6 +- RGB.NET.Core/Update/TimerUpdateTrigger.cs | 33 +++++---- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 4 +- .../Generic/AsusUnspecifiedRGBDevice.cs | 2 +- .../Generic/AsusUpdateQueue.cs | 12 ++-- .../GraphicsCard/AsusGraphicsCardRGBDevice.cs | 2 +- .../Headset/AsusHeadsetRGBDevice.cs | 2 +- .../Keyboard/AsusKeyboardRGBDevice.cs | 2 +- .../Keyboard/AsusKeyboardRGBDeviceInfo.cs | 2 +- .../Mainboard/AsusMainboardRGBDevice.cs | 2 +- .../Mouse/AsusMouseRGBDevice.cs | 2 +- .../Attributes/DeviceTypeAttribute.cs | 2 +- .../CoolerMasterDeviceProvider.cs | 4 +- .../Enum/CoolerMasterDevicesIndexes.cs | 2 - .../Enum/CoolerMasterEffects.cs | 40 ----------- .../Generic/CoolerMasterUpdateQueue.cs | 2 +- .../Keyboard/CoolerMasterKeyboardRGBDevice.cs | 2 +- .../CoolerMasterKeyboardRGBDeviceInfo.cs | 2 +- .../Mouse/CoolerMasterMouseRGBDevice.cs | 2 +- .../Mouse/CoolerMasterMouseRGBDeviceInfo.cs | 2 +- .../Cooler/CorsairCoolerRGBDevice.cs | 2 +- .../Cooler/CorsairCoolerRGBDeviceInfo.cs | 2 +- .../CorsairDeviceProvider.cs | 4 +- .../Exceptions/CUEException.cs | 2 +- .../Fan/CorsairFanRGBDevice.cs | 2 +- .../Fan/CorsairFanRGBDeviceInfo.cs | 2 +- .../Generic/CorsairDeviceUpdateQueue.cs | 4 +- .../Generic/CorsairProtocolDetails.cs | 2 +- .../CorsairGraphicsCardRGBDevice.cs | 2 +- .../CorsairGraphicsCardRGBDeviceInfo.cs | 2 +- .../Headset/CorsairHeadsetRGBDevice.cs | 2 +- .../Headset/CorsairHeadsetRGBDeviceInfo.cs | 2 +- .../CorsairHeadsetStandRGBDevice.cs | 2 +- .../CorsairHeadsetStandRGBDeviceInfo.cs | 2 +- .../Keyboard/CorsairKeyboardRGBDevice.cs | 2 +- .../Keyboard/CorsairKeyboardRGBDeviceInfo.cs | 2 +- .../LedStrip/CorsairLedStripGBDevice.cs | 2 +- .../LedStrip/CorsairLedStripRGBDeviceInfo.cs | 2 +- .../Mainboard/CorsairMainboardRGBDevice.cs | 2 +- .../CorsairMainboardRGBDeviceInfo.cs | 2 +- .../Memory/CorsairMemoryRGBDevice.cs | 2 +- .../Memory/CorsairMemoryRGBDeviceInfo.cs | 2 +- .../Mouse/CorsairMouseRGBDevice.cs | 2 +- .../Mouse/CorsairMouseRGBDeviceInfo.cs | 2 +- .../Mousepad/CorsairMousepadRGBDevice.cs | 2 +- .../Mousepad/CorsairMousepadRGBDeviceInfo.cs | 2 +- .../Native/_CorsairDeviceFilter.cs | 2 +- .../Native/_CorsairDeviceInfo.cs | 2 +- .../Native/_CorsairLedPosition.cs | 2 +- .../Native/_CorsairSessionDetails.cs | 2 +- .../Native/_CorsairSessionStateChanged.cs | 2 +- .../Native/_CorsairVersion.cs | 2 +- .../Touchbar/CorsairTouchbarRGBDevice.cs | 2 +- .../Touchbar/CorsairTouchbarRGBDeviceInfo.cs | 2 +- .../Unknown/CorsairUnknownRGBDevice.cs | 2 +- .../Unknown/CorsairUnknownRGBDeviceInfo.cs | 2 +- RGB.NET.Devices.DMX/DMXDeviceProvider.cs | 2 +- .../E131/E131DMXDeviceDefinition.cs | 2 +- RGB.NET.Devices.DMX/E131/E131Device.cs | 2 +- RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs | 2 +- RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs | 2 +- .../Generic/LedChannelMapping.cs | 2 +- RGB.NET.Devices.Debug/DebugDeviceProvider.cs | 4 +- .../DebugDeviceUpdateQueue.cs | 2 +- RGB.NET.Devices.Debug/DebugRGBDevice.cs | 2 +- RGB.NET.Devices.Debug/DebugRGBDeviceInfo.cs | 2 +- .../HID/LightspeedHidLoader.cs | 2 +- .../PerDevice/LogitechPerDeviceRGBDevice.cs | 2 +- .../PerDevice/LogitechPerDeviceUpdateQueue.cs | 2 +- .../PerKey/LogitechPerKeyRGBDevice.cs | 2 +- .../PerKey/LogitechPerKeyUpdateQueue.cs | 5 +- .../Zone/LogitechZoneRGBDevice.cs | 2 +- .../Zone/LogitechZoneUpdateQueue.cs | 2 +- .../Exceptions/MysticLightException.cs | 2 +- .../Generic/MsiDeviceUpdateQueue.cs | 2 +- .../GraphicsCard/MsiGraphicsCardRGBDevice.cs | 2 +- .../Mainboard/MsiMainboardRGBDevice.cs | 2 +- .../Mouse/MsiMouseRGBDevice.cs | 2 +- .../Attributes/ColorCapabilityAttribute.cs | 2 +- .../Attributes/DeviceIdAttribute.cs | 2 +- .../Attributes/LedIdMappingAttribute.cs | 2 +- .../Generic/LimitedColorUpdateQueue.cs | 4 +- .../Generic/RGBColorUpdateQueue.cs | 4 +- .../Launchpad/NovationLaunchpadRGBDevice.cs | 4 +- .../NovationLaunchpadRGBDeviceInfo.cs | 2 +- .../NovationDeviceProvider.cs | 2 +- .../Generic/OpenRGBGenericDevice.cs | 2 +- .../Generic/OpenRGBUpdateQueue.cs | 2 +- .../OpenRGBDeviceProvider.cs | 4 +- .../OpenRGBServerDefinition.cs | 2 +- .../PerZone/OpenRGBZoneDevice.cs | 2 +- .../Segment/OpenRGBSegmentDevice.cs | 2 +- .../PicoPi/PicoPiBulkUpdateQueue.cs | 2 +- .../PicoPi/PicoPiHIDUpdateQueue.cs | 2 +- .../PicoPi/PicoPiRGBDevice.cs | 2 +- .../PicoPi/PicoPiRGBDeviceInfo.cs | 2 +- RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs | 4 +- .../PicoPiDeviceProvider.cs | 2 +- .../ChromaLink/RazerChromaLinkRGBDevice.cs | 2 +- .../ChromaLink/RazerChromaLinkUpdateQueue.cs | 2 +- .../Exceptions/RazerException.cs | 2 +- RGB.NET.Devices.Razer/Generic/Devices.cs | 70 ------------------- .../Headset/RazerHeadsetRGBDevice.cs | 2 +- .../Headset/RazerHeadsetUpdateQueue.cs | 2 +- .../Keyboard/RazerKeyboardRGBDevice.cs | 2 +- .../Keyboard/RazerKeyboardRGBDeviceInfo.cs | 2 +- .../Keyboard/RazerKeyboardUpdateQueue.cs | 2 +- .../Keypad/RazerKeypadRGBDevice.cs | 2 +- .../Keypad/RazerKeypadUpdateQueue.cs | 2 +- .../Mouse/RazerMouseRGBDevice.cs | 2 +- .../Mouse/RazerMouseUpdateQueue.cs | 2 +- .../Mousepad/RazerMousepadRGBDevice.cs | 2 +- .../Mousepad/RazerMousepadUpdateQueue.cs | 2 +- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 4 +- .../API/Model/CoreProps.cs | 2 +- .../API/Model/Event.cs | 2 +- RGB.NET.Devices.SteelSeries/API/Model/Game.cs | 2 +- .../API/Model/GoLispHandler.cs | 2 +- .../Attribute/APIName.cs | 2 +- .../Generic/SteelSeriesDeviceUpdateQueue.cs | 2 +- .../Generic/SteelSeriesRGBDevice.cs | 2 +- .../Generic/SteelSeriesRGBDeviceInfo.cs | 2 +- .../SteelSeriesDeviceProvider.cs | 6 +- .../Arduino/ArduinoWS2812USBDevice.cs | 2 +- .../Arduino/ArduinoWS2812USBDeviceInfo.cs | 2 +- .../Arduino/ArduinoWS2812USBUpdateQueue.cs | 2 +- .../Arduino/ArduinoWS281XDeviceDefinition.cs | 2 +- .../Bitwizard/BitwizardWS2812USBDevice.cs | 2 +- .../Bitwizard/BitwizardWS2812USBDeviceInfo.cs | 2 +- .../BitwizardWS2812USBUpdateQueue.cs | 2 +- .../BitwizardWS281XDeviceDefinition.cs | 2 +- .../Generic/SerialPortConnection.cs | 7 +- .../NodeMCU/NodeMCUWS2812USBDevice.cs | 2 +- .../NodeMCU/NodeMCUWS2812USBDeviceInfo.cs | 2 +- .../NodeMCU/NodeMCUWS2812USBUpdateQueue.cs | 4 +- .../NodeMCU/NodeMCUWS281XDeviceDefinition.cs | 2 +- .../WS281XDeviceProvider.cs | 4 +- .../Generic/WootingUpdateQueue.cs | 4 +- .../Keyboard/WootingKeyboardRGBDevice.cs | 7 +- .../Keyboard/WootingKeyboardRGBDeviceInfo.cs | 2 +- .../WootingDeviceProvider.cs | 4 +- RGB.NET.HID/HIDLoader.cs | 2 +- RGB.NET.Presets/Decorators/FlashDecorator.cs | 2 +- RGB.NET.Presets/Groups/RectangleLedGroup.cs | 2 +- .../Textures/Gradients/GradientStop.cs | 2 +- .../Textures/Gradients/LinearGradient.cs | 11 +-- .../Textures/Gradients/RainbowGradient.cs | 4 +- .../Textures/Sampler/AverageByteSampler.cs | 2 +- .../Textures/Sampler/AverageFloatSampler.cs | 2 +- 155 files changed, 205 insertions(+), 344 deletions(-) delete mode 100644 RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterEffects.cs delete mode 100644 RGB.NET.Devices.Razer/Generic/Devices.cs diff --git a/RGB.NET.Core/Groups/ListLedGroup.cs b/RGB.NET.Core/Groups/ListLedGroup.cs index a97b6ecc..4bca2fbd 100644 --- a/RGB.NET.Core/Groups/ListLedGroup.cs +++ b/RGB.NET.Core/Groups/ListLedGroup.cs @@ -11,7 +11,7 @@ namespace RGB.NET.Core; /// /// Represents a ledgroup containing arbitrary . /// -public class ListLedGroup : AbstractLedGroup +public sealed class ListLedGroup : AbstractLedGroup { #region Properties & Fields @@ -20,7 +20,7 @@ public class ListLedGroup : AbstractLedGroup /// /// Gets the list containing the of this . /// - protected IList GroupLeds { get; } = new List(); + private readonly IList _groupLeds = new List(); #endregion @@ -81,10 +81,10 @@ public ListLedGroup(RGBSurface? surface, params Led[] leds) /// The to add. public void AddLeds(IEnumerable leds) { - lock (GroupLeds) + lock (_groupLeds) foreach (Led led in leds) if (!ContainsLed(led)) - GroupLeds.Add(led); + _groupLeds.Add(led); } /// @@ -99,9 +99,9 @@ public void AddLeds(IEnumerable leds) /// The to remove. public void RemoveLeds(IEnumerable leds) { - lock (GroupLeds) + lock (_groupLeds) foreach (Led led in leds) - GroupLeds.Remove(led); + _groupLeds.Remove(led); } /// @@ -111,8 +111,8 @@ public void RemoveLeds(IEnumerable leds) /// true if the LED is contained by this ledgroup; otherwise, false. public bool ContainsLed(Led led) { - lock (GroupLeds) - return GroupLeds.Contains(led); + lock (_groupLeds) + return _groupLeds.Contains(led); } /// @@ -121,10 +121,10 @@ public bool ContainsLed(Led led) /// The ledgroup to merge. public void MergeLeds(ILedGroup groupToMerge) { - lock (GroupLeds) + lock (_groupLeds) foreach (Led led in groupToMerge) - if (!GroupLeds.Contains(led)) - GroupLeds.Add(led); + if (!_groupLeds.Contains(led)) + _groupLeds.Add(led); } /// @@ -141,18 +141,18 @@ public void MergeLeds(ILedGroup groupToMerge) /// The list containing the . public override IList ToList() { - lock (GroupLeds) - return new List(GroupLeds); + lock (_groupLeds) + return new List(_groupLeds); } protected override IDisposable ToListUnsafe(out IList leds) { - Monitor.Enter(GroupLeds); - leds = GroupLeds; + Monitor.Enter(_groupLeds); + leds = _groupLeds; return _unlockDisposable; } - private void Unlock() => Monitor.Exit(GroupLeds); + private void Unlock() => Monitor.Exit(_groupLeds); #endregion } \ No newline at end of file diff --git a/RGB.NET.Core/Leds/Led.cs b/RGB.NET.Core/Leds/Led.cs index ad2e3f9f..2fb05ea6 100644 --- a/RGB.NET.Core/Leds/Led.cs +++ b/RGB.NET.Core/Leds/Led.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Core; /// Represents a single LED of a RGB-device. /// [DebuggerDisplay("{Id} {Color}")] -public class Led : Placeable +public sealed class Led : Placeable { #region Properties & Fields diff --git a/RGB.NET.Core/Leds/LedMapping.cs b/RGB.NET.Core/Leds/LedMapping.cs index 05a10ec3..0aab16d7 100644 --- a/RGB.NET.Core/Leds/LedMapping.cs +++ b/RGB.NET.Core/Leds/LedMapping.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Core; /// Represents a mapping from to a custom identifier. /// /// The identifier the is mapped to. -public class LedMapping : IEnumerable<(LedId ledId, T mapping)> +public sealed class LedMapping : IEnumerable<(LedId ledId, T mapping)> where T : notnull { #region Constants diff --git a/RGB.NET.Core/Rendering/Brushes/SolidColorBrush.cs b/RGB.NET.Core/Rendering/Brushes/SolidColorBrush.cs index 4175db11..158705c3 100644 --- a/RGB.NET.Core/Rendering/Brushes/SolidColorBrush.cs +++ b/RGB.NET.Core/Rendering/Brushes/SolidColorBrush.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Core; /// /// Represents a brush drawing only a single color. /// -public class SolidColorBrush : AbstractBrush +public sealed class SolidColorBrush : AbstractBrush { #region Properties & Fields diff --git a/RGB.NET.Core/Rendering/Brushes/TextureBrush.cs b/RGB.NET.Core/Rendering/Brushes/TextureBrush.cs index 4a2de6e7..41280cd2 100644 --- a/RGB.NET.Core/Rendering/Brushes/TextureBrush.cs +++ b/RGB.NET.Core/Rendering/Brushes/TextureBrush.cs @@ -4,7 +4,7 @@ /// /// Represents a brush drawing a texture. /// -public class TextureBrush : AbstractBrush +public sealed class TextureBrush : AbstractBrush { #region Properties & Fields diff --git a/RGB.NET.Core/Rendering/Textures/EmptyTexture.cs b/RGB.NET.Core/Rendering/Textures/EmptyTexture.cs index 588b62b8..7aca9b7a 100644 --- a/RGB.NET.Core/Rendering/Textures/EmptyTexture.cs +++ b/RGB.NET.Core/Rendering/Textures/EmptyTexture.cs @@ -1,6 +1,6 @@ namespace RGB.NET.Core; -internal class EmptyTexture : ITexture +internal sealed class EmptyTexture : ITexture { #region Properties & Fields diff --git a/RGB.NET.Core/Update/CustomUpdateData.cs b/RGB.NET.Core/Update/CustomUpdateData.cs index a657e96d..4888cd1b 100644 --- a/RGB.NET.Core/Update/CustomUpdateData.cs +++ b/RGB.NET.Core/Update/CustomUpdateData.cs @@ -48,7 +48,7 @@ public interface ICustomUpdateData /// /// Represents a set of custom data, each indexed by a string-key. /// -public class CustomUpdateData : ICustomUpdateData +public sealed class CustomUpdateData : ICustomUpdateData { #region Properties & Fields @@ -92,7 +92,7 @@ public CustomUpdateData(params (string key, object value)[] values) #endregion } -internal class DefaultCustomUpdateData : ICustomUpdateData +internal sealed class DefaultCustomUpdateData : ICustomUpdateData { #region Constants @@ -120,7 +120,7 @@ public object? this[string key] #region Constructors - public DefaultCustomUpdateData(bool flushLeds) + private DefaultCustomUpdateData(bool flushLeds) { this._flushLeds = flushLeds; } diff --git a/RGB.NET.Core/Update/TimerUpdateTrigger.cs b/RGB.NET.Core/Update/TimerUpdateTrigger.cs index 9f2b2b60..6b94b3f4 100644 --- a/RGB.NET.Core/Update/TimerUpdateTrigger.cs +++ b/RGB.NET.Core/Update/TimerUpdateTrigger.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Core; /// /// Represents an update trigger that triggers in a set interval. /// -public class TimerUpdateTrigger : AbstractUpdateTrigger +public sealed class TimerUpdateTrigger : AbstractUpdateTrigger { #region Properties & Fields @@ -21,17 +21,17 @@ public class TimerUpdateTrigger : AbstractUpdateTrigger /// /// Gets or sets the update loop of this trigger. /// - protected Task? UpdateTask { get; set; } + private Task? _updateTask; /// - /// Gets or sets the cancellation token source used to create the cancellation token checked by the . + /// Gets or sets the cancellation token source used to create the cancellation token checked by the . /// - protected CancellationTokenSource? UpdateTokenSource { get; set; } + private CancellationTokenSource? _updateTokenSource; /// - /// Gets or sets the cancellation token checked by the . + /// Gets or sets the cancellation token checked by the . /// - protected CancellationToken UpdateToken { get; set; } + private CancellationToken _updateToken; private double _updateFrequency = 1.0 / 30.0; /// @@ -88,11 +88,11 @@ public override void Start() { lock (_lock) { - if (UpdateTask == null) + if (_updateTask == null) { - UpdateTokenSource?.Dispose(); - UpdateTokenSource = new CancellationTokenSource(); - UpdateTask = Task.Factory.StartNew(UpdateLoop, (UpdateToken = UpdateTokenSource.Token), TaskCreationOptions.LongRunning, TaskScheduler.Default); + _updateTokenSource?.Dispose(); + _updateTokenSource = new CancellationTokenSource(); + _updateTask = Task.Factory.StartNew(UpdateLoop, (_updateToken = _updateTokenSource.Token), TaskCreationOptions.LongRunning, TaskScheduler.Default); } } } @@ -104,13 +104,13 @@ public void Stop() { lock (_lock) { - if (UpdateTask != null) + if (_updateTask != null) { - UpdateTokenSource?.Cancel(); + _updateTokenSource?.Cancel(); try { // ReSharper disable once MethodSupportsCancellation - UpdateTask.Wait(); + _updateTask.Wait(); } catch (AggregateException) { @@ -118,8 +118,8 @@ public void Stop() } finally { - UpdateTask.Dispose(); - UpdateTask = null; + _updateTask.Dispose(); + _updateTask = null; } } } @@ -130,7 +130,7 @@ private void UpdateLoop() OnStartup(); using (TimerHelper.RequestHighResolutionTimer()) - while (!UpdateToken.IsCancellationRequested) + while (!_updateToken.IsCancellationRequested) LastUpdateTime = TimerHelper.Execute(TimerExecute, UpdateFrequency * 1000); } @@ -140,7 +140,6 @@ private void UpdateLoop() public override void Dispose() { Stop(); - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index f9af5b39..318850ed 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.Asus; /// /// Represents a device provider responsible for Cooler Master devices. /// -public class AsusDeviceProvider : AbstractRGBDeviceProvider +public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields @@ -88,8 +88,6 @@ public override void Dispose() _devices = null; _sdk = null; - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs b/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs index bb405782..fe3c2389 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.Asus; /// /// Represents a Asus headset. /// -public class AsusUnspecifiedRGBDevice : AsusRGBDevice, IUnknownDevice +public sealed class AsusUnspecifiedRGBDevice : AsusRGBDevice, IUnknownDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs index 012ed7e6..2f40ec68 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Asus; /// /// Represents the update-queue performing updates for asus devices. /// -public class AsusUpdateQueue : UpdateQueue +public sealed class AsusUpdateQueue : UpdateQueue { #region Properties & Fields @@ -17,7 +17,7 @@ public class AsusUpdateQueue : UpdateQueue /// /// The device to be updated. /// - protected IAuraSyncDevice Device { get; } + private readonly IAuraSyncDevice _device; #endregion @@ -31,7 +31,7 @@ public class AsusUpdateQueue : UpdateQueue public AsusUpdateQueue(IDeviceUpdateTrigger updateTrigger, IAuraSyncDevice device) : base(updateTrigger) { - this.Device = device; + this._device = device; this._lights = new IAuraRgbLight[device.Lights.Count]; for (int i = 0; i < device.Lights.Count; i++) @@ -47,9 +47,9 @@ protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSe { try { - if ((Device.Type == (uint)AsusDeviceType.KEYBOARD_RGB) || (Device.Type == (uint)AsusDeviceType.NB_KB_RGB)) + if ((_device.Type == (uint)AsusDeviceType.KEYBOARD_RGB) || (_device.Type == (uint)AsusDeviceType.NB_KB_RGB)) { - if (Device is not IAuraSyncKeyboard keyboard) + if (_device is not IAuraSyncKeyboard keyboard) return true; foreach ((object customData, Color value) in dataSet) @@ -87,7 +87,7 @@ protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSe } } - Device.Apply(); + _device.Apply(); return true; } diff --git a/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDevice.cs index 15c23831..1debf597 100644 --- a/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDevice.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.Asus; /// /// Represents a Asus graphicsCard. /// -public class AsusGraphicsCardRGBDevice : AsusRGBDevice, IGraphicsCard +public sealed class AsusGraphicsCardRGBDevice : AsusRGBDevice, IGraphicsCard { #region Constructors diff --git a/RGB.NET.Devices.Asus/Headset/AsusHeadsetRGBDevice.cs b/RGB.NET.Devices.Asus/Headset/AsusHeadsetRGBDevice.cs index 71f9e109..516dab6d 100644 --- a/RGB.NET.Devices.Asus/Headset/AsusHeadsetRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Headset/AsusHeadsetRGBDevice.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.Asus; /// /// Represents a Asus headset. /// -public class AsusHeadsetRGBDevice : AsusRGBDevice, IHeadset +public sealed class AsusHeadsetRGBDevice : AsusRGBDevice, IHeadset { #region Constructors diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs index 86f64aad..30b429cc 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs @@ -20,7 +20,7 @@ public record AsusKeyboardExtraMapping(Regex Regex, LedMapping LedMapping); /// /// Represents a Asus keyboard. /// -public class AsusKeyboardRGBDevice : AsusRGBDevice, IKeyboard +public sealed class AsusKeyboardRGBDevice : AsusRGBDevice, IKeyboard { #region Properties & Fields diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs index 41732713..b40ec593 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Asus; /// /// Represents a generic information for a . /// -public class AsusKeyboardRGBDeviceInfo : AsusRGBDeviceInfo, IKeyboardDeviceInfo +public sealed class AsusKeyboardRGBDeviceInfo : AsusRGBDeviceInfo, IKeyboardDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs b/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs index 2f92bb63..137ae905 100644 --- a/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.Asus; /// /// Represents a Asus mainboard. /// -public class AsusMainboardRGBDevice : AsusRGBDevice, IMainboard +public sealed class AsusMainboardRGBDevice : AsusRGBDevice, IMainboard { #region Constructors diff --git a/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDevice.cs b/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDevice.cs index 3db166ad..e4ae049a 100644 --- a/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDevice.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.Asus; /// /// Represents a Asus mouse. /// -public class AsusMouseRGBDevice : AsusRGBDevice, IMouse +public sealed class AsusMouseRGBDevice : AsusRGBDevice, IMouse { #region Constructors diff --git a/RGB.NET.Devices.CoolerMaster/Attributes/DeviceTypeAttribute.cs b/RGB.NET.Devices.CoolerMaster/Attributes/DeviceTypeAttribute.cs index 8aad3001..07245cb0 100644 --- a/RGB.NET.Devices.CoolerMaster/Attributes/DeviceTypeAttribute.cs +++ b/RGB.NET.Devices.CoolerMaster/Attributes/DeviceTypeAttribute.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.CoolerMaster; /// Specifies the of a field. /// [AttributeUsage(AttributeTargets.Field)] -public class DeviceTypeAttribute : Attribute +public sealed class DeviceTypeAttribute : Attribute { #region Properties & Fields diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index e51ed8a2..ab16a450 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Devices.CoolerMaster; /// /// Represents a device provider responsible for Cooler Master devices. /// -public class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider +public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields @@ -100,8 +100,6 @@ public override void Dispose() try { _CoolerMasterSDK.Reload(); } catch { /* Unlucky.. */ } - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterDevicesIndexes.cs b/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterDevicesIndexes.cs index f528ccf3..66eb53b0 100644 --- a/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterDevicesIndexes.cs +++ b/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterDevicesIndexes.cs @@ -4,8 +4,6 @@ using System.ComponentModel; using RGB.NET.Core; -#pragma warning disable 1591 // Missing XML comment for publicly visible type or member - namespace RGB.NET.Devices.CoolerMaster; /// diff --git a/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterEffects.cs b/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterEffects.cs deleted file mode 100644 index b9fcaa1c..00000000 --- a/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterEffects.cs +++ /dev/null @@ -1,40 +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.CoolerMaster; - -/// -/// Contains a list of available effects. -/// -public enum CoolerMasterEffects -{ - FullOn = 0, - Breath = 1, - BreathCycle = 2, - Single = 3, - Wave = 4, - Ripple = 5, - Cross = 6, - Rain = 7, - Star = 8, - Snake = 9, - Rec = 10, - - Spectrum = 11, - RapidFire = 12, - Indicator = 13, //mouse Effect - FireBall = 14, - WaterRipple = 15, - ReactivePunch = 16, - Snowing = 17, - HeartBeat = 18, - ReactiveTornade = 19, - - Multi1 = 0xE0, - Multi2 = 0xE1, - Multi3 = 0xE2, - Multi4 = 0xE3, - Off = 0xFE -} \ No newline at end of file diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs index 4121c4f7..99e14281 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.CoolerMaster; /// /// Represents the update-queue performing updates for cooler master devices. /// -public class CoolerMasterUpdateQueue : UpdateQueue +public sealed class CoolerMasterUpdateQueue : UpdateQueue { #region Properties & Fields diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs index 29b1e3c1..1d03191b 100644 --- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.CoolerMaster; /// /// Represents a CoolerMaster keyboard. /// -public class CoolerMasterKeyboardRGBDevice : CoolerMasterRGBDevice, IKeyboard +public sealed class CoolerMasterKeyboardRGBDevice : CoolerMasterRGBDevice, IKeyboard { #region Properties & Fields diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs index df9fec99..591a62f4 100644 --- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs @@ -5,7 +5,7 @@ namespace RGB.NET.Devices.CoolerMaster; /// /// Represents a generic information for a . /// -public class CoolerMasterKeyboardRGBDeviceInfo : CoolerMasterRGBDeviceInfo, IKeyboardDeviceInfo +public sealed class CoolerMasterKeyboardRGBDeviceInfo : CoolerMasterRGBDeviceInfo, IKeyboardDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDevice.cs index 16ba91c5..53e45225 100644 --- a/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDevice.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.CoolerMaster; /// /// Represents a CoolerMaster mouse. /// -public class CoolerMasterMouseRGBDevice : CoolerMasterRGBDevice, IMouse +public sealed class CoolerMasterMouseRGBDevice : CoolerMasterRGBDevice, IMouse { #region Constructors diff --git a/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDeviceInfo.cs b/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDeviceInfo.cs index 14f6b0eb..26982162 100644 --- a/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDeviceInfo.cs +++ b/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDeviceInfo.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.CoolerMaster; /// /// Represents a generic information for a . /// -public class CoolerMasterMouseRGBDeviceInfo : CoolerMasterRGBDeviceInfo +public sealed class CoolerMasterMouseRGBDeviceInfo : CoolerMasterRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDevice.cs b/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDevice.cs index fd5b89b8..e92a7310 100644 --- a/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair cooler. /// -public class CorsairCoolerRGBDevice : CorsairRGBDevice, ICooler +public sealed class CorsairCoolerRGBDevice : CorsairRGBDevice, ICooler { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDeviceInfo.cs index 958f129f..96333b49 100644 --- a/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Cooler/CorsairCoolerRGBDeviceInfo.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairCoolerRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairCoolerRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index ac363b96..87ab725e 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a device provider responsible for corsair (CUE) devices. /// -public class CorsairDeviceProvider : AbstractRGBDeviceProvider +public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields @@ -306,8 +306,6 @@ public override void Dispose() try { _CUESDK.CorsairDisconnect(); } catch { /* at least we tried */ } try { _CUESDK.UnloadCUESDK(); } catch { /* at least we tried */ } - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Corsair/Exceptions/CUEException.cs b/RGB.NET.Devices.Corsair/Exceptions/CUEException.cs index aca2994d..902860f2 100644 --- a/RGB.NET.Devices.Corsair/Exceptions/CUEException.cs +++ b/RGB.NET.Devices.Corsair/Exceptions/CUEException.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents an exception thrown by the CUE. /// -public class CUEException : ApplicationException +public sealed class CUEException : ApplicationException { #region Properties & Fields diff --git a/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDevice.cs b/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDevice.cs index 65200818..eb914925 100644 --- a/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair fan. /// -public class CorsairFanRGBDevice : CorsairRGBDevice, IFan +public sealed class CorsairFanRGBDevice : CorsairRGBDevice, IFan { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDeviceInfo.cs index f4973c57..35124d07 100644 --- a/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Fan/CorsairFanRGBDeviceInfo.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairFanRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairFanRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs index 8bea2eb6..be3a3bf7 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents the update-queue performing updates for corsair devices. /// -public class CorsairDeviceUpdateQueue : UpdateQueue +public sealed class CorsairDeviceUpdateQueue : UpdateQueue { #region Properties & Fields @@ -76,8 +76,6 @@ public override void Dispose() _isDisposed = true; Marshal.FreeHGlobal(_colorPtr); - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs b/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs index 70697761..afca46b6 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents version information for the Corsair-SDK /// -public class CorsairSessionDetails +public sealed class CorsairSessionDetails { #region Properties & Fields diff --git a/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDevice.cs index ce7fb8c0..51aa88aa 100644 --- a/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair graphics card. /// -public class CorsairGraphicsCardRGBDevice : CorsairRGBDevice, IGraphicsCard +public sealed class CorsairGraphicsCardRGBDevice : CorsairRGBDevice, IGraphicsCard { #region Constructors diff --git a/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs index ec5b4365..7c57ff0e 100644 --- a/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairGraphicsCardRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairGraphicsCardRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs index c2336d60..1cbd1136 100644 --- a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair headset. /// -public class CorsairHeadsetRGBDevice : CorsairRGBDevice, IHeadset +public sealed class CorsairHeadsetRGBDevice : CorsairRGBDevice, IHeadset { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs index 5bac705d..c7de7f9d 100644 --- a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairHeadsetRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairHeadsetRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs index 7103b76a..5d79725a 100644 --- a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair headset stand. /// -public class CorsairHeadsetStandRGBDevice : CorsairRGBDevice, IHeadsetStand +public sealed class CorsairHeadsetStandRGBDevice : CorsairRGBDevice, IHeadsetStand { #region Constructors diff --git a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs index cc6b2742..48b20496 100644 --- a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairHeadsetStandRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairHeadsetStandRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs index d1fa9317..51336193 100644 --- a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair keyboard. /// -public class CorsairKeyboardRGBDevice : CorsairRGBDevice, IKeyboard +public sealed class CorsairKeyboardRGBDevice : CorsairRGBDevice, IKeyboard { #region Properties & Fields diff --git a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs index dcab0880..8f5774cf 100644 --- a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairKeyboardRGBDeviceInfo : CorsairRGBDeviceInfo, IKeyboardDeviceInfo +public sealed class CorsairKeyboardRGBDeviceInfo : CorsairRGBDeviceInfo, IKeyboardDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripGBDevice.cs b/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripGBDevice.cs index 53eb5b05..9f46411a 100644 --- a/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripGBDevice.cs +++ b/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair ledStrip. /// -public class CorsairLedStripRGBDevice : CorsairRGBDevice, ILedStripe +public sealed class CorsairLedStripRGBDevice : CorsairRGBDevice, ILedStripe { #region Constructors diff --git a/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripRGBDeviceInfo.cs index 35006b87..a6497ac0 100644 --- a/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/LedStrip/CorsairLedStripRGBDeviceInfo.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairLedStripRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairLedStripRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDevice.cs b/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDevice.cs index 55ab92c2..98c02e10 100644 --- a/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair memory. /// -public class CorsairMainboardRGBDevice : CorsairRGBDevice, IMainboard +public sealed class CorsairMainboardRGBDevice : CorsairRGBDevice, IMainboard { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDeviceInfo.cs index 4058d108..761f951f 100644 --- a/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Mainboard/CorsairMainboardRGBDeviceInfo.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairMainboardRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairMainboardRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs b/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs index 48b2eb37..ec35a34c 100644 --- a/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair memory. /// -public class CorsairMemoryRGBDevice : CorsairRGBDevice, IDRAM +public sealed class CorsairMemoryRGBDevice : CorsairRGBDevice, IDRAM { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDeviceInfo.cs index 8d779f78..326bd806 100644 --- a/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDeviceInfo.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairMemoryRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairMemoryRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs index 89f25c46..4f66d311 100644 --- a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair mouse. /// -public class CorsairMouseRGBDevice : CorsairRGBDevice, IMouse +public sealed class CorsairMouseRGBDevice : CorsairRGBDevice, IMouse { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs index 422b18a2..b5ab17de 100644 --- a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairMouseRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairMouseRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs index ac7a9b39..7c005ea7 100644 --- a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair mousepad. /// -public class CorsairMousepadRGBDevice : CorsairRGBDevice, IMousepad +public sealed class CorsairMousepadRGBDevice : CorsairRGBDevice, IMousepad { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDeviceInfo.cs index 6b469c0a..901f54f3 100644 --- a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDeviceInfo.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairMousepadRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairMousepadRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs index 76f179da..f598d27c 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.Corsair.Native; /// iCUE-SDK: contains device search filter /// [StructLayout(LayoutKind.Sequential)] -internal class _CorsairDeviceFilter +internal sealed class _CorsairDeviceFilter { #region Properties & Fields diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs index f1228791..b4c8813d 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.Corsair.Native; /// iCUE-SDK: contains information about device /// [StructLayout(LayoutKind.Sequential)] -internal class _CorsairDeviceInfo +internal sealed class _CorsairDeviceInfo { /// /// iCUE-SDK: enum describing device type diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairLedPosition.cs b/RGB.NET.Devices.Corsair/Native/_CorsairLedPosition.cs index b2ff0fee..af2bad1c 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairLedPosition.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairLedPosition.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Devices.Corsair.Native; /// iCUE-SDK: contains led id and position of led /// [StructLayout(LayoutKind.Sequential)] -internal class _CorsairLedPosition +internal sealed class _CorsairLedPosition { /// /// iCUE-SDK: unique identifier of led diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairSessionDetails.cs b/RGB.NET.Devices.Corsair/Native/_CorsairSessionDetails.cs index 392a30b7..2fbf7556 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairSessionDetails.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairSessionDetails.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Devices.Corsair.Native; /// iCUE-SDK: contains information about SDK and iCUE versions /// [StructLayout(LayoutKind.Sequential)] -internal class _CorsairSessionDetails +internal sealed class _CorsairSessionDetails { /// /// iCUE-SDK: version of SDK client (like {4,0,1}). Always contains valid value even if there was no iCUE found. Must comply with the semantic versioning rules. diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairSessionStateChanged.cs b/RGB.NET.Devices.Corsair/Native/_CorsairSessionStateChanged.cs index 99aa8fd5..07b1a38c 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairSessionStateChanged.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairSessionStateChanged.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Devices.Corsair.Native; /// iCUE-SDK: contains information about session state and client/server versions /// [StructLayout(LayoutKind.Sequential)] -internal class _CorsairSessionStateChanged +internal sealed class _CorsairSessionStateChanged { /// /// iCUE-SDK: new session state which SDK client has been transitioned to diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairVersion.cs b/RGB.NET.Devices.Corsair/Native/_CorsairVersion.cs index 790226ec..d786b0f9 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairVersion.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairVersion.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Devices.Corsair.Native; /// iCUE-SDK: contains information about version that consists of three components /// [StructLayout(LayoutKind.Sequential)] -internal class _CorsairVersion +internal sealed class _CorsairVersion { #region Properties & Fields diff --git a/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDevice.cs b/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDevice.cs index d704343a..d5f9248a 100644 --- a/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a corsair touchbar. /// -public class CorsairTouchbarRGBDevice : CorsairRGBDevice, ILedStripe +public sealed class CorsairTouchbarRGBDevice : CorsairRGBDevice, ILedStripe { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDeviceInfo.cs index 68ea4f0c..04f400d1 100644 --- a/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Touchbar/CorsairTouchbarRGBDeviceInfo.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairTouchbarRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairTouchbarRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDevice.cs b/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDevice.cs index d8603365..655bafcf 100644 --- a/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a unknown corsair device. /// -public class CorsairUnknownRGBDevice : CorsairRGBDevice, IUnknownDevice +public sealed class CorsairUnknownRGBDevice : CorsairRGBDevice, IUnknownDevice { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDeviceInfo.cs index e9b6da56..770f65b4 100644 --- a/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Unknown/CorsairUnknownRGBDeviceInfo.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Corsair; /// /// Represents a generic information for a . /// -public class CorsairUnknownRGBDeviceInfo : CorsairRGBDeviceInfo +public sealed class CorsairUnknownRGBDeviceInfo : CorsairRGBDeviceInfo { #region Constructors diff --git a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs index 55e8e3fd..2d85a440 100644 --- a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs +++ b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.DMX; /// /// Represents a device provider responsible for DMX devices. /// -public class DMXDeviceProvider : AbstractRGBDeviceProvider +public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields diff --git a/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs b/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs index 37db5ea0..8e0934bb 100644 --- a/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs +++ b/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.DMX.E131; /// /// Represents the data used to create a E1.31 DMX-device. /// -public class E131DMXDeviceDefinition : IDMXDeviceDefinition +public sealed class E131DMXDeviceDefinition : IDMXDeviceDefinition { #region Properties & Fields diff --git a/RGB.NET.Devices.DMX/E131/E131Device.cs b/RGB.NET.Devices.DMX/E131/E131Device.cs index a7d3473e..5955ddb3 100644 --- a/RGB.NET.Devices.DMX/E131/E131Device.cs +++ b/RGB.NET.Devices.DMX/E131/E131Device.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.DMX.E131; /// /// Represents a E1.31-DXM-device. /// -public class E131Device : AbstractRGBDevice, IUnknownDevice +public sealed class E131Device : AbstractRGBDevice, IUnknownDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs b/RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs index 330a740f..db805f7e 100644 --- a/RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs +++ b/RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.DMX.E131; /// /// Represents device information for a />. /// -public class E131DeviceInfo : IRGBDeviceInfo +public sealed class E131DeviceInfo : IRGBDeviceInfo { #region Constants diff --git a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs index 57159e93..7ebdab83 100644 --- a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs +++ b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.DMX.E131; /// /// Represents the update-queue performing updates for E131-DMX devices. /// -public class E131UpdateQueue : UpdateQueue +public sealed class E131UpdateQueue : UpdateQueue { #region Properties & Fields diff --git a/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs b/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs index 2f999e3e..aa1aa296 100644 --- a/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs +++ b/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs @@ -5,7 +5,7 @@ namespace RGB.NET.Devices.DMX; -internal class LedChannelMapping : IEnumerable<(int channel, Func getValue)> +internal sealed class LedChannelMapping : IEnumerable<(int channel, Func getValue)> { #region Properties & Fields diff --git a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs index d396bc06..f88ad50c 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.Debug; /// /// Represents a device provider responsible for debug devices. /// -public class DebugDeviceProvider : AbstractRGBDeviceProvider +public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields @@ -71,8 +71,6 @@ public override void Dispose() base.Dispose(); _fakeDeviceDefinitions.Clear(); - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs b/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs index 1e00c42f..2789821c 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs @@ -3,7 +3,7 @@ namespace RGB.NET.Devices.Debug; -internal class DebugDeviceUpdateQueue : UpdateQueue +internal sealed class DebugDeviceUpdateQueue : UpdateQueue { #region Constructors diff --git a/RGB.NET.Devices.Debug/DebugRGBDevice.cs b/RGB.NET.Devices.Debug/DebugRGBDevice.cs index 35d1765c..61296ab6 100644 --- a/RGB.NET.Devices.Debug/DebugRGBDevice.cs +++ b/RGB.NET.Devices.Debug/DebugRGBDevice.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Devices.Debug; /// /// Represents a debug device. /// -public class DebugRGBDevice : AbstractRGBDevice, IUnknownDevice +public sealed class DebugRGBDevice : AbstractRGBDevice, IUnknownDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.Debug/DebugRGBDeviceInfo.cs b/RGB.NET.Devices.Debug/DebugRGBDeviceInfo.cs index d724e366..43e3c64a 100644 --- a/RGB.NET.Devices.Debug/DebugRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Debug/DebugRGBDeviceInfo.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.Debug; /// /// Represents device information for a />. /// -public class DebugRGBDeviceInfo : IRGBDeviceInfo +public sealed class DebugRGBDeviceInfo : IRGBDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs b/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs index 69cdce17..355e4573 100644 --- a/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs +++ b/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs @@ -14,7 +14,7 @@ namespace RGB.NET.Devices.Logitech.HID; /// /// The type of the identifier leds are mapped to. /// The type of the custom data added to the HID-device. -public class LightspeedHIDLoader : IEnumerable> +public sealed class LightspeedHIDLoader : IEnumerable> where TLed : notnull { #region Constants diff --git a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs index 7727006e..6a31dad3 100644 --- a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.Logitech; /// /// Represents a logitech per-device-lightable device. /// -public class LogitechPerDeviceRGBDevice : LogitechRGBDevice, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated +public sealed class LogitechPerDeviceRGBDevice : LogitechRGBDevice, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated { #region Properties & Fields diff --git a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs index c32f87d8..b780a283 100644 --- a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Logitech; /// /// Represents the update-queue performing updates for logitech per-device devices. /// -public class LogitechPerDeviceUpdateQueue : UpdateQueue +public sealed class LogitechPerDeviceUpdateQueue : UpdateQueue { #region Constructors diff --git a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs index 715079e3..edd3d950 100644 --- a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.Logitech; /// /// Represents a logitech per-key-lightable device. /// -public class LogitechPerKeyRGBDevice : LogitechRGBDevice, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated +public sealed class LogitechPerKeyRGBDevice : LogitechRGBDevice, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated { #region Properties & Fields diff --git a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs index b0bdaf49..7f1917f2 100644 --- a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Logitech; /// /// Represents the update-queue performing updates for logitech per-key devices. /// -public class LogitechPerKeyUpdateQueue : UpdateQueue +public sealed class LogitechPerKeyUpdateQueue : UpdateQueue { #region Constructors @@ -17,8 +17,7 @@ public class LogitechPerKeyUpdateQueue : UpdateQueue /// The update trigger used by this queue. public LogitechPerKeyUpdateQueue(IDeviceUpdateTrigger updateTrigger) : base(updateTrigger) - { - } + { } #endregion diff --git a/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs b/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs index 4909dcc6..d1050fd1 100644 --- a/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.Logitech; /// /// Represents a logitech zone-lightable device. /// -public class LogitechZoneRGBDevice : LogitechRGBDevice, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated +public sealed class LogitechZoneRGBDevice : LogitechRGBDevice, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated { #region Properties & Fields diff --git a/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs b/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs index eba7a2d9..c9a83a56 100644 --- a/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Logitech; /// /// Represents the update-queue performing updates for logitech zone devices. /// -public class LogitechZoneUpdateQueue : UpdateQueue +public sealed class LogitechZoneUpdateQueue : UpdateQueue { #region Properties & Fields diff --git a/RGB.NET.Devices.Msi/Exceptions/MysticLightException.cs b/RGB.NET.Devices.Msi/Exceptions/MysticLightException.cs index cf688e13..57044fbc 100644 --- a/RGB.NET.Devices.Msi/Exceptions/MysticLightException.cs +++ b/RGB.NET.Devices.Msi/Exceptions/MysticLightException.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Devices.Msi.Exceptions; /// /// Represents an exception thrown by the MysticLight-SDK. /// -public class MysticLightException : ApplicationException +public sealed class MysticLightException : ApplicationException { #region Properties & Fields diff --git a/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs b/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs index 8db204f5..0367029b 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Msi; /// /// Represents the update-queue performing updates for MSI devices. /// -public class MsiDeviceUpdateQueue : UpdateQueue +public sealed class MsiDeviceUpdateQueue : UpdateQueue { #region Properties & Fields diff --git a/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs index a4d72f15..efb72f66 100644 --- a/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs +++ b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Msi; /// /// Represents MSI VGA adapters. /// -public class MsiGraphicsCardRGBDevice : MsiRGBDevice, IGraphicsCard +public sealed class MsiGraphicsCardRGBDevice : MsiRGBDevice, IGraphicsCard { #region Constructors diff --git a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs index 113d364a..23676783 100644 --- a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Msi; /// /// Represents a MSI mainboard. /// -public class MsiMainboardRGBDevice : MsiRGBDevice, IMainboard +public sealed class MsiMainboardRGBDevice : MsiRGBDevice, IMainboard { #region Constructors diff --git a/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs b/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs index fc9adc87..5ebc73c6 100644 --- a/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Msi; /// /// Represents a MSI mouse. /// -public class MsiMouseRGBDevice : MsiRGBDevice +public sealed class MsiMouseRGBDevice : MsiRGBDevice { #region Constructors diff --git a/RGB.NET.Devices.Novation/Attributes/ColorCapabilityAttribute.cs b/RGB.NET.Devices.Novation/Attributes/ColorCapabilityAttribute.cs index d2c0a002..9d2131b8 100644 --- a/RGB.NET.Devices.Novation/Attributes/ColorCapabilityAttribute.cs +++ b/RGB.NET.Devices.Novation/Attributes/ColorCapabilityAttribute.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Novation.Attributes; /// Specifies the color-capability of a field. /// [AttributeUsage(AttributeTargets.Field)] -public class ColorCapabilityAttribute : Attribute +public sealed class ColorCapabilityAttribute : Attribute { #region Properties & Fields diff --git a/RGB.NET.Devices.Novation/Attributes/DeviceIdAttribute.cs b/RGB.NET.Devices.Novation/Attributes/DeviceIdAttribute.cs index 34c8b2e1..ee254858 100644 --- a/RGB.NET.Devices.Novation/Attributes/DeviceIdAttribute.cs +++ b/RGB.NET.Devices.Novation/Attributes/DeviceIdAttribute.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Novation.Attributes; /// Specifies the device-id of a field. /// [AttributeUsage(AttributeTargets.Field)] -public class DeviceIdAttribute : Attribute +public sealed class DeviceIdAttribute : Attribute { #region Properties & Fields diff --git a/RGB.NET.Devices.Novation/Attributes/LedIdMappingAttribute.cs b/RGB.NET.Devices.Novation/Attributes/LedIdMappingAttribute.cs index 1e5ac21b..14e22e10 100644 --- a/RGB.NET.Devices.Novation/Attributes/LedIdMappingAttribute.cs +++ b/RGB.NET.Devices.Novation/Attributes/LedIdMappingAttribute.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Novation.Attributes; /// Specifies the led id mapping of a field. /// [AttributeUsage(AttributeTargets.Field)] -internal class LedIdMappingAttribute : Attribute +internal sealed class LedIdMappingAttribute : Attribute { #region Properties & Fields diff --git a/RGB.NET.Devices.Novation/Generic/LimitedColorUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/LimitedColorUpdateQueue.cs index 9bb0bbe9..987b691e 100644 --- a/RGB.NET.Devices.Novation/Generic/LimitedColorUpdateQueue.cs +++ b/RGB.NET.Devices.Novation/Generic/LimitedColorUpdateQueue.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Novation; /// /// Represents the update-queue performing updates for a limited-color novation device. /// -public class LimitedColorUpdateQueue : MidiUpdateQueue +public sealed class LimitedColorUpdateQueue : MidiUpdateQueue { #region Constructors @@ -37,7 +37,7 @@ protected override ShortMessage CreateMessage(object key, in Color color) /// /// The to convert. /// The novation-representation of the . - protected virtual int ConvertColor(in Color color) + private static int ConvertColor(in Color color) { (double hue, double _, double value) = color.GetHSV(); diff --git a/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs index 5a3367a9..62795930 100644 --- a/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs +++ b/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.Novation; /// /// Represents the update-queue performing updates for a RGB-color novation device. /// -public class RGBColorUpdateQueue : MidiUpdateQueue +public sealed class RGBColorUpdateQueue : MidiUpdateQueue { #region Properties & Fields @@ -165,7 +165,7 @@ public RGBColorUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId) /// /// The to convert. /// The novation-representation of the . - protected virtual int ConvertColor(in Color color) + private static int ConvertColor(in Color color) { int bestVelocity = 0; double bestMatchDistance = double.MaxValue; diff --git a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs index 81e5dce2..0a5b6e10 100644 --- a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs +++ b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Novation; /// /// Represents a Novation launchpad. /// -public class NovationLaunchpadRGBDevice : NovationRGBDevice, ILedMatrix +public sealed class NovationLaunchpadRGBDevice : NovationRGBDevice, ILedMatrix { #region Constructors @@ -50,7 +50,7 @@ private void InitializeLayout() /// /// The mapping of the device. /// Thrown if the value of is not known. - protected virtual Dictionary GetDeviceMapping() + private Dictionary GetDeviceMapping() => DeviceInfo.LedMapping switch { LedIdMappings.Current => LaunchpadIdMapping.CURRENT, diff --git a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDeviceInfo.cs b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDeviceInfo.cs index 06296b95..2805da9b 100644 --- a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDeviceInfo.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.Novation; /// /// Represents a generic information for a . /// -public class NovationLaunchpadRGBDeviceInfo : NovationRGBDeviceInfo +public sealed class NovationLaunchpadRGBDeviceInfo : NovationRGBDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs index 9d2d8d22..837a82c4 100644 --- a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs +++ b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Devices.Novation; /// /// Represents a device provider responsible for Novation devices. /// -public class NovationDeviceProvider : AbstractRGBDeviceProvider +public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields diff --git a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs index 618c3101..7f51c81a 100644 --- a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs +++ b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs @@ -4,7 +4,7 @@ namespace RGB.NET.Devices.OpenRGB; /// -public class OpenRGBGenericDevice : AbstractOpenRGBDevice +public sealed class OpenRGBGenericDevice : AbstractOpenRGBDevice { #region Constructors /// diff --git a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs index ff4daa5f..0537d11b 100644 --- a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs +++ b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.OpenRGB; /// /// Represents the update-queue performing updates for OpenRGB devices. /// -public class OpenRGBUpdateQueue : UpdateQueue +public sealed class OpenRGBUpdateQueue : UpdateQueue { #region Properties & Fields diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs index c9d3cbc4..6c83a680 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.OpenRGB; /// /// Represents a device provider responsible for OpenRGB devices. /// -public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider +public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields @@ -162,8 +162,6 @@ public override void Dispose() _clients.Clear(); DeviceDefinitions.Clear(); Devices = Enumerable.Empty(); - - GC.SuppressFinalize(this); } #endregion } diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBServerDefinition.cs b/RGB.NET.Devices.OpenRGB/OpenRGBServerDefinition.cs index 9de92463..79437759 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBServerDefinition.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBServerDefinition.cs @@ -3,7 +3,7 @@ /// /// Represents a definition of an OpenRGB server. /// -public class OpenRGBServerDefinition +public sealed class OpenRGBServerDefinition { /// /// The name of the client that will appear in the OpenRGB interface. diff --git a/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs b/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs index 6def0927..1e3c4ff5 100644 --- a/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs +++ b/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs @@ -4,7 +4,7 @@ namespace RGB.NET.Devices.OpenRGB; /// -public class OpenRGBZoneDevice : AbstractOpenRGBDevice +public sealed class OpenRGBZoneDevice : AbstractOpenRGBDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs b/RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs index 9d8c6337..bc8e85e2 100644 --- a/RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs +++ b/RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs @@ -4,7 +4,7 @@ namespace RGB.NET.Devices.OpenRGB; /// -public class OpenRGBSegmentDevice : AbstractOpenRGBDevice +public sealed class OpenRGBSegmentDevice : AbstractOpenRGBDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs index 8cd251dd..edd290be 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiBulkUpdateQueue.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.PicoPi; /// /// Using this requires the libusb driver to be installed! /// -public class PicoPiBulkUpdateQueue : UpdateQueue +public sealed class PicoPiBulkUpdateQueue : UpdateQueue { #region Properties & Fields diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs index b3ff9565..652ba807 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiHIDUpdateQueue.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.PicoPi; /// /// Represents the update-queue performing updates for Pico-Pi HID-devices. /// -public class PicoPiHIDUpdateQueue : UpdateQueue +public sealed class PicoPiHIDUpdateQueue : UpdateQueue { #region Properties & Fields diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDevice.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDevice.cs index 486842d6..b50be7b9 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDevice.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDevice.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.PicoPi; /// /// Represents a device based on an Raspberry Pi Pico. /// -public class PicoPiRGBDevice : AbstractRGBDevice +public sealed class PicoPiRGBDevice : AbstractRGBDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDeviceInfo.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDeviceInfo.cs index ffe8e71a..52e3d796 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDeviceInfo.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiRGBDeviceInfo.cs @@ -5,7 +5,7 @@ namespace RGB.NET.Devices.PicoPi; /// /// Represents a generic information for a . /// -public class PicoPiRGBDeviceInfo : IRGBDeviceInfo +public sealed class PicoPiRGBDeviceInfo : IRGBDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs index a47916cd..2dcd6de4 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/PicoPiSDK.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Devices.PicoPi; /// /// Represents a SDK to access devices based on a Raspberry Pi Pico. /// -public class PicoPiSDK : IDisposable +public sealed class PicoPiSDK : IDisposable { #region Constants @@ -303,8 +303,6 @@ public void Dispose() _hidStream.Dispose(); _bulkDevice?.Dispose(); _usbContext?.Dispose(); - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs index bce7e9c7..f18116fa 100644 --- a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs +++ b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs @@ -15,7 +15,7 @@ namespace RGB.NET.Devices.PicoPi; /// Represents a device provider responsible for PicoPi-devices. /// // ReSharper disable once InconsistentNaming -public class PicoPiDeviceProvider : AbstractRGBDeviceProvider +public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider { #region Constants diff --git a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkRGBDevice.cs b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkRGBDevice.cs index 1dd5c70a..adc08f77 100644 --- a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkRGBDevice.cs +++ b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents a razer chroma link. /// -public class RazerChromaLinkRGBDevice : RazerRGBDevice, IUnknownDevice +public sealed class RazerChromaLinkRGBDevice : RazerRGBDevice, IUnknownDevice { #region Constructors diff --git a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs index 42755b95..3d63bf02 100644 --- a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents the update-queue performing updates for razer chroma-link devices. /// -public class RazerChromaLinkUpdateQueue : RazerUpdateQueue +public sealed class RazerChromaLinkUpdateQueue : RazerUpdateQueue { #region Constructors diff --git a/RGB.NET.Devices.Razer/Exceptions/RazerException.cs b/RGB.NET.Devices.Razer/Exceptions/RazerException.cs index 3350c811..ae9ad232 100644 --- a/RGB.NET.Devices.Razer/Exceptions/RazerException.cs +++ b/RGB.NET.Devices.Razer/Exceptions/RazerException.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents an exception thrown by the Razer-SDK. /// -public class RazerException : ApplicationException +public sealed class RazerException : ApplicationException { #region Properties & Fields diff --git a/RGB.NET.Devices.Razer/Generic/Devices.cs b/RGB.NET.Devices.Razer/Generic/Devices.cs deleted file mode 100644 index fb470551..00000000 --- a/RGB.NET.Devices.Razer/Generic/Devices.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace RGB.NET.Devices.Razer; - -internal class Devices -{ - public static readonly List<(Guid guid, string model)> KEYBOARDS = new() - { - (new Guid("2EA1BB63-CA28-428D-9F06-196B88330BBB"), "Blackwidow Chroma"), - (new Guid("ED1C1B82-BFBE-418F-B49D-D03F05B149DF"), "Razer Blackwidow Chroma Tournament Edition"), - (new Guid("18C5AD9B-4326-4828-92C4-2669A66D2283"), "Razer Deathstalker "), - (new Guid("872AB2A9-7959-4478-9FED-15F6186E72E4"), "Overwatch Keyboard"), - (new Guid("5AF60076-ADE9-43D4-B574-52599293B554"), "Razer Blackwidow X Chroma"), - (new Guid("2D84DD51-3290-4AAC-9A89-D8AFDE38B57C"), "Razer Blackwidow X TE Chroma"), - (new Guid("803378C1-CC48-4970-8539-D828CC1D420A"), "Razer Omata Chroma"), - (new Guid("C83BDFE8-E7FC-40E0-99DB-872E23F19891"), "Razer Blade Stealth"), - (new Guid("F2BEDFAF-A0FE-4651-9D41-B6CE603A3DDD"), "Razer Blade"), - (new Guid("A73AC338-F0E5-4BF7-91AE-DD1F7E1737A5"), "Razer Blade Pro"), - (new Guid("608E743F-B402-44BD-A7A6-7AA9F574ECF4"), "Razer Blackwidow Chroma v2"), - (new Guid("F85E7473-8F03-45B6-A16E-CE26CB8D2441"), "Razer Huntsman"), - (new Guid("16BB5ABD-C1CD-4CB3-BDF7-62438748BD98"), "Razer Blackwidow Elite") - }; - - public static readonly List<(Guid guid, string model)> MICE = new() - { - (new Guid("7EC00450-E0EE-4289-89D5-0D879C19061A"), "Razer Mamba Chroma Tournament Edition"), - (new Guid("AEC50D91-B1F1-452F-8E16-7B73F376FDF3"), "Razer Deathadder Chroma "), - (new Guid("FF8A5929-4512-4257-8D59-C647BF9935D0"), "Razer Diamondback"), - (new Guid("D527CBDC-EB0A-483A-9E89-66D50463EC6C"), "Razer Mamba"), - (new Guid("D714C50B-7158-4368-B99C-601ACB985E98"), "Razer Naga Epic"), - (new Guid("F1876328-6CA4-46AE-BE04-BE812B414433"), "Razer Naga"), - (new Guid("52C15681-4ECE-4DD9-8A52-A1418459EB34"), "Razer Orochi Chroma"), - (new Guid("195D70F5-F285-4CFF-99F2-B8C0E9658DB4"), "Razer Naga Hex Chroma"), - (new Guid("77834867-3237-4A9F-AD77-4A46C4183003"), "Razer DeathAdder Elite Chroma") - }; - - public static readonly List<(Guid guid, string model)> HEADSETS = new() - { - (new Guid("DF3164D7-5408-4A0E-8A7F-A7412F26BEBF"), "Razer ManO'War"), - (new Guid("CD1E09A5-D5E6-4A6C-A93B-E6D9BF1D2092"), "Razer Kraken 7.1 Chroma"), - (new Guid("7FB8A36E-9E74-4BB3-8C86-CAC7F7891EBD"), "Razer Kraken 7.1 Chroma Refresh"), - (new Guid("FB357780-4617-43A7-960F-D1190ED54806"), "Razer Kraken Kitty") - }; - - public static readonly List<(Guid guid, string model)> MOUSEMATS = new() - { - (new Guid("80F95A94-73D2-48CA-AE9A-0986789A9AF2"), "Razer Firefly") - }; - - public static readonly List<(Guid guid, string model)> KEYPADS = new() - { - (new Guid("9D24B0AB-0162-466C-9640-7A924AA4D9FD"), "Razer Orbweaver"), - (new Guid("00F0545C-E180-4AD1-8E8A-419061CE505E"), "Razer Tartarus") - }; - - public static readonly List<(Guid guid, string model)> CHROMALINKS = new() - { - (new Guid("0201203B-62F3-4C50-83DD-598BABD208E0"), "Core Chroma"), - (new Guid("35F6F18D-1AE5-436C-A575-AB44A127903A"), "Lenovo Y900"), - (new Guid("47DB1FA7-6B9B-4EE6-B6F4-4071A3B2053B"), "Lenovo Y27"), - (new Guid("BB2E9C9B-B0D2-461A-BA52-230B5D6C3609"), "Chroma Box") - }; - - public static readonly List<(Guid guid, string model)> SPEAKERS = new() - { - (new Guid("45B308F2-CD44-4594-8375-4D5945AD880E"), "Nommo Chroma"), - (new Guid("3017280B-D7F9-4D7B-930E-7B47181B46B5"), "Nommo Chroma Pro") - }; -} \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDevice.cs b/RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDevice.cs index cec7f087..2b61b357 100644 --- a/RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents a razer headset. /// -public class RazerHeadsetRGBDevice : RazerRGBDevice, IHeadset +public sealed class RazerHeadsetRGBDevice : RazerRGBDevice, IHeadset { #region Constructors diff --git a/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs b/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs index 9cb3eaf5..24cc57be 100644 --- a/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents the update-queue performing updates for razer headset devices. /// -public class RazerHeadsetUpdateQueue : RazerUpdateQueue +public sealed class RazerHeadsetUpdateQueue : RazerUpdateQueue { #region Constructors diff --git a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDevice.cs b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDevice.cs index 3a4c5f24..1a5cbfb0 100644 --- a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents a razer keyboard. /// -public class RazerKeyboardRGBDevice : RazerRGBDevice, IKeyboard +public sealed class RazerKeyboardRGBDevice : RazerRGBDevice, IKeyboard { #region Properties & Fields diff --git a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs index 983d030a..2a369f37 100644 --- a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents a generic information for a . /// -public class RazerKeyboardRGBDeviceInfo : RazerRGBDeviceInfo, IKeyboardDeviceInfo +public sealed class RazerKeyboardRGBDeviceInfo : RazerRGBDeviceInfo, IKeyboardDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs index 09b8c2d9..b351d5fa 100644 --- a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents the update-queue performing updates for razer keyboard devices. /// -public class RazerKeyboardUpdateQueue : RazerUpdateQueue +public sealed class RazerKeyboardUpdateQueue : RazerUpdateQueue { #region Constructors diff --git a/RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDevice.cs b/RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDevice.cs index f620388e..6c1c2446 100644 --- a/RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents a razer keypad. /// -public class RazerKeypadRGBDevice : RazerRGBDevice, IKeypad +public sealed class RazerKeypadRGBDevice : RazerRGBDevice, IKeypad { #region Constructors diff --git a/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs b/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs index 2b6dcc6d..9b6908ae 100644 --- a/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents the update-queue performing updates for razer keypad devices. /// -public class RazerKeypadUpdateQueue : RazerUpdateQueue +public sealed class RazerKeypadUpdateQueue : RazerUpdateQueue { #region Constructors diff --git a/RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDevice.cs b/RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDevice.cs index 14334493..fe00b6c9 100644 --- a/RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents a razer mouse. /// -public class RazerMouseRGBDevice : RazerRGBDevice, IMouse +public sealed class RazerMouseRGBDevice : RazerRGBDevice, IMouse { #region Properties & Fields diff --git a/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs b/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs index 5a50911e..22295d0a 100644 --- a/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents the update-queue performing updates for razer mouse devices. /// -public class RazerMouseUpdateQueue : RazerUpdateQueue +public sealed class RazerMouseUpdateQueue : RazerUpdateQueue { #region Constructors diff --git a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDevice.cs b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDevice.cs index af47df3a..33932c4f 100644 --- a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents a razer mousepad. /// -public class RazerMousepadRGBDevice : RazerRGBDevice, IMousepad +public sealed class RazerMousepadRGBDevice : RazerRGBDevice, IMousepad { #region Constructors diff --git a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs index 3b01b672..57d912af 100644 --- a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents the update-queue performing updates for razer mousepad devices. /// -public class RazerMousepadUpdateQueue : RazerUpdateQueue +public sealed class RazerMousepadUpdateQueue : RazerUpdateQueue { #region Constructors diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 04edecc8..313ef089 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -15,7 +15,7 @@ namespace RGB.NET.Devices.Razer; /// /// Represents a device provider responsible for razer devices. /// -public class RazerDeviceProvider : AbstractRGBDeviceProvider +public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields @@ -308,8 +308,6 @@ public override void Dispose() // DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit //try { _RazerSDK.UnloadRazerSDK(); } //catch { /* at least we tried */ } - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.SteelSeries/API/Model/CoreProps.cs b/RGB.NET.Devices.SteelSeries/API/Model/CoreProps.cs index c5cc9709..8e74d0e9 100644 --- a/RGB.NET.Devices.SteelSeries/API/Model/CoreProps.cs +++ b/RGB.NET.Devices.SteelSeries/API/Model/CoreProps.cs @@ -2,7 +2,7 @@ namespace RGB.NET.Devices.SteelSeries.API.Model; -internal class CoreProps +internal sealed class CoreProps { [JsonPropertyName("address")] public string? Address { get; set; } diff --git a/RGB.NET.Devices.SteelSeries/API/Model/Event.cs b/RGB.NET.Devices.SteelSeries/API/Model/Event.cs index 4aa335e5..2862e941 100644 --- a/RGB.NET.Devices.SteelSeries/API/Model/Event.cs +++ b/RGB.NET.Devices.SteelSeries/API/Model/Event.cs @@ -3,7 +3,7 @@ namespace RGB.NET.Devices.SteelSeries.API.Model; -internal class Event +internal sealed class Event { #region Properties & Fields diff --git a/RGB.NET.Devices.SteelSeries/API/Model/Game.cs b/RGB.NET.Devices.SteelSeries/API/Model/Game.cs index b22cb1f8..081d3dd2 100644 --- a/RGB.NET.Devices.SteelSeries/API/Model/Game.cs +++ b/RGB.NET.Devices.SteelSeries/API/Model/Game.cs @@ -2,7 +2,7 @@ namespace RGB.NET.Devices.SteelSeries.API.Model; -internal class Game +internal sealed class Game { #region Properties & Fields diff --git a/RGB.NET.Devices.SteelSeries/API/Model/GoLispHandler.cs b/RGB.NET.Devices.SteelSeries/API/Model/GoLispHandler.cs index 3cd2ec4c..1c6dba1d 100644 --- a/RGB.NET.Devices.SteelSeries/API/Model/GoLispHandler.cs +++ b/RGB.NET.Devices.SteelSeries/API/Model/GoLispHandler.cs @@ -2,7 +2,7 @@ namespace RGB.NET.Devices.SteelSeries.API.Model; -internal class GoLispHandler +internal sealed class GoLispHandler { #region Properties & Fields diff --git a/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs b/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs index dbf99311..d500a536 100644 --- a/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs +++ b/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs @@ -1,6 +1,6 @@ namespace RGB.NET.Devices.SteelSeries; -internal class APIName : System.Attribute +internal sealed class APIName : System.Attribute { #region Properties & Fields diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs index 26d744d9..c85f3946 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.SteelSeries; /// /// Represents the update-queue performing updates for steelseries devices. /// -internal class SteelSeriesDeviceUpdateQueue : UpdateQueue +internal sealed class SteelSeriesDeviceUpdateQueue : UpdateQueue { #region Properties & Fields diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs index f85213bf..86b1bdf9 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.SteelSeries; /// /// Represents a SteelSeries-device. (keyboard, mouse, headset, mousepad). /// -public class SteelSeriesRGBDevice : AbstractRGBDevice, ISteelSeriesRGBDevice, IUnknownDevice//TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated +public sealed class SteelSeriesRGBDevice : AbstractRGBDevice, ISteelSeriesRGBDevice, IUnknownDevice//TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated { #region Properties & Fields diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDeviceInfo.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDeviceInfo.cs index fe1f747b..0ceebba3 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDeviceInfo.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDeviceInfo.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Devices.SteelSeries; /// /// Represents a generic information for a SteelSeries-. /// -public class SteelSeriesRGBDeviceInfo : IRGBDeviceInfo +public sealed class SteelSeriesRGBDeviceInfo : IRGBDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs index ee155334..417a4489 100644 --- a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs +++ b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs @@ -10,11 +10,11 @@ namespace RGB.NET.Devices.SteelSeries; /// /// Represents a device provider responsible for SteelSeries-devices. /// -public class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider +public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider { #region Constants - private static readonly int HEARTBEAT_TIMER = 5000; // flush the device every 5 seconds to prevent timeouts + private const int HEARTBEAT_TIMER = 5000; // flush the device every 5 seconds to prevent timeouts #endregion @@ -137,8 +137,6 @@ public override void Dispose() try { SteelSeriesSDK.Dispose(); } catch { /* shit happens */ } - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs index 4f2bf090..a22502e3 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs @@ -11,7 +11,7 @@ namespace RGB.NET.Devices.WS281X.Arduino; /// /// Represents an arduino WS2812 device. /// -public class ArduinoWS2812USBDevice : AbstractRGBDevice, ILedStripe +public sealed class ArduinoWS2812USBDevice : AbstractRGBDevice, ILedStripe { #region Properties & Fields /// diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDeviceInfo.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDeviceInfo.cs index fede95cc..a03fdf0c 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDeviceInfo.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDeviceInfo.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.WS281X.Arduino; /// /// Represents a generic information for a . /// -public class ArduinoWS2812USBDeviceInfo : IRGBDeviceInfo +public sealed class ArduinoWS2812USBDeviceInfo : IRGBDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs index 603b6f5f..2d035ff1 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Devices.WS281X.Arduino; /// /// Represents the update-queue performing updates for arduino WS2812 devices. /// -public class ArduinoWS2812USBUpdateQueue : SerialConnectionUpdateQueue +public sealed class ArduinoWS2812USBUpdateQueue : SerialConnectionUpdateQueue { #region Constants diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs index 612596d7..e3d25456 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.WS281X.Arduino; /// /// Represents a definition of an arduino WS2812 devices. /// -public class ArduinoWS281XDeviceDefinition : IWS281XDeviceDefinition +public sealed class ArduinoWS281XDeviceDefinition : IWS281XDeviceDefinition { #region Properties & Fields diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs index 1dc38cd7..94d74790 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs @@ -10,7 +10,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard; /// /// Represents an bitwizard WS2812 USB device. /// -public class BitwizardWS2812USBDevice : AbstractRGBDevice, ILedStripe +public sealed class BitwizardWS2812USBDevice : AbstractRGBDevice, ILedStripe { #region Properties & Fields diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDeviceInfo.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDeviceInfo.cs index 65f00541..3e911b74 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDeviceInfo.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDeviceInfo.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard; /// /// Represents a generic information for a . /// -public class BitwizardWS2812USBDeviceInfo : IRGBDeviceInfo +public sealed class BitwizardWS2812USBDeviceInfo : IRGBDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs index cb0ef7b1..b970b54a 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard; /// /// Represents the update-queue performing updates for a bitwizard WS2812 device. /// -public class BitwizardWS2812USBUpdateQueue : SerialConnectionUpdateQueue +public sealed class BitwizardWS2812USBUpdateQueue : SerialConnectionUpdateQueue { #region Constructors diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs index 3da22034..131a879f 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard; /// /// Represents a definition of an bitwizard WS2812 devices. /// -public class BitwizardWS281XDeviceDefinition : IWS281XDeviceDefinition +public sealed class BitwizardWS281XDeviceDefinition : IWS281XDeviceDefinition { #region Properties & Fields diff --git a/RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs b/RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs index f581e3f3..7004a30d 100644 --- a/RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs +++ b/RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs @@ -1,5 +1,4 @@ -using System; -using System.IO.Ports; +using System.IO.Ports; namespace RGB.NET.Devices.WS281X; @@ -7,7 +6,7 @@ namespace RGB.NET.Devices.WS281X; /// /// Represents a serial-connection using the default microsoft serial-port implementation. /// -public class SerialPortConnection : ISerialConnection +public sealed class SerialPortConnection : ISerialConnection { #region Properties & Fields @@ -65,8 +64,6 @@ public SerialPortConnection(string port, int baudRate) public void Dispose() { SerialPort.Dispose(); - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs index 8c55f6b0..f297a603 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU; /// /// Represents an NodeMCU WS2812 device. /// -public class NodeMCUWS2812USBDevice : AbstractRGBDevice, ILedStripe +public sealed class NodeMCUWS2812USBDevice : AbstractRGBDevice, ILedStripe { #region Properties & Fields diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs index 0caf3b6c..d36813f7 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs @@ -7,7 +7,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU; /// /// Represents a generic information for a . /// -public class NodeMCUWS2812USBDeviceInfo : IRGBDeviceInfo +public sealed class NodeMCUWS2812USBDeviceInfo : IRGBDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs index 9e6d30ee..a78343c5 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs @@ -14,7 +14,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU; /// /// Represents the update-queue performing updates for NodeMCU WS2812 devices. /// -public class NodeMCUWS2812USBUpdateQueue : UpdateQueue +public sealed class NodeMCUWS2812USBUpdateQueue : UpdateQueue { #region Properties & Fields @@ -183,8 +183,6 @@ public override void Dispose() ResetDevice(); _httpClient.Dispose(); } - - GC.SuppressFinalize(this); } private string GetUrl(string path) => $"http://{_hostname}/{path}"; diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs index 0f68f2be..a3451198 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU; /// /// Represents a definition of an NodeMCU WS2812 devices. /// -public class NodeMCUWS281XDeviceDefinition : IWS281XDeviceDefinition +public sealed class NodeMCUWS281XDeviceDefinition : IWS281XDeviceDefinition { #region Properties & Fields diff --git a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs index 6a5c49d8..4d2e047e 100644 --- a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs +++ b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.WS281X; /// // ReSharper disable once InconsistentNaming // ReSharper disable once UnusedType.Global -public class WS281XDeviceProvider : AbstractRGBDeviceProvider +public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields @@ -75,8 +75,6 @@ public override void Dispose() base.Dispose(); DeviceDefinitions.Clear(); - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs b/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs index 3791ba06..8a3012eb 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs @@ -8,10 +8,12 @@ namespace RGB.NET.Devices.Wooting.Generic; /// /// Represents the update-queue performing updates for cooler master devices. /// -public class WootingUpdateQueue : UpdateQueue +public sealed class WootingUpdateQueue : UpdateQueue { #region Properties & Fields + private readonly byte _deviceid; + #endregion #region Constructors diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs index 0f5882ca..79e1bafd 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using RGB.NET.Core; using RGB.NET.Devices.Wooting.Generic; using RGB.NET.Devices.Wooting.Native; @@ -10,7 +9,7 @@ namespace RGB.NET.Devices.Wooting.Keyboard; /// /// Represents a Wooting keyboard. /// -public class WootingKeyboardRGBDevice : WootingRGBDevice, IKeyboard +public sealed class WootingKeyboardRGBDevice : WootingRGBDevice, IKeyboard { #region Properties & Fields @@ -53,8 +52,6 @@ public override void Dispose() _WootingSDK.Reset(); base.Dispose(); - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs index dfcc8eb5..e3f8bbf5 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.Wooting.Keyboard; /// /// Represents a generic information for a . /// -public class WootingKeyboardRGBDeviceInfo : WootingRGBDeviceInfo, IKeyboardDeviceInfo +public sealed class WootingKeyboardRGBDeviceInfo : WootingRGBDeviceInfo, IKeyboardDeviceInfo { #region Properties & Fields diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index aebe9c05..484bbaf0 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.Wooting; /// /// Represents a device provider responsible for Wooting devices. /// -public class WootingDeviceProvider : AbstractRGBDeviceProvider +public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields @@ -103,8 +103,6 @@ public override void Dispose() try { _WootingSDK.UnloadWootingSDK(); } catch { /* at least we tried */ } } - - GC.SuppressFinalize(this); } #endregion diff --git a/RGB.NET.HID/HIDLoader.cs b/RGB.NET.HID/HIDLoader.cs index b0ecfe7a..b39df671 100644 --- a/RGB.NET.HID/HIDLoader.cs +++ b/RGB.NET.HID/HIDLoader.cs @@ -19,7 +19,7 @@ public record HIDDeviceDefinition(int ProductId, RGBDeviceType Devi /// /// The type of the identifier leds are mapped to. /// The type of the custom data added to the HID-device. -public class HIDLoader : IEnumerable> +public sealed class HIDLoader : IEnumerable> where TLed : notnull { #region Properties & Fields diff --git a/RGB.NET.Presets/Decorators/FlashDecorator.cs b/RGB.NET.Presets/Decorators/FlashDecorator.cs index 64794b5c..e30a5f28 100644 --- a/RGB.NET.Presets/Decorators/FlashDecorator.cs +++ b/RGB.NET.Presets/Decorators/FlashDecorator.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Presets.Decorators; /// /// Represents a decorator which allows to flash a brush by modifying his opacity. /// -public class FlashDecorator : AbstractUpdateAwareDecorator, IBrushDecorator +public sealed class FlashDecorator : AbstractUpdateAwareDecorator, IBrushDecorator { #region Properties & Fields diff --git a/RGB.NET.Presets/Groups/RectangleLedGroup.cs b/RGB.NET.Presets/Groups/RectangleLedGroup.cs index cf668483..62a59acb 100644 --- a/RGB.NET.Presets/Groups/RectangleLedGroup.cs +++ b/RGB.NET.Presets/Groups/RectangleLedGroup.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Presets.Groups; /// /// Represents a containing which physically lay inside a . /// -public class RectangleLedGroup : AbstractLedGroup +public sealed class RectangleLedGroup : AbstractLedGroup { #region Properties & Fields diff --git a/RGB.NET.Presets/Textures/Gradients/GradientStop.cs b/RGB.NET.Presets/Textures/Gradients/GradientStop.cs index d7aa5361..75b98422 100644 --- a/RGB.NET.Presets/Textures/Gradients/GradientStop.cs +++ b/RGB.NET.Presets/Textures/Gradients/GradientStop.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Presets.Textures.Gradients; /// /// Represents a stop on a gradient. /// -public class GradientStop : AbstractBindable +public sealed class GradientStop : AbstractBindable { #region Properties & Fields diff --git a/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs b/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs index 29a732a6..18fa2521 100644 --- a/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs +++ b/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs @@ -11,12 +11,12 @@ namespace RGB.NET.Presets.Textures.Gradients; /// /// Represents a linear interpolated gradient with n stops. /// -public class LinearGradient : AbstractGradient +public sealed class LinearGradient : AbstractGradient { #region Properties & Fields private bool _isOrderedGradientListDirty = true; - private LinkedList _orderedGradientStops = new(); + private readonly List _orderedGradientStops = new(); #endregion @@ -89,7 +89,10 @@ public override Color GetColor(float offset) if (GradientStops.Count == 1) return GradientStops[0].Color; if (_isOrderedGradientListDirty) - _orderedGradientStops = new LinkedList(GradientStops.OrderBy(x => x.Offset)); + { + _orderedGradientStops.Clear(); + _orderedGradientStops.AddRange(GradientStops.OrderBy(x => x.Offset)); + } (GradientStop gsBefore, GradientStop gsAfter) = GetEnclosingGradientStops(offset, _orderedGradientStops, WrapGradient); @@ -112,7 +115,7 @@ public override Color GetColor(float offset) /// The ordered list of to choose from. /// Bool indicating if the gradient should be wrapped or not. /// The two s encapsulating the specified offset. - protected virtual (GradientStop gsBefore, GradientStop gsAfter) GetEnclosingGradientStops(float offset, LinkedList orderedStops, bool wrap) + private (GradientStop gsBefore, GradientStop gsAfter) GetEnclosingGradientStops(float offset, IEnumerable orderedStops, bool wrap) { LinkedList gradientStops = new(orderedStops); diff --git a/RGB.NET.Presets/Textures/Gradients/RainbowGradient.cs b/RGB.NET.Presets/Textures/Gradients/RainbowGradient.cs index 46c1e5b1..177997ab 100644 --- a/RGB.NET.Presets/Textures/Gradients/RainbowGradient.cs +++ b/RGB.NET.Presets/Textures/Gradients/RainbowGradient.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Presets.Textures.Gradients; /// Represents a rainbow gradient which circles through all colors of the HUE-color-space.
/// See as reference. /// -public class RainbowGradient : AbstractDecoratable, IGradient +public sealed class RainbowGradient : AbstractDecoratable, IGradient { #region Properties & Fields @@ -102,7 +102,7 @@ public void Move(float offset) /// /// Should be called to indicate that the gradient was changed. /// - protected void OnGradientChanged() => GradientChanged?.Invoke(this, EventArgs.Empty); + private void OnGradientChanged() => GradientChanged?.Invoke(this, EventArgs.Empty); #endregion } \ No newline at end of file diff --git a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs index 8d5b8b6d..349afd77 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Presets.Textures.Sampler; /// /// Represents a sampled that averages multiple byte-data entries. /// -public class AverageByteSampler : ISampler +public sealed class AverageByteSampler : ISampler { #region Constants diff --git a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs index 50e95638..d53ad5db 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Presets.Textures.Sampler; /// /// Represents a sampled that averages multiple float-data entries. /// -public class AverageFloatSampler : ISampler +public sealed class AverageFloatSampler : ISampler { #region Methods From e8f168f64ab9b112996028e85fcbb981ff0b9c11 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 19 Apr 2023 22:15:27 +0200 Subject: [PATCH 38/96] Removed .NET 5 artifacts from build --- .github/workflows/ci.yml | 6 ------ .github/workflows/release.yml | 6 ------ 2 files changed, 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd005ceb..36bab7a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,12 +33,6 @@ jobs: run: dotnet build --no-restore --configuration Release /p:Version=${{ steps.versioning.outputs.version }} - name: Test run: dotnet test --no-build --verbosity normal --configuration Release - - name: Upload a Build Artifact NET5 - uses: actions/upload-artifact@v2.2.4 - with: - name: RGB.NET-NET5 - path: bin/net5.0/RGB.NET.*.dll - if-no-files-found: error - name: Upload a Build Artifact NET6 uses: actions/upload-artifact@v2.2.4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f5e9cce6..121fb301 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,12 +32,6 @@ jobs: run: dotnet build --no-restore --configuration Release /p:Version=${{ steps.versioning.outputs.version }} - name: Test run: dotnet test --no-build --verbosity normal --configuration Release - - name: Upload a Build Artifact NET5 - uses: actions/upload-artifact@v2.2.4 - with: - name: RGB.NET-NET5 - path: bin/net5.0/RGB.NET.*.dll - if-no-files-found: error - name: Upload a Build Artifact NET6 uses: actions/upload-artifact@v2.2.4 with: From af3989aa7317857773015a169a970c0a63ba6b71 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 23 Apr 2023 12:16:38 +0200 Subject: [PATCH 39/96] Added Test for the PixelTexture --- .../RGB.NET.Core.Tests/Helper/SimplexNoise.cs | 354 ++++++++++++++++++ .../Texture/PixelTextureTest.cs | 61 +++ 2 files changed, 415 insertions(+) create mode 100644 Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs create mode 100644 Tests/RGB.NET.Core.Tests/Texture/PixelTextureTest.cs diff --git a/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs new file mode 100644 index 00000000..aa756d67 --- /dev/null +++ b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs @@ -0,0 +1,354 @@ +using System; + +namespace RGB.NET.Core.Tests.Helper; + +// Simplex Noise for C# +// Copyright © Benjamin Ward 2019 +// See LICENSE +// Simplex Noise implementation offering 1D, 2D, and 3D forms w/ values in the range of 0 to 255. +// Based on work by Heikki Törmälä (2012) and Stefan Gustavson (2006). + +/// +/// Implementation of the Perlin simplex noise, an improved Perlin noise algorithm. +/// Based loosely on SimplexNoise1234 by Stefan Gustavson: http://staffwww.itn.liu.se/~stegu/aqsis/aqsis-newnoise/ +/// +public static class SimplexNoise +{ + public static float[] Calc1D(int width, float scale) + { + float[] values = new float[width]; + for (int i = 0; i < width; i++) + values[i] = Generate(i * scale); + return values; + } + + public static float[,] Calc2D(int width, int height, float scale) + { + float[,] values = new float[width, height]; + for (int i = 0; i < width; i++) + for (int j = 0; j < height; j++) + values[i, j] = Generate(i * scale, j * scale); + return values; + } + + public static float[,,] Calc3D(int width, int height, int length, float scale) + { + float[,,] values = new float[width, height, length]; + for (int i = 0; i < width; i++) + for (int j = 0; j < height; j++) + for (int k = 0; k < length; k++) + values[i, j, k] = Generate(i * scale, j * scale, k * scale); + return values; + } + + public static float CalcPixel1D(int x, float scale) => Generate(x * scale); + public static float CalcPixel2D(int x, int y, float scale) => Generate(x * scale, y * scale); + public static float CalcPixel3D(int x, int y, int z, float scale) => Generate(x * scale, y * scale, z * scale); + + static SimplexNoise() + { + _perm = new byte[PermOriginal.Length]; + PermOriginal.CopyTo(_perm, 0); + } + + public static int Seed + { + get => _seed; + set + { + if (value == 0) + { + _perm = new byte[PermOriginal.Length]; + PermOriginal.CopyTo(_perm, 0); + } + else + { + _perm = new byte[512]; + Random random = new Random(value); + random.NextBytes(_perm); + } + + _seed = value; + } + } + + private static int _seed; + + /// + /// 1D simplex noise + /// + /// + /// + private static float Generate(float x) + { + int i0 = FastFloor(x); + int i1 = i0 + 1; + float x0 = x - i0; + float x1 = x0 - 1.0f; + + float t0 = 1.0f - (x0 * x0); + t0 *= t0; + float n0 = t0 * t0 * Grad(_perm[i0 & 0xff], x0); + + float t1 = 1.0f - (x1 * x1); + t1 *= t1; + float n1 = t1 * t1 * Grad(_perm[i1 & 0xff], x1); + // The maximum value of this noise is 8*(3/4)^4 = 2.53125 + // A factor of 0.395 scales to fit exactly within [-1,1] + return 0.395f * (n0 + n1); + } + + /// + /// 2D simplex noise + /// + /// + /// + /// + private static float Generate(float x, float y) + { + const float F2 = 0.366025403f; // F2 = 0.5*(sqrt(3.0)-1.0) + const float G2 = 0.211324865f; // G2 = (3.0-Math.sqrt(3.0))/6.0 + + float n0, n1, n2; // Noise contributions from the three corners + + // Skew the input space to determine which simplex cell we're in + float s = (x + y) * F2; // Hairy factor for 2D + float xs = x + s; + float ys = y + s; + int i = FastFloor(xs); + int j = FastFloor(ys); + + float t = (i + j) * G2; + float X0 = i - t; // Unskew the cell origin back to (x,y) space + float Y0 = j - t; + float x0 = x - X0; // The x,y distances from the cell origin + float y0 = y - Y0; + + // For the 2D case, the simplex shape is an equilateral triangle. + // Determine which simplex we are in. + int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords + if (x0 > y0) { i1 = 1; j1 = 0; } // lower triangle, XY order: (0,0)->(1,0)->(1,1) + else { i1 = 0; j1 = 1; } // upper triangle, YX order: (0,0)->(0,1)->(1,1) + + // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and + // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where + // c = (3-sqrt(3))/6 + + float x1 = (x0 - i1) + G2; // Offsets for middle corner in (x,y) unskewed coords + float y1 = (y0 - j1) + G2; + float x2 = (x0 - 1.0f) + (2.0f * G2); // Offsets for last corner in (x,y) unskewed coords + float y2 = (y0 - 1.0f) + (2.0f * G2); + + // Wrap the integer indices at 256, to avoid indexing perm[] out of bounds + int ii = Mod(i, 256); + int jj = Mod(j, 256); + + // Calculate the contribution from the three corners + float t0 = 0.5f - (x0 * x0) - (y0 * y0); + if (t0 < 0.0f) n0 = 0.0f; + else + { + t0 *= t0; + n0 = t0 * t0 * Grad(_perm[ii + _perm[jj]], x0, y0); + } + + float t1 = 0.5f - (x1 * x1) - (y1 * y1); + if (t1 < 0.0f) n1 = 0.0f; + else + { + t1 *= t1; + n1 = t1 * t1 * Grad(_perm[ii + i1 + _perm[jj + j1]], x1, y1); + } + + float t2 = 0.5f - (x2 * x2) - (y2 * y2); + if (t2 < 0.0f) n2 = 0.0f; + else + { + t2 *= t2; + n2 = t2 * t2 * Grad(_perm[ii + 1 + _perm[jj + 1]], x2, y2); + } + + // Add contributions from each corner to get the final noise value. + // The result is scaled to return values in the interval [-1,1]. + return 40.0f * (n0 + n1 + n2); // TODO: The scale factor is preliminary! + } + + + private static float Generate(float x, float y, float z) + { + // Simple skewing factors for the 3D case + const float F3 = 0.333333333f; + const float G3 = 0.166666667f; + + float n0, n1, n2, n3; // Noise contributions from the four corners + + // Skew the input space to determine which simplex cell we're in + float s = (x + y + z) * F3; // Very nice and simple skew factor for 3D + float xs = x + s; + float ys = y + s; + float zs = z + s; + int i = FastFloor(xs); + int j = FastFloor(ys); + int k = FastFloor(zs); + + float t = (i + j + k) * G3; + float X0 = i - t; // Unskew the cell origin back to (x,y,z) space + float Y0 = j - t; + float Z0 = k - t; + float x0 = x - X0; // The x,y,z distances from the cell origin + float y0 = y - Y0; + float z0 = z - Z0; + + // For the 3D case, the simplex shape is a slightly irregular tetrahedron. + // Determine which simplex we are in. + int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords + int i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords + + /* This code would benefit from a backport from the GLSL version! */ + if (x0 >= y0) + { + if (y0 >= z0) + { i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 1; k2 = 0; } // X Y Z order + else if (x0 >= z0) { i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 0; k2 = 1; } // X Z Y order + else { i1 = 0; j1 = 0; k1 = 1; i2 = 1; j2 = 0; k2 = 1; } // Z X Y order + } + else + { // x0 0) ? ((int)x) : (((int)x) - 1); + } + + private static int Mod(int x, int m) + { + int a = x % m; + return a < 0 ? a + m : a; + } + + private static float Grad(int hash, float x) + { + int h = hash & 15; + float grad = 1.0f + (h & 7); // Gradient value 1.0, 2.0, ..., 8.0 + if ((h & 8) != 0) grad = -grad; // Set a random sign for the gradient + return (grad * x); // Multiply the gradient with the distance + } + + private static float Grad(int hash, float x, float y) + { + int h = hash & 7; // Convert low 3 bits of hash code + float u = h < 4 ? x : y; // into 8 simple gradient directions, + float v = h < 4 ? y : x; // and compute the dot product with (x,y). + return ((h & 1) != 0 ? -u : u) + ((h & 2) != 0 ? -2.0f * v : 2.0f * v); + } + + private static float Grad(int hash, float x, float y, float z) + { + int h = hash & 15; // Convert low 4 bits of hash code into 12 simple + float u = h < 8 ? x : y; // gradient directions, and compute dot product. + float v = h < 4 ? y : (h == 12) || (h == 14) ? x : z; // Fix repeats at h = 12 to 15 + return ((h & 1) != 0 ? -u : u) + ((h & 2) != 0 ? -v : v); + } + + private static float Grad(int hash, float x, float y, float z, float t) + { + int h = hash & 31; // Convert low 5 bits of hash code into 32 simple + float u = h < 24 ? x : y; // gradient directions, and compute dot product. + float v = h < 16 ? y : z; + float w = h < 8 ? z : t; + return ((h & 1) != 0 ? -u : u) + ((h & 2) != 0 ? -v : v) + ((h & 4) != 0 ? -w : w); + } +} diff --git a/Tests/RGB.NET.Core.Tests/Texture/PixelTextureTest.cs b/Tests/RGB.NET.Core.Tests/Texture/PixelTextureTest.cs new file mode 100644 index 00000000..bfeeccc9 --- /dev/null +++ b/Tests/RGB.NET.Core.Tests/Texture/PixelTextureTest.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using RGB.NET.Core.Tests.Helper; + +namespace RGB.NET.Core.Tests.Texture; + +[TestClass] +public class PixelTextureTest +{ + #region Methods + + [TestMethod] + public void SampleRegionsTest() + { + const int SIZE = 1024; + + Dictionary testData = new() + { + [new Rectangle(0, 0, 1, 1)] = new Core.Color(255, 106, 159, 118), + [new Rectangle(0.09765625f, 0.486328125f, 0.427734375f, 0.2890625f)] = new Core.Color(255, 86, 115, 175), + [new Rectangle(0.5859375f, 0.111328125f, 0.271484375f, 0.826171875f)] = new Core.Color(255, 85, 183, 123), + [new Rectangle(0.279296875f, 0.439453125f, 0.583984375f, 0.499609375f)] = new Core.Color(255, 96, 144, 145), + [new Rectangle(0.603515625f, 0.646484375f, 0.365234375f, 0.306640625f)] = new Core.Color(255, 92, 151, 141), + [new Rectangle(0.583984375f, 0.11328125f, 0.314453125f, 0.662109375f)] = new Core.Color(255, 75, 201, 115), + [new Rectangle(0.166015625f, 0.740234375f, 0.76171875f, 0.166015625f)] = new Core.Color(255, 90, 150, 142), + [new Rectangle(0.384765625f, 0.017578125f, 0.576171875f, 0.82421875f)] = new Core.Color(255, 94, 164, 128), + [new Rectangle(0.216796875f, 0.5390625f, 0.669921875f, 0.2890625f)] = new Core.Color(255, 76, 135, 169), + [new Rectangle(0.08203125f, 0.060546875f, 0.857421875f, 0.8671875f)] = new Core.Color(255, 98, 167, 117), + [new Rectangle(0.345703125f, 0.431640625f, 0.560546875f, 0.25421875f)] = new Core.Color(255, 106, 167, 116), + [new Rectangle(0.54296875f, 0.12890625f, 0.40234375f, 0.8515625f)] = new Core.Color(255, 89, 183, 115), + [new Rectangle(0.00390625f, 0.462890625f, 0.953125f, 0.052734375f)] = new Core.Color(255, 138, 173, 96), + [new Rectangle(0.322265625f, 0.572265625f, 0.361328125f, 0.40234375f)] = new Core.Color(255, 123, 127, 128), + [new Rectangle(0.56640625f, 0.388671875f, 0.28125f, 0.423828125f)] = new Core.Color(255, 112, 161, 118), + [new Rectangle(0.119140625f, 0.28125f, 0.828125f, 0.501953125f)] = new Core.Color(255, 105, 170, 108), + [new Rectangle(0.173828125f, 0.8359375f, 0.7421875f, 0.119140625f)] = new Core.Color(255, 126, 151, 106), + [new Rectangle(0.109375f, 0.283203125f, 0.748046875f, 0.583984375f)] = new Core.Color(255, 102, 158, 122), + [new Rectangle(0.0546875f, 0.474609375f, 0.87109375f, 0.2734375f)] = new Core.Color(255, 101, 143, 140), + [new Rectangle(0.34765625f, 0.30859375f, 0.39453125f, 0.39453125f)] = new Core.Color(255, 99, 143, 136), + [new Rectangle(0.240234375f, 0.6796875f, 0.515625f, 0.248046875f)] = new Core.Color(255, 114, 135, 132), + }; + + Core.Color[] data = new Core.Color[SIZE * SIZE]; + SimplexNoise.Seed = 1872; + Random random = new(1872); + for (int y = 0; y < SIZE; y++) + for (int x = 0; x < SIZE; x++) + data[(y * SIZE) + x] = HSVColor.Create(SimplexNoise.CalcPixel2D(x, y, 1f / SIZE) * 360, 1, 1); + + PixelTexture texture = new(SIZE, SIZE, data); + foreach ((Rectangle rect, Core.Color color) in testData) + { + // DarthAffe 23.04.2023: To check it "correctly" the test-data would need to be setup with floating point colors, but i don't really bother for now - that should be good enough to detect breaking changes + (byte, byte, byte, byte) sampled = texture[rect].GetRGBBytes(); + (byte, byte, byte, byte) refColor = color.GetRGBBytes(); + Assert.AreEqual(refColor, sampled); + } + } + + #endregion +} \ No newline at end of file From 586734b44a491784bf531217bdf55f37add455f6 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 23 Apr 2023 17:19:51 +0200 Subject: [PATCH 40/96] (MAJOR) Improvied sampling performance by removing the need to copy region data to a buffer first --- .../Rendering/Textures/PixelTexture.cs | 57 ++-------------- .../Textures/Sampler/AverageColorSampler.cs | 56 +++++++++------- .../Rendering/Textures/Sampler/SamplerInfo.cs | 27 ++++++-- RGB.NET.Presets/Textures/BytePixelTexture.cs | 2 + RGB.NET.Presets/Textures/FloatPixelTexture.cs | 2 + .../Textures/Sampler/AverageByteSampler.cs | 66 ++++++++++--------- .../Textures/Sampler/AverageFloatSampler.cs | 50 +++++++------- .../RGB.NET.Core.Tests/Helper/SimplexNoise.cs | 13 +--- .../Sampler/AverageColorSamplerTest.cs | 16 ++--- .../Texture/PixelTextureTest.cs | 4 +- .../Sampler/AverageByteSamplerTest.cs | 28 +++++--- .../Sampler/AverageFloatSamplerTest.cs | 28 +++++--- 12 files changed, 178 insertions(+), 171 deletions(-) diff --git a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs index 3672e2ce..c8a61cc5 100644 --- a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs +++ b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs @@ -1,5 +1,4 @@ using System; -using System.Buffers; using System.Runtime.CompilerServices; namespace RGB.NET.Core; @@ -12,12 +11,6 @@ namespace RGB.NET.Core; public abstract class PixelTexture : ITexture where T : unmanaged { - #region Constants - - private const int STACK_ALLOC_LIMIT = 1024; - - #endregion - #region Properties & Fields private readonly int _dataPerPixel; @@ -85,31 +78,12 @@ public virtual Color this[in Rectangle rectangle] if ((width == 0) || (height == 0)) return Color.Transparent; if ((width == 1) && (height == 1)) return GetColor(GetPixelData(x, y)); - int bufferSize = width * height * _dataPerPixel; - if (bufferSize <= STACK_ALLOC_LIMIT) - { - Span buffer = stackalloc T[bufferSize]; - GetRegionData(x, y, width, height, buffer); - - Span pixelData = stackalloc T[_dataPerPixel]; - Sampler.Sample(new SamplerInfo(width, height, buffer), pixelData); - - return GetColor(pixelData); - } - else - { - T[] rent = ArrayPool.Shared.Rent(bufferSize); - - Span buffer = new Span(rent)[..bufferSize]; - GetRegionData(x, y, width, height, buffer); - - Span pixelData = stackalloc T[_dataPerPixel]; - Sampler.Sample(new SamplerInfo(width, height, buffer), pixelData); + SamplerInfo samplerInfo = new(x, y, width, height, _stride, _dataPerPixel, Data); - ArrayPool.Shared.Return(rent); + Span pixelData = stackalloc T[_dataPerPixel]; + Sampler.Sample(samplerInfo, pixelData); - return GetColor(pixelData); - } + return GetColor(pixelData); } } @@ -152,27 +126,7 @@ public PixelTexture(int with, int height, int dataPerPixel, ISampler sampler, /// The y-location. /// The pixel-data on the specified location. [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected virtual ReadOnlySpan GetPixelData(int x, int y) => Data.Slice((y * _stride) + x, _dataPerPixel); - - /// - /// Writes the pixel-data of the specified region to the passed buffer. - /// - /// The x-location of the region to get the data for. - /// The y-location of the region to get the data for. - /// The width of the region to get the data for. - /// The height of the region to get the data for. - /// The buffer to write the data to. - protected virtual void GetRegionData(int x, int y, int width, int height, in Span buffer) - { - int dataWidth = width * _dataPerPixel; - ReadOnlySpan data = Data; - for (int i = 0; i < height; i++) - { - ReadOnlySpan dataSlice = data.Slice((((y + i) * _stride) + x) * _dataPerPixel, dataWidth); - Span destination = buffer.Slice(i * dataWidth, dataWidth); - dataSlice.CopyTo(destination); - } - } + private ReadOnlySpan GetPixelData(int x, int y) => Data.Slice((y * _stride) + x, _dataPerPixel); #endregion } @@ -225,6 +179,7 @@ public PixelTexture(int with, int height, Color[] data, ISampler sampler) #region Methods /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override Color GetColor(in ReadOnlySpan pixel) => pixel[0]; #endregion diff --git a/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs b/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs index d8fd0061..a9a7b86d 100644 --- a/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs +++ b/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs @@ -30,20 +30,35 @@ public unsafe void Sample(in SamplerInfo info, in Span pixelData) float a = 0, r = 0, g = 0, b = 0; - if (Vector.IsHardwareAccelerated && (info.Data.Length >= Vector.Count)) + if (Vector.IsHardwareAccelerated && (info.Height > 1) && (info.Width >= ELEMENTS_PER_VECTOR)) { - int chunks = info.Data.Length / ELEMENTS_PER_VECTOR; - int missingElements = info.Data.Length - (chunks * ELEMENTS_PER_VECTOR); + int chunks = info.Width / ELEMENTS_PER_VECTOR; + int missingElements = info.Width - (chunks * ELEMENTS_PER_VECTOR); Vector sum = Vector.Zero; - fixed (Color* colorPtr = &MemoryMarshal.GetReference(info.Data)) + for (int y = 0; y < info.Height; y++) { - Color* current = colorPtr; - for (int i = 0; i < chunks; i++) + ReadOnlySpan data = info[y]; + + fixed (Color* colorPtr = &MemoryMarshal.GetReference(data)) { - sum = Vector.Add(sum, *(Vector*)current); - current += ELEMENTS_PER_VECTOR; + Color* current = colorPtr; + for (int i = 0; i < chunks; i++) + { + sum = Vector.Add(sum, *(Vector*)current); + current += ELEMENTS_PER_VECTOR; + } + } + + for (int i = 0; i < missingElements; i++) + { + Color color = data[^(i + 1)]; + + a += color.A; + r += color.R; + g += color.G; + b += color.B; } } @@ -54,26 +69,17 @@ public unsafe void Sample(in SamplerInfo info, in Span pixelData) g += sum[i + 2]; b += sum[i + 3]; } - - for (int i = 0; i < missingElements; i++) - { - Color color = info.Data[^(i + 1)]; - - a += color.A; - r += color.R; - g += color.G; - b += color.B; - } } else { - foreach (Color color in info.Data) - { - a += color.A; - r += color.R; - g += color.G; - b += color.B; - } + for (int y = 0; y < info.Height; y++) + foreach (Color color in info[y]) + { + a += color.A; + r += color.R; + g += color.G; + b += color.B; + } } pixelData[0] = new Color(a / count, r / count, g / count, b / count); diff --git a/RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs b/RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs index ab7a0a19..bf59c937 100644 --- a/RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs +++ b/RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs @@ -10,20 +10,29 @@ public readonly ref struct SamplerInfo { #region Properties & Fields + private readonly ReadOnlySpan _data; + private readonly int _x; + private readonly int _y; + private readonly int _stride; + private readonly int _dataPerPixel; + private readonly int _dataWidth; + /// /// Gets the width of the region the data comes from. /// - public int Width { get; } + public readonly int Width; /// /// Gets the height of region the data comes from. /// - public int Height { get; } + public readonly int Height; /// - /// Gets the data to sample. + /// Gets the data for the requested row. /// - public ReadOnlySpan Data { get; } + /// The row to get the data for. + /// A readonly span containing the data of the row. + public ReadOnlySpan this[int row] => _data.Slice((((_y + row) * _stride) + _x) * _dataPerPixel, _dataWidth); #endregion @@ -35,11 +44,17 @@ public readonly ref struct SamplerInfo /// The width of the region the data comes from. /// The height of region the data comes from. /// The data to sample. - public SamplerInfo(int width, int height, ReadOnlySpan data) + public SamplerInfo(int x, int y, int width, int height, int stride, int dataPerPixel, in ReadOnlySpan data) { + this._x = x; + this._y = y; + this._data = data; + this._stride = stride; + this._dataPerPixel = dataPerPixel; this.Width = width; this.Height = height; - this.Data = data; + + _dataWidth = width * dataPerPixel; } #endregion diff --git a/RGB.NET.Presets/Textures/BytePixelTexture.cs b/RGB.NET.Presets/Textures/BytePixelTexture.cs index eb6cd1c4..103b2ae9 100644 --- a/RGB.NET.Presets/Textures/BytePixelTexture.cs +++ b/RGB.NET.Presets/Textures/BytePixelTexture.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using RGB.NET.Core; using RGB.NET.Presets.Textures.Sampler; @@ -59,6 +60,7 @@ public BytePixelTexture(int with, int height, byte[] data, ISampler sample #region Methods /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override Color GetColor(in ReadOnlySpan pixel) { return ColorFormat switch diff --git a/RGB.NET.Presets/Textures/FloatPixelTexture.cs b/RGB.NET.Presets/Textures/FloatPixelTexture.cs index 55d15fc3..f60b1778 100644 --- a/RGB.NET.Presets/Textures/FloatPixelTexture.cs +++ b/RGB.NET.Presets/Textures/FloatPixelTexture.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using RGB.NET.Core; using RGB.NET.Presets.Textures.Sampler; @@ -59,6 +60,7 @@ public FloatPixelTexture(int with, int height, float[] data, ISampler sam #region Methods /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override Color GetColor(in ReadOnlySpan pixel) { return ColorFormat switch diff --git a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs index 349afd77..1cfbdf8d 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs @@ -24,41 +24,48 @@ public unsafe void Sample(in SamplerInfo info, in Span pixelData) int count = info.Width * info.Height; if (count == 0) return; - ReadOnlySpan data = info.Data; - int dataLength = pixelData.Length; Span sums = stackalloc uint[dataLength]; - if (Vector.IsHardwareAccelerated && (data.Length >= Vector.Count) && (dataLength <= Vector.Count)) + int elementsPerVector = Vector.Count / dataLength; + int valuesPerVector = elementsPerVector * dataLength; + if (Vector.IsHardwareAccelerated && (info.Height > 1) && (info.Width >= valuesPerVector) && (dataLength <= Vector.Count)) { - int elementsPerVector = Vector.Count / dataLength; - int valuesPerVector = elementsPerVector * dataLength; - - int chunks = data.Length / valuesPerVector; - int missingElements = data.Length - (chunks * valuesPerVector); + int chunks = info.Width / elementsPerVector; Vector sum1 = Vector.Zero; Vector sum2 = Vector.Zero; Vector sum3 = Vector.Zero; Vector sum4 = Vector.Zero; - fixed (byte* colorPtr = &MemoryMarshal.GetReference(data)) + for (int y = 0; y < info.Height; y++) { - byte* current = colorPtr; - for (int i = 0; i < chunks; i++) - { - Vector bytes = *(Vector*)current; - Vector.Widen(bytes, out Vector short1, out Vector short2); - Vector.Widen(short1, out Vector int1, out Vector int2); - Vector.Widen(short2, out Vector int3, out Vector int4); + ReadOnlySpan data = info[y]; - sum1 = Vector.Add(sum1, int1); - sum2 = Vector.Add(sum2, int2); - sum3 = Vector.Add(sum3, int3); - sum4 = Vector.Add(sum4, int4); - - current += valuesPerVector; + fixed (byte* colorPtr = &MemoryMarshal.GetReference(data)) + { + byte* current = colorPtr; + for (int i = 0; i < chunks; i++) + { + Vector bytes = *(Vector*)current; + Vector.Widen(bytes, out Vector short1, out Vector short2); + Vector.Widen(short1, out Vector int1, out Vector int2); + Vector.Widen(short2, out Vector int3, out Vector int4); + + sum1 = Vector.Add(sum1, int1); + sum2 = Vector.Add(sum2, int2); + sum3 = Vector.Add(sum3, int3); + sum4 = Vector.Add(sum4, int4); + + current += valuesPerVector; + } } + + int missingElements = data.Length - (chunks * valuesPerVector); + int offset = chunks * valuesPerVector; + for (int i = 0; i < missingElements; i += dataLength) + for (int j = 0; j < sums.Length; j++) + sums[j] += data[offset + i + j]; } int value = 0; @@ -102,17 +109,16 @@ public unsafe void Sample(in SamplerInfo info, in Span pixelData) if (sumIndex >= dataLength) sumIndex = 0; } - - int offset = chunks * valuesPerVector; - for (int i = 0; i < missingElements; i += dataLength) - for (int j = 0; j < sums.Length; j++) - sums[j] += data[offset + i + j]; } else { - for (int i = 0; i < data.Length; i += dataLength) - for (int j = 0; j < sums.Length; j++) - sums[j] += data[i + j]; + for (int y = 0; y < info.Height; y++) + { + ReadOnlySpan data = info[y]; + for (int i = 0; i < data.Length; i += dataLength) + for (int j = 0; j < sums.Length; j++) + sums[j] += data[i + j]; + } } float divisor = count * byte.MaxValue; diff --git a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs index d53ad5db..dfa3f17a 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs @@ -18,45 +18,51 @@ public unsafe void Sample(in SamplerInfo info, in Span pixelData) int count = info.Width * info.Height; if (count == 0) return; - ReadOnlySpan data = info.Data; - int dataLength = pixelData.Length; Span sums = stackalloc float[dataLength]; - - if (Vector.IsHardwareAccelerated && (data.Length >= Vector.Count) && (dataLength <= Vector.Count)) - { - int elementsPerVector = Vector.Count / dataLength; - int valuesPerVector = elementsPerVector * dataLength; - int chunks = data.Length / valuesPerVector; - int missingElements = data.Length - (chunks * valuesPerVector); + int elementsPerVector = Vector.Count / dataLength; + int valuesPerVector = elementsPerVector * dataLength; + if (Vector.IsHardwareAccelerated && (info.Height > 1) && (info.Width >= valuesPerVector) && (dataLength <= Vector.Count)) + { + int chunks = info.Width / elementsPerVector; Vector sum = Vector.Zero; - fixed (float* colorPtr = &MemoryMarshal.GetReference(data)) + for (int y = 0; y < info.Height; y++) { - float* current = colorPtr; - for (int i = 0; i < chunks; i++) + ReadOnlySpan data = info[y]; + + fixed (float* colorPtr = &MemoryMarshal.GetReference(data)) { - sum = Vector.Add(sum, *(Vector*)current); - current += valuesPerVector; + float* current = colorPtr; + for (int i = 0; i < chunks; i++) + { + sum = Vector.Add(sum, *(Vector*)current); + current += valuesPerVector; + } } + + int missingElements = data.Length - (chunks * valuesPerVector); + int offset = chunks * valuesPerVector; + for (int i = 0; i < missingElements; i += dataLength) + for (int j = 0; j < sums.Length; j++) + sums[j] += data[offset + i + j]; } for (int i = 0; i < valuesPerVector; i += dataLength) for (int j = 0; j < sums.Length; j++) sums[j] += sum[i + j]; - - int offset = chunks * valuesPerVector; - for (int i = 0; i < missingElements; i += dataLength) - for (int j = 0; j < sums.Length; j++) - sums[j] += data[offset + i + j]; } else { - for (int i = 0; i < data.Length; i += dataLength) - for (int j = 0; j < sums.Length; j++) - sums[j] += data[i + j]; + for (int y = 0; y < info.Height; y++) + { + ReadOnlySpan data = info[y]; + for (int i = 0; i < data.Length; i += dataLength) + for (int j = 0; j < sums.Length; j++) + sums[j] += data[i + j]; + } } for (int i = 0; i < pixelData.Length; i++) diff --git a/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs index aa756d67..f28dd164 100644 --- a/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs +++ b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs @@ -1,4 +1,6 @@ -using System; +// ReSharper disable InconsistentNaming + +using System; namespace RGB.NET.Core.Tests.Helper; @@ -342,13 +344,4 @@ private static float Grad(int hash, float x, float y, float z) float v = h < 4 ? y : (h == 12) || (h == 14) ? x : z; // Fix repeats at h = 12 to 15 return ((h & 1) != 0 ? -u : u) + ((h & 2) != 0 ? -v : v); } - - private static float Grad(int hash, float x, float y, float z, float t) - { - int h = hash & 31; // Convert low 5 bits of hash code into 32 simple - float u = h < 24 ? x : y; // gradient directions, and compute dot product. - float v = h < 16 ? y : z; - float w = h < 8 ? z : t; - return ((h & 1) != 0 ? -u : u) + ((h & 2) != 0 ? -v : v) + ((h & 4) != 0 ? -w : w); - } } diff --git a/Tests/RGB.NET.Core.Tests/Sampler/AverageColorSamplerTest.cs b/Tests/RGB.NET.Core.Tests/Sampler/AverageColorSamplerTest.cs index 99398ec7..49c14855 100644 --- a/Tests/RGB.NET.Core.Tests/Sampler/AverageColorSamplerTest.cs +++ b/Tests/RGB.NET.Core.Tests/Sampler/AverageColorSamplerTest.cs @@ -15,11 +15,11 @@ public void WhiteTest() data.Fill(new Core.Color(1f, 1f, 1f, 1f)); Core.Color[] result = new Core.Color[1]; - SamplerInfo info = new(2, 3, data[..6]); + SamplerInfo info = new(0, 0, 2, 3, 16, 1, data); new AverageColorSampler().Sample(info, result); Assert.AreEqual(new Core.Color(1f, 1f, 1f, 1f), result[0]); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 16, 16, 16, 1, data); new AverageColorSampler().Sample(info, result); Assert.AreEqual(new Core.Color(1f, 1f, 1f, 1f), result[0]); } @@ -31,11 +31,11 @@ public void BlackTest() data.Fill(new Core.Color(1f, 0f, 0f, 0f)); Core.Color[] result = new Core.Color[1]; - SamplerInfo info = new(2, 3, data[..6]); + SamplerInfo info = new(0, 0, 2, 3, 16, 1, data); new AverageColorSampler().Sample(info, result); Assert.AreEqual(new Core.Color(1f, 0f, 0f, 0f), result[0]); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 16, 16, 16, 1, data); new AverageColorSampler().Sample(info, result); Assert.AreEqual(new Core.Color(1f, 0f, 0f, 0f), result[0]); } @@ -48,11 +48,11 @@ public void GrayTest() data[i] = (i % 2) == 0 ? new Core.Color(1f, 0f, 0f, 0f) : new Core.Color(1f, 1f, 1f, 1f); Core.Color[] result = new Core.Color[1]; - SamplerInfo info = new(2, 3, data[..6]); + SamplerInfo info = new(0, 0, 2, 3, 16, 1, data); new AverageColorSampler().Sample(info, result); Assert.AreEqual(new Core.Color(1f, 0.5f, 0.5f, 0.5f), result[0]); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 16, 16, 16, 1, data); new AverageColorSampler().Sample(info, result); Assert.AreEqual(new Core.Color(1f, 0.5f, 0.5f, 0.5f), result[0]); } @@ -72,11 +72,11 @@ public void MixedTest() }; Core.Color[] result = new Core.Color[1]; - SamplerInfo info = new(2, 3, data[..6]); + SamplerInfo info = new(0, 0, 2, 3, 2, 1, data[..6]); new AverageColorSampler().Sample(info, result); Assert.AreEqual(new Core.Color(0.5833333f, 0.5f, 0.291666657f, 0.25f), result[0]); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 16, 16, 16, 1, data); new AverageColorSampler().Sample(info, result); Assert.AreEqual(new Core.Color(0.5019531f, 0.40234375f, 0.3486328f, 0.298828125f), result[0]); } diff --git a/Tests/RGB.NET.Core.Tests/Texture/PixelTextureTest.cs b/Tests/RGB.NET.Core.Tests/Texture/PixelTextureTest.cs index bfeeccc9..52c2f838 100644 --- a/Tests/RGB.NET.Core.Tests/Texture/PixelTextureTest.cs +++ b/Tests/RGB.NET.Core.Tests/Texture/PixelTextureTest.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using RGB.NET.Core.Tests.Helper; @@ -42,7 +41,6 @@ public void SampleRegionsTest() Core.Color[] data = new Core.Color[SIZE * SIZE]; SimplexNoise.Seed = 1872; - Random random = new(1872); for (int y = 0; y < SIZE; y++) for (int x = 0; x < SIZE; x++) data[(y * SIZE) + x] = HSVColor.Create(SimplexNoise.CalcPixel2D(x, y, 1f / SIZE) * 360, 1, 1); diff --git a/Tests/RGB.NET.Presets.Tests/Sampler/AverageByteSamplerTest.cs b/Tests/RGB.NET.Presets.Tests/Sampler/AverageByteSamplerTest.cs index 34a1e344..0ceb9e71 100644 --- a/Tests/RGB.NET.Presets.Tests/Sampler/AverageByteSamplerTest.cs +++ b/Tests/RGB.NET.Presets.Tests/Sampler/AverageByteSamplerTest.cs @@ -27,11 +27,15 @@ public void WhiteTest() data[index++] = colorData[i].GetB(); } - SamplerInfo info = new(2, 3, data[..(6 * 4)]); + SamplerInfo info = new(0, 0, 2, 3, 16, 4, data); new AverageByteSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 1f, 1f, 1f), new Color(result[0], result[1], result[2], result[3])); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 13, 13, 16, 4, data); + new AverageByteSampler().Sample(info, result); + Assert.AreEqual(new Color(1f, 1f, 1f, 1f), new Color(result[0], result[1], result[2], result[3])); + + info = new SamplerInfo(0, 0, 16, 16, 16, 4, data); new AverageByteSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 1f, 1f, 1f), new Color(result[0], result[1], result[2], result[3])); } @@ -53,11 +57,15 @@ public void BlackTest() data[index++] = colorData[i].GetB(); } - SamplerInfo info = new(2, 3, data[..(6 * 4)]); + SamplerInfo info = new(0, 0, 2, 3, 16, 4, data); + new AverageByteSampler().Sample(info, result); + Assert.AreEqual(new Color(1f, 0f, 0f, 0f), new Color(result[0], result[1], result[2], result[3])); + + info = new SamplerInfo(0, 0, 13, 13, 16, 4, data); new AverageByteSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 0f, 0f, 0f), new Color(result[0], result[1], result[2], result[3])); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 16, 16, 16, 4, data); new AverageByteSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 0f, 0f, 0f), new Color(result[0], result[1], result[2], result[3])); } @@ -80,11 +88,15 @@ public void GrayTest() data[index++] = colorData[i].GetB(); } - SamplerInfo info = new(2, 3, data[..(6 * 4)]); + SamplerInfo info = new(0, 0, 2, 3, 16, 4, data); new AverageByteSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 0.5f, 0.5f, 0.5f), new Color(result[0], result[1], result[2], result[3])); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 13, 13, 16, 4, data); + new AverageByteSampler().Sample(info, result); + Assert.AreEqual(new Color(1f, (6f / 13f).GetByteValueFromPercentage(), (6f / 13f).GetByteValueFromPercentage(), (6f / 13f).GetByteValueFromPercentage()), new Color(result[0], result[1], result[2], result[3])); + + info = new SamplerInfo(0, 0, 16, 16, 16, 4, data); new AverageByteSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 0.5f, 0.5f, 0.5f), new Color(result[0], result[1], result[2], result[3])); } @@ -114,11 +126,11 @@ public void MixedTest() data[index++] = colorData[i].GetB(); } - SamplerInfo info = new(2, 3, data[..(6 * 4)]); + SamplerInfo info = new(0, 0, 2, 3, 2, 4, data[..(6 * 4)]); new AverageByteSampler().Sample(info, result); Assert.AreEqual(new Color(149, 128, 74, 64), new Color(result[0], result[1], result[2], result[3])); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 16, 16, 16, 4, data); new AverageByteSampler().Sample(info, result); Assert.AreEqual(new Color(128, 103, 89, 76), new Color(result[0], result[1], result[2], result[3])); } diff --git a/Tests/RGB.NET.Presets.Tests/Sampler/AverageFloatSamplerTest.cs b/Tests/RGB.NET.Presets.Tests/Sampler/AverageFloatSamplerTest.cs index 6795f2cd..a9ef8a43 100644 --- a/Tests/RGB.NET.Presets.Tests/Sampler/AverageFloatSamplerTest.cs +++ b/Tests/RGB.NET.Presets.Tests/Sampler/AverageFloatSamplerTest.cs @@ -27,11 +27,15 @@ public void WhiteTest() data[index++] = colorData[i].B; } - SamplerInfo info = new(2, 3, data[..(6 * 4)]); + SamplerInfo info = new(0, 0, 2, 3, 16, 4, data); new AverageFloatSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 1f, 1f, 1f), new Color(result[0], result[1], result[2], result[3])); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 13, 13, 16, 4, data); + new AverageFloatSampler().Sample(info, result); + Assert.AreEqual(new Color(1f, 1f, 1f, 1f), new Color(result[0], result[1], result[2], result[3])); + + info = new SamplerInfo(0, 0, 16, 16, 16, 4, data); new AverageFloatSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 1f, 1f, 1f), new Color(result[0], result[1], result[2], result[3])); } @@ -53,11 +57,15 @@ public void BlackTest() data[index++] = colorData[i].B; } - SamplerInfo info = new(2, 3, data[..(6 * 4)]); + SamplerInfo info = new(0, 0, 2, 3, 16, 4, data); + new AverageFloatSampler().Sample(info, result); + Assert.AreEqual(new Color(1f, 0f, 0f, 0f), new Color(result[0], result[1], result[2], result[3])); + + info = new SamplerInfo(0, 0, 13, 13, 16, 4, data); new AverageFloatSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 0f, 0f, 0f), new Color(result[0], result[1], result[2], result[3])); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 16, 16, 16, 4, data); new AverageFloatSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 0f, 0f, 0f), new Color(result[0], result[1], result[2], result[3])); } @@ -80,11 +88,15 @@ public void GrayTest() data[index++] = colorData[i].B; } - SamplerInfo info = new(2, 3, data[..(6 * 4)]); + SamplerInfo info = new(0, 0, 2, 3, 16, 4, data); new AverageFloatSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 0.5f, 0.5f, 0.5f), new Color(result[0], result[1], result[2], result[3])); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 13, 13, 16, 4, data); + new AverageFloatSampler().Sample(info, result); + Assert.AreEqual(new Color(1f, 6f / 13f, 6f / 13f, 6f / 13f), new Color(result[0], result[1], result[2], result[3])); + + info = new SamplerInfo(0, 0, 16, 16, 16, 4, data); new AverageFloatSampler().Sample(info, result); Assert.AreEqual(new Color(1f, 0.5f, 0.5f, 0.5f), new Color(result[0], result[1], result[2], result[3])); } @@ -114,11 +126,11 @@ public void MixedTest() data[index++] = colorData[i].B; } - SamplerInfo info = new(2, 3, data[..(6 * 4)]); + SamplerInfo info = new(0, 0, 2, 3, 2, 4, data[..(6 * 4)]); new AverageFloatSampler().Sample(info, result); Assert.AreEqual(new Color(0.5833333f, 0.5f, 0.291666657f, 0.25f), new Color(result[0], result[1], result[2], result[3])); - info = new SamplerInfo(16, 16, data); + info = new SamplerInfo(0, 0, 16, 16, 16, 4, data); new AverageFloatSampler().Sample(info, result); Assert.AreEqual(new Color(0.5019531f, 0.40234375f, 0.3486328f, 0.298828125f), new Color(result[0], result[1], result[2], result[3])); } From 928d5c2ef95160afcb6c32d0b44a066a00fbaa62 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 23 Apr 2023 17:36:22 +0200 Subject: [PATCH 41/96] Added license link to SimplexNoise --- Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs index f28dd164..322eb5ce 100644 --- a/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs +++ b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs @@ -6,7 +6,7 @@ namespace RGB.NET.Core.Tests.Helper; // Simplex Noise for C# // Copyright © Benjamin Ward 2019 -// See LICENSE +// See LICENSE (https://github.com/WardBenjamin/SimplexNoise/blob/2afa9a63483562cc4c0a95bbfa6b183fc256a790/LICENSE.txt) // Simplex Noise implementation offering 1D, 2D, and 3D forms w/ values in the range of 0 to 255. // Based on work by Heikki Törmälä (2012) and Stefan Gustavson (2006). From 9f8e64fbcbe032b430f959e15ab8332287b34259 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 23 Apr 2023 18:02:11 +0200 Subject: [PATCH 42/96] Changed DataPerPixel and Stride to be protected in PixelTexture --- .../Rendering/Textures/PixelTexture.cs | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs index c8a61cc5..8fd1da6d 100644 --- a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs +++ b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs @@ -1,4 +1,6 @@ -using System; +// ReSharper disable MemberCanBePrivate.Global + +using System; using System.Runtime.CompilerServices; namespace RGB.NET.Core; @@ -12,9 +14,21 @@ public abstract class PixelTexture : ITexture where T : unmanaged { #region Properties & Fields + + /// + /// Gets the underlying pixel data. + /// + protected abstract ReadOnlySpan Data { get; } - private readonly int _dataPerPixel; - private readonly int _stride; + /// + /// Gets the amount of data-entries per pixel. + /// + protected readonly int DataPerPixel; + + /// + /// Gets the stride of the data. + /// + protected readonly int Stride; /// /// Gets or sets the sampler used to get the color of a region. @@ -24,11 +38,6 @@ public abstract class PixelTexture : ITexture /// public Size Size { get; } - /// - /// Gets the underlying pixel data. - /// - protected abstract ReadOnlySpan Data { get; } - /// public virtual Color this[in Point point] { @@ -78,9 +87,9 @@ public virtual Color this[in Rectangle rectangle] if ((width == 0) || (height == 0)) return Color.Transparent; if ((width == 1) && (height == 1)) return GetColor(GetPixelData(x, y)); - SamplerInfo samplerInfo = new(x, y, width, height, _stride, _dataPerPixel, Data); + SamplerInfo samplerInfo = new(x, y, width, height, Stride, DataPerPixel, Data); - Span pixelData = stackalloc T[_dataPerPixel]; + Span pixelData = stackalloc T[DataPerPixel]; Sampler.Sample(samplerInfo, pixelData); return GetColor(pixelData); @@ -101,8 +110,8 @@ public virtual Color this[in Rectangle rectangle] /// The stride of the data or -1 if the width should be used. public PixelTexture(int with, int height, int dataPerPixel, ISampler sampler, int stride = -1) { - this._stride = stride == -1 ? with : stride; - this._dataPerPixel = dataPerPixel; + this.Stride = stride == -1 ? with : stride; + this.DataPerPixel = dataPerPixel; this.Sampler = sampler; Size = new Size(with, height); @@ -126,7 +135,7 @@ public PixelTexture(int with, int height, int dataPerPixel, ISampler sampler, /// The y-location. /// The pixel-data on the specified location. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private ReadOnlySpan GetPixelData(int x, int y) => Data.Slice((y * _stride) + x, _dataPerPixel); + private ReadOnlySpan GetPixelData(int x, int y) => Data.Slice((y * Stride) + x, DataPerPixel); #endregion } From a2194849b66f51e3a9e17e8fc485b616d52a5dff Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 23 Apr 2023 18:05:24 +0200 Subject: [PATCH 43/96] Changed stride and DataPerPixel in the PixelTexture to be a property for consistency --- RGB.NET.Core/Rendering/Textures/PixelTexture.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs index 8fd1da6d..170d2d55 100644 --- a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs +++ b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs @@ -14,7 +14,7 @@ public abstract class PixelTexture : ITexture where T : unmanaged { #region Properties & Fields - + /// /// Gets the underlying pixel data. /// @@ -23,12 +23,12 @@ public abstract class PixelTexture : ITexture /// /// Gets the amount of data-entries per pixel. /// - protected readonly int DataPerPixel; + protected int DataPerPixel { get; } /// /// Gets the stride of the data. /// - protected readonly int Stride; + protected int Stride { get; } /// /// Gets or sets the sampler used to get the color of a region. From 93cd8055a28caa1fcd9c46e3853b65fff79d0891 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 24 Apr 2023 23:13:12 +0200 Subject: [PATCH 44/96] Simplified span-fixes in Samplers --- RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs | 3 +-- RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs | 3 +-- RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs b/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs index a9a7b86d..9ba2cb02 100644 --- a/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs +++ b/RGB.NET.Core/Rendering/Textures/Sampler/AverageColorSampler.cs @@ -1,6 +1,5 @@ using System; using System.Numerics; -using System.Runtime.InteropServices; namespace RGB.NET.Core; @@ -41,7 +40,7 @@ public unsafe void Sample(in SamplerInfo info, in Span pixelData) { ReadOnlySpan data = info[y]; - fixed (Color* colorPtr = &MemoryMarshal.GetReference(data)) + fixed (Color* colorPtr = data) { Color* current = colorPtr; for (int i = 0; i < chunks; i++) diff --git a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs index 1cfbdf8d..bf5d7c6b 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs @@ -1,6 +1,5 @@ using System; using System.Numerics; -using System.Runtime.InteropServices; using RGB.NET.Core; namespace RGB.NET.Presets.Textures.Sampler; @@ -42,7 +41,7 @@ public unsafe void Sample(in SamplerInfo info, in Span pixelData) { ReadOnlySpan data = info[y]; - fixed (byte* colorPtr = &MemoryMarshal.GetReference(data)) + fixed (byte* colorPtr = data) { byte* current = colorPtr; for (int i = 0; i < chunks; i++) diff --git a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs index dfa3f17a..cea8f451 100644 --- a/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs +++ b/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs @@ -1,6 +1,5 @@ using System; using System.Numerics; -using System.Runtime.InteropServices; using RGB.NET.Core; namespace RGB.NET.Presets.Textures.Sampler; @@ -33,7 +32,7 @@ public unsafe void Sample(in SamplerInfo info, in Span pixelData) { ReadOnlySpan data = info[y]; - fixed (float* colorPtr = &MemoryMarshal.GetReference(data)) + fixed (float* colorPtr = data) { float* current = colorPtr; for (int i = 0; i < chunks; i++) From 0c8f48ea4406858bde5ef2733f3dc53f25a304ce Mon Sep 17 00:00:00 2001 From: David Ross Smith <5095074+DragRedSim@users.noreply.github.com> Date: Tue, 2 May 2023 21:50:47 +1000 Subject: [PATCH 45/96] Asus - Modify device type enum to add new items - USB keyboard with 5-zone lighting (also passed as a keyboard) - Watercooler (uses generic lighting) - Sourced from https://www.asus.com/microsite/aurareadydevportal/interface_aura_service_lib_1_1_i_aura_sdk.html --- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 1 + RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index 318850ed..e3b093c2 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -69,6 +69,7 @@ protected override IEnumerable LoadDevices() AsusDeviceType.HEADSET_RGB => new AsusHeadsetRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Headset, device), GetUpdateTrigger()), AsusDeviceType.DRAM_RGB => new AsusDramRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.DRAM, device), GetUpdateTrigger()), AsusDeviceType.KEYBOARD_RGB => new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device), LedMappings.KeyboardMapping, GetUpdateTrigger()), + AsusDeviceType.KEYBOARD_5ZONE_RGB => new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device), null, GetUpdateTrigger()), AsusDeviceType.NB_KB_RGB => new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device), LedMappings.KeyboardMapping, GetUpdateTrigger()), AsusDeviceType.NB_KB_4ZONE_RGB => new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device), null, GetUpdateTrigger()), AsusDeviceType.MOUSE_RGB => new AsusMouseRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mouse, device), GetUpdateTrigger()), diff --git a/RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs b/RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs index bb5f16f2..bb9a2bef 100644 --- a/RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs +++ b/RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs @@ -16,10 +16,12 @@ internal enum AsusDeviceType : uint EXTERNAL_BLUE_RAY_RGB = 0x61000, DRAM_RGB = 0x70000, KEYBOARD_RGB = 0x80000, + KEYBOARD_5ZONE_RGB = 0x80001, NB_KB_RGB = 0x81000, NB_KB_4ZONE_RGB = 0x81001, MOUSE_RGB = 0x90000, CHASSIS_RGB = 0xB0000, PROJECTOR_RGB = 0xC0000, + WATERCOOLER_RGB = 0xD1000, TERMINAL_RGB = 0xE0000 } \ No newline at end of file From e9cd657eac16b1606bf17b71a549d2719c8b05a3 Mon Sep 17 00:00:00 2001 From: David Ross Smith <5095074+DragRedSim@users.noreply.github.com> Date: Tue, 2 May 2023 21:51:32 +1000 Subject: [PATCH 46/96] Asus - Corrected unspecified device documentation - Previous info was copy/pasted from headset values --- RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs b/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs index fe3c2389..6d209526 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs @@ -4,7 +4,7 @@ namespace RGB.NET.Devices.Asus; /// /// -/// Represents a Asus headset. +/// Represents a Asus device that is otherwise not handled by a more specific helper. /// public sealed class AsusUnspecifiedRGBDevice : AsusRGBDevice, IUnknownDevice { @@ -18,9 +18,9 @@ public sealed class AsusUnspecifiedRGBDevice : AsusRGBDevice, /// /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// The specific information provided by Asus for the headset. + /// The specific information provided by Asus for the device. /// The ledId of the first led of this device. All other leds are created by incrementing this base-id by 1. /// The update trigger used to update this device. internal AsusUnspecifiedRGBDevice(AsusRGBDeviceInfo info, LedId baseLedId, IDeviceUpdateTrigger updateTrigger) From 184a5823e8f77117aef0fa39265eaa9f53a07aa2 Mon Sep 17 00:00:00 2001 From: David Ross Smith <5095074+DragRedSim@users.noreply.github.com> Date: Tue, 2 May 2023 21:55:36 +1000 Subject: [PATCH 47/96] Asus - added LED mapping for ROG Strix G15 (2021) - Device is a laptop with RGB in the keyboard, as well as an LED strip - LED mappings reuse those from the ROG Zephyrus Duo where appropriate --- .../Keyboard/AsusKeyboardLedMapping.cs | 45 +++++++++++++++++++ .../Keyboard/AsusKeyboardRGBDevice.cs | 5 ++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMapping.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMapping.cs index 9eb8d1fd..298dd611 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMapping.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMapping.cs @@ -188,4 +188,49 @@ public static class LedMappings { LedId.Keyboard_Custom59, 131 }, { LedId.Keyboard_Custom60, 133 }, }; + + /// + /// A LED mapping containing extra lights for the ROG Strix G15 (2021) + /// + /// + /// + /// ASUS notebooks have extra lights under wide keys like space and backspace, these do not appear as keys on the device. + /// Instead they only appear in the Lights enumerable, this mapping maps the matching keys to the index of these lights. + /// There are also some keys which do not use the default key scan code mappings for LEDs, and instead rely on lights. + /// + /// You may add more of these by further populating . + /// + public static LedMapping ROGStrixG15 { get; } = new() + { + { LedId.Keyboard_Custom71, 4 }, //Mic Mute + { LedId.Keyboard_Custom72, 5 }, //Fan + { LedId.Keyboard_Custom73, 6 }, //ROG Logo + //{ LedId.Keyboard_Function, 127 }, //commented out because adding a mapping fails if a mapping already exists for a key, even if it is incorrect for this device + //use Keyboard_Custom36 in the default mapping to get the Fn key on this laptop + + { LedId.Keyboard_Custom52, 55 }, //backspace extra LEDs (x2) - these are named to match the appropriate LEDs in the previous ROG Zephyrus mapping + { LedId.Keyboard_Custom53, 57 }, + { LedId.Keyboard_Custom54, 97 }, //enter extra LEDs (x2) + { LedId.Keyboard_Custom55, 99 }, + { LedId.Keyboard_Custom56, 118 }, //right shift extra LEDs (x2) + { LedId.Keyboard_Custom57, 120 }, + { LedId.Keyboard_Custom58, 130 }, //space bar extra LEDs (x3) + { LedId.Keyboard_Custom59, 131 }, //this one specifically is also exposed as Custom7 (AsusLedID.KEY_NOCONVERT) in the main map + { LedId.Keyboard_Custom60, 133 }, + + { LedId.Keyboard_MediaVolumeDown, 2 }, + { LedId.Keyboard_MediaVolumeUp, 3 }, + { LedId.Keyboard_MediaPlay, 58 }, + { LedId.Keyboard_MediaStop, 79 }, + { LedId.Keyboard_MediaPreviousTrack, 100 }, + { LedId.Keyboard_MediaNextTrack, 121 }, + + { LedId.LedStripe1, 174 }, //front LED strip; yes, these are in reverse order, since the SDK exposes them from right to left + { LedId.LedStripe2, 173 }, + { LedId.LedStripe3, 172 }, + { LedId.LedStripe4, 171 }, + { LedId.LedStripe5, 170 }, + { LedId.LedStripe6, 169 }, + + }; } \ No newline at end of file diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs index 30b429cc..ee5f5498 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs @@ -37,7 +37,8 @@ public sealed class AsusKeyboardRGBDevice : AsusRGBDevice ExtraLedMappings = new() { - new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15) + new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15), + new AsusKeyboardExtraMapping(new Regex("(ROG Strix G513QM).*?"), LedMappings.ROGStrixG15) }; #endregion @@ -65,7 +66,7 @@ internal AsusKeyboardRGBDevice(AsusKeyboardRGBDeviceInfo info, LedMapping Date: Mon, 8 May 2023 20:47:47 +0200 Subject: [PATCH 48/96] Removed allocation when applying decorators --- RGB.NET.Core/Rendering/Brushes/AbstractBrush.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/RGB.NET.Core/Rendering/Brushes/AbstractBrush.cs b/RGB.NET.Core/Rendering/Brushes/AbstractBrush.cs index 553e53b1..bc39b5d3 100644 --- a/RGB.NET.Core/Rendering/Brushes/AbstractBrush.cs +++ b/RGB.NET.Core/Rendering/Brushes/AbstractBrush.cs @@ -74,9 +74,13 @@ protected virtual void ApplyDecorators(in Rectangle rectangle, in RenderTarget r if (Decorators.Count == 0) return; lock (Decorators) - foreach (IBrushDecorator decorator in Decorators) + // ReSharper disable once ForCanBeConvertedToForeach - Sadly this does not get optimized reliably and causes allocations if foreached + for (int i = 0; i < Decorators.Count; i++) + { + IBrushDecorator decorator = Decorators[i]; if (decorator.IsEnabled) decorator.ManipulateColor(rectangle, renderTarget, ref color); + } } /// From 7e72d3199beefca076fd12bbba2802b4ba2940e3 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 8 May 2023 21:28:55 +0200 Subject: [PATCH 49/96] Added DevicesChanged-event to device providers --- .../Devices/AbstractRGBDeviceProvider.cs | 55 +++++++++++++++++-- RGB.NET.Core/Devices/IRGBDeviceProvider.cs | 7 ++- .../Events/DevicesChangedEventArgs.cs | 34 ++++++++++++ .../OpenRGBDeviceProvider.cs | 2 +- 4 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 RGB.NET.Core/Events/DevicesChangedEventArgs.cs diff --git a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs index d61fcbb9..e76554e1 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs @@ -20,8 +20,13 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider /// public bool ThrowsExceptions { get; protected set; } + /// + /// The list of devices managed by this device-provider. + /// + protected List InternalDevices { get; } = new(); + /// - public virtual IEnumerable Devices { get; protected set; } = Enumerable.Empty(); + public virtual IReadOnlyList Devices => new ReadOnlyCollection(InternalDevices); /// /// Gets the dictionary containing the registered update triggers. @@ -39,6 +44,9 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider /// public event EventHandler? Exception; + /// + public event EventHandler? DevicesChanged; + #endregion #region Constructors @@ -67,7 +75,8 @@ public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwE InitializeSDK(); - Devices = new ReadOnlyCollection(GetLoadedDevices(loadFilter).ToList()); + foreach (IRGBDevice device in GetLoadedDevices(loadFilter)) + AddDevice(device); foreach (IDeviceUpdateTrigger updateTrigger in UpdateTriggerMapping.Values) updateTrigger.Start(); @@ -168,11 +177,43 @@ protected virtual void Reset() foreach (IRGBDevice device in Devices) device.Dispose(); - Devices = Enumerable.Empty(); + List devices = new(InternalDevices); + foreach (IRGBDevice device in devices) + RemoveDevice(device); + UpdateTriggerMapping.Clear(); IsInitialized = false; } + /// + /// Adds the provided device to the list of managed devices. + /// + /// The device to add. + /// true if the device was added successfully; otherwise false. + protected virtual bool AddDevice(IRGBDevice device) + { + if (InternalDevices.Contains(device)) return false; + + InternalDevices.Add(device); + try { OnDevicesChanged(DevicesChangedEventArgs.CreateDevicesAddedArgs(device)); } catch { /* we don't want to throw due to bad event handlers */ } + + return true; + } + + /// + /// Removes the provided device from the list of managed devices. + /// + /// The device to remove. + /// true if the device was removed successfully; otherwise false. + protected virtual bool RemoveDevice(IRGBDevice device) + { + if (!InternalDevices.Remove(device)) return false; + + try { OnDevicesChanged(DevicesChangedEventArgs.CreateDevicesRemovedArgs(device)); } catch { /* we don't want to throw due to bad event handlers */ } + + return true; + } + /// /// Triggers the -event and throws the specified exception if is true and it is not overriden in the event. /// @@ -188,11 +229,17 @@ public virtual void Throw(Exception ex, bool isCritical = false) } /// - /// Throws the event. + /// Throws the .event. /// /// The parameters passed to the event. protected virtual void OnException(ExceptionEventArgs args) => Exception?.Invoke(this, args); + /// + /// Throws the -event. + /// + /// The parameters passed to the event. + protected virtual void OnDevicesChanged(DevicesChangedEventArgs args) => DevicesChanged?.Invoke(this, args); + /// public virtual void Dispose() { diff --git a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs index 86f41e13..6e22d12e 100644 --- a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs +++ b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs @@ -29,7 +29,7 @@ public interface IRGBDeviceProvider : IDisposable /// /// Gets a collection of loaded by this . /// - IEnumerable Devices { get; } + IReadOnlyList Devices { get; } /// /// Gets a collection registered to this device provider. @@ -45,6 +45,11 @@ public interface IRGBDeviceProvider : IDisposable /// event EventHandler? Exception; + /// + /// Occures when the devices provided by this device provider changed. + /// + event EventHandler? DevicesChanged; + #endregion #region Methods diff --git a/RGB.NET.Core/Events/DevicesChangedEventArgs.cs b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs new file mode 100644 index 00000000..5b5012d2 --- /dev/null +++ b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; + +namespace RGB.NET.Core; + +public sealed class DevicesChangedEventArgs : EventArgs +{ + #region Properties & Fields + + public IList Added { get; } + public IList Removed { get; } + + #endregion + + #region Constructors + + private DevicesChangedEventArgs(IList added, IList removed) + { + this.Added = added; + this.Removed = removed; + } + + #endregion + + #region Methods + + public static DevicesChangedEventArgs CreateDevicesAddedArgs(params IRGBDevice[] addedDevices) => CreateDevicesAddedArgs((IEnumerable)addedDevices); + public static DevicesChangedEventArgs CreateDevicesAddedArgs(IEnumerable addedDevices) => new(new List(addedDevices), new List()); + + public static DevicesChangedEventArgs CreateDevicesRemovedArgs(params IRGBDevice[] removedDevices) => CreateDevicesRemovedArgs((IEnumerable)removedDevices); + public static DevicesChangedEventArgs CreateDevicesRemovedArgs(IEnumerable removedDevices) => new(new List(), new List(removedDevices)); + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs index 6c83a680..4d194843 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs @@ -161,7 +161,7 @@ public override void Dispose() _clients.Clear(); DeviceDefinitions.Clear(); - Devices = Enumerable.Empty(); } + #endregion } From 67f3625993695d41e86e70aa85b0c1e55365e128 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 8 May 2023 21:30:52 +0200 Subject: [PATCH 50/96] Changed device lists in the DevicesChanged-event to readonly --- RGB.NET.Core/Events/DevicesChangedEventArgs.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/RGB.NET.Core/Events/DevicesChangedEventArgs.cs b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs index 5b5012d2..53a5a97e 100644 --- a/RGB.NET.Core/Events/DevicesChangedEventArgs.cs +++ b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; namespace RGB.NET.Core; @@ -7,8 +8,8 @@ public sealed class DevicesChangedEventArgs : EventArgs { #region Properties & Fields - public IList Added { get; } - public IList Removed { get; } + public IReadOnlyList Added { get; } + public IReadOnlyList Removed { get; } #endregion @@ -16,8 +17,8 @@ public sealed class DevicesChangedEventArgs : EventArgs private DevicesChangedEventArgs(IList added, IList removed) { - this.Added = added; - this.Removed = removed; + this.Added = new ReadOnlyCollection(added); + this.Removed = new ReadOnlyCollection(removed); } #endregion From 4684e29610e68a610048f846b0e21b97d0650f76 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 8 May 2023 21:47:51 +0200 Subject: [PATCH 51/96] Changed DevicesChanged-event to provide a single device instead of a list --- .../Events/DevicesChangedEventArgs.cs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/RGB.NET.Core/Events/DevicesChangedEventArgs.cs b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs index 53a5a97e..02706de0 100644 --- a/RGB.NET.Core/Events/DevicesChangedEventArgs.cs +++ b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; namespace RGB.NET.Core; @@ -8,28 +6,25 @@ public sealed class DevicesChangedEventArgs : EventArgs { #region Properties & Fields - public IReadOnlyList Added { get; } - public IReadOnlyList Removed { get; } + public IRGBDevice? Added { get; } + public IRGBDevice? Removed { get; } #endregion #region Constructors - private DevicesChangedEventArgs(IList added, IList removed) + private DevicesChangedEventArgs(IRGBDevice? added, IRGBDevice? removed) { - this.Added = new ReadOnlyCollection(added); - this.Removed = new ReadOnlyCollection(removed); + this.Added = added; + this.Removed = removed; } #endregion #region Methods - public static DevicesChangedEventArgs CreateDevicesAddedArgs(params IRGBDevice[] addedDevices) => CreateDevicesAddedArgs((IEnumerable)addedDevices); - public static DevicesChangedEventArgs CreateDevicesAddedArgs(IEnumerable addedDevices) => new(new List(addedDevices), new List()); - - public static DevicesChangedEventArgs CreateDevicesRemovedArgs(params IRGBDevice[] removedDevices) => CreateDevicesRemovedArgs((IEnumerable)removedDevices); - public static DevicesChangedEventArgs CreateDevicesRemovedArgs(IEnumerable removedDevices) => new(new List(), new List(removedDevices)); + public static DevicesChangedEventArgs CreateDevicesAddedArgs(IRGBDevice addedDevice) => new(addedDevice, null); + public static DevicesChangedEventArgs CreateDevicesRemovedArgs(IRGBDevice removedDevice) => new(null, removedDevice); #endregion } \ No newline at end of file From 124f76b382c064c568099893f90392f8626450f8 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 8 May 2023 22:03:41 +0200 Subject: [PATCH 52/96] Fixed comment --- RGB.NET.Core/MVVM/AbstractBindable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Core/MVVM/AbstractBindable.cs b/RGB.NET.Core/MVVM/AbstractBindable.cs index b12f302a..1cb7197a 100644 --- a/RGB.NET.Core/MVVM/AbstractBindable.cs +++ b/RGB.NET.Core/MVVM/AbstractBindable.cs @@ -27,7 +27,7 @@ public abstract class AbstractBindable : IBindable /// Type of the property. /// Reference to the backing-filed. /// Value to apply. - /// true if the value needs to be updated; otherweise false. + /// true if the value needs to be updated; otherwise false. [MethodImpl(MethodImplOptions.AggressiveInlining)] protected virtual bool RequiresUpdate(ref T storage, T value) => !EqualityComparer.Default.Equals(storage, value); From 73b7f1f24fe17d4fc975c7e8bbab89c1c6e7ac4f Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 8 May 2023 22:04:36 +0200 Subject: [PATCH 53/96] Changed Bindable-Methods to not be virtual since there is not really a point in overriding them --- RGB.NET.Core/MVVM/AbstractBindable.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Core/MVVM/AbstractBindable.cs b/RGB.NET.Core/MVVM/AbstractBindable.cs index 1cb7197a..26ac0b5e 100644 --- a/RGB.NET.Core/MVVM/AbstractBindable.cs +++ b/RGB.NET.Core/MVVM/AbstractBindable.cs @@ -29,7 +29,7 @@ public abstract class AbstractBindable : IBindable /// Value to apply. /// true if the value needs to be updated; otherwise false. [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected virtual bool RequiresUpdate(ref T storage, T value) => !EqualityComparer.Default.Equals(storage, value); + protected bool RequiresUpdate(ref T storage, T value) => !EqualityComparer.Default.Equals(storage, value); /// /// Checks if the property already matches the desired value and updates it if not. @@ -40,7 +40,7 @@ public abstract class AbstractBindable : IBindable /// Name of the property used to notify listeners. This value is optional /// and can be provided automatically when invoked from compilers that support . /// true if the value was changed, false if the existing value matched the desired value. - protected virtual bool SetProperty(ref T storage, T value, [CallerMemberName] string? propertyName = null) + protected bool SetProperty(ref T storage, T value, [CallerMemberName] string? propertyName = null) { if (!RequiresUpdate(ref storage, value)) return false; @@ -55,7 +55,7 @@ protected virtual bool SetProperty(ref T storage, T value, [CallerMemberName] /// /// Name of the property used to notify listeners. This value is optional /// and can be provided automatically when invoked from compilers that support . - protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) + protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); #endregion From a196d2a0a4a5832147f0d498631dcb74149c9377 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 8 May 2023 22:07:49 +0200 Subject: [PATCH 54/96] Changed the calculation mode of the SolidColor-brush to absolute for performance reasons --- RGB.NET.Core/Rendering/Brushes/SolidColorBrush.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RGB.NET.Core/Rendering/Brushes/SolidColorBrush.cs b/RGB.NET.Core/Rendering/Brushes/SolidColorBrush.cs index 158705c3..02f8e2db 100644 --- a/RGB.NET.Core/Rendering/Brushes/SolidColorBrush.cs +++ b/RGB.NET.Core/Rendering/Brushes/SolidColorBrush.cs @@ -32,6 +32,8 @@ public Color Color public SolidColorBrush(Color color) { this.Color = color; + + CalculationMode = RenderMode.Absolute; } #endregion From d53801117b631b5549e3defb3260177a85270586 Mon Sep 17 00:00:00 2001 From: Danielle Date: Thu, 11 May 2023 19:44:37 +1000 Subject: [PATCH 55/96] Add more Razer Keyboard HIDs Added extra Razer Keyboard device HIDs, sourced from https://github.com/openrazer/openrazer. --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 313ef089..61e89689 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -109,6 +109,28 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x026C, RGBDeviceType.Keyboard, "Huntsman V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028D, RGBDeviceType.Keyboard, "BlackWidow V4", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0295, RGBDeviceType.Keyboard, "DeathStalker V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0292, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, #Wired + { 0x0290, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, #Wireless + { 0x0298, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, #Wired + { 0x0296, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, #Wireless + { 0x0294, RGBDeviceType.Keyboard, "Ornata V3 X", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x028C, RGBDeviceType.Keyboard, "Blade 14 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x028B, RGBDeviceType.Keyboard, "Blade 17 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x028A, RGBDeviceType.Keyboard, "Blade 15 Advanced (Early 2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x027A, RGBDeviceType.Keyboard, "Blade 15 Base (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0279, RGBDeviceType.Keyboard, "Blade 17 Pro (Mid 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0276, RGBDeviceType.Keyboard, "Blade 15 Advanced (Mid 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0270, RGBDeviceType.Keyboard, "Blade 14 (2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x026F, RGBDeviceType.Keyboard, "Blade 15 Base (Early 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x026E, RGBDeviceType.Keyboard, "Blade 17 Pro (Early 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x026D, RGBDeviceType.Keyboard, "Blade 15 Advanced (Early 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x026A, RGBDeviceType.Keyboard, "Book 13 (2020)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0282, RGBDeviceType.Keyboard, "Huntsman Mini Analog", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0271, RGBDeviceType.Keyboard, "BlackWidow V3 Mini Hyperspeed", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x026B, RGBDeviceType.Keyboard, "Huntsman V2 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0269, RGBDeviceType.Keyboard, "Huntsman Mini (JP)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Mice { 0x0013, RGBDeviceType.Mouse, "Orochi 2011", LedMappings.Mouse, RazerEndpointType.Mouse }, From b90c47076a51d160c1bd6a23091fdc7cb8aa52fd Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 15 May 2023 22:45:28 +0200 Subject: [PATCH 56/96] Changed DevicesChangedEventArgs to only contain the device causing the change and an enum indicatin what happened --- .../Events/DevicesChangedEventArgs.cs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/RGB.NET.Core/Events/DevicesChangedEventArgs.cs b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs index 02706de0..a0d648be 100644 --- a/RGB.NET.Core/Events/DevicesChangedEventArgs.cs +++ b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs @@ -6,25 +6,31 @@ public sealed class DevicesChangedEventArgs : EventArgs { #region Properties & Fields - public IRGBDevice? Added { get; } - public IRGBDevice? Removed { get; } + public IRGBDevice Device { get; } + public DevicesChangedAction Action { get; } #endregion #region Constructors - private DevicesChangedEventArgs(IRGBDevice? added, IRGBDevice? removed) + public DevicesChangedEventArgs(IRGBDevice device, DevicesChangedAction action) { - this.Added = added; - this.Removed = removed; + this.Device = device; + this.Action = action; } #endregion #region Methods - public static DevicesChangedEventArgs CreateDevicesAddedArgs(IRGBDevice addedDevice) => new(addedDevice, null); - public static DevicesChangedEventArgs CreateDevicesRemovedArgs(IRGBDevice removedDevice) => new(null, removedDevice); + public static DevicesChangedEventArgs CreateDevicesAddedArgs(IRGBDevice addedDevice) => new(addedDevice, DevicesChangedAction.Added); + public static DevicesChangedEventArgs CreateDevicesRemovedArgs(IRGBDevice removedDevice) => new(removedDevice, DevicesChangedAction.Removed); #endregion + + public enum DevicesChangedAction + { + Added, + Removed + } } \ No newline at end of file From 1532e31a33c7e070f15dd7e09fbf7c0117decb0d Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 15 May 2023 22:50:47 +0200 Subject: [PATCH 57/96] Improved Stop of DeviceUpdateTrigger --- RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs index 00abcc79..a45ae6ca 100644 --- a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs +++ b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs @@ -133,7 +133,7 @@ public override void Start() /// /// Stops the trigger. /// - public async void Stop() + public virtual async void Stop() { if (!IsRunning) return; @@ -141,7 +141,9 @@ public async void Stop() UpdateTokenSource?.Cancel(); if (UpdateTask != null) - await UpdateTask; + try { await UpdateTask.ConfigureAwait(false); } + catch (TaskCanceledException) { } + catch (OperationCanceledException) { } UpdateTask?.Dispose(); UpdateTask = null; From 0aca2d84b16868f35ded00d4f9c4db615bfb8345 Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Sat, 20 May 2023 19:36:53 +0000 Subject: [PATCH 58/96] Apply suggestions from code review --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 61e89689..4513d3db 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -111,10 +111,10 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0295, RGBDeviceType.Keyboard, "DeathStalker V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x0292, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, #Wired - { 0x0290, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, #Wireless - { 0x0298, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, #Wired - { 0x0296, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, #Wireless + { 0x0292, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired + { 0x0290, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless + { 0x0298, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired + { 0x0296, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless { 0x0294, RGBDeviceType.Keyboard, "Ornata V3 X", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028C, RGBDeviceType.Keyboard, "Blade 14 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028B, RGBDeviceType.Keyboard, "Blade 17 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, From 5dbcd9c81eb05564bd843ad91c2dfb7921ecbeaf Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 20 May 2023 22:34:29 +0200 Subject: [PATCH 59/96] Added SteelSeries Aerox 5 Wireless #323 --- RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs index 417a4489..61f32548 100644 --- a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs +++ b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs @@ -55,6 +55,8 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider { 0x1832, RGBDeviceType.Mouse, "Sensei Ten", LedMappings.MouseTwoZone, SteelSeriesDeviceType.TwoZone }, { 0x1838, RGBDeviceType.Mouse, "Aerox 3 Wireless", LedMappings.MouseThreeZone, SteelSeriesDeviceType.ThreeZone }, { 0x183C, RGBDeviceType.Mouse, "Rival 5", LedMappings.MouseTenZone, SteelSeriesDeviceType.TenZone }, + { 0x1854, RGBDeviceType.Mouse, "Aerox 5 Wireless", LedMappings.MouseThreeZone, SteelSeriesDeviceType.ThreeZone }, + { 0x1852, RGBDeviceType.Mouse, "Aerox 5 Wireless", LedMappings.MouseThreeZone, SteelSeriesDeviceType.ThreeZone }, //Keyboards { 0x161C, RGBDeviceType.Keyboard, "Apex 5", LedMappings.KeyboardMappingUk, SteelSeriesDeviceType.PerKey }, From e547bae2096bce5499c1c3b13745157f8c2b0ab0 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Tue, 23 May 2023 22:58:13 +0100 Subject: [PATCH 60/96] Update OpenRGB.NET nuget --- RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj index 94ce6047..f3b3a814 100644 --- a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj +++ b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj @@ -57,7 +57,7 @@ - + From ca3c9fc5d382a017cc71b1a9f718c2e55a12ea6a Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Fri, 2 Jun 2023 22:14:12 +0100 Subject: [PATCH 61/96] WIP - Fixed corsair partial devices getting longer the first device has the correct size, all following ones are larger than intended. tested with corsaid lighting node core and sp120 --- .../Generic/CorsairRGBDevice.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs index 94fd49c1..e780de15 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using RGB.NET.Core; using RGB.NET.Devices.Corsair.Native; @@ -58,6 +58,18 @@ protected virtual void InitializeLayout() Rectangle rectangle = ledPosition.ToRectangle(); AddLed(ledId, rectangle.Location, rectangle.Size); } + + if (DeviceInfo.LedOffset > 0) + FixOffsetDeviceLayout(); + } + + protected virtual void FixOffsetDeviceLayout() + { + float minX = this.Min(x => x.Location.X); + float minY = this.Min(x => x.Location.Y); + + foreach (Led led in this) + led.Location = led.Location.Translate(-minX, -minY); } protected abstract LedMapping CreateMapping(IEnumerable ids); From d7fffb42136c9e46141821983be322bdd1d50b27 Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Sat, 3 Jun 2023 19:28:15 +0000 Subject: [PATCH 62/96] Added comment to new corsai FixOffsetDeviceLayout-method --- RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs index e780de15..9fcbca62 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs @@ -63,6 +63,9 @@ protected virtual void InitializeLayout() FixOffsetDeviceLayout(); } + /// + /// Fixes the locations for devices split by offset by aligning them to the top left. + /// protected virtual void FixOffsetDeviceLayout() { float minX = this.Min(x => x.Location.X); From bf711325cfca92815347e3282e7ec95c954a7904 Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 11 Jun 2023 10:19:27 +0200 Subject: [PATCH 63/96] Added more Razer keyboard and mouse PIDs --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 71 +++++++++++++------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 4513d3db..efa7daa9 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -55,6 +55,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x010F, RGBDeviceType.Keyboard, "Anansi", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x011A, RGBDeviceType.Keyboard, "BlackWidow Ultimate 2013", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x011B, RGBDeviceType.Keyboard, "BlackWidow Stealth", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x011C, RGBDeviceType.Keyboard, "BlackWidow Tournament Edition 2014", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0202, RGBDeviceType.Keyboard, "DeathStalker Expert", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0203, RGBDeviceType.Keyboard, "BlackWidow Chroma", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0204, RGBDeviceType.Keyboard, "DeathStalker Chroma", LedMappings.Keyboard, RazerEndpointType.Keyboard }, @@ -77,6 +78,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0227, RGBDeviceType.Keyboard, "Huntsman", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0228, RGBDeviceType.Keyboard, "BlackWidow Elite", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x022A, RGBDeviceType.Keyboard, "Cynosa Chroma", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x022C, RGBDeviceType.Keyboard, "Cynosa Chroma Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x022D, RGBDeviceType.Keyboard, "Blade Stealth (Mid 2017)", LedMappings.Keyboard, RazerEndpointType.LaptopKeyboard }, { 0x022F, RGBDeviceType.Keyboard, "Blade Pro FullHD (2017)", LedMappings.Keyboard, RazerEndpointType.LaptopKeyboard }, { 0x0232, RGBDeviceType.Keyboard, "Blade Stealth (Late 2017)", LedMappings.Keyboard, RazerEndpointType.LaptopKeyboard }, @@ -100,37 +102,40 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0252, RGBDeviceType.Keyboard, "Blade Stealth (Early 2020)", LedMappings.Keyboard, RazerEndpointType.LaptopKeyboard }, { 0x0253, RGBDeviceType.Keyboard, "Blade 15 Advanced (2020)", LedMappings.Keyboard, RazerEndpointType.LaptopKeyboard }, { 0x0255, RGBDeviceType.Keyboard, "Blade 15 (Early 2020) Base", LedMappings.Keyboard, RazerEndpointType.LaptopKeyboard }, + { 0x0256, RGBDeviceType.Keyboard, "Blade Blade Pro (Early 2020)", LedMappings.Keyboard, RazerEndpointType.LaptopKeyboard }, + { 0x0257, RGBDeviceType.Keyboard, "Huntsman Mini", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0258, RGBDeviceType.Keyboard, "BlackWidow V3 Mini", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0259, RGBDeviceType.Keyboard, "Blade Stealth (Late 2020)", LedMappings.Keyboard, RazerEndpointType.LaptopKeyboard }, - { 0x25A, RGBDeviceType.Keyboard, "BlackWidow V3 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // The keyboard, only present when connected with cable - { 0x25C, RGBDeviceType.Keyboard, "BlackWidow V3 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // The dongle, may not be present when connected with cable + { 0x025A, RGBDeviceType.Keyboard, "BlackWidow V3 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // The keyboard, only present when connected with cable + { 0x025C, RGBDeviceType.Keyboard, "BlackWidow V3 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // The dongle, may not be present when connected with cable { 0x025D, RGBDeviceType.Keyboard, "Ornata Chroma V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x025E, RGBDeviceType.Keyboard, "Cynosa V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0266, RGBDeviceType.Keyboard, "Huntsman V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0269, RGBDeviceType.Keyboard, "Huntsman Mini (JP)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x026A, RGBDeviceType.Keyboard, "Book 13 (2020)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x026B, RGBDeviceType.Keyboard, "Huntsman V2 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x026C, RGBDeviceType.Keyboard, "Huntsman V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x026D, RGBDeviceType.Keyboard, "Blade 15 Advanced (Early 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x026E, RGBDeviceType.Keyboard, "Blade 17 Pro (Early 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x026F, RGBDeviceType.Keyboard, "Blade 15 Base (Early 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0270, RGBDeviceType.Keyboard, "Blade 14 (2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0271, RGBDeviceType.Keyboard, "BlackWidow V3 Mini Hyperspeed", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0276, RGBDeviceType.Keyboard, "Blade 15 Advanced (Mid 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0279, RGBDeviceType.Keyboard, "Blade 17 Pro (Mid 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x027A, RGBDeviceType.Keyboard, "Blade 15 Base (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0282, RGBDeviceType.Keyboard, "Huntsman Mini Analog", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x028A, RGBDeviceType.Keyboard, "Blade 15 Advanced (Early 2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x028B, RGBDeviceType.Keyboard, "Blade 17 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x028C, RGBDeviceType.Keyboard, "Blade 14 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028D, RGBDeviceType.Keyboard, "BlackWidow V4", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x0295, RGBDeviceType.Keyboard, "DeathStalker V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x0292, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired { 0x0290, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless - { 0x0298, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired - { 0x0296, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless + { 0x0292, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired { 0x0294, RGBDeviceType.Keyboard, "Ornata V3 X", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x028C, RGBDeviceType.Keyboard, "Blade 14 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x028B, RGBDeviceType.Keyboard, "Blade 17 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x028A, RGBDeviceType.Keyboard, "Blade 15 Advanced (Early 2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x027A, RGBDeviceType.Keyboard, "Blade 15 Base (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x0279, RGBDeviceType.Keyboard, "Blade 17 Pro (Mid 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x0276, RGBDeviceType.Keyboard, "Blade 15 Advanced (Mid 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x0270, RGBDeviceType.Keyboard, "Blade 14 (2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x026F, RGBDeviceType.Keyboard, "Blade 15 Base (Early 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x026E, RGBDeviceType.Keyboard, "Blade 17 Pro (Early 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x026D, RGBDeviceType.Keyboard, "Blade 15 Advanced (Early 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x026A, RGBDeviceType.Keyboard, "Book 13 (2020)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x0282, RGBDeviceType.Keyboard, "Huntsman Mini Analog", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x0271, RGBDeviceType.Keyboard, "BlackWidow V3 Mini Hyperspeed", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x026B, RGBDeviceType.Keyboard, "Huntsman V2 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x0269, RGBDeviceType.Keyboard, "Huntsman Mini (JP)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0295, RGBDeviceType.Keyboard, "DeathStalker V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0296, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless + { 0x0298, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired + { 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Mice { 0x0013, RGBDeviceType.Mouse, "Orochi 2011", LedMappings.Mouse, RazerEndpointType.Mouse }, @@ -138,6 +143,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0020, RGBDeviceType.Mouse, "Abyssus 1800", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0024, RGBDeviceType.Mouse, "Mamba 2012 (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0025, RGBDeviceType.Mouse, "Mamba 2012 (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x0029, RGBDeviceType.Mouse, "DeathAdder V3 5G", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x002E, RGBDeviceType.Mouse, "Naga 2012", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x002F, RGBDeviceType.Mouse, "Imperator 2012", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0032, RGBDeviceType.Mouse, "Ouroboros 2012", LedMappings.Mouse, RazerEndpointType.Mouse }, @@ -167,6 +173,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0060, RGBDeviceType.Mouse, "Lancehead Tournament Edition", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0062, RGBDeviceType.Mouse, "Atheris (Receiver)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0064, RGBDeviceType.Mouse, "Basilisk", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x0065, RGBDeviceType.Mouse, "Basilisk Essential", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0067, RGBDeviceType.Mouse, "Naga Trinity", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x006A, RGBDeviceType.Mouse, "Abyssus Elite (D.Va Edition)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x006B, RGBDeviceType.Mouse, "Abyssus Essential", LedMappings.Mouse, RazerEndpointType.Mouse }, @@ -177,24 +184,38 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0071, RGBDeviceType.Mouse, "DeathAdder Essential (White Edition)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0072, RGBDeviceType.Mouse, "Mamba Wireless (Receiver)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0073, RGBDeviceType.Mouse, "Mamba Wireless (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x0077, RGBDeviceType.Mouse, "Pro Click (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0078, RGBDeviceType.Mouse, "Viper", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x007A, RGBDeviceType.Mouse, "Viper Ultimate (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x007B, RGBDeviceType.Mouse, "Viper Ultimate (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x007C, RGBDeviceType.Mouse, "DeathAdder V2 Pro (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x007D, RGBDeviceType.Mouse, "DeathAdder V2 Pro (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x0080, RGBDeviceType.Mouse, "Pro Click (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0083, RGBDeviceType.Mouse, "Basilisk X HyperSpeed", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x0084, RGBDeviceType.Mouse, "DeathAdder V2", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0085, RGBDeviceType.Mouse, "Basilisk V2", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x0085, RGBDeviceType.Mouse, "Basilisk Ultimate (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0088, RGBDeviceType.Mouse, "Basilisk Ultimate", LedMappings.Mouse, RazerEndpointType.Mouse }, - { 0x0084, RGBDeviceType.Mouse, "DeathAdder V2", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x008A, RGBDeviceType.Mouse, "Viper Mini", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x008C, RGBDeviceType.Mouse, "DeathAdder V2 Mini", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x008D, RGBDeviceType.Mouse, "Naga Left Handed Edition", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x008F, RGBDeviceType.Mouse, "Naga Pro", LedMappings.Mouse, RazerEndpointType.Mouse }, //this is via usb connection { 0x0090, RGBDeviceType.Mouse, "Naga Pro", LedMappings.Mouse, RazerEndpointType.Mouse }, //this is via bluetooth connection { 0x0091, RGBDeviceType.Mouse, "Viper 8khz", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x0094, RGBDeviceType.Mouse, "Orochi V2", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0096, RGBDeviceType.Mouse, "Naga X", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0099, RGBDeviceType.Mouse, "Basilisk v3", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x009A, RGBDeviceType.Mouse, "Pro Click Mini (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x009C, RGBDeviceType.Mouse, "DeathAdder V2 X Hyperspeed", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x00A1, RGBDeviceType.Mouse, "DeathAdder V2 Lite", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x00A5, RGBDeviceType.Mouse, "Viper V2 Pro (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x00A6, RGBDeviceType.Mouse, "Viper V2 Pro (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00A8, RGBDeviceType.Mouse, "Naga V2 Pro", LedMappings.Mouse, RazerEndpointType.Mouse }, - + { 0x00AA, RGBDeviceType.Mouse, "Basilisk V3 Pro (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x00AB, RGBDeviceType.Mouse, "Basilisk V3 Pro (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x00B6, RGBDeviceType.Mouse, "DeathAdder V3 (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x00B7, RGBDeviceType.Mouse, "DeathAdder V3 (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, + // Mousepads { 0x0068, RGBDeviceType.Mousepad, "Firefly Hyperflux", LedMappings.Mousepad, RazerEndpointType.Mousepad }, { 0x0C00, RGBDeviceType.Mousepad, "Firefly", LedMappings.Mousepad, RazerEndpointType.Mousepad }, From 2b203b2308695f9c784d2d869c3ba6d6912a5677 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 12 Jun 2023 19:48:52 +0200 Subject: [PATCH 64/96] Fix duplicate --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index efa7daa9..344f96e1 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -194,7 +194,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0083, RGBDeviceType.Mouse, "Basilisk X HyperSpeed", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0084, RGBDeviceType.Mouse, "DeathAdder V2", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0085, RGBDeviceType.Mouse, "Basilisk V2", LedMappings.Mouse, RazerEndpointType.Mouse }, - { 0x0085, RGBDeviceType.Mouse, "Basilisk Ultimate (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x0086, RGBDeviceType.Mouse, "Basilisk Ultimate (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0088, RGBDeviceType.Mouse, "Basilisk Ultimate", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x008A, RGBDeviceType.Mouse, "Viper Mini", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x008C, RGBDeviceType.Mouse, "DeathAdder V2 Mini", LedMappings.Mouse, RazerEndpointType.Mouse }, From fdc69fdac5e0273aaafcdb455e3297a752d71446 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 15 Jun 2023 23:03:24 +0200 Subject: [PATCH 65/96] Implemented recommended dispose pattern for DeviceProviders --- .../Devices/AbstractRGBDeviceProvider.cs | 34 +++++++++++++++++-- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 5 +-- .../CoolerMasterDeviceProvider.cs | 6 ++-- .../CorsairDeviceProvider.cs | 6 ++-- RGB.NET.Devices.DMX/DMXDeviceProvider.cs | 8 +++++ RGB.NET.Devices.Debug/DebugDeviceProvider.cs | 6 ++-- .../LogitechDeviceProvider.cs | 6 ++-- RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 8 ++--- .../NovationDeviceProvider.cs | 8 +++++ .../OpenRGBDeviceProvider.cs | 16 +++++---- .../PicoPiDeviceProvider.cs | 8 +++++ RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 6 ++-- .../SteelSeriesDeviceProvider.cs | 6 ++-- .../WS281XDeviceProvider.cs | 6 ++-- .../WootingDeviceProvider.cs | 6 ++-- 15 files changed, 103 insertions(+), 32 deletions(-) diff --git a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs index e76554e1..2d1f2eba 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs @@ -12,6 +12,8 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider { #region Properties & Fields + private bool _isDisposed = false; + private readonly double _defaultUpdateRateHardLimit; /// @@ -60,6 +62,8 @@ protected AbstractRGBDeviceProvider(double defaultUpdateRateHardLimit = 0) this._defaultUpdateRateHardLimit = defaultUpdateRateHardLimit; } + ~AbstractRGBDeviceProvider() => Dispose(false); + #endregion #region Methods @@ -67,6 +71,8 @@ protected AbstractRGBDeviceProvider(double defaultUpdateRateHardLimit = 0) /// public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { + if (_isDisposed) throw new ObjectDisposedException(GetType().FullName); + ThrowsExceptions = throwExceptions; try @@ -108,6 +114,8 @@ public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwE /// The filtered collection of loaded devices. protected virtual IEnumerable GetLoadedDevices(RGBDeviceType loadFilter) { + if (_isDisposed) throw new ObjectDisposedException(GetType().FullName); + List devices = new(); foreach (IRGBDevice device in LoadDevices()) { @@ -152,6 +160,8 @@ protected virtual IEnumerable GetLoadedDevices(RGBDeviceType loadFil /// The update trigger mapped to the specified id. protected virtual IDeviceUpdateTrigger GetUpdateTrigger(int id = -1, double? updateRateHardLimit = null) { + if (_isDisposed) throw new ObjectDisposedException(GetType().FullName); + if (!UpdateTriggerMapping.TryGetValue(id, out IDeviceUpdateTrigger? updaeTrigger)) UpdateTriggerMapping[id] = (updaeTrigger = CreateUpdateTrigger(id, updateRateHardLimit ?? _defaultUpdateRateHardLimit)); @@ -171,6 +181,8 @@ protected virtual IDeviceUpdateTrigger GetUpdateTrigger(int id = -1, double? upd /// protected virtual void Reset() { + if (_isDisposed) throw new ObjectDisposedException(GetType().FullName); + foreach (IDeviceUpdateTrigger updateTrigger in UpdateTriggerMapping.Values) updateTrigger.Dispose(); @@ -192,6 +204,8 @@ protected virtual void Reset() /// true if the device was added successfully; otherwise false. protected virtual bool AddDevice(IRGBDevice device) { + if (_isDisposed) throw new ObjectDisposedException(GetType().FullName); + if (InternalDevices.Contains(device)) return false; InternalDevices.Add(device); @@ -207,6 +221,8 @@ protected virtual bool AddDevice(IRGBDevice device) /// true if the device was removed successfully; otherwise false. protected virtual bool RemoveDevice(IRGBDevice device) { + if (_isDisposed) throw new ObjectDisposedException(GetType().FullName); + if (!InternalDevices.Remove(device)) return false; try { OnDevicesChanged(DevicesChangedEventArgs.CreateDevicesRemovedArgs(device)); } catch { /* we don't want to throw due to bad event handlers */ } @@ -241,12 +257,26 @@ public virtual void Throw(Exception ex, bool isCritical = false) protected virtual void OnDevicesChanged(DevicesChangedEventArgs args) => DevicesChanged?.Invoke(this, args); /// - public virtual void Dispose() + public void Dispose() { - Reset(); + if (_isDisposed) return; + + try + { + Dispose(true); + } + catch { /* don't throw in dispose! */ } GC.SuppressFinalize(this); + + _isDisposed = true; } + /// + /// Disposes the object and frees all resources. + /// + /// true if explicitely called through the Dispose-Method, false if called by the destructor. + protected virtual void Dispose(bool disposing) => Reset(); + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index e3b093c2..1558f6d7 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -80,15 +80,16 @@ protected override IEnumerable LoadDevices() } /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + base.Dispose(disposing); try { _sdk?.ReleaseControl(0); } catch { /* at least we tried */ } _devices = null; _sdk = null; + _instance = null; } #endregion diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index ab16a450..be075dfc 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -94,12 +94,14 @@ protected override IEnumerable LoadDevices() } /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + base.Dispose(disposing); try { _CoolerMasterSDK.Reload(); } catch { /* Unlucky.. */ } + + _instance = null; } #endregion diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 87ab725e..88f45098 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -300,12 +300,14 @@ private IEnumerable LoadCorsairDevices() } /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + base.Dispose(disposing); try { _CUESDK.CorsairDisconnect(); } catch { /* at least we tried */ } try { _CUESDK.UnloadCUESDK(); } catch { /* at least we tried */ } + + _instance = null; } #endregion diff --git a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs index 2d85a440..0baad66f 100644 --- a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs +++ b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs @@ -86,5 +86,13 @@ protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updat return updateTrigger; } + /// + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + _instance = null; + } + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs index f88ad50c..f37e4e94 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs @@ -66,11 +66,13 @@ protected override IEnumerable LoadDevices() } /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + base.Dispose(disposing); _fakeDeviceDefinitions.Clear(); + + _instance = null; } #endregion diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs index 4ebd163f..f6a8862d 100644 --- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs +++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs @@ -254,9 +254,9 @@ protected override IEnumerable LoadDevices() } /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + base.Dispose(disposing); try { _LogitechGSDK.LogiLedRestoreLighting(); } catch { /* at least we tried */ } @@ -264,7 +264,7 @@ public override void Dispose() try { _LogitechGSDK.UnloadLogitechGSDK(); } catch { /* at least we tried */ } - GC.SuppressFinalize(this); + _instance = null; } #endregion diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index fb188272..c45a2df3 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -98,14 +98,14 @@ protected override IEnumerable LoadDevices() private void ThrowMsiError(int errorCode, bool isCritical = false) => Throw(new MysticLightException(errorCode, _MsiSDK.GetErrorMessage(errorCode)), isCritical); /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + base.Dispose(disposing); try { _MsiSDK.UnloadMsiSDK(); } catch { /* at least we tried */ } - - GC.SuppressFinalize(this); + + _instance = null; } #endregion diff --git a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs index 837a82c4..9c9555b8 100644 --- a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs +++ b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs @@ -67,5 +67,13 @@ protected override IEnumerable LoadDevices() } } + /// + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + _instance = null; + } + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs index 4d194843..50647a1c 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs @@ -107,22 +107,22 @@ protected override IEnumerable LoadDevices() continue; } - if (device.Zones.Length == 0) + if (device.Zones.Length == 0) continue; - if (device.Zones.All(z => z.LedCount == 0)) + if (device.Zones.All(z => z.LedCount == 0)) continue; OpenRGBUpdateQueue updateQueue = new(GetUpdateTrigger(), i, openRgb, device); - + bool anyZoneHasSegments = device.Zones.Any(z => z.Segments.Length > 0); - bool splitDeviceByZones = anyZoneHasSegments || PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type)); + bool splitDeviceByZones = anyZoneHasSegments || PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type)); if (!splitDeviceByZones) { yield return new OpenRGBGenericDevice(new OpenRGBDeviceInfo(device), updateQueue); continue; } - + int totalLedCount = 0; foreach (Zone zone in device.Zones) @@ -149,9 +149,9 @@ protected override IEnumerable LoadDevices() } /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + base.Dispose(disposing); foreach (OpenRgbClient client in _clients) { @@ -161,6 +161,8 @@ public override void Dispose() _clients.Clear(); DeviceDefinitions.Clear(); + + _instance = null; } #endregion diff --git a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs index f18116fa..debdc39e 100644 --- a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs +++ b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs @@ -126,5 +126,13 @@ protected override void Reset() _sdks.Clear(); } + /// + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + _instance = null; + } + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 344f96e1..05c18c15 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -342,15 +342,17 @@ private void TryUnInit() } /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + base.Dispose(disposing); TryUnInit(); // DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit //try { _RazerSDK.UnloadRazerSDK(); } //catch { /* at least we tried */ } + + _instance = null; } #endregion diff --git a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs index 61f32548..eeeff1c6 100644 --- a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs +++ b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs @@ -133,12 +133,14 @@ protected override IEnumerable LoadDevices() protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new DeviceUpdateTrigger(updateRateHardLimit) { HeartbeatTimer = HEARTBEAT_TIMER }; /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + base.Dispose(disposing); try { SteelSeriesSDK.Dispose(); } catch { /* shit happens */ } + + _instance = null; } #endregion diff --git a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs index 4d2e047e..43077c8c 100644 --- a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs +++ b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs @@ -70,11 +70,13 @@ protected override IEnumerable LoadDevices() } /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + base.Dispose(disposing); DeviceDefinitions.Clear(); + + _instance = null; } #endregion diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 484bbaf0..079ffb1f 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -94,15 +94,17 @@ protected override IEnumerable LoadDevices() } /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + base.Dispose(disposing); lock (_WootingSDK.SdkLock) { try { _WootingSDK.UnloadWootingSDK(); } catch { /* at least we tried */ } } + + _instance = null; } #endregion From 0609e4957170531253b8ace965bbf04f5be70778 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 18 Jun 2023 19:54:57 +0200 Subject: [PATCH 66/96] Added locks around device provider instance usages --- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 34 +++++++++++----- .../CoolerMasterDeviceProvider.cs | 30 ++++++++++---- .../CorsairDeviceProvider.cs | 33 +++++++++++---- RGB.NET.Devices.DMX/DMXDeviceProvider.cs | 26 +++++++++--- RGB.NET.Devices.Debug/DebugDeviceProvider.cs | 28 ++++++++++--- .../LogitechDeviceProvider.cs | 37 ++++++++++++----- RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 32 +++++++++++---- .../NovationDeviceProvider.cs | 26 +++++++++--- .../OpenRGBDeviceProvider.cs | 40 +++++++++++++------ .../PicoPiDeviceProvider.cs | 26 +++++++++--- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 36 ++++++++++++----- .../SteelSeriesDeviceProvider.cs | 30 ++++++++++---- .../WS281XDeviceProvider.cs | 28 ++++++++++--- .../WootingDeviceProvider.cs | 36 ++++++++++++----- 14 files changed, 335 insertions(+), 107 deletions(-) diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index 1558f6d7..805db68e 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -16,11 +16,21 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static AsusDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static AsusDeviceProvider Instance => _instance ?? new AsusDeviceProvider(); + public static AsusDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new AsusDeviceProvider(); + } + } private IAuraSdk2? _sdk; private IAuraSyncDeviceCollection? _devices; //HACK DarthAffe 05.04.2021: Due to some researches this might fix the access violation in the asus-sdk @@ -35,8 +45,11 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public AsusDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(AsusDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(AsusDeviceProvider)}"); + _instance = this; + } } #endregion @@ -82,14 +95,17 @@ protected override IEnumerable LoadDevices() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - try { _sdk?.ReleaseControl(0); } - catch { /* at least we tried */ } + try { _sdk?.ReleaseControl(0); } + catch { /* at least we tried */ } - _devices = null; - _sdk = null; - _instance = null; + _devices = null; + _sdk = null; + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index be075dfc..8678e1a1 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -17,11 +17,21 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static CoolerMasterDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static CoolerMasterDeviceProvider Instance => _instance ?? new CoolerMasterDeviceProvider(); + public static CoolerMasterDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new CoolerMasterDeviceProvider(); + } + } /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. @@ -45,8 +55,11 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public CoolerMasterDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CoolerMasterDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CoolerMasterDeviceProvider)}"); + _instance = this; + } } #endregion @@ -96,12 +109,15 @@ protected override IEnumerable LoadDevices() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - try { _CoolerMasterSDK.Reload(); } - catch { /* Unlucky.. */ } + try { _CoolerMasterSDK.Reload(); } + catch { /* Unlucky.. */ } - _instance = null; + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 88f45098..89f46841 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -17,11 +17,21 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static CorsairDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static CorsairDeviceProvider Instance => _instance ?? new CorsairDeviceProvider(); + public static CorsairDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new CorsairDeviceProvider(); + } + } /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. @@ -80,8 +90,11 @@ private set /// Thrown if this constructor is called even if there is already an instance of this class. public CorsairDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairDeviceProvider)}"); + _instance = this; + } } #endregion @@ -302,12 +315,18 @@ private IEnumerable LoadCorsairDevices() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - try { _CUESDK.CorsairDisconnect(); } catch { /* at least we tried */ } - try { _CUESDK.UnloadCUESDK(); } catch { /* at least we tried */ } + try { _CUESDK.CorsairDisconnect(); } + catch { /* at least we tried */ } - _instance = null; + try { _CUESDK.UnloadCUESDK(); } + catch { /* at least we tried */ } + + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs index 0baad66f..d5f2456a 100644 --- a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs +++ b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs @@ -16,11 +16,21 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static DMXDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static DMXDeviceProvider Instance => _instance ?? new DMXDeviceProvider(); + public static DMXDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new DMXDeviceProvider(); + } + } /// /// Gets a list of all defined device-definitions. @@ -37,8 +47,11 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public DMXDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DMXDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DMXDeviceProvider)}"); + _instance = this; + } } #endregion @@ -89,9 +102,12 @@ protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updat /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - _instance = null; + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs index f37e4e94..836c6db6 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs @@ -16,11 +16,21 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static DebugDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static DebugDeviceProvider Instance => _instance ?? new DebugDeviceProvider(); + public static DebugDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new DebugDeviceProvider(); + } + } private List<(IDeviceLayout layout, Action>? updateLedsAction)> _fakeDeviceDefinitions = new(); @@ -34,8 +44,11 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public DebugDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DebugDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DebugDeviceProvider)}"); + _instance = this; + } } #endregion @@ -68,11 +81,14 @@ protected override IEnumerable LoadDevices() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - _fakeDeviceDefinitions.Clear(); + _fakeDeviceDefinitions.Clear(); - _instance = null; + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs index f6a8862d..4a12b395 100644 --- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs +++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs @@ -20,11 +20,21 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static LogitechDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static LogitechDeviceProvider Instance => _instance ?? new LogitechDeviceProvider(); + public static LogitechDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new LogitechDeviceProvider(); + } + } /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. @@ -112,7 +122,7 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider { 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4, 0) }, }; - + /// /// Gets the HID-definitions for wireless per-zone-devices. /// @@ -164,8 +174,12 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public LogitechDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(LogitechDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) + throw new InvalidOperationException($"There can be only one instance of type {nameof(LogitechDeviceProvider)}"); + _instance = this; + } } #endregion @@ -256,15 +270,18 @@ protected override IEnumerable LoadDevices() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - try { _LogitechGSDK.LogiLedRestoreLighting(); } - catch { /* at least we tried */ } + try { _LogitechGSDK.LogiLedRestoreLighting(); } + catch { /* at least we tried */ } - try { _LogitechGSDK.UnloadLogitechGSDK(); } - catch { /* at least we tried */ } + try { _LogitechGSDK.UnloadLogitechGSDK(); } + catch { /* at least we tried */ } - _instance = null; + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index c45a2df3..1a305cc5 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -17,11 +17,21 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static MsiDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static MsiDeviceProvider Instance => _instance ?? new MsiDeviceProvider(); + public static MsiDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new MsiDeviceProvider(); + } + } /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. @@ -45,8 +55,11 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public MsiDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(MsiDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(MsiDeviceProvider)}"); + _instance = this; + } } #endregion @@ -100,12 +113,15 @@ protected override IEnumerable LoadDevices() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - try { _MsiSDK.UnloadMsiSDK(); } - catch { /* at least we tried */ } - - _instance = null; + try { _MsiSDK.UnloadMsiSDK(); } + catch { /* at least we tried */ } + + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs index 9c9555b8..9a86f6f5 100644 --- a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs +++ b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs @@ -17,11 +17,21 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static NovationDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static NovationDeviceProvider Instance => _instance ?? new NovationDeviceProvider(); + public static NovationDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new NovationDeviceProvider(); + } + } #endregion @@ -33,8 +43,11 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. private NovationDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(NovationDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(NovationDeviceProvider)}"); + _instance = this; + } } #endregion @@ -70,9 +83,12 @@ protected override IEnumerable LoadDevices() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - _instance = null; + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs index 50647a1c..4ad82cc6 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs @@ -14,6 +14,9 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private readonly List _clients = new(); private static OpenRGBDeviceProvider? _instance; @@ -21,7 +24,14 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider /// /// Gets the singleton instance. /// - public static OpenRGBDeviceProvider Instance => _instance ?? new OpenRGBDeviceProvider(); + public static OpenRGBDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new OpenRGBDeviceProvider(); + } + } /// /// Gets a list of all defined device-definitions. @@ -48,8 +58,11 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public OpenRGBDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(OpenRGBDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(OpenRGBDeviceProvider)}"); + _instance = this; + } } #endregion @@ -151,18 +164,21 @@ protected override IEnumerable LoadDevices() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); - - foreach (OpenRgbClient client in _clients) + lock (_lock) { - try { client.Dispose(); } - catch { /* at least we tried */ } - } + base.Dispose(disposing); + + foreach (OpenRgbClient client in _clients) + { + try { client.Dispose(); } + catch { /* at least we tried */ } + } - _clients.Clear(); - DeviceDefinitions.Clear(); + _clients.Clear(); + DeviceDefinitions.Clear(); - _instance = null; + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs index debdc39e..c7994609 100644 --- a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs +++ b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs @@ -25,11 +25,21 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static PicoPiDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static PicoPiDeviceProvider Instance => _instance ?? new PicoPiDeviceProvider(); + public static PicoPiDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new PicoPiDeviceProvider(); + } + } /// /// Gets the HID-definitions for PicoPi-devices. @@ -57,8 +67,11 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public PicoPiDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(PicoPiDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(PicoPiDeviceProvider)}"); + _instance = this; + } } #endregion @@ -129,9 +142,12 @@ protected override void Reset() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - _instance = null; + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 05c18c15..54cabf87 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -19,11 +19,21 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static RazerDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static RazerDeviceProvider Instance => _instance ?? new RazerDeviceProvider(); + public static RazerDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new RazerDeviceProvider(); + } + } /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. @@ -254,7 +264,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x0F13, RGBDeviceType.Unknown, "Lian Li O11", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F1D, RGBDeviceType.Unknown, "Mouse Bungee V3 Chroma", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F1F, RGBDeviceType.LedController, "Addressable RGB Controller", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, - + }; #endregion @@ -267,8 +277,11 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public RazerDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(RazerDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(RazerDeviceProvider)}"); + _instance = this; + } } #endregion @@ -344,15 +357,18 @@ private void TryUnInit() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - TryUnInit(); + TryUnInit(); - // DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit - //try { _RazerSDK.UnloadRazerSDK(); } - //catch { /* at least we tried */ } + // DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit + //try { _RazerSDK.UnloadRazerSDK(); } + //catch { /* at least we tried */ } - _instance = null; + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs index eeeff1c6..0bf1958e 100644 --- a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs +++ b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs @@ -20,11 +20,21 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static SteelSeriesDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static SteelSeriesDeviceProvider Instance => _instance ?? new SteelSeriesDeviceProvider(); + public static SteelSeriesDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new SteelSeriesDeviceProvider(); + } + } private const int VENDOR_ID = 0x1038; @@ -93,8 +103,11 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public SteelSeriesDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SteelSeriesDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SteelSeriesDeviceProvider)}"); + _instance = this; + } } #endregion @@ -135,12 +148,15 @@ protected override IEnumerable LoadDevices() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - try { SteelSeriesSDK.Dispose(); } - catch { /* shit happens */ } + try { SteelSeriesSDK.Dispose(); } + catch { /* shit happens */ } - _instance = null; + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs index 43077c8c..e1500287 100644 --- a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs +++ b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs @@ -16,11 +16,21 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static WS281XDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static WS281XDeviceProvider Instance => _instance ?? new WS281XDeviceProvider(); + public static WS281XDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new WS281XDeviceProvider(); + } + } /// /// Gets a list of all defined device-definitions. @@ -39,8 +49,11 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public WS281XDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WS281XDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WS281XDeviceProvider)}"); + _instance = this; + } } #endregion @@ -72,11 +85,14 @@ protected override IEnumerable LoadDevices() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); + lock (_lock) + { + base.Dispose(disposing); - DeviceDefinitions.Clear(); + DeviceDefinitions.Clear(); - _instance = null; + _instance = null; + } } #endregion diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 079ffb1f..6d16b2f7 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -16,11 +16,21 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static WootingDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static WootingDeviceProvider Instance => _instance ?? new WootingDeviceProvider(); + public static WootingDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new WootingDeviceProvider(); + } + } /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications. @@ -57,8 +67,11 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public WootingDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}"); + _instance = this; + } } #endregion @@ -96,15 +109,18 @@ protected override IEnumerable LoadDevices() /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); - - lock (_WootingSDK.SdkLock) + lock (_lock) { - try { _WootingSDK.UnloadWootingSDK(); } - catch { /* at least we tried */ } - } + base.Dispose(disposing); - _instance = null; + lock (_WootingSDK.SdkLock) + { + try { _WootingSDK.UnloadWootingSDK(); } + catch { /* at least we tried */ } + } + + _instance = null; + } } #endregion From ba99ecfbdcabdee3a9eb5d952d449e6457fc8a57 Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 9 Jul 2023 13:43:54 +0200 Subject: [PATCH 67/96] Layout - Allow loading directly from a stream --- RGB.NET.Layout/DeviceLayout.cs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/RGB.NET.Layout/DeviceLayout.cs b/RGB.NET.Layout/DeviceLayout.cs index bdddb99b..24efd371 100644 --- a/RGB.NET.Layout/DeviceLayout.cs +++ b/RGB.NET.Layout/DeviceLayout.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; @@ -118,20 +118,16 @@ public class DeviceLayout : IDeviceLayout /// /// Creates a new from the specified xml. /// - /// The path to the xml file. + /// The stream that contains the layout to be loaded. /// The type of the custom data. /// The type of the custom data of the leds. /// The deserialized . - public static DeviceLayout? Load(string path, Type? customDeviceDataType = null, Type? customLedDataType = null) + public static DeviceLayout? Load(Stream stream, Type? customDeviceDataType = null, Type? customLedDataType = null) { - if (!File.Exists(path)) return null; - try { XmlSerializer serializer = new(typeof(DeviceLayout)); - using StreamReader reader = new(path); - - DeviceLayout? layout = serializer.Deserialize(reader) as DeviceLayout; + DeviceLayout? layout = serializer.Deserialize(stream) as DeviceLayout; if (layout != null) layout.CustomData = layout.GetCustomData(layout.InternalCustomData, customDeviceDataType); @@ -155,6 +151,21 @@ public class DeviceLayout : IDeviceLayout } } + /// + /// Creates a new from the specified xml. + /// + /// The path to the xml file. + /// The type of the custom data. + /// The type of the custom data of the leds. + /// The deserialized . + public static DeviceLayout? Load(string path, Type? customDeviceDataType = null, Type? customLedDataType = null) + { + if (!File.Exists(path)) return null; + + using Stream stream = File.OpenRead(path); + return Load(stream, customDeviceDataType, customLedDataType); + } + /// /// Gets the deserialized custom data. /// @@ -177,4 +188,4 @@ public class DeviceLayout : IDeviceLayout } #endregion -} \ No newline at end of file +} From 803acf2f994f6d54e1e23d2fd1cf44918fa672bd Mon Sep 17 00:00:00 2001 From: DELUUXE Date: Sat, 22 Jul 2023 23:39:23 +0200 Subject: [PATCH 68/96] Added Razer Blade 16 PID --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 344f96e1..f2e6aedc 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -127,6 +127,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x028A, RGBDeviceType.Keyboard, "Blade 15 Advanced (Early 2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028B, RGBDeviceType.Keyboard, "Blade 17 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028C, RGBDeviceType.Keyboard, "Blade 14 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x029F, RGBDeviceType.Keyboard, "Blade 16 (2023)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028D, RGBDeviceType.Keyboard, "BlackWidow V4", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0290, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless { 0x0292, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired From 6f91af903974ac745915fd41b9d45301c9e64a0b Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 23 Jul 2023 19:49:30 +0200 Subject: [PATCH 69/96] Readded support for older CUE-SDKs --- .../CorsairLegacyDeviceProvider.cs | 213 ++ .../Custom/CorsairCustomRGBDevice.cs | 74 + .../Custom/CorsairCustomRGBDeviceInfo.cs | 155 ++ .../Enum/CorsairAccessMode.cs | 14 + .../Enum/CorsairChannelDeviceType.cs | 25 + .../Enum/CorsairDeviceCaps.cs | 28 + .../Enum/CorsairDeviceType.cs | 27 + .../Enum/CorsairError.cs | 41 + .../Enum/CorsairLedId.cs | 1742 +++++++++++++++++ .../Enum/CorsairLogicalKeyboardLayout.cs | 30 + .../Enum/CorsairPhysicalKeyboardLayout.cs | 35 + .../Enum/CorsairPhysicalMouseLayout.cs | 107 + .../Exceptions/CUEException.cs | 36 + .../Generic/CorsairDeviceUpdateQueue.cs | 80 + .../Generic/CorsairProtocolDetails.cs | 65 + .../Generic/CorsairRGBDevice.cs | 76 + .../Generic/CorsairRGBDeviceInfo.cs | 95 + .../Generic/ICorsairRGBDevice.cs | 11 + .../Generic/LedMappings.cs | 302 +++ .../CorsairGraphicsCardRGBDevice.cs | 27 + .../CorsairGraphicsCardRGBDeviceInfo.cs | 28 + .../Headset/CorsairHeadsetRGBDevice.cs | 27 + .../Headset/CorsairHeadsetRGBDeviceInfo.cs | 25 + .../CorsairHeadsetStandRGBDevice.cs | 27 + .../CorsairHeadsetStandRGBDeviceInfo.cs | 25 + .../Helper/DictionaryExtension.cs | 12 + .../Helper/NativeExtensions.cs | 18 + .../Keyboard/CorsairKeyboardRGBDevice.cs | 33 + .../Keyboard/CorsairKeyboardRGBDeviceInfo.cs | 56 + .../Mainboard/CorsairMainboardRGBDevice.cs | 27 + .../CorsairMainboardRGBDeviceInfo.cs | 28 + .../Memory/CorsairMemoryRGBDevice.cs | 27 + .../Memory/CorsairMemoryRGBDeviceInfo.cs | 28 + .../Mouse/CorsairMouseRGBDevice.cs | 27 + .../Mouse/CorsairMouseRGBDeviceInfo.cs | 36 + .../Mousepad/CorsairMousepadRGBDevice.cs | 27 + .../Mousepad/CorsairMousepadRGBDeviceInfo.cs | 25 + .../Native/_CUESDK.cs | 193 ++ .../Native/_CorsairChannelDeviceInfo.cs | 27 + .../Native/_CorsairChannelInfo.cs | 33 + .../Native/_CorsairChannelsInfo.cs | 28 + .../Native/_CorsairDeviceInfo.cs | 58 + .../Native/_CorsairLedColor.cs | 37 + .../Native/_CorsairLedPosition.cs | 42 + .../Native/_CorsairLedPositions.cs | 26 + .../Native/_CorsairProtocolDetails.cs | 43 + RGB.NET.Devices.Corsair_Legacy/README.md | 24 + .../RGB.NET.Devices.Corsair_Legacy.csproj | 63 + ....Devices.Corsair_Legacy.csproj.DotSettings | 22 + .../Touchbar/CorsairTouchbarRGBDevice.cs | 27 + .../Touchbar/CorsairTouchbarRGBDeviceInfo.cs | 28 + RGB.NET.sln | 7 + 52 files changed, 4317 insertions(+) create mode 100644 RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Enum/CorsairAccessMode.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Enum/CorsairChannelDeviceType.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Enum/CorsairDeviceCaps.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Enum/CorsairDeviceType.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Enum/CorsairError.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Enum/CorsairLedId.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Enum/CorsairLogicalKeyboardLayout.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Enum/CorsairPhysicalKeyboardLayout.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Enum/CorsairPhysicalMouseLayout.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Exceptions/CUEException.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Generic/ICorsairRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/GraphicsCard/CorsairGraphicsCardRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Headset/CorsairHeadsetRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Headset/CorsairHeadsetRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/HeadsetStand/CorsairHeadsetStandRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Helper/DictionaryExtension.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Keyboard/CorsairKeyboardRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Keyboard/CorsairKeyboardRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Mainboard/CorsairMainboardRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Mainboard/CorsairMainboardRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Memory/CorsairMemoryRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Memory/CorsairMemoryRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Mouse/CorsairMouseRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Mouse/CorsairMouseRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Mousepad/CorsairMousepadRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Mousepad/CorsairMousepadRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedColor.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPosition.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/README.md create mode 100644 RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj create mode 100644 RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj.DotSettings create mode 100644 RGB.NET.Devices.Corsair_Legacy/Touchbar/CorsairTouchbarRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair_Legacy/Touchbar/CorsairTouchbarRGBDeviceInfo.cs diff --git a/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs b/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs new file mode 100644 index 00000000..20a1b58c --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs @@ -0,0 +1,213 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a device provider responsible for corsair (CUE) devices. +/// +public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider +{ + #region Properties & Fields + + private static CorsairLegacyDeviceProvider? _instance; + /// + /// Gets the singleton instance. + /// + public static CorsairLegacyDeviceProvider Instance => _instance ?? new CorsairLegacyDeviceProvider(); + + /// + /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. + /// The first match will be used. + /// + public static List PossibleX86NativePaths { get; } = new() { "x86/CUESDK.dll", "x86/CUESDK_2019.dll", "x86/CUESDK_2017.dll", "x86/CUESDK_2015.dll", "x86/CUESDK_2013.dll" }; + + /// + /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. + /// The first match will be used. + /// + public static List PossibleX64NativePaths { get; } = new() { "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll", "x64/CUESDK.x64_2017.dll", "x64/CUESDK_2019.dll", "x64/CUESDK_2017.dll", "x64/CUESDK_2015.dll", "x64/CUESDK_2013.dll" }; + + /// + /// Gets the protocol details for the current SDK-connection. + /// + public CorsairProtocolDetails? ProtocolDetails { get; private set; } + + /// + /// Gets the last error documented by CUE. + /// + public static CorsairError LastError => _CUESDK.CorsairGetLastError(); + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// Thrown if this constructor is called even if there is already an instance of this class. + public CorsairLegacyDeviceProvider() + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairLegacyDeviceProvider)}"); + _instance = this; + } + + #endregion + + #region Methods + + /// + protected override void InitializeSDK() + { + _CUESDK.Reload(); + + ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake()); + + CorsairError error = LastError; + if (error != CorsairError.Success) + Throw(new CUEException(error), true); + + if (ProtocolDetails.BreakingChanges) + Throw(new RGBDeviceException("The SDK currently used isn't compatible with the installed version of CUE.\r\n" + + $"CUE-Version: {ProtocolDetails.ServerVersion} (Protocol {ProtocolDetails.ServerProtocolVersion})\r\n" + + $"SDK-Version: {ProtocolDetails.SdkVersion} (Protocol {ProtocolDetails.SdkProtocolVersion})"), true); + + // DarthAffe 02.02.2021: 127 is iCUE + if (!_CUESDK.CorsairSetLayerPriority(128)) + Throw(new CUEException(LastError)); + } + + /// + protected override IEnumerable LoadDevices() + { + foreach (ICorsairRGBDevice corsairDevice in LoadCorsairDevices()) + { + corsairDevice.Initialize(); + yield return corsairDevice; + } + } + + private IEnumerable LoadCorsairDevices() + { + int deviceCount = _CUESDK.CorsairGetDeviceCount(); + for (int i = 0; i < deviceCount; i++) + { + _CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo))!; + if (!((CorsairDeviceCaps)nativeDeviceInfo.capsMask).HasFlag(CorsairDeviceCaps.Lighting)) + continue; // Everything that doesn't support lighting control is useless + + CorsairDeviceUpdateQueue updateQueue = new(GetUpdateTrigger(), i); + switch (nativeDeviceInfo.type) + { + case CorsairDeviceType.Keyboard: + yield return new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); + break; + + case CorsairDeviceType.Mouse: + yield return new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); + break; + + case CorsairDeviceType.Headset: + yield return new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); + break; + + case CorsairDeviceType.Mousepad: + yield return new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); + break; + + case CorsairDeviceType.HeadsetStand: + yield return new CorsairHeadsetStandRGBDevice(new CorsairHeadsetStandRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); + break; + + case CorsairDeviceType.MemoryModule: + yield return new CorsairMemoryRGBDevice(new CorsairMemoryRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); + break; + + case CorsairDeviceType.Mainboard: + yield return new CorsairMainboardRGBDevice(new CorsairMainboardRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); + break; + + case CorsairDeviceType.GraphicsCard: + yield return new CorsairGraphicsCardRGBDevice(new CorsairGraphicsCardRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); + break; + + case CorsairDeviceType.Touchbar: + yield return new CorsairTouchbarRGBDevice(new CorsairTouchbarRGBDeviceInfo(i, nativeDeviceInfo), updateQueue); + break; + + case CorsairDeviceType.Cooler: + case CorsairDeviceType.CommanderPro: + case CorsairDeviceType.LightningNodePro: + List<_CorsairChannelInfo> channels = GetChannels(nativeDeviceInfo).ToList(); + int channelsLedCount = channels.Sum(x => x.totalLedsCount); + int deviceLedCount = nativeDeviceInfo.ledsCount - channelsLedCount; + + if (deviceLedCount > 0) + yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(i, nativeDeviceInfo, deviceLedCount), updateQueue); + + int ledOffset = deviceLedCount; + foreach (_CorsairChannelInfo channelInfo in channels) + { + int channelDeviceInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelDeviceInfo)); + IntPtr channelDeviceInfoPtr = channelInfo.devices; + for (int device = 0; (device < channelInfo.devicesCount) && (ledOffset < nativeDeviceInfo.ledsCount); device++) + { + _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo))!; + + yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(i, nativeDeviceInfo, channelDeviceInfo, ledOffset), updateQueue); + + ledOffset += channelDeviceInfo.deviceLedCount; + channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize); + } + } + break; + + default: + Throw(new RGBDeviceException("Unknown Device-Type")); + break; + } + } + } + + private static IEnumerable<_CorsairChannelInfo> GetChannels(_CorsairDeviceInfo deviceInfo) + { + _CorsairChannelsInfo? channelsInfo = deviceInfo.channels; + if (channelsInfo == null) yield break; + + IntPtr channelInfoPtr = channelsInfo.channels; + for (int channel = 0; channel < channelsInfo.channelsCount; channel++) + { + yield return (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo))!; + + int channelInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelInfo)); + channelInfoPtr = new IntPtr(channelInfoPtr.ToInt64() + channelInfoStructSize); + } + } + + /// + protected override void Reset() + { + ProtocolDetails = null; + + base.Reset(); + } + + /// + public override void Dispose() + { + base.Dispose(); + + try { _CUESDK.UnloadCUESDK(); } + catch { /* at least we tried */ } + } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs new file mode 100644 index 00000000..4f5a301c --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs @@ -0,0 +1,74 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using System; +using System.Runtime.InteropServices; +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a corsair custom. +/// +public class CorsairCustomRGBDevice : CorsairRGBDevice, IUnknownDevice +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the custom-device. + /// The queue used to update this device. + internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, new LedMapping(), updateQueue) + { } + + #endregion + + #region Methods + + /// + protected override void InitializeLayout() + { + Mapping.Clear(); + + _CorsairLedPositions? nativeLedPositions = (_CorsairLedPositions?)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex), typeof(_CorsairLedPositions)); + if (nativeLedPositions == null) return; + + int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); + IntPtr ptr = new(nativeLedPositions.pLedPosition.ToInt64() + (structSize * DeviceInfo.LedOffset)); + + LedId referenceLedId = GetReferenceLed(DeviceInfo.DeviceType); + for (int i = 0; i < DeviceInfo.LedCount; i++) + { + LedId ledId = referenceLedId + i; + _CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition)); + if (ledPosition == null) + { + ptr = new IntPtr(ptr.ToInt64() + structSize); + continue; + } + + Mapping.Add(ledId, ledPosition.LedId); + + Rectangle rectangle = ledPosition.ToRectangle(); + AddLed(ledId, rectangle.Location, rectangle.Size); + + ptr = new IntPtr(ptr.ToInt64() + structSize); + } + } + + private static LedId GetReferenceLed(RGBDeviceType deviceType) + => deviceType switch + { + RGBDeviceType.LedStripe => LedId.LedStripe1, + RGBDeviceType.Fan => LedId.Fan1, + RGBDeviceType.Cooler => LedId.Cooler1, + _ => LedId.Custom1 + }; + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs new file mode 100644 index 00000000..3664f0d6 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs @@ -0,0 +1,155 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using System; +using System.Runtime.InteropServices; +using System.Text.RegularExpressions; +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairCustomRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Properties & Fields + + /// + /// Gets the amount of LEDs this device contains. + /// + public int LedCount { get; } + + /// + /// Gets the offset used to access the LEDs of this device. + /// + internal int LedOffset { get; } + + #endregion + + #region Constructors + + /// + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The native -struct + /// The native representing this device. + /// The offset used to find the LEDs of this device. + internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, int ledOffset) + : base(deviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo, + GetModelName(nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase), channelDeviceInfo)) + { + this.LedOffset = ledOffset; + + LedCount = channelDeviceInfo.deviceLedCount; + } + + internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, int ledCount) + : base(deviceIndex, GetDeviceType(nativeInfo.type), nativeInfo) + { + this.LedCount = ledCount; + + LedOffset = 0; + } + + #endregion + + #region Methods + + private static RGBDeviceType GetDeviceType(CorsairChannelDeviceType deviceType) + => deviceType switch + { + CorsairChannelDeviceType.Invalid => RGBDeviceType.Unknown, + CorsairChannelDeviceType.FanHD => RGBDeviceType.Fan, + CorsairChannelDeviceType.FanSP => RGBDeviceType.Fan, + CorsairChannelDeviceType.FanLL => RGBDeviceType.Fan, + CorsairChannelDeviceType.FanML => RGBDeviceType.Fan, + CorsairChannelDeviceType.DAP => RGBDeviceType.Fan, + CorsairChannelDeviceType.FanQL => RGBDeviceType.Fan, + CorsairChannelDeviceType.EightLedSeriesFan => RGBDeviceType.Fan, + CorsairChannelDeviceType.Strip => RGBDeviceType.LedStripe, + CorsairChannelDeviceType.Pump => RGBDeviceType.Cooler, + CorsairChannelDeviceType.WaterBlock => RGBDeviceType.Cooler, + _ => throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null) + }; + + private static RGBDeviceType GetDeviceType(CorsairDeviceType deviceType) + => deviceType switch + { + CorsairDeviceType.Unknown => RGBDeviceType.Unknown, + CorsairDeviceType.Mouse => RGBDeviceType.Mouse, + CorsairDeviceType.Keyboard => RGBDeviceType.Keyboard, + CorsairDeviceType.Headset => RGBDeviceType.Headset, + CorsairDeviceType.Mousepad => RGBDeviceType.Mousepad, + CorsairDeviceType.HeadsetStand => RGBDeviceType.HeadsetStand, + CorsairDeviceType.CommanderPro => RGBDeviceType.LedController, + CorsairDeviceType.LightningNodePro => RGBDeviceType.LedController, + CorsairDeviceType.MemoryModule => RGBDeviceType.DRAM, + CorsairDeviceType.Cooler => RGBDeviceType.Cooler, + CorsairDeviceType.Mainboard => RGBDeviceType.Mainboard, + CorsairDeviceType.GraphicsCard => RGBDeviceType.GraphicsCard, + _ => throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null) + }; + + private static string GetModelName(string model, _CorsairChannelDeviceInfo channelDeviceInfo) + { + switch (channelDeviceInfo.type) + { + case CorsairChannelDeviceType.Invalid: + return model; + + case CorsairChannelDeviceType.FanHD: + return "HD Fan"; + + case CorsairChannelDeviceType.FanSP: + return "SP Fan"; + + case CorsairChannelDeviceType.FanLL: + return "LL Fan"; + + case CorsairChannelDeviceType.FanML: + return "ML Fan"; + + case CorsairChannelDeviceType.FanQL: + return "QL Fan"; + + case CorsairChannelDeviceType.EightLedSeriesFan: + return "8-Led-Series Fan Fan"; + + case CorsairChannelDeviceType.Strip: + // LS100 Led Strips are reported as one big strip if configured in monitor mode in iCUE, 138 LEDs for dual monitor, 84 for single + if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 138)) + return "LS100 LED Strip (dual monitor)"; + else if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 84)) + return "LS100 LED Strip (single monitor)"; + // Any other value means an "External LED Strip" in iCUE, these are reported per-strip, 15 for short strips, 27 for long + else if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 15)) + return "LS100 LED Strip (short)"; + else if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 27)) + return "LS100 LED Strip (long)"; + // Device model is "Commander Pro" for regular LED strips + else + return "LED Strip"; + + case CorsairChannelDeviceType.DAP: + return "DAP Fan"; + + case CorsairChannelDeviceType.WaterBlock: + return "Water Block"; + + case CorsairChannelDeviceType.Pump: + return "Pump"; + + default: +#pragma warning disable CA2208 // Instantiate argument exceptions correctly + throw new ArgumentOutOfRangeException($"{nameof(channelDeviceInfo)}.{nameof(channelDeviceInfo.type)}", channelDeviceInfo.type, null); +#pragma warning restore CA2208 // Instantiate argument exceptions correctly + } + } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairAccessMode.cs b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairAccessMode.cs new file mode 100644 index 00000000..98885da2 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairAccessMode.cs @@ -0,0 +1,14 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global + +#pragma warning disable 1591 // Missing XML comment for publicly visible type or member + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Represents an SDK access mode. +/// +public enum CorsairAccessMode +{ + ExclusiveLightingControl = 0 +}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairChannelDeviceType.cs b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairChannelDeviceType.cs new file mode 100644 index 00000000..99c943f4 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairChannelDeviceType.cs @@ -0,0 +1,25 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global + + +#pragma warning disable 1591 // Missing XML comment for publicly visible type or member + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Contains a list of available corsair channel device types. +/// +public enum CorsairChannelDeviceType +{ + Invalid = 0, + FanHD = 1, + FanSP = 2, + FanLL = 3, + FanML = 4, + Strip = 5, + DAP = 6, + Pump = 7, + FanQL = 8, + WaterBlock = 9, + EightLedSeriesFan = 10 // Previously called FanSPPRO +}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairDeviceCaps.cs b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairDeviceCaps.cs new file mode 100644 index 00000000..2e77521c --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairDeviceCaps.cs @@ -0,0 +1,28 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global + +using System; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Contains a list of corsair device capabilities. +/// +[Flags] +public enum CorsairDeviceCaps +{ + /// + /// For devices that do not support any SDK functions. + /// + None = 0, + + /// + /// For devices that has controlled lighting. + /// + Lighting = 1, + + /// + /// For devices that provide current state through set of properties. + /// + PropertyLookup = 2 +}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairDeviceType.cs b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairDeviceType.cs new file mode 100644 index 00000000..339a72f4 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairDeviceType.cs @@ -0,0 +1,27 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global + + +#pragma warning disable 1591 // Missing XML comment for publicly visible type or member + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Contains a list of available corsair device types. +/// +public enum CorsairDeviceType +{ + Unknown = 0, + Mouse = 1, + Keyboard = 2, + Headset = 3, + Mousepad = 4, + HeadsetStand = 5, + CommanderPro = 6, + LightningNodePro = 7, + MemoryModule = 8, + Cooler = 9, + Mainboard = 10, + GraphicsCard = 11, + Touchbar = 12 +}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairError.cs b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairError.cs new file mode 100644 index 00000000..dfe87032 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairError.cs @@ -0,0 +1,41 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Shared list of all errors which could happen during calling of Corsair* functions. +/// +public enum CorsairError +{ + /// + /// If previously called function completed successfully. + /// + Success, + + /// + /// CUE is not running or was shut down or third-party control is disabled in CUE settings. (runtime error) + /// + ServerNotFound, + + /// + /// If some other client has or took over exclusive control. (runtime error) + /// + NoControl, + + /// + /// If developer did not perform protocol handshake. (developer error) + /// + ProtocolHandshakeMissing, + + /// + /// If developer is calling the function that is not supported by the server (either because protocol has broken by server or client or because the function is new and server is too old. + /// Check CorsairProtocolDetails for details). (developer error) + /// + IncompatibleProtocol, + + /// + /// If developer supplied invalid arguments to the function (for specifics look at function descriptions). (developer error) + /// + InvalidArguments +}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairLedId.cs b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairLedId.cs new file mode 100644 index 00000000..00ce18b7 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairLedId.cs @@ -0,0 +1,1742 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global +#pragma warning disable 1591 + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Contains a list of all LEDs available for all corsair devices. +/// +public enum CorsairLedId +{ + Invalid = 0, + Escape = 1, + F1 = 2, + F2 = 3, + F3 = 4, + F4 = 5, + F5 = 6, + F6 = 7, + F7 = 8, + F8 = 9, + F9 = 10, + F10 = 11, + F11 = 12, + GraveAccentAndTilde = 13, + D1 = 14, + D2 = 15, + D3 = 16, + D4 = 17, + D5 = 18, + D6 = 19, + D7 = 20, + D8 = 21, + D9 = 22, + D0 = 23, + MinusAndUnderscore = 24, + Tab = 25, + Q = 26, + W = 27, + E = 28, + R = 29, + T = 30, + Y = 31, + U = 32, + I = 33, + O = 34, + P = 35, + BracketLeft = 36, + CapsLock = 37, + A = 38, + S = 39, + D = 40, + F = 41, + G = 42, + H = 43, + J = 44, + K = 45, + L = 46, + SemicolonAndColon = 47, + ApostropheAndDoubleQuote = 48, + LeftShift = 49, + NonUsBackslash = 50, + Z = 51, + X = 52, + C = 53, + V = 54, + B = 55, + N = 56, + M = 57, + CommaAndLessThan = 58, + PeriodAndBiggerThan = 59, + SlashAndQuestionMark = 60, + LeftCtrl = 61, + LeftGui = 62, + LeftAlt = 63, + Lang2 = 64, + Space = 65, + Lang1 = 66, + International2 = 67, + RightAlt = 68, + RightGui = 69, + Application = 70, + LedProgramming = 71, + Brightness = 72, + F12 = 73, + PrintScreen = 74, + ScrollLock = 75, + PauseBreak = 76, + Insert = 77, + Home = 78, + PageUp = 79, + BracketRight = 80, + Backslash = 81, + NonUsTilde = 82, + Enter = 83, + International1 = 84, + EqualsAndPlus = 85, + International3 = 86, + Backspace = 87, + Delete = 88, + End = 89, + PageDown = 90, + RightShift = 91, + RightCtrl = 92, + UpArrow = 93, + LeftArrow = 94, + DownArrow = 95, + RightArrow = 96, + WinLock = 97, + Mute = 98, + Stop = 99, + ScanPreviousTrack = 100, + PlayPause = 101, + ScanNextTrack = 102, + NumLock = 103, + KeypadSlash = 104, + KeypadAsterisk = 105, + KeypadMinus = 106, + KeypadPlus = 107, + KeypadEnter = 108, + Keypad7 = 109, + Keypad8 = 110, + Keypad9 = 111, + KeypadComma = 112, + Keypad4 = 113, + Keypad5 = 114, + Keypad6 = 115, + Keypad1 = 116, + Keypad2 = 117, + Keypad3 = 118, + Keypad0 = 119, + KeypadPeriodAndDelete = 120, + G1 = 121, + G2 = 122, + G3 = 123, + G4 = 124, + G5 = 125, + G6 = 126, + G7 = 127, + G8 = 128, + G9 = 129, + G10 = 130, + VolumeUp = 131, + VolumeDown = 132, + MR = 133, + M1 = 134, + M2 = 135, + M3 = 136, + G11 = 137, + G12 = 138, + G13 = 139, + G14 = 140, + G15 = 141, + G16 = 142, + G17 = 143, + G18 = 144, + International5 = 145, + International4 = 146, + Fn = 147, + + B1 = 148, + B2 = 149, + B3 = 150, + B4 = 151, + + LeftLogo = 152, + RightLogo = 153, + + Logo = 154, + + Zone1 = 155, + Zone2 = 156, + Zone3 = 157, + Zone4 = 158, + Zone5 = 159, + Zone6 = 160, + Zone7 = 161, + Zone8 = 162, + Zone9 = 163, + Zone10 = 164, + Zone11 = 165, + Zone12 = 166, + Zone13 = 167, + Zone14 = 168, + Zone15 = 169, + + Lightbar1 = 170, + Lightbar2 = 171, + Lightbar3 = 172, + Lightbar4 = 173, + Lightbar5 = 174, + Lightbar6 = 175, + Lightbar7 = 176, + Lightbar8 = 177, + Lightbar9 = 178, + Lightbar10 = 179, + Lightbar11 = 180, + Lightbar12 = 181, + Lightbar13 = 182, + Lightbar14 = 183, + Lightbar15 = 184, + Lightbar16 = 185, + Lightbar17 = 186, + Lightbar18 = 187, + Lightbar19 = 188, + + B5 = 189, + B6 = 190, + + HeadsetStandZone1 = 191, + HeadsetStandZone2 = 192, + HeadsetStandZone3 = 193, + HeadsetStandZone4 = 194, + HeadsetStandZone5 = 195, + HeadsetStandZone6 = 196, + HeadsetStandZone7 = 197, + HeadsetStandZone8 = 198, + HeadsetStandZone9 = 199, + + CustomDeviceChannel1Led1 = 200, + CustomDeviceChannel1Led2 = 201, + CustomDeviceChannel1Led3 = 202, + CustomDeviceChannel1Led4 = 203, + CustomDeviceChannel1Led5 = 204, + CustomDeviceChannel1Led6 = 205, + CustomDeviceChannel1Led7 = 206, + CustomDeviceChannel1Led8 = 207, + CustomDeviceChannel1Led9 = 208, + CustomDeviceChannel1Led10 = 209, + CustomDeviceChannel1Led11 = 210, + CustomDeviceChannel1Led12 = 211, + CustomDeviceChannel1Led13 = 212, + CustomDeviceChannel1Led14 = 213, + CustomDeviceChannel1Led15 = 214, + CustomDeviceChannel1Led16 = 215, + CustomDeviceChannel1Led17 = 216, + CustomDeviceChannel1Led18 = 217, + CustomDeviceChannel1Led19 = 218, + CustomDeviceChannel1Led20 = 219, + CustomDeviceChannel1Led21 = 220, + CustomDeviceChannel1Led22 = 221, + CustomDeviceChannel1Led23 = 222, + CustomDeviceChannel1Led24 = 223, + CustomDeviceChannel1Led25 = 224, + CustomDeviceChannel1Led26 = 225, + CustomDeviceChannel1Led27 = 226, + CustomDeviceChannel1Led28 = 227, + CustomDeviceChannel1Led29 = 228, + CustomDeviceChannel1Led30 = 229, + CustomDeviceChannel1Led31 = 230, + CustomDeviceChannel1Led32 = 231, + CustomDeviceChannel1Led33 = 232, + CustomDeviceChannel1Led34 = 233, + CustomDeviceChannel1Led35 = 234, + CustomDeviceChannel1Led36 = 235, + CustomDeviceChannel1Led37 = 236, + CustomDeviceChannel1Led38 = 237, + CustomDeviceChannel1Led39 = 238, + CustomDeviceChannel1Led40 = 239, + CustomDeviceChannel1Led41 = 240, + CustomDeviceChannel1Led42 = 241, + CustomDeviceChannel1Led43 = 242, + CustomDeviceChannel1Led44 = 243, + CustomDeviceChannel1Led45 = 244, + CustomDeviceChannel1Led46 = 245, + CustomDeviceChannel1Led47 = 246, + CustomDeviceChannel1Led48 = 247, + CustomDeviceChannel1Led49 = 248, + CustomDeviceChannel1Led50 = 249, + CustomDeviceChannel1Led51 = 250, + CustomDeviceChannel1Led52 = 251, + CustomDeviceChannel1Led53 = 252, + CustomDeviceChannel1Led54 = 253, + CustomDeviceChannel1Led55 = 254, + CustomDeviceChannel1Led56 = 255, + CustomDeviceChannel1Led57 = 256, + CustomDeviceChannel1Led58 = 257, + CustomDeviceChannel1Led59 = 258, + CustomDeviceChannel1Led60 = 259, + CustomDeviceChannel1Led61 = 260, + CustomDeviceChannel1Led62 = 261, + CustomDeviceChannel1Led63 = 262, + CustomDeviceChannel1Led64 = 263, + CustomDeviceChannel1Led65 = 264, + CustomDeviceChannel1Led66 = 265, + CustomDeviceChannel1Led67 = 266, + CustomDeviceChannel1Led68 = 267, + CustomDeviceChannel1Led69 = 268, + CustomDeviceChannel1Led70 = 269, + CustomDeviceChannel1Led71 = 270, + CustomDeviceChannel1Led72 = 271, + CustomDeviceChannel1Led73 = 272, + CustomDeviceChannel1Led74 = 273, + CustomDeviceChannel1Led75 = 274, + CustomDeviceChannel1Led76 = 275, + CustomDeviceChannel1Led77 = 276, + CustomDeviceChannel1Led78 = 277, + CustomDeviceChannel1Led79 = 278, + CustomDeviceChannel1Led80 = 279, + CustomDeviceChannel1Led81 = 280, + CustomDeviceChannel1Led82 = 281, + CustomDeviceChannel1Led83 = 282, + CustomDeviceChannel1Led84 = 283, + CustomDeviceChannel1Led85 = 284, + CustomDeviceChannel1Led86 = 285, + CustomDeviceChannel1Led87 = 286, + CustomDeviceChannel1Led88 = 287, + CustomDeviceChannel1Led89 = 288, + CustomDeviceChannel1Led90 = 289, + CustomDeviceChannel1Led91 = 290, + CustomDeviceChannel1Led92 = 291, + CustomDeviceChannel1Led93 = 292, + CustomDeviceChannel1Led94 = 293, + CustomDeviceChannel1Led95 = 294, + CustomDeviceChannel1Led96 = 295, + CustomDeviceChannel1Led97 = 296, + CustomDeviceChannel1Led98 = 297, + CustomDeviceChannel1Led99 = 298, + CustomDeviceChannel1Led100 = 299, + CustomDeviceChannel1Led101 = 300, + CustomDeviceChannel1Led102 = 301, + CustomDeviceChannel1Led103 = 302, + CustomDeviceChannel1Led104 = 303, + CustomDeviceChannel1Led105 = 304, + CustomDeviceChannel1Led106 = 305, + CustomDeviceChannel1Led107 = 306, + CustomDeviceChannel1Led108 = 307, + CustomDeviceChannel1Led109 = 308, + CustomDeviceChannel1Led110 = 309, + CustomDeviceChannel1Led111 = 310, + CustomDeviceChannel1Led112 = 311, + CustomDeviceChannel1Led113 = 312, + CustomDeviceChannel1Led114 = 313, + CustomDeviceChannel1Led115 = 314, + CustomDeviceChannel1Led116 = 315, + CustomDeviceChannel1Led117 = 316, + CustomDeviceChannel1Led118 = 317, + CustomDeviceChannel1Led119 = 318, + CustomDeviceChannel1Led120 = 319, + CustomDeviceChannel1Led121 = 320, + CustomDeviceChannel1Led122 = 321, + CustomDeviceChannel1Led123 = 322, + CustomDeviceChannel1Led124 = 323, + CustomDeviceChannel1Led125 = 324, + CustomDeviceChannel1Led126 = 325, + CustomDeviceChannel1Led127 = 326, + CustomDeviceChannel1Led128 = 327, + CustomDeviceChannel1Led129 = 328, + CustomDeviceChannel1Led130 = 329, + CustomDeviceChannel1Led131 = 330, + CustomDeviceChannel1Led132 = 331, + CustomDeviceChannel1Led133 = 332, + CustomDeviceChannel1Led134 = 333, + CustomDeviceChannel1Led135 = 334, + CustomDeviceChannel1Led136 = 335, + CustomDeviceChannel1Led137 = 336, + CustomDeviceChannel1Led138 = 337, + CustomDeviceChannel1Led139 = 338, + CustomDeviceChannel1Led140 = 339, + CustomDeviceChannel1Led141 = 340, + CustomDeviceChannel1Led142 = 341, + CustomDeviceChannel1Led143 = 342, + CustomDeviceChannel1Led144 = 343, + CustomDeviceChannel1Led145 = 344, + CustomDeviceChannel1Led146 = 345, + CustomDeviceChannel1Led147 = 346, + CustomDeviceChannel1Led148 = 347, + CustomDeviceChannel1Led149 = 348, + CustomDeviceChannel1Led150 = 349, + + CustomDeviceChannel2Led1 = 350, + CustomDeviceChannel2Led2 = 351, + CustomDeviceChannel2Led3 = 352, + CustomDeviceChannel2Led4 = 353, + CustomDeviceChannel2Led5 = 354, + CustomDeviceChannel2Led6 = 355, + CustomDeviceChannel2Led7 = 356, + CustomDeviceChannel2Led8 = 357, + CustomDeviceChannel2Led9 = 358, + CustomDeviceChannel2Led10 = 359, + CustomDeviceChannel2Led11 = 360, + CustomDeviceChannel2Led12 = 361, + CustomDeviceChannel2Led13 = 362, + CustomDeviceChannel2Led14 = 363, + CustomDeviceChannel2Led15 = 364, + CustomDeviceChannel2Led16 = 365, + CustomDeviceChannel2Led17 = 366, + CustomDeviceChannel2Led18 = 367, + CustomDeviceChannel2Led19 = 368, + CustomDeviceChannel2Led20 = 369, + CustomDeviceChannel2Led21 = 370, + CustomDeviceChannel2Led22 = 371, + CustomDeviceChannel2Led23 = 372, + CustomDeviceChannel2Led24 = 373, + CustomDeviceChannel2Led25 = 374, + CustomDeviceChannel2Led26 = 375, + CustomDeviceChannel2Led27 = 376, + CustomDeviceChannel2Led28 = 377, + CustomDeviceChannel2Led29 = 378, + CustomDeviceChannel2Led30 = 379, + CustomDeviceChannel2Led31 = 380, + CustomDeviceChannel2Led32 = 381, + CustomDeviceChannel2Led33 = 382, + CustomDeviceChannel2Led34 = 383, + CustomDeviceChannel2Led35 = 384, + CustomDeviceChannel2Led36 = 385, + CustomDeviceChannel2Led37 = 386, + CustomDeviceChannel2Led38 = 387, + CustomDeviceChannel2Led39 = 388, + CustomDeviceChannel2Led40 = 389, + CustomDeviceChannel2Led41 = 390, + CustomDeviceChannel2Led42 = 391, + CustomDeviceChannel2Led43 = 392, + CustomDeviceChannel2Led44 = 393, + CustomDeviceChannel2Led45 = 394, + CustomDeviceChannel2Led46 = 395, + CustomDeviceChannel2Led47 = 396, + CustomDeviceChannel2Led48 = 397, + CustomDeviceChannel2Led49 = 398, + CustomDeviceChannel2Led50 = 399, + CustomDeviceChannel2Led51 = 400, + CustomDeviceChannel2Led52 = 401, + CustomDeviceChannel2Led53 = 402, + CustomDeviceChannel2Led54 = 403, + CustomDeviceChannel2Led55 = 404, + CustomDeviceChannel2Led56 = 405, + CustomDeviceChannel2Led57 = 406, + CustomDeviceChannel2Led58 = 407, + CustomDeviceChannel2Led59 = 408, + CustomDeviceChannel2Led60 = 409, + CustomDeviceChannel2Led61 = 410, + CustomDeviceChannel2Led62 = 411, + CustomDeviceChannel2Led63 = 412, + CustomDeviceChannel2Led64 = 413, + CustomDeviceChannel2Led65 = 414, + CustomDeviceChannel2Led66 = 415, + CustomDeviceChannel2Led67 = 416, + CustomDeviceChannel2Led68 = 417, + CustomDeviceChannel2Led69 = 418, + CustomDeviceChannel2Led70 = 419, + CustomDeviceChannel2Led71 = 420, + CustomDeviceChannel2Led72 = 421, + CustomDeviceChannel2Led73 = 422, + CustomDeviceChannel2Led74 = 423, + CustomDeviceChannel2Led75 = 424, + CustomDeviceChannel2Led76 = 425, + CustomDeviceChannel2Led77 = 426, + CustomDeviceChannel2Led78 = 427, + CustomDeviceChannel2Led79 = 428, + CustomDeviceChannel2Led80 = 429, + CustomDeviceChannel2Led81 = 430, + CustomDeviceChannel2Led82 = 431, + CustomDeviceChannel2Led83 = 432, + CustomDeviceChannel2Led84 = 433, + CustomDeviceChannel2Led85 = 434, + CustomDeviceChannel2Led86 = 435, + CustomDeviceChannel2Led87 = 436, + CustomDeviceChannel2Led88 = 437, + CustomDeviceChannel2Led89 = 438, + CustomDeviceChannel2Led90 = 439, + CustomDeviceChannel2Led91 = 440, + CustomDeviceChannel2Led92 = 441, + CustomDeviceChannel2Led93 = 442, + CustomDeviceChannel2Led94 = 443, + CustomDeviceChannel2Led95 = 444, + CustomDeviceChannel2Led96 = 445, + CustomDeviceChannel2Led97 = 446, + CustomDeviceChannel2Led98 = 447, + CustomDeviceChannel2Led99 = 448, + CustomDeviceChannel2Led100 = 449, + CustomDeviceChannel2Led101 = 450, + CustomDeviceChannel2Led102 = 451, + CustomDeviceChannel2Led103 = 452, + CustomDeviceChannel2Led104 = 453, + CustomDeviceChannel2Led105 = 454, + CustomDeviceChannel2Led106 = 455, + CustomDeviceChannel2Led107 = 456, + CustomDeviceChannel2Led108 = 457, + CustomDeviceChannel2Led109 = 458, + CustomDeviceChannel2Led110 = 459, + CustomDeviceChannel2Led111 = 460, + CustomDeviceChannel2Led112 = 461, + CustomDeviceChannel2Led113 = 462, + CustomDeviceChannel2Led114 = 463, + CustomDeviceChannel2Led115 = 464, + CustomDeviceChannel2Led116 = 465, + CustomDeviceChannel2Led117 = 466, + CustomDeviceChannel2Led118 = 467, + CustomDeviceChannel2Led119 = 468, + CustomDeviceChannel2Led120 = 469, + CustomDeviceChannel2Led121 = 470, + CustomDeviceChannel2Led122 = 471, + CustomDeviceChannel2Led123 = 472, + CustomDeviceChannel2Led124 = 473, + CustomDeviceChannel2Led125 = 474, + CustomDeviceChannel2Led126 = 475, + CustomDeviceChannel2Led127 = 476, + CustomDeviceChannel2Led128 = 477, + CustomDeviceChannel2Led129 = 478, + CustomDeviceChannel2Led130 = 479, + CustomDeviceChannel2Led131 = 480, + CustomDeviceChannel2Led132 = 481, + CustomDeviceChannel2Led133 = 482, + CustomDeviceChannel2Led134 = 483, + CustomDeviceChannel2Led135 = 484, + CustomDeviceChannel2Led136 = 485, + CustomDeviceChannel2Led137 = 486, + CustomDeviceChannel2Led138 = 487, + CustomDeviceChannel2Led139 = 488, + CustomDeviceChannel2Led140 = 489, + CustomDeviceChannel2Led141 = 490, + CustomDeviceChannel2Led142 = 491, + CustomDeviceChannel2Led143 = 492, + CustomDeviceChannel2Led144 = 493, + CustomDeviceChannel2Led145 = 494, + CustomDeviceChannel2Led146 = 495, + CustomDeviceChannel2Led147 = 496, + CustomDeviceChannel2Led148 = 497, + CustomDeviceChannel2Led149 = 498, + CustomDeviceChannel2Led150 = 499, + + OemLed1 = 500, + OemLed2 = 501, + OemLed3 = 502, + OemLed4 = 503, + OemLed5 = 504, + OemLed6 = 505, + OemLed7 = 506, + OemLed8 = 507, + OemLed9 = 508, + OemLed10 = 509, + OemLed11 = 510, + OemLed12 = 511, + OemLed13 = 512, + OemLed14 = 513, + OemLed15 = 514, + OemLed16 = 515, + OemLed17 = 516, + OemLed18 = 517, + OemLed19 = 518, + OemLed20 = 519, + OemLed21 = 520, + OemLed22 = 521, + OemLed23 = 522, + OemLed24 = 523, + OemLed25 = 524, + OemLed26 = 525, + OemLed27 = 526, + OemLed28 = 527, + OemLed29 = 528, + OemLed30 = 529, + OemLed31 = 530, + OemLed32 = 531, + OemLed33 = 532, + OemLed34 = 533, + OemLed35 = 534, + OemLed36 = 535, + OemLed37 = 536, + OemLed38 = 537, + OemLed39 = 538, + OemLed40 = 539, + OemLed41 = 540, + OemLed42 = 541, + OemLed43 = 542, + OemLed44 = 543, + OemLed45 = 544, + OemLed46 = 545, + OemLed47 = 546, + OemLed48 = 547, + OemLed49 = 548, + OemLed50 = 549, + OemLed51 = 550, + OemLed52 = 551, + OemLed53 = 552, + OemLed54 = 553, + OemLed55 = 554, + OemLed56 = 555, + OemLed57 = 556, + OemLed58 = 557, + OemLed59 = 558, + OemLed60 = 559, + OemLed61 = 560, + OemLed62 = 561, + OemLed63 = 562, + OemLed64 = 563, + OemLed65 = 564, + OemLed66 = 565, + OemLed67 = 566, + OemLed68 = 567, + OemLed69 = 568, + OemLed70 = 569, + OemLed71 = 570, + OemLed72 = 571, + OemLed73 = 572, + OemLed74 = 573, + OemLed75 = 574, + OemLed76 = 575, + OemLed77 = 576, + OemLed78 = 577, + OemLed79 = 578, + OemLed80 = 579, + OemLed81 = 580, + OemLed82 = 581, + OemLed83 = 582, + OemLed84 = 583, + OemLed85 = 584, + OemLed86 = 585, + OemLed87 = 586, + OemLed88 = 587, + OemLed89 = 588, + OemLed90 = 589, + OemLed91 = 590, + OemLed92 = 591, + OemLed93 = 592, + OemLed94 = 593, + OemLed95 = 594, + OemLed96 = 595, + OemLed97 = 596, + OemLed98 = 597, + OemLed99 = 598, + OemLed100 = 599, + + DRAM1 = 600, + DRAM2 = 601, + DRAM3 = 602, + DRAM4 = 603, + DRAM5 = 604, + DRAM6 = 605, + DRAM7 = 606, + DRAM8 = 607, + DRAM9 = 608, + DRAM10 = 609, + DRAM11 = 610, + DRAM12 = 611, + + CustomDeviceChannel3Led1 = 612, + CustomDeviceChannel3Led2 = 613, + CustomDeviceChannel3Led3 = 614, + CustomDeviceChannel3Led4 = 615, + CustomDeviceChannel3Led5 = 616, + CustomDeviceChannel3Led6 = 617, + CustomDeviceChannel3Led7 = 618, + CustomDeviceChannel3Led8 = 619, + CustomDeviceChannel3Led9 = 620, + CustomDeviceChannel3Led10 = 621, + CustomDeviceChannel3Led11 = 622, + CustomDeviceChannel3Led12 = 623, + CustomDeviceChannel3Led13 = 624, + CustomDeviceChannel3Led14 = 625, + CustomDeviceChannel3Led15 = 626, + CustomDeviceChannel3Led16 = 627, + CustomDeviceChannel3Led17 = 628, + CustomDeviceChannel3Led18 = 629, + CustomDeviceChannel3Led19 = 630, + CustomDeviceChannel3Led20 = 631, + CustomDeviceChannel3Led21 = 632, + CustomDeviceChannel3Led22 = 633, + CustomDeviceChannel3Led23 = 634, + CustomDeviceChannel3Led24 = 635, + CustomDeviceChannel3Led25 = 636, + CustomDeviceChannel3Led26 = 637, + CustomDeviceChannel3Led27 = 638, + CustomDeviceChannel3Led28 = 639, + CustomDeviceChannel3Led29 = 640, + CustomDeviceChannel3Led30 = 641, + CustomDeviceChannel3Led31 = 642, + CustomDeviceChannel3Led32 = 643, + CustomDeviceChannel3Led33 = 644, + CustomDeviceChannel3Led34 = 645, + CustomDeviceChannel3Led35 = 646, + CustomDeviceChannel3Led36 = 647, + CustomDeviceChannel3Led37 = 648, + CustomDeviceChannel3Led38 = 649, + CustomDeviceChannel3Led39 = 650, + CustomDeviceChannel3Led40 = 651, + CustomDeviceChannel3Led41 = 652, + CustomDeviceChannel3Led42 = 653, + CustomDeviceChannel3Led43 = 654, + CustomDeviceChannel3Led44 = 655, + CustomDeviceChannel3Led45 = 656, + CustomDeviceChannel3Led46 = 657, + CustomDeviceChannel3Led47 = 658, + CustomDeviceChannel3Led48 = 659, + CustomDeviceChannel3Led49 = 660, + CustomDeviceChannel3Led50 = 661, + CustomDeviceChannel3Led51 = 662, + CustomDeviceChannel3Led52 = 663, + CustomDeviceChannel3Led53 = 664, + CustomDeviceChannel3Led54 = 665, + CustomDeviceChannel3Led55 = 666, + CustomDeviceChannel3Led56 = 667, + CustomDeviceChannel3Led57 = 668, + CustomDeviceChannel3Led58 = 669, + CustomDeviceChannel3Led59 = 670, + CustomDeviceChannel3Led60 = 671, + CustomDeviceChannel3Led61 = 672, + CustomDeviceChannel3Led62 = 673, + CustomDeviceChannel3Led63 = 674, + CustomDeviceChannel3Led64 = 675, + CustomDeviceChannel3Led65 = 676, + CustomDeviceChannel3Led66 = 677, + CustomDeviceChannel3Led67 = 678, + CustomDeviceChannel3Led68 = 679, + CustomDeviceChannel3Led69 = 680, + CustomDeviceChannel3Led70 = 681, + CustomDeviceChannel3Led71 = 682, + CustomDeviceChannel3Led72 = 683, + CustomDeviceChannel3Led73 = 684, + CustomDeviceChannel3Led74 = 685, + CustomDeviceChannel3Led75 = 686, + CustomDeviceChannel3Led76 = 687, + CustomDeviceChannel3Led77 = 688, + CustomDeviceChannel3Led78 = 689, + CustomDeviceChannel3Led79 = 690, + CustomDeviceChannel3Led80 = 691, + CustomDeviceChannel3Led81 = 692, + CustomDeviceChannel3Led82 = 693, + CustomDeviceChannel3Led83 = 694, + CustomDeviceChannel3Led84 = 695, + CustomDeviceChannel3Led85 = 696, + CustomDeviceChannel3Led86 = 697, + CustomDeviceChannel3Led87 = 698, + CustomDeviceChannel3Led88 = 699, + CustomDeviceChannel3Led89 = 700, + CustomDeviceChannel3Led90 = 701, + CustomDeviceChannel3Led91 = 702, + CustomDeviceChannel3Led92 = 703, + CustomDeviceChannel3Led93 = 704, + CustomDeviceChannel3Led94 = 705, + CustomDeviceChannel3Led95 = 706, + CustomDeviceChannel3Led96 = 707, + CustomDeviceChannel3Led97 = 708, + CustomDeviceChannel3Led98 = 709, + CustomDeviceChannel3Led99 = 710, + CustomDeviceChannel3Led100 = 711, + CustomDeviceChannel3Led101 = 712, + CustomDeviceChannel3Led102 = 713, + CustomDeviceChannel3Led103 = 714, + CustomDeviceChannel3Led104 = 715, + CustomDeviceChannel3Led105 = 716, + CustomDeviceChannel3Led106 = 717, + CustomDeviceChannel3Led107 = 718, + CustomDeviceChannel3Led108 = 719, + CustomDeviceChannel3Led109 = 720, + CustomDeviceChannel3Led110 = 721, + CustomDeviceChannel3Led111 = 722, + CustomDeviceChannel3Led112 = 723, + CustomDeviceChannel3Led113 = 724, + CustomDeviceChannel3Led114 = 725, + CustomDeviceChannel3Led115 = 726, + CustomDeviceChannel3Led116 = 727, + CustomDeviceChannel3Led117 = 728, + CustomDeviceChannel3Led118 = 729, + CustomDeviceChannel3Led119 = 730, + CustomDeviceChannel3Led120 = 731, + CustomDeviceChannel3Led121 = 732, + CustomDeviceChannel3Led122 = 733, + CustomDeviceChannel3Led123 = 734, + CustomDeviceChannel3Led124 = 735, + CustomDeviceChannel3Led125 = 736, + CustomDeviceChannel3Led126 = 737, + CustomDeviceChannel3Led127 = 738, + CustomDeviceChannel3Led128 = 739, + CustomDeviceChannel3Led129 = 740, + CustomDeviceChannel3Led130 = 741, + CustomDeviceChannel3Led131 = 742, + CustomDeviceChannel3Led132 = 743, + CustomDeviceChannel3Led133 = 744, + CustomDeviceChannel3Led134 = 745, + CustomDeviceChannel3Led135 = 746, + CustomDeviceChannel3Led136 = 747, + CustomDeviceChannel3Led137 = 748, + CustomDeviceChannel3Led138 = 749, + CustomDeviceChannel3Led139 = 750, + CustomDeviceChannel3Led140 = 751, + CustomDeviceChannel3Led141 = 752, + CustomDeviceChannel3Led142 = 753, + CustomDeviceChannel3Led143 = 754, + CustomDeviceChannel3Led144 = 755, + CustomDeviceChannel3Led145 = 756, + CustomDeviceChannel3Led146 = 757, + CustomDeviceChannel3Led147 = 758, + CustomDeviceChannel3Led148 = 759, + CustomDeviceChannel3Led149 = 760, + CustomDeviceChannel3Led150 = 761, + + CustomLiquidCoolerChannel1Led1 = 762, + CustomLiquidCoolerChannel1Led2 = 763, + CustomLiquidCoolerChannel1Led3 = 764, + CustomLiquidCoolerChannel1Led4 = 765, + CustomLiquidCoolerChannel1Led5 = 766, + CustomLiquidCoolerChannel1Led6 = 767, + CustomLiquidCoolerChannel1Led7 = 768, + CustomLiquidCoolerChannel1Led8 = 769, + CustomLiquidCoolerChannel1Led9 = 770, + CustomLiquidCoolerChannel1Led10 = 771, + CustomLiquidCoolerChannel1Led11 = 772, + CustomLiquidCoolerChannel1Led12 = 773, + CustomLiquidCoolerChannel1Led13 = 774, + CustomLiquidCoolerChannel1Led14 = 775, + CustomLiquidCoolerChannel1Led15 = 776, + CustomLiquidCoolerChannel1Led16 = 777, + CustomLiquidCoolerChannel1Led17 = 778, + CustomLiquidCoolerChannel1Led18 = 779, + CustomLiquidCoolerChannel1Led19 = 780, + CustomLiquidCoolerChannel1Led20 = 781, + CustomLiquidCoolerChannel1Led21 = 782, + CustomLiquidCoolerChannel1Led22 = 783, + CustomLiquidCoolerChannel1Led23 = 784, + CustomLiquidCoolerChannel1Led24 = 785, + CustomLiquidCoolerChannel1Led25 = 786, + CustomLiquidCoolerChannel1Led26 = 787, + CustomLiquidCoolerChannel1Led27 = 788, + CustomLiquidCoolerChannel1Led28 = 789, + CustomLiquidCoolerChannel1Led29 = 790, + CustomLiquidCoolerChannel1Led30 = 791, + CustomLiquidCoolerChannel1Led31 = 792, + CustomLiquidCoolerChannel1Led32 = 793, + CustomLiquidCoolerChannel1Led33 = 794, + CustomLiquidCoolerChannel1Led34 = 795, + CustomLiquidCoolerChannel1Led35 = 796, + CustomLiquidCoolerChannel1Led36 = 797, + CustomLiquidCoolerChannel1Led37 = 798, + CustomLiquidCoolerChannel1Led38 = 799, + CustomLiquidCoolerChannel1Led39 = 800, + CustomLiquidCoolerChannel1Led40 = 801, + CustomLiquidCoolerChannel1Led41 = 802, + CustomLiquidCoolerChannel1Led42 = 803, + CustomLiquidCoolerChannel1Led43 = 804, + CustomLiquidCoolerChannel1Led44 = 805, + CustomLiquidCoolerChannel1Led45 = 806, + CustomLiquidCoolerChannel1Led46 = 807, + CustomLiquidCoolerChannel1Led47 = 808, + CustomLiquidCoolerChannel1Led48 = 809, + CustomLiquidCoolerChannel1Led49 = 810, + CustomLiquidCoolerChannel1Led50 = 811, + CustomLiquidCoolerChannel1Led51 = 812, + CustomLiquidCoolerChannel1Led52 = 813, + CustomLiquidCoolerChannel1Led53 = 814, + CustomLiquidCoolerChannel1Led54 = 815, + CustomLiquidCoolerChannel1Led55 = 816, + CustomLiquidCoolerChannel1Led56 = 817, + CustomLiquidCoolerChannel1Led57 = 818, + CustomLiquidCoolerChannel1Led58 = 819, + CustomLiquidCoolerChannel1Led59 = 820, + CustomLiquidCoolerChannel1Led60 = 821, + CustomLiquidCoolerChannel1Led61 = 822, + CustomLiquidCoolerChannel1Led62 = 823, + CustomLiquidCoolerChannel1Led63 = 824, + CustomLiquidCoolerChannel1Led64 = 825, + CustomLiquidCoolerChannel1Led65 = 826, + CustomLiquidCoolerChannel1Led66 = 827, + CustomLiquidCoolerChannel1Led67 = 828, + CustomLiquidCoolerChannel1Led68 = 829, + CustomLiquidCoolerChannel1Led69 = 830, + CustomLiquidCoolerChannel1Led70 = 831, + CustomLiquidCoolerChannel1Led71 = 832, + CustomLiquidCoolerChannel1Led72 = 833, + CustomLiquidCoolerChannel1Led73 = 834, + CustomLiquidCoolerChannel1Led74 = 835, + CustomLiquidCoolerChannel1Led75 = 836, + CustomLiquidCoolerChannel1Led76 = 837, + CustomLiquidCoolerChannel1Led77 = 838, + CustomLiquidCoolerChannel1Led78 = 839, + CustomLiquidCoolerChannel1Led79 = 840, + CustomLiquidCoolerChannel1Led80 = 841, + CustomLiquidCoolerChannel1Led81 = 842, + CustomLiquidCoolerChannel1Led82 = 843, + CustomLiquidCoolerChannel1Led83 = 844, + CustomLiquidCoolerChannel1Led84 = 845, + CustomLiquidCoolerChannel1Led85 = 846, + CustomLiquidCoolerChannel1Led86 = 847, + CustomLiquidCoolerChannel1Led87 = 848, + CustomLiquidCoolerChannel1Led88 = 849, + CustomLiquidCoolerChannel1Led89 = 850, + CustomLiquidCoolerChannel1Led90 = 851, + CustomLiquidCoolerChannel1Led91 = 852, + CustomLiquidCoolerChannel1Led92 = 853, + CustomLiquidCoolerChannel1Led93 = 854, + CustomLiquidCoolerChannel1Led94 = 855, + CustomLiquidCoolerChannel1Led95 = 856, + CustomLiquidCoolerChannel1Led96 = 857, + CustomLiquidCoolerChannel1Led97 = 858, + CustomLiquidCoolerChannel1Led98 = 859, + CustomLiquidCoolerChannel1Led99 = 860, + CustomLiquidCoolerChannel1Led100 = 861, + CustomLiquidCoolerChannel1Led101 = 862, + CustomLiquidCoolerChannel1Led102 = 863, + CustomLiquidCoolerChannel1Led103 = 864, + CustomLiquidCoolerChannel1Led104 = 865, + CustomLiquidCoolerChannel1Led105 = 866, + CustomLiquidCoolerChannel1Led106 = 867, + CustomLiquidCoolerChannel1Led107 = 868, + CustomLiquidCoolerChannel1Led108 = 869, + CustomLiquidCoolerChannel1Led109 = 870, + CustomLiquidCoolerChannel1Led110 = 871, + CustomLiquidCoolerChannel1Led111 = 872, + CustomLiquidCoolerChannel1Led112 = 873, + CustomLiquidCoolerChannel1Led113 = 874, + CustomLiquidCoolerChannel1Led114 = 875, + CustomLiquidCoolerChannel1Led115 = 876, + CustomLiquidCoolerChannel1Led116 = 877, + CustomLiquidCoolerChannel1Led117 = 878, + CustomLiquidCoolerChannel1Led118 = 879, + CustomLiquidCoolerChannel1Led119 = 880, + CustomLiquidCoolerChannel1Led120 = 881, + CustomLiquidCoolerChannel1Led121 = 882, + CustomLiquidCoolerChannel1Led122 = 883, + CustomLiquidCoolerChannel1Led123 = 884, + CustomLiquidCoolerChannel1Led124 = 885, + CustomLiquidCoolerChannel1Led125 = 886, + CustomLiquidCoolerChannel1Led126 = 887, + CustomLiquidCoolerChannel1Led127 = 888, + CustomLiquidCoolerChannel1Led128 = 889, + CustomLiquidCoolerChannel1Led129 = 890, + CustomLiquidCoolerChannel1Led130 = 891, + CustomLiquidCoolerChannel1Led131 = 892, + CustomLiquidCoolerChannel1Led132 = 893, + CustomLiquidCoolerChannel1Led133 = 894, + CustomLiquidCoolerChannel1Led134 = 895, + CustomLiquidCoolerChannel1Led135 = 896, + CustomLiquidCoolerChannel1Led136 = 897, + CustomLiquidCoolerChannel1Led137 = 898, + CustomLiquidCoolerChannel1Led138 = 899, + CustomLiquidCoolerChannel1Led139 = 900, + CustomLiquidCoolerChannel1Led140 = 901, + CustomLiquidCoolerChannel1Led141 = 902, + CustomLiquidCoolerChannel1Led142 = 903, + CustomLiquidCoolerChannel1Led143 = 904, + CustomLiquidCoolerChannel1Led144 = 905, + CustomLiquidCoolerChannel1Led145 = 906, + CustomLiquidCoolerChannel1Led146 = 907, + CustomLiquidCoolerChannel1Led147 = 908, + CustomLiquidCoolerChannel1Led148 = 909, + CustomLiquidCoolerChannel1Led149 = 910, + CustomLiquidCoolerChannel1Led150 = 911, + + CustomDeviceChannel1Led151 = 912, + CustomDeviceChannel1Led152 = 913, + CustomDeviceChannel1Led153 = 914, + CustomDeviceChannel1Led154 = 915, + CustomDeviceChannel1Led155 = 916, + CustomDeviceChannel1Led156 = 917, + CustomDeviceChannel1Led157 = 918, + CustomDeviceChannel1Led158 = 919, + CustomDeviceChannel1Led159 = 920, + CustomDeviceChannel1Led160 = 921, + CustomDeviceChannel1Led161 = 922, + CustomDeviceChannel1Led162 = 923, + CustomDeviceChannel1Led163 = 924, + CustomDeviceChannel1Led164 = 925, + CustomDeviceChannel1Led165 = 926, + CustomDeviceChannel1Led166 = 927, + CustomDeviceChannel1Led167 = 928, + CustomDeviceChannel1Led168 = 929, + CustomDeviceChannel1Led169 = 930, + CustomDeviceChannel1Led170 = 931, + CustomDeviceChannel1Led171 = 932, + CustomDeviceChannel1Led172 = 933, + CustomDeviceChannel1Led173 = 934, + CustomDeviceChannel1Led174 = 935, + CustomDeviceChannel1Led175 = 936, + CustomDeviceChannel1Led176 = 937, + CustomDeviceChannel1Led177 = 938, + CustomDeviceChannel1Led178 = 939, + CustomDeviceChannel1Led179 = 940, + CustomDeviceChannel1Led180 = 941, + CustomDeviceChannel1Led181 = 942, + CustomDeviceChannel1Led182 = 943, + CustomDeviceChannel1Led183 = 944, + CustomDeviceChannel1Led184 = 945, + CustomDeviceChannel1Led185 = 946, + CustomDeviceChannel1Led186 = 947, + CustomDeviceChannel1Led187 = 948, + CustomDeviceChannel1Led188 = 949, + CustomDeviceChannel1Led189 = 950, + CustomDeviceChannel1Led190 = 951, + CustomDeviceChannel1Led191 = 952, + CustomDeviceChannel1Led192 = 953, + CustomDeviceChannel1Led193 = 954, + CustomDeviceChannel1Led194 = 955, + CustomDeviceChannel1Led195 = 956, + CustomDeviceChannel1Led196 = 957, + CustomDeviceChannel1Led197 = 958, + CustomDeviceChannel1Led198 = 959, + CustomDeviceChannel1Led199 = 960, + CustomDeviceChannel1Led200 = 961, + CustomDeviceChannel1Led201 = 962, + CustomDeviceChannel1Led202 = 963, + CustomDeviceChannel1Led203 = 964, + CustomDeviceChannel1Led204 = 965, + CustomDeviceChannel1Led205 = 966, + CustomDeviceChannel1Led206 = 967, + CustomDeviceChannel1Led207 = 968, + CustomDeviceChannel1Led208 = 969, + CustomDeviceChannel1Led209 = 970, + CustomDeviceChannel1Led210 = 971, + CustomDeviceChannel1Led211 = 972, + CustomDeviceChannel1Led212 = 973, + CustomDeviceChannel1Led213 = 974, + CustomDeviceChannel1Led214 = 975, + CustomDeviceChannel1Led215 = 976, + CustomDeviceChannel1Led216 = 977, + CustomDeviceChannel1Led217 = 978, + CustomDeviceChannel1Led218 = 979, + CustomDeviceChannel1Led219 = 980, + CustomDeviceChannel1Led220 = 981, + CustomDeviceChannel1Led221 = 982, + CustomDeviceChannel1Led222 = 983, + CustomDeviceChannel1Led223 = 984, + CustomDeviceChannel1Led224 = 985, + CustomDeviceChannel1Led225 = 986, + CustomDeviceChannel1Led226 = 987, + CustomDeviceChannel1Led227 = 988, + CustomDeviceChannel1Led228 = 989, + CustomDeviceChannel1Led229 = 990, + CustomDeviceChannel1Led230 = 991, + CustomDeviceChannel1Led231 = 992, + CustomDeviceChannel1Led232 = 993, + CustomDeviceChannel1Led233 = 994, + CustomDeviceChannel1Led234 = 995, + CustomDeviceChannel1Led235 = 996, + CustomDeviceChannel1Led236 = 997, + CustomDeviceChannel1Led237 = 998, + CustomDeviceChannel1Led238 = 999, + CustomDeviceChannel1Led239 = 1000, + CustomDeviceChannel1Led240 = 1001, + CustomDeviceChannel1Led241 = 1002, + CustomDeviceChannel1Led242 = 1003, + CustomDeviceChannel1Led243 = 1004, + CustomDeviceChannel1Led244 = 1005, + CustomDeviceChannel1Led245 = 1006, + CustomDeviceChannel1Led246 = 1007, + CustomDeviceChannel1Led247 = 1008, + CustomDeviceChannel1Led248 = 1009, + CustomDeviceChannel1Led249 = 1010, + CustomDeviceChannel1Led250 = 1011, + CustomDeviceChannel1Led251 = 1012, + CustomDeviceChannel1Led252 = 1013, + CustomDeviceChannel1Led253 = 1014, + CustomDeviceChannel1Led254 = 1015, + CustomDeviceChannel1Led255 = 1016, + CustomDeviceChannel1Led256 = 1017, + CustomDeviceChannel1Led257 = 1018, + CustomDeviceChannel1Led258 = 1019, + CustomDeviceChannel1Led259 = 1020, + CustomDeviceChannel1Led260 = 1021, + CustomDeviceChannel1Led261 = 1022, + CustomDeviceChannel1Led262 = 1023, + CustomDeviceChannel1Led263 = 1024, + CustomDeviceChannel1Led264 = 1025, + CustomDeviceChannel1Led265 = 1026, + CustomDeviceChannel1Led266 = 1027, + CustomDeviceChannel1Led267 = 1028, + CustomDeviceChannel1Led268 = 1029, + CustomDeviceChannel1Led269 = 1030, + CustomDeviceChannel1Led270 = 1031, + CustomDeviceChannel1Led271 = 1032, + CustomDeviceChannel1Led272 = 1033, + CustomDeviceChannel1Led273 = 1034, + CustomDeviceChannel1Led274 = 1035, + CustomDeviceChannel1Led275 = 1036, + CustomDeviceChannel1Led276 = 1037, + CustomDeviceChannel1Led277 = 1038, + CustomDeviceChannel1Led278 = 1039, + CustomDeviceChannel1Led279 = 1040, + CustomDeviceChannel1Led280 = 1041, + CustomDeviceChannel1Led281 = 1042, + CustomDeviceChannel1Led282 = 1043, + CustomDeviceChannel1Led283 = 1044, + CustomDeviceChannel1Led284 = 1045, + CustomDeviceChannel1Led285 = 1046, + CustomDeviceChannel1Led286 = 1047, + CustomDeviceChannel1Led287 = 1048, + CustomDeviceChannel1Led288 = 1049, + CustomDeviceChannel1Led289 = 1050, + CustomDeviceChannel1Led290 = 1051, + CustomDeviceChannel1Led291 = 1052, + CustomDeviceChannel1Led292 = 1053, + CustomDeviceChannel1Led293 = 1054, + CustomDeviceChannel1Led294 = 1055, + CustomDeviceChannel1Led295 = 1056, + CustomDeviceChannel1Led296 = 1057, + CustomDeviceChannel1Led297 = 1058, + CustomDeviceChannel1Led298 = 1059, + CustomDeviceChannel1Led299 = 1060, + CustomDeviceChannel1Led300 = 1061, + + CustomDeviceChannel2Led151 = 1062, + CustomDeviceChannel2Led152 = 1063, + CustomDeviceChannel2Led153 = 1064, + CustomDeviceChannel2Led154 = 1065, + CustomDeviceChannel2Led155 = 1066, + CustomDeviceChannel2Led156 = 1067, + CustomDeviceChannel2Led157 = 1068, + CustomDeviceChannel2Led158 = 1069, + CustomDeviceChannel2Led159 = 1070, + CustomDeviceChannel2Led160 = 1071, + CustomDeviceChannel2Led161 = 1072, + CustomDeviceChannel2Led162 = 1073, + CustomDeviceChannel2Led163 = 1074, + CustomDeviceChannel2Led164 = 1075, + CustomDeviceChannel2Led165 = 1076, + CustomDeviceChannel2Led166 = 1077, + CustomDeviceChannel2Led167 = 1078, + CustomDeviceChannel2Led168 = 1079, + CustomDeviceChannel2Led169 = 1080, + CustomDeviceChannel2Led170 = 1081, + CustomDeviceChannel2Led171 = 1082, + CustomDeviceChannel2Led172 = 1083, + CustomDeviceChannel2Led173 = 1084, + CustomDeviceChannel2Led174 = 1085, + CustomDeviceChannel2Led175 = 1086, + CustomDeviceChannel2Led176 = 1087, + CustomDeviceChannel2Led177 = 1088, + CustomDeviceChannel2Led178 = 1089, + CustomDeviceChannel2Led179 = 1090, + CustomDeviceChannel2Led180 = 1091, + CustomDeviceChannel2Led181 = 1092, + CustomDeviceChannel2Led182 = 1093, + CustomDeviceChannel2Led183 = 1094, + CustomDeviceChannel2Led184 = 1095, + CustomDeviceChannel2Led185 = 1096, + CustomDeviceChannel2Led186 = 1097, + CustomDeviceChannel2Led187 = 1098, + CustomDeviceChannel2Led188 = 1099, + CustomDeviceChannel2Led189 = 1100, + CustomDeviceChannel2Led190 = 1101, + CustomDeviceChannel2Led191 = 1102, + CustomDeviceChannel2Led192 = 1103, + CustomDeviceChannel2Led193 = 1104, + CustomDeviceChannel2Led194 = 1105, + CustomDeviceChannel2Led195 = 1106, + CustomDeviceChannel2Led196 = 1107, + CustomDeviceChannel2Led197 = 1108, + CustomDeviceChannel2Led198 = 1109, + CustomDeviceChannel2Led199 = 1110, + CustomDeviceChannel2Led200 = 1111, + CustomDeviceChannel2Led201 = 1112, + CustomDeviceChannel2Led202 = 1113, + CustomDeviceChannel2Led203 = 1114, + CustomDeviceChannel2Led204 = 1115, + CustomDeviceChannel2Led205 = 1116, + CustomDeviceChannel2Led206 = 1117, + CustomDeviceChannel2Led207 = 1118, + CustomDeviceChannel2Led208 = 1119, + CustomDeviceChannel2Led209 = 1120, + CustomDeviceChannel2Led210 = 1121, + CustomDeviceChannel2Led211 = 1122, + CustomDeviceChannel2Led212 = 1123, + CustomDeviceChannel2Led213 = 1124, + CustomDeviceChannel2Led214 = 1125, + CustomDeviceChannel2Led215 = 1126, + CustomDeviceChannel2Led216 = 1127, + CustomDeviceChannel2Led217 = 1128, + CustomDeviceChannel2Led218 = 1129, + CustomDeviceChannel2Led219 = 1130, + CustomDeviceChannel2Led220 = 1131, + CustomDeviceChannel2Led221 = 1132, + CustomDeviceChannel2Led222 = 1133, + CustomDeviceChannel2Led223 = 1134, + CustomDeviceChannel2Led224 = 1135, + CustomDeviceChannel2Led225 = 1136, + CustomDeviceChannel2Led226 = 1137, + CustomDeviceChannel2Led227 = 1138, + CustomDeviceChannel2Led228 = 1139, + CustomDeviceChannel2Led229 = 1140, + CustomDeviceChannel2Led230 = 1141, + CustomDeviceChannel2Led231 = 1142, + CustomDeviceChannel2Led232 = 1143, + CustomDeviceChannel2Led233 = 1144, + CustomDeviceChannel2Led234 = 1145, + CustomDeviceChannel2Led235 = 1146, + CustomDeviceChannel2Led236 = 1147, + CustomDeviceChannel2Led237 = 1148, + CustomDeviceChannel2Led238 = 1149, + CustomDeviceChannel2Led239 = 1150, + CustomDeviceChannel2Led240 = 1151, + CustomDeviceChannel2Led241 = 1152, + CustomDeviceChannel2Led242 = 1153, + CustomDeviceChannel2Led243 = 1154, + CustomDeviceChannel2Led244 = 1155, + CustomDeviceChannel2Led245 = 1156, + CustomDeviceChannel2Led246 = 1157, + CustomDeviceChannel2Led247 = 1158, + CustomDeviceChannel2Led248 = 1159, + CustomDeviceChannel2Led249 = 1160, + CustomDeviceChannel2Led250 = 1161, + CustomDeviceChannel2Led251 = 1162, + CustomDeviceChannel2Led252 = 1163, + CustomDeviceChannel2Led253 = 1164, + CustomDeviceChannel2Led254 = 1165, + CustomDeviceChannel2Led255 = 1166, + CustomDeviceChannel2Led256 = 1167, + CustomDeviceChannel2Led257 = 1168, + CustomDeviceChannel2Led258 = 1169, + CustomDeviceChannel2Led259 = 1170, + CustomDeviceChannel2Led260 = 1171, + CustomDeviceChannel2Led261 = 1172, + CustomDeviceChannel2Led262 = 1173, + CustomDeviceChannel2Led263 = 1174, + CustomDeviceChannel2Led264 = 1175, + CustomDeviceChannel2Led265 = 1176, + CustomDeviceChannel2Led266 = 1177, + CustomDeviceChannel2Led267 = 1178, + CustomDeviceChannel2Led268 = 1179, + CustomDeviceChannel2Led269 = 1180, + CustomDeviceChannel2Led270 = 1181, + CustomDeviceChannel2Led271 = 1182, + CustomDeviceChannel2Led272 = 1183, + CustomDeviceChannel2Led273 = 1184, + CustomDeviceChannel2Led274 = 1185, + CustomDeviceChannel2Led275 = 1186, + CustomDeviceChannel2Led276 = 1187, + CustomDeviceChannel2Led277 = 1188, + CustomDeviceChannel2Led278 = 1189, + CustomDeviceChannel2Led279 = 1190, + CustomDeviceChannel2Led280 = 1191, + CustomDeviceChannel2Led281 = 1192, + CustomDeviceChannel2Led282 = 1193, + CustomDeviceChannel2Led283 = 1194, + CustomDeviceChannel2Led284 = 1195, + CustomDeviceChannel2Led285 = 1196, + CustomDeviceChannel2Led286 = 1197, + CustomDeviceChannel2Led287 = 1198, + CustomDeviceChannel2Led288 = 1199, + CustomDeviceChannel2Led289 = 1200, + CustomDeviceChannel2Led290 = 1201, + CustomDeviceChannel2Led291 = 1202, + CustomDeviceChannel2Led292 = 1203, + CustomDeviceChannel2Led293 = 1204, + CustomDeviceChannel2Led294 = 1205, + CustomDeviceChannel2Led295 = 1206, + CustomDeviceChannel2Led296 = 1207, + CustomDeviceChannel2Led297 = 1208, + CustomDeviceChannel2Led298 = 1209, + CustomDeviceChannel2Led299 = 1210, + CustomDeviceChannel2Led300 = 1211, + + CustomDeviceChannel3Led151 = 1212, + CustomDeviceChannel3Led152 = 1213, + CustomDeviceChannel3Led153 = 1214, + CustomDeviceChannel3Led154 = 1215, + CustomDeviceChannel3Led155 = 1216, + CustomDeviceChannel3Led156 = 1217, + CustomDeviceChannel3Led157 = 1218, + CustomDeviceChannel3Led158 = 1219, + CustomDeviceChannel3Led159 = 1220, + CustomDeviceChannel3Led160 = 1221, + CustomDeviceChannel3Led161 = 1222, + CustomDeviceChannel3Led162 = 1223, + CustomDeviceChannel3Led163 = 1224, + CustomDeviceChannel3Led164 = 1225, + CustomDeviceChannel3Led165 = 1226, + CustomDeviceChannel3Led166 = 1227, + CustomDeviceChannel3Led167 = 1228, + CustomDeviceChannel3Led168 = 1229, + CustomDeviceChannel3Led169 = 1230, + CustomDeviceChannel3Led170 = 1231, + CustomDeviceChannel3Led171 = 1232, + CustomDeviceChannel3Led172 = 1233, + CustomDeviceChannel3Led173 = 1234, + CustomDeviceChannel3Led174 = 1235, + CustomDeviceChannel3Led175 = 1236, + CustomDeviceChannel3Led176 = 1237, + CustomDeviceChannel3Led177 = 1238, + CustomDeviceChannel3Led178 = 1239, + CustomDeviceChannel3Led179 = 1240, + CustomDeviceChannel3Led180 = 1241, + CustomDeviceChannel3Led181 = 1242, + CustomDeviceChannel3Led182 = 1243, + CustomDeviceChannel3Led183 = 1244, + CustomDeviceChannel3Led184 = 1245, + CustomDeviceChannel3Led185 = 1246, + CustomDeviceChannel3Led186 = 1247, + CustomDeviceChannel3Led187 = 1248, + CustomDeviceChannel3Led188 = 1249, + CustomDeviceChannel3Led189 = 1250, + CustomDeviceChannel3Led190 = 1251, + CustomDeviceChannel3Led191 = 1252, + CustomDeviceChannel3Led192 = 1253, + CustomDeviceChannel3Led193 = 1254, + CustomDeviceChannel3Led194 = 1255, + CustomDeviceChannel3Led195 = 1256, + CustomDeviceChannel3Led196 = 1257, + CustomDeviceChannel3Led197 = 1258, + CustomDeviceChannel3Led198 = 1259, + CustomDeviceChannel3Led199 = 1260, + CustomDeviceChannel3Led200 = 1261, + CustomDeviceChannel3Led201 = 1262, + CustomDeviceChannel3Led202 = 1263, + CustomDeviceChannel3Led203 = 1264, + CustomDeviceChannel3Led204 = 1265, + CustomDeviceChannel3Led205 = 1266, + CustomDeviceChannel3Led206 = 1267, + CustomDeviceChannel3Led207 = 1268, + CustomDeviceChannel3Led208 = 1269, + CustomDeviceChannel3Led209 = 1270, + CustomDeviceChannel3Led210 = 1271, + CustomDeviceChannel3Led211 = 1272, + CustomDeviceChannel3Led212 = 1273, + CustomDeviceChannel3Led213 = 1274, + CustomDeviceChannel3Led214 = 1275, + CustomDeviceChannel3Led215 = 1276, + CustomDeviceChannel3Led216 = 1277, + CustomDeviceChannel3Led217 = 1278, + CustomDeviceChannel3Led218 = 1279, + CustomDeviceChannel3Led219 = 1280, + CustomDeviceChannel3Led220 = 1281, + CustomDeviceChannel3Led221 = 1282, + CustomDeviceChannel3Led222 = 1283, + CustomDeviceChannel3Led223 = 1284, + CustomDeviceChannel3Led224 = 1285, + CustomDeviceChannel3Led225 = 1286, + CustomDeviceChannel3Led226 = 1287, + CustomDeviceChannel3Led227 = 1288, + CustomDeviceChannel3Led228 = 1289, + CustomDeviceChannel3Led229 = 1290, + CustomDeviceChannel3Led230 = 1291, + CustomDeviceChannel3Led231 = 1292, + CustomDeviceChannel3Led232 = 1293, + CustomDeviceChannel3Led233 = 1294, + CustomDeviceChannel3Led234 = 1295, + CustomDeviceChannel3Led235 = 1296, + CustomDeviceChannel3Led236 = 1297, + CustomDeviceChannel3Led237 = 1298, + CustomDeviceChannel3Led238 = 1299, + CustomDeviceChannel3Led239 = 1300, + CustomDeviceChannel3Led240 = 1301, + CustomDeviceChannel3Led241 = 1302, + CustomDeviceChannel3Led242 = 1303, + CustomDeviceChannel3Led243 = 1304, + CustomDeviceChannel3Led244 = 1305, + CustomDeviceChannel3Led245 = 1306, + CustomDeviceChannel3Led246 = 1307, + CustomDeviceChannel3Led247 = 1308, + CustomDeviceChannel3Led248 = 1309, + CustomDeviceChannel3Led249 = 1310, + CustomDeviceChannel3Led250 = 1311, + CustomDeviceChannel3Led251 = 1312, + CustomDeviceChannel3Led252 = 1313, + CustomDeviceChannel3Led253 = 1314, + CustomDeviceChannel3Led254 = 1315, + CustomDeviceChannel3Led255 = 1316, + CustomDeviceChannel3Led256 = 1317, + CustomDeviceChannel3Led257 = 1318, + CustomDeviceChannel3Led258 = 1319, + CustomDeviceChannel3Led259 = 1320, + CustomDeviceChannel3Led260 = 1321, + CustomDeviceChannel3Led261 = 1322, + CustomDeviceChannel3Led262 = 1323, + CustomDeviceChannel3Led263 = 1324, + CustomDeviceChannel3Led264 = 1325, + CustomDeviceChannel3Led265 = 1326, + CustomDeviceChannel3Led266 = 1327, + CustomDeviceChannel3Led267 = 1328, + CustomDeviceChannel3Led268 = 1329, + CustomDeviceChannel3Led269 = 1330, + CustomDeviceChannel3Led270 = 1331, + CustomDeviceChannel3Led271 = 1332, + CustomDeviceChannel3Led272 = 1333, + CustomDeviceChannel3Led273 = 1334, + CustomDeviceChannel3Led274 = 1335, + CustomDeviceChannel3Led275 = 1336, + CustomDeviceChannel3Led276 = 1337, + CustomDeviceChannel3Led277 = 1338, + CustomDeviceChannel3Led278 = 1339, + CustomDeviceChannel3Led279 = 1340, + CustomDeviceChannel3Led280 = 1341, + CustomDeviceChannel3Led281 = 1342, + CustomDeviceChannel3Led282 = 1343, + CustomDeviceChannel3Led283 = 1344, + CustomDeviceChannel3Led284 = 1345, + CustomDeviceChannel3Led285 = 1346, + CustomDeviceChannel3Led286 = 1347, + CustomDeviceChannel3Led287 = 1348, + CustomDeviceChannel3Led288 = 1349, + CustomDeviceChannel3Led289 = 1350, + CustomDeviceChannel3Led290 = 1351, + CustomDeviceChannel3Led291 = 1352, + CustomDeviceChannel3Led292 = 1353, + CustomDeviceChannel3Led293 = 1354, + CustomDeviceChannel3Led294 = 1355, + CustomDeviceChannel3Led295 = 1356, + CustomDeviceChannel3Led296 = 1357, + CustomDeviceChannel3Led297 = 1358, + CustomDeviceChannel3Led298 = 1359, + CustomDeviceChannel3Led299 = 1360, + CustomDeviceChannel3Led300 = 1361, + + Mainboard1 = 1362, + Mainboard2 = 1363, + Mainboard3 = 1364, + Mainboard4 = 1365, + Mainboard5 = 1366, + Mainboard6 = 1367, + Mainboard7 = 1368, + Mainboard8 = 1369, + Mainboard9 = 1370, + Mainboard10 = 1371, + Mainboard11 = 1372, + Mainboard12 = 1373, + Mainboard13 = 1374, + Mainboard14 = 1375, + Mainboard15 = 1376, + Mainboard16 = 1377, + Mainboard17 = 1378, + Mainboard18 = 1379, + Mainboard19 = 1380, + Mainboard20 = 1381, + Mainboard21 = 1382, + Mainboard22 = 1383, + Mainboard23 = 1384, + Mainboard24 = 1385, + Mainboard25 = 1386, + Mainboard26 = 1387, + Mainboard27 = 1388, + Mainboard28 = 1389, + Mainboard29 = 1390, + Mainboard30 = 1391, + Mainboard31 = 1392, + Mainboard32 = 1393, + Mainboard33 = 1394, + Mainboard34 = 1395, + Mainboard35 = 1396, + Mainboard36 = 1397, + Mainboard37 = 1398, + Mainboard38 = 1399, + Mainboard39 = 1400, + Mainboard40 = 1401, + Mainboard41 = 1402, + Mainboard42 = 1403, + Mainboard43 = 1404, + Mainboard44 = 1405, + Mainboard45 = 1406, + Mainboard46 = 1407, + Mainboard47 = 1408, + Mainboard48 = 1409, + Mainboard49 = 1410, + Mainboard50 = 1411, + Mainboard51 = 1412, + Mainboard52 = 1413, + Mainboard53 = 1414, + Mainboard54 = 1415, + Mainboard55 = 1416, + Mainboard56 = 1417, + Mainboard57 = 1418, + Mainboard58 = 1419, + Mainboard59 = 1420, + Mainboard60 = 1421, + Mainboard61 = 1422, + Mainboard62 = 1423, + Mainboard63 = 1424, + Mainboard64 = 1425, + Mainboard65 = 1426, + Mainboard66 = 1427, + Mainboard67 = 1428, + Mainboard68 = 1429, + Mainboard69 = 1430, + Mainboard70 = 1431, + Mainboard71 = 1432, + Mainboard72 = 1433, + Mainboard73 = 1434, + Mainboard74 = 1435, + Mainboard75 = 1436, + Mainboard76 = 1437, + Mainboard77 = 1438, + Mainboard78 = 1439, + Mainboard79 = 1440, + Mainboard80 = 1441, + Mainboard81 = 1442, + Mainboard82 = 1443, + Mainboard83 = 1444, + Mainboard84 = 1445, + Mainboard85 = 1446, + Mainboard86 = 1447, + Mainboard87 = 1448, + Mainboard88 = 1449, + Mainboard89 = 1450, + Mainboard90 = 1451, + Mainboard91 = 1452, + Mainboard92 = 1453, + Mainboard93 = 1454, + Mainboard94 = 1455, + Mainboard95 = 1456, + Mainboard96 = 1457, + Mainboard97 = 1458, + Mainboard98 = 1459, + Mainboard99 = 1460, + Mainboard100 = 1461, + + GPU1 = 1462, + GPU2 = 1463, + GPU3 = 1464, + GPU4 = 1465, + GPU5 = 1466, + GPU6 = 1467, + GPU7 = 1468, + GPU8 = 1469, + GPU9 = 1470, + GPU10 = 1471, + GPU11 = 1472, + GPU12 = 1473, + GPU13 = 1474, + GPU14 = 1475, + GPU15 = 1476, + GPU16 = 1477, + GPU17 = 1478, + GPU18 = 1479, + GPU19 = 1480, + GPU20 = 1481, + GPU21 = 1482, + GPU22 = 1483, + GPU23 = 1484, + GPU24 = 1485, + GPU25 = 1486, + GPU26 = 1487, + GPU27 = 1488, + GPU28 = 1489, + GPU29 = 1490, + GPU30 = 1491, + GPU31 = 1492, + GPU32 = 1493, + GPU33 = 1494, + GPU34 = 1495, + GPU35 = 1496, + GPU36 = 1497, + GPU37 = 1498, + GPU38 = 1499, + GPU39 = 1500, + GPU40 = 1501, + GPU41 = 1502, + GPU42 = 1503, + GPU43 = 1504, + GPU44 = 1505, + GPU45 = 1506, + GPU46 = 1507, + GPU47 = 1508, + GPU48 = 1509, + GPU49 = 1510, + GPU50 = 1511, + + Lightbar20 = 1512, + Lightbar21 = 1513, + Lightbar22 = 1514, + Lightbar23 = 1515, + Lightbar24 = 1516, + Lightbar25 = 1517, + Lightbar26 = 1518, + Lightbar27 = 1519, + Lightbar28 = 1520, + Lightbar29 = 1521, + Lightbar30 = 1522, + Lightbar31 = 1523, + Lightbar32 = 1524, + Lightbar33 = 1525, + Lightbar34 = 1526, + Lightbar35 = 1527, + Lightbar36 = 1528, + Lightbar37 = 1529, + Lightbar38 = 1530, + Lightbar39 = 1531, + Lightbar40 = 1532, + Lightbar41 = 1533, + Lightbar42 = 1534, + Lightbar43 = 1535, + Lightbar44 = 1536, + Lightbar45 = 1537, + Lightbar46 = 1538, + Lightbar47 = 1539, + Lightbar48 = 1540, + Lightbar49 = 1541, + Lightbar50 = 1542, + + Profile = 1543, + + OemLed101 = 1544, + OemLed102 = 1545, + OemLed103 = 1546, + OemLed104 = 1547, + OemLed105 = 1548, + OemLed106 = 1549, + OemLed107 = 1550, + OemLed108 = 1551, + OemLed109 = 1552, + OemLed110 = 1553, + OemLed111 = 1554, + OemLed112 = 1555, + OemLed113 = 1556, + OemLed114 = 1557, + OemLed115 = 1558, + OemLed116 = 1559, + OemLed117 = 1560, + OemLed118 = 1561, + OemLed119 = 1562, + OemLed120 = 1563, + OemLed121 = 1564, + OemLed122 = 1565, + OemLed123 = 1566, + OemLed124 = 1567, + OemLed125 = 1568, + OemLed126 = 1569, + OemLed127 = 1570, + OemLed128 = 1571, + OemLed129 = 1572, + OemLed130 = 1573, + OemLed131 = 1574, + OemLed132 = 1575, + OemLed133 = 1576, + OemLed134 = 1577, + OemLed135 = 1578, + OemLed136 = 1579, + OemLed137 = 1580, + OemLed138 = 1581, + OemLed139 = 1582, + OemLed140 = 1583, + OemLed141 = 1584, + OemLed142 = 1585, + OemLed143 = 1586, + OemLed144 = 1587, + OemLed145 = 1588, + OemLed146 = 1589, + OemLed147 = 1590, + OemLed148 = 1591, + OemLed149 = 1592, + OemLed150 = 1593, + OemLed151 = 1594, + OemLed152 = 1595, + OemLed153 = 1596, + OemLed154 = 1597, + OemLed155 = 1598, + OemLed156 = 1599, + OemLed157 = 1600, + OemLed158 = 1601, + OemLed159 = 1602, + OemLed160 = 1603, + OemLed161 = 1604, + OemLed162 = 1605, + OemLed163 = 1606, + OemLed164 = 1607, + OemLed165 = 1608, + OemLed166 = 1609, + OemLed167 = 1610, + OemLed168 = 1611, + OemLed169 = 1612, + OemLed170 = 1613, + OemLed171 = 1614, + OemLed172 = 1615, + OemLed173 = 1616, + OemLed174 = 1617, + OemLed175 = 1618, + OemLed176 = 1619, + OemLed177 = 1620, + OemLed178 = 1621, + OemLed179 = 1622, + OemLed180 = 1623, + OemLed181 = 1624, + OemLed182 = 1625, + OemLed183 = 1626, + OemLed184 = 1627, + OemLed185 = 1628, + OemLed186 = 1629, + OemLed187 = 1630, + OemLed188 = 1631, + OemLed189 = 1632, + OemLed190 = 1633, + OemLed191 = 1634, + OemLed192 = 1635, + OemLed193 = 1636, + OemLed194 = 1637, + OemLed195 = 1638, + OemLed196 = 1639, + OemLed197 = 1640, + OemLed198 = 1641, + OemLed199 = 1642, + OemLed200 = 1643, + OemLed201 = 1644, + OemLed202 = 1645, + OemLed203 = 1646, + OemLed204 = 1647, + OemLed205 = 1648, + OemLed206 = 1649, + OemLed207 = 1650, + OemLed208 = 1651, + OemLed209 = 1652, + OemLed210 = 1653, + OemLed211 = 1654, + OemLed212 = 1655, + OemLed213 = 1656, + OemLed214 = 1657, + OemLed215 = 1658, + OemLed216 = 1659, + OemLed217 = 1660, + OemLed218 = 1661, + OemLed219 = 1662, + OemLed220 = 1663, + OemLed221 = 1664, + OemLed222 = 1665, + OemLed223 = 1666, + OemLed224 = 1667, + OemLed225 = 1668, + OemLed226 = 1669, + OemLed227 = 1670, + OemLed228 = 1671, + OemLed229 = 1672, + OemLed230 = 1673, + OemLed231 = 1674, + OemLed232 = 1675, + OemLed233 = 1676, + OemLed234 = 1677, + OemLed235 = 1678, + OemLed236 = 1679, + OemLed237 = 1680, + OemLed238 = 1681, + OemLed239 = 1682, + OemLed240 = 1683, + OemLed241 = 1684, + OemLed242 = 1685, + OemLed243 = 1686, + OemLed244 = 1687, + OemLed245 = 1688, + OemLed246 = 1689, + OemLed247 = 1690, + OemLed248 = 1691, + OemLed249 = 1692, + OemLed250 = 1693, + + B7 = 1694, + B8 = 1695, + B9 = 1696, + B10 = 1697, + B11 = 1698, + B12 = 1699, + B13 = 1700, + B14 = 1701, + B15 = 1702, + B16 = 1703, + B17 = 1704, + B18 = 1705, + B19 = 1706, + B20 = 1707, +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairLogicalKeyboardLayout.cs b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairLogicalKeyboardLayout.cs new file mode 100644 index 00000000..48c8c218 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairLogicalKeyboardLayout.cs @@ -0,0 +1,30 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global +#pragma warning disable 1591 + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Contains a list of available logical layouts for corsair keyboards. +/// +public enum CorsairLogicalKeyboardLayout +{ + US_Int = 1, + NA = 2, + EU = 3, + UK = 4, + BE = 5, + BR = 6, + CH = 7, + CN = 8, + DE = 9, + ES = 10, + FR = 11, + IT = 12, + ND = 13, + RU = 14, + JP = 15, + KR = 16, + TW = 17, + MEX = 18 +}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairPhysicalKeyboardLayout.cs b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairPhysicalKeyboardLayout.cs new file mode 100644 index 00000000..c9177419 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairPhysicalKeyboardLayout.cs @@ -0,0 +1,35 @@ +// ReSharper disable UnusedMember.Global +// ReSharper disable InconsistentNaming + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Contains a list of available physical layouts for corsair keyboards. +/// +public enum CorsairPhysicalKeyboardLayout +{ + /// + /// US-Keyboard + /// + US = 1, + + /// + /// UK-Keyboard + /// + UK = 2, + + /// + /// BR-Keyboard + /// + BR = 3, + + /// + /// JP-Keyboard + /// + JP = 4, + + /// + /// KR-Keyboard + /// + KR = 5 +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairPhysicalMouseLayout.cs b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairPhysicalMouseLayout.cs new file mode 100644 index 00000000..9be87b4c --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Enum/CorsairPhysicalMouseLayout.cs @@ -0,0 +1,107 @@ +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Contains a list of available physical layouts for mice. +/// +public enum CorsairPhysicalMouseLayout +{ + /// + /// Zone1-Mouse + /// + Zones1 = 6, + + /// + /// Zone2-Mouse + /// + Zones2 = 7, + + /// + /// Zone3-Mouse + /// + Zones3 = 8, + + /// + /// Zone4-Mouse + /// + Zones4 = 9, + + /// + /// Zone5-Mouse + /// + Zones5 = 101, + + /// + /// Zone6-Mouse + /// + Zones6 = 11, + + /// + /// Zone7-Mouse + /// + Zones7 = 12, + + /// + /// Zone8-Mouse + /// + Zones8 = 13, + + /// + /// Zone9-Mouse + /// + Zones9 = 14, + + /// + /// Zone10-Mouse + /// + Zones10 = 15, + + /// + /// Zone11-Mouse + /// + Zones11 = 16, + + /// + /// Zone12-Mouse + /// + Zones12 = 17, + + /// + /// Zone13-Mouse + /// + Zones13 = 18, + + /// + /// Zone14-Mouse + /// + Zones14 = 19, + + /// + /// Zone15-Mouse + /// + Zones15 = 20, + + /// + /// Zone16-Mouse + /// + Zones16 = 21, + + /// + /// Zone17-Mouse + /// + Zones17 = 22, + + /// + /// Zone18-Mouse + /// + Zones18 = 23, + + /// + /// Zone19-Mouse + /// + Zones19 = 24, + + /// + /// Zone20-Mouse + /// + Zones20 = 25 +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Exceptions/CUEException.cs b/RGB.NET.Devices.Corsair_Legacy/Exceptions/CUEException.cs new file mode 100644 index 00000000..1618afbd --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Exceptions/CUEException.cs @@ -0,0 +1,36 @@ +// ReSharper disable UnusedAutoPropertyAccessor.Global +// ReSharper disable MemberCanBePrivate.Global + +using System; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents an exception thrown by the CUE. +/// +public class CUEException : ApplicationException +{ + #region Properties & Fields + + /// + /// Gets the provided by CUE. + /// + public CorsairError Error { get; } + + #endregion + + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The provided by CUE, which leads to this exception. + public CUEException(CorsairError error) + { + this.Error = error; + } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs new file mode 100644 index 00000000..6282932b --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs @@ -0,0 +1,80 @@ +using System; +using System.Runtime.InteropServices; +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents the update-queue performing updates for corsair devices. +/// +public class CorsairDeviceUpdateQueue : UpdateQueue +{ + #region Properties & Fields + + private int _deviceIndex; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The update trigger used by this queue. + /// The index used to identify the device. + public CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceIndex) + : base(updateTrigger) + { + this._deviceIndex = deviceIndex; + } + + #endregion + + #region Methods + + /// + protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) + { + try + { + int structSize = Marshal.SizeOf(typeof(_CorsairLedColor)); + IntPtr ptr = Marshal.AllocHGlobal(structSize * dataSet.Length); + IntPtr addPtr = new(ptr.ToInt64()); + try + { + foreach ((object key, Color color) in dataSet) + { + _CorsairLedColor corsairColor = new() + { + ledId = (int)key, + r = color.GetR(), + g = color.GetG(), + b = color.GetB() + }; + + Marshal.StructureToPtr(corsairColor, addPtr, false); + addPtr = new IntPtr(addPtr.ToInt64() + structSize); + } + + _CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Length, ptr); + _CUESDK.CorsairSetLedsColorsFlushBuffer(); + } + finally + { + Marshal.FreeHGlobal(ptr); + } + + return true; + } + catch (Exception ex) + { + CorsairLegacyDeviceProvider.Instance.Throw(ex); + } + + return false; + } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs new file mode 100644 index 00000000..f2cd5207 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs @@ -0,0 +1,65 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global + +using System; +using System.Runtime.InteropServices; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Managed wrapper for CorsairProtocolDetails. +/// +public class CorsairProtocolDetails +{ + #region Properties & Fields + + /// + /// String containing version of SDK(like "1.0.0.1"). + /// Always contains valid value even if there was no CUE found. + /// + public string? SdkVersion { get; } + + /// + /// String containing version of CUE(like "1.0.0.1") or NULL if CUE was not found. + /// + public string? ServerVersion { get; } + + /// + /// Integer that specifies version of protocol that is implemented by current SDK. + /// Numbering starts from 1. + /// Always contains valid value even if there was no CUE found. + /// + public int SdkProtocolVersion { get; } + + /// + /// Integer that specifies version of protocol that is implemented by CUE. + /// Numbering starts from 1. + /// If CUE was not found then this value will be 0. + /// + public int ServerProtocolVersion { get; } + + /// + /// Boolean that specifies if there were breaking changes between version of protocol implemented by server and client. + /// + public bool BreakingChanges { get; } + + #endregion + + #region Constructors + + /// + /// Internal constructor of managed CorsairProtocolDetails. + /// + /// The native CorsairProtocolDetails-struct + internal CorsairProtocolDetails(_CorsairProtocolDetails nativeDetails) + { + this.SdkVersion = nativeDetails.sdkVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.sdkVersion); + this.ServerVersion = nativeDetails.serverVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.serverVersion); + this.SdkProtocolVersion = nativeDetails.sdkProtocolVersion; + this.ServerProtocolVersion = nativeDetails.serverProtocolVersion; + this.BreakingChanges = nativeDetails.breakingChanges != 0; + } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs new file mode 100644 index 00000000..fb9aa2ed --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs @@ -0,0 +1,76 @@ +using System; +using System.Runtime.InteropServices; +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a generic CUE-device. (keyboard, mouse, headset, mousepad). +/// +public abstract class CorsairRGBDevice : AbstractRGBDevice, ICorsairRGBDevice + where TDeviceInfo : CorsairRGBDeviceInfo +{ + #region Properties & Fields + + /// + /// Gets the mapping of to used to update the LEDs of this device. + /// + protected LedMapping Mapping { get; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The generic information provided by CUE for the device. + /// The mapping to used to update the LEDs of this device. + /// The queue used to update this device. + protected CorsairRGBDevice(TDeviceInfo info, LedMapping mapping, CorsairDeviceUpdateQueue updateQueue) + : base(info, updateQueue) + { + this.Mapping = mapping; + } + + #endregion + + #region Methods + + void ICorsairRGBDevice.Initialize() => InitializeLayout(); + + /// + /// Initializes the LEDs of the device based on the data provided by the SDK. + /// + protected virtual void InitializeLayout() + { + _CorsairLedPositions? nativeLedPositions = (_CorsairLedPositions?)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex), typeof(_CorsairLedPositions)); + if (nativeLedPositions == null) return; + + int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); + IntPtr ptr = nativeLedPositions.pLedPosition; + + for (int i = 0; i < nativeLedPositions.numberOfLed; i++) + { + _CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition)); + if (ledPosition == null) + { + ptr = new IntPtr(ptr.ToInt64() + structSize); + continue; + } + + LedId ledId = Mapping.TryGetValue(ledPosition.LedId, out LedId id) ? id : LedId.Invalid; + Rectangle rectangle = ledPosition.ToRectangle(); + AddLed(ledId, rectangle.Location, rectangle.Size); + + ptr = new IntPtr(ptr.ToInt64() + structSize); + } + } + + /// + protected override object GetLedCustomData(LedId ledId) => Mapping.TryGetValue(ledId, out CorsairLedId corsairLedId) ? corsairLedId : CorsairLedId.Invalid; + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs new file mode 100644 index 00000000..f35a65c6 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs @@ -0,0 +1,95 @@ +using System; +using System.Runtime.InteropServices; +using System.Text.RegularExpressions; +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a generic information for a Corsair-. +/// +public class CorsairRGBDeviceInfo : IRGBDeviceInfo +{ + #region Properties & Fields + + /// + /// Gets the corsair specific device type. + /// + public CorsairDeviceType CorsairDeviceType { get; } + + /// + /// Gets the index of the . + /// + public int CorsairDeviceIndex { get; } + + /// + public RGBDeviceType DeviceType { get; } + + /// + public string DeviceName { get; } + + /// + public string Manufacturer => "Corsair"; + + /// + public string Model { get; } + + /// + /// Returns the unique ID provided by the Corsair-SDK. + /// Returns string.Empty for Custom devices. + /// + public string DeviceId { get; } + + /// + public object? LayoutMetadata { get; set; } + + /// + /// Gets a flag that describes device capabilities. () + /// + public CorsairDeviceCaps CapsMask { get; } + + #endregion + + #region Constructors + + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The type of the . + /// The native -struct + internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo) + { + this.CorsairDeviceIndex = deviceIndex; + this.DeviceType = deviceType; + this.CorsairDeviceType = nativeInfo.type; + this.Model = nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase); + this.DeviceId = nativeInfo.deviceId ?? string.Empty; + this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask; + + DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model); + } + + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The type of the . + /// The native -struct + /// The name of the device-model (overwrites the one provided with the device info). + internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo, string modelName) + { + this.CorsairDeviceIndex = deviceIndex; + this.DeviceType = deviceType; + this.CorsairDeviceType = nativeInfo.type; + this.Model = modelName; + this.DeviceId = nativeInfo.deviceId ?? string.Empty; + this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask; + + DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model); + } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/ICorsairRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/ICorsairRGBDevice.cs new file mode 100644 index 00000000..dbb031b2 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/ICorsairRGBDevice.cs @@ -0,0 +1,11 @@ +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Represents a corsair RGB-device. +/// +public interface ICorsairRGBDevice : IRGBDevice +{ + internal void Initialize(); +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs new file mode 100644 index 00000000..ca2da702 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs @@ -0,0 +1,302 @@ +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Contains mappings for to . +/// +public static class LedMappings +{ + static LedMappings() + { + for (int i = 0; i <= (CorsairLedId.GPU50 - CorsairLedId.GPU1); i++) + GraphicsCard.Add(LedId.GraphicsCard1 + i, CorsairLedId.GPU1 + i); + + for (int i = 0; i <= (CorsairLedId.HeadsetStandZone9 - CorsairLedId.HeadsetStandZone1); i++) + HeadsetStand.Add(LedId.HeadsetStand1 + i, CorsairLedId.HeadsetStandZone1 + i); + + for (int i = 0; i <= (CorsairLedId.Mainboard100 - CorsairLedId.Mainboard1); i++) + Mainboard.Add(LedId.Mainboard1 + i, CorsairLedId.Mainboard1 + i); + + for (int i = 0; i <= (CorsairLedId.DRAM12 - CorsairLedId.DRAM1); i++) + Memory.Add(LedId.DRAM1 + i, CorsairLedId.DRAM1 + i); + + for (int i = 0; i <= (CorsairLedId.Zone15 - CorsairLedId.Zone1); i++) + Mousepad.Add(LedId.Mousepad1 + i, CorsairLedId.Zone1 + i); + + for (int i = 0; i <= (CorsairLedId.OemLed100 - CorsairLedId.OemLed1); i++) + Keyboard.Add(LedId.Custom1 + i, CorsairLedId.OemLed1 + i); + + for (int i = 0; i <= (CorsairLedId.OemLed250 - CorsairLedId.OemLed101); i++) + Keyboard.Add(LedId.Custom101 + i, CorsairLedId.OemLed101 + i); + } + + /// + /// Gets the mapping for graphics cards. + /// + public static LedMapping GraphicsCard { get; } = new(); + + /// + /// Gets the mapping for headsets. + /// + public static LedMapping HeadsetStand { get; } = new(); + + /// + /// Gets the mapping for mainboards. + /// + public static LedMapping Mainboard { get; } = new(); + + /// + /// Gets the mapping for memory. + /// + public static LedMapping Memory { get; } = new(); + + /// + /// Gets the mapping for mousepads. + /// + public static LedMapping Mousepad { get; } = new(); + + /// + /// Gets the mapping for headsets. + /// + public static LedMapping Headset { get; } = new() + { + { LedId.Headset1, CorsairLedId.LeftLogo }, + { LedId.Headset2, CorsairLedId.RightLogo }, + }; + + /// + /// Gets the mapping for mice. + /// + public static LedMapping Mouse { get; } = new() + { + { LedId.Mouse1, CorsairLedId.B1 }, + { LedId.Mouse2, CorsairLedId.B2 }, + { LedId.Mouse3, CorsairLedId.B3 }, + { LedId.Mouse4, CorsairLedId.B4 }, + { LedId.Mouse5, CorsairLedId.B5 }, + { LedId.Mouse6, CorsairLedId.B6 }, + { LedId.Mouse7, CorsairLedId.B7 }, + { LedId.Mouse8, CorsairLedId.B8 }, + { LedId.Mouse9, CorsairLedId.B9 }, + { LedId.Mouse10, CorsairLedId.B10 }, + { LedId.Mouse11, CorsairLedId.B11 }, + { LedId.Mouse12, CorsairLedId.B12 }, + { LedId.Mouse13, CorsairLedId.B13 }, + { LedId.Mouse14, CorsairLedId.B14 }, + { LedId.Mouse15, CorsairLedId.B15 }, + { LedId.Mouse16, CorsairLedId.B16 }, + { LedId.Mouse17, CorsairLedId.B17 }, + { LedId.Mouse18, CorsairLedId.B18 }, + { LedId.Mouse19, CorsairLedId.B19 }, + { LedId.Mouse20, CorsairLedId.B20 }, + }; + + /// + /// Gets the mapping for keyboards. + /// + public static LedMapping Keyboard { get; } = new() + { + { LedId.Invalid, CorsairLedId.Invalid }, + { LedId.Logo, CorsairLedId.Logo }, + { LedId.Keyboard_Escape, CorsairLedId.Escape }, + { LedId.Keyboard_F1, CorsairLedId.F1 }, + { LedId.Keyboard_F2, CorsairLedId.F2 }, + { LedId.Keyboard_F3, CorsairLedId.F3 }, + { LedId.Keyboard_F4, CorsairLedId.F4 }, + { LedId.Keyboard_F5, CorsairLedId.F5 }, + { LedId.Keyboard_F6, CorsairLedId.F6 }, + { LedId.Keyboard_F7, CorsairLedId.F7 }, + { LedId.Keyboard_F8, CorsairLedId.F8 }, + { LedId.Keyboard_F9, CorsairLedId.F9 }, + { LedId.Keyboard_F10, CorsairLedId.F10 }, + { LedId.Keyboard_F11, CorsairLedId.F11 }, + { LedId.Keyboard_GraveAccentAndTilde, CorsairLedId.GraveAccentAndTilde }, + { LedId.Keyboard_1, CorsairLedId.D1 }, + { LedId.Keyboard_2, CorsairLedId.D2 }, + { LedId.Keyboard_3, CorsairLedId.D3 }, + { LedId.Keyboard_4, CorsairLedId.D4 }, + { LedId.Keyboard_5, CorsairLedId.D5 }, + { LedId.Keyboard_6, CorsairLedId.D6 }, + { LedId.Keyboard_7, CorsairLedId.D7 }, + { LedId.Keyboard_8, CorsairLedId.D8 }, + { LedId.Keyboard_9, CorsairLedId.D9 }, + { LedId.Keyboard_0, CorsairLedId.D0 }, + { LedId.Keyboard_MinusAndUnderscore, CorsairLedId.MinusAndUnderscore }, + { LedId.Keyboard_Tab, CorsairLedId.Tab }, + { LedId.Keyboard_Q, CorsairLedId.Q }, + { LedId.Keyboard_W, CorsairLedId.W }, + { LedId.Keyboard_E, CorsairLedId.E }, + { LedId.Keyboard_R, CorsairLedId.R }, + { LedId.Keyboard_T, CorsairLedId.T }, + { LedId.Keyboard_Y, CorsairLedId.Y }, + { LedId.Keyboard_U, CorsairLedId.U }, + { LedId.Keyboard_I, CorsairLedId.I }, + { LedId.Keyboard_O, CorsairLedId.O }, + { LedId.Keyboard_P, CorsairLedId.P }, + { LedId.Keyboard_BracketLeft, CorsairLedId.BracketLeft }, + { LedId.Keyboard_CapsLock, CorsairLedId.CapsLock }, + { LedId.Keyboard_A, CorsairLedId.A }, + { LedId.Keyboard_S, CorsairLedId.S }, + { LedId.Keyboard_D, CorsairLedId.D }, + { LedId.Keyboard_F, CorsairLedId.F }, + { LedId.Keyboard_G, CorsairLedId.G }, + { LedId.Keyboard_H, CorsairLedId.H }, + { LedId.Keyboard_J, CorsairLedId.J }, + { LedId.Keyboard_K, CorsairLedId.K }, + { LedId.Keyboard_L, CorsairLedId.L }, + { LedId.Keyboard_SemicolonAndColon, CorsairLedId.SemicolonAndColon }, + { LedId.Keyboard_ApostropheAndDoubleQuote, CorsairLedId.ApostropheAndDoubleQuote }, + { LedId.Keyboard_LeftShift, CorsairLedId.LeftShift }, + { LedId.Keyboard_NonUsBackslash, CorsairLedId.NonUsBackslash }, + { LedId.Keyboard_Z, CorsairLedId.Z }, + { LedId.Keyboard_X, CorsairLedId.X }, + { LedId.Keyboard_C, CorsairLedId.C }, + { LedId.Keyboard_V, CorsairLedId.V }, + { LedId.Keyboard_B, CorsairLedId.B }, + { LedId.Keyboard_N, CorsairLedId.N }, + { LedId.Keyboard_M, CorsairLedId.M }, + { LedId.Keyboard_CommaAndLessThan, CorsairLedId.CommaAndLessThan }, + { LedId.Keyboard_PeriodAndBiggerThan, CorsairLedId.PeriodAndBiggerThan }, + { LedId.Keyboard_SlashAndQuestionMark, CorsairLedId.SlashAndQuestionMark }, + { LedId.Keyboard_LeftCtrl, CorsairLedId.LeftCtrl }, + { LedId.Keyboard_LeftGui, CorsairLedId.LeftGui }, + { LedId.Keyboard_LeftAlt, CorsairLedId.LeftAlt }, + { LedId.Keyboard_Lang2, CorsairLedId.Lang2 }, + { LedId.Keyboard_Space, CorsairLedId.Space }, + { LedId.Keyboard_Lang1, CorsairLedId.Lang1 }, + { LedId.Keyboard_International2, CorsairLedId.International2 }, + { LedId.Keyboard_RightAlt, CorsairLedId.RightAlt }, + { LedId.Keyboard_RightGui, CorsairLedId.RightGui }, + { LedId.Keyboard_Application, CorsairLedId.Application }, + { LedId.Keyboard_Brightness, CorsairLedId.Brightness }, + { LedId.Keyboard_F12, CorsairLedId.F12 }, + { LedId.Keyboard_PrintScreen, CorsairLedId.PrintScreen }, + { LedId.Keyboard_ScrollLock, CorsairLedId.ScrollLock }, + { LedId.Keyboard_PauseBreak, CorsairLedId.PauseBreak }, + { LedId.Keyboard_Insert, CorsairLedId.Insert }, + { LedId.Keyboard_Home, CorsairLedId.Home }, + { LedId.Keyboard_PageUp, CorsairLedId.PageUp }, + { LedId.Keyboard_BracketRight, CorsairLedId.BracketRight }, + { LedId.Keyboard_Backslash, CorsairLedId.Backslash }, + { LedId.Keyboard_NonUsTilde, CorsairLedId.NonUsTilde }, + { LedId.Keyboard_Enter, CorsairLedId.Enter }, + { LedId.Keyboard_International1, CorsairLedId.International1 }, + { LedId.Keyboard_EqualsAndPlus, CorsairLedId.EqualsAndPlus }, + { LedId.Keyboard_International3, CorsairLedId.International3 }, + { LedId.Keyboard_Backspace, CorsairLedId.Backspace }, + { LedId.Keyboard_Delete, CorsairLedId.Delete }, + { LedId.Keyboard_End, CorsairLedId.End }, + { LedId.Keyboard_PageDown, CorsairLedId.PageDown }, + { LedId.Keyboard_RightShift, CorsairLedId.RightShift }, + { LedId.Keyboard_RightCtrl, CorsairLedId.RightCtrl }, + { LedId.Keyboard_ArrowUp, CorsairLedId.UpArrow }, + { LedId.Keyboard_ArrowLeft, CorsairLedId.LeftArrow }, + { LedId.Keyboard_ArrowDown, CorsairLedId.DownArrow }, + { LedId.Keyboard_ArrowRight, CorsairLedId.RightArrow }, + { LedId.Keyboard_WinLock, CorsairLedId.WinLock }, + { LedId.Keyboard_MediaMute, CorsairLedId.Mute }, + { LedId.Keyboard_MediaStop, CorsairLedId.Stop }, + { LedId.Keyboard_MediaPreviousTrack, CorsairLedId.ScanPreviousTrack }, + { LedId.Keyboard_MediaPlay, CorsairLedId.PlayPause }, + { LedId.Keyboard_MediaNextTrack, CorsairLedId.ScanNextTrack }, + { LedId.Keyboard_NumLock, CorsairLedId.NumLock }, + { LedId.Keyboard_NumSlash, CorsairLedId.KeypadSlash }, + { LedId.Keyboard_NumAsterisk, CorsairLedId.KeypadAsterisk }, + { LedId.Keyboard_NumMinus, CorsairLedId.KeypadMinus }, + { LedId.Keyboard_NumPlus, CorsairLedId.KeypadPlus }, + { LedId.Keyboard_NumEnter, CorsairLedId.KeypadEnter }, + { LedId.Keyboard_Num7, CorsairLedId.Keypad7 }, + { LedId.Keyboard_Num8, CorsairLedId.Keypad8 }, + { LedId.Keyboard_Num9, CorsairLedId.Keypad9 }, + { LedId.Keyboard_NumComma, CorsairLedId.KeypadComma }, + { LedId.Keyboard_Num4, CorsairLedId.Keypad4 }, + { LedId.Keyboard_Num5, CorsairLedId.Keypad5 }, + { LedId.Keyboard_Num6, CorsairLedId.Keypad6 }, + { LedId.Keyboard_Num1, CorsairLedId.Keypad1 }, + { LedId.Keyboard_Num2, CorsairLedId.Keypad2 }, + { LedId.Keyboard_Num3, CorsairLedId.Keypad3 }, + { LedId.Keyboard_Num0, CorsairLedId.Keypad0 }, + { LedId.Keyboard_NumPeriodAndDelete, CorsairLedId.KeypadPeriodAndDelete }, + { LedId.Keyboard_Programmable1, CorsairLedId.G1 }, + { LedId.Keyboard_Programmable2, CorsairLedId.G2 }, + { LedId.Keyboard_Programmable3, CorsairLedId.G3 }, + { LedId.Keyboard_Programmable4, CorsairLedId.G4 }, + { LedId.Keyboard_Programmable5, CorsairLedId.G5 }, + { LedId.Keyboard_Programmable6, CorsairLedId.G6 }, + { LedId.Keyboard_Programmable7, CorsairLedId.G7 }, + { LedId.Keyboard_Programmable8, CorsairLedId.G8 }, + { LedId.Keyboard_Programmable9, CorsairLedId.G9 }, + { LedId.Keyboard_Programmable10, CorsairLedId.G10 }, + { LedId.Keyboard_MediaVolumeUp, CorsairLedId.VolumeUp }, + { LedId.Keyboard_MediaVolumeDown, CorsairLedId.VolumeDown }, + { LedId.Keyboard_MacroRecording, CorsairLedId.MR }, + { LedId.Keyboard_Macro1, CorsairLedId.M1 }, + { LedId.Keyboard_Macro2, CorsairLedId.M2 }, + { LedId.Keyboard_Macro3, CorsairLedId.M3 }, + { LedId.Keyboard_Programmable11, CorsairLedId.G11 }, + { LedId.Keyboard_Programmable12, CorsairLedId.G12 }, + { LedId.Keyboard_Programmable13, CorsairLedId.G13 }, + { LedId.Keyboard_Programmable14, CorsairLedId.G14 }, + { LedId.Keyboard_Programmable15, CorsairLedId.G15 }, + { LedId.Keyboard_Programmable16, CorsairLedId.G16 }, + { LedId.Keyboard_Programmable17, CorsairLedId.G17 }, + { LedId.Keyboard_Programmable18, CorsairLedId.G18 }, + { LedId.Keyboard_International5, CorsairLedId.International5 }, + { LedId.Keyboard_International4, CorsairLedId.International4 }, + { LedId.Keyboard_Profile, CorsairLedId.Profile }, + { LedId.Keyboard_LedProgramming, CorsairLedId.LedProgramming }, + { LedId.Keyboard_Function, CorsairLedId.Fn }, + + { LedId.LedStripe1, CorsairLedId.Lightbar1 }, + { LedId.LedStripe2, CorsairLedId.Lightbar2 }, + { LedId.LedStripe3, CorsairLedId.Lightbar3 }, + { LedId.LedStripe4, CorsairLedId.Lightbar4 }, + { LedId.LedStripe5, CorsairLedId.Lightbar5 }, + { LedId.LedStripe6, CorsairLedId.Lightbar6 }, + { LedId.LedStripe7, CorsairLedId.Lightbar7 }, + { LedId.LedStripe8, CorsairLedId.Lightbar8 }, + { LedId.LedStripe9, CorsairLedId.Lightbar9 }, + { LedId.LedStripe10, CorsairLedId.Lightbar10 }, + { LedId.LedStripe11, CorsairLedId.Lightbar11 }, + { LedId.LedStripe12, CorsairLedId.Lightbar12 }, + { LedId.LedStripe13, CorsairLedId.Lightbar13 }, + { LedId.LedStripe14, CorsairLedId.Lightbar14 }, + { LedId.LedStripe15, CorsairLedId.Lightbar15 }, + { LedId.LedStripe16, CorsairLedId.Lightbar16 }, + { LedId.LedStripe17, CorsairLedId.Lightbar17 }, + { LedId.LedStripe18, CorsairLedId.Lightbar18 }, + { LedId.LedStripe19, CorsairLedId.Lightbar19 }, + { LedId.LedStripe20, CorsairLedId.Lightbar20 }, + { LedId.LedStripe21, CorsairLedId.Lightbar21 }, + { LedId.LedStripe22, CorsairLedId.Lightbar22 }, + { LedId.LedStripe23, CorsairLedId.Lightbar23 }, + { LedId.LedStripe24, CorsairLedId.Lightbar24 }, + { LedId.LedStripe25, CorsairLedId.Lightbar25 }, + { LedId.LedStripe26, CorsairLedId.Lightbar26 }, + { LedId.LedStripe27, CorsairLedId.Lightbar27 }, + { LedId.LedStripe28, CorsairLedId.Lightbar28 }, + { LedId.LedStripe29, CorsairLedId.Lightbar29 }, + { LedId.LedStripe30, CorsairLedId.Lightbar30 }, + { LedId.LedStripe31, CorsairLedId.Lightbar31 }, + { LedId.LedStripe32, CorsairLedId.Lightbar32 }, + { LedId.LedStripe33, CorsairLedId.Lightbar33 }, + { LedId.LedStripe34, CorsairLedId.Lightbar34 }, + { LedId.LedStripe35, CorsairLedId.Lightbar35 }, + { LedId.LedStripe36, CorsairLedId.Lightbar36 }, + { LedId.LedStripe37, CorsairLedId.Lightbar37 }, + { LedId.LedStripe38, CorsairLedId.Lightbar38 }, + { LedId.LedStripe39, CorsairLedId.Lightbar39 }, + { LedId.LedStripe40, CorsairLedId.Lightbar40 }, + { LedId.LedStripe41, CorsairLedId.Lightbar41 }, + { LedId.LedStripe42, CorsairLedId.Lightbar42 }, + { LedId.LedStripe43, CorsairLedId.Lightbar43 }, + { LedId.LedStripe44, CorsairLedId.Lightbar44 }, + { LedId.LedStripe45, CorsairLedId.Lightbar45 }, + { LedId.LedStripe46, CorsairLedId.Lightbar46 }, + { LedId.LedStripe47, CorsairLedId.Lightbar47 }, + { LedId.LedStripe48, CorsairLedId.Lightbar48 }, + { LedId.LedStripe49, CorsairLedId.Lightbar49 }, + { LedId.LedStripe50, CorsairLedId.Lightbar50 }, + }; +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/GraphicsCard/CorsairGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/GraphicsCard/CorsairGraphicsCardRGBDevice.cs new file mode 100644 index 00000000..ece723e1 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/GraphicsCard/CorsairGraphicsCardRGBDevice.cs @@ -0,0 +1,27 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a corsair graphics card. +/// +public class CorsairGraphicsCardRGBDevice : CorsairRGBDevice, IGraphicsCard +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the graphics card. + /// The queue used to update this device. + internal CorsairGraphicsCardRGBDevice(CorsairGraphicsCardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, LedMappings.GraphicsCard, updateQueue) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs new file mode 100644 index 00000000..d1b38b65 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/GraphicsCard/CorsairGraphicsCardRGBDeviceInfo.cs @@ -0,0 +1,28 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairGraphicsCardRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The native -struct + internal CorsairGraphicsCardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) + : base(deviceIndex, RGBDeviceType.GraphicsCard, nativeInfo) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Headset/CorsairHeadsetRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Headset/CorsairHeadsetRGBDevice.cs new file mode 100644 index 00000000..1a6adfa0 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Headset/CorsairHeadsetRGBDevice.cs @@ -0,0 +1,27 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a corsair headset. +/// +public class CorsairHeadsetRGBDevice : CorsairRGBDevice, IHeadset +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the headset + /// The queue used to update this device. + internal CorsairHeadsetRGBDevice(CorsairHeadsetRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, LedMappings.Headset, updateQueue) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Headset/CorsairHeadsetRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Headset/CorsairHeadsetRGBDeviceInfo.cs new file mode 100644 index 00000000..090760b1 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Headset/CorsairHeadsetRGBDeviceInfo.cs @@ -0,0 +1,25 @@ +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairHeadsetRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The native -struct + internal CorsairHeadsetRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) + : base(deviceIndex, RGBDeviceType.Headset, nativeInfo) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/HeadsetStand/CorsairHeadsetStandRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/HeadsetStand/CorsairHeadsetStandRGBDevice.cs new file mode 100644 index 00000000..d696cff4 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/HeadsetStand/CorsairHeadsetStandRGBDevice.cs @@ -0,0 +1,27 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a corsair headset stand. +/// +public class CorsairHeadsetStandRGBDevice : CorsairRGBDevice, IHeadsetStand +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the headset stand + /// The queue used to update this device. + internal CorsairHeadsetStandRGBDevice(CorsairHeadsetStandRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, LedMappings.HeadsetStand, updateQueue) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs new file mode 100644 index 00000000..61ab5489 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/HeadsetStand/CorsairHeadsetStandRGBDeviceInfo.cs @@ -0,0 +1,25 @@ +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairHeadsetStandRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The native -struct + internal CorsairHeadsetStandRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) + : base(deviceIndex, RGBDeviceType.HeadsetStand, nativeInfo) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Helper/DictionaryExtension.cs b/RGB.NET.Devices.Corsair_Legacy/Helper/DictionaryExtension.cs new file mode 100644 index 00000000..f33fdeaa --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Helper/DictionaryExtension.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using System.Linq; + +namespace RGB.NET.Devices.CorsairLegacy; + +internal static class DictionaryExtension +{ + public static Dictionary SwapKeyValue(this Dictionary dictionary) + where TKey : notnull + where TValue : notnull + => dictionary.ToDictionary(x => x.Value, x => x.Key); +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs b/RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs new file mode 100644 index 00000000..e153e7a4 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs @@ -0,0 +1,18 @@ +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +internal static class NativeExtensions +{ + internal static Rectangle ToRectangle(this _CorsairLedPosition position) + { + //HACK DarthAffe 08.07.2018: It seems like corsair introduced a bug here - it's always 0. + float width = position.width < 0.5f ? 10 : (float)position.width; + float height = position.height < 0.5f ? 10 : (float)position.height; + float posX = (float)position.left; + float posY = (float)position.top; + + return new Rectangle(posX, posY, width, height); + } +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Keyboard/CorsairKeyboardRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Keyboard/CorsairKeyboardRGBDevice.cs new file mode 100644 index 00000000..5505c803 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Keyboard/CorsairKeyboardRGBDevice.cs @@ -0,0 +1,33 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a corsair keyboard. +/// +public class CorsairKeyboardRGBDevice : CorsairRGBDevice, IKeyboard +{ + #region Properties & Fields + + IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo; + + #endregion + + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the keyboard. + /// The queue used to update this device. + internal CorsairKeyboardRGBDevice(CorsairKeyboardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, LedMappings.Keyboard, updateQueue) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Keyboard/CorsairKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Keyboard/CorsairKeyboardRGBDeviceInfo.cs new file mode 100644 index 00000000..c603b751 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Keyboard/CorsairKeyboardRGBDeviceInfo.cs @@ -0,0 +1,56 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// Represents a generic information for a . +/// +public class CorsairKeyboardRGBDeviceInfo : CorsairRGBDeviceInfo, IKeyboardDeviceInfo +{ + #region Properties & Fields + + /// + public KeyboardLayoutType Layout { get; } + + /// + /// Gets the physical layout of the keyboard. + /// + public CorsairPhysicalKeyboardLayout PhysicalLayout { get; } + + /// + /// Gets the logical layout of the keyboard as set in CUE settings. + /// + public CorsairLogicalKeyboardLayout LogicalLayout { get; } + + #endregion + + #region Constructors + + /// + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The native -struct + internal CorsairKeyboardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) + : base(deviceIndex, RGBDeviceType.Keyboard, nativeInfo) + { + this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout; + this.LogicalLayout = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout; + this.Layout = PhysicalLayout switch + { + CorsairPhysicalKeyboardLayout.US => KeyboardLayoutType.ANSI, + CorsairPhysicalKeyboardLayout.UK => KeyboardLayoutType.ISO, + CorsairPhysicalKeyboardLayout.BR => KeyboardLayoutType.ABNT, + CorsairPhysicalKeyboardLayout.JP => KeyboardLayoutType.JIS, + CorsairPhysicalKeyboardLayout.KR => KeyboardLayoutType.KS, + _ => KeyboardLayoutType.Unknown + }; + } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Mainboard/CorsairMainboardRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Mainboard/CorsairMainboardRGBDevice.cs new file mode 100644 index 00000000..c7f238ef --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Mainboard/CorsairMainboardRGBDevice.cs @@ -0,0 +1,27 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a corsair memory. +/// +public class CorsairMainboardRGBDevice : CorsairRGBDevice, IMainboard +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the memory. + /// The queue used to update this device. + internal CorsairMainboardRGBDevice(CorsairMainboardRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, LedMappings.Mainboard, updateQueue) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Mainboard/CorsairMainboardRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Mainboard/CorsairMainboardRGBDeviceInfo.cs new file mode 100644 index 00000000..56fbb903 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Mainboard/CorsairMainboardRGBDeviceInfo.cs @@ -0,0 +1,28 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairMainboardRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The native -struct + internal CorsairMainboardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) + : base(deviceIndex, RGBDeviceType.Mainboard, nativeInfo) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Memory/CorsairMemoryRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Memory/CorsairMemoryRGBDevice.cs new file mode 100644 index 00000000..053ee818 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Memory/CorsairMemoryRGBDevice.cs @@ -0,0 +1,27 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a corsair memory. +/// +public class CorsairMemoryRGBDevice : CorsairRGBDevice, IDRAM +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the memory. + /// The queue used to update this device. + internal CorsairMemoryRGBDevice(CorsairMemoryRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, LedMappings.Memory, updateQueue) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Memory/CorsairMemoryRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Memory/CorsairMemoryRGBDeviceInfo.cs new file mode 100644 index 00000000..9934135e --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Memory/CorsairMemoryRGBDeviceInfo.cs @@ -0,0 +1,28 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairMemoryRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The native -struct + internal CorsairMemoryRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) + : base(deviceIndex, RGBDeviceType.DRAM, nativeInfo) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Mouse/CorsairMouseRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Mouse/CorsairMouseRGBDevice.cs new file mode 100644 index 00000000..b9a84bf4 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Mouse/CorsairMouseRGBDevice.cs @@ -0,0 +1,27 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a corsair mouse. +/// +public class CorsairMouseRGBDevice : CorsairRGBDevice, IMouse +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the mouse + /// The queue used to update this device. + internal CorsairMouseRGBDevice(CorsairMouseRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, LedMappings.Mouse, updateQueue) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Mouse/CorsairMouseRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Mouse/CorsairMouseRGBDeviceInfo.cs new file mode 100644 index 00000000..89de8243 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Mouse/CorsairMouseRGBDeviceInfo.cs @@ -0,0 +1,36 @@ +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairMouseRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Properties & Fields + + /// + /// Gets the physical layout of the mouse. + /// + public CorsairPhysicalMouseLayout PhysicalLayout { get; } + + #endregion + + #region Constructors + + /// + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The native -struct + internal CorsairMouseRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) + : base(deviceIndex, RGBDeviceType.Mouse, nativeInfo) + { + this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout; + } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Mousepad/CorsairMousepadRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Mousepad/CorsairMousepadRGBDevice.cs new file mode 100644 index 00000000..5d78d5d9 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Mousepad/CorsairMousepadRGBDevice.cs @@ -0,0 +1,27 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a corsair mousepad. +/// +public class CorsairMousepadRGBDevice : CorsairRGBDevice, IMousepad +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the mousepad + /// The queue used to update this device. + internal CorsairMousepadRGBDevice(CorsairMousepadRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, LedMappings.Mousepad, updateQueue) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Mousepad/CorsairMousepadRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Mousepad/CorsairMousepadRGBDeviceInfo.cs new file mode 100644 index 00000000..40f42b54 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Mousepad/CorsairMousepadRGBDeviceInfo.cs @@ -0,0 +1,25 @@ +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairMousepadRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + /// + /// Internal constructor of managed . + /// + /// The index if the . + /// The native -struct + internal CorsairMousepadRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) + : base(deviceIndex, RGBDeviceType.Mousepad, nativeInfo) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs new file mode 100644 index 00000000..718f446d --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs @@ -0,0 +1,193 @@ +#pragma warning disable IDE1006 // Naming Styles +// ReSharper disable UnusedMethodReturnValue.Global +// ReSharper disable UnusedMember.Global + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy.Native; + +// ReSharper disable once InconsistentNaming +internal static class _CUESDK +{ + #region Libary Management + + private static IntPtr _handle = IntPtr.Zero; + + /// + /// Reloads the SDK. + /// + internal static void Reload() + { + UnloadCUESDK(); + LoadCUESDK(); + } + + private static void LoadCUESDK() + { + if (_handle != IntPtr.Zero) return; + + List possiblePathList = GetPossibleLibraryPaths().ToList(); + + string? dllPath = possiblePathList.FirstOrDefault(File.Exists); + if (dllPath == null) throw new RGBDeviceException($"Can't find the CUE-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'"); + + if (!NativeLibrary.TryLoad(dllPath, out _handle)) +#if NET6_0 + throw new RGBDeviceException($"Corsair LoadLibrary failed with error code {Marshal.GetLastPInvokeError()}"); +#else + throw new RGBDeviceException($"Corsair LoadLibrary failed with error code {Marshal.GetLastWin32Error()}"); +#endif + + if (!NativeLibrary.TryGetExport(_handle, "CorsairSetLedsColorsBufferByDeviceIndex", out _corsairSetLedsColorsBufferByDeviceIndexPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairSetLedsColorsBufferByDeviceIndex'"); + if (!NativeLibrary.TryGetExport(_handle, "CorsairSetLedsColorsFlushBuffer", out _corsairSetLedsColorsFlushBufferPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairSetLedsColorsFlushBuffer'"); + if (!NativeLibrary.TryGetExport(_handle, "CorsairGetLedsColorsByDeviceIndex", out _corsairGetLedsColorsByDeviceIndexPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetLedsColorsByDeviceIndex'"); + if (!NativeLibrary.TryGetExport(_handle, "CorsairSetLayerPriority", out _corsairSetLayerPriorityPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairSetLayerPriority'"); + if (!NativeLibrary.TryGetExport(_handle, "CorsairGetDeviceCount", out _corsairGetDeviceCountPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetDeviceCount'"); + if (!NativeLibrary.TryGetExport(_handle, "CorsairGetDeviceInfo", out _corsairGetDeviceInfoPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetDeviceInfo'"); + if (!NativeLibrary.TryGetExport(_handle, "CorsairGetLedIdForKeyName", out _corsairGetLedIdForKeyNamePointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetLedIdForKeyName'"); + if (!NativeLibrary.TryGetExport(_handle, "CorsairGetLedPositionsByDeviceIndex", out _corsairGetLedPositionsByDeviceIndexPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetLedPositionsByDeviceIndex'"); + if (!NativeLibrary.TryGetExport(_handle, "CorsairRequestControl", out _corsairRequestControlPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairRequestControl'"); + if (!NativeLibrary.TryGetExport(_handle, "CorsairReleaseControl", out _corsairReleaseControlPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairReleaseControl'"); + if (!NativeLibrary.TryGetExport(_handle, "CorsairPerformProtocolHandshake", out _corsairPerformProtocolHandshakePointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairPerformProtocolHandshake'"); + if (!NativeLibrary.TryGetExport(_handle, "CorsairGetLastError", out _corsairGetLastErrorPointer)) throw new RGBDeviceException("Failed to load Corsair function 'CorsairGetLastError'"); + } + + private static IEnumerable GetPossibleLibraryPaths() + { + IEnumerable possibleLibraryPaths; + + if (OperatingSystem.IsWindows()) + possibleLibraryPaths = Environment.Is64BitProcess ? CorsairLegacyDeviceProvider.PossibleX64NativePaths : CorsairLegacyDeviceProvider.PossibleX86NativePaths; + else + possibleLibraryPaths = Enumerable.Empty(); + + return possibleLibraryPaths.Select(Environment.ExpandEnvironmentVariables); + } + + internal static void UnloadCUESDK() + { + if (_handle == IntPtr.Zero) return; + + _corsairSetLedsColorsBufferByDeviceIndexPointer = IntPtr.Zero; + _corsairSetLedsColorsFlushBufferPointer = IntPtr.Zero; + _corsairGetLedsColorsByDeviceIndexPointer = IntPtr.Zero; + _corsairSetLayerPriorityPointer = IntPtr.Zero; + _corsairGetDeviceCountPointer = IntPtr.Zero; + _corsairGetDeviceInfoPointer = IntPtr.Zero; + _corsairGetLedIdForKeyNamePointer = IntPtr.Zero; + _corsairGetLedPositionsByDeviceIndexPointer = IntPtr.Zero; + _corsairRequestControlPointer = IntPtr.Zero; + _corsairReleaseControlPointer = IntPtr.Zero; + _corsairPerformProtocolHandshakePointer = IntPtr.Zero; + _corsairGetLastErrorPointer = IntPtr.Zero; + + NativeLibrary.Free(_handle); + _handle = IntPtr.Zero; + } + + #endregion + + #region SDK-METHODS + + #region Pointers + + private static IntPtr _corsairSetLedsColorsBufferByDeviceIndexPointer; + private static IntPtr _corsairSetLedsColorsFlushBufferPointer; + private static IntPtr _corsairGetLedsColorsByDeviceIndexPointer; + private static IntPtr _corsairSetLayerPriorityPointer; + private static IntPtr _corsairGetDeviceCountPointer; + private static IntPtr _corsairGetDeviceInfoPointer; + private static IntPtr _corsairGetLedIdForKeyNamePointer; + private static IntPtr _corsairGetLedPositionsByDeviceIndexPointer; + private static IntPtr _corsairRequestControlPointer; + private static IntPtr _corsairReleaseControlPointer; + private static IntPtr _corsairPerformProtocolHandshakePointer; + private static IntPtr _corsairGetLastErrorPointer; + + #endregion + + /// + /// CUE-SDK: set specified LEDs to some colors. + /// This function set LEDs colors in the buffer which is written to the devices via CorsairSetLedsColorsFlushBuffer or CorsairSetLedsColorsFlushBufferAsync. + /// Typical usecase is next: CorsairSetLedsColorsFlushBuffer or CorsairSetLedsColorsFlushBufferAsync is called to write LEDs colors to the device + /// and follows after one or more calls of CorsairSetLedsColorsBufferByDeviceIndex to set the LEDs buffer. + /// This function does not take logical layout into account. + /// + internal static unsafe bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairSetLedsColorsBufferByDeviceIndexPointer))(deviceIndex, size, ledsColors); + + /// + /// CUE-SDK: writes to the devices LEDs colors buffer which is previously filled by the CorsairSetLedsColorsBufferByDeviceIndex function. + /// This function executes synchronously, if you are concerned about delays consider using CorsairSetLedsColorsFlushBufferAsync + /// + internal static unsafe bool CorsairSetLedsColorsFlushBuffer() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairSetLedsColorsFlushBufferPointer))(); + + /// + /// CUE-SDK: get current color for the list of requested LEDs. + /// The color should represent the actual state of the hardware LED, which could be a combination of SDK and/or CUE input. + /// This function works for keyboard, mouse, mousemat, headset, headset stand and DIY-devices. + /// + internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedsColorsByDeviceIndexPointer))(deviceIndex, size, ledsColors); + + /// + /// CUE-SDK: set layer priority for this shared client. + /// By default CUE has priority of 127 and all shared clients have priority of 128 if they don’t call this function. + /// Layers with higher priority value are shown on top of layers with lower priority. + /// + internal static unsafe bool CorsairSetLayerPriority(int priority) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairSetLayerPriorityPointer))(priority); + + /// + /// CUE-SDK: returns number of connected Corsair devices that support lighting control. + /// + internal static unsafe int CorsairGetDeviceCount() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetDeviceCountPointer))(); + + /// + /// CUE-SDK: returns information about device at provided index. + /// + internal static unsafe IntPtr CorsairGetDeviceInfo(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetDeviceInfoPointer))(deviceIndex); + + /// + /// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions. + /// + internal static unsafe IntPtr CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedPositionsByDeviceIndexPointer))(deviceIndex); + + /// + /// CUE-SDK: retrieves led id for key name taking logical layout into account. + /// + internal static unsafe CorsairLedId CorsairGetLedIdForKeyName(char keyName) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedIdForKeyNamePointer))(keyName); + + /// + /// CUE-SDK: requestes control using specified access mode. + /// By default client has shared control over lighting so there is no need to call CorsairRequestControl unless client requires exclusive control. + /// + internal static unsafe bool CorsairRequestControl(CorsairAccessMode accessMode) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairRequestControlPointer))(accessMode); + + /// + /// CUE-SDK: releases previously requested control for specified access mode. + /// + internal static unsafe bool CorsairReleaseControl(CorsairAccessMode accessMode) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairReleaseControlPointer))(accessMode); + + /// + /// CUE-SDK: checks file and protocol version of CUE to understand which of SDK functions can be used with this version of CUE. + /// + internal static unsafe _CorsairProtocolDetails CorsairPerformProtocolHandshake() => ((delegate* unmanaged[Cdecl]<_CorsairProtocolDetails>)ThrowIfZero(_corsairPerformProtocolHandshakePointer))(); + + /// + /// CUE-SDK: returns last error that occured while using any of Corsair* functions. + /// + internal static unsafe CorsairError CorsairGetLastError() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLastErrorPointer))(); + + private static IntPtr ThrowIfZero(IntPtr ptr) + { + if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Corsair-SDK is not initialized."); + return ptr; + } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelDeviceInfo.cs new file mode 100644 index 00000000..466e99d7 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelDeviceInfo.cs @@ -0,0 +1,27 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned +#pragma warning disable IDE1006 // Naming Styles + +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.CorsairLegacy.Native; + +// ReSharper disable once InconsistentNaming +/// +/// CUE-SDK: contains information about separate LED-device connected to the channel controlled by the DIY-device. +/// +[StructLayout(LayoutKind.Sequential)] + +internal class _CorsairChannelDeviceInfo +{ + /// + /// CUE-SDK: type of the LED-device + /// + internal CorsairChannelDeviceType type; + + /// + /// CUE-SDK: number of LEDs controlled by LED-device. + /// + internal int deviceLedCount; +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs new file mode 100644 index 00000000..c30bfe6a --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs @@ -0,0 +1,33 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned +#pragma warning disable IDE1006 // Naming Styles + +using System; +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.CorsairLegacy.Native; + +// ReSharper disable once InconsistentNaming +/// +/// CUE-SDK: contains information about separate channel of the DIY-device. +/// +[StructLayout(LayoutKind.Sequential)] +internal class _CorsairChannelInfo +{ + /// + /// CUE-SDK: total number of LEDs connected to the channel; + /// + internal int totalLedsCount; + + /// + /// CUE-SDK: number of LED-devices (fans, strips, etc.) connected to the channel which is controlled by the DIY device + /// + internal int devicesCount; + + /// + /// CUE-SDK: array containing information about each separate LED-device connected to the channel controlled by the DIY device. + /// Index of the LED-device in array is same as the index of the LED-device connected to the DIY-device. + /// + internal IntPtr devices; +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs new file mode 100644 index 00000000..61900b92 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs @@ -0,0 +1,28 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned +#pragma warning disable IDE1006 // Naming Styles + +using System; +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.CorsairLegacy.Native; + +// ReSharper disable once InconsistentNaming +/// +/// CUE-SDK: contains information about channels of the DIY-devices. +/// +[StructLayout(LayoutKind.Sequential)] +internal class _CorsairChannelsInfo +{ + /// + /// CUE-SDK: number of channels controlled by the device + /// + internal int channelsCount; + + /// + /// CUE-SDK: array containing information about each separate channel of the DIY-device. + /// Index of the channel in the array is same as index of the channel on the DIY-device. + /// + internal IntPtr channels; +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs new file mode 100644 index 00000000..af3c03e7 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs @@ -0,0 +1,58 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned +#pragma warning disable IDE1006 // Naming Styles + +using System; +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.CorsairLegacy.Native; + +// ReSharper disable once InconsistentNaming +/// +/// CUE-SDK: contains information about device +/// +[StructLayout(LayoutKind.Sequential)] +internal class _CorsairDeviceInfo +{ + /// + /// CUE-SDK: enum describing device type + /// + internal CorsairDeviceType type; + + /// + /// CUE-SDK: null - terminated device model(like “K95RGB”) + /// + internal IntPtr model; + + /// + /// CUE-SDK: enum describing physical layout of the keyboard or mouse + /// + internal int physicalLayout; + + /// + /// CUE-SDK: enum describing logical layout of the keyboard as set in CUE settings + /// + internal int logicalLayout; + + /// + /// CUE-SDK: mask that describes device capabilities, formed as logical “or” of CorsairDeviceCaps enum values + /// + internal int capsMask; + + /// + /// CUE-SDK: number of controllable LEDs on the device + /// + internal int ledsCount; + + /// + /// CUE-SDK: structure that describes channels of the DIY-devices + /// + internal _CorsairChannelsInfo? channels; + + /// + /// CUE-SDK: null-terminated string that contains unique device identifier that uniquely identifies device at least within session + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] + internal string? deviceId; +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedColor.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedColor.cs new file mode 100644 index 00000000..b170918c --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedColor.cs @@ -0,0 +1,37 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned +#pragma warning disable IDE1006 // Naming Styles +// ReSharper disable NotAccessedField.Global + +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.CorsairLegacy.Native; + +// ReSharper disable once InconsistentNaming +/// +/// CUE-SDK: contains information about led and its color +/// +[StructLayout(LayoutKind.Sequential)] +internal class _CorsairLedColor +{ + /// + /// CUE-SDK: identifier of LED to set + /// + internal int ledId; + + /// + /// CUE-SDK: red brightness[0..255] + /// + internal int r; + + /// + /// CUE-SDK: green brightness[0..255] + /// + internal int g; + + /// + /// CUE-SDK: blue brightness[0..255] + /// + internal int b; +}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPosition.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPosition.cs new file mode 100644 index 00000000..baa959f1 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPosition.cs @@ -0,0 +1,42 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned +#pragma warning disable IDE1006 // Naming Styles + +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.CorsairLegacy.Native; + +// ReSharper disable once InconsistentNaming +/// +/// CUE-SDK: contains led id and position of led rectangle.Most of the keys are rectangular. +/// In case if key is not rectangular(like Enter in ISO / UK layout) it returns the smallest rectangle that fully contains the key +/// +[StructLayout(LayoutKind.Sequential)] +internal class _CorsairLedPosition +{ + /// + /// CUE-SDK: identifier of led + /// + internal CorsairLedId LedId; + + /// + /// CUE-SDK: values in mm + /// + internal double top; + + /// + /// CUE-SDK: values in mm + /// + internal double left; + + /// + /// CUE-SDK: values in mm + /// + internal double height; + + /// + /// CUE-SDK: values in mm + /// + internal double width; +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs new file mode 100644 index 00000000..db3d41d6 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs @@ -0,0 +1,26 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned + +using System; +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.CorsairLegacy.Native; + +// ReSharper disable once InconsistentNaming +/// +/// CUE-SDK: contains number of leds and arrays with their positions +/// +[StructLayout(LayoutKind.Sequential)] +internal class _CorsairLedPositions +{ + /// + /// CUE-SDK: integer value.Number of elements in following array + /// + internal int numberOfLed; + + /// + /// CUE-SDK: array of led positions + /// + internal IntPtr pLedPosition; +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs new file mode 100644 index 00000000..23a54777 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs @@ -0,0 +1,43 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned + +using System; +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.CorsairLegacy.Native; + +// ReSharper disable once InconsistentNaming +/// +/// CUE-SDK: contains information about SDK and CUE versions +/// +[StructLayout(LayoutKind.Sequential)] +internal struct _CorsairProtocolDetails +{ + /// + /// CUE-SDK: null - terminated string containing version of SDK(like “1.0.0.1”). Always contains valid value even if there was no CUE found + /// + internal IntPtr sdkVersion; + + /// + /// CUE-SDK: null - terminated string containing version of CUE(like “1.0.0.1”) or NULL if CUE was not found. + /// + internal IntPtr serverVersion; + + /// + /// CUE-SDK: integer number that specifies version of protocol that is implemented by current SDK. + /// Numbering starts from 1. Always contains valid value even if there was no CUE found + /// + internal int sdkProtocolVersion; + + /// + /// CUE-SDK: integer number that specifies version of protocol that is implemented by CUE. + /// Numbering starts from 1. If CUE was not found then this value will be 0 + /// + internal int serverProtocolVersion; + + /// + /// CUE-SDK: boolean value that specifies if there were breaking changes between version of protocol implemented by server and client + /// + internal byte breakingChanges; +}; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/README.md b/RGB.NET.Devices.Corsair_Legacy/README.md new file mode 100644 index 00000000..4448ae16 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/README.md @@ -0,0 +1,24 @@ +[RGB.NET](https://github.com/DarthAffe/RGB.NET) Device-Provider-Package for Corsair-Devices. + +## Usage +This provider follows the default pattern and does not require additional setup. + +```csharp +surface.Load(CorsairDeviceProvider.Instance); +``` + +# Required SDK +This providers requires native SDK-dlls. (version < 4.x) +You can get them directly from Corsair at [https://github.com/CorsairOfficial/cue-sdk/releases](https://github.com/CorsairOfficial/cue-sdk/releases) + +Since the SDK-dlls are native it's important to use the correct architecture you're building your application for. (If in doubt you can always include both.) + +### x64 +`redist\x64\CUESDK.x64_2019.dll` from the SDK-zip needs to be distributed as `\x64\CUESDK.x64_2019.dll` (or simply named `CUESDK.dll`) + +You can use other, custom paths by adding them to `CorsairDeviceProvider.PossibleX64NativePaths`. + +### x86 +`redist\i386\CUESDK_2019.dll` from the SDK-zip needs to be distributed as `\x86\CUESDK_2019.dll` (or simply named `CUESDK.dll`) + +You can use other, custom paths by adding them to `CorsairDeviceProvider.PossibleX86NativePaths`. diff --git a/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj b/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj new file mode 100644 index 00000000..dff737c2 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj @@ -0,0 +1,63 @@ + + + net7.0;net6.0 + latest + enable + + Darth Affe + Wyrez + en-US + en-US + RGB.NET.Devices.CorsairLegacy + RGB.NET.Devices.CorsairLegacy + RGB.NET.Devices.CorsairLegacy + RGB.NET.Devices.CorsairLegacy + RGB.NET.Devices.CorsairLegacy + Corsair-Device-Implementations of RGB.NET using the old SDK + Corsair-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals + Copyright © Darth Affe 2023 + Copyright © Darth Affe 2023 + icon.png + README.md + https://github.com/DarthAffe/RGB.NET + LGPL-2.1-only + Github + https://github.com/DarthAffe/RGB.NET + True + + + + 0.0.1 + 0.0.1 + 0.0.1 + + ..\bin\ + true + True + True + portable + snupkg + true + + + + TRACE;DEBUG + true + false + + + + true + $(NoWarn);CS1591;CS1572;CS1573 + RELEASE + + + + + + + + + + + \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj.DotSettings b/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj.DotSettings new file mode 100644 index 00000000..eeca9716 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj.DotSettings @@ -0,0 +1,22 @@ + + True + True + True + True + True + True + True + True + False + True + True + True + True + True + True + True + True + True + True + True + \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Touchbar/CorsairTouchbarRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Touchbar/CorsairTouchbarRGBDevice.cs new file mode 100644 index 00000000..3b39611d --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Touchbar/CorsairTouchbarRGBDevice.cs @@ -0,0 +1,27 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a corsair touchbar. +/// +public class CorsairTouchbarRGBDevice : CorsairRGBDevice, IDRAM +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the touchbar. + /// The queue used to update this device. + internal CorsairTouchbarRGBDevice(CorsairTouchbarRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, LedMappings.Keyboard, updateQueue) //TODO DarthAffe 17.07.2022: Find someone with such a device and check which LedIds are actually used + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Touchbar/CorsairTouchbarRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Touchbar/CorsairTouchbarRGBDeviceInfo.cs new file mode 100644 index 00000000..575294e7 --- /dev/null +++ b/RGB.NET.Devices.Corsair_Legacy/Touchbar/CorsairTouchbarRGBDeviceInfo.cs @@ -0,0 +1,28 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using RGB.NET.Devices.CorsairLegacy.Native; + +namespace RGB.NET.Devices.CorsairLegacy; + +/// +/// +/// Represents a generic information for a . +/// +public class CorsairTouchbarRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The native -struct + internal CorsairTouchbarRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) + : base(deviceIndex, RGBDeviceType.Keypad, nativeInfo) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.sln b/RGB.NET.sln index afbcb679..25406696 100644 --- a/RGB.NET.sln +++ b/RGB.NET.sln @@ -47,6 +47,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RGB.NET.Presets.Tests", "Te EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RGB.NET.Devices.OpenRGB", "RGB.NET.Devices.OpenRGB\RGB.NET.Devices.OpenRGB.csproj", "{F29A96E5-CDD0-469F-A871-A35A7519BC49}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RGB.NET.Devices.Corsair_Legacy", "..\..\..\..\DarthAffe\Source\Repos\RGB.NET\RGB.NET.Devices.Corsair_Legacy\RGB.NET.Devices.Corsair_Legacy.csproj", "{66AF690C-27A1-4097-AC53-57C0ED89E286}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -133,6 +135,10 @@ Global {F29A96E5-CDD0-469F-A871-A35A7519BC49}.Debug|Any CPU.Build.0 = Debug|Any CPU {F29A96E5-CDD0-469F-A871-A35A7519BC49}.Release|Any CPU.ActiveCfg = Release|Any CPU {F29A96E5-CDD0-469F-A871-A35A7519BC49}.Release|Any CPU.Build.0 = Release|Any CPU + {66AF690C-27A1-4097-AC53-57C0ED89E286}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66AF690C-27A1-4097-AC53-57C0ED89E286}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66AF690C-27A1-4097-AC53-57C0ED89E286}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66AF690C-27A1-4097-AC53-57C0ED89E286}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -154,6 +160,7 @@ Global {7FC5C7A8-7B27-46E7-A8E8-DB80568F49C5} = {D13032C6-432E-4F43-8A32-071133C22B16} {EDBA49D6-AE96-4E96-9E6A-30154D93BD5F} = {92D7C263-D4C9-4D26-93E2-93C1F9C2CD16} {F29A96E5-CDD0-469F-A871-A35A7519BC49} = {D13032C6-432E-4F43-8A32-071133C22B16} + {66AF690C-27A1-4097-AC53-57C0ED89E286} = {D13032C6-432E-4F43-8A32-071133C22B16} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7F222AD4-1F9E-4AAB-9D69-D62372D4C1BA} From 8faedd1e26f3bd86a096d0c4f9eff3865ec46aab Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 24 Jul 2023 00:36:32 +0200 Subject: [PATCH 70/96] Fixed error in solution --- RGB.NET.sln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.sln b/RGB.NET.sln index 25406696..257bf652 100644 --- a/RGB.NET.sln +++ b/RGB.NET.sln @@ -47,7 +47,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RGB.NET.Presets.Tests", "Te EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RGB.NET.Devices.OpenRGB", "RGB.NET.Devices.OpenRGB\RGB.NET.Devices.OpenRGB.csproj", "{F29A96E5-CDD0-469F-A871-A35A7519BC49}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RGB.NET.Devices.Corsair_Legacy", "..\..\..\..\DarthAffe\Source\Repos\RGB.NET\RGB.NET.Devices.Corsair_Legacy\RGB.NET.Devices.Corsair_Legacy.csproj", "{66AF690C-27A1-4097-AC53-57C0ED89E286}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RGB.NET.Devices.Corsair_Legacy", "RGB.NET.Devices.Corsair_Legacy\RGB.NET.Devices.Corsair_Legacy.csproj", "{66AF690C-27A1-4097-AC53-57C0ED89E286}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From 5483a7581d2e1616aa6dd5f080755e85785fcf7b Mon Sep 17 00:00:00 2001 From: DELUUXE Date: Mon, 24 Jul 2023 22:08:39 +0200 Subject: [PATCH 71/96] Added custom led mapping for Razer Blade keyboards --- RGB.NET.Devices.Razer/Generic/LedMappings.cs | 131 +++++++++++++++++++ RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 2 +- 2 files changed, 132 insertions(+), 1 deletion(-) diff --git a/RGB.NET.Devices.Razer/Generic/LedMappings.cs b/RGB.NET.Devices.Razer/Generic/LedMappings.cs index c0e8b3a4..373aae71 100644 --- a/RGB.NET.Devices.Razer/Generic/LedMappings.cs +++ b/RGB.NET.Devices.Razer/Generic/LedMappings.cs @@ -160,6 +160,137 @@ public static class LedMappings //Row 7 is also empty }; + + /// + /// Gets the mapping for Blade keyboards. + /// + public static LedMapping Blade { get; } = new() + { + //Row 0 is empty + + #region Row 1 + + [LedId.Keyboard_Escape] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 2, + [LedId.Keyboard_F1] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 3, + [LedId.Keyboard_F2] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 4, + [LedId.Keyboard_F3] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 5, + [LedId.Keyboard_F4] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 6, + [LedId.Keyboard_F5] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 7, + [LedId.Keyboard_F6] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 8, + [LedId.Keyboard_F7] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 9, + [LedId.Keyboard_F8] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 10, + [LedId.Keyboard_F9] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 11, + [LedId.Keyboard_F10] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 12, + [LedId.Keyboard_F11] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 13, + [LedId.Keyboard_F12] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 14, + [LedId.Keyboard_PrintScreen] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 15, + [LedId.Keyboard_ScrollLock] = (_Defines.KEYBOARD_MAX_COLUMN * 1) + 16, + + #endregion + + #region Row 2 + + [LedId.Keyboard_GraveAccentAndTilde] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 2, + [LedId.Keyboard_1] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 3, + [LedId.Keyboard_2] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 4, + [LedId.Keyboard_3] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 5, + [LedId.Keyboard_4] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 6, + [LedId.Keyboard_5] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 7, + [LedId.Keyboard_6] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 8, + [LedId.Keyboard_7] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 9, + [LedId.Keyboard_8] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 10, + [LedId.Keyboard_9] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 11, + [LedId.Keyboard_0] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 12, + [LedId.Keyboard_MinusAndUnderscore] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 13, + [LedId.Keyboard_EqualsAndPlus] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 14, + [LedId.Keyboard_Backspace] = (_Defines.KEYBOARD_MAX_COLUMN * 2) + 16, + + #endregion + + #region Row 3 + + [LedId.Keyboard_Tab] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 2, + [LedId.Keyboard_Q] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 3, + [LedId.Keyboard_W] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 4, + [LedId.Keyboard_E] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 5, + [LedId.Keyboard_R] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 6, + [LedId.Keyboard_T] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 7, + [LedId.Keyboard_Y] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 8, + [LedId.Keyboard_U] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 9, + [LedId.Keyboard_I] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 10, + [LedId.Keyboard_O] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 11, + [LedId.Keyboard_P] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 12, + [LedId.Keyboard_BracketLeft] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 13, + [LedId.Keyboard_BracketRight] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 14, + [LedId.Keyboard_Backslash] = (_Defines.KEYBOARD_MAX_COLUMN * 3) + 16, + + #endregion + + #region Row 4 + + [LedId.Keyboard_CapsLock] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 2, + [LedId.Keyboard_A] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 3, + [LedId.Keyboard_S] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 4, + [LedId.Keyboard_D] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 5, + [LedId.Keyboard_F] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 6, + [LedId.Keyboard_G] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 7, + [LedId.Keyboard_H] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 8, + [LedId.Keyboard_J] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 9, + [LedId.Keyboard_K] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 10, + [LedId.Keyboard_L] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 11, + [LedId.Keyboard_SemicolonAndColon] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 12, + [LedId.Keyboard_ApostropheAndDoubleQuote] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 13, + [LedId.Keyboard_NonUsTilde] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 14, + [LedId.Keyboard_Enter] = (_Defines.KEYBOARD_MAX_COLUMN * 4) + 16, + + #endregion + + #region Row 5 + + [LedId.Keyboard_LeftShift] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 2, + [LedId.Keyboard_NonUsBackslash] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 3, + [LedId.Keyboard_Z] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 4, + [LedId.Keyboard_X] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 5, + [LedId.Keyboard_C] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 6, + [LedId.Keyboard_V] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 7, + [LedId.Keyboard_B] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 8, + [LedId.Keyboard_N] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 9, + [LedId.Keyboard_M] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 10, + [LedId.Keyboard_CommaAndLessThan] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 11, + [LedId.Keyboard_PeriodAndBiggerThan] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 12, + [LedId.Keyboard_SlashAndQuestionMark] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 13, + [LedId.Keyboard_RightShift] = (_Defines.KEYBOARD_MAX_COLUMN * 5) + 16, + + #endregion + + #region Row 6 + + [LedId.Keyboard_LeftCtrl] = (_Defines.KEYBOARD_MAX_COLUMN * 6) + 2, + // left gui lights left fn key + [LedId.Keyboard_LeftGui] = (_Defines.KEYBOARD_MAX_COLUMN * 6) + 3, + // left alt lights left gui key + [LedId.Keyboard_LeftAlt] = (_Defines.KEYBOARD_MAX_COLUMN * 6) + 4, + // space lights left alt key + [LedId.Keyboard_Space] = (_Defines.KEYBOARD_MAX_COLUMN * 6) + 6, + // see comment bellow + [LedId.Keyboard_RightAlt] = (_Defines.KEYBOARD_MAX_COLUMN * 6) + 10, + // right gui lights right fn key (this one (11) seems to light both right alt and right fn, but 8, 9 and 10 don't light anything) + [LedId.Keyboard_RightGui] = (_Defines.KEYBOARD_MAX_COLUMN * 6) + 11, + // application key lights right control to make room for up/down keys stacked in 1 key spot + [LedId.Keyboard_Application] = (_Defines.KEYBOARD_MAX_COLUMN * 6) + 12, + // right ctrl lights left arrow key + [LedId.Keyboard_RightCtrl] = (_Defines.KEYBOARD_MAX_COLUMN * 6) + 13, + // arrow left lights up arrow key + [LedId.Keyboard_ArrowLeft] = (_Defines.KEYBOARD_MAX_COLUMN * 6) + 14, + // these arrows appear to be flipped + [LedId.Keyboard_ArrowDown] = (_Defines.KEYBOARD_MAX_COLUMN * 6) + 16, + [LedId.Keyboard_ArrowRight] = (_Defines.KEYBOARD_MAX_COLUMN * 6) + 15, + + #endregion + + //Row 7 is also empty + }; + /// /// Gets the mapping for mice. /// diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index f2e6aedc..15f26571 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -127,7 +127,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider { 0x028A, RGBDeviceType.Keyboard, "Blade 15 Advanced (Early 2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028B, RGBDeviceType.Keyboard, "Blade 17 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028C, RGBDeviceType.Keyboard, "Blade 14 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x029F, RGBDeviceType.Keyboard, "Blade 16 (2023)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x029F, RGBDeviceType.Keyboard, "Blade 16 (2023)", LedMappings.Blade, RazerEndpointType.Keyboard }, { 0x028D, RGBDeviceType.Keyboard, "BlackWidow V4", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0290, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless { 0x0292, RGBDeviceType.Keyboard, "DeathStalker V2 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired From 2a2053cc53dd2cd0542f18bcdddf967134b77a76 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 25 Jul 2023 20:11:58 +0200 Subject: [PATCH 72/96] Applied Led-Position-Fix from #331 to Corsair-Legacy-DeviceProvider --- .../Custom/CorsairCustomRGBDevice.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs index 4f5a301c..4e15555e 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedMember.Global using System; +using System.Linq; using System.Runtime.InteropServices; using RGB.NET.Core; using RGB.NET.Devices.CorsairLegacy.Native; @@ -59,6 +60,21 @@ protected override void InitializeLayout() ptr = new IntPtr(ptr.ToInt64() + structSize); } + + if (DeviceInfo.LedOffset > 0) + FixOffsetDeviceLayout(); + } + + /// + /// Fixes the locations for devices split by offset by aligning them to the top left. + /// + protected virtual void FixOffsetDeviceLayout() + { + float minX = this.Min(x => x.Location.X); + float minY = this.Min(x => x.Location.Y); + + foreach (Led led in this) + led.Location = led.Location.Translate(-minX, -minY); } private static LedId GetReferenceLed(RGBDeviceType deviceType) From 2c8bc72dc96150ef016b3ae5a0f6513c3b557684 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 16 Aug 2023 21:47:54 +0200 Subject: [PATCH 73/96] Added missing provider-init-changes to CorsairLegacy --- .../CorsairLegacyDeviceProvider.cs | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs b/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs index 20a1b58c..f82bec28 100644 --- a/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs @@ -18,11 +18,21 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider { #region Properties & Fields + // ReSharper disable once InconsistentNaming + private static readonly object _lock = new(); + private static CorsairLegacyDeviceProvider? _instance; /// /// Gets the singleton instance. /// - public static CorsairLegacyDeviceProvider Instance => _instance ?? new CorsairLegacyDeviceProvider(); + public static CorsairLegacyDeviceProvider Instance + { + get + { + lock (_lock) + return _instance ?? new CorsairLegacyDeviceProvider(); + } + } /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. @@ -56,8 +66,11 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider /// Thrown if this constructor is called even if there is already an instance of this class. public CorsairLegacyDeviceProvider() { - if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairLegacyDeviceProvider)}"); - _instance = this; + lock (_lock) + { + if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairLegacyDeviceProvider)}"); + _instance = this; + } } #endregion @@ -201,12 +214,17 @@ protected override void Reset() } /// - public override void Dispose() + protected override void Dispose(bool disposing) { - base.Dispose(); + lock (_lock) + { + base.Dispose(disposing); - try { _CUESDK.UnloadCUESDK(); } - catch { /* at least we tried */ } + try { _CUESDK.UnloadCUESDK(); } + catch { /* at least we tried */ } + + _instance = null; + } } #endregion From 1f0b1b0774345160c2dce67e53ed33ca5b8616c6 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 17 Aug 2023 23:22:33 +0200 Subject: [PATCH 74/96] Fixed an exception when multiple invalid leds are present in custom corsair devices --- RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs index 4e15555e..c285e5a6 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs @@ -53,6 +53,8 @@ protected override void InitializeLayout() continue; } + if (ledPosition.LedId == CorsairLedId.Invalid) continue; + Mapping.Add(ledId, ledPosition.LedId); Rectangle rectangle = ledPosition.ToRectangle(); From aba0888bd90268015ae2c2905160f5ee16228aea Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 23 Aug 2023 00:50:28 +0200 Subject: [PATCH 75/96] Fixed typo in Core readme --- RGB.NET.Core/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Core/README.md b/RGB.NET.Core/README.md index d31978bc..b07d190f 100644 --- a/RGB.NET.Core/README.md +++ b/RGB.NET.Core/README.md @@ -17,7 +17,7 @@ surface.AlignDevices(); surface.RegisterUpdateTrigger(new TimerUpdateTrigger()); ``` -## Basis Rendering +## Basic Rendering ```csharp // Create a led-group containing all leds on the surface ILedGroup allLeds = new ListLedGroup(surface, surface.Leds); From 5d3a3613e243dc33b11b3625aa74f3ef92dc6c6f Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 23 Aug 2023 00:52:06 +0200 Subject: [PATCH 76/96] Added PID for Razer Black Widow V4 75% --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 8dfadc47..dc892017 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -146,6 +146,7 @@ public static RazerDeviceProvider Instance { 0x0296, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless { 0x0298, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired { 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x02A5, RGBDeviceType.Keyboard, "Razer Bacl Widow V4 75%", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Mice From 3461674e17df9affc05572442b9b58e02720fb58 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 23 Aug 2023 00:53:14 +0200 Subject: [PATCH 77/96] Typo in Keyboard name --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index dc892017..7c135239 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -146,7 +146,7 @@ public static RazerDeviceProvider Instance { 0x0296, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless { 0x0298, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired { 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x02A5, RGBDeviceType.Keyboard, "Razer Bacl Widow V4 75%", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x02A5, RGBDeviceType.Keyboard, "Razer Black Widow V4 75%", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Mice From 9d1188ab33115de79bdf032e83d17caacf46904c Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 23 Aug 2023 00:57:19 +0200 Subject: [PATCH 78/96] Fixed razer naming again --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 7c135239..7a8d50cc 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -146,7 +146,7 @@ public static RazerDeviceProvider Instance { 0x0296, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless { 0x0298, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired { 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard }, - { 0x02A5, RGBDeviceType.Keyboard, "Razer Black Widow V4 75%", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x02A5, RGBDeviceType.Keyboard, "BlackWidow V4 75%", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Mice From c7abac5ecda7d9828780c3588b931c5b4ff96a9e Mon Sep 17 00:00:00 2001 From: Danielle Date: Wed, 23 Aug 2023 14:22:38 +1000 Subject: [PATCH 79/96] Update RazerDeviceProvider.cs Added additional Razer Blackwidow V4 PID. --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 7a8d50cc..5f449e30 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -134,6 +134,7 @@ public static RazerDeviceProvider Instance { 0x0279, RGBDeviceType.Keyboard, "Blade 17 Pro (Mid 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x027A, RGBDeviceType.Keyboard, "Blade 15 Base (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0282, RGBDeviceType.Keyboard, "Huntsman Mini Analog", LedMappings.Keyboard, RazerEndpointType.Keyboard }, + { 0x0287, RGBDeviceType.Keyboard, "BlackWidow V4", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028A, RGBDeviceType.Keyboard, "Blade 15 Advanced (Early 2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028B, RGBDeviceType.Keyboard, "Blade 17 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028C, RGBDeviceType.Keyboard, "Blade 14 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, From 72da2b6bdf14eae4f92c25324838603600d714e8 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 27 Aug 2023 21:40:01 +0200 Subject: [PATCH 80/96] Added LedIds for Indicator-LEDs (like NumLock) --- RGB.NET.Core/Leds/LedId.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/RGB.NET.Core/Leds/LedId.cs b/RGB.NET.Core/Leds/LedId.cs index dff98a5d..18bb0b50 100644 --- a/RGB.NET.Core/Leds/LedId.cs +++ b/RGB.NET.Core/Leds/LedId.cs @@ -372,12 +372,20 @@ public enum LedId Keyboard_Custom127 = 0x0000707F, Keyboard_Custom128 = 0x00007080, + Keyboard_IndicatorNumLock = 0x00008001, + Keyboard_IndicatorCapsLock = 0x00008002, + Keyboard_IndicatorScrollLock = 0x00008003, + Keyboard_IndicatorWinLock = 0x00008004, + Keyboard_IndicatorPower = 0x00008005, + Keyboard_IndicatorMuted = 0x00008006, + Keyboard_IndicatorMacro = 0x00008007, + /*### Mouse ###*/ Mouse1 = 0x00100001, Mouse2 = 0x00100002, Mouse3 = 0x00100003, Mouse4 = 0x00100004, - Mouse5 = 0x00100005, + Mouse5 = 0x00100005, Mouse6 = 0x00100006, Mouse7 = 0x00100007, Mouse8 = 0x00100008, From 5707a247ee8360475beefa16499dd34029341ac9 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 27 Aug 2023 21:41:41 +0200 Subject: [PATCH 81/96] Removed excessive spaces --- RGB.NET.Core/Leds/LedId.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Core/Leds/LedId.cs b/RGB.NET.Core/Leds/LedId.cs index 18bb0b50..43a6a703 100644 --- a/RGB.NET.Core/Leds/LedId.cs +++ b/RGB.NET.Core/Leds/LedId.cs @@ -385,7 +385,7 @@ public enum LedId Mouse2 = 0x00100002, Mouse3 = 0x00100003, Mouse4 = 0x00100004, - Mouse5 = 0x00100005, + Mouse5 = 0x00100005, Mouse6 = 0x00100006, Mouse7 = 0x00100007, Mouse8 = 0x00100008, From c1a4fee18946828c22c01bcb6e34d8906949d9c6 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 4 Sep 2023 11:50:26 +0200 Subject: [PATCH 82/96] Added Razer Kraken Kitty V2 PID --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 5f449e30..8bb176ab 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -244,6 +244,7 @@ public static RazerDeviceProvider Instance { 0x051A, RGBDeviceType.Headset, "Nari Ultimate", LedMappings.Headset, RazerEndpointType.Headset }, { 0x051C, RGBDeviceType.Headset, "Nari", LedMappings.Headset, RazerEndpointType.Headset }, { 0x0527, RGBDeviceType.Headset, "Kraken Ultimate", LedMappings.Headset, RazerEndpointType.Headset }, + { 0x0560, RGBDeviceType.Headset, "Kraken Kitty V2", LedMappings.Headset, RazerEndpointType.Headset }, { 0x0F19, RGBDeviceType.Headset, "Kraken Kitty Edition", LedMappings.Headset, RazerEndpointType.Headset }, // Keypads From 012fdf62a4c9430d273e04fe8f6a6778db34eb83 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Fri, 22 Sep 2023 21:55:53 +0200 Subject: [PATCH 83/96] Added PIDs for Blade 18, Naga V2 Pro (wired?) and Mouse Dock Pro --- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 8bb176ab..9abc8c82 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -146,6 +146,7 @@ public static RazerDeviceProvider Instance { 0x0295, RGBDeviceType.Keyboard, "DeathStalker V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0296, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless { 0x0298, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired + { 0x02A0, RGBDeviceType.Keyboard, "Blade 18", LedMappings.Blade, RazerEndpointType.Keyboard }, { 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x02A5, RGBDeviceType.Keyboard, "BlackWidow V4 75%", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, @@ -223,6 +224,7 @@ public static RazerDeviceProvider Instance { 0x00A1, RGBDeviceType.Mouse, "DeathAdder V2 Lite", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00A5, RGBDeviceType.Mouse, "Viper V2 Pro (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00A6, RGBDeviceType.Mouse, "Viper V2 Pro (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, + { 0x00A7, RGBDeviceType.Mouse, "Naga V2 Pro", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00A8, RGBDeviceType.Mouse, "Naga V2 Pro", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00AA, RGBDeviceType.Mouse, "Basilisk V3 Pro (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00AB, RGBDeviceType.Mouse, "Basilisk V3 Pro (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, @@ -261,6 +263,7 @@ public static RazerDeviceProvider Instance { 0x0F08, RGBDeviceType.HeadsetStand, "Base Station Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, // DarthAffe 16.12.2022: Not tested but based on the V2 I assume this is also a mousepad { 0x0F20, RGBDeviceType.HeadsetStand, "Base Station V2 Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, // DarthAffe 16.12.2022: Not sure why, but it's handled as a mousepad { 0x007E, RGBDeviceType.LedStripe, "Razer Mouse Dock Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, //roxaskeyheart 06.02.2023: Probably handled the same as a mousepad + { 0x00A4, RGBDeviceType.LedStripe, "Mouse Dock Pro", LedMappings.Mousepad, RazerEndpointType.Mousepad }, // DarthAffe 22.09.2023: Most likely also a mousepad? { 0x0517, RGBDeviceType.Speaker, "Nommo Chroma", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0518, RGBDeviceType.Speaker, "Nommo Pro", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F07, RGBDeviceType.Unknown, "Chroma Mug Holder", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, From 736d58c7a305c6060bb6c5a7e784375266e31164 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Tue, 17 Oct 2023 14:20:04 +0100 Subject: [PATCH 84/96] Wooting - Add uwu support --- .../Enum/WootingDeviceType.cs | 47 ++++++++++--------- .../Enum/WootingLayoutType.cs | 1 + .../WootingLedMappings.cs} | 41 +++++++++++++--- .../Generic/WootingRGBDevice.cs | 14 ++++++ .../Helper/EnumExtension.cs | 34 -------------- .../Keyboard/WootingKeyboardRGBDevice.cs | 12 +---- .../Keypad/WootingKeypadRGBDevice.cs | 44 +++++++++++++++++ .../Keypad/WootingKeypadRGBDeviceInfo.cs | 17 +++++++ .../Native/_WootingDeviceInfo.cs | 6 ++- .../WootingDeviceProvider.cs | 8 +++- 10 files changed, 150 insertions(+), 74 deletions(-) rename RGB.NET.Devices.Wooting/{Keyboard/WootingKeyboardLedMappings.cs => Generic/WootingLedMappings.cs} (91%) delete mode 100644 RGB.NET.Devices.Wooting/Helper/EnumExtension.cs create mode 100644 RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs create mode 100644 RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDeviceInfo.cs diff --git a/RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs b/RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs index 513fae59..63ff83a4 100644 --- a/RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs +++ b/RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs @@ -1,24 +1,29 @@ -// ReSharper disable InconsistentNaming - -namespace RGB.NET.Devices.Wooting.Enum; - -/// -/// Represents the type of a wooting device -/// -public enum WootingDeviceType -{ - /// - /// 10 Keyless Keyboard. E.g. Wooting One - /// - KeyboardTKL = 1, - - /// - /// Full Size keyboard. E.g. Wooting Two - /// +// ReSharper disable InconsistentNaming + +namespace RGB.NET.Devices.Wooting.Enum; + +/// +/// Represents the type of a wooting device +/// +public enum WootingDeviceType +{ + /// + /// 10 Keyless Keyboard. E.g. Wooting One + /// + KeyboardTKL = 1, + + /// + /// Full Size keyboard. E.g. Wooting Two + /// Keyboard = 2, - /// - /// Full Size keyboard. E.g. Wooting Two - /// - KeyboardSixtyPercent = 3 + /// + /// 60 percent keyboard, E.g. Wooting 60HE + /// + KeyboardSixtyPercent = 3, + + /// + /// Three key keypad. E.g. Wooting Uwu + /// + Keypad3Keys = 4, } \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Enum/WootingLayoutType.cs b/RGB.NET.Devices.Wooting/Enum/WootingLayoutType.cs index e01a6d14..70c15208 100644 --- a/RGB.NET.Devices.Wooting/Enum/WootingLayoutType.cs +++ b/RGB.NET.Devices.Wooting/Enum/WootingLayoutType.cs @@ -13,6 +13,7 @@ namespace RGB.NET.Devices.Wooting.Enum; /// public enum WootingLayoutType { + Unknown = -1, ANSI = 0, ISO = 1 } \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs similarity index 91% rename from RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs rename to RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs index 0b442375..23746cb7 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs @@ -1,15 +1,15 @@ -// ReSharper disable InconsistentNaming +// ReSharper disable InconsistentNaming +using System.Collections.Generic; using RGB.NET.Core; using RGB.NET.Devices.Wooting.Enum; -using System.Collections.Generic; -namespace RGB.NET.Devices.Wooting.Keyboard; +namespace RGB.NET.Devices.Wooting.Generic; /// /// Contains all the hardware-id mappings for Wooting devices. /// -internal static class WootingKeyboardLedMappings +internal static class WootingLedMappings { #region Properties & Fields @@ -305,6 +305,34 @@ internal static class WootingKeyboardLedMappings { LedId.Keyboard_Function, (5, 13) } }; + private static readonly Dictionary ThreeKeyKeypad = new() + { + //top left - bottom left + [LedId.LedStripe1] = (0, 0), + [LedId.LedStripe2] = (1, 0), + [LedId.LedStripe3] = (3, 0), + + //bottom left - bottom right + [LedId.LedStripe4] = (4, 1), + [LedId.LedStripe5] = (4, 2), + [LedId.LedStripe6] = (4, 4), + [LedId.LedStripe7] = (4, 5), + + //bottom right - top right + [LedId.LedStripe8] = (3, 6), + [LedId.LedStripe9] = (1, 6), + [LedId.LedStripe10] = (0, 6), + + //top right - top left + [LedId.LedStripe11] = (0, 4), + [LedId.LedStripe12] = (0, 2), + + //Analog Keys + [LedId.Keypad1] = (3, 2), + [LedId.Keypad2] = (3, 3), + [LedId.Keypad3] = (3, 4), + }; + /// /// Contains all the hardware-id mappings for Wooting devices. /// @@ -312,8 +340,9 @@ internal static class WootingKeyboardLedMappings { [WootingDeviceType.Keyboard] = Fullsize, [WootingDeviceType.KeyboardTKL] = TKL, - [WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent + [WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent, + [WootingDeviceType.Keypad3Keys] = ThreeKeyKeypad }; #endregion -} \ No newline at end of file +} diff --git a/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs b/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs index 8697eb1c..7bc089ec 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs @@ -1,4 +1,5 @@ using RGB.NET.Core; +using RGB.NET.Devices.Wooting.Native; namespace RGB.NET.Devices.Wooting.Generic; @@ -23,4 +24,17 @@ protected WootingRGBDevice(TDeviceInfo info, IUpdateQueue updateQueue) } #endregion + + + #region Methods + + public override void Dispose() + { + _WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex); + _WootingSDK.Reset(); + + base.Dispose(); + } + + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs b/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs deleted file mode 100644 index 0ec89587..00000000 --- a/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.ComponentModel; -using System.Reflection; - -namespace RGB.NET.Devices.Wooting.Helper; - -/// -/// Offers some extensions and helper-methods for enum related things. -/// -internal static class EnumExtension -{ - /// - /// Gets the value of the . - /// - /// The enum value to get the description from. - /// The value of the or the result of the source. - internal static string GetDescription(this System.Enum source) - => source.GetAttribute()?.Description ?? source.ToString(); - - /// - /// Gets the attribute of type T. - /// - /// The enum value to get the attribute from - /// The generic attribute type - /// The . - private static T? GetAttribute(this System.Enum source) - where T : Attribute - { - FieldInfo? fi = source.GetType().GetField(source.ToString()); - if (fi == null) return null; - T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false); - return attributes.Length > 0 ? attributes[0] : null; - } -} \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs index 79e1bafd..773d2337 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs @@ -37,22 +37,14 @@ internal WootingKeyboardRGBDevice(WootingKeyboardRGBDeviceInfo info, IUpdateQueu private void InitializeLayout() { - Dictionary mapping = WootingKeyboardLedMappings.Mapping[DeviceInfo.WootingDeviceType]; + Dictionary mapping = WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType]; foreach (KeyValuePair led in mapping) AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19)); } /// - protected override object GetLedCustomData(LedId ledId) => WootingKeyboardLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId]; - - public override void Dispose() - { - _WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex); - _WootingSDK.Reset(); - - base.Dispose(); - } + protected override object GetLedCustomData(LedId ledId) => WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId]; #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs b/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs new file mode 100644 index 00000000..5bf55249 --- /dev/null +++ b/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using RGB.NET.Core; +using RGB.NET.Devices.Wooting.Generic; +using RGB.NET.Devices.Wooting.Keyboard; + +namespace RGB.NET.Devices.Wooting.Keypad; + +/// +/// +/// Represents a Wooting keyboard. +/// +public sealed class WootingKeypadRGBDevice : WootingRGBDevice, IKeypad +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by Wooting for the keyboard + /// The update queue used to update this device. + internal WootingKeypadRGBDevice(WootingKeypadRGBDeviceInfo info, IUpdateQueue updateQueue) + : base(info, updateQueue) + { + InitializeLayout(); + } + + #endregion + + #region Methods + + private void InitializeLayout() + { + Dictionary mapping = WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType]; + + foreach (KeyValuePair led in mapping) + AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19)); + } + + /// + protected override object GetLedCustomData(LedId ledId) => WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId]; + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDeviceInfo.cs b/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDeviceInfo.cs new file mode 100644 index 00000000..55088e11 --- /dev/null +++ b/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDeviceInfo.cs @@ -0,0 +1,17 @@ +using RGB.NET.Core; +using RGB.NET.Devices.Wooting.Generic; +using RGB.NET.Devices.Wooting.Native; + +namespace RGB.NET.Devices.Wooting.Keypad; + +/// +/// Represents a generic information for a . +/// +public sealed class WootingKeypadRGBDeviceInfo : WootingRGBDeviceInfo +{ + internal WootingKeypadRGBDeviceInfo(_WootingDeviceInfo deviceInfo, byte deviceIndex) + : base(RGBDeviceType.Keypad, deviceInfo, deviceIndex) + { + + } +} diff --git a/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs b/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs index a672f315..6a59c811 100644 --- a/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs +++ b/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs @@ -17,11 +17,13 @@ internal struct _WootingDeviceInfo internal byte MaxColumns { get; private set; } - internal byte KeycodeLimit { get; private set; } + internal byte MaxLedIndex { get; private set; } internal WootingDeviceType DeviceType { get; private set; } - internal bool V2Interface { get; set; } + internal bool V2Interface { get; private set; } internal WootingLayoutType LayoutType { get; private set; } + + internal bool UsesSmallPackets { get; private set; } } \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 6d16b2f7..415ae4ca 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using RGB.NET.Core; +using RGB.NET.Devices.Wooting.Enum; using RGB.NET.Devices.Wooting.Generic; using RGB.NET.Devices.Wooting.Keyboard; +using RGB.NET.Devices.Wooting.Keypad; using RGB.NET.Devices.Wooting.Native; namespace RGB.NET.Devices.Wooting; @@ -100,7 +102,11 @@ protected override IEnumerable LoadDevices() _WootingSDK.SelectDevice(i); _WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!; - yield return new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(nativeDeviceInfo, i), updateQueue); + yield return nativeDeviceInfo.DeviceType switch + { + WootingDeviceType.Keypad3Keys => new WootingKeypadRGBDevice(new WootingKeypadRGBDeviceInfo(nativeDeviceInfo, i), updateQueue), + _ => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(nativeDeviceInfo, i), updateQueue), + }; } } } From 69d320fca3f121b6c1ba65e1a4668b44de576af0 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Tue, 17 Oct 2023 17:49:09 +0100 Subject: [PATCH 85/96] Ignore UwU non-RGB --- RGB.NET.Devices.Wooting/WootingDeviceProvider.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 415ae4ca..c92661f9 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -101,6 +101,10 @@ protected override IEnumerable LoadDevices() WootingUpdateQueue updateQueue = new(GetUpdateTrigger(), i); _WootingSDK.SelectDevice(i); _WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!; + + //Uwu non-rgb returns zero here. + if (nativeDeviceInfo.MaxLedIndex == 0) + continue; yield return nativeDeviceInfo.DeviceType switch { From 7ad1e595a9c7d4d086775e8d41bc0ebac6188926 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Tue, 17 Oct 2023 19:29:40 +0100 Subject: [PATCH 86/96] Added Missing LEDs --- .../Generic/WootingLedMappings.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs index 23746cb7..9b7860ba 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs @@ -307,27 +307,29 @@ internal static class WootingLedMappings private static readonly Dictionary ThreeKeyKeypad = new() { - //top left - bottom left - [LedId.LedStripe1] = (0, 0), - [LedId.LedStripe2] = (1, 0), + //left (from top to bottom) + [LedId.LedStripe1] = (1, 0), + [LedId.LedStripe2] = (2, 0), [LedId.LedStripe3] = (3, 0), - //bottom left - bottom right + //bottom (from left to right) [LedId.LedStripe4] = (4, 1), [LedId.LedStripe5] = (4, 2), [LedId.LedStripe6] = (4, 4), [LedId.LedStripe7] = (4, 5), - //bottom right - top right + //right (from bottom to top) [LedId.LedStripe8] = (3, 6), - [LedId.LedStripe9] = (1, 6), - [LedId.LedStripe10] = (0, 6), + [LedId.LedStripe9] = (2, 6), + [LedId.LedStripe10] = (1, 6), - //top right - top left - [LedId.LedStripe11] = (0, 4), - [LedId.LedStripe12] = (0, 2), + //top (from right to left) + [LedId.LedStripe11] = (0, 6), + [LedId.LedStripe12] = (0, 4), + [LedId.LedStripe13] = (0, 2), + [LedId.LedStripe14] = (0, 0), - //Analog Keys + //analog keys [LedId.Keypad1] = (3, 2), [LedId.Keypad2] = (3, 3), [LedId.Keypad3] = (3, 4), From fcf86ff9daaea162998227c378643843742ee9bb Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Wed, 18 Oct 2023 14:11:44 +0100 Subject: [PATCH 87/96] Fix analog key coords --- RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs index 9b7860ba..081e9934 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs @@ -330,9 +330,9 @@ internal static class WootingLedMappings [LedId.LedStripe14] = (0, 0), //analog keys - [LedId.Keypad1] = (3, 2), - [LedId.Keypad2] = (3, 3), - [LedId.Keypad3] = (3, 4), + [LedId.Keypad1] = (2, 1), + [LedId.Keypad2] = (2, 3), + [LedId.Keypad3] = (2, 5), }; /// From 883d6cbea449a6bb42141326d7dc521edef82495 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 31 Oct 2023 21:51:40 +0100 Subject: [PATCH 88/96] Added ToString to Scale --- RGB.NET.Core/Positioning/Scale.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/RGB.NET.Core/Positioning/Scale.cs b/RGB.NET.Core/Positioning/Scale.cs index 973bf9cf..18644e6c 100644 --- a/RGB.NET.Core/Positioning/Scale.cs +++ b/RGB.NET.Core/Positioning/Scale.cs @@ -50,6 +50,12 @@ public Scale(float horizontal, float vertical) #region Methods + /// + /// Converts the and value of this to a human-readable string. + /// + /// A string that contains the and value of this . For example "[Horizontal: 1, Vertical: 0.5]". + public override string ToString() => $"[Horizontal: {Horizontal}, Vertical: {Vertical}]\""; + /// /// Tests whether the specified is equivalent to this . /// From 188de3c5587bfd47d963bf33f93f9c05f664721a Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 31 Oct 2023 21:54:58 +0100 Subject: [PATCH 89/96] Fixed an error when parsing custom layout data if the xml-element contains an attribute --- RGB.NET.Layout/DeviceLayout.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Layout/DeviceLayout.cs b/RGB.NET.Layout/DeviceLayout.cs index 24efd371..e33e7609 100644 --- a/RGB.NET.Layout/DeviceLayout.cs +++ b/RGB.NET.Layout/DeviceLayout.cs @@ -174,7 +174,7 @@ public class DeviceLayout : IDeviceLayout /// The deserialized custom data object. protected virtual object? GetCustomData(object? customData, Type? type) { - XmlNode? node = (customData as XmlNode) ?? (customData as IEnumerable)?.FirstOrDefault()?.ParentNode; //HACK DarthAffe 16.01.2021: This gives us the CustomData-Node + XmlNode? node = (customData as XmlNode) ?? (customData as IEnumerable)?.FirstOrDefault(x => x.ParentNode != null)?.ParentNode; //HACK DarthAffe 16.01.2021: This gives us the CustomData-Node if ((node == null) || (type == null)) return null; using MemoryStream ms = new(); From be252790d443c9d4b7689c1922d93eee9f785879 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 31 Oct 2023 22:14:05 +0100 Subject: [PATCH 90/96] Added extension to save layouts --- RGB.NET.Layout/LayoutExtension.cs | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/RGB.NET.Layout/LayoutExtension.cs b/RGB.NET.Layout/LayoutExtension.cs index a6666372..915380b1 100644 --- a/RGB.NET.Layout/LayoutExtension.cs +++ b/RGB.NET.Layout/LayoutExtension.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Xml.Serialization; using RGB.NET.Core; namespace RGB.NET.Layout; @@ -51,4 +53,48 @@ public static void ApplyTo(this IDeviceLayout layout, IRGBDevice device, bool cr device.RemoveLed(led); } } + + /// + /// Saves the specified layout to the given location. + /// + /// The layout to save. + /// The location to save to. + public static void Save(this IDeviceLayout layout, string targetFile) + { + using FileStream fs = new(targetFile, FileMode.Create); + layout.Save(fs); + } + + /// + /// Saves the specified layout to the given stream. + /// + /// The layout to save. + /// The stream to save to. + public static void Save(this IDeviceLayout layout, Stream stream) + { + Type? customDataType = layout.CustomData?.GetType(); + Type? customLedDataType = layout.Leds.FirstOrDefault(x => x.CustomData != null)?.GetType(); + + Type[] customTypes; + if ((customDataType != null) && (customLedDataType != null)) + customTypes = new[] { customDataType, customLedDataType }; + else if (customDataType != null) + customTypes = new[] { customDataType }; + else if (customLedDataType != null) + customTypes = new[] { customLedDataType }; + else + customTypes = Array.Empty(); + + if (layout is DeviceLayout deviceLayout) + { + deviceLayout.InternalCustomData = deviceLayout.CustomData; + + foreach (ILedLayout led in deviceLayout.Leds) + if (led is LedLayout ledLayout) + ledLayout.InternalCustomData = ledLayout.CustomData; + } + + XmlSerializer serializer = new(typeof(DeviceLayout), null, customTypes, null, null); + serializer.Serialize(stream, layout); + } } \ No newline at end of file From 08fbb0e526b2aa3d5f2fb09f65791091ca725780 Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 1 Nov 2023 20:37:12 +0100 Subject: [PATCH 91/96] Fix custom LED data type not being determined correctly --- RGB.NET.Layout/LayoutExtension.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Layout/LayoutExtension.cs b/RGB.NET.Layout/LayoutExtension.cs index 915380b1..0426e3b7 100644 --- a/RGB.NET.Layout/LayoutExtension.cs +++ b/RGB.NET.Layout/LayoutExtension.cs @@ -73,7 +73,7 @@ public static void Save(this IDeviceLayout layout, string targetFile) public static void Save(this IDeviceLayout layout, Stream stream) { Type? customDataType = layout.CustomData?.GetType(); - Type? customLedDataType = layout.Leds.FirstOrDefault(x => x.CustomData != null)?.GetType(); + Type? customLedDataType = layout.Leds.FirstOrDefault(x => x.CustomData != null)?.CustomData?.GetType(); Type[] customTypes; if ((customDataType != null) && (customLedDataType != null)) From a0c90029ebfe88c8810374f977233493754b424f Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 14 Nov 2023 22:34:13 +0100 Subject: [PATCH 92/96] Added .NET 8 build-target --- .github/workflows/ci.yml | 19 +++++++++++++++---- .github/workflows/pr_verify.yml | 11 +++++++---- .github/workflows/release.yml | 19 ++++++++++++++----- RGB.NET.Core/RGB.NET.Core.csproj | 2 +- .../RGB.NET.Devices.Asus.csproj | 2 +- .../RGB.NET.Devices.CoolerMaster.csproj | 2 +- .../RGB.NET.Devices.Corsair.csproj | 2 +- .../RGB.NET.Devices.Corsair_Legacy.csproj | 2 +- .../RGB.NET.Devices.DMX.csproj | 2 +- .../RGB.NET.Devices.Debug.csproj | 2 +- .../RGB.NET.Devices.Logitech.csproj | 2 +- .../RGB.NET.Devices.Msi.csproj | 2 +- .../RGB.NET.Devices.Novation.csproj | 2 +- .../RGB.NET.Devices.OpenRGB.csproj | 2 +- .../RGB.NET.Devices.PicoPi.csproj | 2 +- .../RGB.NET.Devices.Razer.csproj | 2 +- .../RGB.NET.Devices.SteelSeries.csproj | 2 +- .../RGB.NET.Devices.WS281X.csproj | 2 +- .../Keyboard/WootingKeyboardRGBDevice.cs | 1 - .../Keypad/WootingKeypadRGBDevice.cs | 1 - .../RGB.NET.Devices.Wooting.csproj | 2 +- RGB.NET.HID/RGB.NET.HID.csproj | 2 +- RGB.NET.Layout/RGB.NET.Layout.csproj | 2 +- RGB.NET.Presets/RGB.NET.Presets.csproj | 2 +- .../RGB.NET.Core.Tests.csproj | 2 +- .../RGB.NET.Presets.Tests.csproj | 2 +- 26 files changed, 57 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36bab7a2..db64c8ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,16 +11,19 @@ on: jobs: build: - runs-on: windows-2022 + runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: | + 8.0.x + 7.0.x + 6.0.x - name: Git Semantic Version id: versioning uses: PaulHatch/semantic-version@v4.0.3 @@ -45,6 +48,12 @@ jobs: name: RGB.NET-NET7 path: bin/net7.0/RGB.NET.*.dll if-no-files-found: error + - name: Upload a Build Artifact NET8 + uses: actions/upload-artifact@v2.2.4 + with: + name: RGB.NET-NET8 + path: bin/net8.0/RGB.NET.*.dll + if-no-files-found: error - name: Upload Nuget Build Artifact uses: actions/upload-artifact@v2.2.4 with: @@ -53,3 +62,5 @@ jobs: if-no-files-found: error - name: Nuget Push run: dotnet nuget push **\*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json + - name: Symbols Push + run: dotnet nuget push **\*.snupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json diff --git a/.github/workflows/pr_verify.yml b/.github/workflows/pr_verify.yml index b47d33ee..d556fa25 100644 --- a/.github/workflows/pr_verify.yml +++ b/.github/workflows/pr_verify.yml @@ -7,14 +7,17 @@ on: jobs: build: - runs-on: windows-2022 + runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: | + 8.0.x + 7.0.x + 6.0.x - name: Restore dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 121fb301..f6e3df35 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,16 +10,19 @@ on: jobs: build: - runs-on: windows-2022 + runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v3 with: - dotnet-version: 7.0.x + dotnet-version: | + 8.0.x + 7.0.x + 6.0.x - name: Git Semantic Version id: versioning uses: PaulHatch/semantic-version@v4.0.3 @@ -44,6 +47,12 @@ jobs: name: RGB.NET-NET7 path: bin/net7.0/RGB.NET.*.dll if-no-files-found: error + - name: Upload a Build Artifact NET8 + uses: actions/upload-artifact@v2.2.4 + with: + name: RGB.NET-NET8 + path: bin/net8.0/RGB.NET.*.dll + if-no-files-found: error - name: Upload Nuget Build Artifact uses: actions/upload-artifact@v2.2.4 with: @@ -55,6 +64,6 @@ jobs: with: tag_name: ${{ steps.versioning.outputs.version_tag }} generate_release_notes: true - files: bin/net7.0/RGB.NET.*.dll + files: bin/net8.0/RGB.NET.*.dll - name: Nuget Push run: dotnet nuget push **\*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj index 8499b1ea..1022bf04 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj +++ b/RGB.NET.Core/RGB.NET.Core.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj index dc67689c..ecf4ea78 100644 --- a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj +++ b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj index 2adfaa53..73017c6b 100644 --- a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj +++ b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj index ccb143e7..ee6cfcaf 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj b/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj index dff737c2..c80995d1 100644 --- a/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj +++ b/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj index e6e876ee..df8e5475 100644 --- a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj +++ b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj index 980153ce..1f177287 100644 --- a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj +++ b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj index fd412e77..6ae10dd6 100644 --- a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj +++ b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj index 7d604a67..12f416f4 100644 --- a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj +++ b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj index cda9c5e4..c249fc27 100644 --- a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj +++ b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj index f3b3a814..6b325210 100644 --- a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj +++ b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj @@ -1,6 +1,6 @@ - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj b/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj index 6cf8a2c9..a2b134f7 100644 --- a/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj +++ b/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj index 27f72612..36323999 100644 --- a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj +++ b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj index f75e2d85..76525ce4 100644 --- a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj +++ b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj index 5487a8e6..39f4d520 100644 --- a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj +++ b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs index 773d2337..0ba3600e 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using RGB.NET.Core; using RGB.NET.Devices.Wooting.Generic; -using RGB.NET.Devices.Wooting.Native; namespace RGB.NET.Devices.Wooting.Keyboard; diff --git a/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs b/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs index 5bf55249..984072b2 100644 --- a/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using RGB.NET.Core; using RGB.NET.Devices.Wooting.Generic; -using RGB.NET.Devices.Wooting.Keyboard; namespace RGB.NET.Devices.Wooting.Keypad; diff --git a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj index 8a34dcde..37d84ab0 100644 --- a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj +++ b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.HID/RGB.NET.HID.csproj b/RGB.NET.HID/RGB.NET.HID.csproj index 7bf502b1..58b5b0f4 100644 --- a/RGB.NET.HID/RGB.NET.HID.csproj +++ b/RGB.NET.HID/RGB.NET.HID.csproj @@ -1,6 +1,6 @@ - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Layout/RGB.NET.Layout.csproj b/RGB.NET.Layout/RGB.NET.Layout.csproj index 3c901858..473f4214 100644 --- a/RGB.NET.Layout/RGB.NET.Layout.csproj +++ b/RGB.NET.Layout/RGB.NET.Layout.csproj @@ -1,6 +1,6 @@ - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/RGB.NET.Presets/RGB.NET.Presets.csproj b/RGB.NET.Presets/RGB.NET.Presets.csproj index 048087ae..c7b6129e 100644 --- a/RGB.NET.Presets/RGB.NET.Presets.csproj +++ b/RGB.NET.Presets/RGB.NET.Presets.csproj @@ -1,6 +1,6 @@  - net7.0;net6.0 + net8.0;net7.0;net6.0 latest enable diff --git a/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj b/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj index 7e98ef54..7fb09e7c 100644 --- a/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj +++ b/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 false diff --git a/Tests/RGB.NET.Presets.Tests/RGB.NET.Presets.Tests.csproj b/Tests/RGB.NET.Presets.Tests/RGB.NET.Presets.Tests.csproj index ca572305..ba91ec3c 100644 --- a/Tests/RGB.NET.Presets.Tests/RGB.NET.Presets.Tests.csproj +++ b/Tests/RGB.NET.Presets.Tests/RGB.NET.Presets.Tests.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 false From 8aaf602cdd80cdc6b6a68d719867cc7d47e09b74 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Fri, 22 Dec 2023 20:16:14 +0100 Subject: [PATCH 93/96] Added GameController as Core device type; Updated Corsair SDK to 4.0.84 --- RGB.NET.Core/Devices/RGBDeviceType.cs | 5 + .../Devices/TypeInterfaces/IGameController.cs | 7 + RGB.NET.Core/Leds/LedId.cs | 130 ++++++++++++++++++ .../CorsairDeviceProvider.cs | 8 ++ .../Enum/CorsairChannelDeviceType.cs | 1 + .../Enum/CorsairDeviceType.cs | 5 + .../Enum/CorsairLedGroup.cs | 7 +- .../CorsairGameControllerRGBDevice.cs | 34 +++++ .../CorsairGameControllerRGBDeviceInfo.cs | 20 +++ .../Generic/LedMappings.cs | 1 + RGB.NET.Devices.Corsair/README.md | 4 +- ...RGB.NET.Devices.Corsair.csproj.DotSettings | 1 + 12 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs create mode 100644 RGB.NET.Devices.Corsair/GameController/CorsairGameControllerRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair/GameController/CorsairGameControllerRGBDeviceInfo.cs diff --git a/RGB.NET.Core/Devices/RGBDeviceType.cs b/RGB.NET.Core/Devices/RGBDeviceType.cs index 88e4f822..57be1067 100644 --- a/RGB.NET.Core/Devices/RGBDeviceType.cs +++ b/RGB.NET.Core/Devices/RGBDeviceType.cs @@ -93,6 +93,11 @@ public enum RGBDeviceType /// LedController = 1 << 15, + /// + /// Represents a game controller. + /// + GameController = 1 << 16, + /// /// Represents a device where the type is not known or not present in the list. /// diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs b/RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs new file mode 100644 index 00000000..d2c55076 --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs @@ -0,0 +1,7 @@ +namespace RGB.NET.Core; + +/// +/// Represents a gamecontroller-device +/// +public interface IGameController: IRGBDevice +{ } \ No newline at end of file diff --git a/RGB.NET.Core/Leds/LedId.cs b/RGB.NET.Core/Leds/LedId.cs index 43a6a703..a0b12c9a 100644 --- a/RGB.NET.Core/Leds/LedId.cs +++ b/RGB.NET.Core/Leds/LedId.cs @@ -6294,6 +6294,136 @@ public enum LedId Cooler127 = 0x00D0007F, Cooler128 = 0x00D00080, + /*### GameController ###*/ + GameController1 = 0x00E00001, + GameController2 = 0x00E00002, + GameController3 = 0x00E00003, + GameController4 = 0x00E00004, + GameController5 = 0x00E00005, + GameController6 = 0x00E00006, + GameController7 = 0x00E00007, + GameController8 = 0x00E00008, + GameController9 = 0x00E00009, + GameController10 = 0x00E0000A, + GameController11 = 0x00E0000B, + GameController12 = 0x00E0000C, + GameController13 = 0x00E0000D, + GameController14 = 0x00E0000E, + GameController15 = 0x00E0000F, + GameController16 = 0x00E00010, + GameController17 = 0x00E00011, + GameController18 = 0x00E00012, + GameController19 = 0x00E00013, + GameController20 = 0x00E00014, + GameController21 = 0x00E00015, + GameController22 = 0x00E00016, + GameController23 = 0x00E00017, + GameController24 = 0x00E00018, + GameController25 = 0x00E00019, + GameController26 = 0x00E0001A, + GameController27 = 0x00E0001B, + GameController28 = 0x00E0001C, + GameController29 = 0x00E0001D, + GameController30 = 0x00E0001E, + GameController31 = 0x00E0001F, + GameController32 = 0x00E00020, + GameController33 = 0x00E00021, + GameController34 = 0x00E00022, + GameController35 = 0x00E00023, + GameController36 = 0x00E00024, + GameController37 = 0x00E00025, + GameController38 = 0x00E00026, + GameController39 = 0x00E00027, + GameController40 = 0x00E00028, + GameController41 = 0x00E00029, + GameController42 = 0x00E0002A, + GameController43 = 0x00E0002B, + GameController44 = 0x00E0002C, + GameController45 = 0x00E0002D, + GameController46 = 0x00E0002E, + GameController47 = 0x00E0002F, + GameController48 = 0x00E00030, + GameController49 = 0x00E00031, + GameController50 = 0x00E00032, + GameController51 = 0x00E00033, + GameController52 = 0x00E00034, + GameController53 = 0x00E00035, + GameController54 = 0x00E00036, + GameController55 = 0x00E00037, + GameController56 = 0x00E00038, + GameController57 = 0x00E00039, + GameController58 = 0x00E0003A, + GameController59 = 0x00E0003B, + GameController60 = 0x00E0003C, + GameController61 = 0x00E0003D, + GameController62 = 0x00E0003E, + GameController63 = 0x00E0003F, + GameController64 = 0x00E00040, + GameController65 = 0x00E00041, + GameController66 = 0x00E00042, + GameController67 = 0x00E00043, + GameController68 = 0x00E00044, + GameController69 = 0x00E00045, + GameController70 = 0x00E00046, + GameController71 = 0x00E00047, + GameController72 = 0x00E00048, + GameController73 = 0x00E00049, + GameController74 = 0x00E0004A, + GameController75 = 0x00E0004B, + GameController76 = 0x00E0004C, + GameController77 = 0x00E0004D, + GameController78 = 0x00E0004E, + GameController79 = 0x00E0004F, + GameController80 = 0x00E00050, + GameController81 = 0x00E00051, + GameController82 = 0x00E00052, + GameController83 = 0x00E00053, + GameController84 = 0x00E00054, + GameController85 = 0x00E00055, + GameController86 = 0x00E00056, + GameController87 = 0x00E00057, + GameController88 = 0x00E00058, + GameController89 = 0x00E00059, + GameController90 = 0x00E0005A, + GameController91 = 0x00E0005B, + GameController92 = 0x00E0005C, + GameController93 = 0x00E0005D, + GameController94 = 0x00E0005E, + GameController95 = 0x00E0005F, + GameController96 = 0x00E00060, + GameController97 = 0x00E00061, + GameController98 = 0x00E00062, + GameController99 = 0x00E00063, + GameController100 = 0x00E00064, + GameController101 = 0x00E00065, + GameController102 = 0x00E00066, + GameController103 = 0x00E00067, + GameController104 = 0x00E00068, + GameController105 = 0x00E00069, + GameController106 = 0x00E0006A, + GameController107 = 0x00E0006B, + GameController108 = 0x00E0006C, + GameController109 = 0x00E0006D, + GameController110 = 0x00E0006E, + GameController111 = 0x00E0006F, + GameController112 = 0x00E00070, + GameController113 = 0x00E00071, + GameController114 = 0x00E00072, + GameController115 = 0x00E00073, + GameController116 = 0x00E00074, + GameController117 = 0x00E00075, + GameController118 = 0x00E00076, + GameController119 = 0x00E00077, + GameController120 = 0x00E00078, + GameController121 = 0x00E00079, + GameController122 = 0x00E0007A, + GameController123 = 0x00E0007B, + GameController124 = 0x00E0007C, + GameController125 = 0x00E0007D, + GameController126 = 0x00E0007E, + GameController127 = 0x00E0007F, + GameController128 = 0x00E00080, + /*### Custom ###*/ Custom1 = 0x0FE00001, Custom2 = 0x0FE00002, diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 89f46841..3a4a4dac 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -217,6 +217,10 @@ private IEnumerable LoadCorsairDevices() yield return new CorsairCoolerRGBDevice(new CorsairCoolerRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); break; + case CorsairDeviceType.GameController: + yield return new CorsairGameControllerRGBDevice(new CorsairGameControllerRGBDeviceInfo(device, deviceLedCount, 0), updateQueue); + break; + case CorsairDeviceType.FanLedController: case CorsairDeviceType.LedController: case CorsairDeviceType.Unknown: @@ -264,6 +268,10 @@ private IEnumerable LoadCorsairDevices() yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "QL Fan"), updateQueue); break; + case CorsairChannelDeviceType.FanQX: + yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "QX Fan"), updateQueue); + break; + case CorsairChannelDeviceType.EightLedSeriesFan: yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "8-Led-Series Fan Fan"), updateQueue); break; diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs b/RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs index 65a38fad..afadf303 100644 --- a/RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs +++ b/RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs @@ -20,4 +20,5 @@ public enum CorsairChannelDeviceType Pump = 9, DRAM = 10, WaterBlock = 11, + FanQX = 12, }; \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs b/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs index b41be141..9e784038 100644 --- a/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs +++ b/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs @@ -76,6 +76,11 @@ public enum CorsairDeviceType : uint /// Touchbar = 0x0800, + /// + /// iCUE-SDK: for game controllers + /// + GameController = 0x1000, + /// /// iCUE-SDK: for all devices /// diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs b/RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs index 3ec299da..58b7079d 100644 --- a/RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs +++ b/RGB.NET.Devices.Corsair/Enum/CorsairLedGroup.cs @@ -80,5 +80,10 @@ public enum CorsairLedGroup /// /// iCUE-SDK: for touchbar leds /// - Touchbar = 14 + Touchbar = 14, + + /// + /// iCUE-SDK: for game controller leds + /// + GameController = 15 } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/GameController/CorsairGameControllerRGBDevice.cs b/RGB.NET.Devices.Corsair/GameController/CorsairGameControllerRGBDevice.cs new file mode 100644 index 00000000..2c4234d4 --- /dev/null +++ b/RGB.NET.Devices.Corsair/GameController/CorsairGameControllerRGBDevice.cs @@ -0,0 +1,34 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using RGB.NET.Core; +using System.Collections.Generic; + +namespace RGB.NET.Devices.Corsair; + +/// +/// +/// Represents a corsair gamecontroller. +/// +public sealed class CorsairGameControllerRGBDevice : CorsairRGBDevice, IGameController +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the gamecontroller + /// The queue used to update this device. + internal CorsairGameControllerRGBDevice(CorsairGameControllerRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) + : base(info, updateQueue) + { } + + #endregion + + #region Methods + + protected override LedMapping CreateMapping(IEnumerable ids) => LedMappings.CreateGameControllerMapping(ids); + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/GameController/CorsairGameControllerRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/GameController/CorsairGameControllerRGBDeviceInfo.cs new file mode 100644 index 00000000..5d968d7b --- /dev/null +++ b/RGB.NET.Devices.Corsair/GameController/CorsairGameControllerRGBDeviceInfo.cs @@ -0,0 +1,20 @@ +using RGB.NET.Core; +using RGB.NET.Devices.Corsair.Native; + +namespace RGB.NET.Devices.Corsair; + +/// +/// +/// Represents a generic information for a . +/// +public sealed class CorsairGameControllerRGBDeviceInfo : CorsairRGBDeviceInfo +{ + #region Constructors + + /// + internal CorsairGameControllerRGBDeviceInfo(_CorsairDeviceInfo nativeInfo, int ledCount, int ledOffset) + : base(RGBDeviceType.GameController, nativeInfo, ledCount, ledOffset) + { } + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Generic/LedMappings.cs b/RGB.NET.Devices.Corsair/Generic/LedMappings.cs index ffbfa0ff..f37ec876 100644 --- a/RGB.NET.Devices.Corsair/Generic/LedMappings.cs +++ b/RGB.NET.Devices.Corsair/Generic/LedMappings.cs @@ -160,6 +160,7 @@ internal static class LedMappings internal static LedMapping CreateMousepadMapping(IEnumerable ids) => CreateMapping(ids, LedId.Mousepad1); internal static LedMapping CreateHeadsetMapping(IEnumerable ids) => CreateMapping(ids, LedId.Headset1); internal static LedMapping CreateMouseMapping(IEnumerable ids) => CreateMapping(ids, LedId.Mouse1); + internal static LedMapping CreateGameControllerMapping(IEnumerable ids) => CreateMapping(ids, LedId.GameController1); internal static LedMapping CreateUnknownMapping(IEnumerable ids) => CreateMapping(ids, LedId.Unknown1); internal static LedMapping CreateMapping(IEnumerable ids, LedId referenceId) diff --git a/RGB.NET.Devices.Corsair/README.md b/RGB.NET.Devices.Corsair/README.md index c6c1803d..191ad602 100644 --- a/RGB.NET.Devices.Corsair/README.md +++ b/RGB.NET.Devices.Corsair/README.md @@ -11,7 +11,7 @@ surface.Load(CorsairDeviceProvider.Instance); This providers requires native SDK-dlls. You can get them directly from Corsair at [https://github.com/CorsairOfficial/cue-sdk/releases](https://github.com/CorsairOfficial/cue-sdk/releases) -(Developed and tested with iCUE SDK v4.0.48) +(Developed and tested with iCUE SDK v4.0.84) Since the SDK-dlls are native it's important to use the correct architecture you're building your application for. (If in doubt you can always include both.) @@ -20,7 +20,7 @@ Since the SDK-dlls are native it's important to use the correct architecture you You can use other, custom paths by adding them to `CorsairDeviceProvider.PossibleX64NativePaths`. -### x86 +### x86 (only SDKs before v4.0.84) `redist\i386\iCUESDK_2019.dll` from the SDK-zip needs to be distributed as `\x86\iCUESDK_2019.dll` (or simply named `iCUESDK.dll`) You can use other, custom paths by adding them to `CorsairDeviceProvider.PossibleX86NativePaths`. diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings index 16defe6e..9eb538f8 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings @@ -1,6 +1,7 @@  True True + True True True True From d85f1559b301b34bc1db40559d5f0b4bce4bbea3 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Fri, 22 Dec 2023 20:56:56 +0100 Subject: [PATCH 94/96] Applied some C#12 stuff --- .../Decorators/AbstractDecorateable.cs | 2 +- RGB.NET.Core/Decorators/AbstractDecorator.cs | 4 +- RGB.NET.Core/Decorators/IDecoratable.cs | 3 +- RGB.NET.Core/Decorators/ILedGroupDecorator.cs | 3 +- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 2 +- .../Devices/AbstractRGBDeviceProvider.cs | 8 +- .../Devices/TypeInterfaces/ICooler.cs | 3 +- RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs | 3 +- RGB.NET.Core/Devices/TypeInterfaces/IFan.cs | 3 +- .../Devices/TypeInterfaces/IGameController.cs | 3 +- .../Devices/TypeInterfaces/IGraphicsCard.cs | 3 +- .../Devices/TypeInterfaces/IHeadset.cs | 3 +- .../Devices/TypeInterfaces/IHeadsetStand.cs | 3 +- .../Devices/TypeInterfaces/IKeypad.cs | 3 +- .../Devices/TypeInterfaces/ILedMatrix.cs | 3 +- .../Devices/TypeInterfaces/ILedStripe.cs | 3 +- .../Devices/TypeInterfaces/IMainboard.cs | 3 +- RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs | 3 +- .../Devices/TypeInterfaces/IMousepad.cs | 3 +- .../Devices/TypeInterfaces/ISpeaker.cs | 3 +- .../Devices/TypeInterfaces/IUnknownDevice.cs | 3 +- .../Events/DevicesChangedEventArgs.cs | 17 +--- RGB.NET.Core/Events/UpdatedEventArgs.cs | 3 +- RGB.NET.Core/Helper/TimerHelper.cs | 4 +- RGB.NET.Core/Ids/IdGenerator.cs | 10 +- RGB.NET.Core/Leds/LedMapping.cs | 6 +- RGB.NET.Core/MVVM/IBindable.cs | 3 +- .../Misc/AbstractReferenceCounting.cs | 2 +- RGB.NET.Core/Misc/ActionDisposable.cs | 19 +--- RGB.NET.Core/RGBSurface.cs | 4 +- RGB.NET.Core/Update/CustomUpdateData.cs | 2 +- RGB.NET.Core/Update/Devices/IUpdateQueue.cs | 3 +- RGB.NET.Core/Update/Devices/UpdateQueue.cs | 2 +- .../Generic/IAsusRGBDevice.cs | 3 +- .../Keyboard/AsusKeyboardRGBDevice.cs | 16 ++-- .../Keyboard/AsusKeyboardRGBDeviceInfo.cs | 2 +- .../CoolerMasterDeviceProvider.cs | 4 +- .../Generic/ICoolerMasterRGBDevice.cs | 3 +- .../Native/_CoolerMasterSDK.cs | 16 ++-- .../CorsairDeviceProvider.cs | 4 +- .../Generic/LedMappings.cs | 2 +- .../Native/_CorsairDeviceFilter.cs | 1 + .../CorsairLegacyDeviceProvider.cs | 12 +-- .../Custom/CorsairCustomRGBDevice.cs | 9 +- .../Custom/CorsairCustomRGBDeviceInfo.cs | 2 +- .../Generic/CorsairDeviceUpdateQueue.cs | 6 +- .../Generic/CorsairProtocolDetails.cs | 5 +- .../Generic/CorsairRGBDevice.cs | 9 +- .../Generic/CorsairRGBDeviceInfo.cs | 5 +- .../Generic/LedMappings.cs | 10 +- .../Helper/NativeExtensions.cs | 2 +- .../Native/_CUESDK.cs | 74 +++++++-------- .../Native/_CorsairChannelInfo.cs | 3 +- .../Native/_CorsairChannelsInfo.cs | 3 +- .../Native/_CorsairDeviceInfo.cs | 3 +- .../Native/_CorsairLedPositions.cs | 3 +- .../Native/_CorsairProtocolDetails.cs | 5 +- RGB.NET.Devices.DMX/DMXDeviceProvider.cs | 2 +- .../E131/E131DMXDeviceDefinition.cs | 2 +- .../Generic/IDMXDeviceDefinition.cs | 3 +- .../Generic/LedChannelMapping.cs | 14 +-- RGB.NET.Devices.Debug/DebugDeviceProvider.cs | 2 +- .../DebugDeviceUpdateQueue.cs | 10 +- .../Generic/ILogitechRGBDevice.cs | 3 +- .../HID/LightspeedHidLoader.cs | 20 ++-- .../LogitechDeviceProvider.cs | 6 +- .../Native/_LogitechGSDK.cs | 54 +++++------ RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs | 3 +- RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 4 +- RGB.NET.Devices.Msi/Native/_MsiSDK.cs | 8 +- .../Generic/INovationRGBDevice.cs | 3 +- .../Abstract/IOpenRGBDevice.cs | 3 +- .../OpenRGBDeviceProvider.cs | 4 +- RGB.NET.Devices.PicoPi/PicoPi/LedMappings.cs | 2 +- .../PicoPiDeviceProvider.cs | 2 +- .../ChromaLink/RazerChromaLinkUpdateQueue.cs | 6 +- .../Generic/IRazerRGBDevice.cs | 3 +- RGB.NET.Devices.Razer/Generic/LedMappings.cs | 8 +- .../Generic/RazerUpdateQueue.cs | 6 +- .../Headset/RazerHeadsetUpdateQueue.cs | 6 +- .../Keyboard/RazerKeyboardUpdateQueue.cs | 6 +- .../Keypad/RazerKeypadUpdateQueue.cs | 6 +- .../Mouse/RazerMouseUpdateQueue.cs | 6 +- .../Mousepad/RazerMousepadUpdateQueue.cs | 6 +- RGB.NET.Devices.Razer/Native/_Color.cs | 11 +-- RGB.NET.Devices.Razer/Native/_RazerSDK.cs | 94 +++++++++---------- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 4 +- .../API/Model/Event.cs | 2 +- .../Attribute/APIName.cs | 13 +-- .../Attribute/SteelSeriesEnumExtension.cs | 4 +- .../Generic/ISteelSeriesRGBDevice.cs | 3 +- .../Arduino/ArduinoWS2812USBUpdateQueue.cs | 2 +- .../BitwizardWS281XDeviceDefinition.cs | 2 +- .../NodeMCU/NodeMCUWS2812USBUpdateQueue.cs | 4 +- .../WS281XDeviceProvider.cs | 2 +- .../Generic/IWootingRGBDevice.cs | 3 +- RGB.NET.Devices.Wooting/Native/_WootingSDK.cs | 46 ++++----- .../WootingDeviceProvider.cs | 8 +- RGB.NET.HID/HIDLoader.cs | 2 +- RGB.NET.Layout/DeviceLayout.cs | 2 +- RGB.NET.Layout/LayoutExtension.cs | 2 +- .../Decorators/IGradientDecorator.cs | 3 +- .../Textures/Gradients/AbstractGradient.cs | 2 +- .../Textures/Gradients/LinearGradient.cs | 2 +- .../RGB.NET.Core.Tests/Helper/SimplexNoise.cs | 4 +- 105 files changed, 332 insertions(+), 425 deletions(-) diff --git a/RGB.NET.Core/Decorators/AbstractDecorateable.cs b/RGB.NET.Core/Decorators/AbstractDecorateable.cs index 5312eab6..706aa450 100644 --- a/RGB.NET.Core/Decorators/AbstractDecorateable.cs +++ b/RGB.NET.Core/Decorators/AbstractDecorateable.cs @@ -11,7 +11,7 @@ public abstract class AbstractDecoratable : AbstractBindable, IDecoratable { #region Properties & Fields - private readonly List _decorators = new(); + private readonly List _decorators = []; /// public IReadOnlyList Decorators { get; } diff --git a/RGB.NET.Core/Decorators/AbstractDecorator.cs b/RGB.NET.Core/Decorators/AbstractDecorator.cs index 159fb4b2..f9c70593 100644 --- a/RGB.NET.Core/Decorators/AbstractDecorator.cs +++ b/RGB.NET.Core/Decorators/AbstractDecorator.cs @@ -29,7 +29,7 @@ public int Order /// /// Gets a readonly-list of all this decorator is attached to. /// - protected List DecoratedObjects { get; } = new(); + protected List DecoratedObjects { get; } = []; #endregion @@ -46,7 +46,7 @@ public int Order /// protected virtual void Detach() { - List decoratables = new(DecoratedObjects); + List decoratables = [..DecoratedObjects]; foreach (IDecoratable decoratable in decoratables) { IEnumerable types = decoratable.GetType().GetInterfaces().Where(t => t.IsGenericType diff --git a/RGB.NET.Core/Decorators/IDecoratable.cs b/RGB.NET.Core/Decorators/IDecoratable.cs index 5fddf47a..413b6980 100644 --- a/RGB.NET.Core/Decorators/IDecoratable.cs +++ b/RGB.NET.Core/Decorators/IDecoratable.cs @@ -6,8 +6,7 @@ namespace RGB.NET.Core; /// /// Represents a basic decoratable. /// -public interface IDecoratable : INotifyPropertyChanged -{ } +public interface IDecoratable : INotifyPropertyChanged; /// /// diff --git a/RGB.NET.Core/Decorators/ILedGroupDecorator.cs b/RGB.NET.Core/Decorators/ILedGroupDecorator.cs index 051ca9d8..51bd3022 100644 --- a/RGB.NET.Core/Decorators/ILedGroupDecorator.cs +++ b/RGB.NET.Core/Decorators/ILedGroupDecorator.cs @@ -4,5 +4,4 @@ /// /// Represents a basic decorator decorating a . /// -public interface ILedGroupDecorator : IDecorator -{ } \ No newline at end of file +public interface ILedGroupDecorator : IDecorator; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index a03bfa23..9e3572b3 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -53,7 +53,7 @@ public abstract class AbstractRGBDevice : Placeable, IRGBDevice /// Gets a dictionary containing all of the . /// - protected Dictionary LedMapping { get; } = new(); + protected Dictionary LedMapping { get; } = []; /// /// Gets the update queue used to update this device. diff --git a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs index 2d1f2eba..ff2f7df6 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDeviceProvider.cs @@ -25,7 +25,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider /// /// The list of devices managed by this device-provider. /// - protected List InternalDevices { get; } = new(); + protected List InternalDevices { get; } = []; /// public virtual IReadOnlyList Devices => new ReadOnlyCollection(InternalDevices); @@ -34,7 +34,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider /// Gets the dictionary containing the registered update triggers. /// Normally should be used to access them. /// - protected Dictionary UpdateTriggerMapping { get; } = new(); + protected Dictionary UpdateTriggerMapping { get; } = []; /// public IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)>(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList()); @@ -116,7 +116,7 @@ protected virtual IEnumerable GetLoadedDevices(RGBDeviceType loadFil { if (_isDisposed) throw new ObjectDisposedException(GetType().FullName); - List devices = new(); + List devices = []; foreach (IRGBDevice device in LoadDevices()) { try @@ -189,7 +189,7 @@ protected virtual void Reset() foreach (IRGBDevice device in Devices) device.Dispose(); - List devices = new(InternalDevices); + List devices = [..InternalDevices]; foreach (IRGBDevice device in devices) RemoveDevice(device); diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs b/RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs index 1e1eb2f2..da7c2a08 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs @@ -3,5 +3,4 @@ /// /// Represents a cooler-device /// -public interface ICooler : IRGBDevice -{ } \ No newline at end of file +public interface ICooler : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs b/RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs index 3bb4c23a..a395d91f 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs @@ -3,5 +3,4 @@ /// /// Represents a DRAM-device /// -public interface IDRAM : IRGBDevice -{ } \ No newline at end of file +public interface IDRAM : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IFan.cs b/RGB.NET.Core/Devices/TypeInterfaces/IFan.cs index 9f0c803a..fd11b084 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IFan.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IFan.cs @@ -3,5 +3,4 @@ /// /// represents a fan-device /// -public interface IFan : IRGBDevice -{ } \ No newline at end of file +public interface IFan : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs b/RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs index d2c55076..ebfe6a1e 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IGameController.cs @@ -3,5 +3,4 @@ /// /// Represents a gamecontroller-device /// -public interface IGameController: IRGBDevice -{ } \ No newline at end of file +public interface IGameController: IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs b/RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs index 372ec092..9d589445 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs @@ -3,5 +3,4 @@ /// /// Represents a graphics-card-device /// -public interface IGraphicsCard : IRGBDevice -{ } \ No newline at end of file +public interface IGraphicsCard : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs b/RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs index 0256cd5c..fea115e6 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs @@ -3,5 +3,4 @@ /// /// Represents a headset-device /// -public interface IHeadset : IRGBDevice -{ } \ No newline at end of file +public interface IHeadset : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs b/RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs index 537c8564..afc31c7e 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs @@ -3,5 +3,4 @@ /// /// Represents a headset-stand-device /// -public interface IHeadsetStand : IRGBDevice -{ } \ No newline at end of file +public interface IHeadsetStand : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs b/RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs index 2a65233b..ff6a9700 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs @@ -3,5 +3,4 @@ /// /// Represents a keypad-device /// -public interface IKeypad : IRGBDevice -{ } \ No newline at end of file +public interface IKeypad : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs b/RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs index b0f401e5..48d029b2 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs @@ -3,5 +3,4 @@ /// /// Represents a led-matrix-device /// -public interface ILedMatrix : IRGBDevice -{ } \ No newline at end of file +public interface ILedMatrix : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs b/RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs index 4bb5fd80..355cd280 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs @@ -3,5 +3,4 @@ /// /// Represents a led-stripe-device /// -public interface ILedStripe : IRGBDevice -{ } \ No newline at end of file +public interface ILedStripe : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs b/RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs index 10af8f4a..5e7b270d 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs @@ -3,5 +3,4 @@ /// /// Represents a mainboard-device /// -public interface IMainboard : IRGBDevice -{ } \ No newline at end of file +public interface IMainboard : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs b/RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs index 76e62e2e..d0459760 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs @@ -3,5 +3,4 @@ /// /// Represents a mouse-device /// -public interface IMouse : IRGBDevice -{ } \ No newline at end of file +public interface IMouse : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs b/RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs index c89b2548..af875217 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs @@ -3,5 +3,4 @@ /// /// Represents a mousepad-device /// -public interface IMousepad : IRGBDevice -{ } \ No newline at end of file +public interface IMousepad : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs b/RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs index cde47e4e..226d6a8d 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs @@ -3,5 +3,4 @@ /// /// Represents a speaker-device /// -public interface ISpeaker : IRGBDevice -{ } \ No newline at end of file +public interface ISpeaker : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs b/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs index 1d136ad7..a0374536 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs @@ -3,5 +3,4 @@ /// /// Represents a device with unkown or not specified type. /// -public interface IUnknownDevice : IRGBDevice -{ } \ No newline at end of file +public interface IUnknownDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Core/Events/DevicesChangedEventArgs.cs b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs index a0d648be..5a856e5a 100644 --- a/RGB.NET.Core/Events/DevicesChangedEventArgs.cs +++ b/RGB.NET.Core/Events/DevicesChangedEventArgs.cs @@ -2,22 +2,13 @@ namespace RGB.NET.Core; -public sealed class DevicesChangedEventArgs : EventArgs +public sealed class DevicesChangedEventArgs(IRGBDevice device, DevicesChangedEventArgs.DevicesChangedAction action) + : EventArgs { #region Properties & Fields - public IRGBDevice Device { get; } - public DevicesChangedAction Action { get; } - - #endregion - - #region Constructors - - public DevicesChangedEventArgs(IRGBDevice device, DevicesChangedAction action) - { - this.Device = device; - this.Action = action; - } + public IRGBDevice Device { get; } = device; + public DevicesChangedAction Action { get; } = action; #endregion diff --git a/RGB.NET.Core/Events/UpdatedEventArgs.cs b/RGB.NET.Core/Events/UpdatedEventArgs.cs index b4251d4d..467e5033 100644 --- a/RGB.NET.Core/Events/UpdatedEventArgs.cs +++ b/RGB.NET.Core/Events/UpdatedEventArgs.cs @@ -6,5 +6,4 @@ namespace RGB.NET.Core; /// /// Represents the information supplied with an -event. /// -public class UpdatedEventArgs : EventArgs -{ } \ No newline at end of file +public class UpdatedEventArgs : EventArgs; \ No newline at end of file diff --git a/RGB.NET.Core/Helper/TimerHelper.cs b/RGB.NET.Core/Helper/TimerHelper.cs index 432170bf..e2742ab4 100644 --- a/RGB.NET.Core/Helper/TimerHelper.cs +++ b/RGB.NET.Core/Helper/TimerHelper.cs @@ -46,7 +46,7 @@ public static bool UseHighResolutionTimers } // ReSharper disable once InconsistentNaming - private static readonly HashSet _timerLeases = new(); + private static readonly HashSet _timerLeases = []; #endregion @@ -143,7 +143,7 @@ private static void DisableHighResolutionTimers() /// public static void DisposeAllHighResolutionTimerRequests() { - List timerLeases = new(_timerLeases); + List timerLeases = [.._timerLeases]; foreach (HighResolutionTimerDisposable timer in timerLeases) timer.Dispose(); } diff --git a/RGB.NET.Core/Ids/IdGenerator.cs b/RGB.NET.Core/Ids/IdGenerator.cs index c6270e7c..f9bf2177 100644 --- a/RGB.NET.Core/Ids/IdGenerator.cs +++ b/RGB.NET.Core/Ids/IdGenerator.cs @@ -12,9 +12,9 @@ public static class IdGenerator #region Properties & Fields // ReSharper disable InconsistentNaming - private static readonly HashSet _registeredIds = new(); - private static readonly Dictionary> _idMappings = new(); - private static readonly Dictionary> _counter = new(); + private static readonly HashSet _registeredIds = []; + private static readonly Dictionary> _idMappings = []; + private static readonly Dictionary> _counter = []; // ReSharper restore InconsistentNaming #endregion @@ -33,8 +33,8 @@ internal static string MakeUnique(Assembly callingAssembly, string id) { if (!_idMappings.TryGetValue(callingAssembly, out Dictionary? idMapping)) { - _idMappings.Add(callingAssembly, idMapping = new Dictionary()); - _counter.Add(callingAssembly, new Dictionary()); + _idMappings.Add(callingAssembly, idMapping = []); + _counter.Add(callingAssembly, []); } Dictionary counterMapping = _counter[callingAssembly]; diff --git a/RGB.NET.Core/Leds/LedMapping.cs b/RGB.NET.Core/Leds/LedMapping.cs index 0aab16d7..a296bbe2 100644 --- a/RGB.NET.Core/Leds/LedMapping.cs +++ b/RGB.NET.Core/Leds/LedMapping.cs @@ -13,14 +13,14 @@ public sealed class LedMapping : IEnumerable<(LedId ledId, T mapping)> { #region Constants - public static LedMapping Empty { get; } = new(); + public static LedMapping Empty { get; } = []; #endregion #region Properties & Fields - private readonly Dictionary _mapping = new(); - private readonly Dictionary _reverseMapping = new(); + private readonly Dictionary _mapping = []; + private readonly Dictionary _reverseMapping = []; /// /// Gets the number of entries in this mapping. diff --git a/RGB.NET.Core/MVVM/IBindable.cs b/RGB.NET.Core/MVVM/IBindable.cs index 24d1fa52..97192886 100644 --- a/RGB.NET.Core/MVVM/IBindable.cs +++ b/RGB.NET.Core/MVVM/IBindable.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Core; /// /// Represents a basic bindable class which notifies when a property value changes. /// -public interface IBindable : INotifyPropertyChanged -{ } \ No newline at end of file +public interface IBindable : INotifyPropertyChanged; \ No newline at end of file diff --git a/RGB.NET.Core/Misc/AbstractReferenceCounting.cs b/RGB.NET.Core/Misc/AbstractReferenceCounting.cs index 09d64ef4..f55c56ab 100644 --- a/RGB.NET.Core/Misc/AbstractReferenceCounting.cs +++ b/RGB.NET.Core/Misc/AbstractReferenceCounting.cs @@ -6,7 +6,7 @@ public abstract class AbstractReferenceCounting : IReferenceCounting { #region Properties & Fields - private readonly HashSet _referencingObjects = new(); + private readonly HashSet _referencingObjects = []; /// public int ActiveReferenceCount diff --git a/RGB.NET.Core/Misc/ActionDisposable.cs b/RGB.NET.Core/Misc/ActionDisposable.cs index 843605e0..7844a571 100644 --- a/RGB.NET.Core/Misc/ActionDisposable.cs +++ b/RGB.NET.Core/Misc/ActionDisposable.cs @@ -2,26 +2,11 @@ namespace RGB.NET.Core; -public sealed class ActionDisposable : IDisposable +public sealed class ActionDisposable(Action onDispose) : IDisposable { - #region Properties & Fields - - private readonly Action _onDispose; - - #endregion - - #region Constructors - - public ActionDisposable(Action onDispose) - { - this._onDispose = onDispose; - } - - #endregion - #region Methods - public void Dispose() => _onDispose(); + public void Dispose() => onDispose(); #endregion } \ No newline at end of file diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index 8219191b..5c3387fc 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -22,7 +22,7 @@ public sealed class RGBSurface : AbstractBindable, IDisposable private readonly IList _devices = new List(); private readonly IList _updateTriggers = new List(); - private readonly List _ledGroups = new(); + private readonly List _ledGroups = []; /// /// Gets a readonly list containing all loaded . @@ -184,7 +184,7 @@ public void Dispose() { List devices; lock (Devices) - devices = new List(_devices); + devices = [.._devices]; foreach (IRGBDevice device in devices) try { Detach(device); } diff --git a/RGB.NET.Core/Update/CustomUpdateData.cs b/RGB.NET.Core/Update/CustomUpdateData.cs index 4888cd1b..736723a8 100644 --- a/RGB.NET.Core/Update/CustomUpdateData.cs +++ b/RGB.NET.Core/Update/CustomUpdateData.cs @@ -52,7 +52,7 @@ public sealed class CustomUpdateData : ICustomUpdateData { #region Properties & Fields - private readonly Dictionary _data = new(); + private readonly Dictionary _data = []; #endregion diff --git a/RGB.NET.Core/Update/Devices/IUpdateQueue.cs b/RGB.NET.Core/Update/Devices/IUpdateQueue.cs index 29433790..03a3e65e 100644 --- a/RGB.NET.Core/Update/Devices/IUpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/IUpdateQueue.cs @@ -31,5 +31,4 @@ public interface IUpdateQueue : IReferenceCounting, IDisposa /// /// Represents a generic update queue processing -data using -identifiers. /// -public interface IUpdateQueue : IUpdateQueue -{ } \ No newline at end of file +public interface IUpdateQueue : IUpdateQueue; \ No newline at end of file diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index c17e3a9f..22ef7f9e 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -16,7 +16,7 @@ public abstract class UpdateQueue : AbstractReferenceCountin private readonly object _dataLock = new(); private readonly IDeviceUpdateTrigger _updateTrigger; - private readonly Dictionary _currentDataSet = new(); + private readonly Dictionary _currentDataSet = []; /// public bool RequiresFlush { get; private set; } diff --git a/RGB.NET.Devices.Asus/Generic/IAsusRGBDevice.cs b/RGB.NET.Devices.Asus/Generic/IAsusRGBDevice.cs index cb7d4a93..027c83a5 100644 --- a/RGB.NET.Devices.Asus/Generic/IAsusRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Generic/IAsusRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Asus; /// /// Represents a asus RGB-device. /// -public interface IAsusRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface IAsusRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs index ee5f5498..12004290 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs @@ -25,8 +25,8 @@ public sealed class AsusKeyboardRGBDevice : AsusRGBDevice? _ledMapping; - private readonly Dictionary _ledAsusLed = new(); - private readonly Dictionary _ledAsusLights = new(); + private readonly Dictionary _ledAsusLed = []; + private readonly Dictionary _ledAsusLights = []; IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo; @@ -35,11 +35,11 @@ public sealed class AsusKeyboardRGBDevice : AsusRGBDeviceNote: These LED mappings should be based on light indexes. /// // ReSharper disable once InconsistentNaming - public static readonly List ExtraLedMappings = new() - { - new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15), - new AsusKeyboardExtraMapping(new Regex("(ROG Strix G513QM).*?"), LedMappings.ROGStrixG15) - }; + public static readonly List ExtraLedMappings = + [ + new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15), + new AsusKeyboardExtraMapping(new Regex("(ROG Strix G513QM).*?"), LedMappings.ROGStrixG15) + ]; #endregion @@ -66,7 +66,7 @@ internal AsusKeyboardRGBDevice(AsusKeyboardRGBDeviceInfo info, LedMapping to get the real model /// - private static readonly List GENERIC_DEVICE_NAMES = new() { "NotebookKeyboard" }; + private static readonly List GENERIC_DEVICE_NAMES = ["NotebookKeyboard"]; /// public KeyboardLayoutType Layout => KeyboardLayoutType.Unknown; diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index 8678e1a1..cecc41d1 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -37,13 +37,13 @@ public static CoolerMasterDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/CMSDK.dll" }; + public static List PossibleX86NativePaths { get; } = ["x86/CMSDK.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/CMSDK.dll" }; + public static List PossibleX64NativePaths { get; } = ["x64/CMSDK.dll"]; #endregion diff --git a/RGB.NET.Devices.CoolerMaster/Generic/ICoolerMasterRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Generic/ICoolerMasterRGBDevice.cs index 5cf66bba..8c1fb926 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/ICoolerMasterRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/ICoolerMasterRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.CoolerMaster; /// /// Represents a CoolerMaster RGB-device. /// -public interface ICoolerMasterRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface ICoolerMasterRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs index 6b51c39a..6be82b07 100644 --- a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs +++ b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs @@ -16,14 +16,14 @@ internal static class _CoolerMasterSDK { #region Libary Management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; /// /// Reloads the SDK. /// internal static void Reload() { - if (_handle != IntPtr.Zero) + if (_handle != 0) { foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes))) EnableLedControl(false, index); @@ -34,7 +34,7 @@ internal static void Reload() private static void LoadCMSDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; // HACK: Load library at runtime to support both, x86 and x64 with one managed dll List possiblePathList = (Environment.Is64BitProcess ? CoolerMasterDeviceProvider.PossibleX64NativePaths : CoolerMasterDeviceProvider.PossibleX86NativePaths) @@ -47,7 +47,7 @@ private static void LoadCMSDK() #if NET6_0 if (_handle == IntPtr.Zero) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastPInvokeError()}"); #else - if (_handle == IntPtr.Zero) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastWin32Error()}"); + if (_handle == 0) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastWin32Error()}"); #endif _getSDKVersionPointer = (GetSDKVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_handle, "GetCM_SDK_DllVer"), typeof(GetSDKVersionPointer)); @@ -62,7 +62,7 @@ private static void LoadCMSDK() internal static void UnloadCMSDK() { - if (_handle == IntPtr.Zero) return; + if (_handle == 0) return; _getSDKVersionPointer = null; _setControlDevicenPointer = null; @@ -74,14 +74,14 @@ internal static void UnloadCMSDK() _setAllLedColorPointer = null; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] - private static extern IntPtr LoadLibrary(string dllToLoad); + private static extern nint LoadLibrary(string dllToLoad); [DllImport("kernel32.dll", CharSet = CharSet.Ansi)] - private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name); + private static extern nint GetProcAddress(nint dllHandle, string name); #endregion diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 3a4a4dac..4dba9ea8 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -37,13 +37,13 @@ public static CorsairDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/iCUESDK.dll", "x86/CUESDK_2019.dll" }; + public static List PossibleX86NativePaths { get; } = ["x86/iCUESDK.dll", "x86/CUESDK_2019.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/iCUESDK.dll", "x64/iCUESDK.x64_2019.dll", "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll" }; + public static List PossibleX64NativePaths { get; } = ["x64/iCUESDK.dll", "x64/iCUESDK.x64_2019.dll", "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll"]; /// /// Gets or sets the timeout used when connecting to the SDK. diff --git a/RGB.NET.Devices.Corsair/Generic/LedMappings.cs b/RGB.NET.Devices.Corsair/Generic/LedMappings.cs index f37ec876..58e99376 100644 --- a/RGB.NET.Devices.Corsair/Generic/LedMappings.cs +++ b/RGB.NET.Devices.Corsair/Generic/LedMappings.cs @@ -165,7 +165,7 @@ internal static class LedMappings internal static LedMapping CreateMapping(IEnumerable ids, LedId referenceId) { - LedMapping mapping = new(); + LedMapping mapping = []; int counter = 0; foreach (CorsairLedId corsairLedId in ids.OrderBy(x => x)) mapping.Add(referenceId + counter++, corsairLedId); diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs index f598d27c..c2005c50 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceFilter.cs @@ -19,6 +19,7 @@ internal sealed class _CorsairDeviceFilter /// /// iCUE-SDK: mask that describes device types, formed as logical “or” of CorsairDeviceType enum values /// + // ReSharper disable once NotAccessedField.Global internal CorsairDeviceType deviceTypeMask; #endregion diff --git a/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs b/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs index f82bec28..9f770e8e 100644 --- a/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs @@ -38,13 +38,13 @@ public static CorsairLegacyDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/CUESDK.dll", "x86/CUESDK_2019.dll", "x86/CUESDK_2017.dll", "x86/CUESDK_2015.dll", "x86/CUESDK_2013.dll" }; + public static List PossibleX86NativePaths { get; } = ["x86/CUESDK.dll", "x86/CUESDK_2019.dll", "x86/CUESDK_2017.dll", "x86/CUESDK_2015.dll", "x86/CUESDK_2013.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll", "x64/CUESDK.x64_2017.dll", "x64/CUESDK_2019.dll", "x64/CUESDK_2017.dll", "x64/CUESDK_2015.dll", "x64/CUESDK_2013.dll" }; + public static List PossibleX64NativePaths { get; } = ["x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll", "x64/CUESDK.x64_2017.dll", "x64/CUESDK_2019.dll", "x64/CUESDK_2017.dll", "x64/CUESDK_2015.dll", "x64/CUESDK_2013.dll"]; /// /// Gets the protocol details for the current SDK-connection. @@ -170,7 +170,7 @@ private IEnumerable LoadCorsairDevices() foreach (_CorsairChannelInfo channelInfo in channels) { int channelDeviceInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelDeviceInfo)); - IntPtr channelDeviceInfoPtr = channelInfo.devices; + nint channelDeviceInfoPtr = channelInfo.devices; for (int device = 0; (device < channelInfo.devicesCount) && (ledOffset < nativeDeviceInfo.ledsCount); device++) { _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo))!; @@ -178,7 +178,7 @@ private IEnumerable LoadCorsairDevices() yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(i, nativeDeviceInfo, channelDeviceInfo, ledOffset), updateQueue); ledOffset += channelDeviceInfo.deviceLedCount; - channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize); + channelDeviceInfoPtr += channelDeviceInfoStructSize; } } break; @@ -195,13 +195,13 @@ private static IEnumerable<_CorsairChannelInfo> GetChannels(_CorsairDeviceInfo d _CorsairChannelsInfo? channelsInfo = deviceInfo.channels; if (channelsInfo == null) yield break; - IntPtr channelInfoPtr = channelsInfo.channels; + nint channelInfoPtr = channelsInfo.channels; for (int channel = 0; channel < channelsInfo.channelsCount; channel++) { yield return (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo))!; int channelInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelInfo)); - channelInfoPtr = new IntPtr(channelInfoPtr.ToInt64() + channelInfoStructSize); + channelInfoPtr += channelInfoStructSize; } } diff --git a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs index c285e5a6..cc2b57b5 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDevice.cs @@ -1,7 +1,6 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global -using System; using System.Linq; using System.Runtime.InteropServices; using RGB.NET.Core; @@ -24,7 +23,7 @@ public class CorsairCustomRGBDevice : CorsairRGBDeviceThe specific information provided by CUE for the custom-device. /// The queue used to update this device. internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) - : base(info, new LedMapping(), updateQueue) + : base(info, [], updateQueue) { } #endregion @@ -40,7 +39,7 @@ protected override void InitializeLayout() if (nativeLedPositions == null) return; int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); - IntPtr ptr = new(nativeLedPositions.pLedPosition.ToInt64() + (structSize * DeviceInfo.LedOffset)); + nint ptr = nativeLedPositions.pLedPosition + (structSize * DeviceInfo.LedOffset); LedId referenceLedId = GetReferenceLed(DeviceInfo.DeviceType); for (int i = 0; i < DeviceInfo.LedCount; i++) @@ -49,7 +48,7 @@ protected override void InitializeLayout() _CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition)); if (ledPosition == null) { - ptr = new IntPtr(ptr.ToInt64() + structSize); + ptr += structSize; continue; } @@ -60,7 +59,7 @@ protected override void InitializeLayout() Rectangle rectangle = ledPosition.ToRectangle(); AddLed(ledId, rectangle.Location, rectangle.Size); - ptr = new IntPtr(ptr.ToInt64() + structSize); + ptr += structSize; } if (DeviceInfo.LedOffset > 0) diff --git a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs index 3664f0d6..783089e9 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs @@ -41,7 +41,7 @@ public class CorsairCustomRGBDeviceInfo : CorsairRGBDeviceInfo /// The offset used to find the LEDs of this device. internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, int ledOffset) : base(deviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo, - GetModelName(nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase), channelDeviceInfo)) + GetModelName(nativeInfo.model == 0 ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase), channelDeviceInfo)) { this.LedOffset = ledOffset; diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs index 6282932b..a7669117 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairDeviceUpdateQueue.cs @@ -40,8 +40,8 @@ protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSe try { int structSize = Marshal.SizeOf(typeof(_CorsairLedColor)); - IntPtr ptr = Marshal.AllocHGlobal(structSize * dataSet.Length); - IntPtr addPtr = new(ptr.ToInt64()); + nint ptr = Marshal.AllocHGlobal(structSize * dataSet.Length); + nint addPtr = ptr; try { foreach ((object key, Color color) in dataSet) @@ -55,7 +55,7 @@ protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSe }; Marshal.StructureToPtr(corsairColor, addPtr, false); - addPtr = new IntPtr(addPtr.ToInt64() + structSize); + addPtr += structSize; } _CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Length, ptr); diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs index f2cd5207..8bab4b46 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairProtocolDetails.cs @@ -1,7 +1,6 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedAutoPropertyAccessor.Global -using System; using System.Runtime.InteropServices; using RGB.NET.Devices.CorsairLegacy.Native; @@ -54,8 +53,8 @@ public class CorsairProtocolDetails /// The native CorsairProtocolDetails-struct internal CorsairProtocolDetails(_CorsairProtocolDetails nativeDetails) { - this.SdkVersion = nativeDetails.sdkVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.sdkVersion); - this.ServerVersion = nativeDetails.serverVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.serverVersion); + this.SdkVersion = nativeDetails.sdkVersion == 0 ? null : Marshal.PtrToStringAnsi(nativeDetails.sdkVersion); + this.ServerVersion = nativeDetails.serverVersion == 0 ? null : Marshal.PtrToStringAnsi(nativeDetails.serverVersion); this.SdkProtocolVersion = nativeDetails.sdkProtocolVersion; this.ServerProtocolVersion = nativeDetails.serverProtocolVersion; this.BreakingChanges = nativeDetails.breakingChanges != 0; diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs index fb9aa2ed..e86a92ae 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDevice.cs @@ -1,5 +1,4 @@ -using System; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; using RGB.NET.Core; using RGB.NET.Devices.CorsairLegacy.Native; @@ -50,14 +49,14 @@ protected virtual void InitializeLayout() if (nativeLedPositions == null) return; int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); - IntPtr ptr = nativeLedPositions.pLedPosition; + nint ptr = nativeLedPositions.pLedPosition; for (int i = 0; i < nativeLedPositions.numberOfLed; i++) { _CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition)); if (ledPosition == null) { - ptr = new IntPtr(ptr.ToInt64() + structSize); + ptr += structSize; continue; } @@ -65,7 +64,7 @@ protected virtual void InitializeLayout() Rectangle rectangle = ledPosition.ToRectangle(); AddLed(ledId, rectangle.Location, rectangle.Size); - ptr = new IntPtr(ptr.ToInt64() + structSize); + ptr += structSize; } } diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs index f35a65c6..87151855 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/CorsairRGBDeviceInfo.cs @@ -1,5 +1,4 @@ -using System; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; using System.Text.RegularExpressions; using RGB.NET.Core; using RGB.NET.Devices.CorsairLegacy.Native; @@ -65,7 +64,7 @@ internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _Corsai this.CorsairDeviceIndex = deviceIndex; this.DeviceType = deviceType; this.CorsairDeviceType = nativeInfo.type; - this.Model = nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase); + this.Model = nativeInfo.model == 0 ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase); this.DeviceId = nativeInfo.deviceId ?? string.Empty; this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask; diff --git a/RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs b/RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs index ca2da702..d528c2e7 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Generic/LedMappings.cs @@ -34,27 +34,27 @@ static LedMappings() /// /// Gets the mapping for graphics cards. /// - public static LedMapping GraphicsCard { get; } = new(); + public static LedMapping GraphicsCard { get; } = []; /// /// Gets the mapping for headsets. /// - public static LedMapping HeadsetStand { get; } = new(); + public static LedMapping HeadsetStand { get; } = []; /// /// Gets the mapping for mainboards. /// - public static LedMapping Mainboard { get; } = new(); + public static LedMapping Mainboard { get; } = []; /// /// Gets the mapping for memory. /// - public static LedMapping Memory { get; } = new(); + public static LedMapping Memory { get; } = []; /// /// Gets the mapping for mousepads. /// - public static LedMapping Mousepad { get; } = new(); + public static LedMapping Mousepad { get; } = []; /// /// Gets the mapping for headsets. diff --git a/RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs b/RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs index e153e7a4..0da20e5e 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Helper/NativeExtensions.cs @@ -7,7 +7,7 @@ internal static class NativeExtensions { internal static Rectangle ToRectangle(this _CorsairLedPosition position) { - //HACK DarthAffe 08.07.2018: It seems like corsair introduced a bug here - it's always 0. + //HACK DarthAffe 08.07.2018: It seems like corsair introduced a issue here - it's always 0. float width = position.width < 0.5f ? 10 : (float)position.width; float height = position.height < 0.5f ? 10 : (float)position.height; float posX = (float)position.left; diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs index 718f446d..3ace4359 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs @@ -16,7 +16,7 @@ internal static class _CUESDK { #region Libary Management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; /// /// Reloads the SDK. @@ -29,7 +29,7 @@ internal static void Reload() private static void LoadCUESDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; List possiblePathList = GetPossibleLibraryPaths().ToList(); @@ -71,23 +71,23 @@ private static IEnumerable GetPossibleLibraryPaths() internal static void UnloadCUESDK() { - if (_handle == IntPtr.Zero) return; - - _corsairSetLedsColorsBufferByDeviceIndexPointer = IntPtr.Zero; - _corsairSetLedsColorsFlushBufferPointer = IntPtr.Zero; - _corsairGetLedsColorsByDeviceIndexPointer = IntPtr.Zero; - _corsairSetLayerPriorityPointer = IntPtr.Zero; - _corsairGetDeviceCountPointer = IntPtr.Zero; - _corsairGetDeviceInfoPointer = IntPtr.Zero; - _corsairGetLedIdForKeyNamePointer = IntPtr.Zero; - _corsairGetLedPositionsByDeviceIndexPointer = IntPtr.Zero; - _corsairRequestControlPointer = IntPtr.Zero; - _corsairReleaseControlPointer = IntPtr.Zero; - _corsairPerformProtocolHandshakePointer = IntPtr.Zero; - _corsairGetLastErrorPointer = IntPtr.Zero; + if (_handle == 0) return; + + _corsairSetLedsColorsBufferByDeviceIndexPointer = 0; + _corsairSetLedsColorsFlushBufferPointer = 0; + _corsairGetLedsColorsByDeviceIndexPointer = 0; + _corsairSetLayerPriorityPointer = 0; + _corsairGetDeviceCountPointer = 0; + _corsairGetDeviceInfoPointer = 0; + _corsairGetLedIdForKeyNamePointer = 0; + _corsairGetLedPositionsByDeviceIndexPointer = 0; + _corsairRequestControlPointer = 0; + _corsairReleaseControlPointer = 0; + _corsairPerformProtocolHandshakePointer = 0; + _corsairGetLastErrorPointer = 0; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } #endregion @@ -96,18 +96,18 @@ internal static void UnloadCUESDK() #region Pointers - private static IntPtr _corsairSetLedsColorsBufferByDeviceIndexPointer; - private static IntPtr _corsairSetLedsColorsFlushBufferPointer; - private static IntPtr _corsairGetLedsColorsByDeviceIndexPointer; - private static IntPtr _corsairSetLayerPriorityPointer; - private static IntPtr _corsairGetDeviceCountPointer; - private static IntPtr _corsairGetDeviceInfoPointer; - private static IntPtr _corsairGetLedIdForKeyNamePointer; - private static IntPtr _corsairGetLedPositionsByDeviceIndexPointer; - private static IntPtr _corsairRequestControlPointer; - private static IntPtr _corsairReleaseControlPointer; - private static IntPtr _corsairPerformProtocolHandshakePointer; - private static IntPtr _corsairGetLastErrorPointer; + private static nint _corsairSetLedsColorsBufferByDeviceIndexPointer; + private static nint _corsairSetLedsColorsFlushBufferPointer; + private static nint _corsairGetLedsColorsByDeviceIndexPointer; + private static nint _corsairSetLayerPriorityPointer; + private static nint _corsairGetDeviceCountPointer; + private static nint _corsairGetDeviceInfoPointer; + private static nint _corsairGetLedIdForKeyNamePointer; + private static nint _corsairGetLedPositionsByDeviceIndexPointer; + private static nint _corsairRequestControlPointer; + private static nint _corsairReleaseControlPointer; + private static nint _corsairPerformProtocolHandshakePointer; + private static nint _corsairGetLastErrorPointer; #endregion @@ -118,8 +118,8 @@ internal static void UnloadCUESDK() /// and follows after one or more calls of CorsairSetLedsColorsBufferByDeviceIndex to set the LEDs buffer. /// This function does not take logical layout into account. /// - internal static unsafe bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairSetLedsColorsBufferByDeviceIndexPointer))(deviceIndex, size, ledsColors); + internal static unsafe bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIndex, int size, nint ledsColors) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairSetLedsColorsBufferByDeviceIndexPointer))(deviceIndex, size, ledsColors); /// /// CUE-SDK: writes to the devices LEDs colors buffer which is previously filled by the CorsairSetLedsColorsBufferByDeviceIndex function. @@ -132,8 +132,8 @@ internal static unsafe bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIn /// The color should represent the actual state of the hardware LED, which could be a combination of SDK and/or CUE input. /// This function works for keyboard, mouse, mousemat, headset, headset stand and DIY-devices. /// - internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedsColorsByDeviceIndexPointer))(deviceIndex, size, ledsColors); + internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, int size, nint ledsColors) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedsColorsByDeviceIndexPointer))(deviceIndex, size, ledsColors); /// /// CUE-SDK: set layer priority for this shared client. @@ -150,12 +150,12 @@ internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, i /// /// CUE-SDK: returns information about device at provided index. /// - internal static unsafe IntPtr CorsairGetDeviceInfo(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetDeviceInfoPointer))(deviceIndex); + internal static unsafe nint CorsairGetDeviceInfo(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetDeviceInfoPointer))(deviceIndex); /// /// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions. /// - internal static unsafe IntPtr CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedPositionsByDeviceIndexPointer))(deviceIndex); + internal static unsafe nint CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLedPositionsByDeviceIndexPointer))(deviceIndex); /// /// CUE-SDK: retrieves led id for key name taking logical layout into account. @@ -183,9 +183,9 @@ internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, i /// internal static unsafe CorsairError CorsairGetLastError() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_corsairGetLastErrorPointer))(); - private static IntPtr ThrowIfZero(IntPtr ptr) + private static nint ThrowIfZero(nint ptr) { - if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Corsair-SDK is not initialized."); + if (ptr == 0) throw new RGBDeviceException("The Corsair-SDK is not initialized."); return ptr; } diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs index c30bfe6a..82c07b85 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelInfo.cs @@ -3,7 +3,6 @@ #pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable IDE1006 // Naming Styles -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.CorsairLegacy.Native; @@ -29,5 +28,5 @@ internal class _CorsairChannelInfo /// CUE-SDK: array containing information about each separate LED-device connected to the channel controlled by the DIY device. /// Index of the LED-device in array is same as the index of the LED-device connected to the DIY-device. /// - internal IntPtr devices; + internal nint devices; } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs index 61900b92..3dd7d04b 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairChannelsInfo.cs @@ -3,7 +3,6 @@ #pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable IDE1006 // Naming Styles -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.CorsairLegacy.Native; @@ -24,5 +23,5 @@ internal class _CorsairChannelsInfo /// CUE-SDK: array containing information about each separate channel of the DIY-device. /// Index of the channel in the array is same as index of the channel on the DIY-device. /// - internal IntPtr channels; + internal nint channels; } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs index af3c03e7..f2f7eb80 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairDeviceInfo.cs @@ -3,7 +3,6 @@ #pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable IDE1006 // Naming Styles -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.CorsairLegacy.Native; @@ -23,7 +22,7 @@ internal class _CorsairDeviceInfo /// /// CUE-SDK: null - terminated device model(like “K95RGB”) /// - internal IntPtr model; + internal nint model; /// /// CUE-SDK: enum describing physical layout of the keyboard or mouse diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs index db3d41d6..a3f0dbd0 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairLedPositions.cs @@ -2,7 +2,6 @@ #pragma warning disable 414 // Field 'x' is assigned but its value never used #pragma warning disable 649 // Field 'x' is never assigned -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.CorsairLegacy.Native; @@ -22,5 +21,5 @@ internal class _CorsairLedPositions /// /// CUE-SDK: array of led positions /// - internal IntPtr pLedPosition; + internal nint pLedPosition; } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs index 23a54777..5b85faad 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CorsairProtocolDetails.cs @@ -2,7 +2,6 @@ #pragma warning disable 414 // Field 'x' is assigned but its value never used #pragma warning disable 649 // Field 'x' is never assigned -using System; using System.Runtime.InteropServices; namespace RGB.NET.Devices.CorsairLegacy.Native; @@ -17,12 +16,12 @@ internal struct _CorsairProtocolDetails /// /// CUE-SDK: null - terminated string containing version of SDK(like “1.0.0.1”). Always contains valid value even if there was no CUE found /// - internal IntPtr sdkVersion; + internal nint sdkVersion; /// /// CUE-SDK: null - terminated string containing version of CUE(like “1.0.0.1”) or NULL if CUE was not found. /// - internal IntPtr serverVersion; + internal nint serverVersion; /// /// CUE-SDK: integer number that specifies version of protocol that is implemented by current SDK. diff --git a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs index d5f2456a..b5d725c3 100644 --- a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs +++ b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs @@ -35,7 +35,7 @@ public static DMXDeviceProvider Instance /// /// Gets a list of all defined device-definitions. /// - public List DeviceDefinitions { get; } = new(); + public List DeviceDefinitions { get; } = []; #endregion diff --git a/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs b/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs index 8e0934bb..b8b8336d 100644 --- a/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs +++ b/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs @@ -55,7 +55,7 @@ public sealed class E131DMXDeviceDefinition : IDMXDeviceDefinition /// /// Gets or sets the led-mappings used to create the device. /// - public Dictionary getValueFunc)>> Leds { get; } = new(); + public Dictionary getValueFunc)>> Leds { get; } = []; /// /// The time in ms after which the device is updated even if no changes are made in the meantime to prevent the target from timing out or similar problems. diff --git a/RGB.NET.Devices.DMX/Generic/IDMXDeviceDefinition.cs b/RGB.NET.Devices.DMX/Generic/IDMXDeviceDefinition.cs index 5ec87dfc..0700b3f5 100644 --- a/RGB.NET.Devices.DMX/Generic/IDMXDeviceDefinition.cs +++ b/RGB.NET.Devices.DMX/Generic/IDMXDeviceDefinition.cs @@ -3,5 +3,4 @@ /// /// Marker interface for DMX device definitions. /// -public interface IDMXDeviceDefinition -{ } \ No newline at end of file +public interface IDMXDeviceDefinition; \ No newline at end of file diff --git a/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs b/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs index aa1aa296..4f9359f2 100644 --- a/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs +++ b/RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs @@ -5,20 +5,12 @@ namespace RGB.NET.Devices.DMX; -internal sealed class LedChannelMapping : IEnumerable<(int channel, Func getValue)> +internal sealed class LedChannelMapping(List<(int channel, Func getValue)> mappings) + : IEnumerable<(int channel, Func getValue)> { #region Properties & Fields - private readonly List<(int channel, Func getValue)> _mappings; - - #endregion - - #region Constructors - - public LedChannelMapping(List<(int channel, Func getValue)> mappings) - { - this._mappings = new List<(int channel, Func getValue)>(mappings); - } + private readonly List<(int channel, Func getValue)> _mappings = [..mappings]; #endregion diff --git a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs index 836c6db6..636e57f9 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs @@ -32,7 +32,7 @@ public static DebugDeviceProvider Instance } } - private List<(IDeviceLayout layout, Action>? updateLedsAction)> _fakeDeviceDefinitions = new(); + private readonly List<(IDeviceLayout layout, Action>? updateLedsAction)> _fakeDeviceDefinitions = []; #endregion diff --git a/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs b/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs index 2789821c..df86acca 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceUpdateQueue.cs @@ -3,16 +3,8 @@ namespace RGB.NET.Devices.Debug; -internal sealed class DebugDeviceUpdateQueue : UpdateQueue +internal sealed class DebugDeviceUpdateQueue() : UpdateQueue(new DeviceUpdateTrigger()) { - #region Constructors - - public DebugDeviceUpdateQueue() - : base(new DeviceUpdateTrigger()) - { } - - #endregion - #region Methods protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) => true; diff --git a/RGB.NET.Devices.Logitech/Generic/ILogitechRGBDevice.cs b/RGB.NET.Devices.Logitech/Generic/ILogitechRGBDevice.cs index 9ff7cc90..4bcdfe37 100644 --- a/RGB.NET.Devices.Logitech/Generic/ILogitechRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/Generic/ILogitechRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Logitech; /// /// Represents a logitech RGB-device. /// -public interface ILogitechRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface ILogitechRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs b/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs index 355e4573..de498815 100644 --- a/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs +++ b/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs @@ -23,20 +23,20 @@ public sealed class LightspeedHIDLoader : IEnumerable RECEIVER_PIDS = new() - { - 0xC539, - 0xC53A, - 0xC541, - 0xC545, - 0xC547 - }; + private static readonly List RECEIVER_PIDS = + [ + 0xC539, + 0xC53A, + 0xC541, + 0xC545, + 0xC547 + ]; #endregion #region Properties & Fields - private readonly Dictionary> _deviceDefinitions = new(); + private readonly Dictionary> _deviceDefinitions = []; /// /// Gets the vendor id used for this loader. @@ -117,7 +117,7 @@ private Dictionary GetWirelessDevices(IReadOnlyDictionary map = new(); + Dictionary map = []; if (!deviceUsages.TryGetValue(1, out HidDevice? device) || !device.TryOpen(out HidStream stream)) return map; diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs index 4a12b395..22411f80 100644 --- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs +++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs @@ -40,13 +40,13 @@ public static LogitechDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/LogitechLedEnginesWrapper.dll" }; + public static List PossibleX86NativePaths { get; } = ["x86/LogitechLedEnginesWrapper.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/LogitechLedEnginesWrapper.dll" }; + public static List PossibleX64NativePaths { get; } = ["x64/LogitechLedEnginesWrapper.dll"]; private LogitechPerDeviceUpdateQueue? _perDeviceUpdateQueue; private LogitechPerKeyUpdateQueue? _perKeyUpdateQueue; @@ -162,7 +162,7 @@ public static LogitechDeviceProvider Instance /// /// Gets the HID-definitions for wireless per-device-devices. /// - public static LightspeedHIDLoader PerDeviceWirelessDeviceDefinitions { get; } = new(); + public static LightspeedHIDLoader PerDeviceWirelessDeviceDefinitions { get; } = []; #endregion diff --git a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs index 76efa36b..42ebb6cc 100644 --- a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs +++ b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs @@ -17,7 +17,7 @@ internal static class _LogitechGSDK { #region Libary Management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; /// /// Reloads the SDK. @@ -30,7 +30,7 @@ internal static void Reload() private static void LoadLogitechGSDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; List possiblePathList = GetPossibleLibraryPaths().ToList(); @@ -70,21 +70,21 @@ private static IEnumerable GetPossibleLibraryPaths() internal static void UnloadLogitechGSDK() { - if (_handle == IntPtr.Zero) return; - - _logiLedInitPointer = IntPtr.Zero; - _logiLedShutdownPointer = IntPtr.Zero; - _logiLedSetTargetDevicePointer = IntPtr.Zero; - _logiLedGetSdkVersionPointer = IntPtr.Zero; - _lgiLedSaveCurrentLightingPointer = IntPtr.Zero; - _logiLedRestoreLightingPointer = IntPtr.Zero; - _logiLedSetLightingPointer = IntPtr.Zero; - _logiLedSetLightingForKeyWithKeyNamePointer = IntPtr.Zero; - _logiLedSetLightingFromBitmapPointer = IntPtr.Zero; - _logiLedSetLightingForTargetZonePointer = IntPtr.Zero; + if (_handle == 0) return; + + _logiLedInitPointer = 0; + _logiLedShutdownPointer = 0; + _logiLedSetTargetDevicePointer = 0; + _logiLedGetSdkVersionPointer = 0; + _lgiLedSaveCurrentLightingPointer = 0; + _logiLedRestoreLightingPointer = 0; + _logiLedSetLightingPointer = 0; + _logiLedSetLightingForKeyWithKeyNamePointer = 0; + _logiLedSetLightingFromBitmapPointer = 0; + _logiLedSetLightingForTargetZonePointer = 0; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } #endregion @@ -93,16 +93,16 @@ internal static void UnloadLogitechGSDK() #region Pointers - private static IntPtr _logiLedInitPointer; - private static IntPtr _logiLedShutdownPointer; - private static IntPtr _logiLedSetTargetDevicePointer; - private static IntPtr _logiLedGetSdkVersionPointer; - private static IntPtr _lgiLedSaveCurrentLightingPointer; - private static IntPtr _logiLedRestoreLightingPointer; - private static IntPtr _logiLedSetLightingPointer; - private static IntPtr _logiLedSetLightingForKeyWithKeyNamePointer; - private static IntPtr _logiLedSetLightingFromBitmapPointer; - private static IntPtr _logiLedSetLightingForTargetZonePointer; + private static nint _logiLedInitPointer; + private static nint _logiLedShutdownPointer; + private static nint _logiLedSetTargetDevicePointer; + private static nint _logiLedGetSdkVersionPointer; + private static nint _lgiLedSaveCurrentLightingPointer; + private static nint _logiLedRestoreLightingPointer; + private static nint _logiLedSetLightingPointer; + private static nint _logiLedSetLightingForKeyWithKeyNamePointer; + private static nint _logiLedSetLightingFromBitmapPointer; + private static nint _logiLedSetLightingForTargetZonePointer; #endregion @@ -146,9 +146,9 @@ internal static unsafe bool LogiLedSetLightingFromBitmap(byte[] bitmap) internal static unsafe bool LogiLedSetLightingForTargetZone(LogitechDeviceType deviceType, int zone, int redPercentage, int greenPercentage, int bluePercentage) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_logiLedSetLightingForTargetZonePointer))(deviceType, zone, redPercentage, greenPercentage, bluePercentage); - private static IntPtr ThrowIfZero(IntPtr ptr) + private static nint ThrowIfZero(nint ptr) { - if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Logitech-SDK is not initialized."); + if (ptr == 0) throw new RGBDeviceException("The Logitech-SDK is not initialized."); return ptr; } diff --git a/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs b/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs index b8807531..b6b83613 100644 --- a/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Msi; /// /// Represents a MSI RGB-device. /// -public interface IMsiRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface IMsiRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index 1a305cc5..54be621b 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -37,13 +37,13 @@ public static MsiDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { "x86/MysticLight_SDK.dll" }; + public static List PossibleX86NativePaths { get; } = ["x86/MysticLight_SDK.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { "x64/MysticLight_SDK.dll" }; + public static List PossibleX64NativePaths { get; } = ["x64/MysticLight_SDK.dll"]; #endregion diff --git a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs index c13ef81f..1bc63fd6 100644 --- a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs +++ b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs @@ -16,7 +16,7 @@ internal static class _MsiSDK { #region Libary Management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; /// /// Reloads the SDK. @@ -29,7 +29,7 @@ internal static void Reload() private static void LoadMsiSDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; List possiblePathList = GetPossibleLibraryPaths().ToList(); @@ -75,7 +75,7 @@ private static IEnumerable GetPossibleLibraryPaths() internal static void UnloadMsiSDK() { - if (_handle == IntPtr.Zero) return; + if (_handle == 0) return; _initializePointer = null; _getDeviceInfoPointer = null; @@ -93,7 +93,7 @@ internal static void UnloadMsiSDK() _getErrorMessagePointer = null; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] diff --git a/RGB.NET.Devices.Novation/Generic/INovationRGBDevice.cs b/RGB.NET.Devices.Novation/Generic/INovationRGBDevice.cs index 6b8e05ca..e59696e4 100644 --- a/RGB.NET.Devices.Novation/Generic/INovationRGBDevice.cs +++ b/RGB.NET.Devices.Novation/Generic/INovationRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Novation; /// /// Represents a novation RGB-device. /// -public interface INovationRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface INovationRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.OpenRGB/Abstract/IOpenRGBDevice.cs b/RGB.NET.Devices.OpenRGB/Abstract/IOpenRGBDevice.cs index 7659d948..1235c909 100644 --- a/RGB.NET.Devices.OpenRGB/Abstract/IOpenRGBDevice.cs +++ b/RGB.NET.Devices.OpenRGB/Abstract/IOpenRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.OpenRGB; /// /// Represents a generic OpenRGB Device. /// -public interface IOpenRGBDevice : IRGBDevice -{ } +public interface IOpenRGBDevice : IRGBDevice; diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs index 4ad82cc6..26b3a2a9 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs @@ -17,7 +17,7 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider // ReSharper disable once InconsistentNaming private static readonly object _lock = new(); - private readonly List _clients = new(); + private readonly List _clients = []; private static OpenRGBDeviceProvider? _instance; @@ -36,7 +36,7 @@ public static OpenRGBDeviceProvider Instance /// /// Gets a list of all defined device-definitions. /// - public List DeviceDefinitions { get; } = new(); + public List DeviceDefinitions { get; } = []; /// /// Indicates whether all devices will be added, or just the ones with a 'Direct' mode. Defaults to false. diff --git a/RGB.NET.Devices.PicoPi/PicoPi/LedMappings.cs b/RGB.NET.Devices.PicoPi/PicoPi/LedMappings.cs index 85c6c0b4..937b6b8a 100644 --- a/RGB.NET.Devices.PicoPi/PicoPi/LedMappings.cs +++ b/RGB.NET.Devices.PicoPi/PicoPi/LedMappings.cs @@ -12,7 +12,7 @@ public static class LedMappings /// /// Gets the defautlt offset-mapping. /// - public static LedMapping StripeMapping = new(); + public static LedMapping StripeMapping = []; #endregion diff --git a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs index c7994609..ebcdff51 100644 --- a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs +++ b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs @@ -49,7 +49,7 @@ public static PicoPiDeviceProvider Instance { PicoPiSDK.HID_BULK_CONTROLLER_PID, RGBDeviceType.LedStripe, "WS2812B-Controller", LedMappings.StripeMapping, 0 }, }; - private readonly List _sdks = new(); + private readonly List _sdks = []; /// /// Gets or sets the endpoint used to update devices. (default ). diff --git a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs index 3d63bf02..17b7add5 100644 --- a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerChromaLinkUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.CHROMALINK_MAX_LEDS]; @@ -35,14 +35,14 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _ChromaLinkCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateChromaLinkEffect(_Defines.CHROMALINK_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateChromaLinkEffect(_Defines.CHROMALINK_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Generic/IRazerRGBDevice.cs b/RGB.NET.Devices.Razer/Generic/IRazerRGBDevice.cs index 35a38714..5ae8b822 100644 --- a/RGB.NET.Devices.Razer/Generic/IRazerRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Generic/IRazerRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Razer; /// /// Represents a razer RGB-device. /// -public interface IRazerRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface IRazerRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Generic/LedMappings.cs b/RGB.NET.Devices.Razer/Generic/LedMappings.cs index 373aae71..d1a3dabb 100644 --- a/RGB.NET.Devices.Razer/Generic/LedMappings.cs +++ b/RGB.NET.Devices.Razer/Generic/LedMappings.cs @@ -386,20 +386,20 @@ public static class LedMappings /// /// Gets the mapping for mousepads. /// - public static LedMapping Mousepad { get; } = new(); + public static LedMapping Mousepad { get; } = []; /// /// Gets the mapping for headsets. /// - public static LedMapping Headset { get; } = new(); + public static LedMapping Headset { get; } = []; /// /// Gets the mapping for keypads. /// - public static LedMapping Keypad { get; } = new(); + public static LedMapping Keypad { get; } = []; /// /// Gets the mapping for chroma link devices. /// - public static LedMapping ChromaLink { get; } = new(); + public static LedMapping ChromaLink { get; } = []; } diff --git a/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs b/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs index 105fee90..615e48b1 100644 --- a/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Generic/RazerUpdateQueue.cs @@ -34,7 +34,7 @@ protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSe { try { - IntPtr effectParams = CreateEffectParams(dataSet); + nint effectParams = CreateEffectParams(dataSet); Guid effectId = Guid.NewGuid(); CreateEffect(effectParams, ref effectId); @@ -60,7 +60,7 @@ protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSe /// /// The parameters of the effect. /// The id this effect is created with. - protected abstract void CreateEffect(IntPtr effectParams, ref Guid effectId); + protected abstract void CreateEffect(nint effectParams, ref Guid effectId); /// public override void Reset() @@ -77,7 +77,7 @@ public override void Reset() /// /// The data to be updated. /// An pointing to the effect parameter struct. - protected abstract IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet); + protected abstract nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs b/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs index 24cc57be..8ddbce31 100644 --- a/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerHeadsetUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.HEADSET_MAX_LEDS]; @@ -35,14 +35,14 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _HeadsetCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateHeadsetEffect(_Defines.HEADSET_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateHeadsetEffect(_Defines.HEADSET_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs index b351d5fa..68e0f5f7 100644 --- a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerKeyboardUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.KEYBOARD_MAX_LEDS]; @@ -34,14 +34,14 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _KeyboardCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateKeyboardEffect(_Defines.KEYBOARD_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateKeyboardEffect(_Defines.KEYBOARD_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs b/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs index 9b6908ae..7e2470e1 100644 --- a/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerKeypadUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS]; @@ -34,14 +34,14 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _KeypadCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateKeypadEffect(_Defines.KEYPAD_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateKeypadEffect(_Defines.KEYPAD_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs b/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs index 22295d0a..cbdde12b 100644 --- a/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerMouseUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.MOUSE_MAX_LEDS]; @@ -34,7 +34,7 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _MouseCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; @@ -42,7 +42,7 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateMouseEffect(_Defines.MOUSE_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateMouseEffect(_Defines.MOUSE_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs index 57d912af..8f510e43 100644 --- a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs +++ b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs @@ -25,7 +25,7 @@ public RazerMousepadUpdateQueue(IDeviceUpdateTrigger updateTrigger) #region Methods /// - protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) + protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.MOUSEPAD_MAX_LEDS]; @@ -34,14 +34,14 @@ protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color _MousepadCustomEffect effectParams = new() { Color = colors }; - IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); + nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } /// - protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateMousepadEffect(_Defines.MOUSEPAD_EFFECT_ID, effectParams, ref effectId); + protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateMousepadEffect(_Defines.MOUSEPAD_EFFECT_ID, effectParams, ref effectId); #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Native/_Color.cs b/RGB.NET.Devices.Razer/Native/_Color.cs index 6b792a04..c7d2167f 100644 --- a/RGB.NET.Devices.Razer/Native/_Color.cs +++ b/RGB.NET.Devices.Razer/Native/_Color.cs @@ -10,11 +10,12 @@ namespace RGB.NET.Devices.Razer.Native; // ReSharper disable once InconsistentNaming [StructLayout(LayoutKind.Sequential, Size = sizeof(uint))] -internal struct _Color +[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Native-naming")] +internal struct _Color(byte red, byte green, byte blue) { #region Properties & Fields - public uint Color; + public uint Color = red + ((uint)green << 8) + ((uint)blue << 16); #endregion @@ -23,11 +24,5 @@ internal struct _Color public _Color(Color color) : this(color.GetR(), color.GetG(), color.GetB()) { } - public _Color(byte red, byte green, byte blue) - : this() - { - Color = red + ((uint)green << 8) + ((uint)blue << 16); - } - #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/Native/_RazerSDK.cs b/RGB.NET.Devices.Razer/Native/_RazerSDK.cs index a94143db..4b99cc66 100644 --- a/RGB.NET.Devices.Razer/Native/_RazerSDK.cs +++ b/RGB.NET.Devices.Razer/Native/_RazerSDK.cs @@ -16,7 +16,7 @@ internal static class _RazerSDK { #region Libary Management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; /// /// Reloads the SDK. @@ -29,7 +29,7 @@ internal static void Reload() private static void LoadRazerSDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; List possiblePathList = GetPossibleLibraryPaths().ToList(); @@ -71,23 +71,23 @@ private static IEnumerable GetPossibleLibraryPaths() internal static void UnloadRazerSDK() { - if (_handle == IntPtr.Zero) return; - - _initPointer = IntPtr.Zero; - _unInitPointer = IntPtr.Zero; - _queryDevicePointer = IntPtr.Zero; - _createEffectPointer = IntPtr.Zero; - _createHeadsetEffectPointer = IntPtr.Zero; - _createChromaLinkEffectPointer = IntPtr.Zero; - _createKeyboardEffectPointer = IntPtr.Zero; - _createKeypadEffectPointer = IntPtr.Zero; - _createMouseEffectPointer = IntPtr.Zero; - _createMousepadEffectPointer = IntPtr.Zero; - _setEffectPointer = IntPtr.Zero; - _deleteEffectPointer = IntPtr.Zero; + if (_handle == 0) return; + + _initPointer = 0; + _unInitPointer = 0; + _queryDevicePointer = 0; + _createEffectPointer = 0; + _createHeadsetEffectPointer = 0; + _createChromaLinkEffectPointer = 0; + _createKeyboardEffectPointer = 0; + _createKeypadEffectPointer = 0; + _createMouseEffectPointer = 0; + _createMousepadEffectPointer = 0; + _setEffectPointer = 0; + _deleteEffectPointer = 0; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } #endregion @@ -96,18 +96,18 @@ internal static void UnloadRazerSDK() #region Pointers - private static IntPtr _initPointer; - private static IntPtr _unInitPointer; - private static IntPtr _queryDevicePointer; - private static IntPtr _createEffectPointer; - private static IntPtr _createHeadsetEffectPointer; - private static IntPtr _createChromaLinkEffectPointer; - private static IntPtr _createKeyboardEffectPointer; - private static IntPtr _createKeypadEffectPointer; - private static IntPtr _createMouseEffectPointer; - private static IntPtr _createMousepadEffectPointer; - private static IntPtr _setEffectPointer; - private static IntPtr _deleteEffectPointer; + private static nint _initPointer; + private static nint _unInitPointer; + private static nint _queryDevicePointer; + private static nint _createEffectPointer; + private static nint _createHeadsetEffectPointer; + private static nint _createChromaLinkEffectPointer; + private static nint _createKeyboardEffectPointer; + private static nint _createKeypadEffectPointer; + private static nint _createMouseEffectPointer; + private static nint _createMousepadEffectPointer; + private static nint _setEffectPointer; + private static nint _deleteEffectPointer; #endregion @@ -128,9 +128,9 @@ internal static unsafe RazerError UnInit() internal static unsafe RazerError QueryDevice(Guid deviceId, out _DeviceInfo deviceInfo) { int structSize = Marshal.SizeOf(typeof(_DeviceInfo)); - IntPtr deviceInfoPtr = Marshal.AllocHGlobal(structSize); + nint deviceInfoPtr = Marshal.AllocHGlobal(structSize); - RazerError error = ((delegate* unmanaged[Cdecl])ThrowIfZero(_queryDevicePointer))(deviceId, deviceInfoPtr); + RazerError error = ((delegate* unmanaged[Cdecl])ThrowIfZero(_queryDevicePointer))(deviceId, deviceInfoPtr); deviceInfo = (_DeviceInfo)Marshal.PtrToStructure(deviceInfoPtr, typeof(_DeviceInfo))!; Marshal.FreeHGlobal(deviceInfoPtr); @@ -138,26 +138,26 @@ internal static unsafe RazerError QueryDevice(Guid deviceId, out _DeviceInfo dev return error; } - internal static unsafe RazerError CreateEffect(Guid deviceId, int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createEffectPointer))(deviceId, effectType, param, ref effectId); + internal static unsafe RazerError CreateEffect(Guid deviceId, int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createEffectPointer))(deviceId, effectType, param, ref effectId); - internal static unsafe RazerError CreateHeadsetEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createHeadsetEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateHeadsetEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createHeadsetEffectPointer))(effectType, param, ref effectId); - internal static unsafe RazerError CreateChromaLinkEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createChromaLinkEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateChromaLinkEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createChromaLinkEffectPointer))(effectType, param, ref effectId); - internal static unsafe RazerError CreateKeyboardEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createKeyboardEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateKeyboardEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createKeyboardEffectPointer))(effectType, param, ref effectId); - internal static unsafe RazerError CreateKeypadEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createKeypadEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateKeypadEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createKeypadEffectPointer))(effectType, param, ref effectId); - internal static unsafe RazerError CreateMouseEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createMouseEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateMouseEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createMouseEffectPointer))(effectType, param, ref effectId); - internal static unsafe RazerError CreateMousepadEffect(int effectType, IntPtr param, ref Guid effectId) - => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createMousepadEffectPointer))(effectType, param, ref effectId); + internal static unsafe RazerError CreateMousepadEffect(int effectType, nint param, ref Guid effectId) + => ((delegate* unmanaged[Cdecl])ThrowIfZero(_createMousepadEffectPointer))(effectType, param, ref effectId); internal static unsafe RazerError SetEffect(Guid effectId) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_setEffectPointer))(effectId); @@ -165,9 +165,9 @@ internal static unsafe RazerError SetEffect(Guid effectId) internal static unsafe RazerError DeleteEffect(Guid effectId) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_deleteEffectPointer))(effectId); - private static IntPtr ThrowIfZero(IntPtr ptr) + private static nint ThrowIfZero(nint ptr) { - if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Razer-SDK is not initialized."); + if (ptr == 0) throw new RGBDeviceException("The Razer-SDK is not initialized."); return ptr; } diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 9abc8c82..28bd7da9 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -39,13 +39,13 @@ public static RazerDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new() { @"%systemroot%\SysWOW64\RzChromaSDK.dll" }; + public static List PossibleX86NativePaths { get; } = [@"%systemroot%\SysWOW64\RzChromaSDK.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new() { @"%systemroot%\System32\RzChromaSDK.dll", @"%systemroot%\System32\RzChromaSDK64.dll" }; + public static List PossibleX64NativePaths { get; } = [@"%systemroot%\System32\RzChromaSDK.dll", @"%systemroot%\System32\RzChromaSDK64.dll"]; /// /// Forces to load the devices represented by the emulator even if they aren't reported to exist. diff --git a/RGB.NET.Devices.SteelSeries/API/Model/Event.cs b/RGB.NET.Devices.SteelSeries/API/Model/Event.cs index 2862e941..c2aa064e 100644 --- a/RGB.NET.Devices.SteelSeries/API/Model/Event.cs +++ b/RGB.NET.Devices.SteelSeries/API/Model/Event.cs @@ -15,7 +15,7 @@ internal sealed class Event // ReSharper disable once CollectionNeverQueried.Global [JsonPropertyName("data")] - public Dictionary Data { get; } = new(); + public Dictionary Data { get; } = []; #endregion diff --git a/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs b/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs index d500a536..f0aff23d 100644 --- a/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs +++ b/RGB.NET.Devices.SteelSeries/Attribute/APIName.cs @@ -1,19 +1,10 @@ namespace RGB.NET.Devices.SteelSeries; -internal sealed class APIName : System.Attribute +internal sealed class APIName(string name) : System.Attribute { #region Properties & Fields - public string Name { get; set; } - - #endregion - - #region Constructors - - public APIName(string name) - { - this.Name = name; - } + public string Name { get; set; } = name; #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs b/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs index aef597b8..df89db97 100644 --- a/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs +++ b/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs @@ -10,8 +10,8 @@ internal static class SteelSeriesEnumExtension #region Properties & Fields // ReSharper disable InconsistentNaming - private static readonly Dictionary _deviceTypeNames = new(); - private static readonly Dictionary _ledIdNames = new(); + private static readonly Dictionary _deviceTypeNames = []; + private static readonly Dictionary _ledIdNames = []; // ReSharper restore InconsistentNaming #endregion diff --git a/RGB.NET.Devices.SteelSeries/Generic/ISteelSeriesRGBDevice.cs b/RGB.NET.Devices.SteelSeries/Generic/ISteelSeriesRGBDevice.cs index 86948692..736e0475 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/ISteelSeriesRGBDevice.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/ISteelSeriesRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.SteelSeries; /// /// Represents a steelseries RGB-device. /// -internal interface ISteelSeriesRGBDevice : IRGBDevice -{ } \ No newline at end of file +internal interface ISteelSeriesRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs index 2d035ff1..587c0708 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs @@ -21,7 +21,7 @@ public sealed class ArduinoWS2812USBUpdateQueue : SerialConnectionUpdateQueue _dataBuffer = new(); + private readonly Dictionary _dataBuffer = []; #endregion diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs index 131a879f..d4d18f8f 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs @@ -39,7 +39,7 @@ public sealed class BitwizardWS281XDeviceDefinition : IWS281XDeviceDefinition /// /// Gets a list of LED-strips configured on this device. /// - public List<(int pin, int stripLength)> Strips { get; } = new(); + public List<(int pin, int stripLength)> Strips { get; } = []; /// /// Gets or sets the amount of leds controlled by one pin. diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs index a78343c5..38a51f1a 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs @@ -23,8 +23,8 @@ public sealed class NodeMCUWS2812USBUpdateQueue : UpdateQueue private HttpClient _httpClient = new(); private UdpClient? _udpClient; - private readonly Dictionary _dataBuffer = new(); - private readonly Dictionary _sequenceNumbers = new(); + private readonly Dictionary _dataBuffer = []; + private readonly Dictionary _sequenceNumbers = []; private readonly Action _sendDataAction; diff --git a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs index e1500287..109877a2 100644 --- a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs +++ b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs @@ -37,7 +37,7 @@ public static WS281XDeviceProvider Instance /// // ReSharper disable once CollectionNeverUpdated.Global // ReSharper disable once ReturnTypeCanBeEnumerable.Global - public List DeviceDefinitions { get; } = new(); + public List DeviceDefinitions { get; } = []; #endregion diff --git a/RGB.NET.Devices.Wooting/Generic/IWootingRGBDevice.cs b/RGB.NET.Devices.Wooting/Generic/IWootingRGBDevice.cs index 89ab9b5e..c54544b7 100644 --- a/RGB.NET.Devices.Wooting/Generic/IWootingRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Generic/IWootingRGBDevice.cs @@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Wooting.Generic; /// /// Represents a Wooting RGB-device. /// -public interface IWootingRGBDevice : IRGBDevice -{ } \ No newline at end of file +public interface IWootingRGBDevice : IRGBDevice; \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs index 0258cf5b..cc0018c1 100644 --- a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs +++ b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs @@ -15,7 +15,7 @@ internal static class _WootingSDK { #region Library management - private static IntPtr _handle = IntPtr.Zero; + private static nint _handle = 0; internal static object SdkLock = new(); /// @@ -29,7 +29,7 @@ internal static void Reload() private static void LoadWootingSDK() { - if (_handle != IntPtr.Zero) return; + if (_handle != 0) return; List possiblePathList = GetPossibleLibraryPaths().ToList(); @@ -71,21 +71,21 @@ private static IEnumerable GetPossibleLibraryPaths() internal static void UnloadWootingSDK() { - if (_handle == IntPtr.Zero) return; + if (_handle == 0) return; Close(); - _getDeviceInfoPointer = IntPtr.Zero; - _keyboardConnectedPointer = IntPtr.Zero; - _resetPointer = IntPtr.Zero; - _closePointer = IntPtr.Zero; - _arrayUpdateKeyboardPointer = IntPtr.Zero; - _arraySetSinglePointer = IntPtr.Zero; - _getDeviceCountPointer = IntPtr.Zero; - _selectDevicePointer = IntPtr.Zero; + _getDeviceInfoPointer = 0; + _keyboardConnectedPointer = 0; + _resetPointer = 0; + _closePointer = 0; + _arrayUpdateKeyboardPointer = 0; + _arraySetSinglePointer = 0; + _getDeviceCountPointer = 0; + _selectDevicePointer = 0; NativeLibrary.Free(_handle); - _handle = IntPtr.Zero; + _handle = 0; } #endregion @@ -94,18 +94,18 @@ internal static void UnloadWootingSDK() #region Pointers - private static IntPtr _getDeviceInfoPointer; - private static IntPtr _keyboardConnectedPointer; - private static IntPtr _resetPointer; - private static IntPtr _closePointer; - private static IntPtr _arrayUpdateKeyboardPointer; - private static IntPtr _arraySetSinglePointer; - private static IntPtr _getDeviceCountPointer; - private static IntPtr _selectDevicePointer; + private static nint _getDeviceInfoPointer; + private static nint _keyboardConnectedPointer; + private static nint _resetPointer; + private static nint _closePointer; + private static nint _arrayUpdateKeyboardPointer; + private static nint _arraySetSinglePointer; + private static nint _getDeviceCountPointer; + private static nint _selectDevicePointer; #endregion - internal static unsafe IntPtr GetDeviceInfo() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_getDeviceInfoPointer))(); + internal static unsafe nint GetDeviceInfo() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_getDeviceInfoPointer))(); internal static unsafe bool KeyboardConnected() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_keyboardConnectedPointer))(); internal static unsafe bool Reset() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_resetPointer))(); internal static unsafe bool Close() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_closePointer))(); @@ -115,9 +115,9 @@ internal static unsafe bool ArraySetSingle(byte row, byte column, byte red, byte internal static unsafe byte GetDeviceCount() => ((delegate* unmanaged[Cdecl])ThrowIfZero(_getDeviceCountPointer))(); internal static unsafe void SelectDevice(byte index) => ((delegate* unmanaged[Cdecl])ThrowIfZero(_selectDevicePointer))(index); - private static IntPtr ThrowIfZero(IntPtr ptr) + private static nint ThrowIfZero(nint ptr) { - if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Wooting-SDK is not initialized."); + if (ptr == 0) throw new RGBDeviceException("The Wooting-SDK is not initialized."); return ptr; } diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index c92661f9..8b36ff75 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -38,26 +38,26 @@ public static WootingDeviceProvider Instance /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications. /// The first match will be used. /// - public static List PossibleX86NativePathsWindows { get; } = new() { "x86/wooting-rgb-sdk.dll" }; + public static List PossibleX86NativePathsWindows { get; } = ["x86/wooting-rgb-sdk.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 windows applications. /// The first match will be used. /// - public static List PossibleX64NativePathsWindows { get; } = new() { "x64/wooting-rgb-sdk64.dll" }; + public static List PossibleX64NativePathsWindows { get; } = ["x64/wooting-rgb-sdk64.dll"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 linux applications. /// The first match will be used. /// - public static List PossibleNativePathsLinux { get; } = new() { "x64/libwooting-rgb-sdk.so" }; + public static List PossibleNativePathsLinux { get; } = ["x64/libwooting-rgb-sdk.so"]; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 MacOS applications. /// The first match will be used. /// // ReSharper disable once InconsistentNaming - public static List PossibleNativePathsMacOS { get; } = new() { "x64/libwooting-rgb-sdk.dylib" }; + public static List PossibleNativePathsMacOS { get; } = ["x64/libwooting-rgb-sdk.dylib"]; #endregion diff --git a/RGB.NET.HID/HIDLoader.cs b/RGB.NET.HID/HIDLoader.cs index b39df671..987618d1 100644 --- a/RGB.NET.HID/HIDLoader.cs +++ b/RGB.NET.HID/HIDLoader.cs @@ -24,7 +24,7 @@ public sealed class HIDLoader : IEnumerable> _deviceDefinitions = new(); + private readonly Dictionary> _deviceDefinitions = []; /// /// Gets the vendor id used for this loader. diff --git a/RGB.NET.Layout/DeviceLayout.cs b/RGB.NET.Layout/DeviceLayout.cs index e33e7609..adf769d8 100644 --- a/RGB.NET.Layout/DeviceLayout.cs +++ b/RGB.NET.Layout/DeviceLayout.cs @@ -92,7 +92,7 @@ public class DeviceLayout : IDeviceLayout /// Normally you should use to access this data. /// [XmlArray("Leds")] - public List InternalLeds { get; set; } = new(); + public List InternalLeds { get; set; } = []; /// /// Gets or sets a list of representing all the of the . diff --git a/RGB.NET.Layout/LayoutExtension.cs b/RGB.NET.Layout/LayoutExtension.cs index 0426e3b7..0c5383cb 100644 --- a/RGB.NET.Layout/LayoutExtension.cs +++ b/RGB.NET.Layout/LayoutExtension.cs @@ -24,7 +24,7 @@ public static void ApplyTo(this IDeviceLayout layout, IRGBDevice device, bool cr device.Size = new Size(layout.Width, layout.Height); device.DeviceInfo.LayoutMetadata = layout.CustomData; - HashSet ledIds = new(); + HashSet ledIds = []; foreach (ILedLayout layoutLed in layout.Leds) { if (Enum.TryParse(layoutLed.Id, true, out LedId ledId)) diff --git a/RGB.NET.Presets/Decorators/IGradientDecorator.cs b/RGB.NET.Presets/Decorators/IGradientDecorator.cs index 9373e4ea..75631768 100644 --- a/RGB.NET.Presets/Decorators/IGradientDecorator.cs +++ b/RGB.NET.Presets/Decorators/IGradientDecorator.cs @@ -6,5 +6,4 @@ namespace RGB.NET.Presets.Decorators; /// /// Represents a basic decorator decorating a . /// -public interface IGradientDecorator : IDecorator -{ } \ No newline at end of file +public interface IGradientDecorator : IDecorator; \ No newline at end of file diff --git a/RGB.NET.Presets/Textures/Gradients/AbstractGradient.cs b/RGB.NET.Presets/Textures/Gradients/AbstractGradient.cs index 50c51429..b8a54af6 100644 --- a/RGB.NET.Presets/Textures/Gradients/AbstractGradient.cs +++ b/RGB.NET.Presets/Textures/Gradients/AbstractGradient.cs @@ -24,7 +24,7 @@ public abstract class AbstractGradient : AbstractDecoratable /// /// Gets a list of the stops used by this . /// - public ObservableCollection GradientStops { get; } = new(); + public ObservableCollection GradientStops { get; } = []; private bool _wrapGradient; /// diff --git a/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs b/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs index 18fa2521..e756a0b7 100644 --- a/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs +++ b/RGB.NET.Presets/Textures/Gradients/LinearGradient.cs @@ -16,7 +16,7 @@ public sealed class LinearGradient : AbstractGradient #region Properties & Fields private bool _isOrderedGradientListDirty = true; - private readonly List _orderedGradientStops = new(); + private readonly List _orderedGradientStops = []; #endregion diff --git a/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs index 322eb5ce..da9159a3 100644 --- a/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs +++ b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs @@ -172,7 +172,7 @@ private static float Generate(float x, float y) // Add contributions from each corner to get the final noise value. // The result is scaled to return values in the interval [-1,1]. - return 40.0f * (n0 + n1 + n2); // TODO: The scale factor is preliminary! + return 40.0f * (n0 + n1 + n2); } @@ -276,7 +276,7 @@ private static float Generate(float x, float y, float z) // Add contributions from each corner to get the final noise value. // The result is scaled to stay just inside [-1,1] - return 32.0f * (n0 + n1 + n2 + n3); // TODO: The scale factor is preliminary! + return 32.0f * (n0 + n1 + n2 + n3); } private static byte[] _perm; From cc2c7bc973607245fdbecdb4c31da1270783732e Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Fri, 22 Dec 2023 23:14:55 +0000 Subject: [PATCH 95/96] Added tag-creation to ci workflow --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db64c8ca..c4091ba4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,3 +64,9 @@ jobs: run: dotnet nuget push **\*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json - name: Symbols Push run: dotnet nuget push **\*.snupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json + - name: Create Tag + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + custom_tag: ${{ steps.versioning.outputs.version }} + tag_prefix: v From aeab93001f128e9f198179c4b3b2f6d4035680c2 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 27 Dec 2023 15:48:20 +0100 Subject: [PATCH 96/96] More code styling fixes --- RGB.NET.Core/Decorators/AbstractDecorator.cs | 2 +- RGB.NET.Core/Extensions/RectangleExtensions.cs | 13 +++++++------ RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs | 2 +- .../Generic/RGBColorUpdateQueue.cs | 6 +++--- .../Helper/ColorExtensions.cs | 2 +- .../Arduino/ArduinoWS2812USBUpdateQueue.cs | 8 ++++---- RGB.NET.Layout/LayoutExtension.cs | 8 ++++---- Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs | 7 ++++--- 8 files changed, 25 insertions(+), 23 deletions(-) diff --git a/RGB.NET.Core/Decorators/AbstractDecorator.cs b/RGB.NET.Core/Decorators/AbstractDecorator.cs index f9c70593..2043ef6e 100644 --- a/RGB.NET.Core/Decorators/AbstractDecorator.cs +++ b/RGB.NET.Core/Decorators/AbstractDecorator.cs @@ -53,7 +53,7 @@ protected virtual void Detach() && (t.Name == typeof(IDecoratable<>).Name) && t.GenericTypeArguments[0].IsInstanceOfType(this)); foreach (Type decoratableType in types) - decoratableType.GetMethod(nameof(IDecoratable.RemoveDecorator))?.Invoke(decoratable, new object[] { this }); + decoratableType.GetMethod(nameof(IDecoratable.RemoveDecorator))?.Invoke(decoratable, [this]); } } diff --git a/RGB.NET.Core/Extensions/RectangleExtensions.cs b/RGB.NET.Core/Extensions/RectangleExtensions.cs index 68fec324..c97256fd 100644 --- a/RGB.NET.Core/Extensions/RectangleExtensions.cs +++ b/RGB.NET.Core/Extensions/RectangleExtensions.cs @@ -151,12 +151,13 @@ public static bool Contains(this in Rectangle rect, in Rectangle rect2) => (rect /// A array of containing the new locations of the corners of the original rectangle. public static Point[] Rotate(this in Rectangle rect, in Rotation rotation, in Point origin = new()) { - Point[] points = { - rect.Location, // top left - new(rect.Location.X + rect.Size.Width, rect.Location.Y), // top right - new(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height), // bottom right - new(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right - }; + Point[] points = + [ + rect.Location, // top left + new Point(rect.Location.X + rect.Size.Width, rect.Location.Y), // top right + new Point(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height), // bottom right + new Point(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right + ]; float sin = MathF.Sin(rotation.Radians); float cos = MathF.Cos(rotation.Radians); diff --git a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs index 7ebdab83..600a1ea2 100644 --- a/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs +++ b/RGB.NET.Devices.DMX/E131/E131UpdateQueue.cs @@ -21,7 +21,7 @@ public sealed class E131UpdateQueue : UpdateQueue /// Gets the byte-representation of a E1.31 packet as described in http://tsp.esta.org/tsp/documents/docs/E1-31-2016.pdf. /// CID, SequenceNumber, Universe and PropertyValues needs to be updated before use! /// - internal byte[] DataPacket { get; } = { 0x00, 0x10, 0x00, 0x00, 0x41, 0x53, 0x43, 0x2D, 0x45, 0x31, 0x2E, 0x31, 0x37, 0x00, 0x00, 0x00, 0x72, 0x6E, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x58, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x72, 0x0B, 0x02, 0xA1, 0x00, 0x00, 0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + internal byte[] DataPacket { get; } = [0x00, 0x10, 0x00, 0x00, 0x41, 0x53, 0x43, 0x2D, 0x45, 0x31, 0x2E, 0x31, 0x37, 0x00, 0x00, 0x00, 0x72, 0x6E, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x58, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x72, 0x0B, 0x02, 0xA1, 0x00, 0x00, 0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; /// /// The sequence-number used to detect the order in which packages where sent. diff --git a/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs index 62795930..aa3f53d5 100644 --- a/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs +++ b/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs @@ -12,7 +12,7 @@ public sealed class RGBColorUpdateQueue : MidiUpdateQueue #region Properties & Fields private static readonly (Color, int)[] COLOR_PALETTE = - { + [ (new Color(0, 0, 0), 0), (new Color(28, 28, 28), 1), (new Color(124, 124, 124), 2), @@ -130,8 +130,8 @@ private static readonly (Color, int)[] COLOR_PALETTE = (new Color(0, 64, 0), 123), (new Color(61, 48, 0), 125), (new Color(180, 93, 0), 126), - (new Color(74, 20, 0), 127), - }; + (new Color(74, 20, 0), 127) + ]; #endregion diff --git a/RGB.NET.Devices.SteelSeries/Helper/ColorExtensions.cs b/RGB.NET.Devices.SteelSeries/Helper/ColorExtensions.cs index b101ff70..501156e1 100644 --- a/RGB.NET.Devices.SteelSeries/Helper/ColorExtensions.cs +++ b/RGB.NET.Devices.SteelSeries/Helper/ColorExtensions.cs @@ -4,5 +4,5 @@ namespace RGB.NET.Devices.SteelSeries.Helper; internal static class ColorExtensions { - internal static int[] ToIntArray(this Color color) => new int[] { color.GetR(), color.GetG(), color.GetB() }; + internal static int[] ToIntArray(this Color color) => [color.GetR(), color.GetG(), color.GetB()]; } \ No newline at end of file diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs index 587c0708..c6b1c009 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs @@ -13,9 +13,9 @@ public sealed class ArduinoWS2812USBUpdateQueue : SerialConnectionUpdateQueue GetCommands(IList<(object key, Color colo for (int i = 1; i <= channelCount; i++) { SerialConnection.ReadTo(Prompt); - byte[] channelLedCountCommand = { (byte)((i << 4) | COUNT_COMMAND[0]) }; + byte[] channelLedCountCommand = [(byte)((i << 4) | COUNT_COMMAND[0])]; SendCommand(channelLedCountCommand); int ledCount = SerialConnection.ReadByte(); if (ledCount > 0) diff --git a/RGB.NET.Layout/LayoutExtension.cs b/RGB.NET.Layout/LayoutExtension.cs index 0c5383cb..d336e147 100644 --- a/RGB.NET.Layout/LayoutExtension.cs +++ b/RGB.NET.Layout/LayoutExtension.cs @@ -77,13 +77,13 @@ public static void Save(this IDeviceLayout layout, Stream stream) Type[] customTypes; if ((customDataType != null) && (customLedDataType != null)) - customTypes = new[] { customDataType, customLedDataType }; + customTypes = [customDataType, customLedDataType]; else if (customDataType != null) - customTypes = new[] { customDataType }; + customTypes = [customDataType]; else if (customLedDataType != null) - customTypes = new[] { customLedDataType }; + customTypes = [customLedDataType]; else - customTypes = Array.Empty(); + customTypes = []; if (layout is DeviceLayout deviceLayout) { diff --git a/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs index da9159a3..a55592d6 100644 --- a/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs +++ b/Tests/RGB.NET.Core.Tests/Helper/SimplexNoise.cs @@ -66,7 +66,7 @@ public static int Seed else { _perm = new byte[512]; - Random random = new Random(value); + Random random = new(value); random.NextBytes(_perm); } @@ -281,7 +281,8 @@ private static float Generate(float x, float y, float z) private static byte[] _perm; - private static readonly byte[] PermOriginal = { + private static readonly byte[] PermOriginal = + [ 151,160,137,91,90,15, 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, @@ -308,7 +309,7 @@ private static float Generate(float x, float y, float z) 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 - }; + ]; private static int FastFloor(float x) {