// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.WS281X.Arduino;
// ReSharper disable once InconsistentNaming
///
///
/// Represents a definition of an arduino WS2812 devices.
///
public sealed class ArduinoWS281XDeviceDefinition : IWS281XDeviceDefinition
{
#region Properties & Fields
///
/// Gets the serial-connection used for the device.
///
public ISerialConnection SerialConnection { get; }
///
/// Gets the name of the serial-port to connect to.
///
public string Port => SerialConnection.Port;
///
/// Gets the baud-rate used by the serial-connection.
///
public int BaudRate => SerialConnection.BaudRate;
///
/// Gets or sets the name used by this device.
/// This allows to use {0} as a placeholder for a incrementing number if multiple devices are created.
///
public string? Name { get; set; }
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The serial connection used for the device.
public ArduinoWS281XDeviceDefinition(ISerialConnection serialConnection)
{
this.SerialConnection = serialConnection;
}
///
/// Initializes a new instance of the class.
///
/// The name of the serial-port to connect to.
/// The baud-rate of the serial-connection.
public ArduinoWS281XDeviceDefinition(string port, int baudRate = 115200)
{
SerialConnection = new SerialPortConnection(port, baudRate);
}
#endregion
#region Methods
///
public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger)
{
//TODO DarthAffe 04.03.2021: one queue per device
ArduinoWS2812USBUpdateQueue queue = new(updateTrigger, SerialConnection);
IEnumerable<(int channel, int ledCount)> channels = queue.GetChannels();
int counter = 0;
foreach ((int channel, int ledCount) in channels)
{
string name = string.Format(Name ?? $"Arduino WS2812 USB ({Port}) [{{0}}]", ++counter);
yield return new ArduinoWS2812USBDevice(new ArduinoWS2812USBDeviceInfo(name), queue, channel, ledCount);
}
}
#endregion
}