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

Merge branch 'Development' of https://github.com/DarthAffe/RGB.NET into asus-remove-system-management

This commit is contained in:
Aytaç Kayadelen 2023-12-06 20:48:53 +01:00
commit c11965eb3a
55 changed files with 714 additions and 226 deletions

View File

@ -11,16 +11,19 @@ on:
jobs: jobs:
build: build:
runs-on: windows-2022 runs-on: windows-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Setup .NET - name: Setup .NET
uses: actions/setup-dotnet@v1 uses: actions/setup-dotnet@v3
with: with:
dotnet-version: 7.0.x dotnet-version: |
8.0.x
7.0.x
6.0.x
- name: Git Semantic Version - name: Git Semantic Version
id: versioning id: versioning
uses: PaulHatch/semantic-version@v4.0.3 uses: PaulHatch/semantic-version@v4.0.3
@ -45,6 +48,12 @@ jobs:
name: RGB.NET-NET7 name: RGB.NET-NET7
path: bin/net7.0/RGB.NET.*.dll path: bin/net7.0/RGB.NET.*.dll
if-no-files-found: error if-no-files-found: error
- name: Upload a Build Artifact NET8
uses: actions/upload-artifact@v2.2.4
with:
name: RGB.NET-NET8
path: bin/net8.0/RGB.NET.*.dll
if-no-files-found: error
- name: Upload Nuget Build Artifact - name: Upload Nuget Build Artifact
uses: actions/upload-artifact@v2.2.4 uses: actions/upload-artifact@v2.2.4
with: with:
@ -53,3 +62,5 @@ jobs:
if-no-files-found: error if-no-files-found: error
- name: Nuget Push - name: Nuget Push
run: dotnet nuget push **\*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json run: dotnet nuget push **\*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json
- name: Symbols Push
run: dotnet nuget push **\*.snupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json

View File

@ -7,14 +7,17 @@ on:
jobs: jobs:
build: build:
runs-on: windows-2022 runs-on: windows-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Setup .NET - name: Setup .NET
uses: actions/setup-dotnet@v1 uses: actions/setup-dotnet@v3
with: with:
dotnet-version: 7.0.x dotnet-version: |
8.0.x
7.0.x
6.0.x
- name: Restore dependencies - name: Restore dependencies
run: dotnet restore run: dotnet restore
- name: Build - name: Build

View File

@ -10,16 +10,19 @@ on:
jobs: jobs:
build: build:
runs-on: windows-2022 runs-on: windows-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Setup .NET - name: Setup .NET
uses: actions/setup-dotnet@v1 uses: actions/setup-dotnet@v3
with: with:
dotnet-version: 7.0.x dotnet-version: |
8.0.x
7.0.x
6.0.x
- name: Git Semantic Version - name: Git Semantic Version
id: versioning id: versioning
uses: PaulHatch/semantic-version@v4.0.3 uses: PaulHatch/semantic-version@v4.0.3
@ -44,6 +47,12 @@ jobs:
name: RGB.NET-NET7 name: RGB.NET-NET7
path: bin/net7.0/RGB.NET.*.dll path: bin/net7.0/RGB.NET.*.dll
if-no-files-found: error if-no-files-found: error
- name: Upload a Build Artifact NET8
uses: actions/upload-artifact@v2.2.4
with:
name: RGB.NET-NET8
path: bin/net8.0/RGB.NET.*.dll
if-no-files-found: error
- name: Upload Nuget Build Artifact - name: Upload Nuget Build Artifact
uses: actions/upload-artifact@v2.2.4 uses: actions/upload-artifact@v2.2.4
with: with:
@ -55,6 +64,6 @@ jobs:
with: with:
tag_name: ${{ steps.versioning.outputs.version_tag }} tag_name: ${{ steps.versioning.outputs.version_tag }}
generate_release_notes: true generate_release_notes: true
files: bin/net7.0/RGB.NET.*.dll files: bin/net8.0/RGB.NET.*.dll
- name: Nuget Push - name: Nuget Push
run: dotnet nuget push **\*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json run: dotnet nuget push **\*.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json

View File

@ -12,6 +12,8 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
private bool _isDisposed = false;
private readonly double _defaultUpdateRateHardLimit; private readonly double _defaultUpdateRateHardLimit;
/// <inheritdoc /> /// <inheritdoc />
@ -60,6 +62,8 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
this._defaultUpdateRateHardLimit = defaultUpdateRateHardLimit; this._defaultUpdateRateHardLimit = defaultUpdateRateHardLimit;
} }
~AbstractRGBDeviceProvider() => Dispose(false);
#endregion #endregion
#region Methods #region Methods
@ -67,6 +71,8 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <inheritdoc /> /// <inheritdoc />
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false)
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
ThrowsExceptions = throwExceptions; ThrowsExceptions = throwExceptions;
try try
@ -108,6 +114,8 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <returns>The filtered collection of loaded devices.</returns> /// <returns>The filtered collection of loaded devices.</returns>
protected virtual IEnumerable<IRGBDevice> GetLoadedDevices(RGBDeviceType loadFilter) protected virtual IEnumerable<IRGBDevice> GetLoadedDevices(RGBDeviceType loadFilter)
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
List<IRGBDevice> devices = new(); List<IRGBDevice> devices = new();
foreach (IRGBDevice device in LoadDevices()) foreach (IRGBDevice device in LoadDevices())
{ {
@ -152,6 +160,8 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <returns>The update trigger mapped to the specified id.</returns> /// <returns>The update trigger mapped to the specified id.</returns>
protected virtual IDeviceUpdateTrigger GetUpdateTrigger(int id = -1, double? updateRateHardLimit = null) protected virtual IDeviceUpdateTrigger GetUpdateTrigger(int id = -1, double? updateRateHardLimit = null)
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
if (!UpdateTriggerMapping.TryGetValue(id, out IDeviceUpdateTrigger? updaeTrigger)) if (!UpdateTriggerMapping.TryGetValue(id, out IDeviceUpdateTrigger? updaeTrigger))
UpdateTriggerMapping[id] = (updaeTrigger = CreateUpdateTrigger(id, updateRateHardLimit ?? _defaultUpdateRateHardLimit)); UpdateTriggerMapping[id] = (updaeTrigger = CreateUpdateTrigger(id, updateRateHardLimit ?? _defaultUpdateRateHardLimit));
@ -171,6 +181,8 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// </summary> /// </summary>
protected virtual void Reset() protected virtual void Reset()
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
foreach (IDeviceUpdateTrigger updateTrigger in UpdateTriggerMapping.Values) foreach (IDeviceUpdateTrigger updateTrigger in UpdateTriggerMapping.Values)
updateTrigger.Dispose(); updateTrigger.Dispose();
@ -192,6 +204,8 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <returns><c>true</c> if the device was added successfully; otherwise <c>false</c>.</returns> /// <returns><c>true</c> if the device was added successfully; otherwise <c>false</c>.</returns>
protected virtual bool AddDevice(IRGBDevice device) protected virtual bool AddDevice(IRGBDevice device)
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
if (InternalDevices.Contains(device)) return false; if (InternalDevices.Contains(device)) return false;
InternalDevices.Add(device); InternalDevices.Add(device);
@ -207,6 +221,8 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <returns><c>true</c> if the device was removed successfully; otherwise <c>false</c>.</returns> /// <returns><c>true</c> if the device was removed successfully; otherwise <c>false</c>.</returns>
protected virtual bool RemoveDevice(IRGBDevice device) protected virtual bool RemoveDevice(IRGBDevice device)
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
if (!InternalDevices.Remove(device)) return false; if (!InternalDevices.Remove(device)) return false;
try { OnDevicesChanged(DevicesChangedEventArgs.CreateDevicesRemovedArgs(device)); } catch { /* we don't want to throw due to bad event handlers */ } try { OnDevicesChanged(DevicesChangedEventArgs.CreateDevicesRemovedArgs(device)); } catch { /* we don't want to throw due to bad event handlers */ }
@ -241,12 +257,26 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
protected virtual void OnDevicesChanged(DevicesChangedEventArgs args) => DevicesChanged?.Invoke(this, args); protected virtual void OnDevicesChanged(DevicesChangedEventArgs args) => DevicesChanged?.Invoke(this, args);
/// <inheritdoc /> /// <inheritdoc />
public virtual void Dispose() public void Dispose()
{ {
Reset(); if (_isDisposed) return;
try
{
Dispose(true);
}
catch { /* don't throw in dispose! */ }
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
_isDisposed = true;
} }
/// <summary>
/// Disposes the object and frees all resources.
/// </summary>
/// <param name="disposing"><c>true</c> if explicitely called through the Dispose-Method, <c>false</c> if called by the destructor.</param>
protected virtual void Dispose(bool disposing) => Reset();
#endregion #endregion
} }

View File

@ -372,6 +372,14 @@ public enum LedId
Keyboard_Custom127 = 0x0000707F, Keyboard_Custom127 = 0x0000707F,
Keyboard_Custom128 = 0x00007080, Keyboard_Custom128 = 0x00007080,
Keyboard_IndicatorNumLock = 0x00008001,
Keyboard_IndicatorCapsLock = 0x00008002,
Keyboard_IndicatorScrollLock = 0x00008003,
Keyboard_IndicatorWinLock = 0x00008004,
Keyboard_IndicatorPower = 0x00008005,
Keyboard_IndicatorMuted = 0x00008006,
Keyboard_IndicatorMacro = 0x00008007,
/*### Mouse ###*/ /*### Mouse ###*/
Mouse1 = 0x00100001, Mouse1 = 0x00100001,
Mouse2 = 0x00100002, Mouse2 = 0x00100002,

View File

@ -50,6 +50,12 @@ public readonly struct Scale : IEquatable<Scale>
#region Methods #region Methods
/// <summary>
/// Converts the <see cref="Horizontal"/> and <see cref="Vertical"/> value of this <see cref="Scale"/> to a human-readable string.
/// </summary>
/// <returns>A string that contains the <see cref="Horizontal"/> and <see cref="Vertical"/> value of this <see cref="Scale"/>. For example "[Horizontal: 1, Vertical: 0.5]".</returns>
public override string ToString() => $"[Horizontal: {Horizontal}, Vertical: {Vertical}]\"";
/// <summary> /// <summary>
/// Tests whether the specified <see cref="Scale"/> is equivalent to this <see cref="Scale" />. /// Tests whether the specified <see cref="Scale"/> is equivalent to this <see cref="Scale" />.
/// </summary> /// </summary>

View File

@ -17,7 +17,7 @@ surface.AlignDevices();
surface.RegisterUpdateTrigger(new TimerUpdateTrigger()); surface.RegisterUpdateTrigger(new TimerUpdateTrigger());
``` ```
## Basis Rendering ## Basic Rendering
```csharp ```csharp
// Create a led-group containing all leds on the surface // Create a led-group containing all leds on the surface
ILedGroup allLeds = new ListLedGroup(surface, surface.Leds); ILedGroup allLeds = new ListLedGroup(surface, surface.Leds);

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -16,11 +16,21 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static AsusDeviceProvider? _instance; private static AsusDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="AsusDeviceProvider"/> instance. /// Gets the singleton <see cref="AsusDeviceProvider"/> instance.
/// </summary> /// </summary>
public static AsusDeviceProvider Instance => _instance ?? new AsusDeviceProvider(); public static AsusDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new AsusDeviceProvider();
}
}
private IAuraSdk2? _sdk; private IAuraSdk2? _sdk;
private IAuraSyncDeviceCollection? _devices; //HACK DarthAffe 05.04.2021: Due to some researches this might fix the access violation in the asus-sdk private IAuraSyncDeviceCollection? _devices; //HACK DarthAffe 05.04.2021: Due to some researches this might fix the access violation in the asus-sdk
@ -35,8 +45,11 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public AsusDeviceProvider() public AsusDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(AsusDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(AsusDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -80,15 +93,19 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
{
base.Dispose(disposing);
try { _sdk?.ReleaseControl(0); } try { _sdk?.ReleaseControl(0); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
_devices = null; _devices = null;
_sdk = null; _sdk = null;
_instance = null;
}
} }
#endregion #endregion

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -17,11 +17,21 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static CoolerMasterDeviceProvider? _instance; private static CoolerMasterDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="CoolerMasterDeviceProvider"/> instance. /// Gets the singleton <see cref="CoolerMasterDeviceProvider"/> instance.
/// </summary> /// </summary>
public static CoolerMasterDeviceProvider Instance => _instance ?? new CoolerMasterDeviceProvider(); public static CoolerMasterDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new CoolerMasterDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -45,8 +55,11 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public CoolerMasterDeviceProvider() public CoolerMasterDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CoolerMasterDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CoolerMasterDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -94,12 +107,17 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
{
base.Dispose(disposing);
try { _CoolerMasterSDK.Reload(); } try { _CoolerMasterSDK.Reload(); }
catch { /* Unlucky.. */ } catch { /* Unlucky.. */ }
_instance = null;
}
} }
#endregion #endregion

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -17,11 +17,21 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static CorsairDeviceProvider? _instance; private static CorsairDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="CorsairDeviceProvider"/> instance. /// Gets the singleton <see cref="CorsairDeviceProvider"/> instance.
/// </summary> /// </summary>
public static CorsairDeviceProvider Instance => _instance ?? new CorsairDeviceProvider(); public static CorsairDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new CorsairDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -80,8 +90,11 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public CorsairDeviceProvider() public CorsairDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -300,12 +313,20 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
{
base.Dispose(disposing);
try { _CUESDK.CorsairDisconnect(); } catch { /* at least we tried */ } try { _CUESDK.CorsairDisconnect(); }
try { _CUESDK.UnloadCUESDK(); } catch { /* at least we tried */ } catch { /* at least we tried */ }
try { _CUESDK.UnloadCUESDK(); }
catch { /* at least we tried */ }
_instance = null;
}
} }
#endregion #endregion

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -18,11 +18,21 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static CorsairLegacyDeviceProvider? _instance; private static CorsairLegacyDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="CorsairLegacyDeviceProvider"/> instance. /// Gets the singleton <see cref="CorsairLegacyDeviceProvider"/> instance.
/// </summary> /// </summary>
public static CorsairLegacyDeviceProvider Instance => _instance ?? new CorsairLegacyDeviceProvider(); public static CorsairLegacyDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new CorsairLegacyDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -56,8 +66,11 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public CorsairLegacyDeviceProvider() public CorsairLegacyDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairLegacyDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(CorsairLegacyDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -201,12 +214,17 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
{
base.Dispose(disposing);
try { _CUESDK.UnloadCUESDK(); } try { _CUESDK.UnloadCUESDK(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
_instance = null;
}
} }
#endregion #endregion

View File

@ -53,6 +53,8 @@ public class CorsairCustomRGBDevice : CorsairRGBDevice<CorsairCustomRGBDeviceInf
continue; continue;
} }
if (ledPosition.LedId == CorsairLedId.Invalid) continue;
Mapping.Add(ledId, ledPosition.LedId); Mapping.Add(ledId, ledPosition.LedId);
Rectangle rectangle = ledPosition.ToRectangle(); Rectangle rectangle = ledPosition.ToRectangle();

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -16,11 +16,21 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static DMXDeviceProvider? _instance; private static DMXDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="DMXDeviceProvider"/> instance. /// Gets the singleton <see cref="DMXDeviceProvider"/> instance.
/// </summary> /// </summary>
public static DMXDeviceProvider Instance => _instance ?? new DMXDeviceProvider(); public static DMXDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new DMXDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
@ -37,8 +47,11 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public DMXDeviceProvider() public DMXDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DMXDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DMXDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -86,5 +99,16 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider
return updateTrigger; return updateTrigger;
} }
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
lock (_lock)
{
base.Dispose(disposing);
_instance = null;
}
}
#endregion #endregion
} }

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -16,11 +16,21 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static DebugDeviceProvider? _instance; private static DebugDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="DebugDeviceProvider"/> instance. /// Gets the singleton <see cref="DebugDeviceProvider"/> instance.
/// </summary> /// </summary>
public static DebugDeviceProvider Instance => _instance ?? new DebugDeviceProvider(); public static DebugDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new DebugDeviceProvider();
}
}
private List<(IDeviceLayout layout, Action<IEnumerable<Led>>? updateLedsAction)> _fakeDeviceDefinitions = new(); private List<(IDeviceLayout layout, Action<IEnumerable<Led>>? updateLedsAction)> _fakeDeviceDefinitions = new();
@ -34,8 +44,11 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public DebugDeviceProvider() public DebugDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DebugDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DebugDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -66,11 +79,16 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
{
base.Dispose(disposing);
_fakeDeviceDefinitions.Clear(); _fakeDeviceDefinitions.Clear();
_instance = null;
}
} }
#endregion #endregion

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -20,11 +20,21 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static LogitechDeviceProvider? _instance; private static LogitechDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="LogitechDeviceProvider"/> instance. /// Gets the singleton <see cref="LogitechDeviceProvider"/> instance.
/// </summary> /// </summary>
public static LogitechDeviceProvider Instance => _instance ?? new LogitechDeviceProvider(); public static LogitechDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new LogitechDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -112,7 +122,7 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
{ 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4, 0) }, { 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4, 0) },
}; };
/// <summary> /// <summary>
/// Gets the HID-definitions for wireless per-zone-devices. /// Gets the HID-definitions for wireless per-zone-devices.
/// </summary> /// </summary>
@ -164,8 +174,12 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public LogitechDeviceProvider() public LogitechDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(LogitechDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null)
throw new InvalidOperationException($"There can be only one instance of type {nameof(LogitechDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -254,17 +268,20 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
{
base.Dispose(disposing);
try { _LogitechGSDK.LogiLedRestoreLighting(); } try { _LogitechGSDK.LogiLedRestoreLighting(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
try { _LogitechGSDK.UnloadLogitechGSDK(); } try { _LogitechGSDK.UnloadLogitechGSDK(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
GC.SuppressFinalize(this); _instance = null;
}
} }
#endregion #endregion

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -17,11 +17,21 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static MsiDeviceProvider? _instance; private static MsiDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="MsiDeviceProvider"/> instance. /// Gets the singleton <see cref="MsiDeviceProvider"/> instance.
/// </summary> /// </summary>
public static MsiDeviceProvider Instance => _instance ?? new MsiDeviceProvider(); public static MsiDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new MsiDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -45,8 +55,11 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public MsiDeviceProvider() public MsiDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(MsiDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(MsiDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -98,14 +111,17 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider
private void ThrowMsiError(int errorCode, bool isCritical = false) => Throw(new MysticLightException(errorCode, _MsiSDK.GetErrorMessage(errorCode)), isCritical); private void ThrowMsiError(int errorCode, bool isCritical = false) => Throw(new MysticLightException(errorCode, _MsiSDK.GetErrorMessage(errorCode)), isCritical);
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
{
base.Dispose(disposing);
try { _MsiSDK.UnloadMsiSDK(); } try { _MsiSDK.UnloadMsiSDK(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
GC.SuppressFinalize(this); _instance = null;
}
} }
#endregion #endregion

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -17,11 +17,21 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static NovationDeviceProvider? _instance; private static NovationDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="NovationDeviceProvider"/> instance. /// Gets the singleton <see cref="NovationDeviceProvider"/> instance.
/// </summary> /// </summary>
public static NovationDeviceProvider Instance => _instance ?? new NovationDeviceProvider(); public static NovationDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new NovationDeviceProvider();
}
}
#endregion #endregion
@ -33,8 +43,11 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
private NovationDeviceProvider() private NovationDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(NovationDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(NovationDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -67,5 +80,16 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider
} }
} }
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
lock (_lock)
{
base.Dispose(disposing);
_instance = null;
}
}
#endregion #endregion
} }

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -14,6 +14,9 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private readonly List<OpenRgbClient> _clients = new(); private readonly List<OpenRgbClient> _clients = new();
private static OpenRGBDeviceProvider? _instance; private static OpenRGBDeviceProvider? _instance;
@ -21,7 +24,14 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
/// <summary> /// <summary>
/// Gets the singleton <see cref="OpenRGBDeviceProvider"/> instance. /// Gets the singleton <see cref="OpenRGBDeviceProvider"/> instance.
/// </summary> /// </summary>
public static OpenRGBDeviceProvider Instance => _instance ?? new OpenRGBDeviceProvider(); public static OpenRGBDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new OpenRGBDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
@ -48,8 +58,11 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public OpenRGBDeviceProvider() public OpenRGBDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(OpenRGBDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(OpenRGBDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -107,22 +120,22 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
continue; continue;
} }
if (device.Zones.Length == 0) if (device.Zones.Length == 0)
continue; continue;
if (device.Zones.All(z => z.LedCount == 0)) if (device.Zones.All(z => z.LedCount == 0))
continue; continue;
OpenRGBUpdateQueue updateQueue = new(GetUpdateTrigger(), i, openRgb, device); OpenRGBUpdateQueue updateQueue = new(GetUpdateTrigger(), i, openRgb, device);
bool anyZoneHasSegments = device.Zones.Any(z => z.Segments.Length > 0); bool anyZoneHasSegments = device.Zones.Any(z => z.Segments.Length > 0);
bool splitDeviceByZones = anyZoneHasSegments || PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type)); bool splitDeviceByZones = anyZoneHasSegments || PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type));
if (!splitDeviceByZones) if (!splitDeviceByZones)
{ {
yield return new OpenRGBGenericDevice(new OpenRGBDeviceInfo(device), updateQueue); yield return new OpenRGBGenericDevice(new OpenRGBDeviceInfo(device), updateQueue);
continue; continue;
} }
int totalLedCount = 0; int totalLedCount = 0;
foreach (Zone zone in device.Zones) foreach (Zone zone in device.Zones)
@ -149,18 +162,23 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
foreach (OpenRgbClient client in _clients)
{ {
try { client.Dispose(); } base.Dispose(disposing);
catch { /* at least we tried */ }
}
_clients.Clear(); foreach (OpenRgbClient client in _clients)
DeviceDefinitions.Clear(); {
try { client.Dispose(); }
catch { /* at least we tried */ }
}
_clients.Clear();
DeviceDefinitions.Clear();
_instance = null;
}
} }
#endregion #endregion

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -25,11 +25,21 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static PicoPiDeviceProvider? _instance; private static PicoPiDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="PicoPiDeviceProvider"/> instance. /// Gets the singleton <see cref="PicoPiDeviceProvider"/> instance.
/// </summary> /// </summary>
public static PicoPiDeviceProvider Instance => _instance ?? new PicoPiDeviceProvider(); public static PicoPiDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new PicoPiDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets the HID-definitions for PicoPi-devices. /// Gets the HID-definitions for PicoPi-devices.
@ -57,8 +67,11 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public PicoPiDeviceProvider() public PicoPiDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(PicoPiDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(PicoPiDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -126,5 +139,16 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider
_sdks.Clear(); _sdks.Clear();
} }
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
lock (_lock)
{
base.Dispose(disposing);
_instance = null;
}
}
#endregion #endregion
} }

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -19,11 +19,21 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static RazerDeviceProvider? _instance; private static RazerDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="RazerDeviceProvider"/> instance. /// Gets the singleton <see cref="RazerDeviceProvider"/> instance.
/// </summary> /// </summary>
public static RazerDeviceProvider Instance => _instance ?? new RazerDeviceProvider(); public static RazerDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new RazerDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
@ -124,6 +134,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ 0x0279, RGBDeviceType.Keyboard, "Blade 17 Pro (Mid 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0279, RGBDeviceType.Keyboard, "Blade 17 Pro (Mid 2021)", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x027A, RGBDeviceType.Keyboard, "Blade 15 Base (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x027A, RGBDeviceType.Keyboard, "Blade 15 Base (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x0282, RGBDeviceType.Keyboard, "Huntsman Mini Analog", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0282, RGBDeviceType.Keyboard, "Huntsman Mini Analog", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x0287, RGBDeviceType.Keyboard, "BlackWidow V4", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x028A, RGBDeviceType.Keyboard, "Blade 15 Advanced (Early 2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028A, RGBDeviceType.Keyboard, "Blade 15 Advanced (Early 2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x028B, RGBDeviceType.Keyboard, "Blade 17 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028B, RGBDeviceType.Keyboard, "Blade 17 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x028C, RGBDeviceType.Keyboard, "Blade 14 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x028C, RGBDeviceType.Keyboard, "Blade 14 (2022)", LedMappings.Keyboard, RazerEndpointType.Keyboard },
@ -135,7 +146,9 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ 0x0295, RGBDeviceType.Keyboard, "DeathStalker V2", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0295, RGBDeviceType.Keyboard, "DeathStalker V2", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x0296, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless { 0x0296, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wireless
{ 0x0298, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired { 0x0298, RGBDeviceType.Keyboard, "DeathStalker V2 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, // Wired
{ 0x02A0, RGBDeviceType.Keyboard, "Blade 18", LedMappings.Blade, RazerEndpointType.Keyboard },
{ 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x02A5, RGBDeviceType.Keyboard, "BlackWidow V4 75%", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard },
// Mice // Mice
@ -211,6 +224,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ 0x00A1, RGBDeviceType.Mouse, "DeathAdder V2 Lite", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00A1, RGBDeviceType.Mouse, "DeathAdder V2 Lite", LedMappings.Mouse, RazerEndpointType.Mouse },
{ 0x00A5, RGBDeviceType.Mouse, "Viper V2 Pro (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00A5, RGBDeviceType.Mouse, "Viper V2 Pro (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse },
{ 0x00A6, RGBDeviceType.Mouse, "Viper V2 Pro (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00A6, RGBDeviceType.Mouse, "Viper V2 Pro (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse },
{ 0x00A7, RGBDeviceType.Mouse, "Naga V2 Pro", LedMappings.Mouse, RazerEndpointType.Mouse },
{ 0x00A8, RGBDeviceType.Mouse, "Naga V2 Pro", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00A8, RGBDeviceType.Mouse, "Naga V2 Pro", LedMappings.Mouse, RazerEndpointType.Mouse },
{ 0x00AA, RGBDeviceType.Mouse, "Basilisk V3 Pro (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00AA, RGBDeviceType.Mouse, "Basilisk V3 Pro (Wired)", LedMappings.Mouse, RazerEndpointType.Mouse },
{ 0x00AB, RGBDeviceType.Mouse, "Basilisk V3 Pro (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x00AB, RGBDeviceType.Mouse, "Basilisk V3 Pro (Wireless)", LedMappings.Mouse, RazerEndpointType.Mouse },
@ -232,6 +246,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ 0x051A, RGBDeviceType.Headset, "Nari Ultimate", LedMappings.Headset, RazerEndpointType.Headset }, { 0x051A, RGBDeviceType.Headset, "Nari Ultimate", LedMappings.Headset, RazerEndpointType.Headset },
{ 0x051C, RGBDeviceType.Headset, "Nari", LedMappings.Headset, RazerEndpointType.Headset }, { 0x051C, RGBDeviceType.Headset, "Nari", LedMappings.Headset, RazerEndpointType.Headset },
{ 0x0527, RGBDeviceType.Headset, "Kraken Ultimate", LedMappings.Headset, RazerEndpointType.Headset }, { 0x0527, RGBDeviceType.Headset, "Kraken Ultimate", LedMappings.Headset, RazerEndpointType.Headset },
{ 0x0560, RGBDeviceType.Headset, "Kraken Kitty V2", LedMappings.Headset, RazerEndpointType.Headset },
{ 0x0F19, RGBDeviceType.Headset, "Kraken Kitty Edition", LedMappings.Headset, RazerEndpointType.Headset }, { 0x0F19, RGBDeviceType.Headset, "Kraken Kitty Edition", LedMappings.Headset, RazerEndpointType.Headset },
// Keypads // Keypads
@ -248,6 +263,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ 0x0F08, RGBDeviceType.HeadsetStand, "Base Station Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, // DarthAffe 16.12.2022: Not tested but based on the V2 I assume this is also a mousepad { 0x0F08, RGBDeviceType.HeadsetStand, "Base Station Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, // DarthAffe 16.12.2022: Not tested but based on the V2 I assume this is also a mousepad
{ 0x0F20, RGBDeviceType.HeadsetStand, "Base Station V2 Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, // DarthAffe 16.12.2022: Not sure why, but it's handled as a mousepad { 0x0F20, RGBDeviceType.HeadsetStand, "Base Station V2 Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, // DarthAffe 16.12.2022: Not sure why, but it's handled as a mousepad
{ 0x007E, RGBDeviceType.LedStripe, "Razer Mouse Dock Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, //roxaskeyheart 06.02.2023: Probably handled the same as a mousepad { 0x007E, RGBDeviceType.LedStripe, "Razer Mouse Dock Chroma", LedMappings.Mousepad, RazerEndpointType.Mousepad }, //roxaskeyheart 06.02.2023: Probably handled the same as a mousepad
{ 0x00A4, RGBDeviceType.LedStripe, "Mouse Dock Pro", LedMappings.Mousepad, RazerEndpointType.Mousepad }, // DarthAffe 22.09.2023: Most likely also a mousepad?
{ 0x0517, RGBDeviceType.Speaker, "Nommo Chroma", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0517, RGBDeviceType.Speaker, "Nommo Chroma", LedMappings.ChromaLink, RazerEndpointType.ChromaLink },
{ 0x0518, RGBDeviceType.Speaker, "Nommo Pro", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0518, RGBDeviceType.Speaker, "Nommo Pro", LedMappings.ChromaLink, RazerEndpointType.ChromaLink },
{ 0x0F07, RGBDeviceType.Unknown, "Chroma Mug Holder", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F07, RGBDeviceType.Unknown, "Chroma Mug Holder", LedMappings.ChromaLink, RazerEndpointType.ChromaLink },
@ -255,7 +271,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ 0x0F13, RGBDeviceType.Unknown, "Lian Li O11", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F13, RGBDeviceType.Unknown, "Lian Li O11", LedMappings.ChromaLink, RazerEndpointType.ChromaLink },
{ 0x0F1D, RGBDeviceType.Unknown, "Mouse Bungee V3 Chroma", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F1D, RGBDeviceType.Unknown, "Mouse Bungee V3 Chroma", LedMappings.ChromaLink, RazerEndpointType.ChromaLink },
{ 0x0F1F, RGBDeviceType.LedController, "Addressable RGB Controller", LedMappings.ChromaLink, RazerEndpointType.ChromaLink }, { 0x0F1F, RGBDeviceType.LedController, "Addressable RGB Controller", LedMappings.ChromaLink, RazerEndpointType.ChromaLink },
}; };
#endregion #endregion
@ -268,8 +284,11 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public RazerDeviceProvider() public RazerDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(RazerDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(RazerDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -343,15 +362,20 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
{
base.Dispose(disposing);
TryUnInit(); TryUnInit();
// DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit // DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit
//try { _RazerSDK.UnloadRazerSDK(); } //try { _RazerSDK.UnloadRazerSDK(); }
//catch { /* at least we tried */ } //catch { /* at least we tried */ }
_instance = null;
}
} }
#endregion #endregion

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -20,11 +20,21 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static SteelSeriesDeviceProvider? _instance; private static SteelSeriesDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="SteelSeriesDeviceProvider"/> instance. /// Gets the singleton <see cref="SteelSeriesDeviceProvider"/> instance.
/// </summary> /// </summary>
public static SteelSeriesDeviceProvider Instance => _instance ?? new SteelSeriesDeviceProvider(); public static SteelSeriesDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new SteelSeriesDeviceProvider();
}
}
private const int VENDOR_ID = 0x1038; private const int VENDOR_ID = 0x1038;
@ -93,8 +103,11 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public SteelSeriesDeviceProvider() public SteelSeriesDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SteelSeriesDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SteelSeriesDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -133,12 +146,17 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new DeviceUpdateTrigger(updateRateHardLimit) { HeartbeatTimer = HEARTBEAT_TIMER }; protected override IDeviceUpdateTrigger CreateUpdateTrigger(int id, double updateRateHardLimit) => new DeviceUpdateTrigger(updateRateHardLimit) { HeartbeatTimer = HEARTBEAT_TIMER };
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
{
base.Dispose(disposing);
try { SteelSeriesSDK.Dispose(); } try { SteelSeriesSDK.Dispose(); }
catch { /* shit happens */ } catch { /* shit happens */ }
_instance = null;
}
} }
#endregion #endregion

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -16,11 +16,21 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static WS281XDeviceProvider? _instance; private static WS281XDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="WS281XDeviceProvider"/> instance. /// Gets the singleton <see cref="WS281XDeviceProvider"/> instance.
/// </summary> /// </summary>
public static WS281XDeviceProvider Instance => _instance ?? new WS281XDeviceProvider(); public static WS281XDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new WS281XDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
@ -39,8 +49,11 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public WS281XDeviceProvider() public WS281XDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WS281XDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WS281XDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -70,11 +83,16 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
{
base.Dispose(disposing);
DeviceDefinitions.Clear(); DeviceDefinitions.Clear();
_instance = null;
}
} }
#endregion #endregion

View File

@ -1,24 +1,29 @@
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace RGB.NET.Devices.Wooting.Enum; namespace RGB.NET.Devices.Wooting.Enum;
/// <summary> /// <summary>
/// Represents the type of a wooting device /// Represents the type of a wooting device
/// </summary> /// </summary>
public enum WootingDeviceType public enum WootingDeviceType
{ {
/// <summary> /// <summary>
/// 10 Keyless Keyboard. E.g. Wooting One /// 10 Keyless Keyboard. E.g. Wooting One
/// </summary> /// </summary>
KeyboardTKL = 1, KeyboardTKL = 1,
/// <summary> /// <summary>
/// Full Size keyboard. E.g. Wooting Two /// Full Size keyboard. E.g. Wooting Two
/// </summary> /// </summary>
Keyboard = 2, Keyboard = 2,
/// <summary> /// <summary>
/// Full Size keyboard. E.g. Wooting Two /// 60 percent keyboard, E.g. Wooting 60HE
/// </summary> /// </summary>
KeyboardSixtyPercent = 3 KeyboardSixtyPercent = 3,
/// <summary>
/// Three key keypad. E.g. Wooting Uwu
/// </summary>
Keypad3Keys = 4,
} }

View File

@ -13,6 +13,7 @@ namespace RGB.NET.Devices.Wooting.Enum;
/// </remarks> /// </remarks>
public enum WootingLayoutType public enum WootingLayoutType
{ {
Unknown = -1,
ANSI = 0, ANSI = 0,
ISO = 1 ISO = 1
} }

View File

@ -1,15 +1,15 @@
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
using System.Collections.Generic;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum; using RGB.NET.Devices.Wooting.Enum;
using System.Collections.Generic;
namespace RGB.NET.Devices.Wooting.Keyboard; namespace RGB.NET.Devices.Wooting.Generic;
/// <summary> /// <summary>
/// Contains all the hardware-id mappings for Wooting devices. /// Contains all the hardware-id mappings for Wooting devices.
/// </summary> /// </summary>
internal static class WootingKeyboardLedMappings internal static class WootingLedMappings
{ {
#region Properties & Fields #region Properties & Fields
@ -305,6 +305,36 @@ internal static class WootingKeyboardLedMappings
{ LedId.Keyboard_Function, (5, 13) } { LedId.Keyboard_Function, (5, 13) }
}; };
private static readonly Dictionary<LedId, (int row, int column)> ThreeKeyKeypad = new()
{
//left (from top to bottom)
[LedId.LedStripe1] = (1, 0),
[LedId.LedStripe2] = (2, 0),
[LedId.LedStripe3] = (3, 0),
//bottom (from left to right)
[LedId.LedStripe4] = (4, 1),
[LedId.LedStripe5] = (4, 2),
[LedId.LedStripe6] = (4, 4),
[LedId.LedStripe7] = (4, 5),
//right (from bottom to top)
[LedId.LedStripe8] = (3, 6),
[LedId.LedStripe9] = (2, 6),
[LedId.LedStripe10] = (1, 6),
//top (from right to left)
[LedId.LedStripe11] = (0, 6),
[LedId.LedStripe12] = (0, 4),
[LedId.LedStripe13] = (0, 2),
[LedId.LedStripe14] = (0, 0),
//analog keys
[LedId.Keypad1] = (2, 1),
[LedId.Keypad2] = (2, 3),
[LedId.Keypad3] = (2, 5),
};
/// <summary> /// <summary>
/// Contains all the hardware-id mappings for Wooting devices. /// Contains all the hardware-id mappings for Wooting devices.
/// </summary> /// </summary>
@ -312,8 +342,9 @@ internal static class WootingKeyboardLedMappings
{ {
[WootingDeviceType.Keyboard] = Fullsize, [WootingDeviceType.Keyboard] = Fullsize,
[WootingDeviceType.KeyboardTKL] = TKL, [WootingDeviceType.KeyboardTKL] = TKL,
[WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent [WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent,
[WootingDeviceType.Keypad3Keys] = ThreeKeyKeypad
}; };
#endregion #endregion
} }

View File

@ -1,4 +1,5 @@
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting.Generic; namespace RGB.NET.Devices.Wooting.Generic;
@ -23,4 +24,17 @@ public abstract class WootingRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceI
} }
#endregion #endregion
#region Methods
public override void Dispose()
{
_WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex);
_WootingSDK.Reset();
base.Dispose();
}
#endregion
} }

View File

@ -1,34 +0,0 @@
using System;
using System.ComponentModel;
using System.Reflection;
namespace RGB.NET.Devices.Wooting.Helper;
/// <summary>
/// Offers some extensions and helper-methods for enum related things.
/// </summary>
internal static class EnumExtension
{
/// <summary>
/// Gets the value of the <see cref="DescriptionAttribute"/>.
/// </summary>
/// <param name="source">The enum value to get the description from.</param>
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="System.Enum.ToString()" /> result of the source.</returns>
internal static string GetDescription(this System.Enum source)
=> source.GetAttribute<DescriptionAttribute>()?.Description ?? source.ToString();
/// <summary>
/// Gets the attribute of type T.
/// </summary>
/// <param name="source">The enum value to get the attribute from</param>
/// <typeparam name="T">The generic attribute type</typeparam>
/// <returns>The <see cref="Attribute"/>.</returns>
private static T? GetAttribute<T>(this System.Enum source)
where T : Attribute
{
FieldInfo? fi = source.GetType().GetField(source.ToString());
if (fi == null) return null;
T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false);
return attributes.Length > 0 ? attributes[0] : null;
}
}

View File

@ -1,7 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Generic; using RGB.NET.Devices.Wooting.Generic;
using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting.Keyboard; namespace RGB.NET.Devices.Wooting.Keyboard;
@ -37,22 +36,14 @@ public sealed class WootingKeyboardRGBDevice : WootingRGBDevice<WootingKeyboardR
private void InitializeLayout() private void InitializeLayout()
{ {
Dictionary<LedId, (int row, int column)> mapping = WootingKeyboardLedMappings.Mapping[DeviceInfo.WootingDeviceType]; Dictionary<LedId, (int row, int column)> mapping = WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType];
foreach (KeyValuePair<LedId, (int row, int column)> led in mapping) foreach (KeyValuePair<LedId, (int row, int column)> led in mapping)
AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19)); AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
} }
/// <inheritdoc /> /// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => WootingKeyboardLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId]; protected override object GetLedCustomData(LedId ledId) => WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId];
public override void Dispose()
{
_WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex);
_WootingSDK.Reset();
base.Dispose();
}
#endregion #endregion
} }

View File

@ -0,0 +1,43 @@
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Generic;
namespace RGB.NET.Devices.Wooting.Keypad;
/// <inheritdoc cref="WootingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Wooting keyboard.
/// </summary>
public sealed class WootingKeypadRGBDevice : WootingRGBDevice<WootingKeypadRGBDeviceInfo>, IKeypad
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Wooting.Keyboard.WootingKeypadRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by Wooting for the keyboard</param>
/// <param name="updateQueue">The update queue used to update this device.</param>
internal WootingKeypadRGBDevice(WootingKeypadRGBDeviceInfo info, IUpdateQueue updateQueue)
: base(info, updateQueue)
{
InitializeLayout();
}
#endregion
#region Methods
private void InitializeLayout()
{
Dictionary<LedId, (int row, int column)> mapping = WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType];
foreach (KeyValuePair<LedId, (int row, int column)> led in mapping)
AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
}
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId];
#endregion
}

View File

@ -0,0 +1,17 @@
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Generic;
using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting.Keypad;
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Wooting.Keypad.WootingKeypadRGBDevice" />.
/// </summary>
public sealed class WootingKeypadRGBDeviceInfo : WootingRGBDeviceInfo
{
internal WootingKeypadRGBDeviceInfo(_WootingDeviceInfo deviceInfo, byte deviceIndex)
: base(RGBDeviceType.Keypad, deviceInfo, deviceIndex)
{
}
}

View File

@ -17,11 +17,13 @@ internal struct _WootingDeviceInfo
internal byte MaxColumns { get; private set; } internal byte MaxColumns { get; private set; }
internal byte KeycodeLimit { get; private set; } internal byte MaxLedIndex { get; private set; }
internal WootingDeviceType DeviceType { get; private set; } internal WootingDeviceType DeviceType { get; private set; }
internal bool V2Interface { get; set; } internal bool V2Interface { get; private set; }
internal WootingLayoutType LayoutType { get; private set; } internal WootingLayoutType LayoutType { get; private set; }
internal bool UsesSmallPackets { get; private set; }
} }

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -2,8 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum;
using RGB.NET.Devices.Wooting.Generic; using RGB.NET.Devices.Wooting.Generic;
using RGB.NET.Devices.Wooting.Keyboard; using RGB.NET.Devices.Wooting.Keyboard;
using RGB.NET.Devices.Wooting.Keypad;
using RGB.NET.Devices.Wooting.Native; using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting; namespace RGB.NET.Devices.Wooting;
@ -16,11 +18,21 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private static WootingDeviceProvider? _instance; private static WootingDeviceProvider? _instance;
/// <summary> /// <summary>
/// Gets the singleton <see cref="WootingDeviceProvider"/> instance. /// Gets the singleton <see cref="WootingDeviceProvider"/> instance.
/// </summary> /// </summary>
public static WootingDeviceProvider Instance => _instance ?? new WootingDeviceProvider(); public static WootingDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new WootingDeviceProvider();
}
}
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications.
@ -57,8 +69,11 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public WootingDeviceProvider() public WootingDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}"); lock (_lock)
_instance = this; {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}");
_instance = this;
}
} }
#endregion #endregion
@ -86,22 +101,35 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
WootingUpdateQueue updateQueue = new(GetUpdateTrigger(), i); WootingUpdateQueue updateQueue = new(GetUpdateTrigger(), i);
_WootingSDK.SelectDevice(i); _WootingSDK.SelectDevice(i);
_WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!; _WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!;
//Uwu non-rgb returns zero here.
if (nativeDeviceInfo.MaxLedIndex == 0)
continue;
yield return new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(nativeDeviceInfo, i), updateQueue); yield return nativeDeviceInfo.DeviceType switch
{
WootingDeviceType.Keypad3Keys => new WootingKeypadRGBDevice(new WootingKeypadRGBDeviceInfo(nativeDeviceInfo, i), updateQueue),
_ => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(nativeDeviceInfo, i), updateQueue),
};
} }
} }
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() protected override void Dispose(bool disposing)
{ {
base.Dispose(); lock (_lock)
lock (_WootingSDK.SdkLock)
{ {
try { _WootingSDK.UnloadWootingSDK(); } base.Dispose(disposing);
catch { /* at least we tried */ }
lock (_WootingSDK.SdkLock)
{
try { _WootingSDK.UnloadWootingSDK(); }
catch { /* at least we tried */ }
}
_instance = null;
} }
} }

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -174,7 +174,7 @@ public class DeviceLayout : IDeviceLayout
/// <returns>The deserialized custom data object.</returns> /// <returns>The deserialized custom data object.</returns>
protected virtual object? GetCustomData(object? customData, Type? type) protected virtual object? GetCustomData(object? customData, Type? type)
{ {
XmlNode? node = (customData as XmlNode) ?? (customData as IEnumerable<XmlNode>)?.FirstOrDefault()?.ParentNode; //HACK DarthAffe 16.01.2021: This gives us the CustomData-Node XmlNode? node = (customData as XmlNode) ?? (customData as IEnumerable<XmlNode>)?.FirstOrDefault(x => x.ParentNode != null)?.ParentNode; //HACK DarthAffe 16.01.2021: This gives us the CustomData-Node
if ((node == null) || (type == null)) return null; if ((node == null) || (type == null)) return null;
using MemoryStream ms = new(); using MemoryStream ms = new();

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Xml.Serialization;
using RGB.NET.Core; using RGB.NET.Core;
namespace RGB.NET.Layout; namespace RGB.NET.Layout;
@ -51,4 +53,48 @@ public static class LayoutExtension
device.RemoveLed(led); device.RemoveLed(led);
} }
} }
/// <summary>
/// Saves the specified layout to the given location.
/// </summary>
/// <param name="layout">The layout to save.</param>
/// <param name="targetFile">The location to save to.</param>
public static void Save(this IDeviceLayout layout, string targetFile)
{
using FileStream fs = new(targetFile, FileMode.Create);
layout.Save(fs);
}
/// <summary>
/// Saves the specified layout to the given stream.
/// </summary>
/// <param name="layout">The layout to save.</param>
/// <param name="stream">The stream to save to.</param>
public static void Save(this IDeviceLayout layout, Stream stream)
{
Type? customDataType = layout.CustomData?.GetType();
Type? customLedDataType = layout.Leds.FirstOrDefault(x => x.CustomData != null)?.CustomData?.GetType();
Type[] customTypes;
if ((customDataType != null) && (customLedDataType != null))
customTypes = new[] { customDataType, customLedDataType };
else if (customDataType != null)
customTypes = new[] { customDataType };
else if (customLedDataType != null)
customTypes = new[] { customLedDataType };
else
customTypes = Array.Empty<Type>();
if (layout is DeviceLayout deviceLayout)
{
deviceLayout.InternalCustomData = deviceLayout.CustomData;
foreach (ILedLayout led in deviceLayout.Leds)
if (led is LedLayout ledLayout)
ledLayout.InternalCustomData = ledLayout.CustomData;
}
XmlSerializer serializer = new(typeof(DeviceLayout), null, customTypes, null, null);
serializer.Serialize(stream, layout);
}
} }

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks> <TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>