using System; using System.Runtime.InteropServices; using RGB.NET.Core; using RGB.NET.Devices.Razer.Native; namespace RGB.NET.Devices.Razer; /// /// Represents the update-queue performing updates for razer keypad devices. /// public sealed class RazerKeypadUpdateQueue : RazerUpdateQueue { #region Constructors /// /// Initializes a new instance of the class. /// /// The update trigger used to update this queue. public RazerKeypadUpdateQueue(IDeviceUpdateTrigger updateTrigger) : base(updateTrigger) { } #endregion #region Methods /// protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet) { _Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS]; foreach ((object key, Color color) in dataSet) colors[(int)key] = new _Color(color); _KeypadCustomEffect effectParams = new() { Color = colors }; nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } /// protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateKeypadEffect(_Defines.KEYPAD_EFFECT_ID, effectParams, ref effectId); #endregion }