diff --git a/RGB.NET.Brushes/Brushes/ConicalGradientBrush.cs b/RGB.NET.Brushes/Brushes/ConicalGradientBrush.cs
index 9c25109..127ce9c 100644
--- a/RGB.NET.Brushes/Brushes/ConicalGradientBrush.cs
+++ b/RGB.NET.Brushes/Brushes/ConicalGradientBrush.cs
@@ -29,7 +29,7 @@ namespace RGB.NET.Brushes
set => SetProperty(ref _origin, value);
}
- private Point _center = new Point(0.5, 0.5);
+ private Point _center = new(0.5, 0.5);
///
/// Gets or sets the center (as percentage in the range [0..1]) of the drawn by this . (default: 0.5, 0.5)
///
@@ -39,12 +39,12 @@ namespace RGB.NET.Brushes
set => SetProperty(ref _center, value);
}
- private IGradient _gradient;
+ private IGradient? _gradient;
///
///
/// Gets or sets the gradient drawn by the brush. If null it will default to full transparent.
///
- public IGradient Gradient
+ public IGradient? Gradient
{
get => _gradient;
set => SetProperty(ref _gradient, value);
@@ -104,6 +104,8 @@ namespace RGB.NET.Brushes
///
protected override Color GetColorAtPoint(Rectangle rectangle, BrushRenderTarget renderTarget)
{
+ if (Gradient == null) return Color.Transparent;
+
double centerX = rectangle.Size.Width * Center.X;
double centerY = rectangle.Size.Height * Center.Y;
diff --git a/RGB.NET.Brushes/Brushes/IGradientBrush.cs b/RGB.NET.Brushes/Brushes/IGradientBrush.cs
index 5677154..80522a3 100644
--- a/RGB.NET.Brushes/Brushes/IGradientBrush.cs
+++ b/RGB.NET.Brushes/Brushes/IGradientBrush.cs
@@ -12,6 +12,6 @@ namespace RGB.NET.Brushes
///
/// Gets the used by this .
///
- IGradient Gradient { get; }
+ IGradient? Gradient { get; }
}
}
diff --git a/RGB.NET.Brushes/Brushes/LinearGradientBrush.cs b/RGB.NET.Brushes/Brushes/LinearGradientBrush.cs
index 0880e4c..c175068 100644
--- a/RGB.NET.Brushes/Brushes/LinearGradientBrush.cs
+++ b/RGB.NET.Brushes/Brushes/LinearGradientBrush.cs
@@ -20,7 +20,7 @@ namespace RGB.NET.Brushes
{
#region Properties & Fields
- private Point _startPoint = new Point(0, 0.5);
+ private Point _startPoint = new(0, 0.5);
///
/// Gets or sets the start (as percentage in the range [0..1]) of the drawn by this . (default: 0.0, 0.5)
///
@@ -30,7 +30,7 @@ namespace RGB.NET.Brushes
set => SetProperty(ref _startPoint, value);
}
- private Point _endPoint = new Point(1, 0.5);
+ private Point _endPoint = new(1, 0.5);
///
/// Gets or sets the end (as percentage in the range [0..1]) of the drawn by this . (default: 1.0, 0.5)
///
@@ -40,9 +40,9 @@ namespace RGB.NET.Brushes
set => SetProperty(ref _endPoint, value);
}
- private IGradient _gradient;
+ private IGradient? _gradient;
///
- public IGradient Gradient
+ public IGradient? Gradient
{
get => _gradient;
set => SetProperty(ref _gradient, value);
@@ -97,8 +97,8 @@ namespace RGB.NET.Brushes
{
if (Gradient == null) return Color.Transparent;
- Point startPoint = new Point(StartPoint.X * rectangle.Size.Width, StartPoint.Y * rectangle.Size.Height);
- Point endPoint = new Point(EndPoint.X * rectangle.Size.Width, EndPoint.Y * rectangle.Size.Height);
+ Point startPoint = new(StartPoint.X * rectangle.Size.Width, StartPoint.Y * rectangle.Size.Height);
+ Point endPoint = new(EndPoint.X * rectangle.Size.Width, EndPoint.Y * rectangle.Size.Height);
double offset = GradientHelper.CalculateLinearGradientOffset(startPoint, endPoint, renderTarget.Point);
return Gradient.GetColor(offset);
diff --git a/RGB.NET.Brushes/Brushes/RadialGradientBrush.cs b/RGB.NET.Brushes/Brushes/RadialGradientBrush.cs
index 58df28e..9d2ee34 100644
--- a/RGB.NET.Brushes/Brushes/RadialGradientBrush.cs
+++ b/RGB.NET.Brushes/Brushes/RadialGradientBrush.cs
@@ -18,7 +18,7 @@ namespace RGB.NET.Brushes
{
#region Properties & Fields
- private Point _center = new Point(0.5, 0.5);
+ private Point _center = new(0.5, 0.5);
///
/// Gets or sets the center (as percentage in the range [0..1]) around which the should be drawn. (default: 0.5, 0.5)
///
@@ -28,9 +28,9 @@ namespace RGB.NET.Brushes
set => SetProperty(ref _center, value);
}
- private IGradient _gradient;
+ private IGradient? _gradient;
///
- public IGradient Gradient
+ public IGradient? Gradient
{
get => _gradient;
set => SetProperty(ref _gradient, value);
@@ -78,7 +78,7 @@ namespace RGB.NET.Brushes
{
if (Gradient == null) return Color.Transparent;
- Point centerPoint = new Point(rectangle.Location.X + (rectangle.Size.Width * Center.X), rectangle.Location.Y + (rectangle.Size.Height * Center.Y));
+ Point centerPoint = new(rectangle.Location.X + (rectangle.Size.Width * Center.X), rectangle.Location.Y + (rectangle.Size.Height * Center.Y));
// Calculate the distance to the farthest point from the center as reference (this has to be a corner)
// ReSharper disable once RedundantCast - never trust this ...
diff --git a/RGB.NET.Brushes/Brushes/SolidColorBrush.cs b/RGB.NET.Brushes/Brushes/SolidColorBrush.cs
index 3620ea5..8bbd68b 100644
--- a/RGB.NET.Brushes/Brushes/SolidColorBrush.cs
+++ b/RGB.NET.Brushes/Brushes/SolidColorBrush.cs
@@ -52,7 +52,7 @@ namespace RGB.NET.Brushes
/// Converts a to a .
///
/// The to convert.
- public static explicit operator SolidColorBrush(Color color) => new SolidColorBrush(color);
+ public static explicit operator SolidColorBrush(Color color) => new(color);
///
/// Converts a to a .
diff --git a/RGB.NET.Brushes/Gradients/AbstractGradient.cs b/RGB.NET.Brushes/Gradients/AbstractGradient.cs
index c32a0da..2a6350b 100644
--- a/RGB.NET.Brushes/Gradients/AbstractGradient.cs
+++ b/RGB.NET.Brushes/Gradients/AbstractGradient.cs
@@ -23,7 +23,7 @@ namespace RGB.NET.Brushes.Gradients
///
/// Gets a list of the stops used by this .
///
- public ObservableCollection GradientStops { get; } = new ObservableCollection();
+ public ObservableCollection GradientStops { get; } = new();
private bool _wrapGradient;
///
@@ -42,7 +42,7 @@ namespace RGB.NET.Brushes.Gradients
#region Events
///
- public event EventHandler GradientChanged;
+ public event EventHandler? GradientChanged;
#endregion
@@ -54,7 +54,7 @@ namespace RGB.NET.Brushes.Gradients
protected AbstractGradient()
{
GradientStops.CollectionChanged += GradientCollectionChanged;
- PropertyChanged += (sender, args) => OnGradientChanged();
+ PropertyChanged += (_, _) => OnGradientChanged();
}
///
@@ -64,7 +64,7 @@ namespace RGB.NET.Brushes.Gradients
protected AbstractGradient(params GradientStop[] gradientStops)
{
GradientStops.CollectionChanged += GradientCollectionChanged;
- PropertyChanged += (sender, args) => OnGradientChanged();
+ PropertyChanged += (_, _) => OnGradientChanged();
foreach (GradientStop gradientStop in gradientStops)
GradientStops.Add(gradientStop);
@@ -80,7 +80,7 @@ namespace RGB.NET.Brushes.Gradients
this.WrapGradient = wrapGradient;
GradientStops.CollectionChanged += GradientCollectionChanged;
- PropertyChanged += (sender, args) => OnGradientChanged();
+ PropertyChanged += (_, _) => OnGradientChanged();
foreach (GradientStop gradientStop in gradientStops)
GradientStops.Add(gradientStop);
@@ -128,9 +128,9 @@ namespace RGB.NET.Brushes.Gradients
///
/// Should be called to indicate that the gradient was changed.
///
- protected void OnGradientChanged() => GradientChanged?.Invoke(this, null);
+ protected void OnGradientChanged() => GradientChanged?.Invoke(this, EventArgs.Empty);
- private void GradientCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
+ private void GradientCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
if (e.OldItems != null)
foreach (GradientStop gradientStop in e.OldItems)
@@ -143,7 +143,7 @@ namespace RGB.NET.Brushes.Gradients
OnGradientChanged();
}
- private void GradientStopChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) => OnGradientChanged();
+ private void GradientStopChanged(object? sender, PropertyChangedEventArgs propertyChangedEventArgs) => OnGradientChanged();
#endregion
}
diff --git a/RGB.NET.Brushes/Gradients/LinearGradient.cs b/RGB.NET.Brushes/Gradients/LinearGradient.cs
index 535fe5d..f22ec24 100644
--- a/RGB.NET.Brushes/Gradients/LinearGradient.cs
+++ b/RGB.NET.Brushes/Gradients/LinearGradient.cs
@@ -16,7 +16,7 @@ namespace RGB.NET.Brushes.Gradients
#region Properties & Fields
private bool _isOrderedGradientListDirty = true;
- private LinkedList _orderedGradientStops;
+ private LinkedList _orderedGradientStops = new();
#endregion
@@ -60,12 +60,12 @@ namespace RGB.NET.Brushes.Gradients
private void Initialize()
{
- void OnGradientStopOnPropertyChanged(object sender, PropertyChangedEventArgs args) => _isOrderedGradientListDirty = true;
+ void OnGradientStopOnPropertyChanged(object? sender, PropertyChangedEventArgs args) => _isOrderedGradientListDirty = true;
foreach (GradientStop gradientStop in GradientStops)
gradientStop.PropertyChanged += OnGradientStopOnPropertyChanged;
- GradientStops.CollectionChanged += (sender, args) =>
+ GradientStops.CollectionChanged += (_, args) =>
{
if (args.OldItems != null)
foreach (GradientStop gradientStop in args.OldItems)
@@ -114,18 +114,18 @@ namespace RGB.NET.Brushes.Gradients
///
protected virtual (GradientStop gsBefore, GradientStop gsAfter) GetEnclosingGradientStops(double offset, LinkedList orderedStops, bool wrap)
{
- LinkedList gradientStops = new LinkedList(orderedStops);
+ LinkedList gradientStops = new(orderedStops);
if (wrap)
{
- GradientStop gsBefore, gsAfter;
+ GradientStop? gsBefore, gsAfter;
do
{
gsBefore = gradientStops.LastOrDefault(n => n.Offset <= offset);
if (gsBefore == null)
{
- GradientStop lastStop = gradientStops.Last.Value;
+ GradientStop lastStop = gradientStops.Last!.Value;
gradientStops.AddFirst(new GradientStop(lastStop.Offset - 1, lastStop.Color));
gradientStops.RemoveLast();
}
@@ -133,7 +133,7 @@ namespace RGB.NET.Brushes.Gradients
gsAfter = gradientStops.FirstOrDefault(n => n.Offset >= offset);
if (gsAfter == null)
{
- GradientStop firstStop = gradientStops.First.Value;
+ GradientStop firstStop = gradientStops.First!.Value;
gradientStops.AddLast(new GradientStop(firstStop.Offset + 1, firstStop.Color));
gradientStops.RemoveFirst();
}
diff --git a/RGB.NET.Brushes/Gradients/RainbowGradient.cs b/RGB.NET.Brushes/Gradients/RainbowGradient.cs
index 01946d0..2c5c2b6 100644
--- a/RGB.NET.Brushes/Gradients/RainbowGradient.cs
+++ b/RGB.NET.Brushes/Gradients/RainbowGradient.cs
@@ -41,7 +41,7 @@ namespace RGB.NET.Brushes.Gradients
#region Events
///
- public event EventHandler GradientChanged;
+ public event EventHandler? GradientChanged;
#endregion
@@ -57,7 +57,7 @@ namespace RGB.NET.Brushes.Gradients
this.StartHue = startHue;
this.EndHue = endHue;
- PropertyChanged += (sender, args) => OnGradientChanged();
+ PropertyChanged += (_, _) => OnGradientChanged();
}
#endregion
@@ -85,7 +85,7 @@ namespace RGB.NET.Brushes.Gradients
StartHue += offset;
EndHue += offset;
-
+
while ((StartHue > 360) && (EndHue > 360))
{
StartHue -= 360;
@@ -101,7 +101,7 @@ namespace RGB.NET.Brushes.Gradients
///
/// Should be called to indicate that the gradient was changed.
///
- protected void OnGradientChanged() => GradientChanged?.Invoke(this, null);
+ protected void OnGradientChanged() => GradientChanged?.Invoke(this, EventArgs.Empty);
#endregion
}
diff --git a/RGB.NET.Core/Brushes/AbstractBrush.cs b/RGB.NET.Core/Brushes/AbstractBrush.cs
index 7521bf2..541b6ac 100644
--- a/RGB.NET.Core/Brushes/AbstractBrush.cs
+++ b/RGB.NET.Core/Brushes/AbstractBrush.cs
@@ -35,7 +35,7 @@ namespace RGB.NET.Core
public Rectangle RenderedRectangle { get; protected set; }
///
- public Dictionary RenderedTargets { get; } = new Dictionary();
+ public Dictionary RenderedTargets { get; } = new();
#endregion
diff --git a/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs b/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs
index 83597ce..40b0eec 100644
--- a/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs
+++ b/RGB.NET.Core/Color/Behaviors/DefaultColorBehavior.cs
@@ -15,7 +15,7 @@
///
/// The object to test.
/// true if is a equivalent to this ; otherwise, false.
- public virtual bool Equals(Color color, object obj)
+ public virtual bool Equals(Color color, object? obj)
{
if (!(obj is Color)) return false;
diff --git a/RGB.NET.Core/Decorators/AbstractDecorator.cs b/RGB.NET.Core/Decorators/AbstractDecorator.cs
index 50e007c..e4a765f 100644
--- a/RGB.NET.Core/Decorators/AbstractDecorator.cs
+++ b/RGB.NET.Core/Decorators/AbstractDecorator.cs
@@ -29,7 +29,7 @@ namespace RGB.NET.Core
///
/// Gets a readonly-list of all this decorator is attached to.
///
- protected List DecoratedObjects { get; } = new List();
+ protected List DecoratedObjects { get; } = new();
#endregion
@@ -46,7 +46,7 @@ namespace RGB.NET.Core
///
protected virtual void Detach()
{
- List decoratables = new List(DecoratedObjects);
+ List decoratables = new(DecoratedObjects);
foreach (IDecoratable decoratable in decoratables)
{
IEnumerable types = decoratable.GetType().GetInterfaces().Where(t => t.IsGenericType
diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs
index ad4bc5a..e7c6d08 100644
--- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs
+++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs
@@ -131,7 +131,7 @@ namespace RGB.NET.Core
DeviceUpdate();
// Send LEDs to SDK
- List ledsToUpdate = GetLedsToUpdate(flushLeds)?.ToList() ?? new List();
+ List ledsToUpdate = GetLedsToUpdate(flushLeds).ToList();
foreach (Led ledToUpdate in ledsToUpdate)
ledToUpdate.Update();
diff --git a/RGB.NET.Core/Extensions/PointExtensions.cs b/RGB.NET.Core/Extensions/PointExtensions.cs
index 7c413e9..9766bf3 100644
--- a/RGB.NET.Core/Extensions/PointExtensions.cs
+++ b/RGB.NET.Core/Extensions/PointExtensions.cs
@@ -13,7 +13,7 @@ namespace RGB.NET.Core
/// The x-ammount to move.
/// The y-ammount to move.
/// The new location of the point.
- public static Point Translate(this Point point, double x = 0, double y = 0) => new Point(point.X + x, point.Y + y);
+ public static Point Translate(this Point point, double x = 0, double y = 0) => new(point.X + x, point.Y + y);
///
/// Rotates the specified by the given amuont around the given origin.
@@ -22,7 +22,7 @@ namespace RGB.NET.Core
/// The rotation.
/// The origin to rotate around. [0,0] if not set.
/// The new location of the point.
- public static Point Rotate(this Point point, Rotation rotation, Point origin = new Point())
+ public static Point Rotate(this Point point, Rotation rotation, Point origin = new())
{
double sin = Math.Sin(rotation.Radians);
double cos = Math.Cos(rotation.Radians);
diff --git a/RGB.NET.Core/Helper/CultureHelper.cs b/RGB.NET.Core/Helper/CultureHelper.cs
deleted file mode 100644
index 3ea900a..0000000
--- a/RGB.NET.Core/Helper/CultureHelper.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-using System;
-using System.Globalization;
-using System.Runtime.InteropServices;
-
-namespace RGB.NET.Core
-{
- ///
- /// Offers some helper-methods for culture related things.
- ///
- public static class CultureHelper
- {
- #region DLLImports
-
- [DllImport("user32.dll")]
- private static extern IntPtr GetKeyboardLayout(uint thread);
-
- #endregion
-
- #region Constructors
-
- #endregion
-
- #region Methods
-
- ///
- /// Gets the current keyboard-layout from the OS.
- ///
- /// The current keyboard-layout
- public static CultureInfo GetCurrentCulture()
- {
- try
- {
- int keyboardLayout = GetKeyboardLayout(0).ToInt32() & 0xFFFF;
- return new CultureInfo(keyboardLayout);
- }
- catch
- {
- return new CultureInfo(1033); // en-US on error.
- }
- }
-
- #endregion
- }
-}
diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs
index bd2c8ad..d64584e 100644
--- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs
+++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs
@@ -14,7 +14,7 @@ namespace RGB.NET.Core
{
#region Properties & Fields
- private readonly object _dataLock = new object();
+ private readonly object _dataLock = new();
private readonly IDeviceUpdateTrigger _updateTrigger;
private Dictionary? _currentDataSet;
diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs
index 8547b14..7ad35d4 100644
--- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs
+++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
+using System.Linq;
using AuraServiceLib;
using RGB.NET.Core;
@@ -18,7 +19,7 @@ namespace RGB.NET.Devices.Asus
{
#region Properties & Fields
- private static AsusDeviceProvider _instance;
+ private static AsusDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
@@ -31,26 +32,14 @@ namespace RGB.NET.Devices.Asus
public bool IsInitialized { get; private set; }
///
- ///
- /// Gets whether the application has exclusive access to the SDK or not.
- ///
- public bool HasExclusiveAccess { get; private set; }
-
- ///
- public IEnumerable Devices { get; private set; }
-
- ///
- /// Gets or sets a function to get the culture for a specific device.
- ///
- // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global
- public Func GetCulture { get; set; } = CultureHelper.GetCurrentCulture;
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
///
/// The used to trigger the updates for asus devices.
///
public DeviceUpdateTrigger UpdateTrigger { get; private set; }
- private IAuraSdk2 _sdk;
+ private IAuraSdk2? _sdk;
#endregion
@@ -79,7 +68,7 @@ namespace RGB.NET.Devices.Asus
try
{
- UpdateTrigger?.Stop();
+ UpdateTrigger.Stop();
// ReSharper disable once SuspiciousTypeConversion.Global
_sdk = (IAuraSdk2)new AuraSdk();
@@ -141,7 +130,7 @@ namespace RGB.NET.Devices.Asus
}
}
- UpdateTrigger?.Start();
+ UpdateTrigger.Start();
Devices = new ReadOnlyCollection(devices);
IsInitialized = true;
diff --git a/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs b/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs
index cafd420..8b57013 100644
--- a/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs
+++ b/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs
@@ -24,7 +24,7 @@ namespace RGB.NET.Devices.Asus
/// Gets or sets the update queue performing updates for this device.
///
// ReSharper disable once MemberCanBePrivate.Global
- protected AsusUpdateQueue UpdateQueue { get; set; }
+ protected AsusUpdateQueue? UpdateQueue { get; set; }
#endregion
@@ -52,7 +52,7 @@ namespace RGB.NET.Devices.Asus
if (Size == Size.Invalid)
{
- Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
+ Rectangle ledRectangle = new(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
@@ -66,8 +66,8 @@ namespace RGB.NET.Devices.Asus
protected abstract void InitializeLayout();
///
- protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
-
+ protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
+
///
public override void Dispose()
{
diff --git a/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs
index f54a26b..e55c276 100644
--- a/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Asus/Generic/AsusRGBDeviceInfo.cs
@@ -38,7 +38,7 @@ namespace RGB.NET.Devices.Asus
/// The backing this RGB.NET device.
/// The manufacturer-name of the .
/// The model-name of the .
- internal AsusRGBDeviceInfo(RGBDeviceType deviceType, IAuraSyncDevice device, string model = null, string manufacturer = "Asus")
+ internal AsusRGBDeviceInfo(RGBDeviceType deviceType, IAuraSyncDevice device, string? model = null, string manufacturer = "Asus")
{
this.DeviceType = deviceType;
this.Device = device;
diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs
index 9a3b260..1623fa7 100644
--- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs
+++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs
@@ -15,7 +15,7 @@ namespace RGB.NET.Devices.Asus
///
/// The device to be updated.
///
- protected IAuraSyncDevice Device { get; private set; }
+ protected IAuraSyncDevice? Device { get; private set; }
#endregion
@@ -45,15 +45,16 @@ namespace RGB.NET.Devices.Asus
///
protected override void Update(Dictionary
- public static List PossibleX86NativePaths { get; } = new List { "x86/CMSDK.dll" };
+ public static List PossibleX86NativePaths { get; } = new() { "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 List { "x64/CMSDK.dll" };
+ public static List PossibleX64NativePaths { get; } = new() { "x64/CMSDK.dll" };
///
///
/// Indicates if the SDK is initialized and ready to use.
///
public bool IsInitialized { get; private set; }
-
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- public string LoadedArchitecture => _CoolerMasterSDK.LoadedArchitecture;
-
+
///
- ///
- /// Gets whether the application has exclusive access to the SDK or not.
- ///
- public bool HasExclusiveAccess { get; private set; }
-
- ///
- public IEnumerable Devices { get; private set; }
-
- ///
- /// Gets or sets a function to get the culture for a specific device.
- ///
- // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global
- public Func GetCulture { get; set; } = CultureHelper.GetCurrentCulture;
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
///
/// The used to trigger the updates for cooler master devices.
///
- public DeviceUpdateTrigger UpdateTrigger { get; private set; }
+ public DeviceUpdateTrigger UpdateTrigger { get; }
#endregion
@@ -95,7 +78,7 @@ namespace RGB.NET.Devices.CoolerMaster
try
{
- UpdateTrigger?.Stop();
+ UpdateTrigger.Stop();
_CoolerMasterSDK.Reload();
if (_CoolerMasterSDK.GetSDKVersion() <= 0) return false;
@@ -118,7 +101,7 @@ namespace RGB.NET.Devices.CoolerMaster
{
case RGBDeviceType.Keyboard:
CoolerMasterPhysicalKeyboardLayout physicalLayout = _CoolerMasterSDK.GetDeviceLayout(index);
- device = new CoolerMasterKeyboardRGBDevice(new CoolerMasterKeyboardRGBDeviceInfo(index, physicalLayout, GetCulture()));
+ device = new CoolerMasterKeyboardRGBDevice(new CoolerMasterKeyboardRGBDeviceInfo(index, physicalLayout));
break;
case RGBDeviceType.Mouse:
@@ -142,7 +125,7 @@ namespace RGB.NET.Devices.CoolerMaster
catch { if (throwExceptions) throw; }
}
- UpdateTrigger?.Start();
+ UpdateTrigger.Start();
Devices = new ReadOnlyCollection(devices);
IsInitialized = true;
diff --git a/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterLogicalKeyboardLayout.cs b/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterLogicalKeyboardLayout.cs
deleted file mode 100644
index c41ac93..0000000
--- a/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterLogicalKeyboardLayout.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-// ReSharper disable InconsistentNaming
-// ReSharper disable UnusedMember.Global
-
-#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
-
-namespace RGB.NET.Devices.CoolerMaster
-{
- ///
- /// Contains list of available logical layouts for cooler master keyboards.
- ///
- public enum CoolerMasterLogicalKeyboardLayout
- {
- DE
- };
-}
diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs
index d33351f..054981d 100644
--- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs
+++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs
@@ -26,7 +26,7 @@ namespace RGB.NET.Devices.CoolerMaster
/// Gets or sets the update queue performing updates for this device.
///
// ReSharper disable once MemberCanBePrivate.Global
- protected CoolerMasterUpdateQueue UpdateQueue { get; set; }
+ protected CoolerMasterUpdateQueue? UpdateQueue { get; set; }
#endregion
@@ -55,7 +55,7 @@ namespace RGB.NET.Devices.CoolerMaster
if (Size == Size.Invalid)
{
- Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
+ Rectangle ledRectangle = new(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
@@ -68,7 +68,7 @@ namespace RGB.NET.Devices.CoolerMaster
protected abstract void InitializeLayout();
///
- protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
+ protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
///
///
diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDeviceInfo.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDeviceInfo.cs
index dccc434..d95993e 100644
--- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDeviceInfo.cs
@@ -1,5 +1,4 @@
-using System;
-using RGB.NET.Core;
+using RGB.NET.Core;
using RGB.NET.Devices.CoolerMaster.Helper;
namespace RGB.NET.Devices.CoolerMaster
@@ -45,7 +44,7 @@ namespace RGB.NET.Devices.CoolerMaster
this.DeviceType = deviceType;
this.DeviceIndex = deviceIndex;
- Model = deviceIndex.GetDescription();
+ Model = deviceIndex.GetDescription() ?? "Unknown";
DeviceName = $"{Manufacturer} {Model}";
}
diff --git a/RGB.NET.Devices.CoolerMaster/Helper/EnumExtension.cs b/RGB.NET.Devices.CoolerMaster/Helper/EnumExtension.cs
index 9ebd427..9cd05ce 100644
--- a/RGB.NET.Devices.CoolerMaster/Helper/EnumExtension.cs
+++ b/RGB.NET.Devices.CoolerMaster/Helper/EnumExtension.cs
@@ -14,38 +14,29 @@ namespace RGB.NET.Devices.CoolerMaster.Helper
/// Gets the value of the .
///
/// The enum value to get the description from.
- /// The generic enum-type
/// The value of the or the result of the source.
- internal static string GetDescription(this T source)
- where T : struct
- {
- return source.GetAttribute()?.Description ?? source.ToString();
- }
+ internal static string? GetDescription(this Enum source)
+ => source.GetAttribute()?.Description ?? source.ToString();
///
/// Gets the value of the .
///
/// The enum value to get the description from.
- /// The generic enum-type
/// The value of the or the result of the source.
- internal static RGBDeviceType GetDeviceType(this T source)
- where T : struct
- {
- return source.GetAttribute()?.DeviceType ?? RGBDeviceType.Unknown;
- }
+ internal static RGBDeviceType GetDeviceType(this Enum source)
+ => source.GetAttribute()?.DeviceType ?? RGBDeviceType.Unknown;
///
/// Gets the attribute of type T.
///
/// The enum value to get the attribute from
/// The generic attribute type
- /// The generic enum-type
/// The .
- private static T GetAttribute(this TEnum source)
+ private static T? GetAttribute(this Enum source)
where T : Attribute
- where TEnum : struct
{
- FieldInfo fi = source.GetType().GetField(source.ToString());
+ 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;
}
diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardLedMappings.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardLedMappings.cs
index 57548f1..77da300 100644
--- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardLedMappings.cs
+++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardLedMappings.cs
@@ -14,8 +14,8 @@ namespace RGB.NET.Devices.CoolerMaster
#region MasterKeysL
- private static readonly Dictionary MasterKeysL_US = new Dictionary
- {
+ private static readonly Dictionary MasterKeysL_US = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -131,8 +131,8 @@ namespace RGB.NET.Devices.CoolerMaster
{ LedId.Keyboard_NumPeriodAndDelete, (5,20) }
};
- private static readonly Dictionary MasterKeysL_EU = new Dictionary
- {
+ private static readonly Dictionary MasterKeysL_EU = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -253,8 +253,8 @@ namespace RGB.NET.Devices.CoolerMaster
#region MasterKeysM
- private static readonly Dictionary MasterKeysM_US = new Dictionary
- {
+ private static readonly Dictionary MasterKeysM_US = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -354,8 +354,8 @@ namespace RGB.NET.Devices.CoolerMaster
{ LedId.Keyboard_NumPeriodAndDelete, (5,17) }
};
- private static readonly Dictionary MasterKeysM_EU = new Dictionary
- {
+ private static readonly Dictionary MasterKeysM_EU = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -460,8 +460,8 @@ namespace RGB.NET.Devices.CoolerMaster
#region MasterKeysS
- private static readonly Dictionary MasterKeysS_US = new Dictionary
- {
+ private static readonly Dictionary MasterKeysS_US = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -556,8 +556,8 @@ namespace RGB.NET.Devices.CoolerMaster
{ LedId.Keyboard_ArrowRight, (5,17) }
};
- private static readonly Dictionary MasterKeysS_EU = new Dictionary
- {
+ private static readonly Dictionary MasterKeysS_EU = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -657,8 +657,8 @@ namespace RGB.NET.Devices.CoolerMaster
#region MasterKeysMK750
- private static readonly Dictionary MasterKeysMK750_US = new Dictionary
- {
+ private static readonly Dictionary MasterKeysMK750_US = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -801,8 +801,8 @@ namespace RGB.NET.Devices.CoolerMaster
{ LedId.Keyboard_Custom22, (6,17) },
};
- private static readonly Dictionary MasterKeysMK750_EU = new Dictionary
- {
+ private static readonly Dictionary MasterKeysMK750_EU = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -946,8 +946,8 @@ namespace RGB.NET.Devices.CoolerMaster
{ LedId.Keyboard_Custom22, (6,17) }
};
- private static readonly Dictionary MasterKeysMK750_JP = new Dictionary
- {
+ private static readonly Dictionary MasterKeysMK750_JP = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -1099,8 +1099,8 @@ namespace RGB.NET.Devices.CoolerMaster
#region CKxxx
- private static readonly Dictionary CKxxx_US = new Dictionary
- {
+ private static readonly Dictionary CKxxx_US = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -1212,8 +1212,8 @@ namespace RGB.NET.Devices.CoolerMaster
{ LedId.Keyboard_NumPeriodAndDelete, (5,20) }
};
- private static readonly Dictionary CKxxx_EU = new Dictionary
- {
+ private static readonly Dictionary CKxxx_EU = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -1326,8 +1326,8 @@ namespace RGB.NET.Devices.CoolerMaster
{ LedId.Keyboard_NumPeriodAndDelete, (5,20) }
};
- private static readonly Dictionary CKxxx_JP = new Dictionary
- {
+ private static readonly Dictionary CKxxx_JP = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,1) },
{ LedId.Keyboard_F2, (0,2) },
@@ -1450,7 +1450,7 @@ namespace RGB.NET.Devices.CoolerMaster
/// Contains all the hardware-id mappings for CoolerMaster devices.
///
public static readonly Dictionary>> Mapping =
- new Dictionary>>
+ new()
{
{ CoolerMasterDevicesIndexes.MasterKeys_L, new Dictionary>
{
diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs
index e3dfc27..cf67d76 100644
--- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs
+++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs
@@ -27,13 +27,13 @@ namespace RGB.NET.Devices.CoolerMaster
///
protected override void InitializeLayout()
{
- if (!CoolerMasterKeyboardLedMappings.Mapping.TryGetValue(DeviceInfo.DeviceIndex, out Dictionary> deviceMappings))
+ if (!CoolerMasterKeyboardLedMappings.Mapping.TryGetValue(DeviceInfo.DeviceIndex, out Dictionary>? deviceMappings))
throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex}");
- if (!deviceMappings.TryGetValue(DeviceInfo.PhysicalLayout, out Dictionary mapping))
+ if (!deviceMappings.TryGetValue(DeviceInfo.PhysicalLayout, out Dictionary? mapping))
throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex} with physical layout {DeviceInfo.PhysicalLayout}");
- foreach (KeyValuePair led in mapping)
- AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
+ foreach ((LedId ledId, (int row, int column)) in mapping)
+ AddLed(ledId, new Point(column * 19, row * 19), new Size(19, 19));
}
///
diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs
index c13e4cc..6b63cbe 100644
--- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs
@@ -1,5 +1,4 @@
-using System.Globalization;
-using RGB.NET.Core;
+using RGB.NET.Core;
namespace RGB.NET.Devices.CoolerMaster
{
@@ -16,11 +15,6 @@ namespace RGB.NET.Devices.CoolerMaster
///
public CoolerMasterPhysicalKeyboardLayout PhysicalLayout { get; }
- ///
- /// Gets the of the .
- ///
- public CoolerMasterLogicalKeyboardLayout LogicalLayout { get; private set; }
-
#endregion
#region Constructors
@@ -32,23 +26,10 @@ namespace RGB.NET.Devices.CoolerMaster
/// The index of the .
/// The of the .
/// The of the layout this keyboard is using
- internal CoolerMasterKeyboardRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex, CoolerMasterPhysicalKeyboardLayout physicalKeyboardLayout, CultureInfo culture)
+ internal CoolerMasterKeyboardRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex, CoolerMasterPhysicalKeyboardLayout physicalKeyboardLayout)
: base(RGBDeviceType.Keyboard, deviceIndex)
{
this.PhysicalLayout = physicalKeyboardLayout;
-
- SetLayouts(culture.KeyboardLayoutId);
- }
-
- private void SetLayouts(int keyboardLayoutId)
- {
- switch (keyboardLayoutId)
- {
- //TODO DarthAffe 02.04.2017: Check all available keyboards and there layout-ids
- default:
- LogicalLayout = CoolerMasterLogicalKeyboardLayout.DE;
- break;
- }
}
#endregion
diff --git a/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseLedMappings.cs b/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseLedMappings.cs
index 61bee7d..74fd5b2 100644
--- a/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseLedMappings.cs
+++ b/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseLedMappings.cs
@@ -15,7 +15,7 @@ namespace RGB.NET.Devices.CoolerMaster
///
// ReSharper disable once InconsistentNaming
public static readonly Dictionary> Mapping =
- new Dictionary>
+ new()
{
{ CoolerMasterDevicesIndexes.MasterMouse_L, new Dictionary
{
diff --git a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs
index ac23587..6cf86c6 100644
--- a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs
+++ b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs
@@ -16,12 +16,7 @@ namespace RGB.NET.Devices.CoolerMaster.Native
#region Libary Management
private static IntPtr _dllHandle = IntPtr.Zero;
-
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- internal static string LoadedArchitecture { get; private set; }
-
+
///
/// Reloads the SDK.
///
@@ -37,7 +32,7 @@ namespace RGB.NET.Devices.CoolerMaster.Native
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
List possiblePathList = Environment.Is64BitProcess ? CoolerMasterDeviceProvider.PossibleX64NativePaths : CoolerMasterDeviceProvider.PossibleX86NativePaths;
- string dllPath = possiblePathList.FirstOrDefault(File.Exists);
+ string? dllPath = possiblePathList.FirstOrDefault(File.Exists);
if (dllPath == null) throw new RGBDeviceException($"Can't find the CoolerMaster-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
_dllHandle = LoadLibrary(dllPath);
@@ -76,14 +71,14 @@ namespace RGB.NET.Devices.CoolerMaster.Native
#region Pointers
- private static GetSDKVersionPointer _getSDKVersionPointer;
- private static SetControlDevicePointer _setControlDevicenPointer;
- private static IsDevicePlugPointer _isDevicePlugPointer;
- private static GetDeviceLayoutPointer _getDeviceLayoutPointer;
- private static EnableLedControlPointer _enableLedControlPointer;
- private static RefreshLedPointer _refreshLedPointer;
- private static SetLedColorPointer _setLedColorPointer;
- private static SetAllLedColorPointer _setAllLedColorPointer;
+ private static GetSDKVersionPointer? _getSDKVersionPointer;
+ private static SetControlDevicePointer? _setControlDevicenPointer;
+ private static IsDevicePlugPointer? _isDevicePlugPointer;
+ private static GetDeviceLayoutPointer? _getDeviceLayoutPointer;
+ private static EnableLedControlPointer? _enableLedControlPointer;
+ private static RefreshLedPointer? _refreshLedPointer;
+ private static SetLedColorPointer? _setLedColorPointer;
+ private static SetAllLedColorPointer? _setAllLedColorPointer;
#endregion
@@ -125,49 +120,49 @@ namespace RGB.NET.Devices.CoolerMaster.Native
///
/// CM-SDK: Get SDK Dll's Version.
///
- internal static int GetSDKVersion() => _getSDKVersionPointer();
+ internal static int GetSDKVersion() => (_getSDKVersionPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke();
///
/// CM-SDK: set operating device
///
internal static void SetControlDevice(CoolerMasterDevicesIndexes devicesIndexes)
- => _setControlDevicenPointer(devicesIndexes);
+ => (_setControlDevicenPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(devicesIndexes);
///
/// CM-SDK: verify if the deviced is plugged in
///
internal static bool IsDevicePlugged(CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
- => _isDevicePlugPointer(devIndex);
+ => (_isDevicePlugPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(devIndex);
///
/// CM-SDK: Obtain current device layout
///
internal static CoolerMasterPhysicalKeyboardLayout GetDeviceLayout(CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
- => _getDeviceLayoutPointer(devIndex);
+ => (_getDeviceLayoutPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(devIndex);
///
/// CM-SDK: set control over device’s LED
///
internal static bool EnableLedControl(bool value, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
- => _enableLedControlPointer(value, devIndex);
+ => (_enableLedControlPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(value, devIndex);
///
/// CM-SDK: Print out the lights setting from Buffer to LED
///
internal static bool RefreshLed(bool autoRefresh, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
- => _refreshLedPointer(autoRefresh, devIndex);
+ => (_refreshLedPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(autoRefresh, devIndex);
///
/// CM-SDK: Set single Key LED color
///
internal static bool SetLedColor(int row, int column, byte r, byte g, byte b, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
- => _setLedColorPointer(row, column, r, g, b, devIndex);
+ => (_setLedColorPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(row, column, r, g, b, devIndex);
///
/// CM-SDK: Set Keyboard "every LED" color
///
internal static bool SetAllLedColor(_CoolerMasterColorMatrix colorMatrix, CoolerMasterDevicesIndexes devIndex = CoolerMasterDevicesIndexes.Default)
- => _setAllLedColorPointer(colorMatrix, devIndex);
+ => (_setAllLedColorPointer ?? throw new RGBDeviceException("The CoolerMaster-SDK is not initialized.")).Invoke(colorMatrix, devIndex);
// ReSharper restore EventExceptionNotDocumented
diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs
index 1e73657..b484518 100644
--- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs
+++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
using System.Runtime.InteropServices;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
@@ -18,7 +19,7 @@ namespace RGB.NET.Devices.Corsair
{
#region Properties & Fields
- private static CorsairDeviceProvider _instance;
+ private static CorsairDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
@@ -28,35 +29,24 @@ namespace RGB.NET.Devices.Corsair
/// 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 List { "x86/CUESDK.dll", "x86/CUESDK_2015.dll", "x86/CUESDK_2013.dll" };
+ public static List PossibleX86NativePaths { get; } = new() { "x86/CUESDK.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 List { "x64/CUESDK.dll", "x64/CUESDK_2015.dll", "x64/CUESDK_2013.dll" };
+ public static List PossibleX64NativePaths { get; } = new() { "x64/CUESDK.dll", "x64/CUESDK_2015.dll", "x64/CUESDK_2013.dll" };
///
///
/// Indicates if the SDK is initialized and ready to use.
///
public bool IsInitialized { get; private set; }
-
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- public string LoadedArchitecture => _CUESDK.LoadedArchitecture;
-
+
///
/// Gets the protocol details for the current SDK-connection.
///
- public CorsairProtocolDetails ProtocolDetails { get; private set; }
-
- ///
- ///
- /// Gets whether the application has exclusive access to the SDK or not.
- ///
- public bool HasExclusiveAccess { get; private set; }
+ public CorsairProtocolDetails? ProtocolDetails { get; private set; }
///
/// Gets the last error documented by CUE.
@@ -64,7 +54,7 @@ namespace RGB.NET.Devices.Corsair
public CorsairError LastError => _CUESDK.CorsairGetLastError();
///
- public IEnumerable Devices { get; private set; }
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
///
/// The used to trigger the updates for corsair devices.
@@ -100,7 +90,7 @@ namespace RGB.NET.Devices.Corsair
try
{
- UpdateTrigger?.Stop();
+ UpdateTrigger.Stop();
_CUESDK.Reload();
@@ -115,33 +105,23 @@ namespace RGB.NET.Devices.Corsair
+ $"CUE-Version: {ProtocolDetails.ServerVersion} (Protocol {ProtocolDetails.ServerProtocolVersion})\r\n"
+ $"SDK-Version: {ProtocolDetails.SdkVersion} (Protocol {ProtocolDetails.SdkProtocolVersion})");
- if (exclusiveAccessIfPossible)
- {
- if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
- throw new CUEException(LastError);
-
- HasExclusiveAccess = true;
- }
- else
- HasExclusiveAccess = false;
-
- // DarthAffe 07.07.2018: 127 is CUE, we want to directly compete with it as in older versions.
- if (!_CUESDK.CorsairSetLayerPriority(127))
+ // DarthAffe 02.02.2021: 127 is iCUE
+ if (!_CUESDK.CorsairSetLayerPriority(128))
throw new CUEException(LastError);
- Dictionary modelCounter = new Dictionary();
+ Dictionary modelCounter = new();
IList devices = new List();
int deviceCount = _CUESDK.CorsairGetDeviceCount();
for (int i = 0; i < deviceCount; i++)
{
try
{
- _CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo));
- CorsairRGBDeviceInfo info = new CorsairRGBDeviceInfo(i, RGBDeviceType.Unknown, nativeDeviceInfo, modelCounter);
+ _CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo))!;
+ CorsairRGBDeviceInfo info = new(i, RGBDeviceType.Unknown, nativeDeviceInfo, modelCounter);
if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting))
continue; // Everything that doesn't support lighting control is useless
- CorsairDeviceUpdateQueue deviceUpdateQueue = null;
+ CorsairDeviceUpdateQueue? deviceUpdateQueue = null;
foreach (ICorsairRGBDevice device in GetRGBDevice(info, i, nativeDeviceInfo, modelCounter))
{
if ((device == null) || !loadFilter.HasFlag(device.DeviceInfo.DeviceType)) continue;
@@ -161,7 +141,7 @@ namespace RGB.NET.Devices.Corsair
catch { if (throwExceptions) throw; }
}
- UpdateTrigger?.Start();
+ UpdateTrigger.Start();
Devices = new ReadOnlyCollection(devices);
IsInitialized = true;
@@ -207,7 +187,7 @@ namespace RGB.NET.Devices.Corsair
case CorsairDeviceType.Cooler:
case CorsairDeviceType.CommanderPro:
case CorsairDeviceType.LightningNodePro:
- _CorsairChannelsInfo channelsInfo = nativeDeviceInfo.channels;
+ _CorsairChannelsInfo? channelsInfo = nativeDeviceInfo.channels;
if (channelsInfo != null)
{
IntPtr channelInfoPtr = channelsInfo.channels;
@@ -217,14 +197,14 @@ namespace RGB.NET.Devices.Corsair
CorsairLedId referenceLed = GetChannelReferenceId(info.CorsairDeviceType, channel);
if (referenceLed == CorsairLedId.Invalid) continue;
- _CorsairChannelInfo channelInfo = (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo));
+ _CorsairChannelInfo channelInfo = (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo))!;
int channelDeviceInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelDeviceInfo));
IntPtr channelDeviceInfoPtr = channelInfo.devices;
for (int device = 0; device < channelInfo.devicesCount; device++)
{
- _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo));
+ _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo))!;
yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(info, nativeDeviceInfo, channelDeviceInfo, referenceLed, modelCounter));
referenceLed += channelDeviceInfo.deviceLedCount;
@@ -278,8 +258,7 @@ namespace RGB.NET.Devices.Corsair
private void Reset()
{
ProtocolDetails = null;
- HasExclusiveAccess = false;
- Devices = null;
+ Devices = Enumerable.Empty();
IsInitialized = false;
}
diff --git a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs
index 174fd47..7107aa0 100644
--- a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs
+++ b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs
@@ -14,7 +14,7 @@ namespace RGB.NET.Devices.Corsair
{
#region Properties & Fields
- private readonly Dictionary _idMapping = new Dictionary();
+ private readonly Dictionary _idMapping = new();
#endregion
diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs
index 664a6e6..ae1859a 100644
--- a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs
+++ b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs
@@ -40,11 +40,11 @@ namespace RGB.NET.Devices.Corsair
{
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
IntPtr ptr = Marshal.AllocHGlobal(structSize * dataSet.Count);
- IntPtr addPtr = new IntPtr(ptr.ToInt64());
+ IntPtr addPtr = new(ptr.ToInt64());
foreach (KeyValuePair data in dataSet)
{
- _CorsairLedColor color = new _CorsairLedColor
- {
+ _CorsairLedColor color = new()
+ {
ledId = (int)data.Key,
r = data.Value.GetR(),
g = data.Value.GetG(),
diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs b/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs
index 3f66761..1bd2786 100644
--- a/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs
+++ b/RGB.NET.Devices.Corsair/Generic/CorsairProtocolDetails.cs
@@ -18,12 +18,12 @@ namespace RGB.NET.Devices.Corsair
/// 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; }
+ 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; }
+ public string? ServerVersion { get; }
///
/// Integer that specifies version of protocol that is implemented by current SDK.
diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs
index ef12ad4..9dd74ea 100644
--- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs
+++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs
@@ -1,9 +1,6 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
-using System.Runtime.InteropServices;
using RGB.NET.Core;
-using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
{
@@ -27,13 +24,13 @@ namespace RGB.NET.Devices.Corsair
/// Gets a dictionary containing all of the .
///
// ReSharper disable once MemberCanBePrivate.Global
- protected Dictionary InternalLedMapping { get; } = new Dictionary();
+ protected Dictionary InternalLedMapping { get; } = new();
///
/// Gets or sets the update queue performing updates for this device.
///
// ReSharper disable once MemberCanBePrivate.Global
- protected CorsairDeviceUpdateQueue DeviceUpdateQueue { get; set; }
+ protected CorsairDeviceUpdateQueue? DeviceUpdateQueue { get; set; }
#endregion
@@ -45,7 +42,7 @@ namespace RGB.NET.Devices.Corsair
/// The of the to get.
/// The with the specified or null if no is found.
// ReSharper disable once MemberCanBePrivate.Global
- public Led this[CorsairLedId ledId] => InternalLedMapping.TryGetValue(ledId, out Led led) ? led : null;
+ public Led? this[CorsairLedId ledId] => InternalLedMapping.TryGetValue(ledId, out Led? led) ? led : null;
#endregion
@@ -75,14 +72,13 @@ namespace RGB.NET.Devices.Corsair
foreach (Led led in LedMapping.Values)
{
- CorsairLedId ledId = (CorsairLedId)led.CustomData;
- if (ledId != CorsairLedId.Invalid)
+ if (led.CustomData is CorsairLedId ledId && (ledId != CorsairLedId.Invalid))
InternalLedMapping.Add(ledId, led);
}
if (Size == Size.Invalid)
{
- Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
+ Rectangle ledRectangle = new(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
}
@@ -94,7 +90,7 @@ namespace RGB.NET.Devices.Corsair
///
protected override void UpdateLeds(IEnumerable ledsToUpdate)
- => DeviceUpdateQueue.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is CorsairLedId ledId && (ledId != CorsairLedId.Invalid))));
+ => DeviceUpdateQueue?.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is CorsairLedId ledId && (ledId != CorsairLedId.Invalid))));
///
public override void Dispose()
diff --git a/RGB.NET.Devices.Corsair/Headset/HeadsetIdMapping.cs b/RGB.NET.Devices.Corsair/Headset/HeadsetIdMapping.cs
index d446f09..7448184 100644
--- a/RGB.NET.Devices.Corsair/Headset/HeadsetIdMapping.cs
+++ b/RGB.NET.Devices.Corsair/Headset/HeadsetIdMapping.cs
@@ -5,8 +5,8 @@ namespace RGB.NET.Devices.Corsair
{
internal static class HeadsetIdMapping
{
- internal static readonly Dictionary DEFAULT = new Dictionary
- {
+ internal static readonly Dictionary DEFAULT = new()
+ {
{ LedId.Headset1, CorsairLedId.LeftLogo },
{ LedId.Headset2, CorsairLedId.RightLogo },
};
diff --git a/RGB.NET.Devices.Corsair/HeadsetStand/HeadsetStandIdMapping.cs b/RGB.NET.Devices.Corsair/HeadsetStand/HeadsetStandIdMapping.cs
index 619f823..4987118 100644
--- a/RGB.NET.Devices.Corsair/HeadsetStand/HeadsetStandIdMapping.cs
+++ b/RGB.NET.Devices.Corsair/HeadsetStand/HeadsetStandIdMapping.cs
@@ -5,8 +5,8 @@ namespace RGB.NET.Devices.Corsair
{
internal static class HeadsetStandIdMapping
{
- internal static readonly Dictionary DEFAULT = new Dictionary
- {
+ internal static readonly Dictionary DEFAULT = new()
+ {
{ LedId.HeadsetStand1, CorsairLedId.HeadsetStandZone1 },
{ LedId.HeadsetStand2, CorsairLedId.HeadsetStandZone2 },
{ LedId.HeadsetStand3, CorsairLedId.HeadsetStandZone3 },
diff --git a/RGB.NET.Devices.Corsair/Helper/DictionaryExtension.cs b/RGB.NET.Devices.Corsair/Helper/DictionaryExtension.cs
index 2bc44f5..936d560 100644
--- a/RGB.NET.Devices.Corsair/Helper/DictionaryExtension.cs
+++ b/RGB.NET.Devices.Corsair/Helper/DictionaryExtension.cs
@@ -5,6 +5,9 @@ namespace RGB.NET.Devices.Corsair
{
internal static class DictionaryExtension
{
- public static Dictionary SwapKeyValue(this Dictionary dictionary) => dictionary.ToDictionary(x => x.Value, x => x.Key);
+ public static Dictionary SwapKeyValue(this Dictionary dictionary)
+ where TKey : notnull
+ where TValue : notnull
+ => dictionary.ToDictionary(x => x.Value, x => x.Key);
}
}
diff --git a/RGB.NET.Devices.Corsair/Keyboard/KeyboardIdMapping.cs b/RGB.NET.Devices.Corsair/Keyboard/KeyboardIdMapping.cs
index 547cfef..d7855f6 100644
--- a/RGB.NET.Devices.Corsair/Keyboard/KeyboardIdMapping.cs
+++ b/RGB.NET.Devices.Corsair/Keyboard/KeyboardIdMapping.cs
@@ -5,8 +5,8 @@ namespace RGB.NET.Devices.Corsair
{
internal static class KeyboardIdMapping
{
- internal static readonly Dictionary DEFAULT = new Dictionary
- {
+ internal static readonly Dictionary DEFAULT = new()
+ {
{ LedId.Invalid, CorsairLedId.Invalid },
{ LedId.Logo, CorsairLedId.Logo },
{ LedId.Keyboard_Escape, CorsairLedId.Escape },
diff --git a/RGB.NET.Devices.Corsair/Memory/MemoryIdMapping.cs b/RGB.NET.Devices.Corsair/Memory/MemoryIdMapping.cs
index b7d7db4..50750cd 100644
--- a/RGB.NET.Devices.Corsair/Memory/MemoryIdMapping.cs
+++ b/RGB.NET.Devices.Corsair/Memory/MemoryIdMapping.cs
@@ -5,8 +5,8 @@ namespace RGB.NET.Devices.Corsair
{
internal static class MemoryIdMapping
{
- internal static readonly Dictionary DEFAULT = new Dictionary
- {
+ internal static readonly Dictionary DEFAULT = new()
+ {
{ LedId.Invalid, CorsairLedId.Invalid },
{ LedId.DRAM1, CorsairLedId.DRAM1 },
{ LedId.DRAM2, CorsairLedId.DRAM2 },
diff --git a/RGB.NET.Devices.Corsair/Mouse/MouseIdMapping.cs b/RGB.NET.Devices.Corsair/Mouse/MouseIdMapping.cs
index 00dea5b..95982fd 100644
--- a/RGB.NET.Devices.Corsair/Mouse/MouseIdMapping.cs
+++ b/RGB.NET.Devices.Corsair/Mouse/MouseIdMapping.cs
@@ -5,8 +5,8 @@ namespace RGB.NET.Devices.Corsair
{
internal static class MouseIdMapping
{
- internal static readonly Dictionary DEFAULT = new Dictionary
- {
+ internal static readonly Dictionary DEFAULT = new()
+ {
{ LedId.Mouse1, CorsairLedId.B1 },
{ LedId.Mouse2, CorsairLedId.B2 },
{ LedId.Mouse3, CorsairLedId.B3 },
@@ -15,15 +15,15 @@ namespace RGB.NET.Devices.Corsair
{ LedId.Mouse6, CorsairLedId.B6 },
};
- internal static readonly Dictionary GLAIVE = new Dictionary
- {
+ internal static readonly Dictionary GLAIVE = new()
+ {
{ LedId.Mouse1, CorsairLedId.B1 },
{ LedId.Mouse2, CorsairLedId.B2 },
{ LedId.Mouse3, CorsairLedId.B5 },
};
- internal static readonly Dictionary M65_RGB_ELITE = new Dictionary
- {
+ internal static readonly Dictionary M65_RGB_ELITE = new()
+ {
{ LedId.Mouse1, CorsairLedId.B1 },
{ LedId.Mouse2, CorsairLedId.B3 },
};
diff --git a/RGB.NET.Devices.Corsair/Mousepad/MousepadIdMapping.cs b/RGB.NET.Devices.Corsair/Mousepad/MousepadIdMapping.cs
index 3b49ad6..a415df6 100644
--- a/RGB.NET.Devices.Corsair/Mousepad/MousepadIdMapping.cs
+++ b/RGB.NET.Devices.Corsair/Mousepad/MousepadIdMapping.cs
@@ -5,8 +5,8 @@ namespace RGB.NET.Devices.Corsair
{
internal static class MousepadIdMapping
{
- internal static readonly Dictionary DEFAULT = new Dictionary
- {
+ internal static readonly Dictionary DEFAULT = new()
+ {
{ LedId.Mousepad1, CorsairLedId.Zone1 },
{ LedId.Mousepad2, CorsairLedId.Zone2 },
{ LedId.Mousepad3, CorsairLedId.Zone3 },
diff --git a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs
index 9b217e4..e8a0656 100644
--- a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs
+++ b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs
@@ -16,12 +16,7 @@ namespace RGB.NET.Devices.Corsair.Native
#region Libary Management
private static IntPtr _dllHandle = IntPtr.Zero;
-
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- internal static string LoadedArchitecture { get; private set; }
-
+
///
/// Reloads the SDK.
///
@@ -37,7 +32,7 @@ namespace RGB.NET.Devices.Corsair.Native
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
List possiblePathList = Environment.Is64BitProcess ? CorsairDeviceProvider.PossibleX64NativePaths : CorsairDeviceProvider.PossibleX86NativePaths;
- string dllPath = possiblePathList.FirstOrDefault(File.Exists);
+ 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))}'");
_dllHandle = LoadLibrary(dllPath);
@@ -80,18 +75,18 @@ namespace RGB.NET.Devices.Corsair.Native
#region Pointers
- private static CorsairSetLedsColorsBufferByDeviceIndexPointer _corsairSetLedsColorsBufferByDeviceIndexPointer;
- private static CorsairSetLedsColorsFlushBufferPointer _corsairSetLedsColorsFlushBufferPointer;
- private static CorsairGetLedsColorsByDeviceIndexPointer _corsairGetLedsColorsByDeviceIndexPointer;
- private static CorsairSetLayerPriorityPointer _corsairSetLayerPriorityPointer;
- private static CorsairGetDeviceCountPointer _corsairGetDeviceCountPointer;
- private static CorsairGetDeviceInfoPointer _corsairGetDeviceInfoPointer;
- private static CorsairGetLedIdForKeyNamePointer _corsairGetLedIdForKeyNamePointer;
- private static CorsairGetLedPositionsByDeviceIndexPointer _corsairGetLedPositionsByDeviceIndexPointer;
- private static CorsairRequestControlPointer _corsairRequestControlPointer;
- private static CorsairReleaseControlPointer _corsairReleaseControlPointer;
- private static CorsairPerformProtocolHandshakePointer _corsairPerformProtocolHandshakePointer;
- private static CorsairGetLastErrorPointer _corsairGetLastErrorPointer;
+ private static CorsairSetLedsColorsBufferByDeviceIndexPointer? _corsairSetLedsColorsBufferByDeviceIndexPointer;
+ private static CorsairSetLedsColorsFlushBufferPointer? _corsairSetLedsColorsFlushBufferPointer;
+ private static CorsairGetLedsColorsByDeviceIndexPointer? _corsairGetLedsColorsByDeviceIndexPointer;
+ private static CorsairSetLayerPriorityPointer? _corsairSetLayerPriorityPointer;
+ private static CorsairGetDeviceCountPointer? _corsairGetDeviceCountPointer;
+ private static CorsairGetDeviceInfoPointer? _corsairGetDeviceInfoPointer;
+ private static CorsairGetLedIdForKeyNamePointer? _corsairGetLedIdForKeyNamePointer;
+ private static CorsairGetLedPositionsByDeviceIndexPointer? _corsairGetLedPositionsByDeviceIndexPointer;
+ private static CorsairRequestControlPointer? _corsairRequestControlPointer;
+ private static CorsairReleaseControlPointer? _corsairReleaseControlPointer;
+ private static CorsairPerformProtocolHandshakePointer? _corsairPerformProtocolHandshakePointer;
+ private static CorsairGetLastErrorPointer? _corsairGetLastErrorPointer;
#endregion
@@ -144,68 +139,70 @@ namespace RGB.NET.Devices.Corsair.Native
/// 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 bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) => _corsairSetLedsColorsBufferByDeviceIndexPointer(deviceIndex, size, ledsColors);
+ internal static bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors)
+ => (_corsairSetLedsColorsBufferByDeviceIndexPointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke(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 bool CorsairSetLedsColorsFlushBuffer() => _corsairSetLedsColorsFlushBufferPointer();
+ internal static bool CorsairSetLedsColorsFlushBuffer() => (_corsairSetLedsColorsFlushBufferPointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke();
///
/// 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 bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) => _corsairGetLedsColorsByDeviceIndexPointer(deviceIndex, size, ledsColors);
+ internal static bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors)
+ => (_corsairGetLedsColorsByDeviceIndexPointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke(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 bool CorsairSetLayerPriority(int priority) => _corsairSetLayerPriorityPointer(priority);
+ internal static bool CorsairSetLayerPriority(int priority) => (_corsairSetLayerPriorityPointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke(priority);
///
/// CUE-SDK: returns number of connected Corsair devices that support lighting control.
///
- internal static int CorsairGetDeviceCount() => _corsairGetDeviceCountPointer();
+ internal static int CorsairGetDeviceCount() => (_corsairGetDeviceCountPointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke();
///
/// CUE-SDK: returns information about device at provided index.
///
- internal static IntPtr CorsairGetDeviceInfo(int deviceIndex) => _corsairGetDeviceInfoPointer(deviceIndex);
+ internal static IntPtr CorsairGetDeviceInfo(int deviceIndex) => (_corsairGetDeviceInfoPointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke(deviceIndex);
///
/// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions.
///
- internal static IntPtr CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => _corsairGetLedPositionsByDeviceIndexPointer(deviceIndex);
+ internal static IntPtr CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => (_corsairGetLedPositionsByDeviceIndexPointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke(deviceIndex);
///
/// CUE-SDK: retrieves led id for key name taking logical layout into account.
///
- internal static CorsairLedId CorsairGetLedIdForKeyName(char keyName) => _corsairGetLedIdForKeyNamePointer(keyName);
+ internal static CorsairLedId CorsairGetLedIdForKeyName(char keyName) => (_corsairGetLedIdForKeyNamePointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke(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 bool CorsairRequestControl(CorsairAccessMode accessMode) => _corsairRequestControlPointer(accessMode);
+ internal static bool CorsairRequestControl(CorsairAccessMode accessMode) => (_corsairRequestControlPointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke(accessMode);
///
/// CUE-SDK: releases previously requested control for specified access mode.
///
- internal static bool CorsairReleaseControl(CorsairAccessMode accessMode) => _corsairReleaseControlPointer(accessMode);
+ internal static bool CorsairReleaseControl(CorsairAccessMode accessMode) => (_corsairReleaseControlPointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke(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 _CorsairProtocolDetails CorsairPerformProtocolHandshake() => _corsairPerformProtocolHandshakePointer();
+ internal static _CorsairProtocolDetails CorsairPerformProtocolHandshake() => (_corsairPerformProtocolHandshakePointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke();
///
/// CUE-SDK: returns last error that occured while using any of Corsair* functions.
///
- internal static CorsairError CorsairGetLastError() => _corsairGetLastErrorPointer();
+ internal static CorsairError CorsairGetLastError() => (_corsairGetLastErrorPointer ?? throw new RGBDeviceException("The Corsair-SDK is not initialized.")).Invoke();
// ReSharper restore EventExceptionNotDocumented
diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs
index d584d73..418e9f6 100644
--- a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs
+++ b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs
@@ -47,6 +47,6 @@ namespace RGB.NET.Devices.Corsair.Native
///
/// CUE-SDK: structure that describes channels of the DIY-devices
///
- internal _CorsairChannelsInfo channels;
+ internal _CorsairChannelsInfo? channels;
}
}
diff --git a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs
index a151778..7535198 100644
--- a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs
+++ b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.DMX.E131;
@@ -17,7 +18,7 @@ namespace RGB.NET.Devices.DMX
{
#region Properties & Fields
- private static DMXDeviceProvider _instance;
+ private static DMXDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
@@ -27,20 +28,17 @@ namespace RGB.NET.Devices.DMX
public bool IsInitialized { get; private set; }
///
- public IEnumerable Devices { get; private set; }
-
- ///
- public bool HasExclusiveAccess => false;
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
///
/// Gets a list of all defined device-definitions.
///
- public List DeviceDefinitions { get; } = new List();
+ public List DeviceDefinitions { get; } = new();
///
/// The used to trigger the updates for dmx devices.
///
- public DeviceUpdateTrigger UpdateTrigger { get; private set; }
+ public DeviceUpdateTrigger UpdateTrigger { get; }
#endregion
@@ -87,7 +85,7 @@ namespace RGB.NET.Devices.DMX
{
if (e131DMXDeviceDefinition.Leds.Count > 0)
{
- E131Device device = new E131Device(new E131DeviceInfo(e131DMXDeviceDefinition), e131DMXDeviceDefinition.Leds);
+ E131Device device = new(new E131DeviceInfo(e131DMXDeviceDefinition), e131DMXDeviceDefinition.Leds);
device.Initialize(UpdateTrigger);
devices.Add(device);
}
diff --git a/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs b/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs
index 8e7fb9b..ca37238 100644
--- a/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs
+++ b/RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs
@@ -45,7 +45,7 @@ namespace RGB.NET.Devices.DMX.E131
/// Gets or sets the CID of the device (null will generate a random CID)
///
// ReSharper disable once InconsistentNaming
- public byte[] CID { get; set; }
+ public byte[]? CID { get; set; }
///
/// Gets or sets the universe the device belongs to.
@@ -55,7 +55,7 @@ namespace RGB.NET.Devices.DMX.E131
///
/// Gets or sets the led-mappings used to create the device.
///
- public Dictionary getValueFunc)>> Leds { get; } = new Dictionary getValueFunc)>>();
+ public Dictionary getValueFunc)>> Leds { get; } = new();
#endregion
diff --git a/RGB.NET.Devices.DMX/E131/E131Device.cs b/RGB.NET.Devices.DMX/E131/E131Device.cs
index 22dd25e..5131b9a 100644
--- a/RGB.NET.Devices.DMX/E131/E131Device.cs
+++ b/RGB.NET.Devices.DMX/E131/E131Device.cs
@@ -17,7 +17,7 @@ namespace RGB.NET.Devices.DMX.E131
private readonly Dictionary getValueFunc)>> _ledMappings;
- private E131UpdateQueue _updateQueue;
+ private E131UpdateQueue? _updateQueue;
#endregion
@@ -42,7 +42,7 @@ namespace RGB.NET.Devices.DMX.E131
if (Size == Size.Invalid)
{
- Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
+ Rectangle ledRectangle = new(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
@@ -56,7 +56,7 @@ namespace RGB.NET.Devices.DMX.E131
///
- protected override void UpdateLeds(IEnumerable ledsToUpdate) => _updateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
+ protected override void UpdateLeds(IEnumerable ledsToUpdate) => _updateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
///
public override void Dispose()
diff --git a/RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs b/RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs
index 667fba3..dc5c33e 100644
--- a/RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs
+++ b/RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs
@@ -32,7 +32,7 @@ namespace RGB.NET.Devices.DMX.E131
///
public string Model { get; }
-
+
public object? LayoutMetadata { get; set; }
///
@@ -66,15 +66,17 @@ namespace RGB.NET.Devices.DMX.E131
this.Model = deviceDefinition.Model;
this.Hostname = deviceDefinition.Hostname;
this.Port = deviceDefinition.Port;
- this.CID = deviceDefinition.CID;
this.Universe = deviceDefinition.Universe;
+ byte[]? cid = deviceDefinition.CID;
if ((CID == null) || (CID.Length != CID_LENGTH))
{
CID = new byte[CID_LENGTH];
new Random().NextBytes(CID);
}
+ CID = cid!;
+
DeviceName = $"{Manufacturer} {Model}";
}
diff --git a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs
index 4efe3d6..66ec439 100644
--- a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs
+++ b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
using RGB.NET.Core;
using RGB.NET.Layout;
@@ -17,7 +18,7 @@ namespace RGB.NET.Devices.Debug
{
#region Properties & Fields
- private static DebugDeviceProvider _instance;
+ private static DebugDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
@@ -27,10 +28,9 @@ namespace RGB.NET.Devices.Debug
public bool IsInitialized { get; private set; }
///
- public IEnumerable Devices { get; private set; }
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
- private List<(IDeviceLayout layout, string imageLayout, Action>? updateLedsAction)> _fakeDeviceDefinitions
- = new List<(IDeviceLayout layout, string imageLayout, Action>? updateLedsAction)>();
+ private List<(IDeviceLayout layout, string imageLayout, Action>? updateLedsAction)> _fakeDeviceDefinitions = new();
#endregion
@@ -70,10 +70,10 @@ namespace RGB.NET.Devices.Debug
IsInitialized = false;
try
{
- List devices = new List();
+ List devices = new();
foreach ((IDeviceLayout layout, string imageLayout, Action>? updateLedsAction) in _fakeDeviceDefinitions)
{
- DebugRGBDevice device = new DebugRGBDevice(layout, updateLedsAction);
+ DebugRGBDevice device = new(layout, updateLedsAction);
devices.Add(device);
}
diff --git a/RGB.NET.Devices.Logitech/Generic/LogitechRGBDevice.cs b/RGB.NET.Devices.Logitech/Generic/LogitechRGBDevice.cs
index d46c76f..eacb6b6 100644
--- a/RGB.NET.Devices.Logitech/Generic/LogitechRGBDevice.cs
+++ b/RGB.NET.Devices.Logitech/Generic/LogitechRGBDevice.cs
@@ -22,7 +22,7 @@ namespace RGB.NET.Devices.Logitech
/// Gets or sets the update queue performing updates for this device.
///
// ReSharper disable once MemberCanBePrivate.Global
- protected UpdateQueue UpdateQueue { get; set; }
+ protected UpdateQueue? UpdateQueue { get; set; }
#endregion
diff --git a/RGB.NET.Devices.Logitech/Generic/LogitechRGBDeviceInfo.cs b/RGB.NET.Devices.Logitech/Generic/LogitechRGBDeviceInfo.cs
index aefa7b5..bdf0614 100644
--- a/RGB.NET.Devices.Logitech/Generic/LogitechRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Logitech/Generic/LogitechRGBDeviceInfo.cs
@@ -34,16 +34,6 @@ namespace RGB.NET.Devices.Logitech
///
public int Zones { get; }
- ///
- /// Gets the layout used to decide which images to load.
- ///
- internal string ImageLayout { get; }
-
- ///
- /// Gets the path/name of the layout-file.
- ///
- internal string LayoutPath { get; }
-
#endregion
#region Constructors
@@ -57,15 +47,12 @@ namespace RGB.NET.Devices.Logitech
/// The amount of zones the device is able to control.
/// The layout used to decide which images to load.
/// The path/name of the layout-file.
- internal LogitechRGBDeviceInfo(RGBDeviceType deviceType, string model, LogitechDeviceCaps deviceCaps,
- int zones, string imageLayout, string layoutPath)
+ internal LogitechRGBDeviceInfo(RGBDeviceType deviceType, string model, LogitechDeviceCaps deviceCaps, int zones)
{
this.DeviceType = deviceType;
this.Model = model;
this.DeviceCaps = deviceCaps;
this.Zones = zones;
- this.ImageLayout = imageLayout;
- this.LayoutPath = layoutPath;
DeviceName = $"{Manufacturer} {Model}";
}
diff --git a/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs b/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs
index 5684fd7..800cc3e 100644
--- a/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs
+++ b/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs
@@ -5,83 +5,81 @@ using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech.HID
{
- //TODO DarthAffe 04.02.2017: Rewrite this once the SDK supports per-device lighting to get all the devices connected.
internal static class DeviceChecker
{
#region Constants
private const int VENDOR_ID = 0x046D;
- //TODO DarthAffe 14.11.2017: Add devices
- private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> PER_KEY_DEVICES
- = new List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>
- {
- ("G910", RGBDeviceType.Keyboard, 0xC32B, 0, "DE", @"Keyboards\G910\UK"), //TODO DarthAffe 15.11.2017: Somehow detect the current layout
- ("G910v2", RGBDeviceType.Keyboard, 0xC335, 0, "DE", @"Keyboards\G910\UK"),
- ("G915", RGBDeviceType.Keyboard, 0xC541, 0, "DE", @"Keyboards\G915\UK"),
- ("G810", RGBDeviceType.Keyboard, 0xC337, 0, "DE", @"Keyboards\G810\UK"),
- ("G810", RGBDeviceType.Keyboard, 0xC331, 0, "DE", @"Keyboards\G810\UK"),
- ("G610", RGBDeviceType.Keyboard, 0xC333, 0, "DE", @"Keyboards\G610\UK"),
- ("G512", RGBDeviceType.Keyboard, 0xC33C, 0, "DE", @"Keyboards\G512\UK"),
- ("G512 SE", RGBDeviceType.Keyboard, 0xC342, 0, "DE", @"Keyboards\G512SE\UK"),
- ("G410", RGBDeviceType.Keyboard, 0xC330, 0, "DE", @"Keyboards\G410\UK"),
- ("G213", RGBDeviceType.Keyboard, 0xC336, 0, "DE", @"Keyboards\G213\UK"),
- ("Pro", RGBDeviceType.Keyboard, 0xC339, 0, "DE", @"Keyboards\Pro\UK"),
- ("G915 TKL", RGBDeviceType.Keyboard, 0xC343, 0, "DE", @"Keyboards\G915TKL\UK"),
- ("Lightspeed Keyboard Dongle", RGBDeviceType.Keyboard, 0xC545, 0, "DE", @"Keyboards\G915\UK"),
- };
+ private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones)> PER_KEY_DEVICES
+ = new()
+ {
+ ("G910", RGBDeviceType.Keyboard, 0xC32B, 0),
+ ("G910v2", RGBDeviceType.Keyboard, 0xC335, 0),
+ ("G915", RGBDeviceType.Keyboard, 0xC541, 0),
+ ("G810", RGBDeviceType.Keyboard, 0xC337, 0),
+ ("G810", RGBDeviceType.Keyboard, 0xC331, 0),
+ ("G610", RGBDeviceType.Keyboard, 0xC333, 0),
+ ("G512", RGBDeviceType.Keyboard, 0xC33C, 0),
+ ("G512 SE", RGBDeviceType.Keyboard, 0xC342, 0),
+ ("G410", RGBDeviceType.Keyboard, 0xC330, 0),
+ ("G213", RGBDeviceType.Keyboard, 0xC336, 0),
+ ("Pro", RGBDeviceType.Keyboard, 0xC339, 0),
+ ("G915 TKL", RGBDeviceType.Keyboard, 0xC343, 0),
+ ("Lightspeed Keyboard Dongle", RGBDeviceType.Keyboard, 0xC545, 0),
+ };
- private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> PER_DEVICE_DEVICES
- = new List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>
- {
- ("G19", RGBDeviceType.Keyboard, 0xC228, 0, "DE", @"Keyboards\G19\UK"),
- ("G19s", RGBDeviceType.Keyboard, 0xC229, 0, "DE", @"Keyboards\G19s\UK"),
- ("G600", RGBDeviceType.Mouse, 0xC24A, 0, "default", @"Mice\G600"),
- ("G300s", RGBDeviceType.Mouse, 0xC246, 0, "default", @"Mice\G300s"),
- ("G510", RGBDeviceType.Keyboard, 0xC22D, 0, "DE", @"Keyboards\G510\UK"),
- ("G510s", RGBDeviceType.Keyboard, 0xC22E, 0, "DE", @"Keyboards\G510s\UK"),
- ("G13", RGBDeviceType.Keypad, 0xC21C, 0, "DE", @"Keypads\G13\UK"),
- ("G110", RGBDeviceType.Keyboard, 0xC22B, 0, "DE", @"Keyboards\G110\UK"),
- ("G710+", RGBDeviceType.Keyboard, 0xC24D, 0, "DE", @"Keyboards\G710+\UK"),
- ("G105", RGBDeviceType.Keyboard, 0xC248, 0, "DE", @"Keyboards\G105\UK"),
- ("G15", RGBDeviceType.Keyboard, 0xC222, 0, "DE", @"Keyboards\G15\UK"),
- ("G11", RGBDeviceType.Keyboard, 0xC225, 0, "DE", @"Keyboards\G11\UK"),
- };
+ private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones)> PER_DEVICE_DEVICES
+ = new()
+ {
+ ("G19", RGBDeviceType.Keyboard, 0xC228, 0),
+ ("G19s", RGBDeviceType.Keyboard, 0xC229, 0),
+ ("G600", RGBDeviceType.Mouse, 0xC24A, 0),
+ ("G300s", RGBDeviceType.Mouse, 0xC246, 0),
+ ("G510", RGBDeviceType.Keyboard, 0xC22D, 0),
+ ("G510s", RGBDeviceType.Keyboard, 0xC22E, 0),
+ ("G13", RGBDeviceType.Keypad, 0xC21C, 0),
+ ("G110", RGBDeviceType.Keyboard, 0xC22B, 0),
+ ("G710+", RGBDeviceType.Keyboard, 0xC24D, 0),
+ ("G105", RGBDeviceType.Keyboard, 0xC248, 0),
+ ("G15", RGBDeviceType.Keyboard, 0xC222, 0),
+ ("G11", RGBDeviceType.Keyboard, 0xC225, 0),
+ };
- private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> ZONE_DEVICES
- = new List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>
- {
- ("G213", RGBDeviceType.Keyboard, 0xC336, 5, "default", @"Keyboards\G213"),
- ("G903", RGBDeviceType.Mouse, 0xC086, 2, "default", @"Mice\G903"),
- ("Lightspeed Mouse Dongle", RGBDeviceType.Mouse, 0xC539, 2, "default", @"Mice\G900"),
- ("G703", RGBDeviceType.Mouse, 0xC087, 2, "default", @"Mice\G703"),
- ("G502 HERO", RGBDeviceType.Mouse, 0xC08B, 2, "default", @"Mice\G502"),
- ("G502 Lightspeed", RGBDeviceType.Mouse, 0xC08D, 2, "default", @"Mice\G502"),
- ("G502", RGBDeviceType.Mouse, 0xC332, 2, "default", @"Mice\G502"),
- ("G403", RGBDeviceType.Mouse, 0xC083, 2, "default", @"Mice\G403"),
- ("G303", RGBDeviceType.Mouse, 0xC080, 2, "default", @"Mice\G303"),
- ("G203", RGBDeviceType.Mouse, 0xC084, 1, "default", @"Mice\G203"),
- ("G Pro", RGBDeviceType.Mouse, 0xC085, 1, "default", @"Mice\GPro"),
- ("G Pro Wireless", RGBDeviceType.Mouse, 0xC088, 2, "default", @"Mice\GProWireless"),
- ("G Pro Hero", RGBDeviceType.Mouse, 0xC08C, 1, "default", @"Mice\GProHero"),
- ("G633", RGBDeviceType.Headset, 0x0A5C, 2, "default", @"Headsets\G633"),
- ("G933", RGBDeviceType.Headset, 0x0A5B, 2, "default", @"Headsets\G933"),
- ("G935", RGBDeviceType.Headset, 0x0A87, 2, "default", @"Headsets\G935"),
- ("G560", RGBDeviceType.Speaker, 0x0A78, 4, "default", @"Speakers\G560"),
- };
+ private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones)> ZONE_DEVICES
+ = new()
+ {
+ ("G213", RGBDeviceType.Keyboard, 0xC336, 5),
+ ("G903", RGBDeviceType.Mouse, 0xC086, 2),
+ ("Lightspeed Mouse Dongle", RGBDeviceType.Mouse, 0xC539, 2),
+ ("G703", RGBDeviceType.Mouse, 0xC087, 2),
+ ("G502 HERO", RGBDeviceType.Mouse, 0xC08B, 2),
+ ("G502 Lightspeed", RGBDeviceType.Mouse, 0xC08D, 2),
+ ("G502", RGBDeviceType.Mouse, 0xC332, 2),
+ ("G403", RGBDeviceType.Mouse, 0xC083, 2),
+ ("G303", RGBDeviceType.Mouse, 0xC080, 2),
+ ("G203", RGBDeviceType.Mouse, 0xC084, 1),
+ ("G Pro", RGBDeviceType.Mouse, 0xC085, 1),
+ ("G Pro Wireless", RGBDeviceType.Mouse, 0xC088, 2),
+ ("G Pro Hero", RGBDeviceType.Mouse, 0xC08C, 1),
+ ("G633", RGBDeviceType.Headset, 0x0A5C, 2),
+ ("G933", RGBDeviceType.Headset, 0x0A5B, 2),
+ ("G935", RGBDeviceType.Headset, 0x0A87, 2),
+ ("G560", RGBDeviceType.Speaker, 0x0A78, 4),
+ };
#endregion
#region Properties & Fields
public static bool IsPerKeyDeviceConnected { get; private set; }
- public static (string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath) PerKeyDeviceData { get; private set; }
+ public static (string model, RGBDeviceType deviceType, int id, int zones) PerKeyDeviceData { get; private set; }
public static bool IsPerDeviceDeviceConnected { get; private set; }
- public static (string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath) PerDeviceDeviceData { get; private set; }
+ public static (string model, RGBDeviceType deviceType, int id, int zones) PerDeviceDeviceData { get; private set; }
public static bool IsZoneDeviceConnected { get; private set; }
- public static IEnumerable<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> ZoneDeviceData { get; private set; }
+ public static IEnumerable<(string model, RGBDeviceType deviceType, int id, int zones)> ZoneDeviceData { get; private set; } = Enumerable.Empty<(string model, RGBDeviceType deviceType, int id, int zones)>();
#endregion
@@ -91,7 +89,7 @@ namespace RGB.NET.Devices.Logitech.HID
{
List ids = DeviceList.Local.GetHidDevices(VENDOR_ID).Select(x => x.ProductID).Distinct().ToList();
- foreach ((string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath) deviceData in PER_KEY_DEVICES)
+ foreach ((string model, RGBDeviceType deviceType, int id, int zones) deviceData in PER_KEY_DEVICES)
if (ids.Contains(deviceData.id))
{
IsPerKeyDeviceConnected = true;
@@ -99,7 +97,7 @@ namespace RGB.NET.Devices.Logitech.HID
break;
}
- foreach ((string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath) deviceData in PER_DEVICE_DEVICES)
+ foreach ((string model, RGBDeviceType deviceType, int id, int zones) deviceData in PER_DEVICE_DEVICES)
if (ids.Contains(deviceData.id))
{
IsPerDeviceDeviceConnected = true;
@@ -107,21 +105,19 @@ namespace RGB.NET.Devices.Logitech.HID
break;
}
- Dictionary> connectedZoneDevices
- = new Dictionary>();
- foreach ((string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath) deviceData in ZONE_DEVICES)
+ Dictionary> connectedZoneDevices = new();
+ foreach ((string model, RGBDeviceType deviceType, int id, int zones) deviceData in ZONE_DEVICES)
{
if (ids.Contains(deviceData.id))
{
IsZoneDeviceConnected = true;
- if (!connectedZoneDevices.TryGetValue(deviceData.deviceType, out List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> deviceList))
- connectedZoneDevices.Add(deviceData.deviceType, deviceList = new List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>());
+ if (!connectedZoneDevices.TryGetValue(deviceData.deviceType, out List<(string model, RGBDeviceType deviceType, int id, int zones)>? deviceList))
+ connectedZoneDevices.Add(deviceData.deviceType, deviceList = new List<(string model, RGBDeviceType deviceType, int id, int zones)>());
deviceList.Add(deviceData);
}
}
- List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)> zoneDeviceData
- = new List<(string model, RGBDeviceType deviceType, int id, int zones, string imageLayout, string layoutPath)>();
- foreach (KeyValuePair> connectedZoneDevice in connectedZoneDevices)
+ List<(string model, RGBDeviceType deviceType, int id, int zones)> zoneDeviceData = new();
+ foreach (KeyValuePair> connectedZoneDevice in connectedZoneDevices)
{
int maxZones = connectedZoneDevice.Value.Max(x => x.zones);
zoneDeviceData.Add(connectedZoneDevice.Value.First(x => x.zones == maxZones));
diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs
index 5169eb3..d5fb52a 100644
--- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs
+++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs
@@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
-using System.Globalization;
+using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.HID;
using RGB.NET.Devices.Logitech.Native;
@@ -19,7 +19,7 @@ namespace RGB.NET.Devices.Logitech
{
#region Properties & Fields
- private static LogitechDeviceProvider _instance;
+ private static LogitechDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
@@ -29,40 +29,27 @@ namespace RGB.NET.Devices.Logitech
/// 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 List { "x86/LogitechLedEnginesWrapper.dll" };
+ public static List PossibleX86NativePaths { get; } = new() { "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 List { "x64/LogitechLedEnginesWrapper.dll" };
+ public static List PossibleX64NativePaths { get; } = new() { "x64/LogitechLedEnginesWrapper.dll" };
///
public bool IsInitialized { get; private set; }
-
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- public string LoadedArchitecture => _LogitechGSDK.LoadedArchitecture;
-
+
///
- public IEnumerable Devices { get; private set; }
-
- ///
- public bool HasExclusiveAccess => false; // Exclusive access isn't possible for logitech devices.
-
- ///
- /// Gets or sets a function to get the culture for a specific device.
- ///
- public Func GetCulture { get; set; } = CultureHelper.GetCurrentCulture;
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
///
/// The used to trigger the updates for logitech devices.
///
- public DeviceUpdateTrigger UpdateTrigger { get; private set; }
+ public DeviceUpdateTrigger UpdateTrigger { get; }
// ReSharper disable once CollectionNeverQueried.Local - for now this is just to make sure they're never collected
- private readonly Dictionary _zoneUpdateQueues = new Dictionary();
+ private readonly Dictionary _zoneUpdateQueues = new();
private LogitechPerDeviceUpdateQueue _perDeviceUpdateQueue;
private LogitechPerKeyUpdateQueue _perKeyUpdateQueue;
@@ -102,7 +89,7 @@ namespace RGB.NET.Devices.Logitech
try
{
- UpdateTrigger?.Stop();
+ UpdateTrigger.Stop();
_LogitechGSDK.Reload();
if (!_LogitechGSDK.LogiLedInit()) return false;
@@ -116,10 +103,10 @@ namespace RGB.NET.Devices.Logitech
{
if (DeviceChecker.IsPerKeyDeviceConnected)
{
- (string model, RGBDeviceType deviceType, int _, int _, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData;
+ (string model, RGBDeviceType deviceType, int _, int _) = DeviceChecker.PerKeyDeviceData;
if (loadFilter.HasFlag(deviceType)) //TODO DarthAffe 07.12.2017: Check if it's worth to try another device if the one returned doesn't match the filter
{
- ILogitechRGBDevice device = new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.PerKeyRGB, 0, imageLayout, layoutPath));
+ ILogitechRGBDevice device = new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.PerKeyRGB, 0));
device.Initialize(_perKeyUpdateQueue);
devices.Add(device);
}
@@ -131,10 +118,10 @@ namespace RGB.NET.Devices.Logitech
{
if (DeviceChecker.IsPerDeviceDeviceConnected)
{
- (string model, RGBDeviceType deviceType, int _, int _, string imageLayout, string layoutPath) = DeviceChecker.PerDeviceDeviceData;
+ (string model, RGBDeviceType deviceType, int _, int _) = DeviceChecker.PerDeviceDeviceData;
if (loadFilter.HasFlag(deviceType)) //TODO DarthAffe 07.12.2017: Check if it's worth to try another device if the one returned doesn't match the filter
{
- ILogitechRGBDevice device = new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, 0, imageLayout, layoutPath));
+ ILogitechRGBDevice device = new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, 0));
device.Initialize(_perDeviceUpdateQueue);
devices.Add(device);
}
@@ -146,13 +133,13 @@ namespace RGB.NET.Devices.Logitech
{
if (DeviceChecker.IsZoneDeviceConnected)
{
- foreach ((string model, RGBDeviceType deviceType, int _, int zones, string imageLayout, string layoutPath) in DeviceChecker.ZoneDeviceData)
+ foreach ((string model, RGBDeviceType deviceType, int _, int zones) in DeviceChecker.ZoneDeviceData)
try
{
if (loadFilter.HasFlag(deviceType))
{
- LogitechZoneUpdateQueue updateQueue = new LogitechZoneUpdateQueue(UpdateTrigger, deviceType);
- ILogitechRGBDevice device = new LogitechZoneRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, zones, imageLayout, layoutPath));
+ LogitechZoneUpdateQueue updateQueue = new(UpdateTrigger, deviceType);
+ ILogitechRGBDevice device = new LogitechZoneRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, zones));
device.Initialize(updateQueue);
devices.Add(device);
_zoneUpdateQueues.Add(deviceType, updateQueue);
@@ -163,7 +150,7 @@ namespace RGB.NET.Devices.Logitech
}
catch { if (throwExceptions) throw; }
- UpdateTrigger?.Start();
+ UpdateTrigger.Start();
Devices = new ReadOnlyCollection(devices);
IsInitialized = true;
diff --git a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs
index 8f1b826..0fd1c05 100644
--- a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs
+++ b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs
@@ -17,12 +17,7 @@ namespace RGB.NET.Devices.Logitech.Native
#region Libary Management
private static IntPtr _dllHandle = IntPtr.Zero;
-
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- internal static string LoadedArchitecture { get; private set; }
-
+
///
/// Reloads the SDK.
///
@@ -38,7 +33,7 @@ namespace RGB.NET.Devices.Logitech.Native
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
List possiblePathList = Environment.Is64BitProcess ? LogitechDeviceProvider.PossibleX64NativePaths : LogitechDeviceProvider.PossibleX86NativePaths;
- string dllPath = possiblePathList.FirstOrDefault(File.Exists);
+ string? dllPath = possiblePathList.FirstOrDefault(File.Exists);
if (dllPath == null) throw new RGBDeviceException($"Can't find the Logitech-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
_dllHandle = LoadLibrary(dllPath);
@@ -81,16 +76,16 @@ namespace RGB.NET.Devices.Logitech.Native
#region Pointers
- private static LogiLedInitPointer _logiLedInitPointer;
- private static LogiLedShutdownPointer _logiLedShutdownPointer;
- private static LogiLedSetTargetDevicePointer _logiLedSetTargetDevicePointer;
- private static LogiLedGetSdkVersionPointer _logiLedGetSdkVersionPointer;
- private static LogiLedSaveCurrentLightingPointer _lgiLedSaveCurrentLightingPointer;
- private static LogiLedRestoreLightingPointer _logiLedRestoreLightingPointer;
- private static LogiLedSetLightingPointer _logiLedSetLightingPointer;
- private static LogiLedSetLightingForKeyWithKeyNamePointer _logiLedSetLightingForKeyWithKeyNamePointer;
- private static LogiLedSetLightingFromBitmapPointer _logiLedSetLightingFromBitmapPointer;
- private static LogiLedSetLightingForTargetZonePointer _logiLedSetLightingForTargetZonePointer;
+ private static LogiLedInitPointer? _logiLedInitPointer;
+ private static LogiLedShutdownPointer? _logiLedShutdownPointer;
+ private static LogiLedSetTargetDevicePointer? _logiLedSetTargetDevicePointer;
+ private static LogiLedGetSdkVersionPointer? _logiLedGetSdkVersionPointer;
+ private static LogiLedSaveCurrentLightingPointer? _lgiLedSaveCurrentLightingPointer;
+ private static LogiLedRestoreLightingPointer? _logiLedRestoreLightingPointer;
+ private static LogiLedSetLightingPointer? _logiLedSetLightingPointer;
+ private static LogiLedSetLightingForKeyWithKeyNamePointer? _logiLedSetLightingForKeyWithKeyNamePointer;
+ private static LogiLedSetLightingFromBitmapPointer? _logiLedSetLightingFromBitmapPointer;
+ private static LogiLedSetLightingForTargetZonePointer? _logiLedSetLightingForTargetZonePointer;
#endregion
@@ -130,11 +125,11 @@ namespace RGB.NET.Devices.Logitech.Native
// ReSharper disable EventExceptionNotDocumented
- internal static bool LogiLedInit() => _logiLedInitPointer();
+ internal static bool LogiLedInit() => (_logiLedInitPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
- internal static void LogiLedShutdown() => _logiLedShutdownPointer();
+ internal static void LogiLedShutdown() => (_logiLedShutdownPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
- internal static bool LogiLedSetTargetDevice(LogitechDeviceCaps targetDevice) => _logiLedSetTargetDevicePointer((int)targetDevice);
+ internal static bool LogiLedSetTargetDevice(LogitechDeviceCaps targetDevice) => (_logiLedSetTargetDevicePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke((int)targetDevice);
internal static string LogiLedGetSdkVersion()
{
@@ -146,21 +141,23 @@ namespace RGB.NET.Devices.Logitech.Native
return $"{major}.{minor}.{build}";
}
- internal static bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum) => _logiLedGetSdkVersionPointer(ref majorNum, ref minorNum, ref buildNum);
+ internal static bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum) =>
+ (_logiLedGetSdkVersionPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(ref majorNum, ref minorNum, ref buildNum);
- internal static bool LogiLedSaveCurrentLighting() => _lgiLedSaveCurrentLightingPointer();
+ internal static bool LogiLedSaveCurrentLighting() => (_lgiLedSaveCurrentLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
- internal static bool LogiLedRestoreLighting() => _logiLedRestoreLightingPointer();
+ internal static bool LogiLedRestoreLighting() => (_logiLedRestoreLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
- internal static bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage) => _logiLedSetLightingPointer(redPercentage, greenPercentage, bluePercentage);
+ internal static bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage) =>
+ (_logiLedSetLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(redPercentage, greenPercentage, bluePercentage);
internal static bool LogiLedSetLightingForKeyWithKeyName(int keyCode, int redPercentage, int greenPercentage, int bluePercentage)
- => _logiLedSetLightingForKeyWithKeyNamePointer(keyCode, redPercentage, greenPercentage, bluePercentage);
+ => (_logiLedSetLightingForKeyWithKeyNamePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(keyCode, redPercentage, greenPercentage, bluePercentage);
- internal static bool LogiLedSetLightingFromBitmap(byte[] bitmap) => _logiLedSetLightingFromBitmapPointer(bitmap);
+ internal static bool LogiLedSetLightingFromBitmap(byte[] bitmap) => (_logiLedSetLightingFromBitmapPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(bitmap);
internal static bool LogiLedSetLightingForTargetZone(LogitechDeviceType deviceType, int zone, int redPercentage, int greenPercentage, int bluePercentage)
- => _logiLedSetLightingForTargetZonePointer(deviceType, zone, redPercentage, greenPercentage, bluePercentage);
+ => (_logiLedSetLightingForTargetZonePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(deviceType, zone, redPercentage, greenPercentage, bluePercentage);
// ReSharper restore EventExceptionNotDocumented
diff --git a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs
index f2c1656..416e18e 100644
--- a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs
+++ b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs
@@ -33,10 +33,10 @@ namespace RGB.NET.Devices.Logitech
AddLed(LedId.Custom1, new Point(0, 0), new Size(10, 10));
}
///
- protected override object? GetLedCustomData(LedId ledId) => (ledId, LogitechLedId.DEVICE);
+ protected override object GetLedCustomData(LedId ledId) => (ledId, LogitechLedId.DEVICE);
///
- protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0).Take(1));
+ protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0).Take(1));
#endregion
}
diff --git a/RGB.NET.Devices.Logitech/PerKey/BitmapMapping.cs b/RGB.NET.Devices.Logitech/PerKey/BitmapMapping.cs
index 9bd9a6e..dcfba20 100644
--- a/RGB.NET.Devices.Logitech/PerKey/BitmapMapping.cs
+++ b/RGB.NET.Devices.Logitech/PerKey/BitmapMapping.cs
@@ -14,8 +14,8 @@ namespace RGB.NET.Devices.Logitech
#region Properties & Fields
- internal static Dictionary BitmapOffset { get; } = new Dictionary
- {
+ internal static Dictionary BitmapOffset { get; } = new()
+ {
{ LedId.Keyboard_Escape, 0 },
{ LedId.Keyboard_F1, 4 },
{ LedId.Keyboard_F2, 8 },
diff --git a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs
index 2328370..68d7353 100644
--- a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs
+++ b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs
@@ -29,7 +29,7 @@ namespace RGB.NET.Devices.Logitech
protected override object? GetLedCustomData(LedId ledId) => (ledId, PerKeyIdMapping.DEFAULT.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : LogitechLedId.Invalid);
///
- protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
+ protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
#endregion
}
diff --git a/RGB.NET.Devices.Logitech/PerKey/PerKeyIdMapping.cs b/RGB.NET.Devices.Logitech/PerKey/PerKeyIdMapping.cs
index 68d2cf4..9f8afbc 100644
--- a/RGB.NET.Devices.Logitech/PerKey/PerKeyIdMapping.cs
+++ b/RGB.NET.Devices.Logitech/PerKey/PerKeyIdMapping.cs
@@ -5,8 +5,8 @@ namespace RGB.NET.Devices.Logitech
{
internal static class PerKeyIdMapping
{
- internal static readonly Dictionary DEFAULT = new Dictionary
- {
+ internal static readonly Dictionary DEFAULT = new()
+ {
{ LedId.Invalid, LogitechLedId.Invalid },
{ LedId.Keyboard_Escape, LogitechLedId.ESC },
{ LedId.Keyboard_F1, LogitechLedId.F1 },
diff --git a/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs b/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs
index d250d4d..4b0da4f 100644
--- a/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs
+++ b/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs
@@ -12,13 +12,13 @@ namespace RGB.NET.Devices.Logitech
{
#region Constants
- private static readonly Dictionary BASE_LED_MAPPING = new Dictionary
+ private static readonly Dictionary BASE_LED_MAPPING = new()
{
- {RGBDeviceType.Keyboard, LedId.Keyboard_Programmable1},
- {RGBDeviceType.Mouse, LedId.Mouse1},
- {RGBDeviceType.Headset, LedId.Headset1},
- {RGBDeviceType.Mousepad, LedId.Mousepad1},
- {RGBDeviceType.Speaker, LedId.Speaker1}
+ { RGBDeviceType.Keyboard, LedId.Keyboard_Programmable1 },
+ { RGBDeviceType.Mouse, LedId.Mouse1 },
+ { RGBDeviceType.Headset, LedId.Headset1 },
+ { RGBDeviceType.Mousepad, LedId.Mousepad1 },
+ { RGBDeviceType.Speaker, LedId.Speaker1 }
};
#endregion
@@ -59,7 +59,7 @@ namespace RGB.NET.Devices.Logitech
protected override object? GetLedCustomData(LedId ledId) => (int)(ledId - _baseLedId);
///
- protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
+ protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
#endregion
}
diff --git a/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs b/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs
index a95ca98..c3fb9ef 100644
--- a/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs
+++ b/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs
@@ -12,8 +12,8 @@ namespace RGB.NET.Devices.Logitech
{
#region Constants
- private static readonly Dictionary DEVICE_TYPE_MAPPING = new Dictionary
- {
+ private static readonly Dictionary DEVICE_TYPE_MAPPING = new()
+ {
{RGBDeviceType.Keyboard, LogitechDeviceType.Keyboard},
{RGBDeviceType.Mouse, LogitechDeviceType.Mouse},
{RGBDeviceType.Headset, LogitechDeviceType.Headset},
diff --git a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs
index 258bf84..a6933cc 100644
--- a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs
+++ b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs
@@ -24,7 +24,7 @@ namespace RGB.NET.Devices.Msi
/// Gets or sets the update queue performing updates for this device.
///
// ReSharper disable once MemberCanBePrivate.Global
- protected MsiDeviceUpdateQueue DeviceUpdateQueue { get; set; }
+ protected MsiDeviceUpdateQueue? DeviceUpdateQueue { get; set; }
#endregion
@@ -54,7 +54,7 @@ namespace RGB.NET.Devices.Msi
if (Size == Size.Invalid)
{
- Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
+ Rectangle ledRectangle = new(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
}
@@ -66,7 +66,7 @@ namespace RGB.NET.Devices.Msi
///
protected override void UpdateLeds(IEnumerable ledsToUpdate)
- => DeviceUpdateQueue.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is int)));
+ => DeviceUpdateQueue?.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is int)));
///
public override void Dispose()
diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs
index ffc9506..62d3405 100644
--- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs
+++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
+using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.Msi.Exceptions;
using RGB.NET.Devices.Msi.Native;
@@ -19,7 +20,7 @@ namespace RGB.NET.Devices.Msi
{
#region Properties & Fields
- private static MsiDeviceProvider _instance;
+ private static MsiDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
@@ -29,13 +30,13 @@ namespace RGB.NET.Devices.Msi
/// 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 List { "x86/MysticLight_SDK.dll" };
+ public static List PossibleX86NativePaths { get; } = new() { "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 List { "x64/MysticLight_SDK.dll" };
+ public static List PossibleX64NativePaths { get; } = new() { "x64/MysticLight_SDK.dll" };
///
///
@@ -43,24 +44,8 @@ namespace RGB.NET.Devices.Msi
///
public bool IsInitialized { get; private set; }
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- public string LoadedArchitecture => _MsiSDK.LoadedArchitecture;
-
///
- ///
- /// Gets whether the application has exclusive access to the SDK or not.
- ///
- public bool HasExclusiveAccess { get; private set; }
-
- ///
- public IEnumerable Devices { get; private set; }
-
- ///
- /// Gets or sets a function to get the culture for a specific device.
- ///
- public Func GetCulture { get; set; } = CultureHelper.GetCurrentCulture;
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
///
/// The used to trigger the updates for corsair devices.
@@ -94,7 +79,7 @@ namespace RGB.NET.Devices.Msi
try
{
- UpdateTrigger?.Stop();
+ UpdateTrigger.Stop();
_MsiSDK.Reload();
@@ -117,7 +102,7 @@ namespace RGB.NET.Devices.Msi
//Hex3l: MSI_MB provide access to the motherboard "leds" where a led must be intended as a led header (JRGB, JRAINBOW etc..) (Tested on MSI X570 Unify)
if (deviceType.Equals("MSI_MB"))
{
- MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType);
+ MsiDeviceUpdateQueue updateQueue = new(UpdateTrigger, deviceType);
IMsiRGBDevice motherboard = new MsiMainboardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mainboard, deviceType, "MSI", "Motherboard"));
motherboard.Initialize(updateQueue, ledCount);
devices.Add(motherboard);
@@ -127,7 +112,7 @@ namespace RGB.NET.Devices.Msi
//Hex3l: Every led under MSI_VGA should be a different graphics card. Handling all the cards together seems a good way to avoid overlapping of leds
//Hex3l: The led name is the name of the card (e.g. NVIDIA GeForce RTX 2080 Ti) we could provide it in device info.
- MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType);
+ MsiDeviceUpdateQueue updateQueue = new(UpdateTrigger, deviceType);
IMsiRGBDevice graphicscard = new MsiGraphicsCardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.GraphicsCard, deviceType, "MSI", "GraphicsCard"));
graphicscard.Initialize(updateQueue, ledCount);
devices.Add(graphicscard);
@@ -137,7 +122,7 @@ namespace RGB.NET.Devices.Msi
//Hex3l: Every led under MSI_MOUSE should be a different mouse. Handling all the mouses together seems a good way to avoid overlapping of leds
//Hex3l: The led name is the name of the mouse (e.g. msi CLUTCH GM11) we could provide it in device info.
- MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType);
+ MsiDeviceUpdateQueue updateQueue = new(UpdateTrigger, deviceType);
IMsiRGBDevice mouses = new MsiMouseRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mouse, deviceType, "MSI", "Mouse"));
mouses.Initialize(updateQueue, ledCount);
devices.Add(mouses);
@@ -148,7 +133,7 @@ namespace RGB.NET.Devices.Msi
catch { if (throwExceptions) throw; }
}
- UpdateTrigger?.Start();
+ UpdateTrigger.Start();
Devices = new ReadOnlyCollection(devices);
IsInitialized = true;
diff --git a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs
index 930352f..3bede30 100644
--- a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs
+++ b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs
@@ -17,11 +17,6 @@ namespace RGB.NET.Devices.Msi.Native
private static IntPtr _dllHandle = IntPtr.Zero;
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- internal static string LoadedArchitecture { get; private set; }
-
///
/// Reloads the SDK.
///
@@ -37,10 +32,10 @@ namespace RGB.NET.Devices.Msi.Native
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
List possiblePathList = Environment.Is64BitProcess ? MsiDeviceProvider.PossibleX64NativePaths : MsiDeviceProvider.PossibleX86NativePaths;
- string dllPath = possiblePathList.FirstOrDefault(File.Exists);
+ string? dllPath = possiblePathList.FirstOrDefault(File.Exists);
if (dllPath == null) throw new RGBDeviceException($"Can't find the Msi-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
- SetDllDirectory(Path.GetDirectoryName(Path.GetFullPath(dllPath)));
+ SetDllDirectory(Path.GetDirectoryName(Path.GetFullPath(dllPath))!);
_dllHandle = LoadLibrary(dllPath);
@@ -87,20 +82,20 @@ namespace RGB.NET.Devices.Msi.Native
#region Pointers
- private static InitializePointer _initializePointer;
- private static GetDeviceInfoPointer _getDeviceInfoPointer;
- private static GetLedInfoPointer _getLedInfoPointer;
- private static GetLedColorPointer _getLedColorPointer;
- private static GetLedStylePointer _getLedStylePointer;
- private static GetLedMaxBrightPointer _getLedMaxBrightPointer;
- private static GetLedBrightPointer _getLedBrightPointer;
- private static GetLedMaxSpeedPointer _getLedMaxSpeedPointer;
- private static GetLedSpeedPointer _getLedSpeedPointer;
- private static SetLedColorPointer _setLedColorPointer;
- private static SetLedStylePointer _setLedStylePointer;
- private static SetLedBrightPointer _setLedBrightPointer;
- private static SetLedSpeedPointer _setLedSpeedPointer;
- private static GetErrorMessagePointer _getErrorMessagePointer;
+ private static InitializePointer? _initializePointer;
+ private static GetDeviceInfoPointer? _getDeviceInfoPointer;
+ private static GetLedInfoPointer? _getLedInfoPointer;
+ private static GetLedColorPointer? _getLedColorPointer;
+ private static GetLedStylePointer? _getLedStylePointer;
+ private static GetLedMaxBrightPointer? _getLedMaxBrightPointer;
+ private static GetLedBrightPointer? _getLedBrightPointer;
+ private static GetLedMaxSpeedPointer? _getLedMaxSpeedPointer;
+ private static GetLedSpeedPointer? _getLedSpeedPointer;
+ private static SetLedColorPointer? _setLedColorPointer;
+ private static SetLedStylePointer? _setLedStylePointer;
+ private static SetLedBrightPointer? _setLedBrightPointer;
+ private static SetLedSpeedPointer? _setLedSpeedPointer;
+ private static GetErrorMessagePointer? _getErrorMessagePointer;
#endregion
@@ -192,11 +187,11 @@ namespace RGB.NET.Devices.Msi.Native
#endregion
- internal static int Initialize() => _initializePointer();
+ internal static int Initialize() => (_initializePointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke();
internal static int GetDeviceInfo(out string[] pDevType, out int[] pLedCount)
{
// HACK - SDK GetDeviceInfo returns a string[] for ledCount, so we'll parse that to int.
- int result = _getDeviceInfoPointer(out pDevType, out string[] ledCount);
+ int result = (_getDeviceInfoPointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(out pDevType, out string[] ledCount);
pLedCount = new int[ledCount.Length];
for (int i = 0; i < ledCount.Length; i++)
@@ -205,21 +200,21 @@ namespace RGB.NET.Devices.Msi.Native
return result;
}
- internal static int GetLedInfo(string type, int index, out string pName, out string[] pLedStyles) => _getLedInfoPointer(type, index, out pName, out pLedStyles);
- internal static int GetLedColor(string type, int index, out int r, out int g, out int b) => _getLedColorPointer(type, index, out r, out g, out b);
- internal static int GetLedStyle(string type, int index, out string style) => _getLedStylePointer(type, index, out style);
- internal static int GetLedMaxBright(string type, int index, out int maxLevel) => _getLedMaxBrightPointer(type, index, out maxLevel);
- internal static int GetLedBright(string type, int index, out int currentLevel) => _getLedBrightPointer(type, index, out currentLevel);
- internal static int GetLedMaxSpeed(string type, int index, out int maxSpeed) => _getLedMaxSpeedPointer(type, index, out maxSpeed);
- internal static int GetLedSpeed(string type, int index, out int currentSpeed) => _getLedSpeedPointer(type, index, out currentSpeed);
- internal static int SetLedColor(string type, int index, int r, int g, int b) => _setLedColorPointer(type, index, r, g, b);
- internal static int SetLedStyle(string type, int index, string style) => _setLedStylePointer(type, index, style);
- internal static int SetLedBright(string type, int index, int level) => _setLedBrightPointer(type, index, level);
- internal static int SetLedSpeed(string type, int index, int speed) => _setLedSpeedPointer(type, index, speed);
+ internal static int GetLedInfo(string type, int index, out string pName, out string[] pLedStyles) => (_getLedInfoPointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(type, index, out pName, out pLedStyles);
+ internal static int GetLedColor(string type, int index, out int r, out int g, out int b) => (_getLedColorPointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(type, index, out r, out g, out b);
+ internal static int GetLedStyle(string type, int index, out string style) => (_getLedStylePointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(type, index, out style);
+ internal static int GetLedMaxBright(string type, int index, out int maxLevel) => (_getLedMaxBrightPointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(type, index, out maxLevel);
+ internal static int GetLedBright(string type, int index, out int currentLevel) => (_getLedBrightPointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(type, index, out currentLevel);
+ internal static int GetLedMaxSpeed(string type, int index, out int maxSpeed) => (_getLedMaxSpeedPointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(type, index, out maxSpeed);
+ internal static int GetLedSpeed(string type, int index, out int currentSpeed) => (_getLedSpeedPointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(type, index, out currentSpeed);
+ internal static int SetLedColor(string type, int index, int r, int g, int b) => (_setLedColorPointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(type, index, r, g, b);
+ internal static int SetLedStyle(string type, int index, string style) => (_setLedStylePointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(type, index, style);
+ internal static int SetLedBright(string type, int index, int level) => (_setLedBrightPointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(type, index, level);
+ internal static int SetLedSpeed(string type, int index, int speed) => (_setLedSpeedPointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(type, index, speed);
internal static string GetErrorMessage(int errorCode)
{
- _getErrorMessagePointer(errorCode, out string description);
+ (_getErrorMessagePointer ?? throw new RGBDeviceException("The MSI-SDK is not initialized.")).Invoke(errorCode, out string description);
return description;
}
diff --git a/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs
index 6e34359..5ce5547 100644
--- a/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs
+++ b/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs
@@ -47,9 +47,9 @@ namespace RGB.NET.Devices.Novation
/// Sends the specified message to the device this queue is performing updates for.
///
/// The message to send.
- protected virtual void SendMessage(ShortMessage message)
+ protected virtual void SendMessage(ShortMessage? message)
{
- if (message != null)
+ if (message != null)
_outputDevice.SendShort(message.Message);
}
@@ -59,7 +59,7 @@ namespace RGB.NET.Devices.Novation
///
/// The data set to create the message from.
/// The message created out of the data set.
- protected abstract ShortMessage CreateMessage(KeyValuePair data);
+ protected abstract ShortMessage? CreateMessage(KeyValuePair data);
///
public override void Dispose()
diff --git a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs
index d1f7679..c41c77e 100644
--- a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs
+++ b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs
@@ -25,7 +25,7 @@ namespace RGB.NET.Devices.Novation
/// The used to update this .
///
// ReSharper disable once MemberCanBePrivate.Global
- protected MidiUpdateQueue UpdateQueue { get; set; }
+ protected MidiUpdateQueue? UpdateQueue { get; set; }
#endregion
@@ -53,7 +53,7 @@ namespace RGB.NET.Devices.Novation
if (Size == Size.Invalid)
{
- Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
+ Rectangle ledRectangle = new(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
@@ -71,12 +71,12 @@ namespace RGB.NET.Devices.Novation
protected abstract void InitializeLayout();
///
- protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
+ protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
///
/// Resets the back to default.
///
- public virtual void Reset() => UpdateQueue.Reset();
+ public virtual void Reset() => UpdateQueue?.Reset();
///
///
diff --git a/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs
index 5dd9d54..2998059 100644
--- a/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs
+++ b/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs
@@ -152,7 +152,7 @@ namespace RGB.NET.Devices.Novation
#region Methods
///
- protected override ShortMessage CreateMessage(KeyValuePair data)
+ protected override ShortMessage? CreateMessage(KeyValuePair data)
{
(byte mode, byte id) = ((byte, byte))data.Key;
if (mode == 0x00) return null;
diff --git a/RGB.NET.Devices.Novation/Helper/EnumExtension.cs b/RGB.NET.Devices.Novation/Helper/EnumExtension.cs
index a3f432a..caeecfa 100644
--- a/RGB.NET.Devices.Novation/Helper/EnumExtension.cs
+++ b/RGB.NET.Devices.Novation/Helper/EnumExtension.cs
@@ -14,7 +14,7 @@ namespace RGB.NET.Devices.Novation
///
/// The enum value to get the description from.
/// The value of the of the source.
- internal static string GetDeviceId(this Enum source) => source.GetAttribute()?.Id;
+ internal static string? GetDeviceId(this Enum source) => source.GetAttribute()?.Id;
///
/// Gets the value of the .
@@ -36,10 +36,11 @@ namespace RGB.NET.Devices.Novation
/// The enum value to get the attribute from
/// The generic attribute type
/// The .
- private static T GetAttribute(this Enum source)
+ private static T? GetAttribute(this Enum source)
where T : Attribute
{
- FieldInfo fi = source.GetType().GetField(source.ToString());
+ 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;
}
diff --git a/RGB.NET.Devices.Novation/Launchpad/LaunchpadIdMapping.cs b/RGB.NET.Devices.Novation/Launchpad/LaunchpadIdMapping.cs
index 39aa29f..6a2a83c 100644
--- a/RGB.NET.Devices.Novation/Launchpad/LaunchpadIdMapping.cs
+++ b/RGB.NET.Devices.Novation/Launchpad/LaunchpadIdMapping.cs
@@ -5,8 +5,8 @@ namespace RGB.NET.Devices.Novation
{
internal static class LaunchpadIdMapping
{
- internal static readonly Dictionary LEGACY = new Dictionary
- {
+ internal static readonly Dictionary LEGACY = new()
+ {
{ LedId.Invalid, (0x00, 0xFF, 8, 0) },
{ LedId.LedMatrix1, (0x90, 0x00, 0, 1) },
@@ -93,8 +93,8 @@ namespace RGB.NET.Devices.Novation
{ LedId.Custom16, (0x90, 0x78, 8, 8) }, //Scene8
};
- internal static readonly Dictionary CURRENT = new Dictionary
- {
+ internal static readonly Dictionary CURRENT = new()
+ {
{ LedId.Invalid, (0x00, 0xFF, 8, 0) },
{ LedId.LedMatrix1, (0x90, 81, 0, 1) },
diff --git a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs
index 4e031fe..8299301 100644
--- a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs
+++ b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs
@@ -18,7 +18,7 @@ namespace RGB.NET.Devices.Novation
{
#region Properties & Fields
- private static NovationDeviceProvider _instance;
+ private static NovationDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
@@ -31,18 +31,12 @@ namespace RGB.NET.Devices.Novation
public bool IsInitialized { get; private set; }
///
- ///
- /// Gets whether the application has exclusive access to the SDK or not.
- ///
- public bool HasExclusiveAccess => false;
-
- ///
- public IEnumerable Devices { get; private set; }
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
///
/// The used to trigger the updates for novation devices.
///
- public DeviceUpdateTrigger UpdateTrigger { get; private set; }
+ public DeviceUpdateTrigger UpdateTrigger { get; }
#endregion
@@ -71,7 +65,7 @@ namespace RGB.NET.Devices.Novation
try
{
- UpdateTrigger?.Stop();
+ UpdateTrigger.Stop();
IList devices = new List();
@@ -85,7 +79,7 @@ namespace RGB.NET.Devices.Novation
NovationDevices? deviceId = (NovationDevices?)Enum.GetValues(typeof(NovationDevices))
.Cast()
- .FirstOrDefault(x => x.GetDeviceId().ToUpperInvariant().Contains(outCaps.name.ToUpperInvariant()));
+ .FirstOrDefault(x => x.GetDeviceId()?.ToUpperInvariant().Contains(outCaps.name.ToUpperInvariant()) ?? false);
if (deviceId == null) continue;
@@ -99,7 +93,7 @@ namespace RGB.NET.Devices.Novation
catch { if (throwExceptions) throw; }
}
- UpdateTrigger?.Start();
+ UpdateTrigger.Start();
Devices = new ReadOnlyCollection(devices);
IsInitialized = true;
}
@@ -118,7 +112,7 @@ namespace RGB.NET.Devices.Novation
{
foreach (IRGBDevice device in Devices)
{
- NovationLaunchpadRGBDevice novationDevice = device as NovationLaunchpadRGBDevice;
+ NovationLaunchpadRGBDevice? novationDevice = device as NovationLaunchpadRGBDevice;
novationDevice?.Reset();
}
}
@@ -126,7 +120,7 @@ namespace RGB.NET.Devices.Novation
///
public void Dispose()
{
- try { UpdateTrigger?.Dispose(); }
+ try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
}
diff --git a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs
index a9ade2b..7455aa4 100644
--- a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs
+++ b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkUpdateQueue.cs
@@ -34,7 +34,8 @@ namespace RGB.NET.Devices.Razer
foreach (KeyValuePair data in dataSet)
colors[(int)data.Key] = new _Color(data.Value);
- _ChromaLinkCustomEffect effectParams = new _ChromaLinkCustomEffect { Color = colors };
+ _ChromaLinkCustomEffect effectParams = new()
+ { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
diff --git a/RGB.NET.Devices.Razer/Enum/RazerLogicalKeyboardLayout.cs b/RGB.NET.Devices.Razer/Enum/RazerLogicalKeyboardLayout.cs
deleted file mode 100644
index 1ec9382..0000000
--- a/RGB.NET.Devices.Razer/Enum/RazerLogicalKeyboardLayout.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-// ReSharper disable InconsistentNaming
-// ReSharper disable UnusedMember.Global
-
-#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
-
-namespace RGB.NET.Devices.Razer
-{
- ///
- /// Contains list of available logical layouts for razer keyboards.
- ///
- public enum RazerLogicalKeyboardLayout
- {
- TODO
- };
-}
diff --git a/RGB.NET.Devices.Razer/Enum/RazerPhysicalKeyboardLayout.cs b/RGB.NET.Devices.Razer/Enum/RazerPhysicalKeyboardLayout.cs
deleted file mode 100644
index 090a2db..0000000
--- a/RGB.NET.Devices.Razer/Enum/RazerPhysicalKeyboardLayout.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-// ReSharper disable UnusedMember.Global
-// ReSharper disable InconsistentNaming
-
-#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
-
-namespace RGB.NET.Devices.Razer
-{
- ///
- /// Contains list of available physical layouts for razer keyboards.
- ///
- public enum RazerPhysicalKeyboardLayout
- {
- TODO
- }
-}
diff --git a/RGB.NET.Devices.Razer/Generic/Devices.cs b/RGB.NET.Devices.Razer/Generic/Devices.cs
index a1eeeff..bb596b1 100644
--- a/RGB.NET.Devices.Razer/Generic/Devices.cs
+++ b/RGB.NET.Devices.Razer/Generic/Devices.cs
@@ -5,8 +5,8 @@ namespace RGB.NET.Devices.Razer
{
internal class Devices
{
- public static readonly List<(Guid guid, string model)> KEYBOARDS = new List<(Guid guid, string model)>
- {
+ 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 "),
@@ -22,8 +22,8 @@ namespace RGB.NET.Devices.Razer
(new Guid("16BB5ABD-C1CD-4CB3-BDF7-62438748BD98"), "Razer Blackwidow Elite")
};
- public static readonly List<(Guid guid, string model)> MICE = new List<(Guid guid, string model)>
- {
+ 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"),
@@ -35,35 +35,35 @@ namespace RGB.NET.Devices.Razer
(new Guid("77834867-3237-4A9F-AD77-4A46C4183003"), "Razer DeathAdder Elite Chroma")
};
- public static readonly List<(Guid guid, string model)> HEADSETS = new List<(Guid guid, string model)>
- {
+ 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 List<(Guid guid, string model)>
- {
+ 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 List<(Guid guid, string model)>
- {
+ 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 List<(Guid guid, string model)>
- {
+ 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 List<(Guid guid, string model)>
- {
+ 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")
};
diff --git a/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs b/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs
index e537caf..25dc2f9 100644
--- a/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs
+++ b/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs
@@ -24,7 +24,7 @@ namespace RGB.NET.Devices.Razer
/// Gets or sets the update queue performing updates for this device.
///
// ReSharper disable once MemberCanBePrivate.Global
- protected RazerUpdateQueue UpdateQueue { get; set; }
+ protected RazerUpdateQueue? UpdateQueue { get; set; }
#endregion
@@ -54,7 +54,7 @@ namespace RGB.NET.Devices.Razer
if (Size == Size.Invalid)
{
- Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
+ Rectangle ledRectangle = new(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
@@ -74,12 +74,12 @@ namespace RGB.NET.Devices.Razer
protected abstract void InitializeLayout();
///
- protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
+ protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
///
/// Resets the device.
///
- public void Reset() => UpdateQueue.Reset();
+ public void Reset() => UpdateQueue?.Reset();
///
public override void Dispose()
diff --git a/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs b/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs
index 91563e1..7e5d9b7 100644
--- a/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs
+++ b/RGB.NET.Devices.Razer/Headset/RazerHeadsetUpdateQueue.cs
@@ -34,7 +34,8 @@ namespace RGB.NET.Devices.Razer
foreach (KeyValuePair data in dataSet)
colors[(int)data.Key] = new _Color(data.Value);
- _HeadsetCustomEffect effectParams = new _HeadsetCustomEffect { Color = colors };
+ _HeadsetCustomEffect effectParams = new()
+ { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
diff --git a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs
index 1057ecc..d380028 100644
--- a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs
@@ -2,7 +2,6 @@
// ReSharper disable UnusedMember.Global
using System;
-using System.Globalization;
using RGB.NET.Core;
namespace RGB.NET.Devices.Razer
@@ -13,20 +12,6 @@ namespace RGB.NET.Devices.Razer
///
public class RazerKeyboardRGBDeviceInfo : RazerRGBDeviceInfo
{
- #region Properties & Fields
-
- ///
- /// Gets the physical layout of the keyboard.
- ///
- public RazerPhysicalKeyboardLayout PhysicalLayout { get; private set; }
-
- ///
- /// Gets the logical layout of the keyboard as set in CUE settings.
- ///
- public RazerLogicalKeyboardLayout LogicalLayout { get; private set; }
-
- #endregion
-
#region Constructors
///
@@ -36,27 +21,9 @@ namespace RGB.NET.Devices.Razer
/// The Id of the .
/// The model of the .
/// The of the layout this keyboard is using.
- internal RazerKeyboardRGBDeviceInfo(Guid deviceId, string model, CultureInfo culture)
+ internal RazerKeyboardRGBDeviceInfo(Guid deviceId, string model)
: base(deviceId, RGBDeviceType.Keyboard, model)
- {
- SetLayouts(culture.KeyboardLayoutId);
- }
-
- #endregion
-
- #region Methods
-
- private void SetLayouts(int keyboardLayoutId)
- {
- switch (keyboardLayoutId)
- {
- //TODO DarthAffe 07.10.2017: Implement
- default:
- PhysicalLayout = RazerPhysicalKeyboardLayout.TODO;
- LogicalLayout = RazerLogicalKeyboardLayout.TODO;
- break;
- }
- }
+ { }
#endregion
}
diff --git a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs
index 9e00530..e87a987 100644
--- a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs
+++ b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardUpdateQueue.cs
@@ -34,7 +34,8 @@ namespace RGB.NET.Devices.Razer
foreach (KeyValuePair data in dataSet)
colors[(int)data.Key] = new _Color(data.Value);
- _KeyboardCustomEffect effectParams = new _KeyboardCustomEffect { Color = colors };
+ _KeyboardCustomEffect effectParams = new()
+ { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
diff --git a/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs b/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs
index 2efd757..f0e884d 100644
--- a/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs
+++ b/RGB.NET.Devices.Razer/Keypad/RazerKeypadUpdateQueue.cs
@@ -34,7 +34,8 @@ namespace RGB.NET.Devices.Razer
foreach (KeyValuePair data in dataSet)
colors[(int)data.Key] = new _Color(data.Value);
- _KeypadCustomEffect effectParams = new _KeypadCustomEffect { Color = colors };
+ _KeypadCustomEffect effectParams = new()
+ { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
diff --git a/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs b/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs
index f1b039d..95547d8 100644
--- a/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs
+++ b/RGB.NET.Devices.Razer/Mouse/RazerMouseUpdateQueue.cs
@@ -34,7 +34,8 @@ namespace RGB.NET.Devices.Razer
foreach (KeyValuePair data in dataSet)
colors[(int)data.Key] = new _Color(data.Value);
- _MouseCustomEffect effectParams = new _MouseCustomEffect { Color = colors };
+ _MouseCustomEffect effectParams = new()
+ { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
diff --git a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs
index f7ddb04..419099b 100644
--- a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs
+++ b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadUpdateQueue.cs
@@ -34,7 +34,8 @@ namespace RGB.NET.Devices.Razer
foreach (KeyValuePair data in dataSet)
colors[(int)data.Key] = new _Color(data.Value);
- _MousepadCustomEffect effectParams = new _MousepadCustomEffect { Color = colors };
+ _MousepadCustomEffect effectParams = new()
+ { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
diff --git a/RGB.NET.Devices.Razer/Native/_RazerSDK.cs b/RGB.NET.Devices.Razer/Native/_RazerSDK.cs
index ca096e5..2b9c1ef 100644
--- a/RGB.NET.Devices.Razer/Native/_RazerSDK.cs
+++ b/RGB.NET.Devices.Razer/Native/_RazerSDK.cs
@@ -17,11 +17,6 @@ namespace RGB.NET.Devices.Razer.Native
private static IntPtr _dllHandle = IntPtr.Zero;
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- internal static string LoadedArchitecture { get; private set; }
-
///
/// Reloads the SDK.
///
@@ -78,16 +73,16 @@ namespace RGB.NET.Devices.Razer.Native
#region Pointers
- private static InitPointer _initPointer;
- private static UnInitPointer _unInitPointer;
- private static QueryDevicePointer _queryDevicePointer;
- private static CreateEffectPointer _createEffectPointer;
- private static CreateHeadsetEffectPointer _createHeadsetEffectPointer;
- private static CreateChromaLinkEffectPointer _createChromaLinkEffectPointer;
- private static CreateKeyboardEffectPointer _createKeyboardEffectPointer;
- private static CreateMousepadEffectPointer _createMousepadEffectPointer;
- private static SetEffectPointer _setEffectPointer;
- private static DeleteEffectPointer _deleteEffectPointer;
+ private static InitPointer? _initPointer;
+ private static UnInitPointer? _unInitPointer;
+ private static QueryDevicePointer? _queryDevicePointer;
+ private static CreateEffectPointer? _createEffectPointer;
+ private static CreateHeadsetEffectPointer? _createHeadsetEffectPointer;
+ private static CreateChromaLinkEffectPointer? _createChromaLinkEffectPointer;
+ private static CreateKeyboardEffectPointer? _createKeyboardEffectPointer;
+ private static CreateMousepadEffectPointer? _createMousepadEffectPointer;
+ private static SetEffectPointer? _setEffectPointer;
+ private static DeleteEffectPointer? _deleteEffectPointer;
#endregion
@@ -130,12 +125,12 @@ namespace RGB.NET.Devices.Razer.Native
///
/// Razer-SDK: Initialize Chroma SDK.
///
- internal static RazerError Init() => _initPointer();
+ internal static RazerError Init() => (_initPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke();
///
/// Razer-SDK: UnInitialize Chroma SDK.
///
- internal static RazerError UnInit() => _unInitPointer();
+ internal static RazerError UnInit() => (_unInitPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke();
///
/// Razer-SDK: Query for device information.
@@ -145,27 +140,27 @@ namespace RGB.NET.Devices.Razer.Native
int structSize = Marshal.SizeOf(typeof(_DeviceInfo));
IntPtr deviceInfoPtr = Marshal.AllocHGlobal(structSize);
- RazerError error = _queryDevicePointer(deviceId, deviceInfoPtr);
+ RazerError error = (_queryDevicePointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(deviceId, deviceInfoPtr);
- deviceInfo = (_DeviceInfo)Marshal.PtrToStructure(deviceInfoPtr, typeof(_DeviceInfo));
+ deviceInfo = (_DeviceInfo)Marshal.PtrToStructure(deviceInfoPtr, typeof(_DeviceInfo))!;
Marshal.FreeHGlobal(deviceInfoPtr);
return error;
}
- internal static RazerError CreateEffect(Guid deviceId, int effectType, IntPtr param, ref Guid effectId) => _createEffectPointer(deviceId, effectType, param, ref effectId);
+ internal static RazerError CreateEffect(Guid deviceId, int effectType, IntPtr param, ref Guid effectId) => (_createEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(deviceId, effectType, param, ref effectId);
- internal static RazerError CreateHeadsetEffect(int effectType, IntPtr param, ref Guid effectId) => _createHeadsetEffectPointer(effectType, param, ref effectId);
+ internal static RazerError CreateHeadsetEffect(int effectType, IntPtr param, ref Guid effectId) => (_createHeadsetEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectType, param, ref effectId);
- internal static RazerError CreateChromaLinkEffect(int effectType, IntPtr param, ref Guid effectId) => _createChromaLinkEffectPointer(effectType, param, ref effectId);
+ internal static RazerError CreateChromaLinkEffect(int effectType, IntPtr param, ref Guid effectId) => (_createChromaLinkEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectType, param, ref effectId);
- internal static RazerError CreateKeyboardEffect(int effectType, IntPtr param, ref Guid effectId) => _createKeyboardEffectPointer(effectType, param, ref effectId);
+ internal static RazerError CreateKeyboardEffect(int effectType, IntPtr param, ref Guid effectId) => (_createKeyboardEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectType, param, ref effectId);
- internal static RazerError CreateMousepadEffect(int effectType, IntPtr param, ref Guid effectId) => _createMousepadEffectPointer(effectType, param, ref effectId);
+ internal static RazerError CreateMousepadEffect(int effectType, IntPtr param, ref Guid effectId) => (_createMousepadEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectType, param, ref effectId);
- internal static RazerError SetEffect(Guid effectId) => _setEffectPointer(effectId);
+ internal static RazerError SetEffect(Guid effectId) => (_setEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectId);
- internal static RazerError DeleteEffect(Guid effectId) => _deleteEffectPointer(effectId);
+ internal static RazerError DeleteEffect(Guid effectId) => (_deleteEffectPointer ?? throw new RGBDeviceException("The Razer-SDK is not initialized.")).Invoke(effectId);
// ReSharper restore EventExceptionNotDocumented
diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs
index a155248..70fa748 100644
--- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs
+++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs
@@ -20,7 +20,7 @@ namespace RGB.NET.Devices.Razer
{
#region Properties & Fields
- private static RazerDeviceProvider _instance;
+ private static RazerDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
@@ -30,13 +30,13 @@ namespace RGB.NET.Devices.Razer
/// 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 List { @"%systemroot%\SysWOW64\RzChromaSDK.dll" };
+ public static List PossibleX86NativePaths { get; } = new() { @"%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 List { @"%systemroot%\System32\RzChromaSDK.dll", @"%systemroot%\System32\RzChromaSDK64.dll" };
+ public static List PossibleX64NativePaths { get; } = new() { @"%systemroot%\System32\RzChromaSDK.dll", @"%systemroot%\System32\RzChromaSDK64.dll" };
///
///
@@ -44,24 +44,8 @@ namespace RGB.NET.Devices.Razer
///
public bool IsInitialized { get; private set; }
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- public string LoadedArchitecture => _RazerSDK.LoadedArchitecture;
-
///
- ///
- /// Gets whether the application has exclusive access to the SDK or not.
- ///
- public bool HasExclusiveAccess => false;
-
- ///
- public IEnumerable Devices { get; private set; }
-
- ///
- /// Gets or sets a function to get the culture for a specific device.
- ///
- public Func GetCulture { get; set; } = CultureHelper.GetCurrentCulture;
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
///
/// Forces to load the devices represented by the emulator even if they aren't reported to exist.
@@ -71,7 +55,7 @@ namespace RGB.NET.Devices.Razer
///
/// The used to trigger the updates for razer devices.
///
- public DeviceUpdateTrigger UpdateTrigger { get; private set; }
+ public DeviceUpdateTrigger UpdateTrigger { get; }
#endregion
@@ -103,7 +87,7 @@ namespace RGB.NET.Devices.Razer
try
{
- UpdateTrigger?.Stop();
+ UpdateTrigger.Stop();
_RazerSDK.Reload();
@@ -121,7 +105,7 @@ namespace RGB.NET.Devices.Razer
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.KEYBOARDS.FirstOrDefault().guid != guid))) continue;
- RazerKeyboardRGBDevice device = new RazerKeyboardRGBDevice(new RazerKeyboardRGBDeviceInfo(guid, model, GetCulture()));
+ RazerKeyboardRGBDevice device = new(new RazerKeyboardRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
@@ -134,7 +118,7 @@ namespace RGB.NET.Devices.Razer
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.MICE.FirstOrDefault().guid != guid))) continue;
- RazerMouseRGBDevice device = new RazerMouseRGBDevice(new RazerMouseRGBDeviceInfo(guid, model));
+ RazerMouseRGBDevice device = new(new RazerMouseRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
@@ -147,7 +131,7 @@ namespace RGB.NET.Devices.Razer
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.HEADSETS.FirstOrDefault().guid != guid))) continue;
- RazerHeadsetRGBDevice device = new RazerHeadsetRGBDevice(new RazerHeadsetRGBDeviceInfo(guid, model));
+ RazerHeadsetRGBDevice device = new(new RazerHeadsetRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
@@ -160,7 +144,7 @@ namespace RGB.NET.Devices.Razer
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.MOUSEMATS.FirstOrDefault().guid != guid))) continue;
- RazerMousepadRGBDevice device = new RazerMousepadRGBDevice(new RazerMousepadRGBDeviceInfo(guid, model));
+ RazerMousepadRGBDevice device = new(new RazerMousepadRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
@@ -173,7 +157,7 @@ namespace RGB.NET.Devices.Razer
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.KEYPADS.FirstOrDefault().guid != guid))) continue;
- RazerKeypadRGBDevice device = new RazerKeypadRGBDevice(new RazerKeypadRGBDeviceInfo(guid, model));
+ RazerKeypadRGBDevice device = new(new RazerKeypadRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
@@ -186,13 +170,13 @@ namespace RGB.NET.Devices.Razer
if (((_RazerSDK.QueryDevice(guid, out _DeviceInfo deviceInfo) != RazerError.Success) || (deviceInfo.Connected < 1))
&& (!LoadEmulatorDevices || (Razer.Devices.CHROMALINKS.FirstOrDefault().guid != guid))) continue;
- RazerChromaLinkRGBDevice device = new RazerChromaLinkRGBDevice(new RazerChromaLinkRGBDeviceInfo(guid, model));
+ RazerChromaLinkRGBDevice device = new(new RazerChromaLinkRGBDeviceInfo(guid, model));
device.Initialize(UpdateTrigger);
devices.Add(device);
}
catch { if (throwExceptions) throw; }
- UpdateTrigger?.Start();
+ UpdateTrigger.Start();
Devices = new ReadOnlyCollection(devices);
IsInitialized = true;
}
diff --git a/RGB.NET.Devices.SteelSeries/API/Model/CoreProps.cs b/RGB.NET.Devices.SteelSeries/API/Model/CoreProps.cs
index 2fde5f8..f5f9c52 100644
--- a/RGB.NET.Devices.SteelSeries/API/Model/CoreProps.cs
+++ b/RGB.NET.Devices.SteelSeries/API/Model/CoreProps.cs
@@ -5,6 +5,6 @@ namespace RGB.NET.Devices.SteelSeries.API.Model
internal class CoreProps
{
[JsonPropertyName("address")]
- public string Address { get; set; }
+ 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 2e5f043..0a7935c 100644
--- a/RGB.NET.Devices.SteelSeries/API/Model/Event.cs
+++ b/RGB.NET.Devices.SteelSeries/API/Model/Event.cs
@@ -8,13 +8,13 @@ namespace RGB.NET.Devices.SteelSeries.API.Model
#region Properties & Fields
[JsonPropertyName("game")]
- public string Game { get; set; }
+ public string? Game { get; set; }
[JsonPropertyName("event")]
- public string Name { get; set; }
+ public string? Name { get; set; }
[JsonPropertyName("data")]
- public Dictionary Data { get; } = new Dictionary();
+ public Dictionary Data { get; } = new();
#endregion
diff --git a/RGB.NET.Devices.SteelSeries/API/Model/Game.cs b/RGB.NET.Devices.SteelSeries/API/Model/Game.cs
index 33c62b1..fc418da 100644
--- a/RGB.NET.Devices.SteelSeries/API/Model/Game.cs
+++ b/RGB.NET.Devices.SteelSeries/API/Model/Game.cs
@@ -7,10 +7,10 @@ namespace RGB.NET.Devices.SteelSeries.API.Model
#region Properties & Fields
[JsonPropertyName("game")]
- public string Name { get; set; }
+ public string? Name { get; set; }
[JsonPropertyName("game_display_name")]
- public string DisplayName { get; set; }
+ public string? DisplayName { get; set; }
#endregion
diff --git a/RGB.NET.Devices.SteelSeries/API/Model/GoLispHandler.cs b/RGB.NET.Devices.SteelSeries/API/Model/GoLispHandler.cs
index f84b4b5..7ccf389 100644
--- a/RGB.NET.Devices.SteelSeries/API/Model/GoLispHandler.cs
+++ b/RGB.NET.Devices.SteelSeries/API/Model/GoLispHandler.cs
@@ -7,10 +7,10 @@ namespace RGB.NET.Devices.SteelSeries.API.Model
#region Properties & Fields
[JsonPropertyName("game")]
- public string Game { get; set; }
+ public string? Game { get; set; }
[JsonPropertyName("golisp")]
- public string Handler { get; set; }
+ public string? Handler { get; set; }
#endregion
diff --git a/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs b/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs
index 012d749..4d36107 100644
--- a/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs
+++ b/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs
@@ -6,7 +6,6 @@ using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
-using System.Text.Json.Serialization;
using RGB.NET.Devices.SteelSeries.API.Model;
namespace RGB.NET.Devices.SteelSeries.API
@@ -55,10 +54,10 @@ namespace RGB.NET.Devices.SteelSeries.API
#region Properties & Fields
// ReSharper disable InconsistentNaming
- private static readonly HttpClient _client = new HttpClient();
- private static readonly Game _game = new Game(GAME_NAME, GAME_DISPLAYNAME);
- private static readonly Event _event = new Event(_game, EVENT_NAME);
- private static string _baseUrl;
+ private static readonly HttpClient _client = new();
+ private static readonly Game _game = new(GAME_NAME, GAME_DISPLAYNAME);
+ private static readonly Event _event = new(_game, EVENT_NAME);
+ private static string? _baseUrl;
internal static bool IsInitialized => !string.IsNullOrWhiteSpace(_baseUrl);
@@ -74,7 +73,7 @@ namespace RGB.NET.Devices.SteelSeries.API
string corePropsPath = GetCorePropsPath();
if (!string.IsNullOrWhiteSpace(corePropsPath) && File.Exists(corePropsPath))
{
- CoreProps coreProps = JsonSerializer.Deserialize(File.ReadAllText(corePropsPath));
+ CoreProps? coreProps = JsonSerializer.Deserialize(File.ReadAllText(corePropsPath));
_baseUrl = coreProps?.Address;
if (_baseUrl != null)
{
@@ -93,12 +92,12 @@ namespace RGB.NET.Devices.SteelSeries.API
return IsInitialized;
}
- internal static void UpdateLeds(string device, Dictionary data)
+ internal static void UpdateLeds(string device, IList<(string zone, int[] color)> data)
{
_event.Data.Clear();
_event.Data.Add("value", device);
- _event.Data.Add("colors", data.Values.ToList());
- _event.Data.Add("zones", data.Keys.ToList());
+ _event.Data.Add("colors", data.Select(x => x.color).ToList());
+ _event.Data.Add("zones", data.Select(x => x.zone).ToList());
TriggerEvent(_event);
}
diff --git a/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs b/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs
index 3331a50..ce41a96 100644
--- a/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs
+++ b/RGB.NET.Devices.SteelSeries/Attribute/SteelSeriesEnumExtension.cs
@@ -10,31 +10,31 @@ namespace RGB.NET.Devices.SteelSeries
#region Properties & Fields
// ReSharper disable InconsistentNaming
- private static readonly Dictionary _deviceTypeNames = new Dictionary();
- private static readonly Dictionary _ledIdNames = new Dictionary();
+ private static readonly Dictionary _deviceTypeNames = new();
+ private static readonly Dictionary _ledIdNames = new();
// ReSharper restore InconsistentNaming
#endregion
#region Methods
- internal static string GetAPIName(this SteelSeriesDeviceType deviceType)
+ internal static string? GetAPIName(this SteelSeriesDeviceType deviceType)
{
- if (!_deviceTypeNames.TryGetValue(deviceType, out string apiName))
+ if (!_deviceTypeNames.TryGetValue(deviceType, out string? apiName))
_deviceTypeNames.Add(deviceType, apiName = GetAPIName(typeof(SteelSeriesDeviceType), deviceType));
return apiName;
}
- internal static string GetAPIName(this SteelSeriesLedId ledId)
+ internal static string? GetAPIName(this SteelSeriesLedId ledId)
{
- if (!_ledIdNames.TryGetValue(ledId, out string apiName))
+ if (!_ledIdNames.TryGetValue(ledId, out string? apiName))
_ledIdNames.Add(ledId, apiName = GetAPIName(typeof(SteelSeriesLedId), ledId));
return apiName;
}
- private static string GetAPIName(Type type, Enum value)
+ private static string? GetAPIName(Type type, Enum value)
{
MemberInfo[] memInfo = type.GetMember(value.ToString());
if (memInfo.Length == 0) return null;
diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs
index c2befb6..25de272 100644
--- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs
+++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs
@@ -35,9 +35,9 @@ namespace RGB.NET.Devices.SteelSeries
#region Methods
- protected override void OnUpdate(object sender, CustomUpdateData customData)
+ protected override void OnUpdate(object? sender, CustomUpdateData customData)
{
- if ((customData != null) && (customData["refresh"] as bool? ?? false))
+ if (customData["refresh"] as bool? ?? false)
SteelSeriesSDK.SendHeartbeat();
else
base.OnUpdate(sender, customData);
@@ -45,7 +45,7 @@ namespace RGB.NET.Devices.SteelSeries
///
protected override void Update(Dictionary dataSet)
- => SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.ToDictionary(x => ((SteelSeriesLedId)x.Key).GetAPIName(), x => x.Value.ToIntArray()));
+ => SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.Select(x => (((SteelSeriesLedId)x.Key).GetAPIName(), x.Value.ToIntArray())).Where(x => x.Item1 != null).ToList()!);
#endregion
}
diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateTrigger.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateTrigger.cs
index c6a6823..cf33016 100644
--- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateTrigger.cs
+++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateTrigger.cs
@@ -71,7 +71,7 @@ namespace RGB.NET.Devices.SteelSeries
}
///
- protected override void OnUpdate(CustomUpdateData updateData = null)
+ protected override void OnUpdate(CustomUpdateData? updateData = null)
{
base.OnUpdate(updateData);
_lastUpdateTimestamp = Stopwatch.GetTimestamp();
diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs
index 4d04d9e..255dd90 100644
--- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs
+++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs
@@ -13,7 +13,7 @@ namespace RGB.NET.Devices.SteelSeries
{
#region Properties & Fields
- private Dictionary _ledMapping;
+ private Dictionary _ledMapping = new();
///
///
@@ -25,7 +25,7 @@ namespace RGB.NET.Devices.SteelSeries
/// Gets or sets the update queue performing updates for this device.
///
// ReSharper disable once MemberCanBePrivate.Global
- protected UpdateQueue UpdateQueue { get; set; }
+ protected UpdateQueue? UpdateQueue { get; set; }
#endregion
@@ -68,7 +68,7 @@ namespace RGB.NET.Devices.SteelSeries
protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId];
///
- protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
+ protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
///
public override void Dispose()
diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDeviceInfo.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDeviceInfo.cs
index 0c30675..96ba1f1 100644
--- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDeviceInfo.cs
@@ -1,5 +1,4 @@
-using System;
-using RGB.NET.Core;
+using RGB.NET.Core;
namespace RGB.NET.Devices.SteelSeries
{
@@ -27,17 +26,7 @@ namespace RGB.NET.Devices.SteelSeries
public object? LayoutMetadata { get; set; }
public SteelSeriesDeviceType SteelSeriesDeviceType { get; }
-
- ///
- /// Gets the layout used to decide which images to load.
- ///
- internal string ImageLayout { get; }
-
- ///
- /// Gets the path/name of the layout-file.
- ///
- internal string LayoutPath { get; }
-
+
#endregion
#region Constructors
@@ -50,13 +39,11 @@ namespace RGB.NET.Devices.SteelSeries
/// The lighting-capabilities of the device.
/// The layout used to decide which images to load.
/// The path/name of the layout-file.
- internal SteelSeriesRGBDeviceInfo(RGBDeviceType deviceType, string model, SteelSeriesDeviceType steelSeriesDeviceType, string imageLayout, string layoutPath)
+ internal SteelSeriesRGBDeviceInfo(RGBDeviceType deviceType, string model, SteelSeriesDeviceType steelSeriesDeviceType)
{
this.DeviceType = deviceType;
this.Model = model;
this.SteelSeriesDeviceType = steelSeriesDeviceType;
- this.ImageLayout = imageLayout;
- this.LayoutPath = layoutPath;
DeviceName = $"{Manufacturer} {Model}";
}
diff --git a/RGB.NET.Devices.SteelSeries/HID/DeviceChecker.cs b/RGB.NET.Devices.SteelSeries/HID/DeviceChecker.cs
index 16192db..deca9f3 100644
--- a/RGB.NET.Devices.SteelSeries/HID/DeviceChecker.cs
+++ b/RGB.NET.Devices.SteelSeries/HID/DeviceChecker.cs
@@ -2,7 +2,7 @@
using System.Linq;
using HidSharp;
using RGB.NET.Core;
-using DeviceDataList = System.Collections.Generic.List<(string model, RGB.NET.Core.RGBDeviceType deviceType, int id, RGB.NET.Devices.SteelSeries.SteelSeriesDeviceType steelSeriesDeviceType, string imageLayout, string layoutPath, System.Collections.Generic.Dictionary ledMapping)>;
+using DeviceDataList = System.Collections.Generic.List<(string model, RGB.NET.Core.RGBDeviceType deviceType, int id, RGB.NET.Devices.SteelSeries.SteelSeriesDeviceType steelSeriesDeviceType, System.Collections.Generic.Dictionary ledMapping)>;
using LedMapping = System.Collections.Generic.Dictionary;
namespace RGB.NET.Devices.SteelSeries.HID
@@ -11,7 +11,7 @@ namespace RGB.NET.Devices.SteelSeries.HID
{
#region Constants
- private static readonly LedMapping KEYBOARD_MAPPING_UK = new LedMapping
+ private static readonly LedMapping KEYBOARD_MAPPING_UK = new()
{
{ LedId.Logo, SteelSeriesLedId.Logo },
{ LedId.Keyboard_Escape, SteelSeriesLedId.Escape },
@@ -121,7 +121,7 @@ namespace RGB.NET.Devices.SteelSeries.HID
{ LedId.Keyboard_NumPeriodAndDelete, SteelSeriesLedId.KeypadPeriod }
};
- private static readonly LedMapping KEYBOARD_TKL_MAPPING_UK = new LedMapping
+ private static readonly LedMapping KEYBOARD_TKL_MAPPING_UK = new()
{
{ LedId.Logo, SteelSeriesLedId.Logo },
{ LedId.Keyboard_Escape, SteelSeriesLedId.Escape },
@@ -214,87 +214,87 @@ namespace RGB.NET.Devices.SteelSeries.HID
{ LedId.Keyboard_ArrowRight, SteelSeriesLedId.RightArrow }
};
- private static readonly LedMapping MOUSE_ONE_ZONE = new LedMapping
+ private static readonly LedMapping MOUSE_ONE_ZONE = new()
{
- {LedId.Mouse1, SteelSeriesLedId.ZoneOne}
+ { LedId.Mouse1, SteelSeriesLedId.ZoneOne }
};
- private static readonly LedMapping MOUSE_TWO_ZONE = new LedMapping
- {
- {LedId.Mouse1, SteelSeriesLedId.ZoneOne},
- {LedId.Mouse2, SteelSeriesLedId.ZoneTwo}
- };
+ private static readonly LedMapping MOUSE_TWO_ZONE = new()
+ {
+ { LedId.Mouse1, SteelSeriesLedId.ZoneOne },
+ { LedId.Mouse2, SteelSeriesLedId.ZoneTwo }
+ };
- private static readonly LedMapping MOUSE_THREE_ZONE = new LedMapping
- {
- {LedId.Mouse1, SteelSeriesLedId.ZoneOne},
- {LedId.Mouse2, SteelSeriesLedId.ZoneTwo},
- {LedId.Mouse3, SteelSeriesLedId.ZoneThree}
- };
-
- private static readonly LedMapping MOUSE_EIGHT_ZONE = new LedMapping
- {
- { LedId.Mouse1, SteelSeriesLedId.ZoneOne},
- { LedId.Mouse2, SteelSeriesLedId.ZoneTwo},
- { LedId.Mouse3, SteelSeriesLedId.ZoneThree},
- { LedId.Mouse4, SteelSeriesLedId.ZoneFour},
- { LedId.Mouse5, SteelSeriesLedId.ZoneFive},
- { LedId.Mouse6, SteelSeriesLedId.ZoneSix},
- { LedId.Mouse7, SteelSeriesLedId.ZoneSeven},
- { LedId.Mouse8, SteelSeriesLedId.ZoneEight}
- };
-
- private static readonly LedMapping HEADSET_TWO_ZONE = new LedMapping
+ private static readonly LedMapping MOUSE_THREE_ZONE = new()
{
- {LedId.Headset1, SteelSeriesLedId.ZoneOne},
- {LedId.Headset2, SteelSeriesLedId.ZoneTwo}
+ { LedId.Mouse1, SteelSeriesLedId.ZoneOne },
+ { LedId.Mouse2, SteelSeriesLedId.ZoneTwo },
+ { LedId.Mouse3, SteelSeriesLedId.ZoneThree }
};
-
+
+ private static readonly LedMapping MOUSE_EIGHT_ZONE = new()
+ {
+ { LedId.Mouse1, SteelSeriesLedId.ZoneOne },
+ { LedId.Mouse2, SteelSeriesLedId.ZoneTwo },
+ { LedId.Mouse3, SteelSeriesLedId.ZoneThree },
+ { LedId.Mouse4, SteelSeriesLedId.ZoneFour },
+ { LedId.Mouse5, SteelSeriesLedId.ZoneFive },
+ { LedId.Mouse6, SteelSeriesLedId.ZoneSix },
+ { LedId.Mouse7, SteelSeriesLedId.ZoneSeven },
+ { LedId.Mouse8, SteelSeriesLedId.ZoneEight }
+ };
+
+ private static readonly LedMapping HEADSET_TWO_ZONE = new()
+ {
+ { LedId.Headset1, SteelSeriesLedId.ZoneOne },
+ { LedId.Headset2, SteelSeriesLedId.ZoneTwo }
+ };
+
private const int VENDOR_ID = 0x1038;
//TODO DarthAffe 16.02.2019: Add devices
- private static readonly DeviceDataList DEVICES = new DeviceDataList
+ private static readonly DeviceDataList DEVICES = new()
{
//Mice
- ("Aerox 3", RGBDeviceType.Mouse, 0x1836, SteelSeriesDeviceType.ThreeZone, "default", @"Mice\Aerox3", MOUSE_THREE_ZONE),
- ("Aerox 3 Wireless", RGBDeviceType.Mouse, 0x183A, SteelSeriesDeviceType.ThreeZone, "default", @"Mice\Aerox3Wireless", MOUSE_THREE_ZONE),
- ("Rival 100", RGBDeviceType.Mouse, 0x1702, SteelSeriesDeviceType.OneZone, "default", @"Mice\Rival100", MOUSE_ONE_ZONE),
- ("Rival 105", RGBDeviceType.Mouse, 0x1814, SteelSeriesDeviceType.OneZone, "default", @"Mice\Rival105", MOUSE_ONE_ZONE),
- ("Rival 106", RGBDeviceType.Mouse, 0x1816, SteelSeriesDeviceType.OneZone, "default", @"Mice\Rival106", MOUSE_ONE_ZONE),
- ("Rival 110", RGBDeviceType.Mouse, 0x1729, SteelSeriesDeviceType.OneZone, "default", @"Mice\Rival110", MOUSE_ONE_ZONE),
- ("Rival 150", RGBDeviceType.Mouse, 0x0472, SteelSeriesDeviceType.OneZone, "default", @"Mice\Rival150", MOUSE_ONE_ZONE),
- ("Rival 300", RGBDeviceType.Mouse, 0x1710, SteelSeriesDeviceType.TwoZone, "default", @"Mice\Rival300", MOUSE_TWO_ZONE),
- ("Rival 310", RGBDeviceType.Mouse, 0x1720, SteelSeriesDeviceType.TwoZone, "default", @"Mice\Rival310", MOUSE_TWO_ZONE),
- ("Rival 500", RGBDeviceType.Mouse, 0x170E, SteelSeriesDeviceType.TwoZone, "default", @"Mice\Rival500", MOUSE_TWO_ZONE),
- ("Rival 600", RGBDeviceType.Mouse, 0x1724, SteelSeriesDeviceType.EightZone, "default", @"Mice\Rival600", MOUSE_EIGHT_ZONE),
- ("Rival 700", RGBDeviceType.Mouse, 0x1700, SteelSeriesDeviceType.TwoZone, "default", @"Mice\Rival700", MOUSE_TWO_ZONE),
- ("Rival 3 (Old Firmware)", RGBDeviceType.Mouse, 0x1824, SteelSeriesDeviceType.ThreeZone, "default", @"Mice\Rival3", MOUSE_THREE_ZONE),
- ("Rival 3", RGBDeviceType.Mouse, 0x184C, SteelSeriesDeviceType.ThreeZone, "default", @"Mice\Rival3", MOUSE_THREE_ZONE),
- ("Rival 3 Wireless", RGBDeviceType.Mouse, 0x1830, SteelSeriesDeviceType.ThreeZone, "default", @"Mice\Rival3Wireless", MOUSE_THREE_ZONE),
- ("Sensei Ten", RGBDeviceType.Mouse, 0x1832, SteelSeriesDeviceType.TwoZone, "default", @"Mice\SenseiTen", MOUSE_TWO_ZONE),
+ ("Aerox 3", RGBDeviceType.Mouse, 0x1836, SteelSeriesDeviceType.ThreeZone, MOUSE_THREE_ZONE),
+ ("Aerox 3 Wireless", RGBDeviceType.Mouse, 0x183A, SteelSeriesDeviceType.ThreeZone, MOUSE_THREE_ZONE),
+ ("Rival 100", RGBDeviceType.Mouse, 0x1702, SteelSeriesDeviceType.OneZone, MOUSE_ONE_ZONE),
+ ("Rival 105", RGBDeviceType.Mouse, 0x1814, SteelSeriesDeviceType.OneZone, MOUSE_ONE_ZONE),
+ ("Rival 106", RGBDeviceType.Mouse, 0x1816, SteelSeriesDeviceType.OneZone, MOUSE_ONE_ZONE),
+ ("Rival 110", RGBDeviceType.Mouse, 0x1729, SteelSeriesDeviceType.OneZone, MOUSE_ONE_ZONE),
+ ("Rival 150", RGBDeviceType.Mouse, 0x0472, SteelSeriesDeviceType.OneZone, MOUSE_ONE_ZONE),
+ ("Rival 300", RGBDeviceType.Mouse, 0x1710, SteelSeriesDeviceType.TwoZone, MOUSE_TWO_ZONE),
+ ("Rival 310", RGBDeviceType.Mouse, 0x1720, SteelSeriesDeviceType.TwoZone, MOUSE_TWO_ZONE),
+ ("Rival 500", RGBDeviceType.Mouse, 0x170E, SteelSeriesDeviceType.TwoZone, MOUSE_TWO_ZONE),
+ ("Rival 600", RGBDeviceType.Mouse, 0x1724, SteelSeriesDeviceType.EightZone, MOUSE_EIGHT_ZONE),
+ ("Rival 700", RGBDeviceType.Mouse, 0x1700, SteelSeriesDeviceType.TwoZone, MOUSE_TWO_ZONE),
+ ("Rival 3 (Old Firmware)", RGBDeviceType.Mouse, 0x1824, SteelSeriesDeviceType.ThreeZone, MOUSE_THREE_ZONE),
+ ("Rival 3", RGBDeviceType.Mouse, 0x184C, SteelSeriesDeviceType.ThreeZone, MOUSE_THREE_ZONE),
+ ("Rival 3 Wireless", RGBDeviceType.Mouse, 0x1830, SteelSeriesDeviceType.ThreeZone, MOUSE_THREE_ZONE),
+ ("Sensei Ten", RGBDeviceType.Mouse, 0x1832, SteelSeriesDeviceType.TwoZone, MOUSE_TWO_ZONE),
//Keyboards
- ("Apex 5", RGBDeviceType.Keyboard, 0x161C, SteelSeriesDeviceType.PerKey, "UK", @"Keyboards\5\UK", KEYBOARD_MAPPING_UK),
- ("Apex 7", RGBDeviceType.Keyboard, 0x1612, SteelSeriesDeviceType.PerKey, "UK", @"Keyboards\7\UK", KEYBOARD_MAPPING_UK),
- ("Apex 7 TKL", RGBDeviceType.Keyboard, 0x1618, SteelSeriesDeviceType.PerKey, "UK", @"Keyboards\7TKL\UK", KEYBOARD_TKL_MAPPING_UK),
- ("Apex M750", RGBDeviceType.Keyboard, 0x0616, SteelSeriesDeviceType.PerKey, "UK", @"Keyboards\M750\UK", KEYBOARD_MAPPING_UK),
- ("Apex M800", RGBDeviceType.Keyboard, 0x1600, SteelSeriesDeviceType.PerKey, "UK", @"Keyboards\M800\UK", KEYBOARD_MAPPING_UK),
- ("Apex Pro", RGBDeviceType.Keyboard, 0x1610, SteelSeriesDeviceType.PerKey, "UK", @"Keyboards\Pro\UK", KEYBOARD_MAPPING_UK),
- ("Apex Pro TKL", RGBDeviceType.Keyboard, 0x1614, SteelSeriesDeviceType.PerKey, "UK", @"Keyboards\ProTKL\UK", KEYBOARD_TKL_MAPPING_UK),
+ ("Apex 5", RGBDeviceType.Keyboard, 0x161C, SteelSeriesDeviceType.PerKey, KEYBOARD_MAPPING_UK),
+ ("Apex 7", RGBDeviceType.Keyboard, 0x1612, SteelSeriesDeviceType.PerKey, KEYBOARD_MAPPING_UK),
+ ("Apex 7 TKL", RGBDeviceType.Keyboard, 0x1618, SteelSeriesDeviceType.PerKey, KEYBOARD_TKL_MAPPING_UK),
+ ("Apex M750", RGBDeviceType.Keyboard, 0x0616, SteelSeriesDeviceType.PerKey, KEYBOARD_MAPPING_UK),
+ ("Apex M800", RGBDeviceType.Keyboard, 0x1600, SteelSeriesDeviceType.PerKey, KEYBOARD_MAPPING_UK),
+ ("Apex Pro", RGBDeviceType.Keyboard, 0x1610, SteelSeriesDeviceType.PerKey, KEYBOARD_MAPPING_UK),
+ ("Apex Pro TKL", RGBDeviceType.Keyboard, 0x1614, SteelSeriesDeviceType.PerKey, KEYBOARD_TKL_MAPPING_UK),
//Headsets
- ("Arctis 5", RGBDeviceType.Headset, 0x12AA, SteelSeriesDeviceType.TwoZone, "default", @"Headsets\Artis5", HEADSET_TWO_ZONE),
- ("Arctis 5 Game", RGBDeviceType.Headset, 0x1250, SteelSeriesDeviceType.TwoZone, "default", @"Headsets\Artis5", HEADSET_TWO_ZONE),
- ("Arctis 5 Game - Dota 2 edition", RGBDeviceType.Headset, 0x1251, SteelSeriesDeviceType.TwoZone, "default", @"Headsets\Artis5", HEADSET_TWO_ZONE),
- ("Arctis 5 Game - PUBG edition", RGBDeviceType.Headset, 0x12A8, SteelSeriesDeviceType.TwoZone, "default", @"Headsets\Artis5", HEADSET_TWO_ZONE),
- ("Arctis Pro Game", RGBDeviceType.Headset, 0x1252, SteelSeriesDeviceType.TwoZone, "default", @"Headsets\Artis5", HEADSET_TWO_ZONE),
+ ("Arctis 5", RGBDeviceType.Headset, 0x12AA, SteelSeriesDeviceType.TwoZone, HEADSET_TWO_ZONE),
+ ("Arctis 5 Game", RGBDeviceType.Headset, 0x1250, SteelSeriesDeviceType.TwoZone, HEADSET_TWO_ZONE),
+ ("Arctis 5 Game - Dota 2 edition", RGBDeviceType.Headset, 0x1251, SteelSeriesDeviceType.TwoZone, HEADSET_TWO_ZONE),
+ ("Arctis 5 Game - PUBG edition", RGBDeviceType.Headset, 0x12A8, SteelSeriesDeviceType.TwoZone, HEADSET_TWO_ZONE),
+ ("Arctis Pro Game", RGBDeviceType.Headset, 0x1252, SteelSeriesDeviceType.TwoZone, HEADSET_TWO_ZONE),
};
#endregion
#region Properties & Fields
- public static DeviceDataList ConnectedDevices { get; } = new DeviceDataList();
+ public static DeviceDataList ConnectedDevices { get; } = new();
#endregion
@@ -304,7 +304,7 @@ namespace RGB.NET.Devices.SteelSeries.HID
{
ConnectedDevices.Clear();
- HashSet ids = new HashSet(DeviceList.Local.GetHidDevices(VENDOR_ID).Select(x => x.ProductID).Distinct());
+ HashSet ids = new(DeviceList.Local.GetHidDevices(VENDOR_ID).Select(x => x.ProductID).Distinct());
DeviceDataList connectedDevices = DEVICES.Where(d => ids.Contains(d.id) && loadFilter.HasFlag(d.deviceType)).ToList();
List connectedDeviceTypes = connectedDevices.Select(d => d.steelSeriesDeviceType).ToList();
diff --git a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs
index 21402dd..2cbad8c 100644
--- a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs
+++ b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.SteelSeries.API;
using RGB.NET.Devices.SteelSeries.HID;
@@ -15,7 +16,7 @@ namespace RGB.NET.Devices.SteelSeries
{
#region Properties & Fields
- private static SteelSeriesDeviceProvider _instance;
+ private static SteelSeriesDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
@@ -28,13 +29,7 @@ namespace RGB.NET.Devices.SteelSeries
public bool IsInitialized { get; private set; }
///
- ///
- /// Gets whether the application has exclusive access to the SDK or not.
- ///
- public bool HasExclusiveAccess => false;
-
- ///
- public IEnumerable Devices { get; private set; }
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
///
/// The used to trigger the updates for SteelSeries devices.
@@ -68,7 +63,7 @@ namespace RGB.NET.Devices.SteelSeries
{
IsInitialized = false;
- UpdateTrigger?.Stop();
+ UpdateTrigger.Stop();
if (!SteelSeriesSDK.IsInitialized)
SteelSeriesSDK.Initialize();
@@ -78,17 +73,18 @@ namespace RGB.NET.Devices.SteelSeries
try
{
- foreach ((string model, RGBDeviceType deviceType, int _, SteelSeriesDeviceType steelSeriesDeviceType, string imageLayout, string layoutPath, Dictionary ledMapping) in DeviceChecker.ConnectedDevices)
+ foreach ((string model, RGBDeviceType deviceType, int _, SteelSeriesDeviceType steelSeriesDeviceType, Dictionary ledMapping) in DeviceChecker.ConnectedDevices)
{
- ISteelSeriesRGBDevice device = new SteelSeriesRGBDevice(new SteelSeriesRGBDeviceInfo(deviceType, model, steelSeriesDeviceType, imageLayout, layoutPath));
- SteelSeriesDeviceUpdateQueue updateQueue = new SteelSeriesDeviceUpdateQueue(UpdateTrigger, steelSeriesDeviceType.GetAPIName());
+ ISteelSeriesRGBDevice device = new SteelSeriesRGBDevice(new SteelSeriesRGBDeviceInfo(deviceType, model, steelSeriesDeviceType));
+ string apiName = steelSeriesDeviceType.GetAPIName() ?? throw new RGBDeviceException($"Missing API-name for device {model}");
+ SteelSeriesDeviceUpdateQueue updateQueue = new(UpdateTrigger, apiName);
device.Initialize(updateQueue, ledMapping);
devices.Add(device);
}
}
catch { if (throwExceptions) throw; }
- UpdateTrigger?.Start();
+ UpdateTrigger.Start();
Devices = new ReadOnlyCollection(devices);
IsInitialized = true;
diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs
index bce6c8f..ec4b053 100644
--- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs
+++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs
@@ -66,7 +66,7 @@ namespace RGB.NET.Devices.WS281X.Arduino
protected override object GetLedCustomData(LedId ledId) => (Channel, (int)ledId - (int)LedId.LedStripe1);
///
- protected override IEnumerable GetLedsToUpdate(bool flushLeds) => (flushLeds || LedMapping.Values.Any(x => x.IsDirty)) ? LedMapping.Values : null;
+ 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(ledsToUpdate.Where(x => x.Color.A > 0));
diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs
index 6b2c1cb..ebe5a76 100644
--- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs
+++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs
@@ -21,7 +21,7 @@ namespace RGB.NET.Devices.WS281X.Arduino
#region Properties & Fields
- private readonly Dictionary _dataBuffer = new Dictionary();
+ private readonly Dictionary _dataBuffer = new();
#endregion
@@ -42,7 +42,7 @@ namespace RGB.NET.Devices.WS281X.Arduino
#region Methods
///
- protected override void OnStartup(object sender, CustomUpdateData customData)
+ protected override void OnStartup(object? sender, CustomUpdateData customData)
{
base.OnStartup(sender, customData);
@@ -56,7 +56,7 @@ namespace RGB.NET.Devices.WS281X.Arduino
.GroupBy(x => x.Item1.channel))
{
int channel = channelData.Key;
- if (!_dataBuffer.TryGetValue(channel, out byte[] dataBuffer) || (dataBuffer.Length != ((dataSet.Count * 3) + 1)))
+ if (!_dataBuffer.TryGetValue(channel, out byte[]? dataBuffer) || (dataBuffer.Length != ((dataSet.Count * 3) + 1)))
_dataBuffer[channel] = dataBuffer = new byte[(dataSet.Count * 3) + 1];
dataBuffer[0] = (byte)((channel << 4) | UPDATE_COMMAND[0]);
diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs
index ff1b88f..093dfb9 100644
--- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs
+++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs
@@ -24,7 +24,7 @@ namespace RGB.NET.Devices.WS281X.Arduino
///
/// Gets the name of the serial-port to connect to.
///
- public string Port => SerialConnection?.Port;
+ public string Port => SerialConnection.Port;
///
/// Gets the baud-rate used by the serial-connection.
@@ -35,7 +35,7 @@ namespace RGB.NET.Devices.WS281X.Arduino
/// Gets or sets the name used by this device.
/// This allows to use {0} as a placeholder for a incrementing number if multiple devices are created.
///
- public string Name { get; set; }
+ public string? Name { get; set; }
#endregion
@@ -67,13 +67,13 @@ namespace RGB.NET.Devices.WS281X.Arduino
///
public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger)
{
- ArduinoWS2812USBUpdateQueue queue = new ArduinoWS2812USBUpdateQueue(updateTrigger, SerialConnection);
+ ArduinoWS2812USBUpdateQueue queue = new(updateTrigger, SerialConnection);
IEnumerable<(int channel, int ledCount)> channels = queue.GetChannels();
int counter = 0;
foreach ((int channel, int ledCount) in channels)
{
string name = string.Format(Name ?? $"Arduino WS2812 USB ({Port}) [{{0}}]", ++counter);
- ArduinoWS2812USBDevice device = new ArduinoWS2812USBDevice(new ArduinoWS2812USBDeviceInfo(name), queue, channel);
+ ArduinoWS2812USBDevice device = new(new ArduinoWS2812USBDeviceInfo(name), queue, channel);
device.Initialize(ledCount);
yield return device;
}
diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs
index a3a12e9..c8edc06 100644
--- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs
+++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs
@@ -54,7 +54,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard
if (Size == Size.Invalid)
{
- Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
+ Rectangle ledRectangle = new(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
}
diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs
index dd6acc0..242b6d1 100644
--- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs
+++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs
@@ -28,7 +28,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard
#region Methods
///
- protected override void OnStartup(object sender, CustomUpdateData customData)
+ protected override void OnStartup(object? sender, CustomUpdateData customData)
{
base.OnStartup(sender, customData);
@@ -38,8 +38,8 @@ namespace RGB.NET.Devices.WS281X.Bitwizard
///
protected override IEnumerable GetCommands(Dictionary dataSet)
{
- foreach (KeyValuePair data in dataSet)
- yield return $"pix {(int)data.Key} {data.Value.AsRGBHexString(false)}";
+ foreach ((object key, Color value) in dataSet)
+ yield return $"pix {(int)key} {value.AsRGBHexString(false)}";
}
#endregion
diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs
index f4f784c..3a46ac1 100644
--- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs
+++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs
@@ -24,17 +24,17 @@ namespace RGB.NET.Devices.WS281X.Bitwizard
///
/// Gets the name of the serial-port to connect to.
///
- public string Port => SerialConnection?.Port;
+ public string Port => SerialConnection.Port;
///
/// Gets the baud-rate used by the serial-connection.
///
- public int BaudRate => SerialConnection?.BaudRate ?? 0;
+ public int BaudRate => SerialConnection.BaudRate;
///
/// Gets or sets the name used by this device.
///
- public string Name { get; set; }
+ public string? Name { get; set; }
///
/// Gets or sets the pin sed to control the leds.
@@ -82,10 +82,10 @@ namespace RGB.NET.Devices.WS281X.Bitwizard
///
public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger)
{
- BitwizardWS2812USBUpdateQueue queue = new BitwizardWS2812USBUpdateQueue(updateTrigger, SerialConnection);
+ BitwizardWS2812USBUpdateQueue queue = new(updateTrigger, SerialConnection);
string name = Name ?? $"Bitwizard WS2812 USB ({Port})";
int ledOffset = Pin * MaxStripLength;
- BitwizardWS2812USBDevice device = new BitwizardWS2812USBDevice(new BitwizardWS2812USBDeviceInfo(name), queue, ledOffset);
+ BitwizardWS2812USBDevice device = new(new BitwizardWS2812USBDeviceInfo(name), queue, ledOffset);
device.Initialize(StripLength);
yield return device;
}
diff --git a/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs b/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs
index 0f343da..b3f2b4e 100644
--- a/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs
+++ b/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
-using System.IO.Ports;
using RGB.NET.Core;
namespace RGB.NET.Devices.WS281X
@@ -46,7 +45,7 @@ namespace RGB.NET.Devices.WS281X
#region Methods
///
- protected override void OnStartup(object sender, CustomUpdateData customData)
+ protected override void OnStartup(object? sender, CustomUpdateData customData)
{
base.OnStartup(sender, customData);
diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs
index 907dbaf..6092200 100644
--- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs
+++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs
@@ -57,7 +57,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
if (Size == Size.Invalid)
{
- Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
+ Rectangle ledRectangle = new(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
}
@@ -66,7 +66,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
protected override object GetLedCustomData(LedId ledId) => (Channel, (int)ledId - (int)LedId.LedStripe1);
///
- protected override IEnumerable GetLedsToUpdate(bool flushLeds) => (flushLeds || LedMapping.Values.Any(x => x.IsDirty)) ? LedMapping.Values : null;
+ 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(ledsToUpdate.Where(x => x.Color.A > 0));
diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs
index f5feffe..2c020c4 100644
--- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs
+++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs
@@ -20,11 +20,11 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
private readonly string _hostname;
- private HttpClient _httpClient = new HttpClient();
- private UdpClient _udpClient;
+ private HttpClient _httpClient = new();
+ private UdpClient? _udpClient;
- private readonly Dictionary _dataBuffer = new Dictionary();
- private readonly Dictionary _sequenceNumbers = new Dictionary();
+ private readonly Dictionary _dataBuffer = new();
+ private readonly Dictionary _sequenceNumbers = new();
private readonly Action _sendDataAction;
@@ -69,7 +69,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
#region Methods
///
- protected override void OnStartup(object sender, CustomUpdateData customData)
+ protected override void OnStartup(object? sender, CustomUpdateData customData)
{
base.OnStartup(sender, customData);
@@ -90,7 +90,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
private void SendHttp(byte[] buffer)
{
string data = Convert.ToBase64String(buffer);
- lock (_httpClient) _httpClient?.PostAsync(GetUrl("update"), new StringContent(data, Encoding.ASCII)).Wait();
+ lock (_httpClient) _httpClient.PostAsync(GetUrl("update"), new StringContent(data, Encoding.ASCII)).Wait();
}
private void SendUdp(byte[] buffer)
@@ -149,7 +149,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
private void EnableUdp(int port)
{
_httpClient.PostAsync(GetUrl("enableUDP"), new StringContent(port.ToString(), Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Wait();
- _udpClient.Connect(_hostname, port);
+ _udpClient?.Connect(_hostname, port);
}
private byte GetSequenceNumber(int channel)
@@ -166,14 +166,11 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
{
base.Dispose();
-#if NETSTANDARD
_udpClient?.Dispose();
-#endif
_udpClient = null;
ResetDevice();
_httpClient.Dispose();
- _httpClient = null;
}
}
diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs
index f573eab..b87f39e 100644
--- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs
+++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs
@@ -36,7 +36,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
/// Gets or sets the name used by this device.
/// This allows to use {0} as a placeholder for a incrementing number if multiple devices are created.
///
- public string Name { get; set; }
+ public string? Name { get; set; }
#endregion
@@ -72,7 +72,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
foreach ((int channel, int ledCount) in channels)
{
string name = string.Format(Name ?? $"NodeMCU WS2812 WIFI ({Hostname}) [{{0}}]", ++counter);
- NodeMCUWS2812USBDevice device = new NodeMCUWS2812USBDevice(new NodeMCUWS2812USBDeviceInfo(name), queue, channel);
+ NodeMCUWS2812USBDevice device = new(new NodeMCUWS2812USBDeviceInfo(name), queue, channel);
device.Initialize(ledCount);
yield return device;
}
diff --git a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs
index 3875cf4..e838ce6 100644
--- a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs
+++ b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.WS281X.NodeMCU;
@@ -17,7 +18,7 @@ namespace RGB.NET.Devices.WS281X
{
#region Properties & Fields
- private static WS281XDeviceProvider _instance;
+ private static WS281XDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
@@ -27,17 +28,14 @@ namespace RGB.NET.Devices.WS281X
public bool IsInitialized { get; private set; }
///
- public IEnumerable Devices { get; private set; }
-
- ///
- public bool HasExclusiveAccess => false;
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
///
/// Gets a list of all defined device-definitions.
///
// ReSharper disable once CollectionNeverUpdated.Global
// ReSharper disable once ReturnTypeCanBeEnumerable.Global
- public List DeviceDefinitions { get; } = new List();
+ public List DeviceDefinitions { get; } = new();
///
/// The used to trigger the updates for corsair devices.
@@ -78,9 +76,9 @@ namespace RGB.NET.Devices.WS281X
try
{
- UpdateTrigger?.Stop();
+ UpdateTrigger.Stop();
- List devices = new List();
+ List devices = new();
foreach (IWS281XDeviceDefinition deviceDefinition in DeviceDefinitions)
{
try
@@ -89,7 +87,7 @@ namespace RGB.NET.Devices.WS281X
}
catch { if (throwExceptions) throw; }
}
- UpdateTrigger?.Start();
+ UpdateTrigger.Start();
Devices = new ReadOnlyCollection(devices);
IsInitialized = true;
diff --git a/RGB.NET.Devices.Wooting/Enum/WootingLogicalKeyboardLayout.cs b/RGB.NET.Devices.Wooting/Enum/WootingLogicalKeyboardLayout.cs
deleted file mode 100644
index 640bfee..0000000
--- a/RGB.NET.Devices.Wooting/Enum/WootingLogicalKeyboardLayout.cs
+++ /dev/null
@@ -1,21 +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.Wooting.Enum
-{
- ///
- /// Contains list of available logical layouts for cooler master keyboards.
- ///
- ///
- /// Based on what is available in the shop: https://wooting.store/collections/wooting-keyboards/products/wooting-two
- ///
- public enum WootingLogicalKeyboardLayout
- {
- US = 0,
- UK = 1,
- DE = 2,
- ND = 3
- };
-}
diff --git a/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs b/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs
index b766da8..b466ac8 100644
--- a/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs
+++ b/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs
@@ -23,7 +23,7 @@ namespace RGB.NET.Devices.Wooting.Generic
/// Gets or sets the update queue performing updates for this device.
///
// ReSharper disable once MemberCanBePrivate.Global
- protected UpdateQueue UpdateQueue { get; set; }
+ protected UpdateQueue? UpdateQueue { get; set; }
#endregion
@@ -51,7 +51,7 @@ namespace RGB.NET.Devices.Wooting.Generic
if (Size == Size.Invalid)
{
- Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
+ Rectangle ledRectangle = new(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
diff --git a/RGB.NET.Devices.Wooting/Generic/WootingRGBDeviceInfo.cs b/RGB.NET.Devices.Wooting/Generic/WootingRGBDeviceInfo.cs
index 4925883..662c1b5 100644
--- a/RGB.NET.Devices.Wooting/Generic/WootingRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Wooting/Generic/WootingRGBDeviceInfo.cs
@@ -1,5 +1,4 @@
-using System;
-using RGB.NET.Core;
+using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum;
using RGB.NET.Devices.Wooting.Helper;
@@ -47,7 +46,7 @@ namespace RGB.NET.Devices.Wooting.Generic
this.DeviceType = deviceType;
this.DeviceIndex = deviceIndex;
- Model = deviceIndex.GetDescription();
+ Model = deviceIndex.GetDescription() ?? "Unknown";
DeviceName = $"{Manufacturer} {Model}";
}
diff --git a/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs b/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs
index 7c2e8b3..0585f82 100644
--- a/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs
+++ b/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel;
using System.Reflection;
-using RGB.NET.Core;
namespace RGB.NET.Devices.Wooting.Helper
{
@@ -14,26 +13,21 @@ namespace RGB.NET.Devices.Wooting.Helper
/// Gets the value of the .
///
/// The enum value to get the description from.
- /// The generic enum-type
- /// The value of the or the result of the source.
- internal static string GetDescription(this T source)
- where T : struct
- {
- return source.GetAttribute()?.Description ?? source.ToString();
- }
-
+ /// 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 generic enum-type
/// The .
- private static T GetAttribute(this TEnum source)
+ private static T? GetAttribute(this System.Enum source)
where T : Attribute
- where TEnum : struct
{
- FieldInfo fi = source.GetType().GetField(source.ToString());
+ 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;
}
diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs
index dc9fa15..0ce7e41 100644
--- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs
+++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs
@@ -15,8 +15,8 @@ namespace RGB.NET.Devices.Wooting.Keyboard
#region Wooting One
- private static readonly Dictionary WootingOne_US = new Dictionary
- {
+ private static readonly Dictionary WootingOne_US = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,2) },
{ LedId.Keyboard_F2, (0,3) },
@@ -111,8 +111,8 @@ namespace RGB.NET.Devices.Wooting.Keyboard
{ LedId.Keyboard_ArrowRight, (5,16) }
};
- private static readonly Dictionary WootingOne_UK = new Dictionary
- {
+ private static readonly Dictionary WootingOne_UK = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,2) },
{ LedId.Keyboard_F2, (0,3) },
@@ -213,8 +213,8 @@ namespace RGB.NET.Devices.Wooting.Keyboard
#region Wooting Two
- private static readonly Dictionary WootingTwo_US = new Dictionary
- {
+ private static readonly Dictionary WootingTwo_US = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,2) },
{ LedId.Keyboard_F2, (0,3) },
@@ -330,8 +330,8 @@ namespace RGB.NET.Devices.Wooting.Keyboard
{ LedId.Keyboard_NumPeriodAndDelete, (5,19) }
};
- private static readonly Dictionary WootingTwo_UK = new Dictionary
- {
+ private static readonly Dictionary WootingTwo_UK = new()
+ {
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,2) },
{ LedId.Keyboard_F2, (0,3) },
@@ -455,7 +455,7 @@ namespace RGB.NET.Devices.Wooting.Keyboard
/// Contains all the hardware-id mappings for Wooting devices.
///
public static readonly Dictionary>> Mapping =
- new Dictionary>>
+ new()
{
{ WootingDevicesIndexes.WootingOne, new Dictionary>
{
diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs
index e390a28..a3e8e0c 100644
--- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs
+++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs
@@ -39,7 +39,7 @@ namespace RGB.NET.Devices.Wooting.Keyboard
protected override object GetLedCustomData(LedId ledId) => WootingKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout][ledId];
///
- protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
+ protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
#endregion
}
diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs
index b2bcc70..b9a6641 100644
--- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs
+++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs
@@ -18,11 +18,6 @@ namespace RGB.NET.Devices.Wooting.Keyboard
///
public WootingPhysicalKeyboardLayout PhysicalLayout { get; }
- ///
- /// Gets the of the .
- ///
- public WootingLogicalKeyboardLayout LogicalLayout { get; private set; }
-
#endregion
#region Constructors
@@ -33,29 +28,10 @@ namespace RGB.NET.Devices.Wooting.Keyboard
///
/// The index of the .
/// The of the .
- /// The of the layout this keyboard is using
- internal WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes deviceIndex, WootingPhysicalKeyboardLayout physicalKeyboardLayout,
- CultureInfo culture)
+ internal WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes deviceIndex, WootingPhysicalKeyboardLayout physicalKeyboardLayout)
: base(RGBDeviceType.Keyboard, deviceIndex)
{
this.PhysicalLayout = physicalKeyboardLayout;
-
- DetermineLogicalLayout(culture.KeyboardLayoutId);
- }
-
- private void DetermineLogicalLayout(int keyboardLayoutId)
- {
- switch (keyboardLayoutId)
- {
- // TODO SpoinkyNL 15-12-2019: There doesn't seem to be an accurate way to determine this, perhaps it should be a configurable thing..
- // I'm using US International and it's reporting nl-NL's 1043. Also you can after all just swap your keycaps
- default:
- if (PhysicalLayout == WootingPhysicalKeyboardLayout.US)
- LogicalLayout = WootingLogicalKeyboardLayout.US;
- else
- LogicalLayout = WootingLogicalKeyboardLayout.UK;
- break;
- }
}
#endregion
diff --git a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs
index 1bb7dd9..e6baf08 100644
--- a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs
+++ b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs
@@ -17,11 +17,6 @@ namespace RGB.NET.Devices.Wooting.Native
private static IntPtr _dllHandle = IntPtr.Zero;
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- internal static string LoadedArchitecture { get; private set; }
-
///
/// Reloads the SDK.
///
@@ -37,10 +32,10 @@ namespace RGB.NET.Devices.Wooting.Native
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
List possiblePathList = Environment.Is64BitProcess ? WootingDeviceProvider.PossibleX64NativePaths : WootingDeviceProvider.PossibleX86NativePaths;
- string dllPath = possiblePathList.FirstOrDefault(File.Exists);
+ string? dllPath = possiblePathList.FirstOrDefault(File.Exists);
if (dllPath == null) throw new RGBDeviceException($"Can't find the Wooting-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
- SetDllDirectory(Path.GetDirectoryName(Path.GetFullPath(dllPath)));
+ SetDllDirectory(Path.GetDirectoryName(Path.GetFullPath(dllPath))!);
_dllHandle = LoadLibrary(dllPath);
@@ -79,12 +74,12 @@ namespace RGB.NET.Devices.Wooting.Native
#region Pointers
- private static GetDeviceInfoPointer _getDeviceInfoPointer;
- private static KeyboardConnectedPointer _keyboardConnectedPointer;
- private static ResetPointer _resetPointer;
- private static ClosePointer _closePointer;
- private static ArrayUpdateKeyboardPointer _arrayUpdateKeyboardPointer;
- private static ArraySetSinglePointer _arraySetSinglePointer;
+ private static GetDeviceInfoPointer? _getDeviceInfoPointer;
+ private static KeyboardConnectedPointer? _keyboardConnectedPointer;
+ private static ResetPointer? _resetPointer;
+ private static ClosePointer? _closePointer;
+ private static ArrayUpdateKeyboardPointer? _arrayUpdateKeyboardPointer;
+ private static ArraySetSinglePointer? _arraySetSinglePointer;
#endregion
@@ -110,12 +105,12 @@ namespace RGB.NET.Devices.Wooting.Native
#endregion
- internal static IntPtr GetDeviceInfo() => _getDeviceInfoPointer();
- internal static bool KeyboardConnected() => _keyboardConnectedPointer();
- internal static bool Reset() => _resetPointer();
- internal static bool Close() => _closePointer();
- internal static bool ArrayUpdateKeyboard() => _arrayUpdateKeyboardPointer();
- internal static bool ArraySetSingle(byte row, byte column, byte red, byte green, byte blue) => _arraySetSinglePointer(row, column, red, green, blue);
+ internal static IntPtr GetDeviceInfo() => (_getDeviceInfoPointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke();
+ internal static bool KeyboardConnected() => (_keyboardConnectedPointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke();
+ internal static bool Reset() => (_resetPointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke();
+ internal static bool Close() => (_closePointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke();
+ internal static bool ArrayUpdateKeyboard() => (_arrayUpdateKeyboardPointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke();
+ internal static bool ArraySetSingle(byte row, byte column, byte red, byte green, byte blue) => (_arraySetSinglePointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke(row, column, red, green, blue);
#endregion
}
diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs
index 9b83452..d9f3b49 100644
--- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs
+++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Linq;
using System.Runtime.InteropServices;
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum;
@@ -18,7 +19,7 @@ namespace RGB.NET.Devices.Wooting
{
#region Properties & Fields
- private static WootingDeviceProvider _instance;
+ private static WootingDeviceProvider? _instance;
///
/// Gets the singleton instance.
///
@@ -28,13 +29,13 @@ namespace RGB.NET.Devices.Wooting
/// 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 List { "x86/wooting-rgb-sdk.dll" };
+ public static List PossibleX86NativePaths { get; } = new() { "x86/wooting-rgb-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 List { "x64/wooting-rgb-sdk64.dll" };
+ public static List PossibleX64NativePaths { get; } = new() { "x64/wooting-rgb-sdk64.dll" };
///
///
@@ -42,24 +43,13 @@ namespace RGB.NET.Devices.Wooting
///
public bool IsInitialized { get; private set; }
- ///
- /// Gets the loaded architecture (x64/x86).
- ///
- public string LoadedArchitecture => _WootingSDK.LoadedArchitecture;
-
///
- ///
- /// Gets whether the application has exclusive access to the SDK or not.
- ///
- public bool HasExclusiveAccess => false;
-
- ///
- public IEnumerable Devices { get; private set; }
+ public IEnumerable Devices { get; private set; } = Enumerable.Empty();
///
/// The used to trigger the updates for cooler master devices.
///
- public DeviceUpdateTrigger UpdateTrigger { get; private set; }
+ public DeviceUpdateTrigger UpdateTrigger { get; }
#endregion
@@ -84,45 +74,33 @@ namespace RGB.NET.Devices.Wooting
///
/// Thrown if the SDK failed to initialize
- public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false,
- bool throwExceptions = false)
+ public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
{
IsInitialized = false;
try
{
- UpdateTrigger?.Stop();
+ UpdateTrigger.Stop();
_WootingSDK.Reload();
IList devices = new List();
if (_WootingSDK.KeyboardConnected())
{
- _WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo));
- IWootingRGBDevice device;
- // TODO: Find an accurate way to determine physical and logical layouts
- if (nativeDeviceInfo.Model == "Wooting two")
+ _WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!;
+ IWootingRGBDevice device = nativeDeviceInfo.Model switch
{
- device = new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingTwo,
- WootingPhysicalKeyboardLayout.US,
- CultureHelper.GetCurrentCulture()));
- }
- else if (nativeDeviceInfo.Model == "Wooting one")
- {
- device = new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingOne,
- WootingPhysicalKeyboardLayout.US,
- CultureHelper.GetCurrentCulture()));
- }
- else
- {
- throw new RGBDeviceException("No supported Wooting keyboard connected");
- }
+ // TODO: Find an accurate way to determine physical and logical layouts
+ "Wooting two" => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingTwo, WootingPhysicalKeyboardLayout.US)),
+ "Wooting one" => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingOne, WootingPhysicalKeyboardLayout.US)),
+ _ => throw new RGBDeviceException("No supported Wooting keyboard connected")
+ };
device.Initialize(UpdateTrigger);
devices.Add(device);
}
- UpdateTrigger?.Start();
+ UpdateTrigger.Start();
Devices = new ReadOnlyCollection(devices);
IsInitialized = true;
@@ -143,7 +121,7 @@ namespace RGB.NET.Devices.Wooting
///
public void Dispose()
{
- try { UpdateTrigger?.Dispose(); }
+ try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
try { _WootingSDK.Close(); }
diff --git a/RGB.NET.Groups/Groups/RectangleLedGroup.cs b/RGB.NET.Groups/Groups/RectangleLedGroup.cs
index 0d19568..fadce4d 100644
--- a/RGB.NET.Groups/Groups/RectangleLedGroup.cs
+++ b/RGB.NET.Groups/Groups/RectangleLedGroup.cs
@@ -117,7 +117,7 @@ namespace RGB.NET.Groups
/// Gets a list containing all of this .
///
/// The list containing all of this .
- public override IList GetLeds() => _ledCache ??= (Surface?.Leds.Where(led => led.AbsoluteLedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList() ?? new());
+ public override IList GetLeds() => _ledCache ??= (Surface?.Leds.Where(led => led.AbsoluteLedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList() ?? new List());
private void InvalidateCache() => _ledCache = null;
diff --git a/RGB.NET.sln.DotSettings b/RGB.NET.sln.DotSettings
index 20624f3..de2906a 100644
--- a/RGB.NET.sln.DotSettings
+++ b/RGB.NET.sln.DotSettings
@@ -259,8 +259,10 @@
False
False
AFBG
+ API
ARGB
BWZ
+ CID
CM
CMSDK
CUESDK
@@ -283,6 +285,7 @@
PLZ
RGB
SAP
+ SDK
SQL
UI
USB
diff --git a/Tests/RGB.NET.Core.Tests/Color/ColorTest.cs b/Tests/RGB.NET.Core.Tests/Color/ColorTest.cs
index 20b17a1..bd0fda1 100644
--- a/Tests/RGB.NET.Core.Tests/Color/ColorTest.cs
+++ b/Tests/RGB.NET.Core.Tests/Color/ColorTest.cs
@@ -21,7 +21,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void ToStringTest()
{
- Core.Color color = new Core.Color(255, 120, 13, 1);
+ Core.Color color = new(255, 120, 13, 1);
Assert.AreEqual("[A: 255, R: 120, G: 13, B: 1]", color.ToString());
}
@@ -31,8 +31,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void GetHashCodeTestEqual()
{
- Core.Color color1 = new Core.Color(100, 68, 32, 255);
- Core.Color color2 = new Core.Color(100, 68, 32, 255);
+ Core.Color color1 = new(100, 68, 32, 255);
+ Core.Color color2 = new(100, 68, 32, 255);
Assert.AreEqual(color1.GetHashCode(), color2.GetHashCode());
}
@@ -40,8 +40,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void GetHashCodeTestNotEqualA()
{
- Core.Color color1 = new Core.Color(100, 68, 32, 255);
- Core.Color color2 = new Core.Color(99, 68, 32, 255);
+ Core.Color color1 = new(100, 68, 32, 255);
+ Core.Color color2 = new(99, 68, 32, 255);
Assert.AreNotEqual(color1.GetHashCode(), color2.GetHashCode());
}
@@ -49,8 +49,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void GetHashCodeTestNotEqualR()
{
- Core.Color color1 = new Core.Color(100, 68, 32, 255);
- Core.Color color2 = new Core.Color(100, 69, 32, 255);
+ Core.Color color1 = new(100, 68, 32, 255);
+ Core.Color color2 = new(100, 69, 32, 255);
Assert.AreNotEqual(color1.GetHashCode(), color2.GetHashCode());
}
@@ -58,8 +58,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void GetHashCodeTestNotEqualG()
{
- Core.Color color1 = new Core.Color(100, 68, 32, 255);
- Core.Color color2 = new Core.Color(100, 68, 200, 255);
+ Core.Color color1 = new(100, 68, 32, 255);
+ Core.Color color2 = new(100, 68, 200, 255);
Assert.AreNotEqual(color1.GetHashCode(), color2.GetHashCode());
}
@@ -67,8 +67,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void GetHashCodeTestNotEqualB()
{
- Core.Color color1 = new Core.Color(100, 68, 32, 255);
- Core.Color color2 = new Core.Color(100, 68, 32, 0);
+ Core.Color color1 = new(100, 68, 32, 255);
+ Core.Color color2 = new(100, 68, 32, 0);
Assert.AreNotEqual(color1.GetHashCode(), color2.GetHashCode());
}
@@ -80,8 +80,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void EqualityTestEqual()
{
- Core.Color color1 = new Core.Color(100, 68, 32, 255);
- Core.Color color2 = new Core.Color(100, 68, 32, 255);
+ Core.Color color1 = new(100, 68, 32, 255);
+ Core.Color color2 = new(100, 68, 32, 255);
Assert.IsTrue(color1.Equals(color2), $"Equals returns false on equal colors {color1} and {color2}");
Assert.IsTrue(color1 == color2, $"Equal-operator returns false on equal colors {color1} and {color2}");
@@ -91,8 +91,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void EqualityTestNotEqualA()
{
- Core.Color color1 = new Core.Color(100, 68, 32, 255);
- Core.Color color2 = new Core.Color(99, 68, 32, 255);
+ Core.Color color1 = new(100, 68, 32, 255);
+ Core.Color color2 = new(99, 68, 32, 255);
Assert.IsFalse(color1.Equals(color2), $"Equals returns true on not equal colors {color1} and {color2}");
Assert.IsFalse(color1 == color2, $"Equal-operator returns true on not equal colors {color1} and {color2}");
@@ -102,8 +102,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void EqualityTestNotEqualR()
{
- Core.Color color1 = new Core.Color(100, 68, 32, 255);
- Core.Color color2 = new Core.Color(100, 69, 32, 255);
+ Core.Color color1 = new(100, 68, 32, 255);
+ Core.Color color2 = new(100, 69, 32, 255);
Assert.IsFalse(color1.Equals(color2), $"Equals returns true on not equal colors {color1} and {color2}");
Assert.IsFalse(color1 == color2, $"Equal-operator returns true on not equal colors {color1} and {color2}");
@@ -113,8 +113,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void EqualityTestNotEqualG()
{
- Core.Color color1 = new Core.Color(100, 68, 32, 255);
- Core.Color color2 = new Core.Color(100, 68, 200, 255);
+ Core.Color color1 = new(100, 68, 32, 255);
+ Core.Color color2 = new(100, 68, 200, 255);
Assert.IsFalse(color1.Equals(color2), $"Equals returns true on not equal colors {color1} and {color2}");
Assert.IsFalse(color1 == color2, $"Equal-operator returns true on not equal colors {color1} and {color2}");
@@ -124,8 +124,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void EqualityTestNotEqualB()
{
- Core.Color color1 = new Core.Color(100, 68, 32, 255);
- Core.Color color2 = new Core.Color(100, 68, 32, 0);
+ Core.Color color1 = new(100, 68, 32, 255);
+ Core.Color color2 = new(100, 68, 32, 0);
Assert.IsFalse(color1.Equals(color2), $"Equals returns true on not equal colors {color1} and {color2}");
Assert.IsFalse(color1 == color2, $"Equal-operator returns true on not equal colors {color1} and {color2}");
@@ -141,7 +141,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void RGBByteConstructorTest()
{
- Core.Color color = new Core.Color((byte)10, (byte)120, (byte)255);
+ Core.Color color = new((byte)10, (byte)120, (byte)255);
Assert.AreEqual(255, color.GetA(), "A is not 255");
Assert.AreEqual(10, color.GetR(), "R is not 10");
@@ -152,7 +152,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void ARGBByteConstructorTest()
{
- Core.Color color = new Core.Color((byte)200, (byte)10, (byte)120, (byte)255);
+ Core.Color color = new((byte)200, (byte)10, (byte)120, (byte)255);
Assert.AreEqual(200, color.GetA(), "A is not 200");
Assert.AreEqual(10, color.GetR(), "R is not 10");
@@ -163,7 +163,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void RGBIntConstructorTest()
{
- Core.Color color = new Core.Color(10, 120, 255);
+ Core.Color color = new(10, 120, 255);
Assert.AreEqual(255, color.GetA(), "A is not 255");
Assert.AreEqual(10, color.GetR(), "R is not 10");
@@ -174,7 +174,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void ARGBIntConstructorTest()
{
- Core.Color color = new Core.Color(200, 10, 120, 255);
+ Core.Color color = new(200, 10, 120, 255);
Assert.AreEqual(200, color.GetA(), "A is not 200");
Assert.AreEqual(10, color.GetR(), "R is not 10");
@@ -185,14 +185,14 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void RGBIntConstructorClampTest()
{
- Core.Color color1 = new Core.Color(256, 256, 256);
+ Core.Color color1 = new(256, 256, 256);
Assert.AreEqual(255, color1.GetA(), "A is not 255");
Assert.AreEqual(255, color1.GetR(), "R is not 255");
Assert.AreEqual(255, color1.GetG(), "G is not 255");
Assert.AreEqual(255, color1.GetB(), "B is not 255");
- Core.Color color2 = new Core.Color(-1, -1, -1);
+ Core.Color color2 = new(-1, -1, -1);
Assert.AreEqual(255, color2.GetA(), "A is not 255");
Assert.AreEqual(0, color2.GetR(), "R is not 0");
@@ -203,14 +203,14 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void ARGBIntConstructorClampTest()
{
- Core.Color color = new Core.Color(256, 256, 256, 256);
+ Core.Color color = new(256, 256, 256, 256);
Assert.AreEqual(255, color.GetA(), "A is not 255");
Assert.AreEqual(255, color.GetR(), "R is not 255");
Assert.AreEqual(255, color.GetG(), "G is not 255");
Assert.AreEqual(255, color.GetB(), "B is not 255");
- Core.Color color2 = new Core.Color(-1, -1, -1, -1);
+ Core.Color color2 = new(-1, -1, -1, -1);
Assert.AreEqual(0, color2.GetA(), "A is not 0");
Assert.AreEqual(0, color2.GetR(), "R is not 0");
@@ -221,7 +221,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void RGBPercentConstructorTest()
{
- Core.Color color = new Core.Color(0.25341, 0.55367, 1);
+ Core.Color color = new(0.25341, 0.55367, 1);
Assert.AreEqual(1, color.A, DoubleExtensions.TOLERANCE, "A is not 1");
Assert.AreEqual(0.25341, color.R, DoubleExtensions.TOLERANCE, "R is not 0.25341");
@@ -232,7 +232,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void ARGBPercentConstructorTest()
{
- Core.Color color = new Core.Color(0.3315, 0.25341, 0.55367, 1);
+ Core.Color color = new(0.3315, 0.25341, 0.55367, 1);
Assert.AreEqual(0.3315, color.A, DoubleExtensions.TOLERANCE, "A is not 0.3315");
Assert.AreEqual(0.25341, color.R, DoubleExtensions.TOLERANCE, "R is not 0.25341");
@@ -243,14 +243,14 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void RGBPercentConstructorClampTest()
{
- Core.Color color1 = new Core.Color(1.1, 1.1, 1.1);
+ Core.Color color1 = new(1.1, 1.1, 1.1);
Assert.AreEqual(1, color1.A, "A is not 1");
Assert.AreEqual(1, color1.R, "R is not 1");
Assert.AreEqual(1, color1.G, "G is not 1");
Assert.AreEqual(1, color1.B, "B is not 1");
- Core.Color color2 = new Core.Color(-1.0, -1.0, -1.0);
+ Core.Color color2 = new(-1.0, -1.0, -1.0);
Assert.AreEqual(1, color2.A, "A is not 1");
Assert.AreEqual(0, color2.R, "R is not 0");
@@ -261,14 +261,14 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void ARGBPercentConstructorClampTest()
{
- Core.Color color1 = new Core.Color(1.1, 1.1, 1.1, 1.1);
+ Core.Color color1 = new(1.1, 1.1, 1.1, 1.1);
Assert.AreEqual(1, color1.A, "A is not 1");
Assert.AreEqual(1, color1.R, "R is not 1");
Assert.AreEqual(1, color1.G, "G is not 1");
Assert.AreEqual(1, color1.B, "B is not 1");
- Core.Color color2 = new Core.Color(-1.0, -1.0, -1.0, -1.0);
+ Core.Color color2 = new(-1.0, -1.0, -1.0, -1.0);
Assert.AreEqual(0, color2.A, "A is not 0");
Assert.AreEqual(0, color2.R, "R is not 0");
@@ -279,8 +279,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void CloneConstructorTest()
{
- Core.Color referennceColor = new Core.Color(200, 10, 120, 255);
- Core.Color color = new Core.Color(referennceColor);
+ Core.Color referennceColor = new(200, 10, 120, 255);
+ Core.Color color = new(referennceColor);
Assert.AreEqual(200, color.GetA(), "A is not 200");
Assert.AreEqual(10, color.GetR(), "R is not 10");
@@ -317,76 +317,76 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void AToPercentTest()
{
- Core.Color color1 = new Core.Color(0, 0, 0, 0);
+ Core.Color color1 = new(0, 0, 0, 0);
Assert.AreEqual(0, color1.A);
- Core.Color color2 = new Core.Color(255, 0, 0, 0);
+ Core.Color color2 = new(255, 0, 0, 0);
Assert.AreEqual(1, color2.A);
- Core.Color color3 = new Core.Color(128, 0, 0, 0);
+ Core.Color color3 = new(128, 0, 0, 0);
Assert.AreEqual(128 / 255.0, color3.A);
- Core.Color color4 = new Core.Color(30, 0, 0, 0);
+ Core.Color color4 = new(30, 0, 0, 0);
Assert.AreEqual(30 / 255.0, color4.A);
- Core.Color color5 = new Core.Color(201, 0, 0, 0);
+ Core.Color color5 = new(201, 0, 0, 0);
Assert.AreEqual(201 / 255.0, color5.A);
}
[TestMethod]
public void RToPercentTest()
{
- Core.Color color1 = new Core.Color(0, 0, 0, 0);
+ Core.Color color1 = new(0, 0, 0, 0);
Assert.AreEqual(0, color1.R);
- Core.Color color2 = new Core.Color(0, 255, 0, 0);
+ Core.Color color2 = new(0, 255, 0, 0);
Assert.AreEqual(1, color2.R);
- Core.Color color3 = new Core.Color(0, 128, 0, 0);
+ Core.Color color3 = new(0, 128, 0, 0);
Assert.AreEqual(128 / 255.0, color3.R);
- Core.Color color4 = new Core.Color(0, 30, 0, 0);
+ Core.Color color4 = new(0, 30, 0, 0);
Assert.AreEqual(30 / 255.0, color4.R);
- Core.Color color5 = new Core.Color(0, 201, 0, 0);
+ Core.Color color5 = new(0, 201, 0, 0);
Assert.AreEqual(201 / 255.0, color5.R);
}
[TestMethod]
public void GToPercentTest()
{
- Core.Color color1 = new Core.Color(0, 0, 0, 0);
+ Core.Color color1 = new(0, 0, 0, 0);
Assert.AreEqual(0, color1.G);
- Core.Color color2 = new Core.Color(0, 0, 255, 0);
+ Core.Color color2 = new(0, 0, 255, 0);
Assert.AreEqual(1, color2.G);
- Core.Color color3 = new Core.Color(0, 0, 128, 0);
+ Core.Color color3 = new(0, 0, 128, 0);
Assert.AreEqual(128 / 255.0, color3.G);
- Core.Color color4 = new Core.Color(0, 0, 30, 0);
+ Core.Color color4 = new(0, 0, 30, 0);
Assert.AreEqual(30 / 255.0, color4.G);
- Core.Color color5 = new Core.Color(0, 0, 201, 0);
+ Core.Color color5 = new(0, 0, 201, 0);
Assert.AreEqual(201 / 255.0, color5.G);
}
[TestMethod]
public void BToPercentTest()
{
- Core.Color color1 = new Core.Color(0, 0, 0, 0);
+ Core.Color color1 = new(0, 0, 0, 0);
Assert.AreEqual(0, color1.B);
- Core.Color color2 = new Core.Color(0, 0, 0, 255);
+ Core.Color color2 = new(0, 0, 0, 255);
Assert.AreEqual(1, color2.B);
- Core.Color color3 = new Core.Color(0, 0, 0, 128);
+ Core.Color color3 = new(0, 0, 0, 128);
Assert.AreEqual(128 / 255.0, color3.B);
- Core.Color color4 = new Core.Color(0, 0, 0, 30);
+ Core.Color color4 = new(0, 0, 0, 30);
Assert.AreEqual(30 / 255.0, color4.B);
- Core.Color color5 = new Core.Color(0, 0, 0, 201);
+ Core.Color color5 = new(0, 0, 0, 201);
Assert.AreEqual(201 / 255.0, color5.B);
}
diff --git a/Tests/RGB.NET.Core.Tests/Color/RGBColorTest.cs b/Tests/RGB.NET.Core.Tests/Color/RGBColorTest.cs
index 2624444..7a9abc9 100644
--- a/Tests/RGB.NET.Core.Tests/Color/RGBColorTest.cs
+++ b/Tests/RGB.NET.Core.Tests/Color/RGBColorTest.cs
@@ -12,8 +12,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void BlendOpaqueTest()
{
- Core.Color baseColor = new Core.Color(255, 0, 0);
- Core.Color blendColor = new Core.Color(0, 255, 0);
+ Core.Color baseColor = new(255, 0, 0);
+ Core.Color blendColor = new(0, 255, 0);
Assert.AreEqual(blendColor, baseColor.Blend(blendColor));
}
@@ -21,8 +21,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void BlendTransparentTest()
{
- Core.Color baseColor = new Core.Color(255, 0, 0);
- Core.Color blendColor = new Core.Color(0, 0, 255, 0);
+ Core.Color baseColor = new(255, 0, 0);
+ Core.Color blendColor = new(0, 0, 255, 0);
Assert.AreEqual(baseColor, baseColor.Blend(blendColor));
}
@@ -30,8 +30,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void BlendUpTest()
{
- Core.Color baseColor = new Core.Color(0.0, 0.0, 0.0);
- Core.Color blendColor = new Core.Color(0.5, 1.0, 1.0, 1.0);
+ Core.Color baseColor = new(0.0, 0.0, 0.0);
+ Core.Color blendColor = new(0.5, 1.0, 1.0, 1.0);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.5), baseColor.Blend(blendColor));
}
@@ -39,8 +39,8 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void BlendDownTest()
{
- Core.Color baseColor = new Core.Color(1.0, 1.0, 1.0);
- Core.Color blendColor = new Core.Color(0.5, 0.0, 0.0, 0.0);
+ Core.Color baseColor = new(1.0, 1.0, 1.0);
+ Core.Color blendColor = new(0.5, 0.0, 0.0, 0.0);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.5), baseColor.Blend(blendColor));
}
@@ -52,7 +52,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void AddRGBTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.AddRGB(11, 12, 13);
Assert.AreEqual(new Core.Color(128, 139, 140, 141), result);
@@ -61,7 +61,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void AddRGBPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.AddRGB(0.2, 0.3, 0.4);
Assert.AreEqual(new Core.Color(0.5, 0.7, 0.8, 0.9), result);
@@ -70,7 +70,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void AddATest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.AddA(10);
Assert.AreEqual(new Core.Color(138, 128, 128, 128), result);
@@ -79,7 +79,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void AddAPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.AddA(0.1);
Assert.AreEqual(new Core.Color(0.6, 0.5, 0.5, 0.5), result);
@@ -88,7 +88,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void AddRTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.AddRGB(r: 10);
Assert.AreEqual(new Core.Color(128, 138, 128, 128), result);
@@ -97,7 +97,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void AddRPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.AddRGB(r: 0.1);
Assert.AreEqual(new Core.Color(0.5, 0.6, 0.5, 0.5), result);
@@ -106,7 +106,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void AddGTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.AddRGB(g: 10);
Assert.AreEqual(new Core.Color(128, 128, 138, 128), result);
@@ -115,7 +115,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void AddGPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.AddRGB(g: 0.1);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.6, 0.5), result);
@@ -124,7 +124,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void AddBTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.AddRGB(b: 10);
Assert.AreEqual(new Core.Color(128, 128, 128, 138), result);
@@ -133,7 +133,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void AddBPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.AddRGB(b: 0.1);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.5, 0.6), result);
@@ -146,7 +146,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SubtractRGBTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.SubtractRGB(11, 12, 13);
Assert.AreEqual(new Core.Color(128, 117, 116, 115), result);
@@ -155,7 +155,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SubtractRGBPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.SubtractRGB(0.2, 0.3, 0.4);
Assert.AreEqual(new Core.Color(0.5, 0.3, 0.2, 0.1), result);
@@ -164,7 +164,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SubtractATest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.SubtractA(10);
Assert.AreEqual(new Core.Color(118, 128, 128, 128), result);
@@ -173,7 +173,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SubtractAPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.SubtractA(0.1);
Assert.AreEqual(new Core.Color(0.4, 0.5, 0.5, 0.5), result);
@@ -182,7 +182,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SubtractRTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.SubtractRGB(r: 10);
Assert.AreEqual(new Core.Color(128, 118, 128, 128), result);
@@ -191,7 +191,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SubtractRPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.SubtractRGB(r: 0.1);
Assert.AreEqual(new Core.Color(0.5, 0.4, 0.5, 0.5), result);
@@ -200,7 +200,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SubtractGTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.SubtractRGB(g: 10);
Assert.AreEqual(new Core.Color(128, 128, 118, 128), result);
@@ -209,7 +209,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SubtractGPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.SubtractRGB(g: 0.1);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.4, 0.5), result);
@@ -218,7 +218,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SubtractBTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.SubtractRGB(b: 10);
Assert.AreEqual(new Core.Color(128, 128, 128, 118), result);
@@ -227,7 +227,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SubtractBPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.SubtractRGB(b: 0.1);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.5, 0.4), result);
@@ -240,7 +240,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void MultiplyRGBPercentTest()
{
- Core.Color baseColor = new Core.Color(0.2, 0.2, 0.2, 0.2);
+ Core.Color baseColor = new(0.2, 0.2, 0.2, 0.2);
Core.Color result = baseColor.MultiplyRGB(3, 4, 5);
Assert.AreEqual(new Core.Color(0.2, 0.6, 0.8, 1.0), result);
@@ -249,7 +249,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void MultiplyAPercentTest()
{
- Core.Color baseColor = new Core.Color(0.2, 0.2, 0.2, 0.2);
+ Core.Color baseColor = new(0.2, 0.2, 0.2, 0.2);
Core.Color result = baseColor.MultiplyA(3);
Assert.AreEqual(new Core.Color(0.6, 0.2, 0.2, 0.2), result);
@@ -258,7 +258,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void MultiplyRPercentTest()
{
- Core.Color baseColor = new Core.Color(0.2, 0.2, 0.2, 0.2);
+ Core.Color baseColor = new(0.2, 0.2, 0.2, 0.2);
Core.Color result = baseColor.MultiplyRGB(r: 3);
Assert.AreEqual(new Core.Color(0.2, 0.6, 0.2, 0.2), result);
@@ -267,7 +267,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void MultiplyGPercentTest()
{
- Core.Color baseColor = new Core.Color(0.2, 0.2, 0.2, 0.2);
+ Core.Color baseColor = new(0.2, 0.2, 0.2, 0.2);
Core.Color result = baseColor.MultiplyRGB(g: 3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.6, 0.2), result);
@@ -276,7 +276,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void MultiplyBPercentTest()
{
- Core.Color baseColor = new Core.Color(0.2, 0.2, 0.2, 0.2);
+ Core.Color baseColor = new(0.2, 0.2, 0.2, 0.2);
Core.Color result = baseColor.MultiplyRGB(b: 3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.6), result);
@@ -289,7 +289,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void DivideRGBPercentTest()
{
- Core.Color baseColor = new Core.Color(0.2, 0.6, 0.8, 1.0);
+ Core.Color baseColor = new(0.2, 0.6, 0.8, 1.0);
Core.Color result = baseColor.DivideRGB(3, 4, 5);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.2), result);
@@ -298,7 +298,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void DivideAPercentTest()
{
- Core.Color baseColor = new Core.Color(0.6, 0.2, 0.2, 0.2);
+ Core.Color baseColor = new(0.6, 0.2, 0.2, 0.2);
Core.Color result = baseColor.DivideA(3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.2), result);
@@ -307,7 +307,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void DivideRPercentTest()
{
- Core.Color baseColor = new Core.Color(0.2, 0.6, 0.2, 0.2);
+ Core.Color baseColor = new(0.2, 0.6, 0.2, 0.2);
Core.Color result = baseColor.DivideRGB(r: 3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.2), result);
@@ -316,7 +316,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void DivideGPercentTest()
{
- Core.Color baseColor = new Core.Color(0.2, 0.2, 0.6, 0.2);
+ Core.Color baseColor = new(0.2, 0.2, 0.6, 0.2);
Core.Color result = baseColor.DivideRGB(g: 3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.2), result);
@@ -325,7 +325,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void DivideBPercentTest()
{
- Core.Color baseColor = new Core.Color(0.2, 0.2, 0.2, 0.6);
+ Core.Color baseColor = new(0.2, 0.2, 0.2, 0.6);
Core.Color result = baseColor.DivideRGB(b: 3);
Assert.AreEqual(new Core.Color(0.2, 0.2, 0.2, 0.2), result);
@@ -338,7 +338,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SetRGBTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.SetRGB(11, 12, 13);
Assert.AreEqual(new Core.Color(128, 11, 12, 13), result);
@@ -347,7 +347,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SetRGBPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.SetRGB(0.2, 0.3, 0.4);
Assert.AreEqual(new Core.Color(0.5, 0.2, 0.3, 0.4), result);
@@ -356,7 +356,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SetATest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.SetA(10);
Assert.AreEqual(new Core.Color(10, 128, 128, 128), result);
@@ -365,7 +365,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SetAPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.SetA(0.1);
Assert.AreEqual(new Core.Color(0.1, 0.5, 0.5, 0.5), result);
@@ -374,7 +374,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SetRTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.SetRGB(r: 10);
Assert.AreEqual(new Core.Color(128, 10, 128, 128), result);
@@ -383,7 +383,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SetRPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.SetRGB(r: 0.1);
Assert.AreEqual(new Core.Color(0.5, 0.1, 0.5, 0.5), result);
@@ -392,7 +392,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SetGTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.SetRGB(g: 10);
Assert.AreEqual(new Core.Color(128, 128, 10, 128), result);
@@ -401,7 +401,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SetGPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.SetRGB(g: 0.1);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.1, 0.5), result);
@@ -410,7 +410,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SetBTest()
{
- Core.Color baseColor = new Core.Color(128, 128, 128, 128);
+ Core.Color baseColor = new(128, 128, 128, 128);
Core.Color result = baseColor.SetRGB(b: 10);
Assert.AreEqual(new Core.Color(128, 128, 128, 10), result);
@@ -419,7 +419,7 @@ namespace RGB.NET.Core.Tests.Color
[TestMethod]
public void SetBPercentTest()
{
- Core.Color baseColor = new Core.Color(0.5, 0.5, 0.5, 0.5);
+ Core.Color baseColor = new(0.5, 0.5, 0.5, 0.5);
Core.Color result = baseColor.SetRGB(b: 0.1);
Assert.AreEqual(new Core.Color(0.5, 0.5, 0.5, 0.1), result);