mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Wooting - Add uwu support
This commit is contained in:
parent
d454f94b73
commit
736d58c7a3
@ -1,24 +1,29 @@
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace RGB.NET.Devices.Wooting.Enum;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the type of a wooting device
|
||||
/// </summary>
|
||||
public enum WootingDeviceType
|
||||
{
|
||||
/// <summary>
|
||||
/// 10 Keyless Keyboard. E.g. Wooting One
|
||||
/// </summary>
|
||||
KeyboardTKL = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Full Size keyboard. E.g. Wooting Two
|
||||
/// </summary>
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace RGB.NET.Devices.Wooting.Enum;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the type of a wooting device
|
||||
/// </summary>
|
||||
public enum WootingDeviceType
|
||||
{
|
||||
/// <summary>
|
||||
/// 10 Keyless Keyboard. E.g. Wooting One
|
||||
/// </summary>
|
||||
KeyboardTKL = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Full Size keyboard. E.g. Wooting Two
|
||||
/// </summary>
|
||||
Keyboard = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Full Size keyboard. E.g. Wooting Two
|
||||
/// </summary>
|
||||
KeyboardSixtyPercent = 3
|
||||
/// <summary>
|
||||
/// 60 percent keyboard, E.g. Wooting 60HE
|
||||
/// </summary>
|
||||
KeyboardSixtyPercent = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Three key keypad. E.g. Wooting Uwu
|
||||
/// </summary>
|
||||
Keypad3Keys = 4,
|
||||
}
|
||||
@ -13,6 +13,7 @@ namespace RGB.NET.Devices.Wooting.Enum;
|
||||
/// </remarks>
|
||||
public enum WootingLayoutType
|
||||
{
|
||||
Unknown = -1,
|
||||
ANSI = 0,
|
||||
ISO = 1
|
||||
}
|
||||
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Contains all the hardware-id mappings for Wooting devices.
|
||||
/// </summary>
|
||||
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<LedId, (int row, int column)> 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),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Contains all the hardware-id mappings for Wooting devices.
|
||||
/// </summary>
|
||||
@ -312,8 +340,9 @@ internal static class WootingKeyboardLedMappings
|
||||
{
|
||||
[WootingDeviceType.Keyboard] = Fullsize,
|
||||
[WootingDeviceType.KeyboardTKL] = TKL,
|
||||
[WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent
|
||||
[WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent,
|
||||
[WootingDeviceType.Keypad3Keys] = ThreeKeyKeypad
|
||||
};
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Wooting.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Wooting.Generic;
|
||||
|
||||
@ -23,4 +24,17 @@ public abstract class WootingRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceI
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Methods
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_WootingSDK.SelectDevice(DeviceInfo.WootingDeviceIndex);
|
||||
_WootingSDK.Reset();
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace RGB.NET.Devices.Wooting.Helper;
|
||||
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for enum related things.
|
||||
/// </summary>
|
||||
internal static class EnumExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the value of the <see cref="DescriptionAttribute"/>.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the description from.</param>
|
||||
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="System.Enum.ToString()" /> result of the source.</returns>
|
||||
internal static string GetDescription(this System.Enum source)
|
||||
=> source.GetAttribute<DescriptionAttribute>()?.Description ?? source.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attribute of type T.
|
||||
/// </summary>
|
||||
/// <param name="source">The enum value to get the attribute from</param>
|
||||
/// <typeparam name="T">The generic attribute type</typeparam>
|
||||
/// <returns>The <see cref="Attribute"/>.</returns>
|
||||
private static T? GetAttribute<T>(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;
|
||||
}
|
||||
}
|
||||
@ -37,22 +37,14 @@ public sealed class WootingKeyboardRGBDevice : WootingRGBDevice<WootingKeyboardR
|
||||
|
||||
private void InitializeLayout()
|
||||
{
|
||||
Dictionary<LedId, (int row, int column)> mapping = WootingKeyboardLedMappings.Mapping[DeviceInfo.WootingDeviceType];
|
||||
Dictionary<LedId, (int row, int column)> mapping = WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType];
|
||||
|
||||
foreach (KeyValuePair<LedId, (int row, int column)> led in mapping)
|
||||
AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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
|
||||
}
|
||||
44
RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs
Normal file
44
RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs
Normal file
@ -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;
|
||||
|
||||
/// <inheritdoc cref="WootingRGBDevice{TDeviceInfo}" />
|
||||
/// <summary>
|
||||
/// Represents a Wooting keyboard.
|
||||
/// </summary>
|
||||
public sealed class WootingKeypadRGBDevice : WootingRGBDevice<WootingKeypadRGBDeviceInfo>, IKeypad
|
||||
{
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Wooting.Keyboard.WootingKeypadRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by Wooting for the keyboard</param>
|
||||
/// <param name="updateQueue">The update queue used to update this device.</param>
|
||||
internal WootingKeypadRGBDevice(WootingKeypadRGBDeviceInfo info, IUpdateQueue updateQueue)
|
||||
: base(info, updateQueue)
|
||||
{
|
||||
InitializeLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void InitializeLayout()
|
||||
{
|
||||
Dictionary<LedId, (int row, int column)> mapping = WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType];
|
||||
|
||||
foreach (KeyValuePair<LedId, (int row, int column)> led in mapping)
|
||||
AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override object GetLedCustomData(LedId ledId) => WootingLedMappings.Mapping[DeviceInfo.WootingDeviceType][ledId];
|
||||
|
||||
#endregion
|
||||
}
|
||||
17
RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDeviceInfo.cs
Normal file
17
RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDeviceInfo.cs
Normal file
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Wooting.Keypad.WootingKeypadRGBDevice" />.
|
||||
/// </summary>
|
||||
public sealed class WootingKeypadRGBDeviceInfo : WootingRGBDeviceInfo
|
||||
{
|
||||
internal WootingKeypadRGBDeviceInfo(_WootingDeviceInfo deviceInfo, byte deviceIndex)
|
||||
: base(RGBDeviceType.Keypad, deviceInfo, deviceIndex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@ -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; }
|
||||
}
|
||||
@ -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 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
|
||||
_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),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user