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

@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.Native;
namespace RGB.NET.Devices.Logitech
{
@@ -37,19 +35,10 @@ namespace RGB.NET.Devices.Logitech
}
/// <inheritdoc />
protected override object CreateLedCustomData(LedId ledId) => LogitechLedId.DEVICE;
protected override object CreateLedCustomData(LedId ledId) => (ledId, LogitechLedId.DEVICE);
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
{
Led led = ledsToUpdate.FirstOrDefault(x => x.Color.A > 0);
if (led == null) return;
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.DeviceRGB);
_LogitechGSDK.LogiLedSetLighting((int)Math.Round(led.Color.RPercent * 100),
(int)Math.Round(led.Color.GPercent * 100),
(int)Math.Round(led.Color.BPercent * 100));
}
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0).Take(1));
#endregion
}
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.Native;
namespace RGB.NET.Devices.Logitech
{
public class LogitechPerDeviceUpdateQueue : UpdateQueue
{
#region Constructors
public LogitechPerDeviceUpdateQueue(IUpdateTrigger updateTrigger)
: base(updateTrigger)
{ }
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet)
{
Color color = dataSet.Values.First();
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.DeviceRGB);
_LogitechGSDK.LogiLedSetLighting((int)Math.Round(color.RPercent * 100),
(int)Math.Round(color.GPercent * 100),
(int)Math.Round(color.BPercent * 100));
}
#endregion
}
}