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

Dispose of each keyboard properly

This commit is contained in:
Diogo Trindade 2022-08-09 12:52:23 +01:00
parent 819e6ef1df
commit f3d63f09a9
5 changed files with 15 additions and 5 deletions

View File

@ -37,6 +37,8 @@ public class WootingRGBDeviceInfo : IRGBDeviceInfo
/// </summary>
public WootingLayoutType WootingLayoutType { get; }
public byte WootingDeviceIndex { get; }
#endregion
#region Constructors
@ -46,11 +48,12 @@ public class WootingRGBDeviceInfo : IRGBDeviceInfo
/// </summary>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="deviceInfo">The <see cref="_WootingDeviceInfo"/> of the <see cref="IRGBDevice"/>.</param>
internal WootingRGBDeviceInfo(RGBDeviceType deviceType, _WootingDeviceInfo deviceInfo)
internal WootingRGBDeviceInfo(RGBDeviceType deviceType, _WootingDeviceInfo deviceInfo, byte deviceIndex)
{
this.DeviceType = deviceType;
this.WootingDeviceType = deviceInfo.DeviceType;
this.WootingLayoutType = deviceInfo.LayoutType;
this.WootingDeviceIndex = deviceIndex;
Model = deviceInfo.Model;
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);

View File

@ -1,6 +1,7 @@
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Generic;
using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting.Keyboard;
@ -48,5 +49,12 @@ public class WootingKeyboardRGBDevice : WootingRGBDevice<WootingKeyboardRGBDevic
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate));
public override void Dispose()
{
_WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex);
_WootingSDK.Reset();
base.Dispose();
}
#endregion
}

View File

@ -24,8 +24,8 @@ public class WootingKeyboardRGBDeviceInfo : WootingRGBDeviceInfo, IKeyboardDevic
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Wooting.WootingKeyboardRGBDeviceInfo" />.
/// </summary>
/// <param name="deviceInfo">The native <see cref="T:RGB.NET.Devices.Wooting.Native._WootingDeviceInfo" />.</param>
internal WootingKeyboardRGBDeviceInfo(_WootingDeviceInfo deviceInfo)
: base(RGBDeviceType.Keyboard, deviceInfo)
internal WootingKeyboardRGBDeviceInfo(_WootingDeviceInfo deviceInfo, byte deviceIndex)
: base(RGBDeviceType.Keyboard, deviceInfo, deviceIndex)
{
Layout = WootingLayoutType switch
{

View File

@ -58,7 +58,6 @@ internal static class _WootingSDK
{
if (_handle == IntPtr.Zero) return;
Reset();
Close();
_getDeviceInfoPointer = null;

View File

@ -74,7 +74,7 @@ public class WootingDeviceProvider : AbstractRGBDeviceProvider
_WootingSDK.SelectDevice(i);
_WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!;
yield return new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(nativeDeviceInfo), updateQueue);
yield return new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(nativeDeviceInfo, i), updateQueue);
}
}
}