mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Fully implemented disposing on devices
This commit is contained in:
parent
1cfdeefde1
commit
83edbc6eac
@ -157,8 +157,12 @@ namespace RGB.NET.Core
|
||||
/// <inheritdoc />
|
||||
public virtual void Dispose()
|
||||
{
|
||||
SpecialDeviceParts.Clear();
|
||||
LedMapping.Clear();
|
||||
try
|
||||
{
|
||||
SpecialDeviceParts.Clear();
|
||||
LedMapping.Clear();
|
||||
}
|
||||
catch { /* this really shouldn't happen */ }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -172,7 +172,12 @@ namespace RGB.NET.Devices.Asus
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_sdk?.ReleaseControl(0);
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
try { _sdk?.ReleaseControl(0); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
_sdk = null;
|
||||
}
|
||||
|
||||
|
||||
@ -80,6 +80,15 @@ namespace RGB.NET.Devices.Asus
|
||||
//}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { UpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,6 +268,9 @@ namespace RGB.NET.Devices.Asus
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
try { _AsusSDK.UnloadAsusSDK(); }
|
||||
catch { /* at least we tried */ }
|
||||
}
|
||||
|
||||
@ -80,6 +80,9 @@ namespace RGB.NET.Devices.Asus
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}.Dispose" />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { UpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
if ((DeviceInfo is AsusRGBDeviceInfo deviceInfo) && (deviceInfo.Handle != IntPtr.Zero))
|
||||
Marshal.FreeHGlobal(deviceInfo.Handle);
|
||||
|
||||
|
||||
@ -175,6 +175,9 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
if (IsInitialized)
|
||||
foreach (IRGBDevice device in Devices)
|
||||
{
|
||||
|
||||
@ -74,6 +74,9 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}.Dispose" />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { UpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
_CoolerMasterSDK.EnableLedControl(false, DeviceInfo.DeviceIndex);
|
||||
|
||||
base.Dispose();
|
||||
|
||||
@ -293,6 +293,9 @@ namespace RGB.NET.Devices.Corsair
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
try { _CUESDK.UnloadCUESDK(); }
|
||||
catch { /* at least we tried */ }
|
||||
}
|
||||
|
||||
@ -122,6 +122,15 @@ namespace RGB.NET.Devices.Corsair
|
||||
Marshal.FreeHGlobal(ptr);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { DeviceUpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,7 +116,10 @@ namespace RGB.NET.Devices.DMX
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{ }
|
||||
{
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -59,6 +59,15 @@ namespace RGB.NET.Devices.DMX.E131
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => _updateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { _updateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,6 +70,15 @@ namespace RGB.NET.Devices.Logitech
|
||||
ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Logitech", $"{layoutPath}.xml"), layout, true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { UpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,6 +184,9 @@ namespace RGB.NET.Devices.Logitech
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
try { _LogitechGSDK.LogiLedRestoreLighting(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
|
||||
@ -68,6 +68,15 @@ namespace RGB.NET.Devices.Msi
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
||||
=> DeviceUpdateQueue.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is int)));
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { DeviceUpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,6 +164,9 @@ namespace RGB.NET.Devices.Msi
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
try { _MsiSDK.UnloadMsiSDK(); }
|
||||
catch { /* at least we tried */ }
|
||||
}
|
||||
|
||||
@ -78,8 +78,11 @@ namespace RGB.NET.Devices.Novation
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}.Dispose" />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { UpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
Reset();
|
||||
UpdateQueue.Dispose();
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
|
||||
@ -122,7 +122,10 @@ namespace RGB.NET.Devices.Novation
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{ }
|
||||
{
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -81,6 +81,15 @@ namespace RGB.NET.Devices.Razer
|
||||
/// </summary>
|
||||
public void Reset() => UpdateQueue.Reset();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { UpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,6 +224,9 @@ namespace RGB.NET.Devices.Razer
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
TryUnInit();
|
||||
|
||||
try { _RazerSDK.UnloadRazerSDK(); }
|
||||
|
||||
@ -66,6 +66,9 @@ namespace RGB.NET.Devices.SoIP.Server
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { _updateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
|
||||
_tcpServer.Stop();
|
||||
|
||||
@ -56,7 +56,7 @@ namespace RGB.NET.Devices.SoIP
|
||||
{
|
||||
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SoIPDeviceProvider)}");
|
||||
_instance = this;
|
||||
|
||||
|
||||
UpdateTrigger = new DeviceUpdateTrigger();
|
||||
}
|
||||
|
||||
@ -130,8 +130,8 @@ namespace RGB.NET.Devices.SoIP
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (IRGBDevice device in Devices)
|
||||
device.Dispose();
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -83,6 +83,15 @@ namespace RGB.NET.Devices.SteelSeries
|
||||
ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\SteelSeries", $"{layoutPath}.xml"), layout, true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { UpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,11 +117,11 @@ namespace RGB.NET.Devices.SteelSeries
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
SteelSeriesSDK.Dispose();
|
||||
}
|
||||
catch {/* shit happens */}
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
try { SteelSeriesSDK.Dispose(); }
|
||||
catch { /* shit happens */ }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -73,6 +73,15 @@ namespace RGB.NET.Devices.WS281X.Arduino
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { UpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ namespace RGB.NET.Devices.WS281X.Arduino
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ArduinoWS281XDeviceDefinition"/> class.
|
||||
/// </summary>
|
||||
/// <param name="portName">The name of the serial-port to connect to.</param>
|
||||
/// <param name="port">The name of the serial-port to connect to.</param>
|
||||
public ArduinoWS281XDeviceDefinition(string port)
|
||||
{
|
||||
this.Port = port;
|
||||
@ -50,10 +50,8 @@ namespace RGB.NET.Devices.WS281X.Arduino
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IRGBDevice> CreateDevices()
|
||||
public IEnumerable<IRGBDevice> CreateDevices(IDeviceUpdateTrigger updateTrigger)
|
||||
{
|
||||
DeviceUpdateTrigger updateTrigger = new DeviceUpdateTrigger();
|
||||
|
||||
ArduinoWS2812USBUpdateQueue queue = new ArduinoWS2812USBUpdateQueue(updateTrigger, Port, BaudRate);
|
||||
IEnumerable<(int channel, int ledCount)> channels = queue.GetChannels();
|
||||
int counter = 0;
|
||||
@ -64,8 +62,6 @@ namespace RGB.NET.Devices.WS281X.Arduino
|
||||
device.Initialize(ledCount);
|
||||
yield return device;
|
||||
}
|
||||
|
||||
updateTrigger.Start();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -63,6 +63,15 @@ namespace RGB.NET.Devices.WS281X.Bitwizard
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { UpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BitwizardWS281XDeviceDefinition"/> class.
|
||||
/// </summary>
|
||||
/// <param name="portName">The name of the serial-port to connect to.</param>
|
||||
/// <param name="port">The name of the serial-port to connect to.</param>
|
||||
public BitwizardWS281XDeviceDefinition(string port)
|
||||
{
|
||||
this.Port = port;
|
||||
@ -54,17 +54,13 @@ namespace RGB.NET.Devices.WS281X.Bitwizard
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IRGBDevice> CreateDevices()
|
||||
public IEnumerable<IRGBDevice> CreateDevices(IDeviceUpdateTrigger updateTrigger)
|
||||
{
|
||||
DeviceUpdateTrigger updateTrigger = new DeviceUpdateTrigger();
|
||||
|
||||
BitwizardWS2812USBUpdateQueue queue = new BitwizardWS2812USBUpdateQueue(updateTrigger, Port, BaudRate);
|
||||
string name = Name ?? $"Bitwizard WS2812 USB ({Port})";
|
||||
BitwizardWS2812USBDevice device = new BitwizardWS2812USBDevice(new BitwizardWS2812USBDeviceInfo(name), queue);
|
||||
device.Initialize(StripLength);
|
||||
yield return device;
|
||||
|
||||
updateTrigger.Start();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -13,6 +13,6 @@ namespace RGB.NET.Devices.WS281X
|
||||
/// Gets the devices defined by this definition.
|
||||
/// </summary>
|
||||
/// <returns>The initialized devices defined by this definition.</returns>
|
||||
IEnumerable<IRGBDevice> CreateDevices();
|
||||
IEnumerable<IRGBDevice> CreateDevices(IDeviceUpdateTrigger updateTrigger);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.WS281X
|
||||
@ -37,6 +38,11 @@ namespace RGB.NET.Devices.WS281X
|
||||
// ReSharper disable once ReturnTypeCanBeEnumerable.Global
|
||||
public List<IWS281XDeviceDefinition> DeviceDefinitions { get; } = new List<IWS281XDeviceDefinition>();
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="DeviceUpdateTrigger"/> used to trigger the updates for corsair devices.
|
||||
/// </summary>
|
||||
public DeviceUpdateTrigger UpdateTrigger { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@ -49,6 +55,8 @@ namespace RGB.NET.Devices.WS281X
|
||||
{
|
||||
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WS281XDeviceProvider)}");
|
||||
_instance = this;
|
||||
|
||||
UpdateTrigger = new DeviceUpdateTrigger();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -69,17 +77,20 @@ namespace RGB.NET.Devices.WS281X
|
||||
|
||||
try
|
||||
{
|
||||
UpdateTrigger?.Stop();
|
||||
|
||||
List<IRGBDevice> devices = new List<IRGBDevice>();
|
||||
foreach (IWS281XDeviceDefinition deviceDefinition in DeviceDefinitions)
|
||||
{
|
||||
try
|
||||
{
|
||||
devices.AddRange(deviceDefinition.CreateDevices());
|
||||
devices.AddRange(deviceDefinition.CreateDevices(UpdateTrigger));
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
}
|
||||
Devices = devices;
|
||||
UpdateTrigger?.Start();
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||
IsInitialized = true;
|
||||
}
|
||||
catch
|
||||
@ -99,10 +110,10 @@ namespace RGB.NET.Devices.WS281X
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsInitialized)
|
||||
foreach (IRGBDevice device in Devices)
|
||||
if (device is IDisposable disposable)
|
||||
disposable.Dispose();
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */}
|
||||
|
||||
DeviceDefinitions.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -63,6 +63,15 @@ namespace RGB.NET.Devices.Wooting.Generic
|
||||
/// </summary>
|
||||
protected abstract void InitializeLayout();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
try { UpdateQueue?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,6 +143,9 @@ namespace RGB.NET.Devices.Wooting
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
try { UpdateTrigger?.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
try { _WootingSDK.Reset(); }
|
||||
catch { /* Unlucky.. */ }
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user