mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-11-11 04:57:15 +00:00
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:
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
|
||||
{
|
||||
@@ -28,37 +26,10 @@ namespace RGB.NET.Devices.Logitech
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override object CreateLedCustomData(LedId ledId) => PerKeyIdMapping.DEFAULT.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : LogitechLedId.Invalid;
|
||||
protected override object CreateLedCustomData(LedId ledId) => (ledId, PerKeyIdMapping.DEFAULT.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : LogitechLedId.Invalid);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
||||
{
|
||||
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
|
||||
if (leds.Count <= 0) return;
|
||||
|
||||
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
|
||||
|
||||
byte[] bitmap = null;
|
||||
foreach (Led led in leds)
|
||||
{
|
||||
// DarthAffe 26.03.2017: This is only needed since update by name doesn't work as expected for all keys ...
|
||||
if (BitmapMapping.BitmapOffset.TryGetValue(led.Id, out int bitmapOffset))
|
||||
{
|
||||
if (bitmap == null)
|
||||
bitmap = BitmapMapping.CreateBitmap();
|
||||
|
||||
BitmapMapping.SetColor(ref bitmap, bitmapOffset, led.Color);
|
||||
}
|
||||
else
|
||||
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)led.CustomData,
|
||||
(int)Math.Round(led.Color.RPercent * 100),
|
||||
(int)Math.Round(led.Color.GPercent * 100),
|
||||
(int)Math.Round(led.Color.BPercent * 100));
|
||||
}
|
||||
|
||||
if (bitmap != null)
|
||||
_LogitechGSDK.LogiLedSetLightingFromBitmap(bitmap);
|
||||
}
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Logitech.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Logitech
|
||||
{
|
||||
public class LogitechPerKeyUpdateQueue : UpdateQueue
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
public LogitechPerKeyUpdateQueue(IUpdateTrigger updateTrigger)
|
||||
: base(updateTrigger)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
{
|
||||
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
|
||||
|
||||
byte[] bitmap = null;
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
{
|
||||
(LedId id, int customData) = ((LedId, int))data.Key;
|
||||
|
||||
// DarthAffe 26.03.2017: This is only needed since update by name doesn't work as expected for all keys ...
|
||||
if (BitmapMapping.BitmapOffset.TryGetValue(id, out int bitmapOffset))
|
||||
{
|
||||
if (bitmap == null)
|
||||
bitmap = BitmapMapping.CreateBitmap();
|
||||
|
||||
BitmapMapping.SetColor(ref bitmap, bitmapOffset, data.Value);
|
||||
}
|
||||
else
|
||||
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(customData,
|
||||
(int)Math.Round(data.Value.RPercent * 100),
|
||||
(int)Math.Round(data.Value.GPercent * 100),
|
||||
(int)Math.Round(data.Value.BPercent * 100));
|
||||
}
|
||||
|
||||
if (bitmap != null)
|
||||
_LogitechGSDK.LogiLedSetLightingFromBitmap(bitmap);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user