// 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.NodeMCU { // ReSharper disable once InconsistentNaming /// /// /// Represents a definition of an NodeMCU WS2812 devices. /// public class NodeMCUWS281XDeviceDefinition : IWS281XDeviceDefinition { #region Properties & Fields /// /// Gets the hostname to connect to. /// public string Hostname { get; } /// /// Gets the port of the UDP connection. /// public int Port { get; } /// /// 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 hostname to connect to. /// The port of the UDP connection. public NodeMCUWS281XDeviceDefinition(string hostname, int port = 1872) { this.Hostname = hostname; this.Port = port; } #endregion #region Methods /// public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger) { NodeMCUWS2812USBUpdateQueue queue = new NodeMCUWS2812USBUpdateQueue(updateTrigger, Hostname, Port); IEnumerable<(int channel, int ledCount)> channels = queue.GetChannels(); int counter = 0; foreach ((int channel, int ledCount) in channels) { string name = string.Format(Name ?? $"NodeMCU WS2812 WIFI ({Hostname}) [{{0}}]", ++counter); NodeMCUWS2812USBDevice device = new NodeMCUWS2812USBDevice(new NodeMCUWS2812USBDeviceInfo(name), queue, channel); device.Initialize(ledCount); yield return device; } } #endregion } }