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

Updated for official v1.1.0 Wooting SDK

This commit is contained in:
SpoinkyNL 2020-01-28 19:43:15 +01:00
parent 9958da79d8
commit 1bdbc7b021
4 changed files with 42 additions and 14 deletions

View File

@ -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
}
}

View File

@ -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; }
}
}

View File

@ -45,8 +45,7 @@ namespace RGB.NET.Devices.Wooting.Native
_dllHandle = LoadLibrary(dllPath); _dllHandle = LoadLibrary(dllPath);
_isWootingOnePointer = (IsWootingOnePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_kbd_is_wooting_one"), typeof(IsWootingOnePointer)); _getDeviceInfoPointer = (GetDeviceInfoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_device_info"), typeof(GetDeviceInfoPointer));
_isWootingTwoPointer = (IsWootingTwoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_kbd_is_wooting_two"), typeof(IsWootingTwoPointer));
_keyboardConnectedPointer = (KeyboardConnectedPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_kbd_connected"), typeof(KeyboardConnectedPointer)); _keyboardConnectedPointer = (KeyboardConnectedPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_kbd_connected"), typeof(KeyboardConnectedPointer));
_resetPointer = (ResetPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_reset"), typeof(ResetPointer)); _resetPointer = (ResetPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_reset"), typeof(ResetPointer));
_arrayUpdateKeyboardPointer = (ArrayUpdateKeyboardPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_array_update_keyboard"), typeof(ArrayUpdateKeyboardPointer)); _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 #region Pointers
private static IsWootingOnePointer _isWootingOnePointer; private static GetDeviceInfoPointer _getDeviceInfoPointer;
private static IsWootingTwoPointer _isWootingTwoPointer;
private static KeyboardConnectedPointer _keyboardConnectedPointer; private static KeyboardConnectedPointer _keyboardConnectedPointer;
private static ResetPointer _resetPointer; private static ResetPointer _resetPointer;
private static ArrayUpdateKeyboardPointer _arrayUpdateKeyboardPointer; private static ArrayUpdateKeyboardPointer _arrayUpdateKeyboardPointer;
@ -92,11 +90,8 @@ namespace RGB.NET.Devices.Wooting.Native
#region Delegates #region Delegates
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool IsWootingOnePointer(); private delegate IntPtr GetDeviceInfoPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool IsWootingTwoPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool KeyboardConnectedPointer(); private delegate bool KeyboardConnectedPointer();
@ -108,11 +103,10 @@ namespace RGB.NET.Devices.Wooting.Native
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool ArraySetSinglePointer(byte row, byte column, byte red, byte green, byte blue); private delegate bool ArraySetSinglePointer(byte row, byte column, byte red, byte green, byte blue);
#endregion #endregion
internal static bool IsWootingOne() => _isWootingOnePointer(); internal static IntPtr GetDeviceInfo() => _getDeviceInfoPointer();
internal static bool IsWootingTwo() => _isWootingTwoPointer();
internal static bool KeyboardConnected() => _keyboardConnectedPointer(); internal static bool KeyboardConnected() => _keyboardConnectedPointer();
internal static bool Reset() => _resetPointer(); internal static bool Reset() => _resetPointer();
internal static bool ArrayUpdateKeyboard() => _arrayUpdateKeyboardPointer(); internal static bool ArrayUpdateKeyboard() => _arrayUpdateKeyboardPointer();

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum; using RGB.NET.Devices.Wooting.Enum;
using RGB.NET.Devices.Wooting.Generic; using RGB.NET.Devices.Wooting.Generic;
@ -97,15 +98,16 @@ namespace RGB.NET.Devices.Wooting
IList<IRGBDevice> devices = new List<IRGBDevice>(); IList<IRGBDevice> devices = new List<IRGBDevice>();
if (_WootingSDK.KeyboardConnected()) if (_WootingSDK.KeyboardConnected())
{ {
_WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo));
IWootingRGBDevice device; IWootingRGBDevice device;
// TODO: Find an accurate way to determine physical and logical layouts // 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, device = new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingTwo,
WootingPhysicalKeyboardLayout.US, WootingPhysicalKeyboardLayout.US,
CultureHelper.GetCurrentCulture())); CultureHelper.GetCurrentCulture()));
} }
else if (_WootingSDK.IsWootingOne()) else if (nativeDeviceInfo.Model == "Wooting one")
{ {
device = new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingOne, device = new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingOne,
WootingPhysicalKeyboardLayout.US, WootingPhysicalKeyboardLayout.US,