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

Added physical-layout to KeyboardDeviceInfo

This commit is contained in:
Darth Affe 2021-02-13 18:28:24 +01:00
parent 07a6d8952c
commit 190f5df025
16 changed files with 100 additions and 50 deletions

View File

@ -0,0 +1,10 @@
namespace RGB.NET.Core
{
public enum KeyboardLayoutType
{
Unknown = 0,
Ansi = 1,
Iso = 2,
Jis = 3
}
}

View File

@ -4,5 +4,12 @@
/// Represents a keyboard-device /// Represents a keyboard-device
/// </summary> /// </summary>
public interface IKeyboard : IRGBDevice public interface IKeyboard : IRGBDevice
{ } {
new IKeyboardDeviceInfo DeviceInfo { get; }
}
public interface IKeyboardDeviceInfo : IRGBDeviceInfo
{
KeyboardLayoutType Layout { get; }
}
} }

View File

@ -104,7 +104,7 @@ namespace RGB.NET.Devices.Asus
case AsusDeviceType.KEYBOARD_RGB: case AsusDeviceType.KEYBOARD_RGB:
case AsusDeviceType.NB_KB_RGB: case AsusDeviceType.NB_KB_RGB:
case AsusDeviceType.NB_KB_4ZONE_RGB: case AsusDeviceType.NB_KB_4ZONE_RGB:
rgbDevice = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device, AsusPhysicalKeyboardLayout.Default)); rgbDevice = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device));
break; break;
case AsusDeviceType.MOUSE_RGB: case AsusDeviceType.MOUSE_RGB:

View File

@ -1,15 +0,0 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable InconsistentNaming
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
namespace RGB.NET.Devices.Asus
{
/// <summary>
/// Contains list of available physical layouts for asus keyboards.
/// </summary>
public enum AsusPhysicalKeyboardLayout
{
Default
}
}

View File

@ -11,6 +11,12 @@ namespace RGB.NET.Devices.Asus
/// </summary> /// </summary>
public class AsusKeyboardRGBDevice : AsusRGBDevice<AsusKeyboardRGBDeviceInfo>, IKeyboard public class AsusKeyboardRGBDevice : AsusRGBDevice<AsusKeyboardRGBDeviceInfo>, IKeyboard
{ {
#region Properties & Fields
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
#endregion
#region Constructors #region Constructors
/// <inheritdoc /> /// <inheritdoc />

View File

@ -3,18 +3,15 @@ using RGB.NET.Core;
namespace RGB.NET.Devices.Asus namespace RGB.NET.Devices.Asus
{ {
/// <inheritdoc />
/// <summary> /// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Asus.AsusKeyboardRGBDevice" />. /// Represents a generic information for a <see cref="T:RGB.NET.Devices.Asus.AsusKeyboardRGBDevice" />.
/// </summary> /// </summary>
public class AsusKeyboardRGBDeviceInfo : AsusRGBDeviceInfo public class AsusKeyboardRGBDeviceInfo : AsusRGBDeviceInfo, IKeyboardDeviceInfo
{ {
#region Properties & Fields #region Properties & Fields
/// <summary> /// <inheritdoc />
/// Gets the physical layout of the keyboard. public KeyboardLayoutType Layout => KeyboardLayoutType.Unknown;
/// </summary>
public AsusPhysicalKeyboardLayout PhysicalLayout { get; }
#endregion #endregion
@ -25,11 +22,9 @@ namespace RGB.NET.Devices.Asus
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.Asus.AsusKeyboardRGBDeviceInfo" />. /// Internal constructor of managed <see cref="T:RGB.NET.Devices.Asus.AsusKeyboardRGBDeviceInfo" />.
/// </summary> /// </summary>
/// <param name="device">The <see cref="IAuraSyncDevice"/> backing this RGB.NET device.</param> /// <param name="device">The <see cref="IAuraSyncDevice"/> backing this RGB.NET device.</param>
internal AsusKeyboardRGBDeviceInfo(IAuraSyncDevice device, AsusPhysicalKeyboardLayout layout) internal AsusKeyboardRGBDeviceInfo(IAuraSyncDevice device)
: base(RGBDeviceType.Keyboard, device, device.Name) : base(RGBDeviceType.Keyboard, device, device.Name)
{ { }
this.PhysicalLayout = layout;
}
#endregion #endregion
} }

View File

@ -6,7 +6,7 @@ namespace RGB.NET.Devices.Asus
/// <summary> /// <summary>
/// Represents a Asus mainboard. /// Represents a Asus mainboard.
/// </summary> /// </summary>
public class AsusMainboardRGBDevice : AsusRGBDevice<AsusRGBDeviceInfo>, IKeyboard public class AsusMainboardRGBDevice : AsusRGBDevice<AsusRGBDeviceInfo>, IMainboard
{ {
#region Constructors #region Constructors

View File

@ -9,6 +9,12 @@ namespace RGB.NET.Devices.CoolerMaster
/// </summary> /// </summary>
public class CoolerMasterKeyboardRGBDevice : CoolerMasterRGBDevice<CoolerMasterKeyboardRGBDeviceInfo>, IKeyboard public class CoolerMasterKeyboardRGBDevice : CoolerMasterRGBDevice<CoolerMasterKeyboardRGBDeviceInfo>, IKeyboard
{ {
#region Properties & Fields
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
#endregion
#region Constructors #region Constructors
/// <inheritdoc /> /// <inheritdoc />

View File

@ -2,14 +2,16 @@
namespace RGB.NET.Devices.CoolerMaster namespace RGB.NET.Devices.CoolerMaster
{ {
/// <inheritdoc />
/// <summary> /// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />. /// Represents a generic information for a <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterKeyboardRGBDevice" />.
/// </summary> /// </summary>
public class CoolerMasterKeyboardRGBDeviceInfo : CoolerMasterRGBDeviceInfo public class CoolerMasterKeyboardRGBDeviceInfo : CoolerMasterRGBDeviceInfo, IKeyboardDeviceInfo
{ {
#region Properties & Fields #region Properties & Fields
/// <inheritdoc />
public KeyboardLayoutType Layout { get; }
/// <summary> /// <summary>
/// Gets the <see cref="CoolerMasterPhysicalKeyboardLayout"/> of the <see cref="CoolerMasterKeyboardRGBDevice"/>. /// Gets the <see cref="CoolerMasterPhysicalKeyboardLayout"/> of the <see cref="CoolerMasterKeyboardRGBDevice"/>.
/// </summary> /// </summary>
@ -29,6 +31,14 @@ namespace RGB.NET.Devices.CoolerMaster
: base(RGBDeviceType.Keyboard, deviceIndex) : base(RGBDeviceType.Keyboard, deviceIndex)
{ {
this.PhysicalLayout = physicalKeyboardLayout; this.PhysicalLayout = physicalKeyboardLayout;
this.Layout = physicalKeyboardLayout switch
{
CoolerMasterPhysicalKeyboardLayout.UNINIT => KeyboardLayoutType.Unknown,
CoolerMasterPhysicalKeyboardLayout.US => KeyboardLayoutType.Ansi,
CoolerMasterPhysicalKeyboardLayout.EU => KeyboardLayoutType.Iso,
CoolerMasterPhysicalKeyboardLayout.JP => KeyboardLayoutType.Jis,
_ => KeyboardLayoutType.Unknown
};
} }
#endregion #endregion

View File

@ -15,6 +15,12 @@ namespace RGB.NET.Devices.Corsair
/// </summary> /// </summary>
public class CorsairKeyboardRGBDevice : CorsairRGBDevice<CorsairKeyboardRGBDeviceInfo>, IKeyboard public class CorsairKeyboardRGBDevice : CorsairRGBDevice<CorsairKeyboardRGBDeviceInfo>, IKeyboard
{ {
#region Properties & Fields
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
#endregion
#region Constructors #region Constructors
/// <inheritdoc /> /// <inheritdoc />

View File

@ -7,14 +7,16 @@ using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
{ {
/// <inheritdoc />
/// <summary> /// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Corsair.CorsairKeyboardRGBDevice" />. /// Represents a generic information for a <see cref="T:RGB.NET.Devices.Corsair.CorsairKeyboardRGBDevice" />.
/// </summary> /// </summary>
public class CorsairKeyboardRGBDeviceInfo : CorsairRGBDeviceInfo public class CorsairKeyboardRGBDeviceInfo : CorsairRGBDeviceInfo, IKeyboardDeviceInfo
{ {
#region Properties & Fields #region Properties & Fields
/// <inheritdoc />
public KeyboardLayoutType Layout { get; }
/// <summary> /// <summary>
/// Gets the physical layout of the keyboard. /// Gets the physical layout of the keyboard.
/// </summary> /// </summary>
@ -41,6 +43,15 @@ namespace RGB.NET.Devices.Corsair
{ {
this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout; this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout;
this.LogicalLayout = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout; this.LogicalLayout = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout;
this.Layout = PhysicalLayout switch
{
CorsairPhysicalKeyboardLayout.US => KeyboardLayoutType.Ansi,
CorsairPhysicalKeyboardLayout.UK => KeyboardLayoutType.Iso,
CorsairPhysicalKeyboardLayout.BR => KeyboardLayoutType.Unknown,
CorsairPhysicalKeyboardLayout.JP => KeyboardLayoutType.Jis,
CorsairPhysicalKeyboardLayout.KR => KeyboardLayoutType.Unknown,
_ => KeyboardLayoutType.Unknown
};
} }
#endregion #endregion

View File

@ -12,6 +12,12 @@ namespace RGB.NET.Devices.Razer
/// </summary> /// </summary>
public class RazerKeyboardRGBDevice : RazerRGBDevice<RazerKeyboardRGBDeviceInfo>, IKeyboard public class RazerKeyboardRGBDevice : RazerRGBDevice<RazerKeyboardRGBDeviceInfo>, IKeyboard
{ {
#region Properties & Fields
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
#endregion
#region Constructors #region Constructors
/// <inheritdoc /> /// <inheritdoc />

View File

@ -6,12 +6,18 @@ using RGB.NET.Core;
namespace RGB.NET.Devices.Razer namespace RGB.NET.Devices.Razer
{ {
/// <inheritdoc />
/// <summary> /// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerKeyboardRGBDevice" />. /// Represents a generic information for a <see cref="T:RGB.NET.Devices.Razer.RazerKeyboardRGBDevice" />.
/// </summary> /// </summary>
public class RazerKeyboardRGBDeviceInfo : RazerRGBDeviceInfo public class RazerKeyboardRGBDeviceInfo : RazerRGBDeviceInfo, IKeyboardDeviceInfo
{ {
#region Properties & Fields
/// <inheritdoc />
public KeyboardLayoutType Layout => KeyboardLayoutType.Unknown;
#endregion
#region Constructors #region Constructors
/// <inheritdoc /> /// <inheritdoc />

View File

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum;
using RGB.NET.Devices.Wooting.Generic; using RGB.NET.Devices.Wooting.Generic;
namespace RGB.NET.Devices.Wooting.Keyboard namespace RGB.NET.Devices.Wooting.Keyboard
@ -11,6 +12,12 @@ namespace RGB.NET.Devices.Wooting.Keyboard
/// </summary> /// </summary>
public class WootingKeyboardRGBDevice : WootingRGBDevice<WootingKeyboardRGBDeviceInfo>, IKeyboard public class WootingKeyboardRGBDevice : WootingRGBDevice<WootingKeyboardRGBDeviceInfo>, IKeyboard
{ {
#region Properties & Fields
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
#endregion
#region Constructors #region Constructors
/// <inheritdoc /> /// <inheritdoc />
@ -29,14 +36,15 @@ namespace RGB.NET.Devices.Wooting.Keyboard
/// <inheritdoc /> /// <inheritdoc />
protected override void InitializeLayout() protected override void InitializeLayout()
{ {
Dictionary<LedId, (int row, int column)> mapping = WootingKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout]; //TODO DarthAffe 13.02.2021: Check how the mapping can work without knowing the physical layout
Dictionary<LedId, (int row, int column)> mapping = WootingKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][WootingPhysicalKeyboardLayout.US];
foreach (KeyValuePair<LedId, (int row, int column)> led in mapping) 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)); AddLed(led.Key, new Point(led.Value.column * 19, led.Value.row * 19), new Size(19, 19));
} }
/// <inheritdoc /> /// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => WootingKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout][ledId]; protected override object GetLedCustomData(LedId ledId) => WootingKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][WootingPhysicalKeyboardLayout.US][ledId];
/// <inheritdoc /> /// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));

View File

@ -4,18 +4,15 @@ using RGB.NET.Devices.Wooting.Generic;
namespace RGB.NET.Devices.Wooting.Keyboard namespace RGB.NET.Devices.Wooting.Keyboard
{ {
/// <inheritdoc />
/// <summary> /// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.Wooting.Keyboard.WootingKeyboardRGBDevice" />. /// Represents a generic information for a <see cref="T:RGB.NET.Devices.Wooting.Keyboard.WootingKeyboardRGBDevice" />.
/// </summary> /// </summary>
public class WootingKeyboardRGBDeviceInfo : WootingRGBDeviceInfo public class WootingKeyboardRGBDeviceInfo : WootingRGBDeviceInfo, IKeyboardDeviceInfo
{ {
#region Properties & Fields #region Properties & Fields
/// <summary> /// <inheritdoc />
/// Gets the <see cref="WootingPhysicalKeyboardLayout"/> of the <see cref="WootingKeyboardRGBDevice"/>. public KeyboardLayoutType Layout => KeyboardLayoutType.Unknown;
/// </summary>
public WootingPhysicalKeyboardLayout PhysicalLayout { get; }
#endregion #endregion
@ -27,11 +24,9 @@ namespace RGB.NET.Devices.Wooting.Keyboard
/// </summary> /// </summary>
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Wooting.WootingKeyboardRGBDevice" />.</param> /// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Wooting.WootingKeyboardRGBDevice" />.</param>
/// <param name="physicalKeyboardLayout">The <see cref="T:RGB.NET.Devices.Wooting.WootingPhysicalKeyboardLayout" /> of the <see cref="T:RGB.NET.Devices.Wooting.WootingKeyboardRGBDevice" />.</param> /// <param name="physicalKeyboardLayout">The <see cref="T:RGB.NET.Devices.Wooting.WootingPhysicalKeyboardLayout" /> of the <see cref="T:RGB.NET.Devices.Wooting.WootingKeyboardRGBDevice" />.</param>
internal WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes deviceIndex, WootingPhysicalKeyboardLayout physicalKeyboardLayout) internal WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes deviceIndex)
: base(RGBDeviceType.Keyboard, deviceIndex) : base(RGBDeviceType.Keyboard, deviceIndex)
{ { }
this.PhysicalLayout = physicalKeyboardLayout;
}
#endregion #endregion
} }

View File

@ -90,9 +90,8 @@ namespace RGB.NET.Devices.Wooting
_WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!; _WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!;
IWootingRGBDevice device = nativeDeviceInfo.Model switch IWootingRGBDevice device = nativeDeviceInfo.Model switch
{ {
// TODO: Find an accurate way to determine physical and logical layouts "Wooting two" => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingTwo)),
"Wooting two" => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingTwo, WootingPhysicalKeyboardLayout.US)), "Wooting one" => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingOne)),
"Wooting one" => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingOne, WootingPhysicalKeyboardLayout.US)),
_ => throw new RGBDeviceException("No supported Wooting keyboard connected") _ => throw new RGBDeviceException("No supported Wooting keyboard connected")
}; };