using System;
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
namespace RGB.NET.Devices.DMX.E131
{
///
/// Represents a E1.31-DXM-device.
///
public class E131Device : AbstractRGBDevice, IUnknownDevice
{
#region Properties & Fields
///
public override E131DeviceInfo DeviceInfo { get; }
private readonly Dictionary getValueFunc)>> _ledMappings;
private E131UpdateQueue? _updateQueue;
#endregion
#region Constructors
///
internal E131Device(E131DeviceInfo deviceInfo, Dictionary getValueFunc)>> ledMappings)
{
this.DeviceInfo = deviceInfo;
this._ledMappings = ledMappings;
}
#endregion
#region Methods
internal void Initialize(IDeviceUpdateTrigger updateTrigger)
{
int count = 0;
foreach (LedId id in _ledMappings.Keys)
AddLed(id, new Point((count++) * 10, 0), new Size(10, 10));
_updateQueue = new E131UpdateQueue(updateTrigger, DeviceInfo.Hostname, DeviceInfo.Port);
_updateQueue.DataPacket.SetCID(DeviceInfo.CID);
_updateQueue.DataPacket.SetUniverse(DeviceInfo.Universe);
}
///
protected override object GetLedCustomData(LedId ledId) => new LedChannelMapping(_ledMappings[ledId]);
///
protected override void UpdateLeds(IEnumerable ledsToUpdate) => _updateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
///
public override void Dispose()
{
try { _updateQueue?.Dispose(); }
catch { /* at least we tried */ }
base.Dispose();
}
#endregion
}
}