Skip to content

Commit

Permalink
Wooting - Add uwu support
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotr7 committed Oct 17, 2023
1 parent d454f94 commit 736d58c
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 74 deletions.
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,44 @@ 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>
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; }
}
8 changes: 7 additions & 1 deletion 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 @@ -100,7 +102,11 @@ protected override IEnumerable<IRGBDevice> LoadDevices()
_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),
};
}
}
}
Expand Down

0 comments on commit 736d58c

Please sign in to comment.