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) InitializeLed(id, new Rectangle((count++) * 10, 0, 10, 10)); //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); } _updateQueue = new E131UpdateQueue(updateTrigger, DeviceInfo.Hostname, DeviceInfo.Port); _updateQueue.DataPacket.SetCID(DeviceInfo.CID); _updateQueue.DataPacket.SetUniverse(DeviceInfo.Universe); } /// protected override object CreateLedCustomData(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 } }