// 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.Bitwizard; // ReSharper disable once InconsistentNaming /// /// /// Represents a definition of an bitwizard WS2812 devices. /// public sealed class BitwizardWS281XDeviceDefinition : 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. /// public string? Name { get; set; } /// /// Gets a list of LED-strips configured on this device. /// public List<(int pin, int stripLength)> Strips { get; } = []; /// /// Gets or sets the amount of leds controlled by one pin. /// This only needs to be changed if the firmware on the controller is updated. /// public int MaxStripLength { get; set; } = 384; #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The serial connection used for the device. /// A list of LED-strips connected to this device. public BitwizardWS281XDeviceDefinition(ISerialConnection serialConnection, params (int pin, int stripLength)[] strips) { this.SerialConnection = serialConnection; Strips.AddRange(strips); } /// /// Initializes a new instance of the class. /// /// The name of the serial-port to connect to. /// The baud-rate of the serial-connection. /// A list of LED-strips connected to this device. public BitwizardWS281XDeviceDefinition(string port, int baudRate = 115200, params (int pin, int stripLength)[] strips) { SerialConnection = new SerialPortConnection(port, baudRate); Strips.AddRange(strips); } #endregion #region Methods /// public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger) { foreach ((int pin, int stripLength) in Strips) { BitwizardWS2812USBUpdateQueue queue = new(updateTrigger, SerialConnection); string name = Name ?? $"Bitwizard WS2812 USB ({Port}) Pin {pin}"; int ledOffset = pin * MaxStripLength; yield return new BitwizardWS2812USBDevice(new BitwizardWS2812USBDeviceInfo(name), queue, ledOffset, stripLength); } } #endregion }