using OpenRGB.NET; using RGB.NET.Core; using System; using System.Linq; using Color = RGB.NET.Core.Color; using OpenRGBColor = OpenRGB.NET.Color; using OpenRGBDevice = OpenRGB.NET.Device; namespace RGB.NET.Devices.OpenRGB; /// /// /// Represents the update-queue performing updates for OpenRGB devices. /// public sealed class OpenRGBUpdateQueue : UpdateQueue { #region Properties & Fields private readonly int _deviceId; private readonly OpenRgbClient _openRGB; private readonly OpenRGBColor[] _colors; #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The update trigger used by this queue. /// The index used to identify the device. /// The OpenRGB client used to send updates to the OpenRGB server. /// The OpenRGB Device containing device-specific information. public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId, OpenRgbClient client, OpenRGBDevice device) : base(updateTrigger) { this._deviceId = deviceId; this._openRGB = client; _colors = Enumerable.Range(0, device.Colors.Length) .Select(_ => new OpenRGBColor()) .ToArray(); } #endregion #region Methods /// protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet) { try { foreach ((object key, Color color) in dataSet) _colors[(int)key] = new OpenRGBColor(color.GetR(), color.GetG(), color.GetB()); _openRGB.UpdateLeds(_deviceId, _colors); return true; } catch (Exception ex) { OpenRGBDeviceProvider.Instance.Throw(ex); } return false; } #endregion }