From 1fbe7017c176cc0547e235bf05f8e1781bcac426 Mon Sep 17 00:00:00 2001 From: deckertron9000 <10391684+deckertron9000@users.noreply.github.com> Date: Sun, 31 Mar 2019 15:16:30 -0500 Subject: [PATCH 1/6] Adding marshaling information for sdk calls. --- RGB.NET.Devices.Msi/Native/_MsiSDK.cs | 83 ++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 15 deletions(-) diff --git a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs index 031918d..a67aa94 100644 --- a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs +++ b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs @@ -110,51 +110,104 @@ namespace RGB.NET.Devices.Msi.Native private delegate int InitializePointer(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int GetDeviceInfoPointer(out string[] pDevType, out int[] pLedCount); + private delegate int GetDeviceInfoPointer( + [Out, MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)] out string[] pDevType, + [Out, MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)] out string[] pLedCount); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int GetLedInfoPointer(string type, int index, out string pName, out string[] pLedStyles); + private delegate int GetLedInfoPointer( + [In, MarshalAs(UnmanagedType.BStr)] string type, + [In, MarshalAs(UnmanagedType.I4)] int index, + [Out, MarshalAs(UnmanagedType.BStr)] out string pName, + [Out, MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_BSTR)] out string[] pLedStyles); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int GetLedColorPointer(string type, int index, out int r, out int g, out int b); + private delegate int GetLedColorPointer( + [In, MarshalAs(UnmanagedType.BStr)] string type, + [In, MarshalAs(UnmanagedType.I4)] int index, + [Out, MarshalAs(UnmanagedType.I4)] out int r, + [Out, MarshalAs(UnmanagedType.I4)] out int g, + [Out, MarshalAs(UnmanagedType.I4)] out int b); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int GetLedStylePointer(string type, int index, out int style); + private delegate int GetLedStylePointer( + [In, MarshalAs(UnmanagedType.BStr)] string type, + [In, MarshalAs(UnmanagedType.I4)] int index, + [Out, MarshalAs(UnmanagedType.BStr)] out string style); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int GetLedMaxBrightPointer(string type, int index, out int maxLevel); + private delegate int GetLedMaxBrightPointer( + [In, MarshalAs(UnmanagedType.BStr)] string type, + [In, MarshalAs(UnmanagedType.I4)] int index, + [Out, MarshalAs(UnmanagedType.I4)] out int maxLevel); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int GetLedBrightPointer(string type, int index, out int currentLevel); + private delegate int GetLedBrightPointer( + [In, MarshalAs(UnmanagedType.BStr)] string type, + [In, MarshalAs(UnmanagedType.I4)] int index, + [Out, MarshalAs(UnmanagedType.I4)] out int currentLevel); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int GetLedMaxSpeedPointer(string type, int index, out int maxSpeed); + private delegate int GetLedMaxSpeedPointer( + [In, MarshalAs(UnmanagedType.BStr)] string type, + [In, MarshalAs(UnmanagedType.I4)] int index, + [Out, MarshalAs(UnmanagedType.I4)] out int maxSpeed); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int GetLedSpeedPointer(string type, int index, out int currentSpeed); + private delegate int GetLedSpeedPointer( + [In, MarshalAs(UnmanagedType.BStr)] string type, + [In, MarshalAs(UnmanagedType.I4)] int index, + [Out, MarshalAs(UnmanagedType.I4)] out int currentSpeed); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int SetLedColorPointer(string type, int index, int r, int g, int b); + private delegate int SetLedColorPointer( + [In, MarshalAs(UnmanagedType.BStr)] string type, + [In, MarshalAs(UnmanagedType.I4)] int index, + [In, MarshalAs(UnmanagedType.I4)] int r, + [In, MarshalAs(UnmanagedType.I4)] int g, + [In, MarshalAs(UnmanagedType.I4)] int b); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int SetLedStylePointer(string type, int index, string style); + private delegate int SetLedStylePointer( + [In, MarshalAs(UnmanagedType.BStr)] string type, + [In, MarshalAs(UnmanagedType.I4)] int index, + [In, MarshalAs(UnmanagedType.BStr)] string style); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int SetLedBrightPointer(string type, int index, int level); + private delegate int SetLedBrightPointer( + [In, MarshalAs(UnmanagedType.BStr)] string type, + [In, MarshalAs(UnmanagedType.I4)] int index, + [In, MarshalAs(UnmanagedType.I4)] int level); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int SetLedSpeedPointer(string type, int index, int speed); + private delegate int SetLedSpeedPointer( + [In, MarshalAs(UnmanagedType.BStr)] string type, + [In, MarshalAs(UnmanagedType.I4)] int index, + [In, MarshalAs(UnmanagedType.I4)] int speed); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate int GetErrorMessagePointer(int errorCode, out string pDesc); + private delegate int GetErrorMessagePointer( + [In, MarshalAs(UnmanagedType.I4)] int errorCode, + [Out, MarshalAs(UnmanagedType.BStr)] out string pDesc); #endregion internal static int Initialize() => _initializePointer(); - internal static int GetDeviceInfo(out string[] pDevType, out int[] pLedCount) => _getDeviceInfoPointer(out pDevType, out pLedCount); + internal static int GetDeviceInfo(out string[] pDevType, out int[] pLedCount) + { + // HACK - SDK GetDeviceInfo returns a string[] for ledCount, so we'll parse that to int. + int result = _getDeviceInfoPointer(out pDevType, out string[] ledCount); + pLedCount = new int[ledCount.Length]; + + for (int i = 0; i < ledCount.Length; i++) + pLedCount[i] = int.Parse(ledCount[i]); + + return result; + } + internal static int GetLedInfo(string type, int index, out string pName, out string[] pLedStyles) => _getLedInfoPointer(type, index, out pName, out pLedStyles); internal static int GetLedColor(string type, int index, out int r, out int g, out int b) => _getLedColorPointer(type, index, out r, out g, out b); - internal static int GetLedStyle(string type, int index, out int style) => _getLedStylePointer(type, index, out style); + internal static int GetLedStyle(string type, int index, out string style) => _getLedStylePointer(type, index, out style); internal static int GetLedMaxBright(string type, int index, out int maxLevel) => _getLedMaxBrightPointer(type, index, out maxLevel); internal static int GetLedBright(string type, int index, out int currentLevel) => _getLedBrightPointer(type, index, out currentLevel); internal static int GetLedMaxSpeed(string type, int index, out int maxSpeed) => _getLedMaxSpeedPointer(type, index, out maxSpeed); From b92f121379bee5b51ecdf56bf1cc38c4f7a22d89 Mon Sep 17 00:00:00 2001 From: Hex3l Date: Sat, 15 Feb 2020 17:28:08 +0100 Subject: [PATCH 2/6] Adds support to MSI_MB device (motherboard) --- .../Mainboard/MsiMainboardRGBDevice.cs | 68 +++++++++++++++++++ RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 10 +++ 2 files changed, 78 insertions(+) create mode 100644 RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs diff --git a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs new file mode 100644 index 0000000..7901ffb --- /dev/null +++ b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs @@ -0,0 +1,68 @@ +using System; +using RGB.NET.Core; +using RGB.NET.Devices.Msi.Native; +using RGB.NET.Devices.Msi.Exceptions; + +namespace RGB.NET.Devices.Msi +{ + /// + /// + /// Represents a Msi mainboard. + /// + public class MsiMainboardRGBDevice : MsiRGBDevice + { + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by Asus for the mainboard. + internal MsiMainboardRGBDevice(MsiRGBDeviceInfo info) + : base(info) + { } + + #endregion + + #region Methods + + /// + protected override void InitializeLayout() + { + // Should errors be handled? + _MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts); + + for (int i = 0; i < deviceTypes.Length; i++) + { + // DeviceInfo.MsiDeviceType = "MSI_MB" + if (deviceTypes[i].Equals(DeviceInfo.MsiDeviceType)) + { + for (int j = 0; j < ledCounts[i]; j++) + { + // Should it be configurable in order to provide style access? + // Sets led style to "Steady" in order to have a solid color output therefore a controllable led color + // This is a string defined by the output of _MsiSDK.GetLedStyle, "Steady" should be always present + string style = "Steady"; + + _MsiSDK.SetLedStyle(DeviceInfo.MsiDeviceType, j, style); + InitializeLed(LedId.Mainboard1 + j, new Rectangle(j * 40, 0, 40, 8)); + } + } + } + + //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? + ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Mainboards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); + } + + /// + protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Mainboard1; + + /// + public override void SyncBack() + { } + + /// + + #endregion + } +} diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index 2eba9a0..2d1e377 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -103,6 +103,16 @@ namespace RGB.NET.Devices.Msi try { //TODO DarthAffe 11.11.2017: What is this deviceType? Find someone to try that out + + // MSI_MB provide access to the motherboard "leds" where a led must be intended as a led header (JRGB, JRAINBOW etc..) (Tested on MSI X570 Unify) + if (deviceTypes[i].Equals("MSI_MB")) + { + IMsiRGBDevice motherboard = new MsiMainboardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mainboard, deviceTypes[i], "Msi", "Motherboard")); + motherboard.Initialize(); + devices.Add(motherboard); + } + + // Other devices? } catch { if (throwExceptions) throw; } } From 18887a048efa90f4c77f225e025b64e2174e9128 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 22 Feb 2020 15:59:22 +0100 Subject: [PATCH 3/6] Refactored MSI --- RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs | 4 +- .../Generic/MsiDeviceUpdateQueue.cs | 45 +++++++++++++++++++ RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs | 26 +++++------ .../Generic/MsiRGBDeviceInfo.cs | 2 +- .../Mainboard/MsiMainboardRGBDevice.cs | 24 +++++----- RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 30 ++++++++----- .../MsiDeviceProviderLoader.cs | 2 +- .../RGB.NET.Devices.Msi.csproj.DotSettings | 3 +- 8 files changed, 93 insertions(+), 43 deletions(-) create mode 100644 RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs diff --git a/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs b/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs index f8b35a8..13caa17 100644 --- a/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs @@ -3,10 +3,10 @@ namespace RGB.NET.Devices.Msi { /// - /// Represents a msi RGB-device. + /// Represents a MSI RGB-device. /// internal interface IMsiRGBDevice : IRGBDevice { - void Initialize(); + void Initialize(MsiDeviceUpdateQueue updateQueue); } } diff --git a/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs b/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs new file mode 100644 index 0000000..b2dffc0 --- /dev/null +++ b/RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using RGB.NET.Core; +using RGB.NET.Devices.Msi.Native; + +namespace RGB.NET.Devices.Msi +{ + /// + /// + /// Represents the update-queue performing updates for MSI devices. + /// + public class MsiDeviceUpdateQueue : UpdateQueue + { + #region Properties & Fields + + private string _deviceType; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The update trigger used by this queue. + /// The device-type used to identify the device. + public MsiDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, string deviceType) + : base(updateTrigger) + { + this._deviceType = deviceType; + } + + #endregion + + #region Methods + + /// + protected override void Update(Dictionary dataSet) + { + foreach (KeyValuePair data in dataSet) + _MsiSDK.SetLedColor(_deviceType, (int)data.Key, data.Value.GetR(), data.Value.GetG(), data.Value.GetB()); + } + + #endregion + } +} diff --git a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs index 5fe18ab..6c83ad0 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs @@ -1,14 +1,13 @@ using System.Collections.Generic; using System.Linq; using RGB.NET.Core; -using RGB.NET.Devices.Msi.Native; namespace RGB.NET.Devices.Msi { /// /// /// - /// Represents a generic Msi-device. (keyboard, mouse, headset, mousepad). + /// Represents a generic MSI-device. (keyboard, mouse, headset, mousepad). /// public abstract class MsiRGBDevice : AbstractRGBDevice, IMsiRGBDevice where TDeviceInfo : MsiRGBDeviceInfo @@ -21,6 +20,12 @@ namespace RGB.NET.Devices.Msi /// public override TDeviceInfo DeviceInfo { get; } + /// + /// Gets or sets the update queue performing updates for this device. + /// + // ReSharper disable once MemberCanBePrivate.Global + protected MsiDeviceUpdateQueue DeviceUpdateQueue { get; set; } + #endregion #region Constructors @@ -28,7 +33,7 @@ namespace RGB.NET.Devices.Msi /// /// Initializes a new instance of the class. /// - /// The generic information provided by Msi for the device. + /// The generic information provided by MSI for the device. protected MsiRGBDevice(TDeviceInfo info) { this.DeviceInfo = info; @@ -41,8 +46,10 @@ namespace RGB.NET.Devices.Msi /// /// Initializes the device. /// - public void Initialize() + public void Initialize(MsiDeviceUpdateQueue updateQueue) { + DeviceUpdateQueue = updateQueue; + InitializeLayout(); if (Size == Size.Invalid) @@ -59,16 +66,7 @@ namespace RGB.NET.Devices.Msi /// protected override void UpdateLeds(IEnumerable ledsToUpdate) - { - List leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList(); - - if (leds.Count > 0) - { - string deviceType = DeviceInfo.MsiDeviceType; - foreach (Led led in leds) - _MsiSDK.SetLedColor(deviceType, (int)led.CustomData, led.Color.GetR(), led.Color.GetG(), led.Color.GetB()); - } - } + => DeviceUpdateQueue.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is int))); #endregion } diff --git a/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs b/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs index 1d8e942..d846266 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs @@ -5,7 +5,7 @@ namespace RGB.NET.Devices.Msi { /// /// - /// Represents a generic information for a Corsair-. + /// Represents a generic information for a MSI-. /// public class MsiRGBDeviceInfo : IRGBDeviceInfo { diff --git a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs index 7901ffb..afb4f98 100644 --- a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs @@ -1,13 +1,11 @@ -using System; using RGB.NET.Core; using RGB.NET.Devices.Msi.Native; -using RGB.NET.Devices.Msi.Exceptions; namespace RGB.NET.Devices.Msi { /// /// - /// Represents a Msi mainboard. + /// Represents a MSI mainboard. /// public class MsiMainboardRGBDevice : MsiRGBDevice { @@ -17,7 +15,7 @@ namespace RGB.NET.Devices.Msi /// /// Initializes a new instance of the class. /// - /// The specific information provided by Asus for the mainboard. + /// The specific information provided by MSI for the mainboard. internal MsiMainboardRGBDevice(MsiRGBDeviceInfo info) : base(info) { } @@ -29,7 +27,7 @@ namespace RGB.NET.Devices.Msi /// protected override void InitializeLayout() { - // Should errors be handled? + // Should errors be handled? _MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts); for (int i = 0; i < deviceTypes.Length; i++) @@ -39,30 +37,28 @@ namespace RGB.NET.Devices.Msi { for (int j = 0; j < ledCounts[i]; j++) { - // Should it be configurable in order to provide style access? - // Sets led style to "Steady" in order to have a solid color output therefore a controllable led color - // This is a string defined by the output of _MsiSDK.GetLedStyle, "Steady" should be always present - string style = "Steady"; + //Hex3l: Should it be configurable in order to provide style access? + //Hex3l: Sets led style to "Steady" in order to have a solid color output therefore a controllable led color + //Hex3l: This is a string defined by the output of _MsiSDK.GetLedStyle, "Steady" should be always present + const string LED_STYLE = "Steady"; - _MsiSDK.SetLedStyle(DeviceInfo.MsiDeviceType, j, style); + _MsiSDK.SetLedStyle(DeviceInfo.MsiDeviceType, j, LED_STYLE); InitializeLed(LedId.Mainboard1 + j, new Rectangle(j * 40, 0, 40, 8)); } } } //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? - ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Mainboards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\MSI\Mainboards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); } /// protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Mainboard1; /// - public override void SyncBack() + public override void SyncBack() { } - /// - #endregion } } diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index 2d1e377..f233857 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Devices.Msi { /// /// - /// Represents a device provider responsible for Cooler Master devices. + /// Represents a device provider responsible for MSI devices. /// public class MsiDeviceProvider : IRGBDeviceProvider { @@ -62,6 +62,11 @@ namespace RGB.NET.Devices.Msi /// public Func GetCulture { get; set; } = CultureHelper.GetCurrentCulture; + /// + /// The used to trigger the updates for corsair devices. + /// + public DeviceUpdateTrigger UpdateTrigger { get; } + #endregion #region Constructors @@ -74,6 +79,8 @@ namespace RGB.NET.Devices.Msi { if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(MsiDeviceProvider)}"); _instance = this; + + UpdateTrigger = new DeviceUpdateTrigger(); } #endregion @@ -87,6 +94,8 @@ namespace RGB.NET.Devices.Msi try { + UpdateTrigger?.Stop(); + _MsiSDK.Reload(); IList devices = new List(); @@ -95,28 +104,29 @@ namespace RGB.NET.Devices.Msi if ((errorCode = _MsiSDK.Initialize()) != 0) ThrowMsiError(errorCode); - if ((errorCode = _MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts)) != 0) + if ((errorCode = _MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] _)) != 0) ThrowMsiError(errorCode); - for (int i = 0; i < deviceTypes.Length; i++) + foreach (string deviceType in deviceTypes) { try { - //TODO DarthAffe 11.11.2017: What is this deviceType? Find someone to try that out - - // MSI_MB provide access to the motherboard "leds" where a led must be intended as a led header (JRGB, JRAINBOW etc..) (Tested on MSI X570 Unify) - if (deviceTypes[i].Equals("MSI_MB")) + //Hex3l: MSI_MB provide access to the motherboard "leds" where a led must be intended as a led header (JRGB, JRAINBOW etc..) (Tested on MSI X570 Unify) + if (deviceType.Equals("MSI_MB")) { - IMsiRGBDevice motherboard = new MsiMainboardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mainboard, deviceTypes[i], "Msi", "Motherboard")); - motherboard.Initialize(); + MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType); + IMsiRGBDevice motherboard = new MsiMainboardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mainboard, deviceType, "Msi", "Motherboard")); + motherboard.Initialize(updateQueue); devices.Add(motherboard); } - // Other devices? + //TODO DarthAffe 22.02.2020: Add other devices } catch { if (throwExceptions) throw; } } + UpdateTrigger?.Start(); + Devices = new ReadOnlyCollection(devices); IsInitialized = true; } diff --git a/RGB.NET.Devices.Msi/MsiDeviceProviderLoader.cs b/RGB.NET.Devices.Msi/MsiDeviceProviderLoader.cs index 0aef5c4..b059f85 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProviderLoader.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProviderLoader.cs @@ -3,7 +3,7 @@ namespace RGB.NET.Devices.Msi { /// - /// Represents a device provider loaded used to dynamically load msi devices into an application. + /// Represents a device provider loaded used to dynamically load MSI devices into an application. /// public class MsiDeviceProviderLoader : IRGBDeviceProviderLoader { diff --git a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj.DotSettings b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj.DotSettings index bcc9d7d..1071e1b 100644 --- a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj.DotSettings +++ b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj.DotSettings @@ -1,3 +1,4 @@  True - True \ No newline at end of file + True + True \ No newline at end of file From 7fea5fbde599a333d64589988f1f63aafcfa3d15 Mon Sep 17 00:00:00 2001 From: Hex3l Date: Sat, 22 Feb 2020 20:13:41 +0100 Subject: [PATCH 4/6] Adds MSI VGA support --- .../GraphicsCard/MsiGraphicsCardRGBDevice.cs | 66 +++++++++++++++++++ RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 12 ++++ 2 files changed, 78 insertions(+) create mode 100644 RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs diff --git a/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs new file mode 100644 index 0000000..54ab51b --- /dev/null +++ b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs @@ -0,0 +1,66 @@ +using RGB.NET.Core; +using RGB.NET.Devices.Msi.Native; + +namespace RGB.NET.Devices.Msi +{ + /// + /// + /// Represents MSI VGA adapters. + /// + public class MsiGraphicsCardRGBDevice : MsiRGBDevice + { + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by MSI for graphics cards. + internal MsiGraphicsCardRGBDevice(MsiRGBDeviceInfo info) + : base(info) + { } + + #endregion + + #region Methods + + /// + protected override void InitializeLayout() + { + // Should errors be handled? + _MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts); + + for (int i = 0; i < deviceTypes.Length; i++) + { + // DeviceInfo.MsiDeviceType = "MSI_VGA" + if (deviceTypes[i].Equals(DeviceInfo.MsiDeviceType)) + { + for (int j = 0; j < ledCounts[i]; j++) + { + //Hex3l: Should it be configurable in order to provide style access? + //Hex3l: Sets led style to "Steady" in order to have a solid color output therefore a controllable led color + //Hex3l: This is a string defined by the output of _MsiSDK.GetLedStyle, "Steady" should be always present + const string LED_STYLE = "Steady"; + + //Hex3l: Every led is a video card adapter. + + _MsiSDK.SetLedStyle(DeviceInfo.MsiDeviceType, j, LED_STYLE); + InitializeLed(LedId.GraphicsCard1 + j, new Rectangle(j * 10, 0, 10, 10)); + } + } + } + + //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? + ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\MSI\GraphicsCard\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); + } + + /// + protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.GraphicsCard1; + + /// + public override void SyncBack() + { } + + #endregion + } +} diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index f233857..591050a 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -120,6 +120,18 @@ namespace RGB.NET.Devices.Msi devices.Add(motherboard); } + + if (deviceTypes.Equals("MSI_VGA")) + { + //Hex3l: Every led under MSI_VGA should be a different graphics card. Handling all the cards together seems a good way to avoid overlapping of leds + //Hex3l: The led name is the name of the card (e.g. NVIDIA GeForce RTX 2080 Ti) we could provide it in device info. + + MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType); + IMsiRGBDevice graphicscard = new MsiGraphicsCardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.GraphicsCard, deviceType, "Msi", "GraphicsCard")); + graphicscard.Initialize(updateQueue); + devices.Add(graphicscard); + } + //TODO DarthAffe 22.02.2020: Add other devices } catch { if (throwExceptions) throw; } From 711f8621f2e45f5ebff4cadda3d77743225781d6 Mon Sep 17 00:00:00 2001 From: Hex3l Date: Sat, 22 Feb 2020 20:19:02 +0100 Subject: [PATCH 5/6] fixes typo --- RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index 591050a..703aaea 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -121,7 +121,7 @@ namespace RGB.NET.Devices.Msi } - if (deviceTypes.Equals("MSI_VGA")) + if (deviceType.Equals("MSI_VGA")) { //Hex3l: Every led under MSI_VGA should be a different graphics card. Handling all the cards together seems a good way to avoid overlapping of leds //Hex3l: The led name is the name of the card (e.g. NVIDIA GeForce RTX 2080 Ti) we could provide it in device info. From 93e7e7d0042d91c6deff3c534a676c1327673cb2 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 23 Feb 2020 01:08:47 +0100 Subject: [PATCH 6/6] Small refactorings --- .../Exceptions/MysticLightException.cs | 1 + RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs | 2 +- RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs | 6 ++-- .../GraphicsCard/MsiGraphicsCardRGBDevice.cs | 30 +++++++------------ .../Mainboard/MsiMainboardRGBDevice.cs | 26 +++++----------- RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 15 +++++----- .../RGB.NET.Devices.Msi.csproj.DotSettings | 1 + 7 files changed, 32 insertions(+), 49 deletions(-) diff --git a/RGB.NET.Devices.Msi/Exceptions/MysticLightException.cs b/RGB.NET.Devices.Msi/Exceptions/MysticLightException.cs index d36665b..0b12582 100644 --- a/RGB.NET.Devices.Msi/Exceptions/MysticLightException.cs +++ b/RGB.NET.Devices.Msi/Exceptions/MysticLightException.cs @@ -34,6 +34,7 @@ namespace RGB.NET.Devices.Msi.Exceptions /// The raw error code provided by the SDK. /// The text-description of the error. public MysticLightException(int errorCode, string description) + : base($"MSI error code {errorCode} ({description})") { this.ErrorCode = errorCode; this.Description = description; diff --git a/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs b/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs index 13caa17..cd09af0 100644 --- a/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Generic/IMsiRGBDevice.cs @@ -7,6 +7,6 @@ namespace RGB.NET.Devices.Msi /// internal interface IMsiRGBDevice : IRGBDevice { - void Initialize(MsiDeviceUpdateQueue updateQueue); + void Initialize(MsiDeviceUpdateQueue updateQueue, int ledCount); } } diff --git a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs index 6c83ad0..e6a5210 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs @@ -46,11 +46,11 @@ namespace RGB.NET.Devices.Msi /// /// Initializes the device. /// - public void Initialize(MsiDeviceUpdateQueue updateQueue) + public void Initialize(MsiDeviceUpdateQueue updateQueue, int ledCount) { DeviceUpdateQueue = updateQueue; - InitializeLayout(); + InitializeLayout(ledCount); if (Size == Size.Invalid) { @@ -62,7 +62,7 @@ namespace RGB.NET.Devices.Msi /// /// Initializes the and of the device. /// - protected abstract void InitializeLayout(); + protected abstract void InitializeLayout(int ledCount); /// protected override void UpdateLeds(IEnumerable ledsToUpdate) diff --git a/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs index 54ab51b..ee0800a 100644 --- a/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs +++ b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs @@ -25,29 +25,19 @@ namespace RGB.NET.Devices.Msi #region Methods /// - protected override void InitializeLayout() + protected override void InitializeLayout(int ledCount) { - // Should errors be handled? - _MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts); - - for (int i = 0; i < deviceTypes.Length; i++) + for (int i = 0; i < ledCount; i++) { - // DeviceInfo.MsiDeviceType = "MSI_VGA" - if (deviceTypes[i].Equals(DeviceInfo.MsiDeviceType)) - { - for (int j = 0; j < ledCounts[i]; j++) - { - //Hex3l: Should it be configurable in order to provide style access? - //Hex3l: Sets led style to "Steady" in order to have a solid color output therefore a controllable led color - //Hex3l: This is a string defined by the output of _MsiSDK.GetLedStyle, "Steady" should be always present - const string LED_STYLE = "Steady"; + //Hex3l: Should it be configurable in order to provide style access? + //Hex3l: Sets led style to "Steady" in order to have a solid color output therefore a controllable led color + //Hex3l: This is a string defined by the output of _MsiSDK.GetLedStyle, "Steady" should be always present + const string LED_STYLE = "Steady"; - //Hex3l: Every led is a video card adapter. + //Hex3l: Every led is a video card adapter. - _MsiSDK.SetLedStyle(DeviceInfo.MsiDeviceType, j, LED_STYLE); - InitializeLed(LedId.GraphicsCard1 + j, new Rectangle(j * 10, 0, 10, 10)); - } - } + _MsiSDK.SetLedStyle(DeviceInfo.MsiDeviceType, i, LED_STYLE); + InitializeLed(LedId.GraphicsCard1 + i, new Rectangle(i * 10, 0, 10, 10)); } //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? @@ -58,7 +48,7 @@ namespace RGB.NET.Devices.Msi protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.GraphicsCard1; /// - public override void SyncBack() + public override void SyncBack() { } #endregion diff --git a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs index afb4f98..f80dab0 100644 --- a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs @@ -25,27 +25,17 @@ namespace RGB.NET.Devices.Msi #region Methods /// - protected override void InitializeLayout() + protected override void InitializeLayout(int ledCount) { - // Should errors be handled? - _MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts); - - for (int i = 0; i < deviceTypes.Length; i++) + for (int i = 0; i < ledCount; i++) { - // DeviceInfo.MsiDeviceType = "MSI_MB" - if (deviceTypes[i].Equals(DeviceInfo.MsiDeviceType)) - { - for (int j = 0; j < ledCounts[i]; j++) - { - //Hex3l: Should it be configurable in order to provide style access? - //Hex3l: Sets led style to "Steady" in order to have a solid color output therefore a controllable led color - //Hex3l: This is a string defined by the output of _MsiSDK.GetLedStyle, "Steady" should be always present - const string LED_STYLE = "Steady"; + //Hex3l: Should it be configurable in order to provide style access? + //Hex3l: Sets led style to "Steady" in order to have a solid color output therefore a controllable led color + //Hex3l: This is a string defined by the output of _MsiSDK.GetLedStyle, "Steady" should be always present + const string LED_STYLE = "Steady"; - _MsiSDK.SetLedStyle(DeviceInfo.MsiDeviceType, j, LED_STYLE); - InitializeLed(LedId.Mainboard1 + j, new Rectangle(j * 40, 0, 40, 8)); - } - } + _MsiSDK.SetLedStyle(DeviceInfo.MsiDeviceType, i, LED_STYLE); + InitializeLed(LedId.Mainboard1 + i, new Rectangle(i * 40, 0, 40, 8)); } //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index 703aaea..59a3980 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -104,31 +104,32 @@ namespace RGB.NET.Devices.Msi if ((errorCode = _MsiSDK.Initialize()) != 0) ThrowMsiError(errorCode); - if ((errorCode = _MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] _)) != 0) + if ((errorCode = _MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts)) != 0) ThrowMsiError(errorCode); - foreach (string deviceType in deviceTypes) + for (int i = 0; i < deviceTypes.Length; i++) { try { + string deviceType = deviceTypes[i]; + int ledCount = ledCounts[i]; + //Hex3l: MSI_MB provide access to the motherboard "leds" where a led must be intended as a led header (JRGB, JRAINBOW etc..) (Tested on MSI X570 Unify) if (deviceType.Equals("MSI_MB")) { MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType); IMsiRGBDevice motherboard = new MsiMainboardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mainboard, deviceType, "Msi", "Motherboard")); - motherboard.Initialize(updateQueue); + motherboard.Initialize(updateQueue, ledCount); devices.Add(motherboard); } - - - if (deviceType.Equals("MSI_VGA")) + else if (deviceType.Equals("MSI_VGA")) { //Hex3l: Every led under MSI_VGA should be a different graphics card. Handling all the cards together seems a good way to avoid overlapping of leds //Hex3l: The led name is the name of the card (e.g. NVIDIA GeForce RTX 2080 Ti) we could provide it in device info. MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType); IMsiRGBDevice graphicscard = new MsiGraphicsCardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.GraphicsCard, deviceType, "Msi", "GraphicsCard")); - graphicscard.Initialize(updateQueue); + graphicscard.Initialize(updateQueue, ledCount); devices.Add(graphicscard); } diff --git a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj.DotSettings b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj.DotSettings index 1071e1b..5db6073 100644 --- a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj.DotSettings +++ b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj.DotSettings @@ -1,4 +1,5 @@  True True + True True \ No newline at end of file