-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathOpenRGBUpdateQueue.cs
71 lines (56 loc) · 2 KB
/
OpenRGBUpdateQueue.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
using OpenRGB.NET;
using RGB.NET.Core;
using System;
using System.Linq;
using Color = RGB.NET.Core.Color;
using OpenRGBColor = OpenRGB.NET.Color;
using OpenRGBDevice = OpenRGB.NET.Device;
namespace RGB.NET.Devices.OpenRGB;
/// <inheritdoc />
/// <summary>
/// Represents the update-queue performing updates for OpenRGB devices.
/// </summary>
public sealed class OpenRGBUpdateQueue : UpdateQueue
{
#region Properties & Fields
private readonly int _deviceId;
private readonly OpenRgbClient _openRGB;
private readonly OpenRGBColor[] _colors;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="OpenRGBUpdateQueue"/> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
/// <param name="deviceId">The index used to identify the device.</param>
/// <param name="client">The OpenRGB client used to send updates to the OpenRGB server.</param>
/// <param name="device">The OpenRGB Device containing device-specific information.</param>
public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId, OpenRgbClient client, OpenRGBDevice device)
: base(updateTrigger)
{
this._deviceId = deviceId;
this._openRGB = client;
_colors = Enumerable.Range(0, device.Colors.Length)
.Select(_ => new OpenRGBColor())
.ToArray();
}
#endregion
#region Methods
/// <inheritdoc />
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
foreach ((object key, Color color) in dataSet)
_colors[(int)key] = new OpenRGBColor(color.GetR(), color.GetG(), color.GetB());
_openRGB.UpdateLeds(_deviceId, _colors);
return true;
}
catch (Exception ex)
{
OpenRGBDeviceProvider.Instance.Throw(ex);
}
return false;
}
#endregion
}