1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Small refactorings

This commit is contained in:
Darth Affe 2020-02-23 01:08:47 +01:00
parent 749538741c
commit 93e7e7d004
7 changed files with 32 additions and 49 deletions

View File

@ -34,6 +34,7 @@ namespace RGB.NET.Devices.Msi.Exceptions
/// <param name="errorCode">The raw error code provided by the SDK.</param> /// <param name="errorCode">The raw error code provided by the SDK.</param>
/// <param name="description">The text-description of the error.</param> /// <param name="description">The text-description of the error.</param>
public MysticLightException(int errorCode, string description) public MysticLightException(int errorCode, string description)
: base($"MSI error code {errorCode} ({description})")
{ {
this.ErrorCode = errorCode; this.ErrorCode = errorCode;
this.Description = description; this.Description = description;

View File

@ -7,6 +7,6 @@ namespace RGB.NET.Devices.Msi
/// </summary> /// </summary>
internal interface IMsiRGBDevice : IRGBDevice internal interface IMsiRGBDevice : IRGBDevice
{ {
void Initialize(MsiDeviceUpdateQueue updateQueue); void Initialize(MsiDeviceUpdateQueue updateQueue, int ledCount);
} }
} }

View File

@ -46,11 +46,11 @@ namespace RGB.NET.Devices.Msi
/// <summary> /// <summary>
/// Initializes the device. /// Initializes the device.
/// </summary> /// </summary>
public void Initialize(MsiDeviceUpdateQueue updateQueue) public void Initialize(MsiDeviceUpdateQueue updateQueue, int ledCount)
{ {
DeviceUpdateQueue = updateQueue; DeviceUpdateQueue = updateQueue;
InitializeLayout(); InitializeLayout(ledCount);
if (Size == Size.Invalid) if (Size == Size.Invalid)
{ {
@ -62,7 +62,7 @@ namespace RGB.NET.Devices.Msi
/// <summary> /// <summary>
/// Initializes the <see cref="Led"/> and <see cref="Size"/> of the device. /// Initializes the <see cref="Led"/> and <see cref="Size"/> of the device.
/// </summary> /// </summary>
protected abstract void InitializeLayout(); protected abstract void InitializeLayout(int ledCount);
/// <inheritdoc /> /// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)

View File

@ -25,29 +25,19 @@ namespace RGB.NET.Devices.Msi
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void InitializeLayout() protected override void InitializeLayout(int ledCount)
{ {
// Should errors be handled? for (int i = 0; i < ledCount; i++)
_MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts);
for (int i = 0; i < deviceTypes.Length; i++)
{ {
// DeviceInfo.MsiDeviceType = "MSI_VGA" //Hex3l: Should it be configurable in order to provide style access?
if (deviceTypes[i].Equals(DeviceInfo.MsiDeviceType)) //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
for (int j = 0; j < ledCounts[i]; j++) 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); _MsiSDK.SetLedStyle(DeviceInfo.MsiDeviceType, i, LED_STYLE);
InitializeLed(LedId.GraphicsCard1 + j, new Rectangle(j * 10, 0, 10, 10)); 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? //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; protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.GraphicsCard1;
/// <inheritdoc /> /// <inheritdoc />
public override void SyncBack() public override void SyncBack()
{ } { }
#endregion #endregion

View File

@ -25,27 +25,17 @@ namespace RGB.NET.Devices.Msi
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void InitializeLayout() protected override void InitializeLayout(int ledCount)
{ {
// Should errors be handled? for (int i = 0; i < ledCount; i++)
_MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts);
for (int i = 0; i < deviceTypes.Length; i++)
{ {
// DeviceInfo.MsiDeviceType = "MSI_MB" //Hex3l: Should it be configurable in order to provide style access?
if (deviceTypes[i].Equals(DeviceInfo.MsiDeviceType)) //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
for (int j = 0; j < ledCounts[i]; j++) 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); _MsiSDK.SetLedStyle(DeviceInfo.MsiDeviceType, i, LED_STYLE);
InitializeLed(LedId.Mainboard1 + j, new Rectangle(j * 40, 0, 40, 8)); 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? //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images?

View File

@ -104,31 +104,32 @@ 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[] _)) != 0) if ((errorCode = _MsiSDK.GetDeviceInfo(out string[] deviceTypes, out int[] ledCounts)) != 0)
ThrowMsiError(errorCode); ThrowMsiError(errorCode);
foreach (string deviceType in deviceTypes) for (int i = 0; i < deviceTypes.Length; i++)
{ {
try 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) //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")) if (deviceType.Equals("MSI_MB"))
{ {
MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType); MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType);
IMsiRGBDevice motherboard = new MsiMainboardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mainboard, deviceType, "Msi", "Motherboard")); IMsiRGBDevice motherboard = new MsiMainboardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mainboard, deviceType, "Msi", "Motherboard"));
motherboard.Initialize(updateQueue); motherboard.Initialize(updateQueue, ledCount);
devices.Add(motherboard); devices.Add(motherboard);
} }
else if (deviceType.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: 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. //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); MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType);
IMsiRGBDevice graphicscard = new MsiGraphicsCardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.GraphicsCard, deviceType, "Msi", "GraphicsCard")); IMsiRGBDevice graphicscard = new MsiGraphicsCardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.GraphicsCard, deviceType, "Msi", "GraphicsCard"));
graphicscard.Initialize(updateQueue); graphicscard.Initialize(updateQueue, ledCount);
devices.Add(graphicscard); devices.Add(graphicscard);
} }

View File

@ -1,4 +1,5 @@
<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> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=generic/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=graphicscard/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mainboard/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mainboard/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>