예제 #1
0
        /// <summary>
        /// Performs an update for all dirty keys, or all keys if flushLeds is set to true.
        /// </summary>
        /// <param name="flushLeds">Specifies whether all keys (including clean ones) should be updated.</param>
        public void Update(bool flushLeds = false)
        {
            OnUpdating();

            // Update effects
            foreach (ILedGroup ledGroup in LedGroups)
            {
                ledGroup.UpdateEffects();
            }

            // Render brushes
            Render(this);
            foreach (ILedGroup ledGroup in LedGroups.OrderBy(x => x.ZIndex))
            {
                Render(ledGroup);
            }

            // Device-specific updates
            DeviceUpdate();

            // Send LEDs to SDK
            ICollection <LedUpateRequest> ledsToUpdate = (flushLeds ? LedMapping : LedMapping.Where(x => x.Value.IsDirty)).Select(x => new LedUpateRequest(x.Key, x.Value.RequestedColor)).ToList();

            foreach (LedUpateRequest updateRequest in ledsToUpdate)
            {
                LedMapping[updateRequest.LedId].Update();
            }

            UpdateLeds(ledsToUpdate);

            OnUpdated();
        }
예제 #2
0
 /// <summary>
 /// Gets the <see cref="CorsairLed" /> with the specified ID.
 /// </summary>
 /// <param name="ledId">The ID of the LED to get.</param>
 /// <returns>The LED with the specified ID or null if no LED is found.</returns>
 public CorsairLed this[CorsairLedId ledId]
 {
     get
     {
         CorsairLed key;
         return(LedMapping.TryGetValue(ledId, out key) ? key : null);
     }
 }
예제 #3
0
 /// <summary>
 /// Gets the <see cref="CorsairLed" /> representing the given character by calling the SDK-method 'CorsairGetLedIdForKeyName'.<br />
 /// Note that this currently only works for letters.
 /// </summary>
 /// <param name="key">The character of the key.</param>
 /// <returns>The led representing the given character or null if no led is found.</returns>
 public CorsairLed this[char key]
 {
     get
     {
         CorsairLedId ledId = _CUESDK.CorsairGetLedIdForKeyName(key);
         CorsairLed   led;
         return(LedMapping.TryGetValue(ledId, out led) ? led : null);
     }
 }
예제 #4
0
        /// <summary>
        /// Initializes the LED-Object with the specified id.
        /// </summary>
        /// <param name="ledId">The LED-Id to initialize.</param>
        /// <param name="ledRectangle">The rectangle representing the position of the LED to initialize.</param>
        /// <returns></returns>
        protected CorsairLed InitializeLed(CorsairLedId ledId, RectangleF ledRectangle)
        {
            if (LedMapping.ContainsKey(ledId))
            {
                return(null);
            }

            CorsairLed led = new CorsairLed(this, ledId, ledRectangle);

            LedMapping.Add(ledId, led);
            return(led);
        }
예제 #5
0
        /// <inheritdoc />
        public override void SyncBack()
        {
            lock (_syncbackCache)
            {
                foreach (KeyValuePair <LedId, Color> cacheEntry in _syncbackCache)
                {
                    LedId ledId = cacheEntry.Key;
                    Color color = cacheEntry.Value;

                    if (!LedMapping.TryGetValue(ledId, out Led led))
                    {
                        led = InitializeLed(cacheEntry.Key, new Rectangle(0, 0, 10, 10)); //TODO DarthAffe 10.06.2018: Send layout with initial package
                    }
                    SetLedColorWithoutRequest(led, color);
                }

                _syncbackCache.Clear();
            }
        }
예제 #6
0
        /// <summary>
        /// Applies the given layout.
        /// </summary>
        /// <param name="layoutPath">The file containing the layout.</param>
        /// <param name="imageLayout">The name of the layout used to get the images of the leds.</param>
        /// <param name="imageBasePath">The path images for this device are collected in.</param>
        protected void ApplyLayoutFromFile(string layoutPath, string imageLayout, string imageBasePath)
        {
            DeviceLayout layout = DeviceLayout.Load(layoutPath);

            if (layout != null)
            {
                LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));

                InternalSize = new Size(layout.Width, layout.Height);

                if (layout.Leds != null)
                {
                    foreach (LedLayout layoutLed in layout.Leds)
                    {
                        if (Enum.TryParse(layoutLed.Id, true, out LogitechLedIds ledId))
                        {
                            LogitechLedId id = new LogitechLedId(this, ledId);
                            if (!LedMapping.TryGetValue(id, out Led led))
                            {
                                led = InitializeLed(id, new Rectangle());
                            }

                            led.LedRectangle.Location.X  = layoutLed.X;
                            led.LedRectangle.Location.Y  = layoutLed.Y;
                            led.LedRectangle.Size.Width  = layoutLed.Width;
                            led.LedRectangle.Size.Height = layoutLed.Height;

                            led.Shape     = layoutLed.Shape;
                            led.ShapeData = layoutLed.ShapeData;

                            LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id);
                            led.Image = (!string.IsNullOrEmpty(image?.Image))
                                ? new Uri(Path.Combine(imageBasePath, image.Image), UriKind.Absolute)
                                : new Uri(Path.Combine(imageBasePath, "Missing.png"), UriKind.Absolute);
                        }
                    }
                }
            }
        }