-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathOpenRGBGenericDevice.cs
83 lines (70 loc) · 2.94 KB
/
OpenRGBGenericDevice.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using OpenRGB.NET;
using RGB.NET.Core;
namespace RGB.NET.Devices.OpenRGB;
/// <inheritdoc />
public sealed class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="OpenRGBGenericDevice"/> class.
/// </summary>
/// <param name="info">Generic information for the device.</param>
/// <param name="updateQueue">The queue used to update the device.</param>
public OpenRGBGenericDevice(OpenRGBDeviceInfo info, IUpdateQueue updateQueue)
: base(info, updateQueue)
{
InitializeLayout();
}
#endregion
#region Methods
/// <summary>
/// Initializes the LEDs of the device based on the data provided by the SDK.
/// </summary>
private void InitializeLayout()
{
LedId initial = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType);
int y = 0;
Size ledSize = new(19);
int zoneLedIndex = 0;
const int LED_SPACING = 20;
foreach (Zone? zone in DeviceInfo.OpenRGBDevice.Zones)
{
if (zone.Type == ZoneType.Matrix)
{
for (int row = 0; row < zone.MatrixMap!.Height; row++)
{
for (int column = 0; column < zone.MatrixMap!.Width; column++)
{
uint index = zone.MatrixMap!.Matrix[row, column];
//will be max value if the position does not have an associated key
if (index == uint.MaxValue)
continue;
LedId ledId = LedMappings.DEFAULT.TryGetValue(DeviceInfo.OpenRGBDevice.Leds[zoneLedIndex + index].Name, out LedId id)
? id
: initial++;
//HACK: doing this because some different Led Names are mapped to the same LedId
//for example, "Enter" and "ISO Enter".
//this way, at least they'll be controllable as CustomX
while (AddLed(ledId, new Point(LED_SPACING * column, y + (LED_SPACING * row)), ledSize, zoneLedIndex + (int)index) == null)
ledId = initial++;
}
}
y += (int)(zone.MatrixMap!.Height * LED_SPACING);
}
else
{
for (int i = 0; i < zone.LedCount; i++)
{
LedId ledId = initial++;
while (AddLed(ledId, new Point(LED_SPACING * i, y), ledSize, zoneLedIndex + i) == null)
ledId = initial++;
}
}
//we'll just set each zone in its own row for now,
//with each led for that zone being horizontally distributed
y += LED_SPACING;
zoneLedIndex += (int)zone.LedCount;
}
}
#endregion
}