diff --git a/RGB.NET.Devices.OpenRGB/Abstract/OpenRGBDeviceInfo.cs b/RGB.NET.Devices.OpenRGB/Abstract/OpenRGBDeviceInfo.cs index 05afff3..5d3cc1b 100644 --- a/RGB.NET.Devices.OpenRGB/Abstract/OpenRGBDeviceInfo.cs +++ b/RGB.NET.Devices.OpenRGB/Abstract/OpenRGBDeviceInfo.cs @@ -1,5 +1,5 @@ using RGB.NET.Core; -using OpenRGBDevice = OpenRGB.NET.Models.Device; +using OpenRGBDevice = OpenRGB.NET.Device; namespace RGB.NET.Devices.OpenRGB; diff --git a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs index 8f19c5a..618c310 100644 --- a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs +++ b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBGenericDevice.cs @@ -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 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 ledId = initial++; } } - y += (int)(zone.MatrixMap.Height * LED_SPACING); + y += (int)(zone.MatrixMap!.Height * LED_SPACING); } else { diff --git a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs index fa79e6e..ff4daa5 100644 --- a/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs +++ b/RGB.NET.Devices.OpenRGB/Generic/OpenRGBUpdateQueue.cs @@ -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 class. /// /// The update trigger used by this queue. - /// The index used to identify the device. + /// The index used to identify the device. /// The OpenRGB client used to send updates to the OpenRGB server. /// The OpenRGB Device containing device-specific information. - 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; } diff --git a/RGB.NET.Devices.OpenRGB/Helper.cs b/RGB.NET.Devices.OpenRGB/Helper.cs index 639730e..a79afff 100644 --- a/RGB.NET.Devices.OpenRGB/Helper.cs +++ b/RGB.NET.Devices.OpenRGB/Helper.cs @@ -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; diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs index 0f2b44b..ccf41a3 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs @@ -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 _clients = new(); + private readonly List _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 /// protected override IEnumerable 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); + + bool anyZoneHasSegments = device.Zones.Any(z => z.Segments.Length > 0); + bool splitDeviceByZones = anyZoneHasSegments || PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type)); - if (PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type))) + if (!splitDeviceByZones) { - int totalLedCount = 0; - - foreach (Zone zone in device.Zones) - if (zone.LedCount > 0) - { - yield return new OpenRGBZoneDevice(new OpenRGBDeviceInfo(device), totalLedCount, zone, updateQueue); - totalLedCount += (int)zone.LedCount; - } - } - else yield return new OpenRGBGenericDevice(new OpenRGBDeviceInfo(device), updateQueue); + continue; + } + + int totalLedCount = 0; + + foreach (Zone zone in device.Zones) + { + 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 + { + 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 */ } diff --git a/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs b/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs index 42ab433..6def092 100644 --- a/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs +++ b/RGB.NET.Devices.OpenRGB/PerZone/OpenRGBZoneDevice.cs @@ -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 { 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) diff --git a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj index 9fd3eec..9d4c0e8 100644 --- a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj +++ b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj @@ -57,7 +57,7 @@ - + diff --git a/RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs b/RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs new file mode 100644 index 0000000..9d8c633 --- /dev/null +++ b/RGB.NET.Devices.OpenRGB/Segment/OpenRGBSegmentDevice.cs @@ -0,0 +1,55 @@ +using OpenRGB.NET; +using RGB.NET.Core; + +namespace RGB.NET.Devices.OpenRGB; + +/// +public class OpenRGBSegmentDevice : AbstractOpenRGBDevice +{ + #region Properties & Fields + + private readonly int _initialLed; + private readonly Segment _segment; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The information provided by OpenRGB + /// The ledId of the first led in the device that belongs to this zone. + /// The Segment information provided by OpenRGB. + /// The queue used to update this zone. + 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 +} \ No newline at end of file