1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Merge pull request #430 from DarthAffe/Development

This commit is contained in:
DarthAffe 2025-07-17 21:39:16 +02:00 committed by GitHub
commit b0acc61618
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 454 additions and 140 deletions

View File

@ -273,7 +273,12 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
break; break;
case CorsairChannelDeviceType.EightLedSeriesFan: case CorsairChannelDeviceType.EightLedSeriesFan:
yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "8-Led-Series Fan Fan"), updateQueue); string fanModelName = "8-Led-Series Fan";
if (device.model == "iCUE LINK System Hub")
fanModelName = "RX Fan";
yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, fanModelName), updateQueue);
break; break;
case CorsairChannelDeviceType.DAP: case CorsairChannelDeviceType.DAP:
@ -289,20 +294,20 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
break; break;
case CorsairChannelDeviceType.Strip: case CorsairChannelDeviceType.Strip:
string modelName = "LED Strip"; string stripModelName = "LED Strip";
// LS100 Led Strips are reported as one big strip if configured in monitor mode in iCUE, 138 LEDs for dual monitor, 84 for single // LS100 Led Strips are reported as one big strip if configured in monitor mode in iCUE, 138 LEDs for dual monitor, 84 for single
if ((device.model == "LS100 Starter Kit") && (ledCount == 138)) if ((device.model == "LS100 Starter Kit") && (ledCount == 138))
modelName = "LS100 LED Strip (dual monitor)"; stripModelName = "LS100 LED Strip (dual monitor)";
else if ((device.model == "LS100 Starter Kit") && (ledCount == 84)) else if ((device.model == "LS100 Starter Kit") && (ledCount == 84))
modelName = "LS100 LED Strip (single monitor)"; stripModelName = "LS100 LED Strip (single monitor)";
// Any other value means an "External LED Strip" in iCUE, these are reported per-strip, 15 for short strips, 27 for long // Any other value means an "External LED Strip" in iCUE, these are reported per-strip, 15 for short strips, 27 for long
else if ((device.model == "LS100 Starter Kit") && (ledCount == 15)) else if ((device.model == "LS100 Starter Kit") && (ledCount == 15))
modelName = "LS100 LED Strip (short)"; stripModelName = "LS100 LED Strip (short)";
else if ((device.model == "LS100 Starter Kit") && (ledCount == 27)) else if ((device.model == "LS100 Starter Kit") && (ledCount == 27))
modelName = "LS100 LED Strip (long)"; stripModelName = "LS100 LED Strip (long)";
yield return new CorsairLedStripRGBDevice(new CorsairLedStripRGBDeviceInfo(device, ledCount, offset, modelName), updateQueue); yield return new CorsairLedStripRGBDevice(new CorsairLedStripRGBDeviceInfo(device, ledCount, offset, stripModelName), updateQueue);
break; break;
case CorsairChannelDeviceType.DRAM: case CorsairChannelDeviceType.DRAM:
@ -310,7 +315,12 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
break; break;
default: default:
Throw(new RGBDeviceException("Unknown Device-Type"));
//Workaround to support LX Fans because they have an invalid ChannelDeviceType
if ((device.model == "iCUE LINK System Hub") && (ledCount == 18))
yield return new CorsairFanRGBDevice(new CorsairFanRGBDeviceInfo(device, ledCount, offset, "LX Fan"), updateQueue);
else
Throw(new RGBDeviceException("Unknown Device-Type"));
break; break;
} }

View File

@ -73,6 +73,7 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
{ 0xC541, RGBDeviceType.Keyboard, "G915", LedMappings.PerKey, 0 }, { 0xC541, RGBDeviceType.Keyboard, "G915", LedMappings.PerKey, 0 },
{ 0xC359, RGBDeviceType.Keyboard, "G915 X", LedMappings.PerKey, 0 }, { 0xC359, RGBDeviceType.Keyboard, "G915 X", LedMappings.PerKey, 0 },
{ 0xC547, RGBDeviceType.Keyboard, "G915 X TKL", LedMappings.PerKey, 0 }, { 0xC547, RGBDeviceType.Keyboard, "G915 X TKL", LedMappings.PerKey, 0 },
{ 0xC358, RGBDeviceType.Keyboard, "G515", LedMappings.PerKey, 0 },
//non-rgb //non-rgb
{ 0xC333, RGBDeviceType.Keyboard, "G610", LedMappings.PerKey, 0 }, { 0xC333, RGBDeviceType.Keyboard, "G610", LedMappings.PerKey, 0 },

View File

@ -151,9 +151,11 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ 0x02A0, RGBDeviceType.Keyboard, "Blade 18", LedMappings.Blade, RazerEndpointType.Keyboard }, { 0x02A0, RGBDeviceType.Keyboard, "Blade 18", LedMappings.Blade, RazerEndpointType.Keyboard },
{ 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x02A1, RGBDeviceType.Keyboard, "Ornata V3", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x02A5, RGBDeviceType.Keyboard, "BlackWidow V4 75%", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x02A5, RGBDeviceType.Keyboard, "BlackWidow V4 75%", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x02A6, RGBDeviceType.Keyboard, "Huntsman V3 Pro", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x02A7, RGBDeviceType.Keyboard, "Huntsman V3 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x02A7, RGBDeviceType.Keyboard, "Huntsman V3 Pro TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x0A24, RGBDeviceType.Keyboard, "BlackWidow V3 TKL", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x02BA, RGBDeviceType.Keyboard, "BlackWidow V4 Mini HyperSpeed", LedMappings.Keyboard, RazerEndpointType.Keyboard }, { 0x02BA, RGBDeviceType.Keyboard, "BlackWidow V4 Mini HyperSpeed", LedMappings.Keyboard, RazerEndpointType.Keyboard },
{ 0x02B4, RGBDeviceType.Keyboard, "BlackWidow V4 Pro 75%", LedMappings.Keyboard, RazerEndpointType.Keyboard },
// Mice // Mice
{ 0x0013, RGBDeviceType.Mouse, "Orochi 2011", LedMappings.Mouse, RazerEndpointType.Mouse }, { 0x0013, RGBDeviceType.Mouse, "Orochi 2011", LedMappings.Mouse, RazerEndpointType.Mouse },
@ -255,6 +257,8 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
{ 0x0527, RGBDeviceType.Headset, "Kraken Ultimate", LedMappings.Headset, RazerEndpointType.Headset }, { 0x0527, RGBDeviceType.Headset, "Kraken Ultimate", LedMappings.Headset, RazerEndpointType.Headset },
{ 0x0560, RGBDeviceType.Headset, "Kraken Kitty V2", LedMappings.Headset, RazerEndpointType.Headset }, { 0x0560, RGBDeviceType.Headset, "Kraken Kitty V2", LedMappings.Headset, RazerEndpointType.Headset },
{ 0x0F19, RGBDeviceType.Headset, "Kraken Kitty Edition", LedMappings.Headset, RazerEndpointType.Headset }, { 0x0F19, RGBDeviceType.Headset, "Kraken Kitty Edition", LedMappings.Headset, RazerEndpointType.Headset },
{ 0X0533, RGBDeviceType.Headset, "Kraken V3 HyperSense", LedMappings.Headset, RazerEndpointType.Headset},
{ 0X0574, RGBDeviceType.Headset, "Barracuda X Chroma", LedMappings.Headset, RazerEndpointType.Headset},
// Keypads // Keypads
{ 0x0111, RGBDeviceType.Keypad, "Nostromo", LedMappings.Keypad, RazerEndpointType.Keypad }, { 0x0111, RGBDeviceType.Keypad, "Nostromo", LedMappings.Keypad, RazerEndpointType.Keypad },

View File

@ -96,6 +96,7 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider
//Mousepads //Mousepads
{ 0x1507, RGBDeviceType.Mousepad, "QCK Prism", LedMappings.MousepadTwelveZone, SteelSeriesDeviceType.TwelveZone }, { 0x1507, RGBDeviceType.Mousepad, "QCK Prism", LedMappings.MousepadTwelveZone, SteelSeriesDeviceType.TwelveZone },
{ 0x150D, RGBDeviceType.Mousepad, "QCK Prism Cloth", LedMappings.MousepadTwoZone, SteelSeriesDeviceType.TwoZone }, { 0x150D, RGBDeviceType.Mousepad, "QCK Prism Cloth", LedMappings.MousepadTwoZone, SteelSeriesDeviceType.TwoZone },
{ 0x1516, RGBDeviceType.Mousepad, "QCK Prism Cloth 3XL", LedMappings.MousepadTwoZone, SteelSeriesDeviceType.TwoZone },
//Monitors //Monitors
{ 0x1126, RGBDeviceType.Monitor, "MGP27C", LedMappings.MonitorOnehundredandthreeZone, SteelSeriesDeviceType.OneHundredAndThreeZone }, { 0x1126, RGBDeviceType.Monitor, "MGP27C", LedMappings.MonitorOnehundredandthreeZone, SteelSeriesDeviceType.OneHundredAndThreeZone },

View File

@ -15,5 +15,8 @@ public enum WootingLayoutType
{ {
Unknown = -1, Unknown = -1,
ANSI = 0, ANSI = 0,
ISO = 1 ISO = 1,
JIS = 2,
ANSI_SPLIT_SPACEBAR = 3,
ISO_SPLIT_SPACEBAR = 4,
} }

View File

@ -11,6 +11,10 @@ namespace RGB.NET.Devices.Wooting.Generic;
/// </summary> /// </summary>
internal static class WootingLedMappings internal static class WootingLedMappings
{ {
public const int ROWS = 6;
public const int COLUMNS = 21;
#region Properties & Fields #region Properties & Fields
private static readonly Dictionary<LedId, (int row, int column)> TKL = new() private static readonly Dictionary<LedId, (int row, int column)> TKL = new()
@ -126,7 +130,7 @@ internal static class WootingLedMappings
{ LedId.Keyboard_F10, (0, 11) }, { LedId.Keyboard_F10, (0, 11) },
{ LedId.Keyboard_F11, (0, 12) }, { LedId.Keyboard_F11, (0, 12) },
{ LedId.Keyboard_F12, (0, 13) }, { LedId.Keyboard_F12, (0, 13) },
{ LedId.Keyboard_Custom1, (0, 14) }, { LedId.Keyboard_Profile, (0, 14) },
{ LedId.Keyboard_PrintScreen, (0, 15) }, { LedId.Keyboard_PrintScreen, (0, 15) },
{ LedId.Keyboard_PauseBreak, (0, 16) }, { LedId.Keyboard_PauseBreak, (0, 16) },
@ -200,7 +204,11 @@ internal static class WootingLedMappings
{ LedId.Keyboard_LeftGui, (5, 1) }, { LedId.Keyboard_LeftGui, (5, 1) },
{ LedId.Keyboard_LeftAlt, (5, 2) }, { LedId.Keyboard_LeftAlt, (5, 2) },
{ LedId.Keyboard_International3, (5, 3) },//JIS key { LedId.Keyboard_International3, (5, 3) },//JIS key
{ LedId.Keyboard_Custom1, (5, 4) },
{ LedId.Keyboard_Custom2, (5, 5) },
{ LedId.Keyboard_Space, (5, 6) }, { LedId.Keyboard_Space, (5, 6) },
{ LedId.Keyboard_Custom3, (5, 7) },
{ LedId.Keyboard_Custom4, (5, 8) },
{ LedId.Keyboard_International4, (5, 9) },//JIS key { LedId.Keyboard_International4, (5, 9) },//JIS key
{ LedId.Keyboard_RightAlt, (5, 10) }, { LedId.Keyboard_RightAlt, (5, 10) },
{ LedId.Keyboard_RightGui, (5, 11) }, { LedId.Keyboard_RightGui, (5, 11) },

View File

@ -1,37 +1,44 @@
using RGB.NET.Core; using System.Collections.Generic;
using RGB.NET.Devices.Wooting.Native; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum;
namespace RGB.NET.Devices.Wooting.Generic; namespace RGB.NET.Devices.Wooting.Generic;
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
/// <inheritdoc cref="IWootingRGBDevice" />
/// <summary>
/// Represents a Wooting-device
/// </summary>
public abstract class WootingRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, IWootingRGBDevice public abstract class WootingRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, IWootingRGBDevice
where TDeviceInfo : WootingRGBDeviceInfo where TDeviceInfo : WootingRGBDeviceInfo
{ {
#region Properties & Fields
private readonly Dictionary<LedId, (int row, int column)> _mapping;
#endregion
#region Constructors #region Constructors
/// <summary> internal WootingRGBDevice(WootingDeviceType deviceType, TDeviceInfo info, IUpdateQueue updateQueue)
/// Initializes a new instance of the <see cref="WootingRGBDevice{TDeviceInfo}"/> class.
/// </summary>
/// <param name="info">The generic information provided by Wooting for the device.</param>
/// <param name="updateQueue">The update queue used to update this device.</param>
protected WootingRGBDevice(TDeviceInfo info, IUpdateQueue updateQueue)
: base(info, updateQueue) : base(info, updateQueue)
{ {
_mapping = WootingLedMappings.Mapping[deviceType];
InitializeLayout();
} }
#endregion #endregion
#region Methods #region Methods
private void InitializeLayout()
{
foreach (KeyValuePair<LedId, (int row, int column)> led in _mapping)
AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
}
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => _mapping[ledId];
/// <inheritdoc />
public override void Dispose() public override void Dispose()
{ {
_WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex); UpdateQueue.Dispose();
_WootingSDK.Reset();
base.Dispose(); base.Dispose();
} }

View File

@ -1,14 +1,8 @@
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum;
using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting.Generic; namespace RGB.NET.Devices.Wooting.Generic;
/// <inheritdoc /> public abstract class WootingRGBDeviceInfo : IRGBDeviceInfo
/// <summary>
/// Represents a generic information for a Wooting-<see cref="T:RGB.NET.Core.IRGBDevice" />.
/// </summary>
public class WootingRGBDeviceInfo : IRGBDeviceInfo
{ {
#region Properties & Fields #region Properties & Fields
@ -27,36 +21,15 @@ public class WootingRGBDeviceInfo : IRGBDeviceInfo
/// <inheritdoc /> /// <inheritdoc />
public object? LayoutMetadata { get; set; } public object? LayoutMetadata { get; set; }
/// <summary>
/// Gets the <see cref="Enum.WootingDeviceType"/> of the <see cref="WootingRGBDevice{TDeviceInfo}"/>.
/// </summary>
public WootingDeviceType WootingDeviceType { get; }
/// <summary>
/// Gets the <see cref="Enum.WootingLayoutType"/> of the <see cref="WootingRGBDevice{TDeviceInfo}"/>.
/// </summary>
public WootingLayoutType WootingLayoutType { get; }
public byte WootingDeviceIndex { get; }
#endregion #endregion
#region Constructors #region Constructors
/// <summary> protected WootingRGBDeviceInfo(RGBDeviceType deviceType, string model, string name)
/// Internal constructor of managed <see cref="WootingRGBDeviceInfo"/>.
/// </summary>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="deviceInfo">The <see cref="_WootingDeviceInfo"/> of the <see cref="IRGBDevice"/>.</param>
internal WootingRGBDeviceInfo(RGBDeviceType deviceType, _WootingDeviceInfo deviceInfo, byte deviceIndex)
{ {
this.DeviceType = deviceType; this.DeviceType = deviceType;
this.WootingDeviceType = deviceInfo.DeviceType; this.Model = model;
this.WootingLayoutType = deviceInfo.LayoutType; this.DeviceName = name;
this.WootingDeviceIndex = deviceIndex;
Model = deviceInfo.Model;
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
} }
#endregion #endregion

View File

@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Grpc.Net.Client;
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum;
using RGB.NET.Devices.Wooting.Keyboard;
using RGB.NET.Devices.Wooting.Keypad;
using WootingRgbSdk;
namespace RGB.NET.Devices.Wooting.Grpc;
/// <inheritdoc />
/// <summary>
/// Represents a device provider responsible for Wooting devices.
/// </summary>
public sealed class WootingGrpcDeviceProvider : AbstractRGBDeviceProvider
{
#region Properties & Fields
// ReSharper disable once InconsistentNaming
private static readonly Lock _lock = new();
private GrpcChannel? _channel;
private RgbSdkService.RgbSdkServiceClient? _client;
private static WootingGrpcDeviceProvider? _instance;
/// <summary>
/// Gets the singleton <see cref="WootingGrpcDeviceProvider"/> instance.
/// </summary>
public static WootingGrpcDeviceProvider Instance
{
get
{
lock (_lock)
return _instance ?? new WootingGrpcDeviceProvider();
}
}
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="WootingGrpcDeviceProvider"/> class.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public WootingGrpcDeviceProvider()
{
lock (_lock)
{
if (_instance != null)
throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingGrpcDeviceProvider)}");
_instance = this;
}
}
#endregion
#region Methods
/// <inheritdoc />
protected override void InitializeSDK()
{
_channel = GrpcChannel.ForAddress("http://127.0.0.1:50051");
_client = new RgbSdkService.RgbSdkServiceClient(_channel);
}
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> LoadDevices()
{
ArgumentNullException.ThrowIfNull(_client, nameof(_client));
foreach (RgbGetConnectedDevicesResponse.Types.RgbDevice? device in _client.GetConnectedDevices(new()).Devices)
{
if (device.DeviceType == RgbDeviceType.None)
continue; // Skip devices that are not supported
_client.Initialize(new RgbInitializeRequest { Id = device.Id });
WootingGrpcUpdateQueue updateQueue = new(GetUpdateTrigger(device.SerialNumber.GetHashCode()), device, _client);
WootingDeviceType deviceType = device.DeviceType switch
{
RgbDeviceType.Tkl => WootingDeviceType.KeyboardTKL,
RgbDeviceType.FullSize => WootingDeviceType.Keyboard,
RgbDeviceType.SixtyPercent => WootingDeviceType.KeyboardSixtyPercent,
RgbDeviceType.ThreeKey => WootingDeviceType.Keypad3Keys,
RgbDeviceType.EighyPercent => WootingDeviceType.KeyboardEightyPercent,
_ or RgbDeviceType.None => throw new ArgumentOutOfRangeException()
};
KeyboardLayoutType layoutType = device.LayoutType switch
{
RgbDeviceLayout.Ansi => KeyboardLayoutType.ANSI,
RgbDeviceLayout.Iso => KeyboardLayoutType.ISO,
RgbDeviceLayout.Jis => KeyboardLayoutType.JIS,
RgbDeviceLayout.AnsiSplitSpacebar => KeyboardLayoutType.ANSI,
RgbDeviceLayout.IsoSplitSpacebar => KeyboardLayoutType.ISO,
RgbDeviceLayout.Unknown => KeyboardLayoutType.Unknown,
_ => throw new ArgumentOutOfRangeException()
};
//NOTE: this model name ends up kind of ugly, since `ModelName` is like `Wooting 60HE`. We cannot remove the `Wooting` prefix,
//since that makes loadouts fail to load. The deviceName part, however, is fine to strip.
string model = device.ModelName;
string name =
DeviceHelper.CreateDeviceName("Wooting", $"{device.ModelName.Replace("Wooting", "").Trim()} ({device.SerialNumber})");
yield return deviceType switch
{
WootingDeviceType.Keypad3Keys => new WootingKeypadRGBDevice(deviceType, new(model, name), updateQueue),
_ => new WootingKeyboardRGBDevice(deviceType, new(layoutType, model, name), updateQueue)
};
}
}
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
lock (_lock)
{
base.Dispose(disposing);
try
{
_client = null;
_channel?.Dispose();
}
catch
{ /* at least we tried */
}
_instance = null;
}
}
#endregion
}

View File

@ -0,0 +1,96 @@
using System;
using System.Runtime.InteropServices;
using Google.Protobuf;
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Generic;
using WootingRgbSdk;
namespace RGB.NET.Devices.Wooting.Grpc;
/// <inheritdoc />
/// <summary>
/// Represents the update-queue performing updates for cooler master devices.
/// </summary>
public sealed class WootingGrpcUpdateQueue : UpdateQueue
{
#region Properties & Fields
private readonly RgbSdkService.RgbSdkServiceClient _client;
private readonly RgbGetConnectedDevicesResponse.Types.RgbDevice _wootDevice;
private readonly WootingColor[] _colors;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="WootingGrpcUpdateQueue"/> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
public WootingGrpcUpdateQueue(IDeviceUpdateTrigger updateTrigger, RgbGetConnectedDevicesResponse.Types.RgbDevice wootDevice,
RgbSdkService.RgbSdkServiceClient client)
: base(updateTrigger)
{
this._client = client;
this._wootDevice = wootDevice;
this._colors = new WootingColor[WootingLedMappings.COLUMNS * WootingLedMappings.ROWS];
}
#endregion
#region Methods
/// <inheritdoc />
protected override bool Update(ReadOnlySpan<(object key, Color color)> dataSet)
{
try
{
foreach ((object key, Color color) in dataSet)
{
(int row, int column) = ((int, int))key;
int index = (WootingLedMappings.COLUMNS * row) + column;
_colors[index] = new WootingColor(color.GetR(), color.GetG(), color.GetB());
}
_client.SetColors(new RgbSetColorsRequest
{
Id = _wootDevice.Id,
Colors = ByteString.CopyFrom(MemoryMarshal.AsBytes(_colors.AsSpan()))
});
return true;
}
catch (Exception ex)
{
WootingGrpcDeviceProvider.Instance.Throw(ex);
}
return false;
}
/// <inheritdoc />
public override void Dispose()
{
_client.Close(new RgbCloseRequest { Id = _wootDevice.Id });
base.Dispose();
}
#endregion
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal readonly struct WootingColor
{
public readonly byte r;
public readonly byte g;
public readonly byte b;
public readonly byte a;
public WootingColor(byte r, byte g, byte b)
{
this.r = r;
this.g = g;
this.b = b;
this.a = 0; // Alpha is not used in Wooting devices
}
}

View File

@ -1,5 +1,5 @@
using System.Collections.Generic; using RGB.NET.Core;
using RGB.NET.Core; using RGB.NET.Devices.Wooting.Enum;
using RGB.NET.Devices.Wooting.Generic; using RGB.NET.Devices.Wooting.Generic;
namespace RGB.NET.Devices.Wooting.Keyboard; namespace RGB.NET.Devices.Wooting.Keyboard;
@ -22,28 +22,12 @@ public sealed class WootingKeyboardRGBDevice : WootingRGBDevice<WootingKeyboardR
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Wooting.Keyboard.WootingKeyboardRGBDevice" /> class. /// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Wooting.Keyboard.WootingKeyboardRGBDevice" /> class.
/// </summary> /// </summary>
/// <param name="deviceType">The type of the Wooting device.</param>
/// <param name="info">The specific information provided by Wooting for the keyboard</param> /// <param name="info">The specific information provided by Wooting for the keyboard</param>
/// <param name="updateTrigger">The update trigger used to update this device.</param> /// <param name="updateQueue">The update queue used to update this device.</param>
internal WootingKeyboardRGBDevice(WootingKeyboardRGBDeviceInfo info, IUpdateQueue updateQueue) internal WootingKeyboardRGBDevice(WootingDeviceType deviceType, WootingKeyboardRGBDeviceInfo info, IUpdateQueue updateQueue)
: base(info, updateQueue) : base(deviceType, info, updateQueue)
{ { }
InitializeLayout();
}
#endregion
#region Methods
private void InitializeLayout()
{
Dictionary<LedId, (int row, int column)> mapping = WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType];
foreach (KeyValuePair<LedId, (int row, int column)> led in mapping)
AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
}
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId];
#endregion #endregion
} }

View File

@ -23,16 +23,13 @@ public sealed class WootingKeyboardRGBDeviceInfo : WootingRGBDeviceInfo, IKeyboa
/// <summary> /// <summary>
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Wooting.WootingKeyboardRGBDeviceInfo" />. /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Wooting.WootingKeyboardRGBDeviceInfo" />.
/// </summary> /// </summary>
/// <param name="deviceInfo">The native <see cref="T:RGB.NET.Devices.Wooting.Native._WootingDeviceInfo" />.</param> /// <param name="layout">The layout of the keyboard.</param>
internal WootingKeyboardRGBDeviceInfo(_WootingDeviceInfo deviceInfo, byte deviceIndex) /// <param name="model">The model of the keyboard.</param>
: base(RGBDeviceType.Keyboard, deviceInfo, deviceIndex) /// <param name="name">The name of the keyboard.</param>
internal WootingKeyboardRGBDeviceInfo(KeyboardLayoutType layout, string model, string name)
: base(RGBDeviceType.Keyboard, model, name)
{ {
Layout = WootingLayoutType switch Layout = layout;
{
WootingLayoutType.ANSI => KeyboardLayoutType.ANSI,
WootingLayoutType.ISO => KeyboardLayoutType.ISO,
_ => KeyboardLayoutType.Unknown
};
} }
#endregion #endregion

View File

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum;
using RGB.NET.Devices.Wooting.Generic; using RGB.NET.Devices.Wooting.Generic;
namespace RGB.NET.Devices.Wooting.Keypad; namespace RGB.NET.Devices.Wooting.Keypad;
@ -16,28 +17,12 @@ public sealed class WootingKeypadRGBDevice : WootingRGBDevice<WootingKeypadRGBDe
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Wooting.Keyboard.WootingKeypadRGBDevice" /> class. /// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Wooting.Keyboard.WootingKeypadRGBDevice" /> class.
/// </summary> /// </summary>
/// <param name="deviceType">The type of the Wooting device.</param>
/// <param name="info">The specific information provided by Wooting for the keyboard</param> /// <param name="info">The specific information provided by Wooting for the keyboard</param>
/// <param name="updateQueue">The update queue used to update this device.</param> /// <param name="updateQueue">The update queue used to update this device.</param>
internal WootingKeypadRGBDevice(WootingKeypadRGBDeviceInfo info, IUpdateQueue updateQueue) internal WootingKeypadRGBDevice(WootingDeviceType deviceType, WootingKeypadRGBDeviceInfo info, IUpdateQueue updateQueue)
: base(info, updateQueue) : base(deviceType, info, updateQueue)
{ { }
InitializeLayout();
}
#endregion
#region Methods
private void InitializeLayout()
{
Dictionary<LedId, (int row, int column)> mapping = WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType];
foreach (KeyValuePair<LedId, (int row, int column)> led in mapping)
AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
}
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId];
#endregion #endregion
} }

View File

@ -9,9 +9,7 @@ namespace RGB.NET.Devices.Wooting.Keypad;
/// </summary> /// </summary>
public sealed class WootingKeypadRGBDeviceInfo : WootingRGBDeviceInfo public sealed class WootingKeypadRGBDeviceInfo : WootingRGBDeviceInfo
{ {
internal WootingKeypadRGBDeviceInfo(_WootingDeviceInfo deviceInfo, byte deviceIndex) internal WootingKeypadRGBDeviceInfo(string model, string name)
: base(RGBDeviceType.Keypad, deviceInfo, deviceIndex) : base(RGBDeviceType.Keypad, model, name)
{ { }
}
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
@ -72,7 +72,8 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
{ {
lock (_lock) lock (_lock)
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}"); if (_instance != null)
throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}");
_instance = this; _instance = this;
} }
} }
@ -99,18 +100,35 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
{ {
for (byte i = 0; i < _WootingSDK.GetDeviceCount(); i++) for (byte i = 0; i < _WootingSDK.GetDeviceCount(); i++)
{ {
WootingUpdateQueue updateQueue = new(GetUpdateTrigger(), i); WootingNativeUpdateQueue updateQueue = new(GetUpdateTrigger(), i);
_WootingSDK.SelectDevice(i); _WootingSDK.SelectDevice(i);
_WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!; _WootingDeviceInfo nativeDeviceInfo =
(_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!;
//Uwu non-rgb returns zero here. //Uwu non-rgb returns zero here.
if (nativeDeviceInfo.MaxLedIndex == 0) if (nativeDeviceInfo.MaxLedIndex == 0)
continue; continue;
KeyboardLayoutType layoutType = nativeDeviceInfo.LayoutType switch
{
WootingLayoutType.Unknown => KeyboardLayoutType.Unknown,
WootingLayoutType.ANSI => KeyboardLayoutType.ANSI,
WootingLayoutType.ISO => KeyboardLayoutType.ISO,
WootingLayoutType.JIS => KeyboardLayoutType.JIS,
WootingLayoutType.ANSI_SPLIT_SPACEBAR => KeyboardLayoutType.ANSI,
WootingLayoutType.ISO_SPLIT_SPACEBAR => KeyboardLayoutType.ISO,
_ => throw new ArgumentOutOfRangeException()
};
//Note: we cannot change *any* of these here or the local database Artemis has will no longer match up and everything breaks.
string model = nativeDeviceInfo.Model;
string name = DeviceHelper.CreateDeviceName("Wooting", model);
yield return nativeDeviceInfo.DeviceType switch yield return nativeDeviceInfo.DeviceType switch
{ {
WootingDeviceType.Keypad3Keys => new WootingKeypadRGBDevice(new WootingKeypadRGBDeviceInfo(nativeDeviceInfo, i), updateQueue), WootingDeviceType.Keypad3Keys => new WootingKeypadRGBDevice(nativeDeviceInfo.DeviceType, new(model, name),
_ => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(nativeDeviceInfo, i), updateQueue), updateQueue),
_ => new WootingKeyboardRGBDevice(nativeDeviceInfo.DeviceType, new(layoutType, model, name), updateQueue)
}; };
} }
} }
@ -127,7 +145,9 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
lock (_WootingSDK.SdkLock) lock (_WootingSDK.SdkLock)
{ {
try { _WootingSDK.UnloadWootingSDK(); } try { _WootingSDK.UnloadWootingSDK(); }
catch { /* at least we tried */ } catch
{ /* at least we tried */
}
} }
_instance = null; _instance = null;

View File

@ -1,14 +1,13 @@
using System; using System;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting.Generic; namespace RGB.NET.Devices.Wooting.Native;
/// <inheritdoc /> /// <inheritdoc />
/// <summary> /// <summary>
/// Represents the update-queue performing updates for cooler master devices. /// Represents the update-queue performing updates for cooler master devices.
/// </summary> /// </summary>
public sealed class WootingUpdateQueue : UpdateQueue public sealed class WootingNativeUpdateQueue : UpdateQueue
{ {
#region Properties & Fields #region Properties & Fields
@ -19,10 +18,10 @@ public sealed class WootingUpdateQueue : UpdateQueue
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="WootingUpdateQueue"/> class. /// Initializes a new instance of the <see cref="WootingNativeUpdateQueue"/> class.
/// </summary> /// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param> /// <param name="updateTrigger">The update trigger used by this queue.</param>
public WootingUpdateQueue(IDeviceUpdateTrigger updateTrigger, byte deviceId) public WootingNativeUpdateQueue(IDeviceUpdateTrigger updateTrigger, byte deviceId)
: base(updateTrigger) : base(updateTrigger)
{ {
this._deviceid = deviceId; this._deviceid = deviceId;
@ -60,5 +59,14 @@ public sealed class WootingUpdateQueue : UpdateQueue
return false; return false;
} }
/// <inheritdoc />
public override void Dispose()
{
_WootingSDK.SelectDevice(_deviceid);
_WootingSDK.Reset();
base.Dispose();
}
#endregion #endregion
} }

View File

@ -64,4 +64,17 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" /> <ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.31.1" />
<PackageReference Include="Grpc.Net.Client" Version="2.71.0" />
<PackageReference Include="Grpc.Tools" Version="2.72.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Protobuf Include="WootingRgb.proto" GrpcServices="Client" />
</ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,68 @@
syntax = "proto3";
package wooting_rgb_sdk;
//from C rgb_sdk
enum RgbDeviceType {
None = 0;
Tkl = 1;
FullSize = 2;
SixtyPercent = 3;
ThreeKey = 4;
EighyPercent = 5;
}
//from C rgb_sdk
enum RgbDeviceLayout {
ANSI = 0;
ISO = 1;
JIS = 2;
ANSI_SPLIT_SPACEBAR = 3;
ISO_SPLIT_SPACEBAR = 4;
Unknown = -1;
}
message RgbGetConnectedDevicesRequest {}
message RgbGetConnectedDevicesResponse {
message RgbDevice {
uint64 id = 1;
uint32 rows = 2;
uint32 columns = 3;
string model_name = 4;
string serial_number = 5;
RgbDeviceType device_type = 6;
RgbDeviceLayout layout_type = 7;
}
repeated RgbDevice devices = 1;
}
message RgbInitializeRequest {
uint64 id = 1;
}
message RgbInitializeResponse {
}
message RgbSetColorsRequest {
uint64 id = 1;
bytes colors = 2;
}
message RgbSetColorsResponse {
}
message RgbCloseRequest {
uint64 id = 1;
}
message RgbCloseResponse {
}
service RgbSdkService {
rpc GetConnectedDevices(RgbGetConnectedDevicesRequest) returns (RgbGetConnectedDevicesResponse);
rpc Initialize(RgbInitializeRequest) returns (RgbInitializeResponse);
rpc SetColors(RgbSetColorsRequest) returns (RgbSetColorsResponse);
rpc Close(RgbCloseRequest) returns (RgbCloseResponse);
}