1
0
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:
Darth Affe 2022-09-26 14:35:03 +02:00
parent 7954b876ef
commit d345de2c40
9 changed files with 304 additions and 275 deletions

View File

@ -1,5 +1,4 @@
using RGB.NET.Core; using RGB.NET.Core;
using System.Collections.Generic;
using OpenRGBDevice = OpenRGB.NET.Models.Device; using OpenRGBDevice = OpenRGB.NET.Models.Device;
namespace RGB.NET.Devices.OpenRGB; namespace RGB.NET.Devices.OpenRGB;
@ -9,6 +8,8 @@ namespace RGB.NET.Devices.OpenRGB;
/// </summary> /// </summary>
public class OpenRGBDeviceInfo : IRGBDeviceInfo public class OpenRGBDeviceInfo : IRGBDeviceInfo
{ {
#region Properties & Fields
/// <inheritdoc /> /// <inheritdoc />
public RGBDeviceType DeviceType { get; } public RGBDeviceType DeviceType { get; }
@ -29,16 +30,23 @@ public class OpenRGBDeviceInfo : IRGBDeviceInfo
/// </summary> /// </summary>
public OpenRGBDevice OpenRGBDevice { get; } public OpenRGBDevice OpenRGBDevice { get; }
#endregion
#region Constructors
/// <summary> /// <summary>
/// Initializes a new instance of <see cref="OpenRGBDeviceInfo"/>. /// Initializes a new instance of <see cref="OpenRGBDeviceInfo"/>.
/// </summary> /// </summary>
/// <param name="openRGBDevice">The OpenRGB device to extract information from.</param> /// <param name="openRGBDevice">The OpenRGB device to extract information from.</param>
internal OpenRGBDeviceInfo(OpenRGBDevice openRGBDevice) internal OpenRGBDeviceInfo(OpenRGBDevice openRGBDevice)
{ {
OpenRGBDevice = openRGBDevice; this.OpenRGBDevice = openRGBDevice;
DeviceType = Helper.GetRgbNetDeviceType(openRGBDevice.Type); DeviceType = Helper.GetRgbNetDeviceType(openRGBDevice.Type);
Manufacturer = Helper.GetVendorName(openRGBDevice); Manufacturer = Helper.GetVendorName(openRGBDevice);
Model = Helper.GetModelName(openRGBDevice); Model = Helper.GetModelName(openRGBDevice);
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model); DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
} }
#endregion
} }

View File

@ -5,141 +5,141 @@ namespace RGB.NET.Devices.OpenRGB;
internal static class LedMappings 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: A"] = LedId.Keyboard_A,
["Key: B" ] = LedId.Keyboard_B , ["Key: B"] = LedId.Keyboard_B,
["Key: C" ] = LedId.Keyboard_C , ["Key: C"] = LedId.Keyboard_C,
["Key: D" ] = LedId.Keyboard_D , ["Key: D"] = LedId.Keyboard_D,
["Key: E" ] = LedId.Keyboard_E , ["Key: E"] = LedId.Keyboard_E,
["Key: F" ] = LedId.Keyboard_F , ["Key: F"] = LedId.Keyboard_F,
["Key: G" ] = LedId.Keyboard_G , ["Key: G"] = LedId.Keyboard_G,
["Key: H" ] = LedId.Keyboard_H , ["Key: H"] = LedId.Keyboard_H,
["Key: I" ] = LedId.Keyboard_I , ["Key: I"] = LedId.Keyboard_I,
["Key: J" ] = LedId.Keyboard_J , ["Key: J"] = LedId.Keyboard_J,
["Key: K" ] = LedId.Keyboard_K , ["Key: K"] = LedId.Keyboard_K,
["Key: L" ] = LedId.Keyboard_L , ["Key: L"] = LedId.Keyboard_L,
["Key: M" ] = LedId.Keyboard_M , ["Key: M"] = LedId.Keyboard_M,
["Key: N" ] = LedId.Keyboard_N , ["Key: N"] = LedId.Keyboard_N,
["Key: O" ] = LedId.Keyboard_O , ["Key: O"] = LedId.Keyboard_O,
["Key: P" ] = LedId.Keyboard_P , ["Key: P"] = LedId.Keyboard_P,
["Key: Q" ] = LedId.Keyboard_Q , ["Key: Q"] = LedId.Keyboard_Q,
["Key: R" ] = LedId.Keyboard_R , ["Key: R"] = LedId.Keyboard_R,
["Key: S" ] = LedId.Keyboard_S , ["Key: S"] = LedId.Keyboard_S,
["Key: T" ] = LedId.Keyboard_T , ["Key: T"] = LedId.Keyboard_T,
["Key: U" ] = LedId.Keyboard_U , ["Key: U"] = LedId.Keyboard_U,
["Key: V" ] = LedId.Keyboard_V , ["Key: V"] = LedId.Keyboard_V,
["Key: W" ] = LedId.Keyboard_W , ["Key: W"] = LedId.Keyboard_W,
["Key: X" ] = LedId.Keyboard_X , ["Key: X"] = LedId.Keyboard_X,
["Key: Y" ] = LedId.Keyboard_Y , ["Key: Y"] = LedId.Keyboard_Y,
["Key: Z" ] = LedId.Keyboard_Z , ["Key: Z"] = LedId.Keyboard_Z,
["Key: 1" ] = LedId.Keyboard_1 , ["Key: 1"] = LedId.Keyboard_1,
["Key: 2" ] = LedId.Keyboard_2 , ["Key: 2"] = LedId.Keyboard_2,
["Key: 3" ] = LedId.Keyboard_3 , ["Key: 3"] = LedId.Keyboard_3,
["Key: 4" ] = LedId.Keyboard_4 , ["Key: 4"] = LedId.Keyboard_4,
["Key: 5" ] = LedId.Keyboard_5 , ["Key: 5"] = LedId.Keyboard_5,
["Key: 6" ] = LedId.Keyboard_6 , ["Key: 6"] = LedId.Keyboard_6,
["Key: 7" ] = LedId.Keyboard_7 , ["Key: 7"] = LedId.Keyboard_7,
["Key: 8" ] = LedId.Keyboard_8 , ["Key: 8"] = LedId.Keyboard_8,
["Key: 9" ] = LedId.Keyboard_9 , ["Key: 9"] = LedId.Keyboard_9,
["Key: 0" ] = LedId.Keyboard_0 , ["Key: 0"] = LedId.Keyboard_0,
["Key: Enter" ] = LedId.Keyboard_Enter , ["Key: Enter"] = LedId.Keyboard_Enter,
["Key: Enter (ISO)" ] = LedId.Keyboard_Enter , ["Key: Enter (ISO)"] = LedId.Keyboard_Enter,
["Key: Escape" ] = LedId.Keyboard_Escape , ["Key: Escape"] = LedId.Keyboard_Escape,
["Key: Backspace" ] = LedId.Keyboard_Backspace , ["Key: Backspace"] = LedId.Keyboard_Backspace,
["Key: Tab" ] = LedId.Keyboard_Tab , ["Key: Tab"] = LedId.Keyboard_Tab,
["Key: Space" ] = LedId.Keyboard_Space , ["Key: Space"] = LedId.Keyboard_Space,
["Key: -" ] = LedId.Keyboard_MinusAndUnderscore , ["Key: -"] = LedId.Keyboard_MinusAndUnderscore,
["Key: =" ] = LedId.Keyboard_EqualsAndPlus , ["Key: ="] = LedId.Keyboard_EqualsAndPlus,
["Key: [" ] = LedId.Keyboard_BracketLeft , ["Key: ["] = LedId.Keyboard_BracketLeft,
["Key: ]" ] = LedId.Keyboard_BracketRight , ["Key: ]"] = LedId.Keyboard_BracketRight,
["Key: \\ (ANSI)" ] = LedId.Keyboard_Backslash , ["Key: \\ (ANSI)"] = LedId.Keyboard_Backslash,
["Key: #" ] = LedId.Keyboard_NonUsTilde , ["Key: #"] = LedId.Keyboard_NonUsTilde,
["Key: ;" ] = LedId.Keyboard_SemicolonAndColon , ["Key: ;"] = LedId.Keyboard_SemicolonAndColon,
["Key: '" ] = LedId.Keyboard_ApostropheAndDoubleQuote, ["Key: '"] = LedId.Keyboard_ApostropheAndDoubleQuote,
["Key: `" ] = LedId.Keyboard_GraveAccentAndTilde , ["Key: `"] = LedId.Keyboard_GraveAccentAndTilde,
["Key: ," ] = LedId.Keyboard_CommaAndLessThan , ["Key: ,"] = LedId.Keyboard_CommaAndLessThan,
["Key: ." ] = LedId.Keyboard_PeriodAndBiggerThan , ["Key: ."] = LedId.Keyboard_PeriodAndBiggerThan,
["Key: /" ] = LedId.Keyboard_SlashAndQuestionMark , ["Key: /"] = LedId.Keyboard_SlashAndQuestionMark,
["Key: Caps Lock" ] = LedId.Keyboard_CapsLock , ["Key: Caps Lock"] = LedId.Keyboard_CapsLock,
["Key: F1" ] = LedId.Keyboard_F1 , ["Key: F1"] = LedId.Keyboard_F1,
["Key: F2" ] = LedId.Keyboard_F2 , ["Key: F2"] = LedId.Keyboard_F2,
["Key: F3" ] = LedId.Keyboard_F3 , ["Key: F3"] = LedId.Keyboard_F3,
["Key: F4" ] = LedId.Keyboard_F4 , ["Key: F4"] = LedId.Keyboard_F4,
["Key: F5" ] = LedId.Keyboard_F5 , ["Key: F5"] = LedId.Keyboard_F5,
["Key: F6" ] = LedId.Keyboard_F6 , ["Key: F6"] = LedId.Keyboard_F6,
["Key: F7" ] = LedId.Keyboard_F7 , ["Key: F7"] = LedId.Keyboard_F7,
["Key: F8" ] = LedId.Keyboard_F8 , ["Key: F8"] = LedId.Keyboard_F8,
["Key: F9" ] = LedId.Keyboard_F9 , ["Key: F9"] = LedId.Keyboard_F9,
["Key: F10" ] = LedId.Keyboard_F10 , ["Key: F10"] = LedId.Keyboard_F10,
["Key: F11" ] = LedId.Keyboard_F11 , ["Key: F11"] = LedId.Keyboard_F11,
["Key: F12" ] = LedId.Keyboard_F12 , ["Key: F12"] = LedId.Keyboard_F12,
["Key: Print Screen" ] = LedId.Keyboard_PrintScreen , ["Key: Print Screen"] = LedId.Keyboard_PrintScreen,
["Key: Scroll Lock" ] = LedId.Keyboard_ScrollLock , ["Key: Scroll Lock"] = LedId.Keyboard_ScrollLock,
["Key: Pause/Break" ] = LedId.Keyboard_PauseBreak , ["Key: Pause/Break"] = LedId.Keyboard_PauseBreak,
["Key: Insert" ] = LedId.Keyboard_Insert , ["Key: Insert"] = LedId.Keyboard_Insert,
["Key: Home" ] = LedId.Keyboard_Home , ["Key: Home"] = LedId.Keyboard_Home,
["Key: Page Up" ] = LedId.Keyboard_PageUp , ["Key: Page Up"] = LedId.Keyboard_PageUp,
["Key: Delete" ] = LedId.Keyboard_Delete , ["Key: Delete"] = LedId.Keyboard_Delete,
["Key: End" ] = LedId.Keyboard_End , ["Key: End"] = LedId.Keyboard_End,
["Key: Page Down" ] = LedId.Keyboard_PageDown , ["Key: Page Down"] = LedId.Keyboard_PageDown,
["Key: Right Arrow" ] = LedId.Keyboard_ArrowRight , ["Key: Right Arrow"] = LedId.Keyboard_ArrowRight,
["Key: Left Arrow" ] = LedId.Keyboard_ArrowLeft , ["Key: Left Arrow"] = LedId.Keyboard_ArrowLeft,
["Key: Down Arrow" ] = LedId.Keyboard_ArrowDown , ["Key: Down Arrow"] = LedId.Keyboard_ArrowDown,
["Key: Up Arrow" ] = LedId.Keyboard_ArrowUp , ["Key: Up Arrow"] = LedId.Keyboard_ArrowUp,
["Key: Num Lock" ] = LedId.Keyboard_NumLock , ["Key: Num Lock"] = LedId.Keyboard_NumLock,
["Key: Number Pad /" ] = LedId.Keyboard_NumSlash , ["Key: Number Pad /"] = LedId.Keyboard_NumSlash,
["Key: Number Pad *" ] = LedId.Keyboard_NumAsterisk , ["Key: Number Pad *"] = LedId.Keyboard_NumAsterisk,
["Key: Number Pad -" ] = LedId.Keyboard_NumMinus , ["Key: Number Pad -"] = LedId.Keyboard_NumMinus,
["Key: Number Pad +" ] = LedId.Keyboard_NumPlus , ["Key: Number Pad +"] = LedId.Keyboard_NumPlus,
["Key: Number Pad Enter"] = LedId.Keyboard_NumEnter , ["Key: Number Pad Enter"] = LedId.Keyboard_NumEnter,
["Key: Number Pad 1" ] = LedId.Keyboard_Num1 , ["Key: Number Pad 1"] = LedId.Keyboard_Num1,
["Key: Number Pad 2" ] = LedId.Keyboard_Num2 , ["Key: Number Pad 2"] = LedId.Keyboard_Num2,
["Key: Number Pad 3" ] = LedId.Keyboard_Num3 , ["Key: Number Pad 3"] = LedId.Keyboard_Num3,
["Key: Number Pad 4" ] = LedId.Keyboard_Num4 , ["Key: Number Pad 4"] = LedId.Keyboard_Num4,
["Key: Number Pad 5" ] = LedId.Keyboard_Num5 , ["Key: Number Pad 5"] = LedId.Keyboard_Num5,
["Key: Number Pad 6" ] = LedId.Keyboard_Num6 , ["Key: Number Pad 6"] = LedId.Keyboard_Num6,
["Key: Number Pad 7" ] = LedId.Keyboard_Num7 , ["Key: Number Pad 7"] = LedId.Keyboard_Num7,
["Key: Number Pad 8" ] = LedId.Keyboard_Num8 , ["Key: Number Pad 8"] = LedId.Keyboard_Num8,
["Key: Number Pad 9" ] = LedId.Keyboard_Num9 , ["Key: Number Pad 9"] = LedId.Keyboard_Num9,
["Key: Number Pad 0" ] = LedId.Keyboard_Num0 , ["Key: Number Pad 0"] = LedId.Keyboard_Num0,
["Key: Number Pad ." ] = LedId.Keyboard_NumPeriodAndDelete , ["Key: Number Pad ."] = LedId.Keyboard_NumPeriodAndDelete,
["Key: Left Fn" ] = LedId.Keyboard_Function , ["Key: Left Fn"] = LedId.Keyboard_Function,
["Key: Right Fn" ] = LedId.Keyboard_Function , ["Key: Right Fn"] = LedId.Keyboard_Function,
["Key: \\ (ISO)" ] = LedId.Keyboard_NonUsBackslash , ["Key: \\ (ISO)"] = LedId.Keyboard_NonUsBackslash,
["Key: Menu" ] = LedId.Keyboard_Application , ["Key: Menu"] = LedId.Keyboard_Application,
["Key: Left Control" ] = LedId.Keyboard_LeftCtrl , ["Key: Left Control"] = LedId.Keyboard_LeftCtrl,
["Key: Left Shift" ] = LedId.Keyboard_LeftShift , ["Key: Left Shift"] = LedId.Keyboard_LeftShift,
["Key: Left Alt" ] = LedId.Keyboard_LeftAlt , ["Key: Left Alt"] = LedId.Keyboard_LeftAlt,
["Key: Left Windows" ] = LedId.Keyboard_LeftGui , ["Key: Left Windows"] = LedId.Keyboard_LeftGui,
["Key: Right Control" ] = LedId.Keyboard_RightCtrl , ["Key: Right Control"] = LedId.Keyboard_RightCtrl,
["Key: Right Shift" ] = LedId.Keyboard_RightShift , ["Key: Right Shift"] = LedId.Keyboard_RightShift,
["Key: Right Alt" ] = LedId.Keyboard_RightAlt , ["Key: Right Alt"] = LedId.Keyboard_RightAlt,
["Key: Right Windows" ] = LedId.Keyboard_RightGui , ["Key: Right Windows"] = LedId.Keyboard_RightGui,
["Key: Media Next" ] = LedId.Keyboard_MediaNextTrack , ["Key: Media Next"] = LedId.Keyboard_MediaNextTrack,
["Key: Media Previous" ] = LedId.Keyboard_MediaPreviousTrack , ["Key: Media Previous"] = LedId.Keyboard_MediaPreviousTrack,
["Key: Media Stop" ] = LedId.Keyboard_MediaStop , ["Key: Media Stop"] = LedId.Keyboard_MediaStop,
["Key: Media Pause" ] = LedId.Keyboard_MediaPlay , ["Key: Media Pause"] = LedId.Keyboard_MediaPlay,
["Key: Media Play" ] = LedId.Keyboard_MediaPlay , ["Key: Media Play"] = LedId.Keyboard_MediaPlay,
["Key: Media Play/Pause"] = LedId.Keyboard_MediaPlay , ["Key: Media Play/Pause"] = LedId.Keyboard_MediaPlay,
["Key: Media Mute" ] = LedId.Keyboard_MediaMute , ["Key: Media Mute"] = LedId.Keyboard_MediaMute,
["Logo" ] = LedId.Logo , ["Logo"] = LedId.Logo,
["Key: Brightness" ] = LedId.Keyboard_Brightness , ["Key: Brightness"] = LedId.Keyboard_Brightness,
["Key: M1" ] = LedId.Keyboard_Macro1 , ["Key: M1"] = LedId.Keyboard_Macro1,
["Key: M2" ] = LedId.Keyboard_Macro2 , ["Key: M2"] = LedId.Keyboard_Macro2,
["Key: M3" ] = LedId.Keyboard_Macro3 , ["Key: M3"] = LedId.Keyboard_Macro3,
["Key: M4" ] = LedId.Keyboard_Macro4 , ["Key: M4"] = LedId.Keyboard_Macro4,
["Key: M5" ] = LedId.Keyboard_Macro5 , ["Key: M5"] = LedId.Keyboard_Macro5,
["Key: G1" ] = LedId.Keyboard_Programmable1 , ["Key: G1"] = LedId.Keyboard_Programmable1,
["Key: G2" ] = LedId.Keyboard_Programmable2 , ["Key: G2"] = LedId.Keyboard_Programmable2,
["Key: G3" ] = LedId.Keyboard_Programmable3 , ["Key: G3"] = LedId.Keyboard_Programmable3,
["Key: G4" ] = LedId.Keyboard_Programmable4 , ["Key: G4"] = LedId.Keyboard_Programmable4,
["Key: G5" ] = LedId.Keyboard_Programmable5 , ["Key: G5"] = LedId.Keyboard_Programmable5,
["Key: G6" ] = LedId.Keyboard_Programmable6 , ["Key: G6"] = LedId.Keyboard_Programmable6,
["Key: G7" ] = LedId.Keyboard_Programmable7 , ["Key: G7"] = LedId.Keyboard_Programmable7,
["Key: G8" ] = LedId.Keyboard_Programmable8 , ["Key: G8"] = LedId.Keyboard_Programmable8,
["Key: G9" ] = LedId.Keyboard_Programmable9 , ["Key: G9"] = LedId.Keyboard_Programmable9,
["Lighting" ] = LedId.Keyboard_Brightness , ["Lighting"] = LedId.Keyboard_Brightness,
["Game Mode" ] = LedId.Keyboard_WinLock , ["Game Mode"] = LedId.Keyboard_WinLock,
}; };
} }

View File

@ -1,11 +1,12 @@
using OpenRGB.NET.Enums; using OpenRGB.NET.Enums;
using RGB.NET.Core; using RGB.NET.Core;
namespace RGB.NET.Devices.OpenRGB.Generic; namespace RGB.NET.Devices.OpenRGB;
/// <inheritdoc /> /// <inheritdoc />
public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo> public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
{ {
#region Constructors
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="OpenRGBGenericDevice"/> class. /// Initializes a new instance of the <see cref="OpenRGBGenericDevice"/> class.
/// </summary> /// </summary>
@ -17,6 +18,10 @@ public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
InitializeLayout(); InitializeLayout();
} }
#endregion
#region Methods
/// <summary> /// <summary>
/// Initializes the LEDs of the device based on the data provided by the SDK. /// Initializes the LEDs of the device based on the data provided by the SDK.
/// </summary> /// </summary>
@ -25,9 +30,9 @@ public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
LedId initial = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType); LedId initial = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType);
int y = 0; int y = 0;
Size ledSize = new Size(19); Size ledSize = new(19);
int zoneLedIndex = 0; int zoneLedIndex = 0;
const int ledSpacing = 20; const int LED_SPACING = 20;
foreach (global::OpenRGB.NET.Models.Zone? zone in DeviceInfo.OpenRGBDevice.Zones) foreach (global::OpenRGB.NET.Models.Zone? zone in DeviceInfo.OpenRGBDevice.Zones)
{ {
@ -43,18 +48,18 @@ public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
if (index == uint.MaxValue) if (index == uint.MaxValue)
continue; continue;
LedId ledId = LedMappings.Default.TryGetValue(DeviceInfo.OpenRGBDevice.Leds[zoneLedIndex + index].Name, out LedId l) LedId ledId = LedMappings.DEFAULT.TryGetValue(DeviceInfo.OpenRGBDevice.Leds[zoneLedIndex + index].Name, out LedId id)
? l ? id
: initial++; : initial++;
//HACK: doing this because some different Led Names are mapped to the same LedId //HACK: doing this because some different Led Names are mapped to the same LedId
//for example, "Enter" and "ISO Enter". //for example, "Enter" and "ISO Enter".
//this way, at least they'll be controllable as CustomX //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++; ledId = initial++;
} }
} }
y += (int)(zone.MatrixMap.Height * ledSpacing); y += (int)(zone.MatrixMap.Height * LED_SPACING);
} }
else else
{ {
@ -62,15 +67,17 @@ public class OpenRGBGenericDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
{ {
LedId ledId = initial++; 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++; ledId = initial++;
} }
} }
//we'll just set each zone in its own row for now, //we'll just set each zone in its own row for now,
//with each led for that zone being horizontally distributed //with each led for that zone being horizontally distributed
y += ledSpacing; y += LED_SPACING;
zoneLedIndex += (int)zone.LedCount; zoneLedIndex += (int)zone.LedCount;
} }
} }
#endregion
} }

View File

@ -14,11 +14,13 @@ namespace RGB.NET.Devices.OpenRGB;
public class OpenRGBUpdateQueue : UpdateQueue public class OpenRGBUpdateQueue : UpdateQueue
{ {
#region Properties & Fields #region Properties & Fields
private readonly int _deviceid; private readonly int _deviceid;
private readonly OpenRGBClient _openRGB; private readonly OpenRGBClient _openRGB;
private readonly OpenRGBDevice _device; private readonly OpenRGBDevice _device;
private readonly OpenRGBColor[] _colors; private readonly OpenRGBColor[] _colors;
#endregion #endregion
#region Constructors #region Constructors
@ -33,9 +35,10 @@ public class OpenRGBUpdateQueue : UpdateQueue
public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceid, OpenRGBClient client, OpenRGBDevice device) public OpenRGBUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceid, OpenRGBClient client, OpenRGBDevice device)
: base(updateTrigger) : base(updateTrigger)
{ {
_deviceid = deviceid; this._deviceid = deviceid;
_openRGB = client; this._openRGB = client;
_device = device; this._device = device;
_colors = Enumerable.Range(0, _device.Colors.Length) _colors = Enumerable.Range(0, _device.Colors.Length)
.Select(_ => new OpenRGBColor()) .Select(_ => new OpenRGBColor())
.ToArray(); .ToArray();
@ -49,9 +52,7 @@ public class OpenRGBUpdateQueue : UpdateQueue
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet) protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
foreach ((object key, Color color) in dataSet) foreach ((object key, Color color) in dataSet)
{
_colors[(int)key] = new OpenRGBColor(color.GetR(), color.GetG(), color.GetB()); _colors[(int)key] = new OpenRGBColor(color.GetR(), color.GetG(), color.GetB());
}
_openRGB.UpdateLeds(_deviceid, _colors); _openRGB.UpdateLeds(_deviceid, _colors);
} }

View File

@ -6,48 +6,50 @@ namespace RGB.NET.Devices.OpenRGB;
internal static class Helper 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, RGBDeviceType.Mouse => LedId.Mouse1,
RGBDeviceType.Mousepad => LedId.Mousepad1, RGBDeviceType.Headset => LedId.Headset1,
RGBDeviceType.LedStripe => LedId.LedStripe1, RGBDeviceType.Mousepad => LedId.Mousepad1,
RGBDeviceType.LedMatrix => LedId.LedMatrix1, RGBDeviceType.LedStripe => LedId.LedStripe1,
RGBDeviceType.Mainboard => LedId.Mainboard1, RGBDeviceType.LedMatrix => LedId.LedMatrix1,
RGBDeviceType.GraphicsCard => LedId.GraphicsCard1, RGBDeviceType.Mainboard => LedId.Mainboard1,
RGBDeviceType.DRAM => LedId.DRAM1, RGBDeviceType.GraphicsCard => LedId.GraphicsCard1,
RGBDeviceType.HeadsetStand => LedId.HeadsetStand1, RGBDeviceType.DRAM => LedId.DRAM1,
RGBDeviceType.Keypad => LedId.Keypad1, RGBDeviceType.HeadsetStand => LedId.HeadsetStand1,
RGBDeviceType.Fan => LedId.Fan1, RGBDeviceType.Keypad => LedId.Keypad1,
RGBDeviceType.Speaker => LedId.Speaker1, RGBDeviceType.Fan => LedId.Fan1,
RGBDeviceType.Cooler => LedId.Cooler1, RGBDeviceType.Speaker => LedId.Speaker1,
RGBDeviceType.Keyboard => LedId.Keyboard_Custom1, RGBDeviceType.Cooler => LedId.Cooler1,
_ => LedId.Custom1 RGBDeviceType.Keyboard => LedId.Keyboard_Custom1,
}; _ => 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, DeviceType.Motherboard => RGBDeviceType.Mainboard,
DeviceType.Gpu => RGBDeviceType.GraphicsCard, DeviceType.Dram => RGBDeviceType.DRAM,
DeviceType.Cooler => RGBDeviceType.Cooler, DeviceType.Gpu => RGBDeviceType.GraphicsCard,
DeviceType.Ledstrip => RGBDeviceType.LedStripe, DeviceType.Cooler => RGBDeviceType.Cooler,
DeviceType.Keyboard => RGBDeviceType.Keyboard, DeviceType.Ledstrip => RGBDeviceType.LedStripe,
DeviceType.Mouse => RGBDeviceType.Mouse, DeviceType.Keyboard => RGBDeviceType.Keyboard,
DeviceType.Mousemat => RGBDeviceType.Mousepad, DeviceType.Mouse => RGBDeviceType.Mouse,
DeviceType.Headset => RGBDeviceType.Headset, DeviceType.Mousemat => RGBDeviceType.Mousepad,
DeviceType.HeadsetStand => RGBDeviceType.HeadsetStand, DeviceType.Headset => RGBDeviceType.Headset,
_ => RGBDeviceType.Unknown DeviceType.HeadsetStand => RGBDeviceType.HeadsetStand,
}; _ => RGBDeviceType.Unknown
};
public static LedId GetInitialLedIdForDeviceType(DeviceType type) => public static LedId GetInitialLedIdForDeviceType(DeviceType type)
GetInitialLedIdForDeviceType(GetRgbNetDeviceType(type)); => GetInitialLedIdForDeviceType(GetRgbNetDeviceType(type));
public static string GetVendorName(OpenRGBDevice openRGBDevice) => string.IsNullOrWhiteSpace(openRGBDevice.Vendor) public static string GetVendorName(OpenRGBDevice openRGBDevice) => string.IsNullOrWhiteSpace(openRGBDevice.Vendor)
? "OpenRGB" ? "OpenRGB"
: openRGBDevice.Vendor; : openRGBDevice.Vendor;
public static string GetModelName(OpenRGBDevice openRGBDevice) => string.IsNullOrWhiteSpace(openRGBDevice.Vendor) public static string GetModelName(OpenRGBDevice openRGBDevice) => string.IsNullOrWhiteSpace(openRGBDevice.Vendor)
? openRGBDevice.Name ? openRGBDevice.Name
: openRGBDevice.Name.Replace(openRGBDevice.Vendor, "").Trim(); : openRGBDevice.Name.Replace(openRGBDevice.Vendor, "").Trim();
} }

View File

@ -1,7 +1,6 @@
using OpenRGB.NET; using OpenRGB.NET;
using OpenRGB.NET.Models; using OpenRGB.NET.Models;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.OpenRGB.Generic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -16,7 +15,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
{ {
#region Properties & Fields #region Properties & Fields
private readonly List<OpenRGBClient> _clients = new List<OpenRGBClient>(); private readonly List<OpenRGBClient> _clients = new();
private static OpenRGBDeviceProvider? _instance; private static OpenRGBDeviceProvider? _instance;
@ -28,7 +27,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
/// </summary> /// </summary>
public List<OpenRGBServerDefinition> DeviceDefinitions { get; } = new List<OpenRGBServerDefinition>(); public List<OpenRGBServerDefinition> DeviceDefinitions { get; } = new();
/// <summary> /// <summary>
/// Indicates whether all devices will be added, or just the ones with a 'Direct' mode. Defaults to false. /// 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 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); _clients.Add(openRgb);
deviceDefinition.Connected = true; deviceDefinition.Connected = true;
} }
@ -72,11 +71,11 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
{ {
deviceDefinition.Connected = false; deviceDefinition.Connected = false;
deviceDefinition.LastError = e.Message; deviceDefinition.LastError = e.Message;
Throw(e, false); Throw(e);
} }
} }
} }
/// <inheritdoc /> /// <inheritdoc />
protected override IEnumerable<IRGBDevice> LoadDevices() protected override IEnumerable<IRGBDevice> LoadDevices()
{ {
@ -88,7 +87,7 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
{ {
Device? device = openRgb.GetControllerData(i); 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) if (directModeIndex != -1)
{ {
//set the device to direct mode if it has it //set the device to direct mode if it has it
@ -101,27 +100,21 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
continue; continue;
} }
OpenRGBUpdateQueue? updateQueue = new OpenRGBUpdateQueue(GetUpdateTrigger(), i, openRgb, device); OpenRGBUpdateQueue? updateQueue = new(GetUpdateTrigger(), i, openRgb, device);
if (PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type))) if (PerZoneDeviceFlag.HasFlag(Helper.GetRgbNetDeviceType(device.Type)))
{ {
int totalLedCount = 0; 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]; {
yield return new OpenRGBZoneDevice(new OpenRGBDeviceInfo(device), totalLedCount, zone, updateQueue);
if (zone.LedCount == 0) totalLedCount += (int)zone.LedCount;
continue; }
yield return new OpenRGBZoneDevice(new OpenRGBDeviceInfo(device), totalLedCount, zone, updateQueue);
totalLedCount += (int)zone.LedCount;
}
} }
else else
{
yield return new OpenRGBGenericDevice(new OpenRGBDeviceInfo(device), updateQueue); yield return new OpenRGBGenericDevice(new OpenRGBDeviceInfo(device), updateQueue);
}
} }
} }
} }
@ -131,9 +124,9 @@ public class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
{ {
base.Dispose(); base.Dispose();
foreach (OpenRGBClient? client in _clients) foreach (OpenRGBClient client in _clients)
{ {
try { client?.Dispose(); } try { client.Dispose(); }
catch { /* at least we tried */ } catch { /* at least we tried */ }
} }

View File

@ -7,9 +7,15 @@ namespace RGB.NET.Devices.OpenRGB;
/// <inheritdoc /> /// <inheritdoc />
public class OpenRGBZoneDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo> public class OpenRGBZoneDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
{ {
#region Properties & Fields
private readonly int _initialLed; private readonly int _initialLed;
private readonly Zone _zone; private readonly Zone _zone;
#endregion
#region Constructors
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="OpenRGBZoneDevice"/> class. /// Initializes a new instance of the <see cref="OpenRGBZoneDevice"/> class.
/// </summary> /// </summary>
@ -26,11 +32,15 @@ public class OpenRGBZoneDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
InitializeLayout(); InitializeLayout();
} }
#endregion
#region Methods
private void InitializeLayout() private void InitializeLayout()
{ {
Size ledSize = new Size(19); Size ledSize = new(19);
const int ledSpacing = 20; const int LED_SPACING = 20;
LedId initial = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType) + _initialLed; LedId initialId = Helper.GetInitialLedIdForDeviceType(DeviceInfo.DeviceType) + _initialLed;
if (_zone.Type == ZoneType.Matrix) if (_zone.Type == ZoneType.Matrix)
{ {
@ -44,12 +54,12 @@ public class OpenRGBZoneDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
if (index == uint.MaxValue) if (index == uint.MaxValue)
continue; continue;
LedId ledId = LedMappings.Default.TryGetValue(DeviceInfo.OpenRGBDevice.Leds[_initialLed + index].Name, out LedId l) LedId ledId = LedMappings.DEFAULT.TryGetValue(DeviceInfo.OpenRGBDevice.Leds[_initialLed + index].Name, out LedId id)
? l ? id
: initial++; : initialId++;
while (AddLed(ledId, new Point(ledSpacing * column, ledSpacing * row), ledSize, _initialLed + (int)index) == null) while (AddLed(ledId, new Point(LED_SPACING * column, LED_SPACING * row), ledSize, _initialLed + (int)index) == null)
ledId = initial++; ledId = initialId++;
} }
} }
} }
@ -57,11 +67,13 @@ public class OpenRGBZoneDevice : AbstractOpenRGBDevice<OpenRGBDeviceInfo>
{ {
for (int i = 0; i < _zone.LedCount; i++) 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) while (AddLed(ledId, new Point(LED_SPACING * i, 0), ledSize, _initialLed + i) == null)
ledId = initial++; ledId = initialId++;
} }
} }
} }
#endregion
} }

View File

@ -1,63 +1,65 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net5.0</TargetFrameworks> <TargetFrameworks>net6.0;net5.0</TargetFrameworks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Authors>diogotr7</Authors> <Authors>diogotr7</Authors>
<Company>Wyrez</Company> <Company>Wyrez</Company>
<Language>en-US</Language> <Language>en-US</Language>
<NeutralLanguage>en-US</NeutralLanguage> <NeutralLanguage>en-US</NeutralLanguage>
<Title>RGB.NET.Devices.OpenRGB</Title> <Title>RGB.NET.Devices.OpenRGB</Title>
<AssemblyName>RGB.NET.Devices.OpenRGB</AssemblyName> <AssemblyName>RGB.NET.Devices.OpenRGB</AssemblyName>
<AssemblyTitle>RGB.NET.Devices.OpenRGB</AssemblyTitle> <AssemblyTitle>RGB.NET.Devices.OpenRGB</AssemblyTitle>
<PackageId>RGB.NET.Devices.OpenRGB</PackageId> <PackageId>RGB.NET.Devices.OpenRGB</PackageId>
<RootNamespace>RGB.NET.Devices.OpenRGB</RootNamespace> <RootNamespace>RGB.NET.Devices.OpenRGB</RootNamespace>
<Description>OpenRGB-Device-Implementations of RGB.NET</Description> <Description>OpenRGB-Device-Implementations of RGB.NET</Description>
<Summary>OpenRGB-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals</Summary> <Summary>OpenRGB-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals</Summary>
<Copyright>Copyright © Darth Affe 2022</Copyright> <Copyright>Copyright © Darth Affe 2022</Copyright>
<PackageCopyright>Copyright © Darth Affe 2022</PackageCopyright> <PackageCopyright>Copyright © Darth Affe 2022</PackageCopyright>
<PackageIcon>icon.png</PackageIcon> <PackageIcon>icon.png</PackageIcon>
<PackageProjectUrl>https://github.com/DarthAffe/RGB.NET</PackageProjectUrl> <PackageProjectUrl>https://github.com/DarthAffe/RGB.NET</PackageProjectUrl>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression> <PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<RepositoryType>Github</RepositoryType> <RepositoryType>Github</RepositoryType>
<RepositoryUrl>https://github.com/DarthAffe/RGB.NET</RepositoryUrl> <RepositoryUrl>https://github.com/DarthAffe/RGB.NET</RepositoryUrl>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>0.0.1</Version> <PackageReleaseNotes></PackageReleaseNotes>
<AssemblyVersion>0.0.1</AssemblyVersion>
<FileVersion>0.0.1</FileVersion>
<OutputPath>..\bin\</OutputPath> <Version>0.0.1</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <AssemblyVersion>0.0.1</AssemblyVersion>
<IncludeSource>True</IncludeSource> <FileVersion>0.0.1</FileVersion>
<IncludeSymbols>True</IncludeSymbols>
<DebugType>portable</DebugType>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'"> <OutputPath>..\bin\</OutputPath>
<DefineConstants>$(DefineConstants);TRACE;DEBUG</DefineConstants> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<DebugSymbols>true</DebugSymbols> <IncludeSource>True</IncludeSource>
<Optimize>false</Optimize> <IncludeSymbols>True</IncludeSymbols>
</PropertyGroup> <DebugType>portable</DebugType>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'"> <PropertyGroup Condition="'$(Configuration)'=='Debug'">
<Optimize>true</Optimize> <DefineConstants>$(DefineConstants);TRACE;DEBUG</DefineConstants>
<NoWarn>$(NoWarn);CS1591;CS1572;CS1573</NoWarn> <DebugSymbols>true</DebugSymbols>
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants> <Optimize>false</Optimize>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <PropertyGroup Condition="'$(Configuration)' == 'Release'">
<Content Include="..\Resources\icon.png" Link="icon.png" Pack="true" PackagePath="\" /> <Optimize>true</Optimize>
</ItemGroup> <NoWarn>$(NoWarn);CS1591;CS1572;CS1573</NoWarn>
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="OpenRGB.NET" Version="1.7.0" /> <Content Include="..\Resources\icon.png" Link="icon.png" Pack="true" PackagePath="\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" /> <PackageReference Include="OpenRGB.NET" Version="1.7.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -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>