From 736d58c7a305c6060bb6c5a7e784375266e31164 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Tue, 17 Oct 2023 14:20:04 +0100 Subject: [PATCH 1/4] Wooting - Add uwu support --- .../Enum/WootingDeviceType.cs | 47 ++++++++++--------- .../Enum/WootingLayoutType.cs | 1 + .../WootingLedMappings.cs} | 41 +++++++++++++--- .../Generic/WootingRGBDevice.cs | 14 ++++++ .../Helper/EnumExtension.cs | 34 -------------- .../Keyboard/WootingKeyboardRGBDevice.cs | 12 +---- .../Keypad/WootingKeypadRGBDevice.cs | 44 +++++++++++++++++ .../Keypad/WootingKeypadRGBDeviceInfo.cs | 17 +++++++ .../Native/_WootingDeviceInfo.cs | 6 ++- .../WootingDeviceProvider.cs | 8 +++- 10 files changed, 150 insertions(+), 74 deletions(-) rename RGB.NET.Devices.Wooting/{Keyboard/WootingKeyboardLedMappings.cs => Generic/WootingLedMappings.cs} (91%) delete mode 100644 RGB.NET.Devices.Wooting/Helper/EnumExtension.cs create mode 100644 RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs create mode 100644 RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDeviceInfo.cs diff --git a/RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs b/RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs index 513fae59..63ff83a4 100644 --- a/RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs +++ b/RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs @@ -1,24 +1,29 @@ -// ReSharper disable InconsistentNaming - -namespace RGB.NET.Devices.Wooting.Enum; - -/// -/// Represents the type of a wooting device -/// -public enum WootingDeviceType -{ - /// - /// 10 Keyless Keyboard. E.g. Wooting One - /// - KeyboardTKL = 1, - - /// - /// Full Size keyboard. E.g. Wooting Two - /// +// ReSharper disable InconsistentNaming + +namespace RGB.NET.Devices.Wooting.Enum; + +/// +/// Represents the type of a wooting device +/// +public enum WootingDeviceType +{ + /// + /// 10 Keyless Keyboard. E.g. Wooting One + /// + KeyboardTKL = 1, + + /// + /// Full Size keyboard. E.g. Wooting Two + /// Keyboard = 2, - /// - /// Full Size keyboard. E.g. Wooting Two - /// - KeyboardSixtyPercent = 3 + /// + /// 60 percent keyboard, E.g. Wooting 60HE + /// + KeyboardSixtyPercent = 3, + + /// + /// Three key keypad. E.g. Wooting Uwu + /// + Keypad3Keys = 4, } \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Enum/WootingLayoutType.cs b/RGB.NET.Devices.Wooting/Enum/WootingLayoutType.cs index e01a6d14..70c15208 100644 --- a/RGB.NET.Devices.Wooting/Enum/WootingLayoutType.cs +++ b/RGB.NET.Devices.Wooting/Enum/WootingLayoutType.cs @@ -13,6 +13,7 @@ namespace RGB.NET.Devices.Wooting.Enum; /// public enum WootingLayoutType { + Unknown = -1, ANSI = 0, ISO = 1 } \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs similarity index 91% rename from RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs rename to RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs index 0b442375..23746cb7 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs @@ -1,15 +1,15 @@ -// ReSharper disable InconsistentNaming +// ReSharper disable InconsistentNaming +using System.Collections.Generic; using RGB.NET.Core; using RGB.NET.Devices.Wooting.Enum; -using System.Collections.Generic; -namespace RGB.NET.Devices.Wooting.Keyboard; +namespace RGB.NET.Devices.Wooting.Generic; /// /// Contains all the hardware-id mappings for Wooting devices. /// -internal static class WootingKeyboardLedMappings +internal static class WootingLedMappings { #region Properties & Fields @@ -305,6 +305,34 @@ internal static class WootingKeyboardLedMappings { LedId.Keyboard_Function, (5, 13) } }; + private static readonly Dictionary 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), + }; + /// /// Contains all the hardware-id mappings for Wooting devices. /// @@ -312,8 +340,9 @@ internal static class WootingKeyboardLedMappings { [WootingDeviceType.Keyboard] = Fullsize, [WootingDeviceType.KeyboardTKL] = TKL, - [WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent + [WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent, + [WootingDeviceType.Keypad3Keys] = ThreeKeyKeypad }; #endregion -} \ No newline at end of file +} diff --git a/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs b/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs index 8697eb1c..7bc089ec 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs @@ -1,4 +1,5 @@ using RGB.NET.Core; +using RGB.NET.Devices.Wooting.Native; namespace RGB.NET.Devices.Wooting.Generic; @@ -23,4 +24,17 @@ protected WootingRGBDevice(TDeviceInfo info, IUpdateQueue updateQueue) } #endregion + + + #region Methods + + public override void Dispose() + { + _WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex); + _WootingSDK.Reset(); + + base.Dispose(); + } + + #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs b/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs deleted file mode 100644 index 0ec89587..00000000 --- a/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.ComponentModel; -using System.Reflection; - -namespace RGB.NET.Devices.Wooting.Helper; - -/// -/// Offers some extensions and helper-methods for enum related things. -/// -internal static class EnumExtension -{ - /// - /// Gets the value of the . - /// - /// The enum value to get the description from. - /// The value of the or the result of the source. - internal static string GetDescription(this System.Enum source) - => source.GetAttribute()?.Description ?? source.ToString(); - - /// - /// Gets the attribute of type T. - /// - /// The enum value to get the attribute from - /// The generic attribute type - /// The . - private static T? GetAttribute(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; - } -} \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs index 79e1bafd..773d2337 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs @@ -37,22 +37,14 @@ internal WootingKeyboardRGBDevice(WootingKeyboardRGBDeviceInfo info, IUpdateQueu private void InitializeLayout() { - Dictionary mapping = WootingKeyboardLedMappings.Mapping[DeviceInfo.WootingDeviceType]; + Dictionary mapping = WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType]; foreach (KeyValuePair led in mapping) AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19)); } /// - protected override object GetLedCustomData(LedId ledId) => WootingKeyboardLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId]; - - public override void Dispose() - { - _WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex); - _WootingSDK.Reset(); - - base.Dispose(); - } + protected override object GetLedCustomData(LedId ledId) => WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId]; #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs b/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs new file mode 100644 index 00000000..5bf55249 --- /dev/null +++ b/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs @@ -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; + +/// +/// +/// Represents a Wooting keyboard. +/// +public sealed class WootingKeypadRGBDevice : WootingRGBDevice, IKeypad +{ + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by Wooting for the keyboard + /// The update queue used to update this device. + internal WootingKeypadRGBDevice(WootingKeypadRGBDeviceInfo info, IUpdateQueue updateQueue) + : base(info, updateQueue) + { + InitializeLayout(); + } + + #endregion + + #region Methods + + private void InitializeLayout() + { + Dictionary mapping = WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType]; + + foreach (KeyValuePair led in mapping) + AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19)); + } + + /// + protected override object GetLedCustomData(LedId ledId) => WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId]; + + #endregion +} \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDeviceInfo.cs b/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDeviceInfo.cs new file mode 100644 index 00000000..55088e11 --- /dev/null +++ b/RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDeviceInfo.cs @@ -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; + +/// +/// Represents a generic information for a . +/// +public sealed class WootingKeypadRGBDeviceInfo : WootingRGBDeviceInfo +{ + internal WootingKeypadRGBDeviceInfo(_WootingDeviceInfo deviceInfo, byte deviceIndex) + : base(RGBDeviceType.Keypad, deviceInfo, deviceIndex) + { + + } +} diff --git a/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs b/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs index a672f315..6a59c811 100644 --- a/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs +++ b/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs @@ -17,11 +17,13 @@ internal struct _WootingDeviceInfo 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 bool V2Interface { get; set; } + internal bool V2Interface { get; private set; } internal WootingLayoutType LayoutType { get; private set; } + + internal bool UsesSmallPackets { get; private set; } } \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 6d16b2f7..415ae4ca 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using RGB.NET.Core; +using RGB.NET.Devices.Wooting.Enum; using RGB.NET.Devices.Wooting.Generic; using RGB.NET.Devices.Wooting.Keyboard; +using RGB.NET.Devices.Wooting.Keypad; using RGB.NET.Devices.Wooting.Native; namespace RGB.NET.Devices.Wooting; @@ -100,7 +102,11 @@ protected override IEnumerable LoadDevices() _WootingSDK.SelectDevice(i); _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), + }; } } } From 69d320fca3f121b6c1ba65e1a4668b44de576af0 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Tue, 17 Oct 2023 17:49:09 +0100 Subject: [PATCH 2/4] Ignore UwU non-RGB --- RGB.NET.Devices.Wooting/WootingDeviceProvider.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 415ae4ca..c92661f9 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -101,6 +101,10 @@ protected override IEnumerable LoadDevices() WootingUpdateQueue updateQueue = new(GetUpdateTrigger(), i); _WootingSDK.SelectDevice(i); _WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!; + + //Uwu non-rgb returns zero here. + if (nativeDeviceInfo.MaxLedIndex == 0) + continue; yield return nativeDeviceInfo.DeviceType switch { From 7ad1e595a9c7d4d086775e8d41bc0ebac6188926 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Tue, 17 Oct 2023 19:29:40 +0100 Subject: [PATCH 3/4] Added Missing LEDs --- .../Generic/WootingLedMappings.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs index 23746cb7..9b7860ba 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs @@ -307,27 +307,29 @@ internal static class WootingLedMappings private static readonly Dictionary ThreeKeyKeypad = new() { - //top left - bottom left - [LedId.LedStripe1] = (0, 0), - [LedId.LedStripe2] = (1, 0), + //left (from top to bottom) + [LedId.LedStripe1] = (1, 0), + [LedId.LedStripe2] = (2, 0), [LedId.LedStripe3] = (3, 0), - //bottom left - bottom right + //bottom (from left to right) [LedId.LedStripe4] = (4, 1), [LedId.LedStripe5] = (4, 2), [LedId.LedStripe6] = (4, 4), [LedId.LedStripe7] = (4, 5), - //bottom right - top right + //right (from bottom to top) [LedId.LedStripe8] = (3, 6), - [LedId.LedStripe9] = (1, 6), - [LedId.LedStripe10] = (0, 6), + [LedId.LedStripe9] = (2, 6), + [LedId.LedStripe10] = (1, 6), - //top right - top left - [LedId.LedStripe11] = (0, 4), - [LedId.LedStripe12] = (0, 2), + //top (from right to left) + [LedId.LedStripe11] = (0, 6), + [LedId.LedStripe12] = (0, 4), + [LedId.LedStripe13] = (0, 2), + [LedId.LedStripe14] = (0, 0), - //Analog Keys + //analog keys [LedId.Keypad1] = (3, 2), [LedId.Keypad2] = (3, 3), [LedId.Keypad3] = (3, 4), From fcf86ff9daaea162998227c378643843742ee9bb Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Wed, 18 Oct 2023 14:11:44 +0100 Subject: [PATCH 4/4] Fix analog key coords --- RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs index 9b7860ba..081e9934 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingLedMappings.cs @@ -330,9 +330,9 @@ internal static class WootingLedMappings [LedId.LedStripe14] = (0, 0), //analog keys - [LedId.Keypad1] = (3, 2), - [LedId.Keypad2] = (3, 3), - [LedId.Keypad3] = (3, 4), + [LedId.Keypad1] = (2, 1), + [LedId.Keypad2] = (2, 3), + [LedId.Keypad3] = (2, 5), }; ///