Logitech - Use LogiLedSetLightingForKeyWithKeyName for per key devices

This commit is contained in:
Robert committed 2021-04-14 23:27:49 +02:00
1 parent f8d007b7cd
commit 9343d6ee29
6 files changed
+261 -177

No files matched your search

@@ -1,30 +0,0 @@
using System.Runtime.CompilerServices;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
{
internal static class BitmapMapping
{
#region Constants
private const int BITMAP_SIZE = 21 * 6 * 4;
#endregion
#region Methods
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static byte[] CreateBitmap() => new byte[BITMAP_SIZE];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void SetColor(byte[] bitmap, int offset, Color color)
{
bitmap[offset] = color.GetB();
bitmap[offset + 1] = color.GetG();
bitmap[offset + 2] = color.GetR();
bitmap[offset + 3] = color.GetA();
}
#endregion
}
}
@@ -11,7 +11,7 @@ namespace RGB.NET.Devices.Logitech
{
#region Properties & Fields
private readonly LedMapping<int> _ledMapping;
private readonly LedMapping<LogitechLedId> _ledMapping;
#endregion
@@ -21,7 +21,7 @@ namespace RGB.NET.Devices.Logitech
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechPerKeyRGBDevice" /> class.
/// </summary>
internal LogitechPerKeyRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue, LedMapping<int> ledMapping)
internal LogitechPerKeyRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue, LedMapping<LogitechLedId> ledMapping)
: base(info, updateQueue)
{
this._ledMapping = ledMapping;
@@ -32,7 +32,7 @@ namespace RGB.NET.Devices.Logitech
#region Methods
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => _ledMapping.TryGetValue(ledId, out int logitechLedId) ? logitechLedId : -1;
protected override object GetLedCustomData(LedId ledId) => _ledMapping.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : -1;
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate));
@@ -9,12 +9,6 @@ namespace RGB.NET.Devices.Logitech
/// </summary>
public class LogitechPerKeyUpdateQueue : UpdateQueue
{
#region Properties & Fields
private readonly byte[] _bitmap;
#endregion
#region Constructors
/// <summary>
@@ -24,7 +18,6 @@ namespace RGB.NET.Devices.Logitech
public LogitechPerKeyUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{
_bitmap = BitmapMapping.CreateBitmap();
}
#endregion
@@ -36,15 +29,15 @@ namespace RGB.NET.Devices.Logitech
{
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
Array.Clear(_bitmap, 0, _bitmap.Length);
foreach ((object key, Color color) in dataSet)
{
int offset = key as int? ?? -1;
if (offset >= 0)
BitmapMapping.SetColor(_bitmap, offset, color);
// These will be LogitechLedId but the SDK expects an int and doesn't care about invalid values
int keyName = (int)key;
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(keyName,
(int)MathF.Round(color.R * 100),
(int)MathF.Round(color.G * 100),
(int)MathF.Round(color.B * 100));
}
_LogitechGSDK.LogiLedSetLightingFromBitmap(_bitmap);
}
#endregion