using System.Collections.Generic; using System.Linq; using RGB.NET.Core; namespace RGB.NET.Devices.Razer { /// /// /// /// Represents a generic razer-device. (keyboard, mouse, headset, mousepad). /// public abstract class RazerRGBDevice : AbstractRGBDevice, IRazerRGBDevice where TDeviceInfo : RazerRGBDeviceInfo { #region Properties & Fields /// /// /// Gets information about the . /// public override TDeviceInfo DeviceInfo { get; } /// /// Gets or sets the update queue performing updates for this device. /// // ReSharper disable once MemberCanBePrivate.Global protected RazerUpdateQueue? UpdateQueue { get; set; } #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The generic information provided by razer for the device. protected RazerRGBDevice(TDeviceInfo info) { this.DeviceInfo = info; RequiresFlush = true; } #endregion #region Methods /// /// Initializes the device. /// public void Initialize(IDeviceUpdateTrigger updateTrigger) { InitializeLayout(); UpdateQueue = CreateUpdateQueue(updateTrigger); } /// /// Creates a specific for this device. /// /// The trigger used to update the queue. /// The for this device. protected abstract RazerUpdateQueue CreateUpdateQueue(IDeviceUpdateTrigger updateTrigger); /// /// Initializes the and of the device. /// protected abstract void InitializeLayout(); /// protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); /// /// Resets the device. /// public void Reset() => UpdateQueue?.Reset(); /// public override void Dispose() { try { UpdateQueue?.Dispose(); } catch { /* at least we tried */ } base.Dispose(); } #endregion } }