using System; using System.Collections.Generic; using System.Linq; using RGB.NET.Core; using RGB.NET.Devices.Logitech.Native; namespace RGB.NET.Devices.Logitech { /// /// /// Represents a logitech per-key-lightable device. /// public class LogitechPerKeyRGBDevice : LogitechRGBDevice { #region Properties & Fields /// /// Gets information about the . /// public LogitechRGBDeviceInfo PerKeyDeviceInfo { get; } #endregion #region Constructors /// /// /// Initializes a new instance of the class. /// /// The specific information provided by logitech for the per-key-lightable device internal LogitechPerKeyRGBDevice(LogitechRGBDeviceInfo info) : base(info) { this.PerKeyDeviceInfo = info; } #endregion #region Methods /// protected override void UpdateLeds(IEnumerable ledsToUpdate) { List 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(((LogitechLedId)led.Id).LedId, out int bitmapOffset)) { if (bitmap == null) bitmap = BitmapMapping.CreateBitmap(); BitmapMapping.SetColor(ref bitmap, bitmapOffset, led.Color); } else _LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)((LogitechLedId)led.Id).LedId, (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); } #endregion } }