mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Refactored MSI
This commit is contained in:
parent
65be68f0b4
commit
18887a048e
@ -3,10 +3,10 @@
|
|||||||
namespace RGB.NET.Devices.Msi
|
namespace RGB.NET.Devices.Msi
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a msi RGB-device.
|
/// Represents a MSI RGB-device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal interface IMsiRGBDevice : IRGBDevice
|
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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using RGB.NET.Devices.Msi.Native;
|
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Msi
|
namespace RGB.NET.Devices.Msi
|
||||||
{
|
{
|
||||||
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
|
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
|
||||||
/// <inheritdoc cref="IMsiRGBDevice" />
|
/// <inheritdoc cref="IMsiRGBDevice" />
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a generic Msi-device. (keyboard, mouse, headset, mousepad).
|
/// Represents a generic MSI-device. (keyboard, mouse, headset, mousepad).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class MsiRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, IMsiRGBDevice
|
public abstract class MsiRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, IMsiRGBDevice
|
||||||
where TDeviceInfo : MsiRGBDeviceInfo
|
where TDeviceInfo : MsiRGBDeviceInfo
|
||||||
@ -21,6 +20,12 @@ namespace RGB.NET.Devices.Msi
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override TDeviceInfo DeviceInfo { get; }
|
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
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@ -28,7 +33,7 @@ namespace RGB.NET.Devices.Msi
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="MsiRGBDevice{TDeviceInfo}"/> class.
|
/// Initializes a new instance of the <see cref="MsiRGBDevice{TDeviceInfo}"/> class.
|
||||||
/// </summary>
|
/// </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)
|
protected MsiRGBDevice(TDeviceInfo info)
|
||||||
{
|
{
|
||||||
this.DeviceInfo = info;
|
this.DeviceInfo = info;
|
||||||
@ -41,8 +46,10 @@ namespace RGB.NET.Devices.Msi
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the device.
|
/// Initializes the device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Initialize()
|
public void Initialize(MsiDeviceUpdateQueue updateQueue)
|
||||||
{
|
{
|
||||||
|
DeviceUpdateQueue = updateQueue;
|
||||||
|
|
||||||
InitializeLayout();
|
InitializeLayout();
|
||||||
|
|
||||||
if (Size == Size.Invalid)
|
if (Size == Size.Invalid)
|
||||||
@ -59,16 +66,7 @@ namespace RGB.NET.Devices.Msi
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
||||||
{
|
=> DeviceUpdateQueue.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is int)));
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ namespace RGB.NET.Devices.Msi
|
|||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public class MsiRGBDeviceInfo : IRGBDeviceInfo
|
public class MsiRGBDeviceInfo : IRGBDeviceInfo
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
using System;
|
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using RGB.NET.Devices.Msi.Native;
|
using RGB.NET.Devices.Msi.Native;
|
||||||
using RGB.NET.Devices.Msi.Exceptions;
|
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Msi
|
namespace RGB.NET.Devices.Msi
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a Msi mainboard.
|
/// Represents a MSI mainboard.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MsiMainboardRGBDevice : MsiRGBDevice<MsiRGBDeviceInfo>
|
public class MsiMainboardRGBDevice : MsiRGBDevice<MsiRGBDeviceInfo>
|
||||||
{
|
{
|
||||||
@ -17,7 +15,7 @@ namespace RGB.NET.Devices.Msi
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Msi.MsiMainboardRGBDevice" /> class.
|
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Msi.MsiMainboardRGBDevice" /> class.
|
||||||
/// </summary>
|
/// </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)
|
internal MsiMainboardRGBDevice(MsiRGBDeviceInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{ }
|
{ }
|
||||||
@ -29,7 +27,7 @@ namespace RGB.NET.Devices.Msi
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void InitializeLayout()
|
protected override void InitializeLayout()
|
||||||
{
|
{
|
||||||
// Should errors be handled?
|
// Should errors be handled?
|
||||||
_MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts);
|
_MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts);
|
||||||
|
|
||||||
for (int i = 0; i < deviceTypes.Length; i++)
|
for (int i = 0; i < deviceTypes.Length; i++)
|
||||||
@ -39,19 +37,19 @@ namespace RGB.NET.Devices.Msi
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < ledCounts[i]; j++)
|
for (int j = 0; j < ledCounts[i]; j++)
|
||||||
{
|
{
|
||||||
// Should it be configurable in order to provide style access?
|
//Hex3l: 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
|
//Hex3l: 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
|
//Hex3l: This is a string defined by the output of _MsiSDK.GetLedStyle, "Steady" should be always present
|
||||||
string style = "Steady";
|
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));
|
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?
|
//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 />
|
/// <inheritdoc />
|
||||||
@ -61,8 +59,6 @@ namespace RGB.NET.Devices.Msi
|
|||||||
public override void SyncBack()
|
public override void SyncBack()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ namespace RGB.NET.Devices.Msi
|
|||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a device provider responsible for Cooler Master devices.
|
/// Represents a device provider responsible for MSI devices.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MsiDeviceProvider : IRGBDeviceProvider
|
public class MsiDeviceProvider : IRGBDeviceProvider
|
||||||
{
|
{
|
||||||
@ -62,6 +62,11 @@ namespace RGB.NET.Devices.Msi
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<CultureInfo> GetCulture { get; set; } = CultureHelper.GetCurrentCulture;
|
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
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#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)}");
|
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(MsiDeviceProvider)}");
|
||||||
_instance = this;
|
_instance = this;
|
||||||
|
|
||||||
|
UpdateTrigger = new DeviceUpdateTrigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -87,6 +94,8 @@ namespace RGB.NET.Devices.Msi
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
UpdateTrigger?.Stop();
|
||||||
|
|
||||||
_MsiSDK.Reload();
|
_MsiSDK.Reload();
|
||||||
|
|
||||||
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
||||||
@ -95,28 +104,29 @@ namespace RGB.NET.Devices.Msi
|
|||||||
if ((errorCode = _MsiSDK.Initialize()) != 0)
|
if ((errorCode = _MsiSDK.Initialize()) != 0)
|
||||||
ThrowMsiError(errorCode);
|
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);
|
ThrowMsiError(errorCode);
|
||||||
|
|
||||||
for (int i = 0; i < deviceTypes.Length; i++)
|
foreach (string deviceType in deviceTypes)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//TODO DarthAffe 11.11.2017: What is this deviceType? Find someone to try that out
|
//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"))
|
||||||
// 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"));
|
MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType);
|
||||||
motherboard.Initialize();
|
IMsiRGBDevice motherboard = new MsiMainboardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mainboard, deviceType, "Msi", "Motherboard"));
|
||||||
|
motherboard.Initialize(updateQueue);
|
||||||
devices.Add(motherboard);
|
devices.Add(motherboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other devices?
|
//TODO DarthAffe 22.02.2020: Add other devices
|
||||||
}
|
}
|
||||||
catch { if (throwExceptions) throw; }
|
catch { if (throwExceptions) throw; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateTrigger?.Start();
|
||||||
|
|
||||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||||
IsInitialized = true;
|
IsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
namespace RGB.NET.Devices.Msi
|
namespace RGB.NET.Devices.Msi
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public class MsiDeviceProviderLoader : IRGBDeviceProviderLoader
|
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">
|
<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/=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