mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
OpenRgb - added segments
This commit is contained in:
parent
4675349621
commit
1793d26166
@ -1,5 +1,5 @@
|
||||
using RGB.NET.Core;
|
||||
using OpenRGBDevice = OpenRGB.NET.Models.Device;
|
||||
using OpenRGBDevice = OpenRGB.NET.Device;
|
||||
|
||||
namespace RGB.NET.Devices.OpenRGB;
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using OpenRGB.NET.Enums;
|
||||
using OpenRGB.NET;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.OpenRGB;
|
||||
@ -34,15 +34,15 @@ public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
int zoneLedIndex = 0;
|
||||
const int LED_SPACING = 20;
|
||||
|
||||
foreach (global::OpenRGB.NET.Models.Zone? zone in DeviceInfo.OpenRGBDevice.Zones)
|
||||
foreach (Zone? zone in DeviceInfo.OpenRGBDevice.Zones)
|
||||
{
|
||||
if (zone.Type == ZoneType.Matrix)
|
||||
{
|
||||
for (int row = 0; row < zone.MatrixMap.Height; row++)
|
||||
for (int row = 0; row < zone.MatrixMap!.Height; row++)
|
||||
{
|
||||
for (int column = 0; column < zone.MatrixMap.Width; column++)
|
||||
for (int column = 0; column < zone.MatrixMap!.Width; column++)
|
||||
{
|
||||
uint index = zone.MatrixMap.Matrix[row, 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)
|
||||
@ -59,7 +59,7 @@ public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
ledId = initial++;
|
||||
}
|
||||
}
|
||||
y += (int)(zone.MatrixMap.Height * LED_SPACING);
|
||||
y += (int)(zone.MatrixMap!.Height * LED_SPACING);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -2,8 +2,9 @@
|
||||
using RGB.NET.Core;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRGBColor = OpenRGB.NET.Models.Color;
|
||||
using OpenRGBDevice = OpenRGB.NET.Models.Device;
|
||||
using Color = RGB.NET.Core.Color;
|
||||
using OpenRGBColor = OpenRGB.NET.Color;
|
||||
using OpenRGBDevice = OpenRGB.NET.Device;
|
||||
|
||||
namespace RGB.NET.Devices.OpenRGB;
|
||||
|
||||
@ -15,10 +16,9 @@ public class OpenRGBUpdateQueue : UpdateQueue
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly int _deviceid;
|
||||
private readonly int _deviceId;
|
||||
|
||||
private readonly OpenRGBClient _openRGB;
|
||||
private readonly OpenRGBDevice _device;
|
||||
private readonly OpenRgbClient _openRGB;
|
||||
private readonly OpenRGBColor[] _colors;
|
||||
|
||||
#endregion
|
||||
@ -29,17 +29,16 @@ public class OpenRGBUpdateQueue : UpdateQueue
|
||||
/// 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="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)
|
||||
public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId, OpenRgbClient client, OpenRGBDevice device)
|
||||
: base(updateTrigger)
|
||||
{
|
||||
this._deviceid = deviceid;
|
||||
this._deviceId = deviceId;
|
||||
this._openRGB = client;
|
||||
this._device = device;
|
||||
|
||||
_colors = Enumerable.Range(0, _device.Colors.Length)
|
||||
_colors = Enumerable.Range(0, device.Colors.Length)
|
||||
.Select(_ => new OpenRGBColor())
|
||||
.ToArray();
|
||||
}
|
||||
@ -56,7 +55,7 @@ public class OpenRGBUpdateQueue : UpdateQueue
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
_colors[(int)key] = new OpenRGBColor(color.GetR(), color.GetG(), color.GetB());
|
||||
|
||||
_openRGB.UpdateLeds(_deviceid, _colors);
|
||||
_openRGB.UpdateLeds(_deviceId, _colors);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using OpenRGB.NET.Enums;
|
||||
using OpenRGB.NET;
|
||||
using RGB.NET.Core;
|
||||
using OpenRGBDevice = OpenRGB.NET.Models.Device;
|
||||
using OpenRGBDevice = OpenRGB.NET.Device;
|
||||
|
||||
namespace RGB.NET.Devices.OpenRGB;
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using OpenRGB.NET;
|
||||
using OpenRGB.NET.Models;
|
||||
using RGB.NET.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -15,7 +14,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly List<OpenRGBClient> _clients = new();
|
||||
private readonly List<OpenRgbClient> _clients = new();
|
||||
|
||||
private static OpenRGBDeviceProvider? _instance;
|
||||
|
||||
@ -71,7 +70,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
{
|
||||
try
|
||||
{
|
||||
OpenRGBClient openRgb = new(ip: deviceDefinition.Ip, port: deviceDefinition.Port, name: deviceDefinition.ClientName, autoconnect: true);
|
||||
OpenRgbClient openRgb = new(ip: deviceDefinition.Ip, port: deviceDefinition.Port, name: deviceDefinition.ClientName, autoConnect: true);
|
||||
_clients.Add(openRgb);
|
||||
deviceDefinition.Connected = true;
|
||||
}
|
||||
@ -87,7 +86,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
/// <inheritdoc />
|
||||
protected override IEnumerable<IRGBDevice> LoadDevices()
|
||||
{
|
||||
foreach (OpenRGBClient? openRgb in _clients)
|
||||
foreach (OpenRgbClient? openRgb in _clients)
|
||||
{
|
||||
int deviceCount = openRgb.GetControllerCount();
|
||||
|
||||
@ -99,7 +98,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
if (directModeIndex != -1)
|
||||
{
|
||||
//set the device to direct mode if it has it
|
||||
openRgb.SetMode(i, directModeIndex);
|
||||
openRgb.UpdateMode(i, directModeIndex);
|
||||
}
|
||||
else if (!ForceAddAllDevices)
|
||||
{
|
||||
@ -108,21 +107,43 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
continue;
|
||||
}
|
||||
|
||||
if (device.Zones.Length == 0)
|
||||
continue;
|
||||
if (device.Zones.All(z => z.LedCount == 0))
|
||||
continue;
|
||||
|
||||
OpenRGBUpdateQueue? updateQueue = new(GetUpdateTrigger(), i, openRgb, device);
|
||||
|
||||
if (PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type)))
|
||||
bool anyZoneHasSegments = device.Zones.Any(z => z.Segments.Length > 0);
|
||||
bool splitDeviceByZones = anyZoneHasSegments || PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type));
|
||||
|
||||
if (!splitDeviceByZones)
|
||||
{
|
||||
yield return new OpenRGBGenericDevice(new OpenRGBDeviceInfo(device), updateQueue);
|
||||
continue;
|
||||
}
|
||||
|
||||
int totalLedCount = 0;
|
||||
|
||||
foreach (Zone zone in device.Zones)
|
||||
if (zone.LedCount > 0)
|
||||
{
|
||||
if (zone.LedCount <= 0)
|
||||
continue;
|
||||
|
||||
if (zone.Segments.Length <= 0)
|
||||
{
|
||||
yield return new OpenRGBZoneDevice(new OpenRGBDeviceInfo(device), totalLedCount, zone, updateQueue);
|
||||
totalLedCount += (int)zone.LedCount;
|
||||
}
|
||||
}
|
||||
else
|
||||
yield return new OpenRGBGenericDevice(new OpenRGBDeviceInfo(device), updateQueue);
|
||||
{
|
||||
foreach (Segment segment in zone.Segments)
|
||||
{
|
||||
yield return new OpenRGBSegmentDevice(new OpenRGBDeviceInfo(device), totalLedCount, segment, updateQueue);
|
||||
totalLedCount += (int)segment.LedCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -132,7 +153,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
{
|
||||
base.Dispose();
|
||||
|
||||
foreach (OpenRGBClient client in _clients)
|
||||
foreach (OpenRgbClient client in _clients)
|
||||
{
|
||||
try { client.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using OpenRGB.NET.Enums;
|
||||
using OpenRGB.NET.Models;
|
||||
using OpenRGB.NET;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.OpenRGB;
|
||||
@ -40,15 +39,15 @@ public class OpenRGBZoneDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
{
|
||||
Size ledSize = new(19);
|
||||
const int LED_SPACING = 20;
|
||||
LedId initialId = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType) + _initialLed;
|
||||
LedId initialId = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType);
|
||||
|
||||
if (_zone.Type == ZoneType.Matrix)
|
||||
{
|
||||
for (int row = 0; row < _zone.MatrixMap.Height; row++)
|
||||
for (int row = 0; row < _zone.MatrixMap!.Height; row++)
|
||||
{
|
||||
for (int column = 0; column < _zone.MatrixMap.Width; column++)
|
||||
for (int column = 0; column < _zone.MatrixMap!.Width; column++)
|
||||
{
|
||||
uint index = _zone.MatrixMap.Matrix[row, 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)
|
||||
|
||||
@ -57,7 +57,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OpenRGB.NET" Version="1.7.0" />
|
||||
<PackageReference Include="OpenRGB.NET" Version="2.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
55
RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs
Normal file
55
RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using OpenRGB.NET;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.OpenRGB;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class OpenRGBSegmentDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly int _initialLed;
|
||||
private readonly Segment _segment;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OpenRGBZoneDevice"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The information provided by OpenRGB</param>
|
||||
/// <param name="initialLed">The ledId of the first led in the device that belongs to this zone.</param>
|
||||
/// <param name="segment">The Segment information provided by OpenRGB.</param>
|
||||
/// <param name="updateQueue">The queue used to update this zone.</param>
|
||||
public OpenRGBSegmentDevice(OpenRGBDeviceInfo info, int initialLed, Segment segment, IUpdateQueue updateQueue)
|
||||
: base(info, updateQueue)
|
||||
{
|
||||
_initialLed = initialLed;
|
||||
_segment = segment;
|
||||
|
||||
InitializeLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void InitializeLayout()
|
||||
{
|
||||
Size ledSize = new(19);
|
||||
const int LED_SPACING = 20;
|
||||
LedId initialId = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType);
|
||||
|
||||
for (int i = 0; i < _segment.LedCount; i++)
|
||||
{
|
||||
LedId ledId = initialId++;
|
||||
|
||||
// ReSharper disable once HeapView.BoxingAllocation
|
||||
while (AddLed(ledId, new Point(LED_SPACING * i, 0), ledSize, _initialLed + i) == null)
|
||||
ledId = initialId++;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user