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

ASUS - Keyboards guard against double LEDs

ASUS - Keyboards return the correct AsusLed in GetLedCustomData
This commit is contained in:
Robert 2021-03-27 14:38:09 +01:00
parent c963bcd9d7
commit a52bb474ef

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using AuraServiceLib; using AuraServiceLib;
using RGB.NET.Core; using RGB.NET.Core;
@ -13,6 +12,8 @@ namespace RGB.NET.Devices.Asus
{ {
#region Properties & Fields #region Properties & Fields
private Dictionary<LedId, AsusLedId> _ledAsusLed = new();
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo; IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
#endregion #endregion
@ -42,15 +43,15 @@ namespace RGB.NET.Devices.Asus
foreach (IAuraRgbKey key in ((IAuraSyncKeyboard)DeviceInfo.Device).Keys) foreach (IAuraRgbKey key in ((IAuraSyncKeyboard)DeviceInfo.Device).Keys)
{ {
if (AsusKeyboardLedMapping.MAPPING.TryGetValue((AsusLedId)key.Code, out LedId ledId)) if (AsusKeyboardLedMapping.MAPPING.TryGetValue((AsusLedId)key.Code, out LedId ledId))
AddLed(ledId, new Point(pos++ * 19, 0), new Size(19, 19)); AddAsusLed((AsusLedId)key.Code, ledId, new Point(pos++ * 19, 0), new Size(19, 19));
else else
throw new RGBDeviceException($"Couldn't find a LED mapping for key {key.Code:X} named '{key.Name}' on device '{DeviceInfo.DeviceName}'"); throw new RGBDeviceException($"Couldn't find a LED mapping for key {key.Code:X} named '{key.Name}' on device '{DeviceInfo.DeviceName}'");
} }
//UK Layout // UK Layout
AddLed(AsusKeyboardLedMapping.MAPPING[AsusLedId.KEY_OEM_102], new Point(pos++ * 19, 0), new Size(19, 19)); AddAsusLed(AsusLedId.KEY_OEM_102, AsusKeyboardLedMapping.MAPPING[AsusLedId.KEY_OEM_102], new Point(pos++ * 19, 0), new Size(19, 19));
AddAsusLed(AsusLedId.KEY_OEM_102, AsusKeyboardLedMapping.MAPPING[AsusLedId.UNDOCUMENTED_1], new Point(pos * 19, 0), new Size(19, 19));
AddLed(AsusKeyboardLedMapping.MAPPING[AsusLedId.UNDOCUMENTED_1], new Point(pos * 19, 0), new Size(19, 19));
} }
else else
{ {
@ -60,13 +61,21 @@ namespace RGB.NET.Devices.Asus
} }
} }
private void AddAsusLed(AsusLedId asusLedId, LedId ledId, Point position, Size size)
{
if (this._ledAsusLed.TryGetValue(ledId, out AsusLedId firstAsusLed))
throw new RGBDeviceException($"Got LED '{ledId}' twice, first ASUS LED '{firstAsusLed}' second ASUS LED '{asusLedId}' on device '{DeviceInfo.DeviceName}'");
this._ledAsusLed.Add(ledId, asusLedId);
AddLed(ledId, position, size);
}
/// <inheritdoc /> /// <inheritdoc />
protected override object? GetLedCustomData(LedId ledId) protected override object? GetLedCustomData(LedId ledId)
{ {
if (DeviceInfo.Device.Type == (uint)AsusDeviceType.NB_KB_4ZONE_RGB) if (this._ledAsusLed.TryGetValue(ledId, out AsusLedId asusLedId))
return ledId - LedId.Keyboard_Custom1; return asusLedId;
return null;
return AsusKeyboardLedMapping.MAPPING.FirstOrDefault(m => m.Value == ledId).Key;
} }
#endregion #endregion