// 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 class ArduinoWS281XDeviceDefinition : IWS281XDeviceDefinition { #region Properties & Fields /// /// Gets the name of the serial-port to connect to. /// public string Port { get; } /// /// Gets the baud-rate used by the serial-connection. /// public int BaudRate { get; set; } = 115200; /// /// 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 name of the serial-port to connect to. public ArduinoWS281XDeviceDefinition(string port) { this.Port = port; } #endregion #region Methods /// public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger) { ArduinoWS2812USBUpdateQueue queue = new ArduinoWS2812USBUpdateQueue(updateTrigger, Port, BaudRate); 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); ArduinoWS2812USBDevice device = new ArduinoWS2812USBDevice(new ArduinoWS2812USBDeviceInfo(name), queue, channel); device.Initialize(ledCount); yield return device; } } #endregion } }