From c47afc4704e1a23dcfa5f16181dfc6519c94373f Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 8 Jul 2018 20:04:01 +0200 Subject: [PATCH] Updated corsair SDK This adds support for custom devices (lightning node and commander). And introduced 'fan' as device type. fixes #23 --- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 2 +- RGB.NET.Core/Devices/RGBDeviceType.cs | 5 + RGB.NET.Core/Leds/LedId.cs | 66 ++++ RGB.NET.Core/Update/CustomUpdateData.cs | 4 +- RGB.NET.Core/Update/Devices/UpdateQueue.cs | 15 +- .../CorsairDeviceProvider.cs | 81 ++++- .../Custom/CorsairCustomRGBDevice.cs | 57 ++++ .../Custom/CorsairCustomRGBDeviceInfo.cs | 78 +++++ .../Enum/CorsairChannelDeviceType.cs | 22 ++ .../Enum/CorsairDeviceType.cs | 4 +- RGB.NET.Devices.Corsair/Enum/CorsairLedId.cs | 302 ++++++++++++++++++ ...teQueue.cs => CorsairDeviceUpdateQueue.cs} | 21 +- .../Generic/CorsairRGBDevice.cs | 10 +- .../Generic/CorsairRGBDeviceInfo.cs | 19 +- .../Generic/ICorsairRGBDevice.cs | 2 +- .../CorsairHeadsetStandRGBDevice.cs | 4 +- .../Helper/NativeExtensions.cs | 19 ++ .../Keyboard/CorsairKeyboardRGBDevice.cs | 5 +- .../Mouse/CorsairMouseRGBDeviceInfo.cs | 2 +- .../Mousepad/CorsairMousepadRGBDevice.cs | 2 +- RGB.NET.Devices.Corsair/Native/_CUESDK.cs | 61 ++-- .../Native/_CorsairChannelDeviceInfo.cs | 26 ++ .../Native/_CorsairChannelInfo.cs | 33 ++ .../Native/_CorsairChannelsInfo.cs | 28 ++ .../Native/_CorsairDeviceInfo.cs | 5 + ...RGB.NET.Devices.Corsair.csproj.DotSettings | 1 + 26 files changed, 810 insertions(+), 64 deletions(-) create mode 100644 RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs create mode 100644 RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs rename RGB.NET.Devices.Corsair/Generic/{CorsairUpdateQueue.cs => CorsairDeviceUpdateQueue.cs} (72%) create mode 100644 RGB.NET.Devices.Corsair/Helper/NativeExtensions.cs create mode 100644 RGB.NET.Devices.Corsair/Native/_CorsairChannelDeviceInfo.cs create mode 100644 RGB.NET.Devices.Corsair/Native/_CorsairChannelInfo.cs create mode 100644 RGB.NET.Devices.Corsair/Native/_CorsairChannelsInfo.cs diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index f9ceed4..4579c18 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -204,7 +204,7 @@ namespace RGB.NET.Core /// public T GetSpecialDevicePart() where T : class, IRGBDeviceSpecialPart - => SpecialDeviceParts.TryGetValue(typeof(T), out IRGBDeviceSpecialPart devicePart) ? (T)devicePart : default(T); + => SpecialDeviceParts.TryGetValue(typeof(T), out IRGBDeviceSpecialPart devicePart) ? (T)devicePart : default; #region Enumerator diff --git a/RGB.NET.Core/Devices/RGBDeviceType.cs b/RGB.NET.Core/Devices/RGBDeviceType.cs index bb53fa0..3880189 100644 --- a/RGB.NET.Core/Devices/RGBDeviceType.cs +++ b/RGB.NET.Core/Devices/RGBDeviceType.cs @@ -73,6 +73,11 @@ namespace RGB.NET.Core /// Keypad = 1 << 10, + /// + /// Represents a fan. + /// + Fan = 1 << 1, + /// /// Represents all devices. /// diff --git a/RGB.NET.Core/Leds/LedId.cs b/RGB.NET.Core/Leds/LedId.cs index abef1fe..116dc30 100644 --- a/RGB.NET.Core/Leds/LedId.cs +++ b/RGB.NET.Core/Leds/LedId.cs @@ -1002,6 +1002,72 @@ namespace RGB.NET.Core Keypad63 = 0x00A0003F, Keypad64 = 0x00A00040, + /*### Fan ###*/ + Fan1 = 0x00B00001, + Fan2 = 0x00B00002, + Fan3 = 0x00B00003, + Fan4 = 0x00B00004, + Fan5 = 0x00B00005, + Fan6 = 0x00B00006, + Fan7 = 0x00B00007, + Fan8 = 0x00B00008, + Fan9 = 0x00B00009, + Fan10 = 0x00B0000A, + Fan11 = 0x00B0000B, + Fan12 = 0x00B0000C, + Fan13 = 0x00B0000D, + Fan14 = 0x00B0000E, + Fan15 = 0x00B0000F, + Fan16 = 0x00B00010, + Fan17 = 0x00B00011, + Fan18 = 0x00B00012, + Fan19 = 0x00B00013, + Fan20 = 0x00B00014, + Fan21 = 0x00B00015, + Fan22 = 0x00B00016, + Fan23 = 0x00B00017, + Fan24 = 0x00B00018, + Fan25 = 0x00B00019, + Fan26 = 0x00B0001A, + Fan27 = 0x00B0001B, + Fan28 = 0x00B0001C, + Fan29 = 0x00B0001D, + Fan30 = 0x00B0001E, + Fan31 = 0x00B0001F, + Fan32 = 0x00B00020, + Fan33 = 0x00B00021, + Fan34 = 0x00B00022, + Fan35 = 0x00B00023, + Fan36 = 0x00B00024, + Fan37 = 0x00B00025, + Fan38 = 0x00B00026, + Fan39 = 0x00B00027, + Fan40 = 0x00B00028, + Fan41 = 0x00B00029, + Fan42 = 0x00B0002A, + Fan43 = 0x00B0002B, + Fan44 = 0x00B0002C, + Fan45 = 0x00B0002D, + Fan46 = 0x00B0002E, + Fan47 = 0x00B0002F, + Fan48 = 0x00B00030, + Fan49 = 0x00B00031, + Fan50 = 0x00B00032, + Fan51 = 0x00B00033, + Fan52 = 0x00B00034, + Fan53 = 0x00B00035, + Fan54 = 0x00B00036, + Fan55 = 0x00B00037, + Fan56 = 0x00B00038, + Fan57 = 0x00B00039, + Fan58 = 0x00B0003A, + Fan59 = 0x00B0003B, + Fan60 = 0x00B0003C, + Fan61 = 0x00B0003D, + Fan62 = 0x00B0003E, + Fan63 = 0x00B0003F, + Fan64 = 0x00B00040, + /*### Custom ###*/ Custom1 = 0x0FF00001, Custom2 = 0x0FF00002, diff --git a/RGB.NET.Core/Update/CustomUpdateData.cs b/RGB.NET.Core/Update/CustomUpdateData.cs index 1e7091c..0ecfc7f 100644 --- a/RGB.NET.Core/Update/CustomUpdateData.cs +++ b/RGB.NET.Core/Update/CustomUpdateData.cs @@ -22,8 +22,8 @@ namespace RGB.NET.Core /// The value represented by the given key. public object this[string key] { - get => _data.TryGetValue(key?.ToUpperInvariant(), out object data) ? data : default; - set => _data[key?.ToUpperInvariant()] = value; + get => _data.TryGetValue(key?.ToUpperInvariant() ?? string.Empty, out object data) ? data : default; + set => _data[key?.ToUpperInvariant() ?? string.Empty] = value; } #endregion diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index 11660de..05aff8d 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; namespace RGB.NET.Core @@ -8,7 +9,7 @@ namespace RGB.NET.Core /// /// The type of the key used to identify some data. /// The type of the data. - public abstract class UpdateQueue + public abstract class UpdateQueue : IDisposable { #region Properties & Fields @@ -24,7 +25,7 @@ namespace RGB.NET.Core /// Initializes a new instance of the class. /// /// The causing this queue to update. - public UpdateQueue(IDeviceUpdateTrigger updateTrigger) + protected UpdateQueue(IDeviceUpdateTrigger updateTrigger) { this._updateTrigger = updateTrigger; @@ -99,6 +100,14 @@ namespace RGB.NET.Core _currentDataSet = null; } + public void Dispose() + { + _updateTrigger.Starting -= OnStartup; + _updateTrigger.Update -= OnUpdate; + + Reset(); + } + #endregion } diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 708f6b5..017f735 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -69,8 +69,7 @@ namespace RGB.NET.Devices.Corsair /// /// The used to trigger the updates for corsair devices. /// - public DeviceUpdateTrigger UpdateTrigger { get; private set; } - private CorsairUpdateQueue _updateQueue; + public DeviceUpdateTrigger UpdateTrigger { get; } #endregion @@ -86,7 +85,6 @@ namespace RGB.NET.Devices.Corsair _instance = this; UpdateTrigger = new DeviceUpdateTrigger(); - _updateQueue = new CorsairUpdateQueue(UpdateTrigger); } #endregion @@ -127,6 +125,10 @@ namespace RGB.NET.Devices.Corsair else HasExclusiveAccess = false; + // DarthAffe 07.07.2018: 127 is CUE, we want to directly compete with it as in older versions. + if (!_CUESDK.CorsairSetLayerPriority(127)) + throw new CUEException(LastError); + IList devices = new List(); int deviceCount = _CUESDK.CorsairGetDeviceCount(); for (int i = 0; i < deviceCount; i++) @@ -138,17 +140,23 @@ namespace RGB.NET.Devices.Corsair if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting)) continue; // Everything that doesn't support lighting control is useless - ICorsairRGBDevice device = GetRGBDevice(info, i, nativeDeviceInfo); - if ((device == null) || !loadFilter.HasFlag(device.DeviceInfo.DeviceType)) continue; + CorsairDeviceUpdateQueue deviceUpdateQueue = null; + foreach (ICorsairRGBDevice device in GetRGBDevice(info, i, nativeDeviceInfo)) + { + if ((device == null) || !loadFilter.HasFlag(device.DeviceInfo.DeviceType)) continue; - device.Initialize(_updateQueue); - AddSpecialParts(device); + if (deviceUpdateQueue == null) + deviceUpdateQueue = new CorsairDeviceUpdateQueue(UpdateTrigger, info.CorsairDeviceIndex); - error = LastError; - if (error != CorsairError.Success) - throw new CUEException(error); + device.Initialize(deviceUpdateQueue); + AddSpecialParts(device); - devices.Add(device); + error = LastError; + if (error != CorsairError.Success) + throw new CUEException(error); + + devices.Add(device); + } } catch { if (throwExceptions) throw; } } @@ -168,24 +176,63 @@ namespace RGB.NET.Devices.Corsair return true; } - private static ICorsairRGBDevice GetRGBDevice(CorsairRGBDeviceInfo info, int i, _CorsairDeviceInfo nativeDeviceInfo) + private static IEnumerable GetRGBDevice(CorsairRGBDeviceInfo info, int i, _CorsairDeviceInfo nativeDeviceInfo) { switch (info.CorsairDeviceType) { case CorsairDeviceType.Keyboard: - return new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo)); + yield return new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo)); + break; case CorsairDeviceType.Mouse: - return new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo)); + yield return new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo)); + break; case CorsairDeviceType.Headset: - return new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo)); + yield return new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo)); + break; case CorsairDeviceType.Mousepad: - return new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo)); + yield return new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo)); + break; case CorsairDeviceType.HeadsetStand: - return new CorsairHeadsetStandRGBDevice(new CorsairHeadsetStandRGBDeviceInfo(i, nativeDeviceInfo)); + yield return new CorsairHeadsetStandRGBDevice(new CorsairHeadsetStandRGBDeviceInfo(i, nativeDeviceInfo)); + break; + + case CorsairDeviceType.CommanderPro: + case CorsairDeviceType.LightningNodePro: + _CorsairChannelsInfo channelsInfo = nativeDeviceInfo.channels; + if (channelsInfo != null) + { + IntPtr channelInfoPtr = channelsInfo.channels; + + for (int channel = 0; channel < channelsInfo.channelsCount; channel++) + { + CorsairLedId referenceLed = channel == 0 ? CorsairLedId.CustomDeviceChannel1Led1 : CorsairLedId.CustomDeviceChannel2Led1; + + _CorsairChannelInfo channelInfo = (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo)); + + int channelDeviceInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelDeviceInfo)); + IntPtr channelDeviceInfoPtr = channelInfo.devices; + + for (int device = 0; device < channelInfo.devicesCount; device++) + { + _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo)); + + yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(info.CorsairDeviceIndex, nativeDeviceInfo, channelDeviceInfo, referenceLed)); + referenceLed += channelDeviceInfo.deviceLedCount; + + channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize); + } + + int channelInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelInfo)); + channelInfoPtr = new IntPtr(channelInfoPtr.ToInt64() + channelInfoStructSize); + } + } + + break; + // ReSharper disable once RedundantCaseLabel case CorsairDeviceType.Unknown: diff --git a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs new file mode 100644 index 0000000..e6e502b --- /dev/null +++ b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs @@ -0,0 +1,57 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using System.Collections.Generic; +using RGB.NET.Core; + +namespace RGB.NET.Devices.Corsair +{ + /// + /// + /// Represents a corsair custom. + /// + public class CorsairCustomRGBDevice : CorsairRGBDevice + { + #region Properties & Fields + + private readonly Dictionary _idMapping = new Dictionary(); + + #endregion + + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by CUE for the custom-device. + internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info) + : base(info) + { } + + #endregion + + #region Methods + + /// + protected override void InitializeLayout() + { + LedId referenceId = (DeviceInfo.DeviceType == RGBDeviceType.LedStripe ? LedId.LedStripe1 : (DeviceInfo.DeviceType == RGBDeviceType.Fan ? LedId.Fan1 : LedId.Custom1)); + + for (int i = 0; i < DeviceInfo.LedCount; i++) + { + LedId ledId = referenceId + i; + _idMapping.Add(ledId, DeviceInfo.ReferenceCorsairLed + i); + InitializeLed(ledId, new Rectangle(i * 10, 0, 10, 10)); + } + + string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\Customs\{model}.xml"), null); + } + + /// + protected override object CreateLedCustomData(LedId ledId) => _idMapping.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid; + + #endregion + } +} diff --git a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs new file mode 100644 index 0000000..eac5d13 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs @@ -0,0 +1,78 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using System; +using RGB.NET.Core; +using RGB.NET.Devices.Corsair.Native; + +namespace RGB.NET.Devices.Corsair +{ + /// + /// + /// Represents a generic information for a . + /// + public class CorsairCustomRGBDeviceInfo : CorsairRGBDeviceInfo + { + #region Properties & Fields + + public CorsairLedId ReferenceCorsairLed { get; } + public int LedCount { get; } + + #endregion + + #region Constructors + + //TODO DarthAffe 07.07.2018: DAP is a fan right now, that's most likely wrong + /// + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The native -struct + /// The native representing this device. + /// The id of the first led of this device. + internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, CorsairLedId referenceCorsairLed) + : base(deviceIndex, channelDeviceInfo.type == CorsairChannelDeviceType.Strip ? RGBDeviceType.LedStripe : RGBDeviceType.Fan, nativeInfo, GetModelName(channelDeviceInfo.type)) + { + this.ReferenceCorsairLed = referenceCorsairLed; + + LedCount = channelDeviceInfo.deviceLedCount; + } + + #endregion + + #region Methods + + private static string GetModelName(CorsairChannelDeviceType deviceType) + { + switch (deviceType) + { + case CorsairChannelDeviceType.Invalid: + return "Invalid"; + + case CorsairChannelDeviceType.FanHD: + return "HD Fan"; + + case CorsairChannelDeviceType.FanSP: + return "SP Fan"; + + case CorsairChannelDeviceType.FanLL: + return "LL Fan"; + + case CorsairChannelDeviceType.FanML: + return "ML Fan"; + + case CorsairChannelDeviceType.Strip: + return "Led Strip"; + + case CorsairChannelDeviceType.DAP: + return "DAP Fan"; + + default: + throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null); + } + } + + #endregion + } +} diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs b/RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs new file mode 100644 index 0000000..d834044 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Enum/CorsairChannelDeviceType.cs @@ -0,0 +1,22 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global + + +#pragma warning disable 1591 // Missing XML comment for publicly visible type or member + +namespace RGB.NET.Devices.Corsair +{ + /// + /// Contains list of available corsair channel device types. + /// + public enum CorsairChannelDeviceType + { + Invalid = 0, + FanHD = 1, + FanSP = 2, + FanLL = 3, + FanML = 4, + Strip = 5, + DAP = 6, + }; +} diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs b/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs index 19b7e39..8548bdd 100644 --- a/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs +++ b/RGB.NET.Devices.Corsair/Enum/CorsairDeviceType.cs @@ -16,6 +16,8 @@ namespace RGB.NET.Devices.Corsair Keyboard = 2, Headset = 3, Mousepad = 4, - HeadsetStand = 5 + HeadsetStand = 5, + CommanderPro = 6, + LightningNodePro = 7 }; } diff --git a/RGB.NET.Devices.Corsair/Enum/CorsairLedId.cs b/RGB.NET.Devices.Corsair/Enum/CorsairLedId.cs index f5a1a69..4dd7ffb 100644 --- a/RGB.NET.Devices.Corsair/Enum/CorsairLedId.cs +++ b/RGB.NET.Devices.Corsair/Enum/CorsairLedId.cs @@ -215,5 +215,307 @@ namespace RGB.NET.Devices.Corsair HeadsetStandZone7 = 197, HeadsetStandZone8 = 198, HeadsetStandZone9 = 199, + + CustomDeviceChannel1Led1 = 200, + CustomDeviceChannel1Led2 = 201, + CustomDeviceChannel1Led3 = 202, + CustomDeviceChannel1Led4 = 203, + CustomDeviceChannel1Led5 = 204, + CustomDeviceChannel1Led6 = 205, + CustomDeviceChannel1Led7 = 206, + CustomDeviceChannel1Led8 = 207, + CustomDeviceChannel1Led9 = 208, + CustomDeviceChannel1Led10 = 209, + CustomDeviceChannel1Led11 = 210, + CustomDeviceChannel1Led12 = 211, + CustomDeviceChannel1Led13 = 212, + CustomDeviceChannel1Led14 = 213, + CustomDeviceChannel1Led15 = 214, + CustomDeviceChannel1Led16 = 215, + CustomDeviceChannel1Led17 = 216, + CustomDeviceChannel1Led18 = 217, + CustomDeviceChannel1Led19 = 218, + CustomDeviceChannel1Led20 = 219, + CustomDeviceChannel1Led21 = 220, + CustomDeviceChannel1Led22 = 221, + CustomDeviceChannel1Led23 = 222, + CustomDeviceChannel1Led24 = 223, + CustomDeviceChannel1Led25 = 224, + CustomDeviceChannel1Led26 = 225, + CustomDeviceChannel1Led27 = 226, + CustomDeviceChannel1Led28 = 227, + CustomDeviceChannel1Led29 = 228, + CustomDeviceChannel1Led30 = 229, + CustomDeviceChannel1Led31 = 230, + CustomDeviceChannel1Led32 = 231, + CustomDeviceChannel1Led33 = 232, + CustomDeviceChannel1Led34 = 233, + CustomDeviceChannel1Led35 = 234, + CustomDeviceChannel1Led36 = 235, + CustomDeviceChannel1Led37 = 236, + CustomDeviceChannel1Led38 = 237, + CustomDeviceChannel1Led39 = 238, + CustomDeviceChannel1Led40 = 239, + CustomDeviceChannel1Led41 = 240, + CustomDeviceChannel1Led42 = 241, + CustomDeviceChannel1Led43 = 242, + CustomDeviceChannel1Led44 = 243, + CustomDeviceChannel1Led45 = 244, + CustomDeviceChannel1Led46 = 245, + CustomDeviceChannel1Led47 = 246, + CustomDeviceChannel1Led48 = 247, + CustomDeviceChannel1Led49 = 248, + CustomDeviceChannel1Led50 = 249, + CustomDeviceChannel1Led51 = 250, + CustomDeviceChannel1Led52 = 251, + CustomDeviceChannel1Led53 = 252, + CustomDeviceChannel1Led54 = 253, + CustomDeviceChannel1Led55 = 254, + CustomDeviceChannel1Led56 = 255, + CustomDeviceChannel1Led57 = 256, + CustomDeviceChannel1Led58 = 257, + CustomDeviceChannel1Led59 = 258, + CustomDeviceChannel1Led60 = 259, + CustomDeviceChannel1Led61 = 260, + CustomDeviceChannel1Led62 = 261, + CustomDeviceChannel1Led63 = 262, + CustomDeviceChannel1Led64 = 263, + CustomDeviceChannel1Led65 = 264, + CustomDeviceChannel1Led66 = 265, + CustomDeviceChannel1Led67 = 266, + CustomDeviceChannel1Led68 = 267, + CustomDeviceChannel1Led69 = 268, + CustomDeviceChannel1Led70 = 269, + CustomDeviceChannel1Led71 = 270, + CustomDeviceChannel1Led72 = 271, + CustomDeviceChannel1Led73 = 272, + CustomDeviceChannel1Led74 = 273, + CustomDeviceChannel1Led75 = 274, + CustomDeviceChannel1Led76 = 275, + CustomDeviceChannel1Led77 = 276, + CustomDeviceChannel1Led78 = 277, + CustomDeviceChannel1Led79 = 278, + CustomDeviceChannel1Led80 = 279, + CustomDeviceChannel1Led81 = 280, + CustomDeviceChannel1Led82 = 281, + CustomDeviceChannel1Led83 = 282, + CustomDeviceChannel1Led84 = 283, + CustomDeviceChannel1Led85 = 284, + CustomDeviceChannel1Led86 = 285, + CustomDeviceChannel1Led87 = 286, + CustomDeviceChannel1Led88 = 287, + CustomDeviceChannel1Led89 = 288, + CustomDeviceChannel1Led90 = 289, + CustomDeviceChannel1Led91 = 290, + CustomDeviceChannel1Led92 = 291, + CustomDeviceChannel1Led93 = 292, + CustomDeviceChannel1Led94 = 293, + CustomDeviceChannel1Led95 = 294, + CustomDeviceChannel1Led96 = 295, + CustomDeviceChannel1Led97 = 296, + CustomDeviceChannel1Led98 = 297, + CustomDeviceChannel1Led99 = 298, + CustomDeviceChannel1Led100 = 299, + CustomDeviceChannel1Led101 = 300, + CustomDeviceChannel1Led102 = 301, + CustomDeviceChannel1Led103 = 302, + CustomDeviceChannel1Led104 = 303, + CustomDeviceChannel1Led105 = 304, + CustomDeviceChannel1Led106 = 305, + CustomDeviceChannel1Led107 = 306, + CustomDeviceChannel1Led108 = 307, + CustomDeviceChannel1Led109 = 308, + CustomDeviceChannel1Led110 = 309, + CustomDeviceChannel1Led111 = 310, + CustomDeviceChannel1Led112 = 311, + CustomDeviceChannel1Led113 = 312, + CustomDeviceChannel1Led114 = 313, + CustomDeviceChannel1Led115 = 314, + CustomDeviceChannel1Led116 = 315, + CustomDeviceChannel1Led117 = 316, + CustomDeviceChannel1Led118 = 317, + CustomDeviceChannel1Led119 = 318, + CustomDeviceChannel1Led120 = 319, + CustomDeviceChannel1Led121 = 320, + CustomDeviceChannel1Led122 = 321, + CustomDeviceChannel1Led123 = 322, + CustomDeviceChannel1Led124 = 323, + CustomDeviceChannel1Led125 = 324, + CustomDeviceChannel1Led126 = 325, + CustomDeviceChannel1Led127 = 326, + CustomDeviceChannel1Led128 = 327, + CustomDeviceChannel1Led129 = 328, + CustomDeviceChannel1Led130 = 329, + CustomDeviceChannel1Led131 = 330, + CustomDeviceChannel1Led132 = 331, + CustomDeviceChannel1Led133 = 332, + CustomDeviceChannel1Led134 = 333, + CustomDeviceChannel1Led135 = 334, + CustomDeviceChannel1Led136 = 335, + CustomDeviceChannel1Led137 = 336, + CustomDeviceChannel1Led138 = 337, + CustomDeviceChannel1Led139 = 338, + CustomDeviceChannel1Led140 = 339, + CustomDeviceChannel1Led141 = 340, + CustomDeviceChannel1Led142 = 341, + CustomDeviceChannel1Led143 = 342, + CustomDeviceChannel1Led144 = 343, + CustomDeviceChannel1Led145 = 344, + CustomDeviceChannel1Led146 = 345, + CustomDeviceChannel1Led147 = 346, + CustomDeviceChannel1Led148 = 347, + CustomDeviceChannel1Led149 = 348, + CustomDeviceChannel1Led150 = 349, + + CustomDeviceChannel2Led1 = 350, + CustomDeviceChannel2Led2 = 351, + CustomDeviceChannel2Led3 = 352, + CustomDeviceChannel2Led4 = 353, + CustomDeviceChannel2Led5 = 354, + CustomDeviceChannel2Led6 = 355, + CustomDeviceChannel2Led7 = 356, + CustomDeviceChannel2Led8 = 357, + CustomDeviceChannel2Led9 = 358, + CustomDeviceChannel2Led10 = 359, + CustomDeviceChannel2Led11 = 360, + CustomDeviceChannel2Led12 = 361, + CustomDeviceChannel2Led13 = 362, + CustomDeviceChannel2Led14 = 363, + CustomDeviceChannel2Led15 = 364, + CustomDeviceChannel2Led16 = 365, + CustomDeviceChannel2Led17 = 366, + CustomDeviceChannel2Led18 = 367, + CustomDeviceChannel2Led19 = 368, + CustomDeviceChannel2Led20 = 369, + CustomDeviceChannel2Led21 = 370, + CustomDeviceChannel2Led22 = 371, + CustomDeviceChannel2Led23 = 372, + CustomDeviceChannel2Led24 = 373, + CustomDeviceChannel2Led25 = 374, + CustomDeviceChannel2Led26 = 375, + CustomDeviceChannel2Led27 = 376, + CustomDeviceChannel2Led28 = 377, + CustomDeviceChannel2Led29 = 378, + CustomDeviceChannel2Led30 = 379, + CustomDeviceChannel2Led31 = 380, + CustomDeviceChannel2Led32 = 381, + CustomDeviceChannel2Led33 = 382, + CustomDeviceChannel2Led34 = 383, + CustomDeviceChannel2Led35 = 384, + CustomDeviceChannel2Led36 = 385, + CustomDeviceChannel2Led37 = 386, + CustomDeviceChannel2Led38 = 387, + CustomDeviceChannel2Led39 = 388, + CustomDeviceChannel2Led40 = 389, + CustomDeviceChannel2Led41 = 390, + CustomDeviceChannel2Led42 = 391, + CustomDeviceChannel2Led43 = 392, + CustomDeviceChannel2Led44 = 393, + CustomDeviceChannel2Led45 = 394, + CustomDeviceChannel2Led46 = 395, + CustomDeviceChannel2Led47 = 396, + CustomDeviceChannel2Led48 = 397, + CustomDeviceChannel2Led49 = 398, + CustomDeviceChannel2Led50 = 399, + CustomDeviceChannel2Led51 = 400, + CustomDeviceChannel2Led52 = 401, + CustomDeviceChannel2Led53 = 402, + CustomDeviceChannel2Led54 = 403, + CustomDeviceChannel2Led55 = 404, + CustomDeviceChannel2Led56 = 405, + CustomDeviceChannel2Led57 = 406, + CustomDeviceChannel2Led58 = 407, + CustomDeviceChannel2Led59 = 408, + CustomDeviceChannel2Led60 = 409, + CustomDeviceChannel2Led61 = 410, + CustomDeviceChannel2Led62 = 411, + CustomDeviceChannel2Led63 = 412, + CustomDeviceChannel2Led64 = 413, + CustomDeviceChannel2Led65 = 414, + CustomDeviceChannel2Led66 = 415, + CustomDeviceChannel2Led67 = 416, + CustomDeviceChannel2Led68 = 417, + CustomDeviceChannel2Led69 = 418, + CustomDeviceChannel2Led70 = 419, + CustomDeviceChannel2Led71 = 420, + CustomDeviceChannel2Led72 = 421, + CustomDeviceChannel2Led73 = 422, + CustomDeviceChannel2Led74 = 423, + CustomDeviceChannel2Led75 = 424, + CustomDeviceChannel2Led76 = 425, + CustomDeviceChannel2Led77 = 426, + CustomDeviceChannel2Led78 = 427, + CustomDeviceChannel2Led79 = 428, + CustomDeviceChannel2Led80 = 429, + CustomDeviceChannel2Led81 = 430, + CustomDeviceChannel2Led82 = 431, + CustomDeviceChannel2Led83 = 432, + CustomDeviceChannel2Led84 = 433, + CustomDeviceChannel2Led85 = 434, + CustomDeviceChannel2Led86 = 435, + CustomDeviceChannel2Led87 = 436, + CustomDeviceChannel2Led88 = 437, + CustomDeviceChannel2Led89 = 438, + CustomDeviceChannel2Led90 = 439, + CustomDeviceChannel2Led91 = 440, + CustomDeviceChannel2Led92 = 441, + CustomDeviceChannel2Led93 = 442, + CustomDeviceChannel2Led94 = 443, + CustomDeviceChannel2Led95 = 444, + CustomDeviceChannel2Led96 = 445, + CustomDeviceChannel2Led97 = 446, + CustomDeviceChannel2Led98 = 447, + CustomDeviceChannel2Led99 = 448, + CustomDeviceChannel2Led100 = 449, + CustomDeviceChannel2Led101 = 450, + CustomDeviceChannel2Led102 = 451, + CustomDeviceChannel2Led103 = 452, + CustomDeviceChannel2Led104 = 453, + CustomDeviceChannel2Led105 = 454, + CustomDeviceChannel2Led106 = 455, + CustomDeviceChannel2Led107 = 456, + CustomDeviceChannel2Led108 = 457, + CustomDeviceChannel2Led109 = 458, + CustomDeviceChannel2Led110 = 459, + CustomDeviceChannel2Led111 = 460, + CustomDeviceChannel2Led112 = 461, + CustomDeviceChannel2Led113 = 462, + CustomDeviceChannel2Led114 = 463, + CustomDeviceChannel2Led115 = 464, + CustomDeviceChannel2Led116 = 465, + CustomDeviceChannel2Led117 = 466, + CustomDeviceChannel2Led118 = 467, + CustomDeviceChannel2Led119 = 468, + CustomDeviceChannel2Led120 = 469, + CustomDeviceChannel2Led121 = 470, + CustomDeviceChannel2Led122 = 471, + CustomDeviceChannel2Led123 = 472, + CustomDeviceChannel2Led124 = 473, + CustomDeviceChannel2Led125 = 474, + CustomDeviceChannel2Led126 = 475, + CustomDeviceChannel2Led127 = 476, + CustomDeviceChannel2Led128 = 477, + CustomDeviceChannel2Led129 = 478, + CustomDeviceChannel2Led130 = 479, + CustomDeviceChannel2Led131 = 480, + CustomDeviceChannel2Led132 = 481, + CustomDeviceChannel2Led133 = 482, + CustomDeviceChannel2Led134 = 483, + CustomDeviceChannel2Led135 = 484, + CustomDeviceChannel2Led136 = 485, + CustomDeviceChannel2Led137 = 486, + CustomDeviceChannel2Led138 = 487, + CustomDeviceChannel2Led139 = 488, + CustomDeviceChannel2Led140 = 489, + CustomDeviceChannel2Led141 = 490, + CustomDeviceChannel2Led142 = 491, + CustomDeviceChannel2Led143 = 492, + CustomDeviceChannel2Led144 = 493, + CustomDeviceChannel2Led145 = 494, + CustomDeviceChannel2Led146 = 495, + CustomDeviceChannel2Led147 = 496, + CustomDeviceChannel2Led148 = 497, + CustomDeviceChannel2Led149 = 498, + CustomDeviceChannel2Led150 = 499, } } diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairUpdateQueue.cs b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs similarity index 72% rename from RGB.NET.Devices.Corsair/Generic/CorsairUpdateQueue.cs rename to RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs index fbdee50..9540018 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairUpdateQueue.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs @@ -10,17 +10,26 @@ namespace RGB.NET.Devices.Corsair /// /// Represents the update-queue performing updates for corsair devices. /// - public class CorsairUpdateQueue : UpdateQueue + public class CorsairDeviceUpdateQueue : UpdateQueue { + #region Properties & Fields + + private int _deviceIndex; + + #endregion + #region Constructors /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The update trigger used by this queue. - public CorsairUpdateQueue(IDeviceUpdateTrigger updateTrigger) + /// The index used to identify the device. + public CorsairDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceIndex) : base(updateTrigger) - { } + { + this._deviceIndex = deviceIndex; + } #endregion @@ -45,7 +54,9 @@ namespace RGB.NET.Devices.Corsair Marshal.StructureToPtr(color, addPtr, false); addPtr = new IntPtr(addPtr.ToInt64() + structSize); } - _CUESDK.CorsairSetLedsColors(dataSet.Count, ptr); + + _CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Count, ptr); + _CUESDK.CorsairSetLedsColorsFlushBuffer(); Marshal.FreeHGlobal(ptr); } diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs index 22ad483..bb0c479 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs @@ -33,7 +33,7 @@ namespace RGB.NET.Devices.Corsair /// Gets or sets the update queue performing updates for this device. /// // ReSharper disable once MemberCanBePrivate.Global - protected CorsairUpdateQueue UpdateQueue { get; set; } + protected CorsairDeviceUpdateQueue DeviceUpdateQueue { get; set; } #endregion @@ -67,9 +67,9 @@ namespace RGB.NET.Devices.Corsair /// /// Initializes the device. /// - public void Initialize(CorsairUpdateQueue updateQueue) + public void Initialize(CorsairDeviceUpdateQueue deviceUpdateQueue) { - UpdateQueue = updateQueue; + DeviceUpdateQueue = deviceUpdateQueue; InitializeLayout(); @@ -94,7 +94,7 @@ namespace RGB.NET.Devices.Corsair /// protected override void UpdateLeds(IEnumerable ledsToUpdate) - => UpdateQueue.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is CorsairLedId ledId && (ledId != CorsairLedId.Invalid)))); + => DeviceUpdateQueue.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is CorsairLedId ledId && (ledId != CorsairLedId.Invalid)))); /// public override void SyncBack() @@ -108,7 +108,7 @@ namespace RGB.NET.Devices.Corsair Marshal.StructureToPtr(color, addPtr, false); addPtr = new IntPtr(addPtr.ToInt64() + structSize); } - _CUESDK.CorsairGetLedsColors(LedMapping.Count, ptr); + _CUESDK.CorsairGetLedsColorsByDeviceIndex(DeviceInfo.CorsairDeviceIndex, LedMapping.Count, ptr); IntPtr readPtr = ptr; for (int i = 0; i < LedMapping.Count; i++) diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs index 80965e1..012cfb5 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.InteropServices; +using System.Text.RegularExpressions; using RGB.NET.Core; using RGB.NET.Devices.Corsair.Native; @@ -61,7 +62,23 @@ namespace RGB.NET.Devices.Corsair this.CorsairDeviceIndex = deviceIndex; this.DeviceType = deviceType; this.CorsairDeviceType = nativeInfo.type; - this.Model = nativeInfo.model == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeInfo.model); + this.Model = nativeInfo.model == IntPtr.Zero ? null : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase); + this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask; + } + + /// + /// Internal constructor of managed . + /// + /// The index of the . + /// The type of the . + /// The native -struct + /// The name of the device-model (overwrites the one provided with the device info). + internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo, string modelName) + { + this.CorsairDeviceIndex = deviceIndex; + this.DeviceType = deviceType; + this.CorsairDeviceType = nativeInfo.type; + this.Model = modelName; this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask; } diff --git a/RGB.NET.Devices.Corsair/Generic/ICorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/ICorsairRGBDevice.cs index 2ea2334..325c46c 100644 --- a/RGB.NET.Devices.Corsair/Generic/ICorsairRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Generic/ICorsairRGBDevice.cs @@ -7,6 +7,6 @@ namespace RGB.NET.Devices.Corsair /// internal interface ICorsairRGBDevice : IRGBDevice { - void Initialize(CorsairUpdateQueue updateQueue); + void Initialize(CorsairDeviceUpdateQueue deviceUpdateQueue); } } diff --git a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs index bdb8488..ad855cb 100644 --- a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs @@ -49,11 +49,11 @@ namespace RGB.NET.Devices.Corsair Dictionary mapping = HeadsetStandIdMapping.DEFAULT.SwapKeyValue(); foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.LedId)) - InitializeLed(mapping.TryGetValue(ledPosition.LedId, out LedId ledId) ? ledId : LedId.Invalid, new Rectangle(ledPosition.left, ledPosition.top, ledPosition.width, ledPosition.height)); + InitializeLed(mapping.TryGetValue(ledPosition.LedId, out LedId ledId) ? ledId : LedId.Invalid, ledPosition.ToRectangle()); ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\HeadsetStands\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); } - + /// protected override object CreateLedCustomData(LedId ledId) => HeadsetStandIdMapping.DEFAULT.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid; diff --git a/RGB.NET.Devices.Corsair/Helper/NativeExtensions.cs b/RGB.NET.Devices.Corsair/Helper/NativeExtensions.cs new file mode 100644 index 0000000..d823f09 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Helper/NativeExtensions.cs @@ -0,0 +1,19 @@ +using RGB.NET.Core; +using RGB.NET.Devices.Corsair.Native; + +namespace RGB.NET.Devices.Corsair +{ + internal static class NativeExtensions + { + internal static Rectangle ToRectangle(this _CorsairLedPosition position) + { + //HACK DarthAffe 08.07.2018: It seems like corsair introduced a bug here - it's always 0. + double width = position.width < 0.5 ? 10 : position.width; + double height = position.height < 0.5 ? 10 : position.height; + double posX = position.left; + double posY = position.top; + + return new Rectangle(posX, posY, width, height); + } + } +} diff --git a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs index 9ec251e..8752ee5 100644 --- a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs @@ -33,8 +33,7 @@ namespace RGB.NET.Devices.Corsair /// protected override void InitializeLayout() { - _CorsairLedPositions nativeLedPositions = - (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositions(), typeof(_CorsairLedPositions)); + _CorsairLedPositions nativeLedPositions = (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositionsByDeviceIndex(DeviceInfo.CorsairDeviceIndex), typeof(_CorsairLedPositions)); int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); IntPtr ptr = nativeLedPositions.pLedPosition; @@ -43,7 +42,7 @@ namespace RGB.NET.Devices.Corsair for (int i = 0; i < nativeLedPositions.numberOfLed; i++) { _CorsairLedPosition ledPosition = (_CorsairLedPosition)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition)); - InitializeLed(mapping.TryGetValue(ledPosition.LedId, out LedId ledId) ? ledId : LedId.Invalid, new Rectangle(ledPosition.left, ledPosition.top, ledPosition.width, ledPosition.height)); + InitializeLed(mapping.TryGetValue(ledPosition.LedId, out LedId ledId) ? ledId : LedId.Invalid, ledPosition.ToRectangle()); ptr = new IntPtr(ptr.ToInt64() + structSize); } diff --git a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs index 4d828ae..346fc5e 100644 --- a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs @@ -14,7 +14,7 @@ namespace RGB.NET.Devices.Corsair /// /// Gets the physical layout of the mouse. /// - public CorsairPhysicalMouseLayout PhysicalLayout { get; private set; } + public CorsairPhysicalMouseLayout PhysicalLayout { get; } #endregion diff --git a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs index 2b448f8..b83a0ca 100644 --- a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs @@ -49,7 +49,7 @@ namespace RGB.NET.Devices.Corsair Dictionary mapping = MousepadIdMapping.DEFAULT.SwapKeyValue(); foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.LedId)) - InitializeLed(mapping.TryGetValue(ledPosition.LedId, out LedId ledId) ? ledId : LedId.Invalid, new Rectangle(ledPosition.left, ledPosition.top, ledPosition.width, ledPosition.height)); + InitializeLed(mapping.TryGetValue(ledPosition.LedId, out LedId ledId) ? ledId : LedId.Invalid, ledPosition.ToRectangle()); ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\Mousepads\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); } diff --git a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs index 330d33a..0e319ff 100644 --- a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs +++ b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs @@ -42,11 +42,12 @@ namespace RGB.NET.Devices.Corsair.Native _dllHandle = LoadLibrary(dllPath); - _corsairSetLedsColorsPointer = (CorsairSetLedsColorsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairSetLedsColors"), typeof(CorsairSetLedsColorsPointer)); - _corsairGetLedsColorsPointer = (CorsairGetLedsColorsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedsColors"), typeof(CorsairGetLedsColorsPointer)); + _corsairSetLedsColorsBufferByDeviceIndexPointer = (CorsairSetLedsColorsBufferByDeviceIndexPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairSetLedsColorsBufferByDeviceIndex"), typeof(CorsairSetLedsColorsBufferByDeviceIndexPointer)); + _corsairSetLedsColorsFlushBufferPointer = (CorsairSetLedsColorsFlushBufferPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairSetLedsColorsFlushBuffer"), typeof(CorsairSetLedsColorsFlushBufferPointer)); + _corsairGetLedsColorsByDeviceIndexPointer = (CorsairGetLedsColorsByDeviceIndexPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedsColorsByDeviceIndex"), typeof(CorsairGetLedsColorsByDeviceIndexPointer)); + _corsairSetLayerPriorityPointer = (CorsairSetLayerPriorityPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairSetLayerPriority"), typeof(CorsairSetLayerPriorityPointer)); _corsairGetDeviceCountPointer = (CorsairGetDeviceCountPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceCount"), typeof(CorsairGetDeviceCountPointer)); _corsairGetDeviceInfoPointer = (CorsairGetDeviceInfoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceInfo"), typeof(CorsairGetDeviceInfoPointer)); - _corsairGetLedPositionsPointer = (CorsairGetLedPositionsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedPositions"), typeof(CorsairGetLedPositionsPointer)); _corsairGetLedPositionsByDeviceIndexPointer = (CorsairGetLedPositionsByDeviceIndexPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedPositionsByDeviceIndex"), typeof(CorsairGetLedPositionsByDeviceIndexPointer)); _corsairGetLedIdForKeyNamePointer = (CorsairGetLedIdForKeyNamePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedIdForKeyName"), typeof(CorsairGetLedIdForKeyNamePointer)); _corsairRequestControlPointer = (CorsairRequestControlPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairRequestControl"), typeof(CorsairRequestControlPointer)); @@ -79,11 +80,12 @@ namespace RGB.NET.Devices.Corsair.Native #region Pointers - private static CorsairSetLedsColorsPointer _corsairSetLedsColorsPointer; - private static CorsairGetLedsColorsPointer _corsairGetLedsColorsPointer; + private static CorsairSetLedsColorsBufferByDeviceIndexPointer _corsairSetLedsColorsBufferByDeviceIndexPointer; + private static CorsairSetLedsColorsFlushBufferPointer _corsairSetLedsColorsFlushBufferPointer; + private static CorsairGetLedsColorsByDeviceIndexPointer _corsairGetLedsColorsByDeviceIndexPointer; + private static CorsairSetLayerPriorityPointer _corsairSetLayerPriorityPointer; private static CorsairGetDeviceCountPointer _corsairGetDeviceCountPointer; private static CorsairGetDeviceInfoPointer _corsairGetDeviceInfoPointer; - private static CorsairGetLedPositionsPointer _corsairGetLedPositionsPointer; private static CorsairGetLedIdForKeyNamePointer _corsairGetLedIdForKeyNamePointer; private static CorsairGetLedPositionsByDeviceIndexPointer _corsairGetLedPositionsByDeviceIndexPointer; private static CorsairRequestControlPointer _corsairRequestControlPointer; @@ -96,10 +98,16 @@ namespace RGB.NET.Devices.Corsair.Native #region Delegates [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate bool CorsairSetLedsColorsPointer(int size, IntPtr ledsColors); + private delegate bool CorsairSetLedsColorsBufferByDeviceIndexPointer(int deviceIndex, int size, IntPtr ledsColors); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate bool CorsairGetLedsColorsPointer(int size, IntPtr ledsColors); + private delegate bool CorsairSetLedsColorsFlushBufferPointer(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate bool CorsairGetLedsColorsByDeviceIndexPointer(int deviceIndex, int size, IntPtr ledsColors); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate bool CorsairSetLayerPriorityPointer(int priority); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate int CorsairGetDeviceCountPointer(); @@ -107,9 +115,6 @@ namespace RGB.NET.Devices.Corsair.Native [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate IntPtr CorsairGetDeviceInfoPointer(int deviceIndex); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate IntPtr CorsairGetLedPositionsPointer(); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate IntPtr CorsairGetLedPositionsByDeviceIndexPointer(int deviceIndex); @@ -131,16 +136,35 @@ namespace RGB.NET.Devices.Corsair.Native #endregion // ReSharper disable EventExceptionNotDocumented + + /// + /// CUE-SDK: set specified LEDs to some colors. + /// This function set LEDs colors in the buffer which is written to the devices via CorsairSetLedsColorsFlushBuffer or CorsairSetLedsColorsFlushBufferAsync. + /// Typical usecase is next: CorsairSetLedsColorsFlushBuffer or CorsairSetLedsColorsFlushBufferAsync is called to write LEDs colors to the device + /// and follows after one or more calls of CorsairSetLedsColorsBufferByDeviceIndex to set the LEDs buffer. + /// This function does not take logical layout into account. + /// + internal static bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) => _corsairSetLedsColorsBufferByDeviceIndexPointer(deviceIndex, size, ledsColors); /// - /// CUE-SDK: set specified leds to some colors. The color is retained until changed by successive calls. This function does not take logical layout into account. + /// CUE-SDK: writes to the devices LEDs colors buffer which is previously filled by the CorsairSetLedsColorsBufferByDeviceIndex function. + /// This function executes synchronously, if you are concerned about delays consider using CorsairSetLedsColorsFlushBufferAsync /// - internal static bool CorsairSetLedsColors(int size, IntPtr ledsColors) => _corsairSetLedsColorsPointer(size, ledsColors); - + internal static bool CorsairSetLedsColorsFlushBuffer() => _corsairSetLedsColorsFlushBufferPointer(); + /// /// CUE-SDK: get current color for the list of requested LEDs. + /// The color should represent the actual state of the hardware LED, which could be a combination of SDK and/or CUE input. + /// This function works for keyboard, mouse, mousemat, headset, headset stand and DIY-devices. /// - internal static bool CorsairGetLedsColors(int size, IntPtr ledsColors) => _corsairGetLedsColorsPointer(size, ledsColors); + internal static bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) => _corsairGetLedsColorsByDeviceIndexPointer(deviceIndex, size, ledsColors); + + /// + /// CUE-SDK: set layer priority for this shared client. + /// By default CUE has priority of 127 and all shared clients have priority of 128 if they don’t call this function. + /// Layers with higher priority value are shown on top of layers with lower priority. + /// + internal static bool CorsairSetLayerPriority(int priority) => _corsairSetLayerPriorityPointer(priority); /// /// CUE-SDK: returns number of connected Corsair devices that support lighting control. @@ -151,12 +175,7 @@ namespace RGB.NET.Devices.Corsair.Native /// CUE-SDK: returns information about device at provided index. /// internal static IntPtr CorsairGetDeviceInfo(int deviceIndex) => _corsairGetDeviceInfoPointer(deviceIndex); - - /// - /// CUE-SDK: provides list of keyboard LEDs with their physical positions. - /// - internal static IntPtr CorsairGetLedPositions() => _corsairGetLedPositionsPointer(); - + /// /// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions. /// diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairChannelDeviceInfo.cs b/RGB.NET.Devices.Corsair/Native/_CorsairChannelDeviceInfo.cs new file mode 100644 index 0000000..d3ce82f --- /dev/null +++ b/RGB.NET.Devices.Corsair/Native/_CorsairChannelDeviceInfo.cs @@ -0,0 +1,26 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned + +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.Corsair.Native +{ + // ReSharper disable once InconsistentNaming + /// + /// CUE-SDK: contains information about separate LED-device connected to the channel controlled by the DIY-device. + /// + [StructLayout(LayoutKind.Sequential)] + internal class _CorsairChannelDeviceInfo + { + /// + /// CUE-SDK: type of the LED-device + /// + internal CorsairChannelDeviceType type; + + /// + /// CUE-SDK: number of LEDs controlled by LED-device. + /// + internal int deviceLedCount; + } +} diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairChannelInfo.cs b/RGB.NET.Devices.Corsair/Native/_CorsairChannelInfo.cs new file mode 100644 index 0000000..5933b4e --- /dev/null +++ b/RGB.NET.Devices.Corsair/Native/_CorsairChannelInfo.cs @@ -0,0 +1,33 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned + +using System; +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.Corsair.Native +{ + // ReSharper disable once InconsistentNaming + /// + /// CUE-SDK: contains information about separate channel of the DIY-device. + /// + [StructLayout(LayoutKind.Sequential)] + internal class _CorsairChannelInfo + { + /// + /// CUE-SDK: total number of LEDs connected to the channel; + /// + internal int totalLedsCount; + + /// + /// CUE-SDK: number of LED-devices (fans, strips, etc.) connected to the channel which is controlled by the DIY device + /// + internal int devicesCount; + + /// + /// CUE-SDK: array containing information about each separate LED-device connected to the channel controlled by the DIY device. + /// Index of the LED-device in array is same as the index of the LED-device connected to the DIY-device. + /// + internal IntPtr devices; + } +} diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairChannelsInfo.cs b/RGB.NET.Devices.Corsair/Native/_CorsairChannelsInfo.cs new file mode 100644 index 0000000..8dacba2 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Native/_CorsairChannelsInfo.cs @@ -0,0 +1,28 @@ +#pragma warning disable 169 // Field 'x' is never used +#pragma warning disable 414 // Field 'x' is assigned but its value never used +#pragma warning disable 649 // Field 'x' is never assigned + +using System; +using System.Runtime.InteropServices; + +namespace RGB.NET.Devices.Corsair.Native +{ + // ReSharper disable once InconsistentNaming + /// + /// CUE-SDK: contains information about channels of the DIY-devices. + /// + [StructLayout(LayoutKind.Sequential)] + internal class _CorsairChannelsInfo + { + /// + /// CUE-SDK: number of channels controlled by the device + /// + internal int channelsCount; + + /// + /// CUE-SDK: array containing information about each separate channel of the DIY-device. + /// Index of the channel in the array is same as index of the channel on the DIY-device. + /// + internal IntPtr channels; + } +} diff --git a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs index 4f52e88..d584d73 100644 --- a/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs @@ -43,5 +43,10 @@ namespace RGB.NET.Devices.Corsair.Native /// CUE-SDK: number of controllable LEDs on the device /// internal int ledsCount; + + /// + /// CUE-SDK: structure that describes channels of the DIY-devices + /// + internal _CorsairChannelsInfo channels; } } diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings index 355ebb9..f85c0ca 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj.DotSettings @@ -9,6 +9,7 @@ True True True + True True True True