mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Added a device-provider for DMX devices (currently only E1.31 [sACN] is implemented)
This commit is contained in:
parent
009858b5e7
commit
f323f6206d
28
NuGet/RGB.NET.Devices.DMX.nuspec
Normal file
28
NuGet/RGB.NET.Devices.DMX.nuspec
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>RGB.NET.Devices.DMX</id>
|
||||
<title>RGB.NET.Devices.DMX</title>
|
||||
<version>0.0.1</version>
|
||||
<authors>Darth Affe</authors>
|
||||
<owners>Darth Affe</owners>
|
||||
<projectUrl>https://github.com/DarthAffe/RGB.NET</projectUrl>
|
||||
<licenseUrl>https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE</licenseUrl>
|
||||
<requireLicenseAcceptance>true</requireLicenseAcceptance>
|
||||
<description>DMX-Device-Implementations of RGB.NET</description>
|
||||
<releaseNotes></releaseNotes>
|
||||
<summary>DMX-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals</summary>
|
||||
<copyright>Copyright © Wyrez 2018</copyright>
|
||||
<language>en-US</language>
|
||||
<dependencies>
|
||||
<dependency id="RGB.NET.Core" version="0.0.1" />
|
||||
<dependency id="System.ValueTuple" version="4.4.0" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="..\bin\RGB.NET.Devices.DMX.dll" target="lib\net45\RGB.NET.Devices.DMX.dll" />
|
||||
<file src="..\bin\RGB.NET.Devices.DMX.pdb" target="lib\net45\RGB.NET.Devices.DMX.pdb" />
|
||||
<file src="..\bin\RGB.NET.Devices.DMX.xml" target="lib\net45\RGB.NET.Devices.DMX.xml" />
|
||||
<file src="..\RGB.NET.Devices.DMX\**\*.cs" target="src" exclude="..\RGB.NET.Devices.DMX\obj\**\*.*" />
|
||||
</files>
|
||||
</package>
|
||||
112
RGB.NET.Devices.DMX/DMXDeviceProvider.cs
Normal file
112
RGB.NET.Devices.DMX/DMXDeviceProvider.cs
Normal file
@ -0,0 +1,112 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.DMX.E131;
|
||||
|
||||
namespace RGB.NET.Devices.DMX
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a device provider responsible for DMX devices.
|
||||
/// </summary>
|
||||
public class DMXDeviceProvider : IRGBDeviceProvider
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private static DMXDeviceProvider _instance;
|
||||
/// <summary>
|
||||
/// Gets the singleton <see cref="DMXDeviceProvider"/> instance.
|
||||
/// </summary>
|
||||
public static DMXDeviceProvider Instance => _instance ?? new DMXDeviceProvider();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsInitialized { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IRGBDevice> Devices { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasExclusiveAccess => false;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all defined device-definitions.
|
||||
/// </summary>
|
||||
public List<IDMXDeviceDefinition> DeviceDefinitions { get; } = new List<IDMXDeviceDefinition>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DMXDeviceProvider"/> class.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
|
||||
public DMXDeviceProvider()
|
||||
{
|
||||
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(DMXDeviceProvider)}");
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given <see cref="IDMXDeviceDefinition" /> to this device-provider.
|
||||
/// </summary>
|
||||
/// <param name="deviceDefinition">The <see cref="IDMXDeviceDefinition"/> to add.</param>
|
||||
public void AddDeviceDefinition(IDMXDeviceDefinition deviceDefinition) => DeviceDefinitions.Add(deviceDefinition);
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
|
||||
{
|
||||
IsInitialized = false;
|
||||
|
||||
try
|
||||
{
|
||||
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
||||
|
||||
foreach (IDMXDeviceDefinition dmxDeviceDefinition in DeviceDefinitions)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dmxDeviceDefinition is E131DMXDeviceDefinition e131DMXDeviceDefinition)
|
||||
{
|
||||
if (e131DMXDeviceDefinition.Leds.Count > 0)
|
||||
{
|
||||
E131Device device = new E131Device(new E131DeviceInfo(e131DMXDeviceDefinition), e131DMXDeviceDefinition.Leds);
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
}
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||
IsInitialized = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions) throw;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ResetDevices()
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
24
RGB.NET.Devices.DMX/DMXDeviceProviderLoader.cs
Normal file
24
RGB.NET.Devices.DMX/DMXDeviceProviderLoader.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.DMX
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a device provider loaded used to dynamically load DMX devices into an application.
|
||||
/// </summary>
|
||||
public class DMXDeviceProviderLoader : IRGBDeviceProviderLoader<DMXDeviceProviderLoader>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool RequiresInitialization => true;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public IRGBDeviceProvider GetDeviceProvider() => DMXDeviceProvider.Instance;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
92
RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs
Normal file
92
RGB.NET.Devices.DMX/E131/E131DMXDeviceDefinition.cs
Normal file
@ -0,0 +1,92 @@
|
||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.DMX.E131
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the data used to create a E1.31 DMX-device.
|
||||
/// </summary>
|
||||
public class E131DMXDeviceDefinition : IDMXDeviceDefinition
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the hostname of the device.
|
||||
/// </summary>
|
||||
public string Hostname { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the port to device is listening to.
|
||||
/// </summary>
|
||||
public int Port { get; set; } = 5568;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="RGBDeviceType" /> of the device.
|
||||
/// </summary>
|
||||
public RGBDeviceType DeviceType { get; set; } = RGBDeviceType.Unknown;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the manufacturer of the device.
|
||||
/// </summary>
|
||||
public string Manufacturer { get; set; } = "Unknown";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the model name of the device.
|
||||
/// </summary>
|
||||
public string Model { get; set; } = "Generic DMX-Device";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the CID of the device (null will generate a random CID)
|
||||
/// </summary>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public byte[] CID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the universe the device belongs to.
|
||||
/// </summary>
|
||||
public short Universe { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the led-mappings used to create the device.
|
||||
/// </summary>
|
||||
public Dictionary<LedId, List<(int channel, Func<Color, byte> getValueFunc)>> Leds { get; } = new Dictionary<LedId, List<(int channel, Func<Color, byte> getValueFunc)>>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="hostname"></param>
|
||||
public E131DMXDeviceDefinition(string hostname)
|
||||
{
|
||||
this.Hostname = hostname;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds a led-mapping to the device.
|
||||
/// </summary>
|
||||
/// <param name="id">The <see cref="LedId" /> used to identify the led.</param>
|
||||
/// <param name="channels">The channels the led is using and a function mapping parts of the color to them.</param>
|
||||
public void AddLed(LedId id, params (int channel, Func<Color, byte> getValueFunc)[] channels) => Leds[id] = channels.ToList();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Factory
|
||||
|
||||
//TODO DarthAffe 18.02.2018: Add factory-methods.
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
25
RGB.NET.Devices.DMX/E131/E131DataPacketExtension.cs
Normal file
25
RGB.NET.Devices.DMX/E131/E131DataPacketExtension.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace RGB.NET.Devices.DMX.E131
|
||||
{
|
||||
internal static class E131DataPacketExtension
|
||||
{
|
||||
#region Methods
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
internal static void SetCID(this byte[] data, byte[] cid) => Array.Copy(cid, 0, data, 22, 16);
|
||||
|
||||
internal static void SetSequenceNumber(this byte[] data, byte sequenceNumber) => data[111] = sequenceNumber;
|
||||
|
||||
internal static void SetUniverse(this byte[] data, short universe) => Array.Copy(ToBigEndian(BitConverter.GetBytes(universe)), 0, data, 113, 2);
|
||||
|
||||
internal static void ClearColors(this byte[] data) => Array.Clear(data, 126, 512);
|
||||
|
||||
internal static void SetChannel(this byte[] data, int channel, byte value) => data[126 + channel] = value;
|
||||
|
||||
private static byte[] ToBigEndian(byte[] data) => BitConverter.IsLittleEndian ? data.Reverse().ToArray() : data;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
112
RGB.NET.Devices.DMX/E131/E131Device.cs
Normal file
112
RGB.NET.Devices.DMX/E131/E131Device.cs
Normal file
@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.DMX.E131
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a E1.31-DXM-device.
|
||||
/// </summary>
|
||||
public class E131Device : AbstractRGBDevice<E131DeviceInfo>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UDP-Connection used to send data.
|
||||
/// </summary>
|
||||
private UdpClient _socket;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the byte-representation of a E1.31 packet as described in http://tsp.esta.org/tsp/documents/docs/E1-31-2016.pdf.
|
||||
/// CID, SequenceNumber, Universe and PropertyValues needs to be updated before use!
|
||||
/// </summary>
|
||||
private byte[] _dataPacket = { 0x00, 0x10, 0x00, 0x00, 0x41, 0x53, 0x43, 0x2D, 0x45, 0x31, 0x2E, 0x31, 0x37, 0x00, 0x00, 0x00, 0x72, 0x6E, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x58, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x72, 0x0B, 0x02, 0xA1, 0x00, 0x00, 0x00, 0x01, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Sequence number used to detect the order in which packages where sent.
|
||||
/// </summary>
|
||||
private byte _sequenceNumber = 0;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override E131DeviceInfo DeviceInfo { get; }
|
||||
|
||||
private readonly Dictionary<LedId, List<(int channel, Func<Color, byte> getValueFunc)>> _ledMappings;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
internal E131Device(E131DeviceInfo deviceInfo, Dictionary<LedId, List<(int channel, Func<Color, byte> getValueFunc)>> ledMappings)
|
||||
{
|
||||
this.DeviceInfo = deviceInfo;
|
||||
this._ledMappings = ledMappings;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
internal void Initialize()
|
||||
{
|
||||
int count = 0;
|
||||
foreach (LedId id in _ledMappings.Keys)
|
||||
InitializeLed(id, new Rectangle((count++) * 10, 0, 10, 10));
|
||||
|
||||
_socket = new UdpClient();
|
||||
_socket.Connect(DeviceInfo.Hostname, DeviceInfo.Port);
|
||||
|
||||
_dataPacket.SetCID(DeviceInfo.CID);
|
||||
_dataPacket.SetUniverse(DeviceInfo.Universe);
|
||||
|
||||
//TODO DarthAffe 18.02.2018: Allow to load a layout.
|
||||
|
||||
if (Size == Size.Invalid)
|
||||
{
|
||||
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
|
||||
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override object CreateLedCustomData(LedId ledId) => new LedChannelMapping(_ledMappings[ledId]);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
||||
{
|
||||
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
|
||||
if (leds.Count > 0)
|
||||
{
|
||||
_dataPacket.SetSequenceNumber(GetNextSequenceNumber());
|
||||
|
||||
foreach (Led led in leds)
|
||||
{
|
||||
LedChannelMapping mapping = (LedChannelMapping)led.CustomData;
|
||||
foreach ((int channel, Func<Color, byte> getValue) in mapping)
|
||||
_dataPacket.SetChannel(channel, getValue(led.Color));
|
||||
}
|
||||
|
||||
_socket.Send(_dataPacket, _dataPacket.Length);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increments the sequence number and wraps it if neded.
|
||||
/// </summary>
|
||||
/// <returns>The next usable sequence number.</returns>
|
||||
private byte GetNextSequenceNumber()
|
||||
{
|
||||
if (_sequenceNumber == byte.MaxValue)
|
||||
{
|
||||
_sequenceNumber = byte.MinValue;
|
||||
return byte.MaxValue;
|
||||
}
|
||||
|
||||
return _sequenceNumber++;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
85
RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs
Normal file
85
RGB.NET.Devices.DMX/E131/E131DeviceInfo.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.DMX.E131
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents device information for a <see cref="E131Device"/> />.
|
||||
/// </summary>
|
||||
public class E131DeviceInfo : IRGBDeviceInfo
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// The length of the CID;
|
||||
/// </summary>
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public const int CID_LENGTH = 16;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceType DeviceType { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Manufacturer { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Model { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceLighting Lighting => RGBDeviceLighting.Key;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SupportsSyncBack => false;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Uri Image { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The hostname of the device.
|
||||
/// </summary>
|
||||
public string Hostname { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The port of the device.
|
||||
/// </summary>
|
||||
public int Port { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The CID used to identify against the device.
|
||||
/// </summary>
|
||||
public byte[] CID { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The Universe this device belongs to.
|
||||
/// </summary>
|
||||
public short Universe { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
internal E131DeviceInfo(E131DMXDeviceDefinition deviceDefinition)
|
||||
{
|
||||
this.DeviceType = deviceDefinition.DeviceType;
|
||||
this.Manufacturer = deviceDefinition.Manufacturer;
|
||||
this.Model = deviceDefinition.Model;
|
||||
this.Hostname = deviceDefinition.Hostname;
|
||||
this.Port = deviceDefinition.Port;
|
||||
this.CID = deviceDefinition.CID;
|
||||
this.Universe = deviceDefinition.Universe;
|
||||
|
||||
if ((CID == null) || (CID.Length != CID_LENGTH))
|
||||
{
|
||||
CID = new byte[CID_LENGTH];
|
||||
new Random().NextBytes(CID);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
8
RGB.NET.Devices.DMX/Generic/IDMXDeviceDefinition.cs
Normal file
8
RGB.NET.Devices.DMX/Generic/IDMXDeviceDefinition.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace RGB.NET.Devices.DMX
|
||||
{
|
||||
/// <summary>
|
||||
/// Marker interface for DMX device definitions.
|
||||
/// </summary>
|
||||
public interface IDMXDeviceDefinition
|
||||
{ }
|
||||
}
|
||||
32
RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs
Normal file
32
RGB.NET.Devices.DMX/Generic/LedChannelMapping.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.DMX
|
||||
{
|
||||
internal class LedChannelMapping : IEnumerable<(int channel, Func<Color, byte> getValue)>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly List<(int channel, Func<Color, byte> getValue)> _mappings;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public LedChannelMapping(List<(int channel, Func<Color, byte> getValue)> mappings)
|
||||
{
|
||||
this._mappings = new List<(int channel, Func<Color, byte> getValue)>(mappings);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public IEnumerator<(int channel, Func<Color, byte> getValue)> GetEnumerator() => _mappings.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
35
RGB.NET.Devices.DMX/Properties/AssemblyInfo.cs
Normal file
35
RGB.NET.Devices.DMX/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("RGB.NET.Devices.DMX")]
|
||||
[assembly: AssemblyDescription("DMX-Device-Implementations of RGB.NET")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Wyrez")]
|
||||
[assembly: AssemblyProduct("RGB.NET.Devices.DMX")]
|
||||
[assembly: AssemblyCopyright("Copyright © Wyrez 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("725abfa2-b360-4d3a-82d5-1ac502f5e10f")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
69
RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj
Normal file
69
RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj
Normal file
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{725ABFA2-B360-4D3A-82D5-1AC502F5E10F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>RGB.NET.Devices.DMX</RootNamespace>
|
||||
<AssemblyName>RGB.NET.Devices.DMX</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>..\bin\RGB.NET.Devices.DMX.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>..\bin\RGB.NET.Devices.DMX.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DMXDeviceProviderLoader.cs" />
|
||||
<Compile Include="DMXDeviceProvider.cs" />
|
||||
<Compile Include="E131\E131DataPacketExtension.cs" />
|
||||
<Compile Include="E131\E131Device.cs" />
|
||||
<Compile Include="E131\E131DeviceInfo.cs" />
|
||||
<Compile Include="E131\E131DMXDeviceDefinition.cs" />
|
||||
<Compile Include="Generic\IDMXDeviceDefinition.cs" />
|
||||
<Compile Include="Generic\LedChannelMapping.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj">
|
||||
<Project>{5a4f9a75-75fe-47cd-90e5-914d5b20d232}</Project>
|
||||
<Name>RGB.NET.Core</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@ -0,0 +1,2 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generic/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
4
RGB.NET.Devices.DMX/packages.config
Normal file
4
RGB.NET.Devices.DMX/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
|
||||
</packages>
|
||||
10
RGB.NET.sln
10
RGB.NET.sln
@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27130.2024
|
||||
VisualStudioVersion = 15.0.27130.2027
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RGB.NET.Core", "RGB.NET.Core\RGB.NET.Core.csproj", "{5A4F9A75-75FE-47CD-90E5-914D5B20D232}"
|
||||
EndProject
|
||||
@ -32,6 +32,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{06416566
|
||||
NuGet\RGB.NET.Devices.CoolerMaster.nuspec = NuGet\RGB.NET.Devices.CoolerMaster.nuspec
|
||||
NuGet\RGB.NET.Devices.Corsair.nuspec = NuGet\RGB.NET.Devices.Corsair.nuspec
|
||||
NuGet\RGB.NET.Devices.Debug.nuspec = NuGet\RGB.NET.Devices.Debug.nuspec
|
||||
NuGet\RGB.NET.Devices.DMX.nuspec = NuGet\RGB.NET.Devices.DMX.nuspec
|
||||
NuGet\RGB.NET.Devices.Logitech.nuspec = NuGet\RGB.NET.Devices.Logitech.nuspec
|
||||
NuGet\RGB.NET.Devices.Msi.nuspec = NuGet\RGB.NET.Devices.Msi.nuspec
|
||||
NuGet\RGB.NET.Devices.Novation.nuspec = NuGet\RGB.NET.Devices.Novation.nuspec
|
||||
@ -70,6 +71,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RGB.NET.Devices.Debug", "RG
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RGB.NET.Devices.Roccat", "RGB.NET.Devices.Roccat\RGB.NET.Devices.Roccat.csproj", "{01803E4A-36B8-4675-AFB3-7C8968AC4A13}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RGB.NET.Devices.DMX", "RGB.NET.Devices.DMX\RGB.NET.Devices.DMX.csproj", "{725ABFA2-B360-4D3A-82D5-1AC502F5E10F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -136,6 +139,10 @@ Global
|
||||
{01803E4A-36B8-4675-AFB3-7C8968AC4A13}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{01803E4A-36B8-4675-AFB3-7C8968AC4A13}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{01803E4A-36B8-4675-AFB3-7C8968AC4A13}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{725ABFA2-B360-4D3A-82D5-1AC502F5E10F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{725ABFA2-B360-4D3A-82D5-1AC502F5E10F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{725ABFA2-B360-4D3A-82D5-1AC502F5E10F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{725ABFA2-B360-4D3A-82D5-1AC502F5E10F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -156,6 +163,7 @@ Global
|
||||
{24FF4ACB-D679-4B2D-86D4-50AB6C02D816} = {33D5E279-1C4E-4AB6-9D1E-6D18109A6C25}
|
||||
{D013040E-1931-4F0D-9CCA-0F4AE74A507E} = {33D5E279-1C4E-4AB6-9D1E-6D18109A6C25}
|
||||
{01803E4A-36B8-4675-AFB3-7C8968AC4A13} = {33D5E279-1C4E-4AB6-9D1E-6D18109A6C25}
|
||||
{725ABFA2-B360-4D3A-82D5-1AC502F5E10F} = {33D5E279-1C4E-4AB6-9D1E-6D18109A6C25}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {CDECA6C7-8D18-4AF3-94F7-C70A69B8571B}
|
||||
|
||||
@ -265,6 +265,7 @@
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CUESDK/@EntryIndexedValue">CUESDK</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DB/@EntryIndexedValue">DB</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DG/@EntryIndexedValue">DG</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DMX/@EntryIndexedValue">DMX</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EK/@EntryIndexedValue">EK</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FM/@EntryIndexedValue">FM</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GEZ/@EntryIndexedValue">GEZ</s:String>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user