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