mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
Refactored MSI
This commit is contained in:
parent
65be68f0b4
commit
18887a048e
@ -3,10 +3,10 @@
|
||||
namespace RGB.NET.Devices.Msi
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a msi RGB-device.
|
||||
/// Represents a MSI RGB-device.
|
||||
/// </summary>
|
||||
internal interface IMsiRGBDevice : IRGBDevice
|
||||
{
|
||||
void Initialize();
|
||||
void Initialize(MsiDeviceUpdateQueue updateQueue);
|
||||
}
|
||||
}
|
||||
|
||||
45
RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs
Normal file
45
RGB.NET.Devices.Msi/Generic/MsiDeviceUpdateQueue.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Devices.Msi.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Msi
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents the update-queue performing updates for MSI devices.
|
||||
/// </summary>
|
||||
public class MsiDeviceUpdateQueue : UpdateQueue
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private string _deviceType;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MsiDeviceUpdateQueue"/> class.
|
||||
/// </summary>
|
||||
/// <param name="updateTrigger">The update trigger used by this queue.</param>
|
||||
/// <param name="deviceType">The device-type used to identify the device.</param>
|
||||
public MsiDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger, string deviceType)
|
||||
: base(updateTrigger)
|
||||
{
|
||||
this._deviceType = deviceType;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Update(Dictionary<object, Color> dataSet)
|
||||
{
|
||||
foreach (KeyValuePair<object, Color> data in dataSet)
|
||||
_MsiSDK.SetLedColor(_deviceType, (int)data.Key, data.Value.GetR(), data.Value.GetG(), data.Value.GetB());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
{
|
||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
|
||||
/// <inheritdoc cref="IMsiRGBDevice" />
|
||||
/// <summary>
|
||||
/// Represents a generic Msi-device. (keyboard, mouse, headset, mousepad).
|
||||
/// Represents a generic MSI-device. (keyboard, mouse, headset, mousepad).
|
||||
/// </summary>
|
||||
public abstract class MsiRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, IMsiRGBDevice
|
||||
where TDeviceInfo : MsiRGBDeviceInfo
|
||||
@ -21,6 +20,12 @@ namespace RGB.NET.Devices.Msi
|
||||
/// </summary>
|
||||
public override TDeviceInfo DeviceInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the update queue performing updates for this device.
|
||||
/// </summary>
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
protected MsiDeviceUpdateQueue DeviceUpdateQueue { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@ -28,7 +33,7 @@ namespace RGB.NET.Devices.Msi
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MsiRGBDevice{TDeviceInfo}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The generic information provided by Msi for the device.</param>
|
||||
/// <param name="info">The generic information provided by MSI for the device.</param>
|
||||
protected MsiRGBDevice(TDeviceInfo info)
|
||||
{
|
||||
this.DeviceInfo = info;
|
||||
@ -41,8 +46,10 @@ namespace RGB.NET.Devices.Msi
|
||||
/// <summary>
|
||||
/// Initializes the device.
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
public void Initialize(MsiDeviceUpdateQueue updateQueue)
|
||||
{
|
||||
DeviceUpdateQueue = updateQueue;
|
||||
|
||||
InitializeLayout();
|
||||
|
||||
if (Size == Size.Invalid)
|
||||
@ -59,16 +66,7 @@ namespace RGB.NET.Devices.Msi
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
||||
{
|
||||
List<Led> 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
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ namespace RGB.NET.Devices.Msi
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a generic information for a Corsair-<see cref="T:RGB.NET.Core.IRGBDevice" />.
|
||||
/// Represents a generic information for a MSI-<see cref="T:RGB.NET.Core.IRGBDevice" />.
|
||||
/// </summary>
|
||||
public class MsiRGBDeviceInfo : IRGBDeviceInfo
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a Msi mainboard.
|
||||
/// Represents a MSI mainboard.
|
||||
/// </summary>
|
||||
public class MsiMainboardRGBDevice : MsiRGBDevice<MsiRGBDeviceInfo>
|
||||
{
|
||||
@ -17,7 +15,7 @@ namespace RGB.NET.Devices.Msi
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Msi.MsiMainboardRGBDevice" /> class.
|
||||
/// </summary>
|
||||
/// <param name="info">The specific information provided by Asus for the mainboard.</param>
|
||||
/// <param name="info">The specific information provided by MSI for the mainboard.</param>
|
||||
internal MsiMainboardRGBDevice(MsiRGBDeviceInfo info)
|
||||
: base(info)
|
||||
{ }
|
||||
@ -29,7 +27,7 @@ namespace RGB.NET.Devices.Msi
|
||||
/// <inheritdoc />
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Mainboard1;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void SyncBack()
|
||||
public override void SyncBack()
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ namespace RGB.NET.Devices.Msi
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a device provider responsible for Cooler Master devices.
|
||||
/// Represents a device provider responsible for MSI devices.
|
||||
/// </summary>
|
||||
public class MsiDeviceProvider : IRGBDeviceProvider
|
||||
{
|
||||
@ -62,6 +62,11 @@ namespace RGB.NET.Devices.Msi
|
||||
/// </summary>
|
||||
public Func<CultureInfo> GetCulture { get; set; } = CultureHelper.GetCurrentCulture;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="DeviceUpdateTrigger"/> used to trigger the updates for corsair devices.
|
||||
/// </summary>
|
||||
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<IRGBDevice> devices = new List<IRGBDevice>();
|
||||
@ -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<IRGBDevice>(devices);
|
||||
IsInitialized = true;
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
namespace RGB.NET.Devices.Msi
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public class MsiDeviceProviderLoader : IRGBDeviceProviderLoader
|
||||
{
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enum/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generic/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generic/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mainboard/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
Loading…
x
Reference in New Issue
Block a user