-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathRazerKeyboardRGBDevice.cs
56 lines (42 loc) · 1.8 KB
/
RazerKeyboardRGBDevice.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
48
49
50
51
52
53
54
55
56
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using RGB.NET.Core;
using RGB.NET.Devices.Razer.Native;
namespace RGB.NET.Devices.Razer;
/// <inheritdoc cref="RazerRGBDevice" />
/// <summary>
/// Represents a razer keyboard.
/// </summary>
public sealed class RazerKeyboardRGBDevice : RazerRGBDevice, IKeyboard
{
#region Properties & Fields
IKeyboardDeviceInfo IKeyboard.DeviceInfo => (IKeyboardDeviceInfo)DeviceInfo;
private readonly LedMapping<int> _ledMapping;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Razer.RazerKeyboardRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CUE for the keyboard.</param>
/// <param name="updateTrigger">The update trigger used to update this device.</param>
/// <param name="ledMapping">A mapping of leds this device is initialized with.</param>
internal RazerKeyboardRGBDevice(RazerKeyboardRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger, LedMapping<int> ledMapping)
: base(info, new RazerKeyboardUpdateQueue(updateTrigger))
{
this._ledMapping = ledMapping;
InitializeLayout();
}
#endregion
#region Methods
private void InitializeLayout()
{
for (int row = 0; row < _Defines.KEYBOARD_MAX_ROW; row++)
for (int column = 0; column < _Defines.KEYBOARD_MAX_COLUMN; column++)
if (_ledMapping.TryGetValue((row * _Defines.KEYBOARD_MAX_COLUMN) + column, out LedId id))
AddLed(id, new Point(column * 19, row * 19), new Size(19, 19));
}
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId];
#endregion
}