1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Implemented update queue and corrected the LED mappings

This commit is contained in:
SpoinkyNL 2019-12-13 10:01:05 +01:00
parent 7690a49e43
commit a94509dfcb
8 changed files with 96 additions and 26 deletions

View File

@ -11,6 +11,6 @@ namespace RGB.NET.Devices.Wooting.Enum
public enum WootingLogicalKeyboardLayout public enum WootingLogicalKeyboardLayout
{ {
US = 0, US = 0,
EU = 1 UK = 1
}; };
} }

View File

@ -11,6 +11,6 @@ namespace RGB.NET.Devices.Wooting.Enum
public enum WootingPhysicalKeyboardLayout public enum WootingPhysicalKeyboardLayout
{ {
US = 0, US = 0,
EU = 1 UK = 1
} }
} }

View File

@ -7,6 +7,6 @@ namespace RGB.NET.Devices.Wooting.Generic
/// </summary> /// </summary>
internal interface IWootingRGBDevice : IRGBDevice internal interface IWootingRGBDevice : IRGBDevice
{ {
void Initialize(UpdateQueue updateQueue); void Initialize(IDeviceUpdateTrigger updateTrigger);
} }
} }

View File

@ -1,8 +1,5 @@
using System; using System.Linq;
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting.Generic namespace RGB.NET.Devices.Wooting.Generic
{ {
@ -44,11 +41,11 @@ namespace RGB.NET.Devices.Wooting.Generic
#endregion #endregion
#region Methods #region Methods
/// <summary> /// <summary>
/// Initializes the device. /// Initializes the device.
/// </summary> /// </summary>
public void Initialize(UpdateQueue updateQueue) public void Initialize(IDeviceUpdateTrigger updateTrigger)
{ {
InitializeLayout(); InitializeLayout();
@ -58,7 +55,7 @@ namespace RGB.NET.Devices.Wooting.Generic
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y); Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
} }
UpdateQueue = updateQueue; UpdateQueue = new WootingUpdateQueue(updateTrigger);
} }
/// <summary> /// <summary>

View File

@ -0,0 +1,42 @@
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting.Generic
{
/// <inheritdoc />
/// <summary>
/// Represents the update-queue performing updates for cooler master devices.
/// </summary>
public class WootingUpdateQueue : UpdateQueue
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="WootingUpdateQueue"/> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
public WootingUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{
}
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet)
{
foreach (KeyValuePair<object, Color> data in dataSet)
{
(int row, int column) = ((int, int))data.Key;
_WootingSDK.ArraySetSingle((byte)row, (byte)column, data.Value.GetR(), data.Value.GetG(), data.Value.GetB());
}
_WootingSDK.ArrayUpdateKeyboard();
}
#endregion
}
}

View File

@ -245,14 +245,14 @@ namespace RGB.NET.Devices.Wooting.Keyboard
{ WootingDevicesIndexes.WootingOne, new Dictionary<WootingPhysicalKeyboardLayout, Dictionary<LedId, (int row, int column)>> { WootingDevicesIndexes.WootingOne, new Dictionary<WootingPhysicalKeyboardLayout, Dictionary<LedId, (int row, int column)>>
{ {
{ WootingPhysicalKeyboardLayout.US, WootingOne_US }, { WootingPhysicalKeyboardLayout.US, WootingOne_US },
{ WootingPhysicalKeyboardLayout.EU, WootingOne_US } { WootingPhysicalKeyboardLayout.UK, WootingOne_US }
} }
}, },
{ WootingDevicesIndexes.WootingTwo, new Dictionary<WootingPhysicalKeyboardLayout, Dictionary<LedId, (int row, int column)>> { WootingDevicesIndexes.WootingTwo, new Dictionary<WootingPhysicalKeyboardLayout, Dictionary<LedId, (int row, int column)>>
{ {
{ WootingPhysicalKeyboardLayout.US, WootingTwo_US }, { WootingPhysicalKeyboardLayout.US, WootingTwo_US },
{ WootingPhysicalKeyboardLayout.EU, WootingTwo_US } { WootingPhysicalKeyboardLayout.UK, WootingTwo_US }
} }
} }
}; };

View File

@ -40,14 +40,13 @@ namespace RGB.NET.Devices.Wooting.Keyboard
{ {
this.PhysicalLayout = physicalKeyboardLayout; this.PhysicalLayout = physicalKeyboardLayout;
// For now just go for this
switch (physicalKeyboardLayout) switch (physicalKeyboardLayout)
{ {
case WootingPhysicalKeyboardLayout.US: case WootingPhysicalKeyboardLayout.US:
this.LogicalLayout = WootingLogicalKeyboardLayout.US; this.LogicalLayout = WootingLogicalKeyboardLayout.US;
break; break;
case WootingPhysicalKeyboardLayout.EU: case WootingPhysicalKeyboardLayout.UK:
this.LogicalLayout = WootingLogicalKeyboardLayout.EU; this.LogicalLayout = WootingLogicalKeyboardLayout.UK;
break; break;
} }
} }

View File

@ -2,6 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
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.Keyboard;
using RGB.NET.Devices.Wooting.Native; using RGB.NET.Devices.Wooting.Native;
namespace RGB.NET.Devices.Wooting namespace RGB.NET.Devices.Wooting
@ -24,13 +27,13 @@ namespace RGB.NET.Devices.Wooting
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX86NativePaths { get; } = new List<string> { "x86/wooting-rgb-sdk.dll" }; public static List<string> PossibleX86NativePaths { get; } = new List<string> {"x86/wooting-rgb-sdk.dll"};
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX64NativePaths { get; } = new List<string> { "x64/wooting-rgb-sdk64.dll" }; public static List<string> PossibleX64NativePaths { get; } = new List<string> {"x64/wooting-rgb-sdk64.dll"};
/// <inheritdoc /> /// <inheritdoc />
/// <summary> /// <summary>
@ -52,6 +55,11 @@ namespace RGB.NET.Devices.Wooting
/// <inheritdoc /> /// <inheritdoc />
public IEnumerable<IRGBDevice> Devices { get; private set; } public IEnumerable<IRGBDevice> Devices { get; private set; }
/// <summary>
/// The <see cref="DeviceUpdateTrigger"/> used to trigger the updates for cooler master devices.
/// </summary>
public DeviceUpdateTrigger UpdateTrigger { get; private set; }
#endregion #endregion
#region Constructors #region Constructors
@ -62,8 +70,11 @@ namespace RGB.NET.Devices.Wooting
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception> /// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public WootingDeviceProvider() public WootingDeviceProvider()
{ {
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}"); if (_instance != null)
throw new InvalidOperationException($"There can be only one instance of type {nameof(WootingDeviceProvider)}");
_instance = this; _instance = this;
UpdateTrigger = new DeviceUpdateTrigger();
} }
#endregion #endregion
@ -72,26 +83,45 @@ namespace RGB.NET.Devices.Wooting
/// <inheritdoc /> /// <inheritdoc />
/// <exception cref="RGBDeviceException">Thrown if the SDK failed to initialize</exception> /// <exception cref="RGBDeviceException">Thrown if the SDK failed to initialize</exception>
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false,
bool throwExceptions = false)
{ {
IsInitialized = false; IsInitialized = false;
try try
{ {
UpdateTrigger?.Stop();
_WootingSDK.Reload(); _WootingSDK.Reload();
IList<IRGBDevice> devices = new List<IRGBDevice>(); IList<IRGBDevice> devices = new List<IRGBDevice>();
if (_WootingSDK.KeyboardConnected()) if (_WootingSDK.KeyboardConnected())
{ {
if (_WootingSDK.IsWootingOne()) IWootingRGBDevice device;
// TODO: Find an accurate way to determine physical and logical layouts
if (_WootingSDK.IsWootingTwo())
{ {
device = new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingTwo,
} WootingPhysicalKeyboardLayout.US,
else if (_WootingSDK.IsWootingTwo()) CultureHelper.GetCurrentCulture()));
{
} }
else if (_WootingSDK.IsWootingOne())
{
device = new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingOne,
WootingPhysicalKeyboardLayout.US,
CultureHelper.GetCurrentCulture()));
}
else
{
throw new RGBDeviceException("No supported Wooting keyboard connected");
}
device.Initialize(UpdateTrigger);
devices.Add(device);
} }
UpdateTrigger?.Start();
Devices = new ReadOnlyCollection<IRGBDevice>(devices); Devices = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true; IsInitialized = true;
} }
@ -112,7 +142,9 @@ namespace RGB.NET.Devices.Wooting
public void Dispose() public void Dispose()
{ {
try { _WootingSDK.Reset(); } try { _WootingSDK.Reset(); }
catch { /* Unlucky.. */} catch
{ /* Unlucky.. */
}
} }
#endregion #endregion