diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index 580ab42..609dbf9 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -45,6 +45,7 @@ namespace RGB.NET.Devices.Asus protected override void InitializeSDK() { + // ReSharper disable once SuspiciousTypeConversion.Global _sdk = (IAuraSdk2)new AuraSdk(); _sdk.SwitchMode(); } diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs index 63b5ebd..6b6977a 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs @@ -42,13 +42,23 @@ namespace RGB.NET.Devices.Asus { if ((Device.Type == (uint)AsusDeviceType.KEYBOARD_RGB) || (Device.Type == (uint)AsusDeviceType.NB_KB_RGB)) { - foreach ((object key, Color value) in dataSet) + if (Device is not IAuraSyncKeyboard keyboard) + return; + + foreach ((object customData, Color value) in dataSet) { - AsusLedId index = (AsusLedId)key; - if (Device is IAuraSyncKeyboard keyboard) + (bool, int) customDataTuple = ((bool, int))customData; + if (customDataTuple.Item1) { - IAuraRgbLight light = keyboard.Key[(ushort)index]; - + IAuraRgbLight light = keyboard.Key[(ushort)customDataTuple.Item2]; + (_, byte r, byte g, byte b) = value.GetRGBBytes(); + light.Red = r; + light.Green = g; + light.Blue = b; + } + else + { + IAuraRgbLight light = keyboard.Lights[customDataTuple.Item2]; (_, byte r, byte g, byte b) = value.GetRGBBytes(); light.Red = r; light.Green = g; diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs index 1bba8c5..91823ea 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using AuraServiceLib; using RGB.NET.Core; @@ -13,6 +14,7 @@ namespace RGB.NET.Devices.Asus #region Properties & Fields private Dictionary _ledAsusLed = new(); + private Dictionary _ledAsusLights = new(); IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo; @@ -40,10 +42,28 @@ namespace RGB.NET.Devices.Asus if (DeviceInfo.Device.Type != (uint)AsusDeviceType.NB_KB_4ZONE_RGB) { int pos = 0; - foreach (IAuraRgbKey key in ((IAuraSyncKeyboard)DeviceInfo.Device).Keys) + int unknownLed = (int)LedId.Unknown1; + + List keys = ((IAuraSyncKeyboard)DeviceInfo.Device).Keys.Cast().ToList(); + foreach (IAuraRgbKey key in keys) { if (AsusKeyboardLedMapping.MAPPING.TryGetValue((AsusLedId)key.Code, out LedId ledId)) AddAsusLed((AsusLedId)key.Code, ledId, new Point(pos++ * 19, 0), new Size(19, 19)); + else + { + AddAsusLed((AsusLedId)key.Code, (LedId)unknownLed, new Point(pos++ * 19, 0), new Size(19, 19)); + unknownLed++; + } + } + + for (int index = 0; index < ((IAuraSyncKeyboard)DeviceInfo.Device).Lights.Count; index++) + { + IAuraRgbLight light = ((IAuraSyncKeyboard)DeviceInfo.Device).Lights[index]; + if (keys.Contains(light)) + continue; + + AddAsusLed(index, (LedId)unknownLed, new Point(pos++ * 19, 0), new Size(19, 19)); + unknownLed++; } } else @@ -57,17 +77,26 @@ 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}'"); + 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); } + private void AddAsusLed(int index, LedId ledId, Point position, Size size) + { + this._ledAsusLights.Add(ledId, index); + AddLed(ledId, position, size); + } + /// protected override object? GetLedCustomData(LedId ledId) { if (this._ledAsusLed.TryGetValue(ledId, out AsusLedId asusLedId)) - return asusLedId; + return (true, (int)asusLedId); + if (this._ledAsusLights.TryGetValue(ledId, out int lightIndex)) + return (false, lightIndex); return null; }