1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 01:58:30 +00:00

Wooting - Add uwu support

This commit is contained in:
Diogo Trindade 2023-10-17 14:20:04 +01:00
parent d454f94b73
commit 736d58c7a3
10 changed files with 150 additions and 74 deletions

View File

@ -1,24 +1,29 @@
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace RGB.NET.Devices.Wooting.Enum; namespace RGB.NET.Devices.Wooting.Enum;
/// <summary> /// <summary>
/// Represents the type of a wooting device /// Represents the type of a wooting device
/// </summary> /// </summary>
public enum WootingDeviceType public enum WootingDeviceType
{ {
/// <summary> /// <summary>
/// 10 Keyless Keyboard. E.g. Wooting One /// 10 Keyless Keyboard. E.g. Wooting One
/// </summary> /// </summary>
KeyboardTKL = 1, KeyboardTKL = 1,
/// <summary> /// <summary>
/// Full Size keyboard. E.g. Wooting Two /// Full Size keyboard. E.g. Wooting Two
/// </summary> /// </summary>
Keyboard = 2, Keyboard = 2,
/// <summary> /// <summary>
/// Full Size keyboard. E.g. Wooting Two /// 60 percent keyboard, E.g. Wooting 60HE
/// </summary> /// </summary>
KeyboardSixtyPercent = 3 KeyboardSixtyPercent = 3,
/// <summary>
/// Three key keypad. E.g. Wooting Uwu
/// </summary>
Keypad3Keys = 4,
} }

View File

@ -13,6 +13,7 @@ namespace RGB.NET.Devices.Wooting.Enum;
/// </remarks> /// </remarks>
public enum WootingLayoutType public enum WootingLayoutType
{ {
Unknown = -1,
ANSI = 0, ANSI = 0,
ISO = 1 ISO = 1
} }

View File

@ -1,15 +1,15 @@
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
using System.Collections.Generic;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum; using RGB.NET.Devices.Wooting.Enum;
using System.Collections.Generic;
namespace RGB.NET.Devices.Wooting.Keyboard; namespace RGB.NET.Devices.Wooting.Generic;
/// <summary> /// <summary>
/// Contains all the hardware-id mappings for Wooting devices. /// Contains all the hardware-id mappings for Wooting devices.
/// </summary> /// </summary>
internal static class WootingKeyboardLedMappings internal static class WootingLedMappings
{ {
#region Properties & Fields #region Properties & Fields
@ -305,6 +305,34 @@ internal static class WootingKeyboardLedMappings
{ LedId.Keyboard_Function, (5, 13) } { LedId.Keyboard_Function, (5, 13) }
}; };
private static readonly Dictionary<LedId, (int row, int column)> ThreeKeyKeypad = new()
{
//top left - bottom left
[LedId.LedStripe1] = (0, 0),
[LedId.LedStripe2] = (1, 0),
[LedId.LedStripe3] = (3, 0),
//bottom left - bottom right
[LedId.LedStripe4] = (4, 1),
[LedId.LedStripe5] = (4, 2),
[LedId.LedStripe6] = (4, 4),
[LedId.LedStripe7] = (4, 5),
//bottom right - top right
[LedId.LedStripe8] = (3, 6),
[LedId.LedStripe9] = (1, 6),
[LedId.LedStripe10] = (0, 6),
//top right - top left
[LedId.LedStripe11] = (0, 4),
[LedId.LedStripe12] = (0, 2),
//Analog Keys
[LedId.Keypad1] = (3, 2),
[LedId.Keypad2] = (3, 3),
[LedId.Keypad3] = (3, 4),
};
/// <summary> /// <summary>
/// Contains all the hardware-id mappings for Wooting devices. /// Contains all the hardware-id mappings for Wooting devices.
/// </summary> /// </summary>
@ -312,8 +340,9 @@ internal static class WootingKeyboardLedMappings
{ {
[WootingDeviceType.Keyboard] = Fullsize, [WootingDeviceType.Keyboard] = Fullsize,
[WootingDeviceType.KeyboardTKL] = TKL, [WootingDeviceType.KeyboardTKL] = TKL,
[WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent [WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent,
[WootingDeviceType.Keypad3Keys] = ThreeKeyKeypad
}; };
#endregion #endregion
} }

View File

@ -1,4 +1,5 @@
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.Generic;
@ -23,4 +24,17 @@ public abstract class WootingRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceI
} }
#endregion #endregion
#region Methods
public override void Dispose()
{
_WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex);
_WootingSDK.Reset();
base.Dispose();
}
#endregion
} }

View File

@ -1,34 +0,0 @@
using System;
using System.ComponentModel;
using System.Reflection;
namespace RGB.NET.Devices.Wooting.Helper;
/// <summary>
/// Offers some extensions and helper-methods for enum related things.
/// </summary>
internal static class EnumExtension
{
/// <summary>
/// Gets the value of the <see cref="DescriptionAttribute"/>.
/// </summary>
/// <param name="source">The enum value to get the description from.</param>
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="System.Enum.ToString()" /> result of the source.</returns>
internal static string GetDescription(this System.Enum source)
=> source.GetAttribute<DescriptionAttribute>()?.Description ?? source.ToString();
/// <summary>
/// Gets the attribute of type T.
/// </summary>
/// <param name="source">The enum value to get the attribute from</param>
/// <typeparam name="T">The generic attribute type</typeparam>
/// <returns>The <see cref="Attribute"/>.</returns>
private static T? GetAttribute<T>(this System.Enum source)
where T : Attribute
{
FieldInfo? fi = source.GetType().GetField(source.ToString());
if (fi == null) return null;
T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false);
return attributes.Length > 0 ? attributes[0] : null;
}
}

View File

@ -37,22 +37,14 @@ public sealed class WootingKeyboardRGBDevice : WootingRGBDevice<WootingKeyboardR
private void InitializeLayout() private void InitializeLayout()
{ {
Dictionary<LedId, (int row, int column)> mapping = WootingKeyboardLedMappings.Mapping[DeviceInfo.WootingDeviceType]; Dictionary<LedId, (int row, int column)> mapping = WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType];
foreach (KeyValuePair<LedId, (int row, int column)> led in mapping) 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)); AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
} }
/// <inheritdoc /> /// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => WootingKeyboardLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId]; protected override object GetLedCustomData(LedId ledId) => WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId];
public override void Dispose()
{
_WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex);
_WootingSDK.Reset();
base.Dispose();
}
#endregion #endregion
} }

View File

@ -0,0 +1,44 @@
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Generic;
using RGB.NET.Devices.Wooting.Keyboard;
namespace RGB.NET.Devices.Wooting.Keypad;
/// <inheritdoc cref="WootingRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a Wooting keyboard.
/// </summary>
public sealed class WootingKeypadRGBDevice : WootingRGBDevice<WootingKeypadRGBDeviceInfo>, IKeypad
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Wooting.Keyboard.WootingKeypadRGBDevice" /> class.
/// </summary>
/// <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>
internal WootingKeypadRGBDevice(WootingKeypadRGBDeviceInfo info, IUpdateQueue updateQueue)
: base(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
}

View File

@ -0,0 +1,17 @@
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Generic;
using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting.Keypad;
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Wooting.Keypad.WootingKeypadRGBDevice" />.
/// </summary>
public sealed class WootingKeypadRGBDeviceInfo : WootingRGBDeviceInfo
{
internal WootingKeypadRGBDeviceInfo(_WootingDeviceInfo deviceInfo, byte deviceIndex)
: base(RGBDeviceType.Keypad, deviceInfo, deviceIndex)
{
}
}

View File

@ -17,11 +17,13 @@ internal struct _WootingDeviceInfo
internal byte MaxColumns { get; private set; } internal byte MaxColumns { get; private set; }
internal byte KeycodeLimit { get; private set; } internal byte MaxLedIndex { get; private set; }
internal WootingDeviceType DeviceType { get; private set; } internal WootingDeviceType DeviceType { get; private set; }
internal bool V2Interface { get; set; } internal bool V2Interface { get; private set; }
internal WootingLayoutType LayoutType { get; private set; } internal WootingLayoutType LayoutType { get; private set; }
internal bool UsesSmallPackets { get; private set; }
} }

View File

@ -2,8 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
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;
using RGB.NET.Devices.Wooting.Keyboard; using RGB.NET.Devices.Wooting.Keyboard;
using RGB.NET.Devices.Wooting.Keypad;
using RGB.NET.Devices.Wooting.Native; using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting; namespace RGB.NET.Devices.Wooting;
@ -100,7 +102,11 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
_WootingSDK.SelectDevice(i); _WootingSDK.SelectDevice(i);
_WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!; _WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!;
yield return new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(nativeDeviceInfo, i), updateQueue); yield return nativeDeviceInfo.DeviceType switch
{
WootingDeviceType.Keypad3Keys => new WootingKeypadRGBDevice(new WootingKeypadRGBDeviceInfo(nativeDeviceInfo, i), updateQueue),
_ => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(nativeDeviceInfo, i), updateQueue),
};
} }
} }
} }