/// <inheritdoc />
        protected override void Update(Dictionary <object, Color> dataSet)
        {
            _LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);

            Array.Clear(_bitmap, 0, _bitmap.Length);
            bool usesBitmap = false;

            foreach (KeyValuePair <object, Color> data in dataSet)
            {
                (LedId id, LogitechLedId customData) = ((LedId, LogitechLedId))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))
                {
                    BitmapMapping.SetColor(_bitmap, bitmapOffset, data.Value);
                    usesBitmap = true;
                }
                else
                {
                    _LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)customData,
                                                                      (int)Math.Round(data.Value.RPercent * 100),
                                                                      (int)Math.Round(data.Value.GPercent * 100),
                                                                      (int)Math.Round(data.Value.BPercent * 100));
                }
            }

            if (usesBitmap)
            {
                _LogitechGSDK.LogiLedSetLightingFromBitmap(_bitmap);
            }
        }
示例#2
0
        /// <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(((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);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="LogitechPerKeyUpdateQueue"/> class.
 /// </summary>
 /// <param name="updateTrigger">The update trigger used by this queue.</param>
 public LogitechPerKeyUpdateQueue(IDeviceUpdateTrigger updateTrigger)
     : base(updateTrigger)
 {
     _bitmap = BitmapMapping.CreateBitmap();
 }