Changed all existing device-providers to use update-queues to decouple the physical update from the internal update-loop (first draft, code-documention is missing)

This commit is contained in:
DarthAffe committed 2018-03-25 15:53:13 +02:00
1 parent 3965bfb9a0
commit 66d03cdf4f
61 files changed
+1125 -440

No files matched your search

@@ -15,12 +15,15 @@ namespace RGB.NET.Devices.CoolerMaster
where TDeviceInfo : CoolerMasterRGBDeviceInfo
{
#region Properties & Fields
/// <inheritdoc />
/// <summary>
/// Gets information about the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterRGBDevice" />.
/// </summary>
public override TDeviceInfo DeviceInfo { get; }
protected CoolerMasterUpdateQueue UpdateQueue { get; set; }
#endregion
#region Constructors
@@ -42,7 +45,7 @@ namespace RGB.NET.Devices.CoolerMaster
/// <summary>
/// Initializes the device.
/// </summary>
public void Initialize()
public void Initialize(IUpdateTrigger updateTrigger)
{
InitializeLayout();
@@ -51,6 +54,8 @@ namespace RGB.NET.Devices.CoolerMaster
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
UpdateQueue = new CoolerMasterUpdateQueue(updateTrigger, DeviceInfo.DeviceIndex);
}
/// <summary>
@@ -59,23 +64,7 @@ namespace RGB.NET.Devices.CoolerMaster
protected abstract void InitializeLayout();
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
{
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
if (leds.Count > 0)
{
_CoolerMasterSDK.SetControlDevice(DeviceInfo.DeviceIndex);
foreach (Led led in leds)
{
(int row, int column) = ((int, int))led.CustomData;
_CoolerMasterSDK.SetLedColor(row, column, led.Color.R, led.Color.G, led.Color.B);
}
_CoolerMasterSDK.RefreshLed(false);
}
}
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
/// <inheritdoc cref="IDisposable.Dispose" />
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}.Dispose" />
@@ -0,0 +1,43 @@
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.CoolerMaster.Native;
namespace RGB.NET.Devices.CoolerMaster
{
public class CoolerMasterUpdateQueue : UpdateQueue
{
#region Properties & Fields
private CoolerMasterDevicesIndexes _deviceIndex;
#endregion
#region Constructors
public CoolerMasterUpdateQueue(IUpdateTrigger updateTrigger, CoolerMasterDevicesIndexes deviceIndex)
: base(updateTrigger)
{
this._deviceIndex = deviceIndex;
}
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet)
{
_CoolerMasterSDK.SetControlDevice(_deviceIndex);
foreach (KeyValuePair<object, Color> data in dataSet)
{
(int row, int column) = ((int, int))data.Key;
_CoolerMasterSDK.SetLedColor(row, column, data.Value.R, data.Value.G, data.Value.B);
}
_CoolerMasterSDK.RefreshLed(false);
}
#endregion
}
}
@@ -7,6 +7,6 @@ namespace RGB.NET.Devices.CoolerMaster
/// </summary>
internal interface ICoolerMasterRGBDevice : IRGBDevice
{
void Initialize();
void Initialize(IUpdateTrigger updateTrigger);
}
}