// 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
{
#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++)
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) => (Channel, (int)ledId - (int)LedId.LedStripe1);
///
protected override IEnumerable GetLedsToUpdate(bool flushLeds) => (flushLeds || LedMapping.Values.Any(x => x.IsDirty)) ? LedMapping.Values : null;
///
protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
#endregion
}
}