// ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global using System.Collections.Generic; using System.Linq; using RGB.NET.Core; namespace RGB.NET.Devices.WS281X.Arduino { // ReSharper disable once InconsistentNaming /// /// /// Represents an arduino WS2812 device. /// public class ArduinoWS2812USBDevice : AbstractRGBDevice, ILedStripe { #region Properties & Fields /// /// Gets the update queue performing updates for this device. /// public ArduinoWS2812USBUpdateQueue UpdateQueue { get; } /// public override ArduinoWS2812USBDeviceInfo DeviceInfo { get; } /// /// Gets the channel (as defined in the arduino-sketch) this device is attached to. /// public int Channel { 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. /// The channel (as defined in the arduino-sketch) this device is attached to. public ArduinoWS2812USBDevice(ArduinoWS2812USBDeviceInfo deviceInfo, ArduinoWS2812USBUpdateQueue updateQueue, int channel) { this.DeviceInfo = deviceInfo; this.UpdateQueue = updateQueue; this.Channel = channel; } #endregion #region Methods internal void Initialize(int ledCount) { for (int i = 0; i < ledCount; i++) AddLed(LedId.LedStripe1 + i, new Point(i * 10, 0), new Size(10, 10)); } /// protected override object GetLedCustomData(LedId ledId) => (Channel, (int)ledId - (int)LedId.LedStripe1); /// protected override IEnumerable GetLedsToUpdate(bool flushLeds) => (flushLeds || LedMapping.Values.Any(x => x.IsDirty)) ? LedMapping.Values : Enumerable.Empty(); /// 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 } }