using System; using System.Collections.Generic; using RGB.NET.Core; namespace RGB.NET.Devices.Asus { /// /// /// Represents the update-queue performing updates for asus devices. /// public class AsusUpdateQueue : UpdateQueue { #region Properties & Fields /// /// Gets or sets the internal color-data cache. /// // ReSharper disable once MemberCanBePrivate.Global protected byte[] ColorData { get; private set; } private Action _updateAction; private IntPtr _handle; #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The update trigger used by this queue. public AsusUpdateQueue(IDeviceUpdateTrigger updateTrigger) : base(updateTrigger) { } #endregion #region Methods /// /// Initializes the queue. /// /// The update-action called by the queue to perform updates. /// The handle of the device this queue performs updates for. /// The amount of leds of the device this queue performs updates for. public void Initialize(Action updateAction, IntPtr handle, int ledCount) { _updateAction = updateAction; _handle = handle; ColorData = new byte[ledCount * 3]; } /// protected override void Update(Dictionary dataSet) { foreach (KeyValuePair data in dataSet) { int index = ((int)data.Key) * 3; ColorData[index] = data.Value.GetR(); ColorData[index + 1] = data.Value.GetB(); ColorData[index + 2] = data.Value.GetG(); } _updateAction(_handle, ColorData); } #endregion } }