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..081e9934 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,36 @@ internal static class WootingKeyboardLedMappings { LedId.Keyboard_Function, (5, 13) } }; + private static readonly Dictionary ThreeKeyKeypad = new() + { + //left (from top to bottom) + [LedId.LedStripe1] = (1, 0), + [LedId.LedStripe2] = (2, 0), + [LedId.LedStripe3] = (3, 0), + + //bottom (from left to right) + [LedId.LedStripe4] = (4, 1), + [LedId.LedStripe5] = (4, 2), + [LedId.LedStripe6] = (4, 4), + [LedId.LedStripe7] = (4, 5), + + //right (from bottom to top) + [LedId.LedStripe8] = (3, 6), + [LedId.LedStripe9] = (2, 6), + [LedId.LedStripe10] = (1, 6), + + //top (from right to left) + [LedId.LedStripe11] = (0, 6), + [LedId.LedStripe12] = (0, 4), + [LedId.LedStripe13] = (0, 2), + [LedId.LedStripe14] = (0, 0), + + //analog keys + [LedId.Keypad1] = (2, 1), + [LedId.Keypad2] = (2, 3), + [LedId.Keypad3] = (2, 5), + }; + /// /// Contains all the hardware-id mappings for Wooting devices. /// @@ -312,8 +342,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..c92661f9 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; @@ -99,8 +101,16 @@ protected override IEnumerable LoadDevices() WootingUpdateQueue updateQueue = new(GetUpdateTrigger(), i); _WootingSDK.SelectDevice(i); _WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!; - - yield return new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(nativeDeviceInfo, i), updateQueue); + + //Uwu non-rgb returns zero here. + if (nativeDeviceInfo.MaxLedIndex == 0) + continue; + + yield return nativeDeviceInfo.DeviceType switch + { + WootingDeviceType.Keypad3Keys => new WootingKeypadRGBDevice(new WootingKeypadRGBDeviceInfo(nativeDeviceInfo, i), updateQueue), + _ => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(nativeDeviceInfo, i), updateQueue), + }; } } }