-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathRazerKeyboardUpdateQueue.cs
47 lines (35 loc) · 1.41 KB
/
RazerKeyboardUpdateQueue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Runtime.InteropServices;
using RGB.NET.Core;
using RGB.NET.Devices.Razer.Native;
namespace RGB.NET.Devices.Razer;
/// <summary>
/// Represents the update-queue performing updates for razer keyboard devices.
/// </summary>
public sealed class RazerKeyboardUpdateQueue : RazerUpdateQueue
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RazerKeyboardUpdateQueue" /> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used to update this queue.</param>
public RazerKeyboardUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{ }
#endregion
#region Methods
/// <inheritdoc />
protected override nint CreateEffectParams(ReadOnlySpan<(object key, Color color)> dataSet)
{
_Color[] colors = new _Color[_Defines.KEYBOARD_MAX_LEDS];
foreach ((object key, Color color) in dataSet)
colors[(int)key] = new _Color(color);
_KeyboardCustomEffect effectParams = new() { Color = colors };
nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
return ptr;
}
/// <inheritdoc />
protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateKeyboardEffect(_Defines.KEYBOARD_EFFECT_ID, effectParams, ref effectId);
#endregion
}