using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using RGB.NET.Core;
namespace RGB.NET.Devices.WS281X.NodeMCU
{
// ReSharper disable once InconsistentNaming
///
///
/// Represents the update-queue performing updates for NodeMCU WS2812 devices.
///
public class NodeMCUWS2812USBUpdateQueue : UpdateQueue
{
#region Properties & Fields
private readonly string _hostname;
private HttpClient _httpClient = new HttpClient();
private UdpClient _udpClient;
private readonly Dictionary _dataBuffer = new Dictionary();
private readonly Dictionary _sequenceNumbers = new Dictionary();
private readonly Action _sendDataAction;
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
/// If this constructor is used UDP updates are disabled.
///
/// The update trigger used by this queue.
/// The hostname to connect to.
public NodeMCUWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, string hostname)
: base(updateTrigger)
{
this._hostname = hostname;
_sendDataAction = SendHttp;
}
///
/// Initializes a new instance of the class.
/// If this constructor is used UDP updates are enabled.
///
/// The update trigger used by this queue.
/// The hostname to connect to.
/// The port used by the UDP-connection.
public NodeMCUWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, string hostname, int udpPort)
: base(updateTrigger)
{
this._hostname = hostname;
_udpClient = new UdpClient();
EnableUdp(udpPort);
_sendDataAction = SendUdp;
}
#endregion
#region Methods
///
protected override void OnStartup(object sender, CustomUpdateData customData)
{
base.OnStartup(sender, customData);
ResetDevice();
}
///
protected override void Update(Dictionary