diff --git a/RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs b/RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs new file mode 100644 index 0000000..86f79cf --- /dev/null +++ b/RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs @@ -0,0 +1,11 @@ +namespace RGB.NET.Devices.Wooting.Enum +{ + public enum WootingDeviceType + { + /// 10 Keyless Keyboard. E.g. Wooting One + KeyboardTKL = 1, + + /// Full Size keyboard. E.g. Wooting Two + Keyboard = 2 + } +} diff --git a/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs b/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs new file mode 100644 index 0000000..5855a7b --- /dev/null +++ b/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs @@ -0,0 +1,21 @@ +using System.Runtime.InteropServices; +using RGB.NET.Devices.Wooting.Enum; + +namespace RGB.NET.Devices.Wooting.Native +{ + [StructLayout(LayoutKind.Sequential)] + public struct _WootingDeviceInfo + { + public bool Connected { get; private set; } + + public string Model { get; private set; } + + public byte MaxRows { get; private set; } + + public byte MaxColumns { get; private set; } + + public byte KeycodeLimit { get; private set; } + + public WootingDeviceType DeviceType { get; private set; } + } +} diff --git a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs index 402f6f4..a9017f3 100644 --- a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs +++ b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs @@ -45,8 +45,7 @@ namespace RGB.NET.Devices.Wooting.Native _dllHandle = LoadLibrary(dllPath); - _isWootingOnePointer = (IsWootingOnePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_kbd_is_wooting_one"), typeof(IsWootingOnePointer)); - _isWootingTwoPointer = (IsWootingTwoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_kbd_is_wooting_two"), typeof(IsWootingTwoPointer)); + _getDeviceInfoPointer = (GetDeviceInfoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_device_info"), typeof(GetDeviceInfoPointer)); _keyboardConnectedPointer = (KeyboardConnectedPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_kbd_connected"), typeof(KeyboardConnectedPointer)); _resetPointer = (ResetPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_reset"), typeof(ResetPointer)); _arrayUpdateKeyboardPointer = (ArrayUpdateKeyboardPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_array_update_keyboard"), typeof(ArrayUpdateKeyboardPointer)); @@ -80,8 +79,7 @@ namespace RGB.NET.Devices.Wooting.Native #region Pointers - private static IsWootingOnePointer _isWootingOnePointer; - private static IsWootingTwoPointer _isWootingTwoPointer; + private static GetDeviceInfoPointer _getDeviceInfoPointer; private static KeyboardConnectedPointer _keyboardConnectedPointer; private static ResetPointer _resetPointer; private static ArrayUpdateKeyboardPointer _arrayUpdateKeyboardPointer; @@ -92,11 +90,8 @@ namespace RGB.NET.Devices.Wooting.Native #region Delegates [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate bool IsWootingOnePointer(); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate bool IsWootingTwoPointer(); - + private delegate IntPtr GetDeviceInfoPointer(); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate bool KeyboardConnectedPointer(); @@ -108,11 +103,10 @@ namespace RGB.NET.Devices.Wooting.Native [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate bool ArraySetSinglePointer(byte row, byte column, byte red, byte green, byte blue); - + #endregion - internal static bool IsWootingOne() => _isWootingOnePointer(); - internal static bool IsWootingTwo() => _isWootingTwoPointer(); + internal static IntPtr GetDeviceInfo() => _getDeviceInfoPointer(); internal static bool KeyboardConnected() => _keyboardConnectedPointer(); internal static bool Reset() => _resetPointer(); internal static bool ArrayUpdateKeyboard() => _arrayUpdateKeyboardPointer(); diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index dbcb883..5a1113c 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Runtime.InteropServices; using RGB.NET.Core; using RGB.NET.Devices.Wooting.Enum; using RGB.NET.Devices.Wooting.Generic; @@ -97,15 +98,16 @@ namespace RGB.NET.Devices.Wooting IList devices = new List(); if (_WootingSDK.KeyboardConnected()) { + _WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo)); IWootingRGBDevice device; // TODO: Find an accurate way to determine physical and logical layouts - if (_WootingSDK.IsWootingTwo()) + if (nativeDeviceInfo.Model == "Wooting two") { device = new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingTwo, WootingPhysicalKeyboardLayout.US, CultureHelper.GetCurrentCulture())); } - else if (_WootingSDK.IsWootingOne()) + else if (nativeDeviceInfo.Model == "Wooting one") { device = new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingOne, WootingPhysicalKeyboardLayout.US,