mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
Applied code-formatting
This commit is contained in:
parent
7954b876ef
commit
d345de2c40
@ -1,5 +1,4 @@
|
||||
using RGB.NET.Core;
|
||||
using System.Collections.Generic;
|
||||
using OpenRGBDevice = OpenRGB.NET.Models.Device;
|
||||
|
||||
namespace RGB.NET.Devices.OpenRGB;
|
||||
@ -9,6 +8,8 @@ namespace RGB.NET.Devices.OpenRGB;
|
||||
/// </summary>
|
||||
public class OpenRGBDeviceInfo : IRGBDeviceInfo
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <inheritdoc />
|
||||
public RGBDeviceType DeviceType { get; }
|
||||
|
||||
@ -29,16 +30,23 @@ public class OpenRGBDeviceInfo : IRGBDeviceInfo
|
||||
/// </summary>
|
||||
public OpenRGBDevice OpenRGBDevice { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="OpenRGBDeviceInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="openRGBDevice">The OpenRGB device to extract information from.</param>
|
||||
internal OpenRGBDeviceInfo(OpenRGBDevice openRGBDevice)
|
||||
{
|
||||
OpenRGBDevice = openRGBDevice;
|
||||
this.OpenRGBDevice = openRGBDevice;
|
||||
|
||||
DeviceType = Helper.GetRgbNetDeviceType(openRGBDevice.Type);
|
||||
Manufacturer = Helper.GetVendorName(openRGBDevice);
|
||||
Model = Helper.GetModelName(openRGBDevice);
|
||||
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ namespace RGB.NET.Devices.OpenRGB;
|
||||
|
||||
internal static class LedMappings
|
||||
{
|
||||
public static readonly Dictionary<string, LedId> Default = new()
|
||||
public static readonly Dictionary<string, LedId> DEFAULT = new()
|
||||
{
|
||||
["Key: A"] = LedId.Keyboard_A,
|
||||
["Key: B"] = LedId.Keyboard_B,
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
using OpenRGB.NET.Enums;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.OpenRGB.Generic;
|
||||
namespace RGB.NET.Devices.OpenRGB;
|
||||
|
||||
/// <inheritdoc />
|
||||
public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
{
|
||||
#region Constructors
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OpenRGBGenericDevice"/> class.
|
||||
/// </summary>
|
||||
@ -17,6 +18,10 @@ public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
InitializeLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the LEDs of the device based on the data provided by the SDK.
|
||||
/// </summary>
|
||||
@ -25,9 +30,9 @@ public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
LedId initial = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType);
|
||||
|
||||
int y = 0;
|
||||
Size ledSize = new Size(19);
|
||||
Size ledSize = new(19);
|
||||
int zoneLedIndex = 0;
|
||||
const int ledSpacing = 20;
|
||||
const int LED_SPACING = 20;
|
||||
|
||||
foreach (global::OpenRGB.NET.Models.Zone? zone in DeviceInfo.OpenRGBDevice.Zones)
|
||||
{
|
||||
@ -43,18 +48,18 @@ public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
if (index == uint.MaxValue)
|
||||
continue;
|
||||
|
||||
LedId ledId = LedMappings.Default.TryGetValue(DeviceInfo.OpenRGBDevice.Leds[zoneLedIndex + index].Name, out LedId l)
|
||||
? l
|
||||
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(ledSpacing * column, y + (ledSpacing * row)), ledSize, zoneLedIndex + (int)index) == null)
|
||||
while (AddLed(ledId, new Point(LED_SPACING * column, y + (LED_SPACING * row)), ledSize, zoneLedIndex + (int)index) == null)
|
||||
ledId = initial++;
|
||||
}
|
||||
}
|
||||
y += (int)(zone.MatrixMap.Height * ledSpacing);
|
||||
y += (int)(zone.MatrixMap.Height * LED_SPACING);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -62,15 +67,17 @@ public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
{
|
||||
LedId ledId = initial++;
|
||||
|
||||
while (AddLed(ledId, new Point(ledSpacing * i, y), ledSize, zoneLedIndex + i) == null)
|
||||
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 += ledSpacing;
|
||||
y += LED_SPACING;
|
||||
zoneLedIndex += (int)zone.LedCount;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -14,11 +14,13 @@ namespace RGB.NET.Devices.OpenRGB;
|
||||
public class OpenRGBUpdateQueue : UpdateQueue
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly int _deviceid;
|
||||
|
||||
private readonly OpenRGBClient _openRGB;
|
||||
private readonly OpenRGBDevice _device;
|
||||
private readonly OpenRGBColor[] _colors;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@ -33,9 +35,10 @@ public class OpenRGBUpdateQueue : UpdateQueue
|
||||
public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceid, OpenRGBClient client, OpenRGBDevice device)
|
||||
: base(updateTrigger)
|
||||
{
|
||||
_deviceid = deviceid;
|
||||
_openRGB = client;
|
||||
_device = device;
|
||||
this._deviceid = deviceid;
|
||||
this._openRGB = client;
|
||||
this._device = device;
|
||||
|
||||
_colors = Enumerable.Range(0, _device.Colors.Length)
|
||||
.Select(_ => new OpenRGBColor())
|
||||
.ToArray();
|
||||
@ -49,9 +52,7 @@ public class OpenRGBUpdateQueue : UpdateQueue
|
||||
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
|
||||
{
|
||||
foreach ((object key, Color color) in dataSet)
|
||||
{
|
||||
_colors[(int)key] = new OpenRGBColor(color.GetR(), color.GetG(), color.GetB());
|
||||
}
|
||||
|
||||
_openRGB.UpdateLeds(_deviceid, _colors);
|
||||
}
|
||||
|
||||
@ -6,7 +6,8 @@ namespace RGB.NET.Devices.OpenRGB;
|
||||
|
||||
internal static class Helper
|
||||
{
|
||||
public static LedId GetInitialLedIdForDeviceType(RGBDeviceType type) => type switch
|
||||
public static LedId GetInitialLedIdForDeviceType(RGBDeviceType type)
|
||||
=> type switch
|
||||
{
|
||||
RGBDeviceType.Mouse => LedId.Mouse1,
|
||||
RGBDeviceType.Headset => LedId.Headset1,
|
||||
@ -25,7 +26,8 @@ internal static class Helper
|
||||
_ => LedId.Custom1
|
||||
};
|
||||
|
||||
public static RGBDeviceType GetRgbNetDeviceType(DeviceType type) => type switch
|
||||
public static RGBDeviceType GetRgbNetDeviceType(DeviceType type)
|
||||
=> type switch
|
||||
{
|
||||
DeviceType.Motherboard => RGBDeviceType.Mainboard,
|
||||
DeviceType.Dram => RGBDeviceType.DRAM,
|
||||
@ -40,8 +42,8 @@ internal static class Helper
|
||||
_ => RGBDeviceType.Unknown
|
||||
};
|
||||
|
||||
public static LedId GetInitialLedIdForDeviceType(DeviceType type) =>
|
||||
GetInitialLedIdForDeviceType(GetRgbNetDeviceType(type));
|
||||
public static LedId GetInitialLedIdForDeviceType(DeviceType type)
|
||||
=> GetInitialLedIdForDeviceType(GetRgbNetDeviceType(type));
|
||||
|
||||
public static string GetVendorName(OpenRGBDevice openRGBDevice) => string.IsNullOrWhiteSpace(openRGBDevice.Vendor)
|
||||
? "OpenRGB"
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
using OpenRGB.NET;
|
||||
using OpenRGB.NET.Models;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.OpenRGB.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -16,7 +15,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly List<OpenRGBClient> _clients = new List<OpenRGBClient>();
|
||||
private readonly List<OpenRGBClient> _clients = new();
|
||||
|
||||
private static OpenRGBDeviceProvider? _instance;
|
||||
|
||||
@ -28,7 +27,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
/// <summary>
|
||||
/// Gets a list of all defined device-definitions.
|
||||
/// </summary>
|
||||
public List<OpenRGBServerDefinition> DeviceDefinitions { get; } = new List<OpenRGBServerDefinition>();
|
||||
public List<OpenRGBServerDefinition> DeviceDefinitions { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether all devices will be added, or just the ones with a 'Direct' mode. Defaults to false.
|
||||
@ -64,7 +63,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
{
|
||||
try
|
||||
{
|
||||
OpenRGBClient? openRgb = new OpenRGBClient(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;
|
||||
}
|
||||
@ -72,7 +71,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
{
|
||||
deviceDefinition.Connected = false;
|
||||
deviceDefinition.LastError = e.Message;
|
||||
Throw(e, false);
|
||||
Throw(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,7 +87,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
{
|
||||
Device? device = openRgb.GetControllerData(i);
|
||||
|
||||
int directModeIndex = Array.FindIndex(device.Modes, device => device.Name == "Direct");
|
||||
int directModeIndex = Array.FindIndex(device.Modes, d => d.Name == "Direct");
|
||||
if (directModeIndex != -1)
|
||||
{
|
||||
//set the device to direct mode if it has it
|
||||
@ -101,39 +100,33 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
|
||||
continue;
|
||||
}
|
||||
|
||||
OpenRGBUpdateQueue? updateQueue = new OpenRGBUpdateQueue(GetUpdateTrigger(), i, openRgb, device);
|
||||
OpenRGBUpdateQueue? updateQueue = new(GetUpdateTrigger(), i, openRgb, device);
|
||||
|
||||
if (PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type)))
|
||||
{
|
||||
int totalLedCount = 0;
|
||||
|
||||
for (int zoneIndex = 0; zoneIndex < device.Zones.Length; zoneIndex++)
|
||||
foreach (Zone zone in device.Zones)
|
||||
if (zone.LedCount > 0)
|
||||
{
|
||||
Zone zone = device.Zones[zoneIndex];
|
||||
|
||||
if (zone.LedCount == 0)
|
||||
continue;
|
||||
|
||||
yield return new OpenRGBZoneDevice(new OpenRGBDeviceInfo(device), totalLedCount, zone, updateQueue);
|
||||
totalLedCount += (int)zone.LedCount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return new OpenRGBGenericDevice(new OpenRGBDeviceInfo(device), updateQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
|
||||
foreach (OpenRGBClient? client in _clients)
|
||||
foreach (OpenRGBClient client in _clients)
|
||||
{
|
||||
try { client?.Dispose(); }
|
||||
try { client.Dispose(); }
|
||||
catch { /* at least we tried */ }
|
||||
}
|
||||
|
||||
|
||||
@ -7,9 +7,15 @@ namespace RGB.NET.Devices.OpenRGB;
|
||||
/// <inheritdoc />
|
||||
public class OpenRGBZoneDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly int _initialLed;
|
||||
private readonly Zone _zone;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OpenRGBZoneDevice"/> class.
|
||||
/// </summary>
|
||||
@ -26,11 +32,15 @@ public class OpenRGBZoneDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
InitializeLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void InitializeLayout()
|
||||
{
|
||||
Size ledSize = new Size(19);
|
||||
const int ledSpacing = 20;
|
||||
LedId initial = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType) + _initialLed;
|
||||
Size ledSize = new(19);
|
||||
const int LED_SPACING = 20;
|
||||
LedId initialId = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType) + _initialLed;
|
||||
|
||||
if (_zone.Type == ZoneType.Matrix)
|
||||
{
|
||||
@ -44,12 +54,12 @@ public class OpenRGBZoneDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
if (index == uint.MaxValue)
|
||||
continue;
|
||||
|
||||
LedId ledId = LedMappings.Default.TryGetValue(DeviceInfo.OpenRGBDevice.Leds[_initialLed + index].Name, out LedId l)
|
||||
? l
|
||||
: initial++;
|
||||
LedId ledId = LedMappings.DEFAULT.TryGetValue(DeviceInfo.OpenRGBDevice.Leds[_initialLed + index].Name, out LedId id)
|
||||
? id
|
||||
: initialId++;
|
||||
|
||||
while (AddLed(ledId, new Point(ledSpacing * column, ledSpacing * row), ledSize, _initialLed + (int)index) == null)
|
||||
ledId = initial++;
|
||||
while (AddLed(ledId, new Point(LED_SPACING * column, LED_SPACING * row), ledSize, _initialLed + (int)index) == null)
|
||||
ledId = initialId++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -57,11 +67,13 @@ public class OpenRGBZoneDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
|
||||
{
|
||||
for (int i = 0; i < _zone.LedCount; i++)
|
||||
{
|
||||
LedId ledId = initial++;
|
||||
LedId ledId = initialId++;
|
||||
|
||||
while (AddLed(ledId, new Point(ledSpacing * i, 0), ledSize, _initialLed + i) == null)
|
||||
ledId = initial++;
|
||||
while (AddLed(ledId, new Point(LED_SPACING * i, 0), ledSize, _initialLed + i) == null)
|
||||
ledId = initialId++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -24,6 +24,8 @@
|
||||
<RepositoryUrl>https://github.com/DarthAffe/RGB.NET</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
|
||||
<Version>0.0.1</Version>
|
||||
<AssemblyVersion>0.0.1</AssemblyVersion>
|
||||
<FileVersion>0.0.1</FileVersion>
|
||||
|
||||
@ -0,0 +1,4 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=abstract/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generic/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=perzone/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
Loading…
x
Reference in New Issue
Block a user