// ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global using System.Collections.Generic; using System.Linq; using RGB.NET.Core; namespace RGB.NET.Devices.WS281X.Bitwizard { // ReSharper disable once InconsistentNaming /// /// /// Represents an bitwizard WS2812 USB device. /// public class BitwizardWS2812USBDevice : AbstractRGBDevice, ILedStripe { #region Properties & Fields /// /// Gets the update queue performing updates for this device. /// public BitwizardWS2812USBUpdateQueue UpdateQueue { get; } /// public override BitwizardWS2812USBDeviceInfo DeviceInfo { get; } #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The update trigger used by this queue. /// The update queue performing updates for this device. public BitwizardWS2812USBDevice(BitwizardWS2812USBDeviceInfo deviceInfo, BitwizardWS2812USBUpdateQueue updateQueue) { this.DeviceInfo = deviceInfo; this.UpdateQueue = updateQueue; } #endregion #region Methods internal void Initialize(int ledCount) { for (int i = 0; i < ledCount; i++) InitializeLed(LedId.LedStripe1 + i, new Rectangle(i * 10, 0, 10, 10)); //TODO DarthAffe 23.12.2018: Allow to load a layout. if (Size == Size.Invalid) { Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle)); Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y); } } /// protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.LedStripe1; /// protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); /// public override void Dispose() { try { UpdateQueue?.Dispose(); } catch { /* at least we tried */ } base.Dispose(); } #endregion } }