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

Merge pull request #103 from DarthAffe/SDK/Wooting

Updated for official v1.1.0 Wooting SDK
This commit is contained in:
Robert Beekman 2020-02-05 14:09:26 +01:00 committed by GitHub
commit 185fd05c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);
_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();

View File

@ -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<IRGBDevice> devices = new List<IRGBDevice>();
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,