Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wooting - Add uwu support #355

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions RGB.NET.Devices.Wooting/Enum/WootingDeviceType.cs
Original file line number Diff line number Diff line change
@@ -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,
}
1 change: 1 addition & 0 deletions RGB.NET.Devices.Wooting/Enum/WootingLayoutType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace RGB.NET.Devices.Wooting.Enum;
/// </remarks>
public enum WootingLayoutType
{
Unknown = -1,
ANSI = 0,
ISO = 1
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -305,15 +305,46 @@ internal static class WootingKeyboardLedMappings
{ LedId.Keyboard_Function, (5, 13) }
};

private static readonly Dictionary<LedId, (int row, int column)> 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),
};

/// <summary>
/// Contains all the hardware-id mappings for Wooting devices.
/// </summary>
public static readonly Dictionary<WootingDeviceType, Dictionary<LedId, (int row, int column)>> Mapping = new()
{
[WootingDeviceType.Keyboard] = Fullsize,
[WootingDeviceType.KeyboardTKL] = TKL,
[WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent
[WootingDeviceType.KeyboardSixtyPercent] = SixtyPercent,
[WootingDeviceType.Keypad3Keys] = ThreeKeyKeypad
};

#endregion
}
}
14 changes: 14 additions & 0 deletions RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Native;

namespace RGB.NET.Devices.Wooting.Generic;

Expand All @@ -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
}
34 changes: 0 additions & 34 deletions RGB.NET.Devices.Wooting/Helper/EnumExtension.cs

This file was deleted.

12 changes: 2 additions & 10 deletions RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,14 @@ internal WootingKeyboardRGBDevice(WootingKeyboardRGBDeviceInfo info, IUpdateQueu

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 changes: 44 additions & 0 deletions RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDevice.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions RGB.NET.Devices.Wooting/Keypad/WootingKeypadRGBDeviceInfo.cs
Original file line number Diff line number Diff line change
@@ -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)
{

}
}
6 changes: 4 additions & 2 deletions RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
14 changes: 12 additions & 2 deletions RGB.NET.Devices.Wooting/WootingDeviceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,8 +101,16 @@ protected override IEnumerable<IRGBDevice> 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),
};
}
}
}
Expand Down
Loading