Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LED strips using UDP (e.g. WLED) #2145

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Allow specifying port per ip
nzbr committed Jan 18, 2021
commit 77d644d5d26913466814cb702167da26c6160485
26 changes: 17 additions & 9 deletions Project-Aurora/Project-Aurora/Devices/UDP/UDPDevice.cs
Original file line number Diff line number Diff line change
@@ -21,21 +21,21 @@ public class UdpDevice : DefaultDevice
private List<IPEndPoint> endpoints;
private DeviceKeys deviceKey;
private int ledCount;
private int udpPort;

private Color lastColor;

protected override string DeviceInfo => string.Join(", ", ips);
private const int defaultPort = 19446;

protected override string DeviceInfo => string.Join(", ", endpoints.Select(endpoint => endpoint.ToString()));

protected override void RegisterVariables(VariableRegistry variableRegistry)
{
var devKeysEnumAsEnumerable = Enum.GetValues(typeof(DeviceKeys)).Cast<DeviceKeys>();

variableRegistry.Register($"{DeviceName}_devicekey", DeviceKeys.Peripheral, "Key Color to Use",
devKeysEnumAsEnumerable.Max(), devKeysEnumAsEnumerable.Min());
devKeysEnumAsEnumerable.Max(), devKeysEnumAsEnumerable.Min());
variableRegistry.Register($"{DeviceName}_led_count", 300, "LED Count");
variableRegistry.Register($"{DeviceName}_ip", "", "IP Adresses (Comma separated)");
variableRegistry.Register($"{DeviceName}_port", 19446, "UDP Port");
variableRegistry.Register($"{DeviceName}_ip", "", "Addresses (IP:port - Comma separated)");
}


@@ -45,8 +45,6 @@ public override bool Initialize()

deviceKey = Global.Configuration.VarRegistry.GetVariable<DeviceKeys>($"{DeviceName}_devicekey");
ledCount = Global.Configuration.VarRegistry.GetVariable<int>($"{DeviceName}_led_count");

udpPort = Global.Configuration.VarRegistry.GetVariable<int>($"{DeviceName}_port");
ips = Global.Configuration.VarRegistry.GetVariable<string>($"{DeviceName}_ip").Split(',');

if (ips.Length < 2 && ips[0] == "")
@@ -64,7 +62,16 @@ public override bool Initialize()
{
try
{
endpoints.Add(new IPEndPoint(IPAddress.Parse(ip), udpPort));
int udpPort = defaultPort;
var parts = ip.Split(':');
if (parts.Length > 1)
{
if (!int.TryParse(parts[1], out udpPort))
{
udpPort = defaultPort;
}
}
endpoints.Add(new IPEndPoint(IPAddress.Parse(parts[0]), udpPort));
}
catch (FormatException)
{
@@ -88,7 +95,8 @@ public override void Shutdown()
IsInitialized = false;
}

public override bool UpdateDevice(Dictionary<DeviceKeys, Color> keyColors, DoWorkEventArgs e, bool forced = false)
public override bool UpdateDevice(Dictionary<DeviceKeys, Color> keyColors, DoWorkEventArgs e,
bool forced = false)
{
if (!IsInitialized) return false;