using System; using System.Collections.Generic; using System.Runtime.InteropServices; using RGB.NET.Core; using RGB.NET.Devices.Corsair.Native; namespace RGB.NET.Devices.Corsair { /// /// /// Represents the update-queue performing updates for corsair devices. /// public class CorsairDeviceUpdateQueue : UpdateQueue { #region Properties & Fields private int _deviceIndex; #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The update trigger used by this queue. /// The index used to identify the device. public CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceIndex) : base(updateTrigger) { this._deviceIndex = deviceIndex; } #endregion #region Methods /// protected override void Update(Dictionary dataSet) { int structSize = Marshal.SizeOf(typeof(_CorsairLedColor)); IntPtr ptr = Marshal.AllocHGlobal(structSize * dataSet.Count); IntPtr addPtr = new IntPtr(ptr.ToInt64()); foreach (KeyValuePair data in dataSet) { _CorsairLedColor color = new _CorsairLedColor { ledId = (int)data.Key, r = data.Value.GetR(), g = data.Value.GetG(), b = data.Value.GetB() }; Marshal.StructureToPtr(color, addPtr, false); addPtr = new IntPtr(addPtr.ToInt64() + structSize); } _CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Count, ptr); _CUESDK.CorsairSetLedsColorsFlushBuffer(); Marshal.FreeHGlobal(ptr); } #endregion } }