Update logitech integration to make use of the new zone-system in the latest logitech SDK

This commit is contained in:
DarthAffe committed 2018-07-15 17:06:59 +02:00
1 parent c056aa7444
commit 0412058e6a
9 files changed
+246 -31

No files matched your search

@@ -0,0 +1,66 @@
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
{
/// <inheritdoc />
/// <summary>
/// Represents a logitech zone-lightable device.
/// </summary>
public class LogitechZoneRGBDevice : LogitechRGBDevice<LogitechRGBDeviceInfo>
{
#region Constants
private static readonly Dictionary<RGBDeviceType, LedId> BASE_LED_MAPPING = new Dictionary<RGBDeviceType, LedId>
{
{RGBDeviceType.Keyboard, LedId.Keyboard_Programmable1},
{RGBDeviceType.Mouse, LedId.Mouse1},
{RGBDeviceType.Headset, LedId.Headset1},
{RGBDeviceType.Mousepad, LedId.Mousepad1},
{RGBDeviceType.Speaker, LedId.Speaker1}
};
#endregion
#region Properties & Fields
private LedId _baseLedId;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechZoneRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by logitech for the zone-lightable device</param>
internal LogitechZoneRGBDevice(LogitechRGBDeviceInfo info)
: base(info)
{
_baseLedId = BASE_LED_MAPPING.TryGetValue(info.DeviceType, out LedId id) ? id : LedId.Custom1;
}
#endregion
#region Methods
/// <inheritdoc />
protected override void InitializeLayout()
{
for (int i = 0; i < DeviceInfo.Zones; i++)
InitializeLed(_baseLedId + i, new Rectangle(i * 10, 0, 10, 10));
base.InitializeLayout();
}
/// <inheritdoc />
protected override object CreateLedCustomData(LedId ledId) => (int)(ledId - _baseLedId);
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
#endregion
}
}
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.Native;
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Represents the update-queue performing updates for logitech zone devices.
/// </summary>
public class LogitechZoneUpdateQueue : UpdateQueue
{
#region Constants
private static readonly Dictionary<RGBDeviceType, LogitechDeviceType> DEVICE_TYPE_MAPPING = new Dictionary<RGBDeviceType, LogitechDeviceType>
{
{RGBDeviceType.Keyboard, LogitechDeviceType.Keyboard},
{RGBDeviceType.Mouse, LogitechDeviceType.Mouse},
{RGBDeviceType.Headset, LogitechDeviceType.Headset},
{RGBDeviceType.Mousepad, LogitechDeviceType.Mousemat},
{RGBDeviceType.Speaker, LogitechDeviceType.Speaker}
};
#endregion
#region Properties & Fields
private readonly LogitechDeviceType _deviceType;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="LogitechZoneUpdateQueue"/> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
/// <param name="deviceType">The tpye of the device this queue is updating.</param>
public LogitechZoneUpdateQueue(IDeviceUpdateTrigger updateTrigger, RGBDeviceType deviceType)
: base(updateTrigger)
{
if (!DEVICE_TYPE_MAPPING.TryGetValue(deviceType, out _deviceType))
throw new ArgumentException($"Invalid type '{deviceType.ToString()}'", nameof(deviceType));
}
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet)
{
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.All);
foreach (KeyValuePair<object, Color> data in dataSet)
{
int zone = (int)data.Key;
_LogitechGSDK.LogiLedSetLightingForTargetZone(_deviceType, zone,
(int)Math.Round(data.Value.RPercent * 100),
(int)Math.Round(data.Value.GPercent * 100),
(int)Math.Round(data.Value.BPercent * 100));
}
}
#endregion
}
}