// 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 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 ?? 0;
///
/// Gets or sets the name used by this device.
///
public string Name { get; set; }
///
/// Gets or sets the amount of leds of this device.
///
public int StripLength { get; set; } = 384;
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The serial connection used for the device.
public BitwizardWS281XDeviceDefinition(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 BitwizardWS281XDeviceDefinition(string port, int baudRate = 115200)
{
SerialConnection = new SerialPortConnection(port, baudRate);
}
#endregion
#region Methods
///
public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger)
{
BitwizardWS2812USBUpdateQueue queue = new BitwizardWS2812USBUpdateQueue(updateTrigger, SerialConnection);
string name = Name ?? $"Bitwizard WS2812 USB ({Port})";
BitwizardWS2812USBDevice device = new BitwizardWS2812USBDevice(new BitwizardWS2812USBDeviceInfo(name), queue);
device.Initialize(StripLength);
yield return device;
}
#endregion
}
}