diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUUpdateMode.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUUpdateMode.cs
new file mode 100644
index 0000000..f20bd8e
--- /dev/null
+++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUUpdateMode.cs
@@ -0,0 +1,21 @@
+namespace RGB.NET.Devices.WS281X.NodeMCU
+{
+ ///
+ /// Contaisn a list of possible update-modes for NodeMCU-devices.
+ ///
+ // ReSharper disable once InconsistentNaming
+ public enum NodeMCUUpdateMode
+ {
+ ///
+ /// Updates through the HTTP-REST-API.
+ /// Slow, but reliable.
+ ///
+ Http,
+
+ ///
+ /// Updates through a UDP-connection.
+ /// Fast, but might skip updates if the network connection is bad.
+ ///
+ Udp
+ }
+}
diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs
index cb4424e..f5feffe 100644
--- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs
+++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs
@@ -1,7 +1,10 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Linq;
-using System.Net;
+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
@@ -13,94 +16,169 @@ namespace RGB.NET.Devices.WS281X.NodeMCU
///
public class NodeMCUWS2812USBUpdateQueue : UpdateQueue
{
- #region Constants
-
- private static readonly byte UPDATE_COMMAND = 0x02;
-
- #endregion
-
#region Properties & Fields
private readonly string _hostname;
- private readonly UdpClient _udpClient;
+ 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.
- /// The port used by the web-connection.
- public NodeMCUWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, string hostname, int port)
+ public NodeMCUWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, string hostname)
: base(updateTrigger)
{
this._hostname = hostname;
- _udpClient = new UdpClient(_hostname, port);
- _udpClient.Connect(_hostname, port);
+ _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