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

Added DeviceName

This commit is contained in:
Darth Affe 2018-07-10 20:59:52 +02:00
parent 7c5306232f
commit d0c3d4a9dc
19 changed files with 124 additions and 28 deletions

View File

@ -14,6 +14,11 @@ namespace RGB.NET.Core
/// </summary>
RGBDeviceType DeviceType { get; }
/// <summary>
/// Unique name of the <see cref="IRGBDevice"/>.
/// </summary>
string DeviceName { get; }
/// <summary>
/// Gets the manufacturer-name of the <see cref="IRGBDevice"/>.
/// </summary>

View File

@ -14,6 +14,9 @@ namespace RGB.NET.Devices.Asus
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer { get; }
@ -51,6 +54,8 @@ namespace RGB.NET.Devices.Asus
this.Handle = handle;
this.Model = model;
this.Manufacturer = manufacturer;
DeviceName = $"{Manufacturer} {Model}";
}
#endregion

View File

@ -15,6 +15,9 @@ namespace RGB.NET.Devices.CoolerMaster
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer => "Cooler Master";
@ -50,6 +53,7 @@ namespace RGB.NET.Devices.CoolerMaster
this.DeviceIndex = deviceIndex;
Model = deviceIndex.GetDescription();
DeviceName = $"{Manufacturer} {Model}";
}
#endregion

View File

@ -129,6 +129,7 @@ namespace RGB.NET.Devices.Corsair
if (!_CUESDK.CorsairSetLayerPriority(127))
throw new CUEException(LastError);
Dictionary<string, int> modelCounter = new Dictionary<string, int>();
IList<IRGBDevice> devices = new List<IRGBDevice>();
int deviceCount = _CUESDK.CorsairGetDeviceCount();
for (int i = 0; i < deviceCount; i++)
@ -136,12 +137,12 @@ namespace RGB.NET.Devices.Corsair
try
{
_CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo));
CorsairRGBDeviceInfo info = new CorsairRGBDeviceInfo(i, RGBDeviceType.Unknown, nativeDeviceInfo);
CorsairRGBDeviceInfo info = new CorsairRGBDeviceInfo(i, RGBDeviceType.Unknown, nativeDeviceInfo, modelCounter);
if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting))
continue; // Everything that doesn't support lighting control is useless
CorsairDeviceUpdateQueue deviceUpdateQueue = null;
foreach (ICorsairRGBDevice device in GetRGBDevice(info, i, nativeDeviceInfo))
foreach (ICorsairRGBDevice device in GetRGBDevice(info, i, nativeDeviceInfo, modelCounter))
{
if ((device == null) || !loadFilter.HasFlag(device.DeviceInfo.DeviceType)) continue;
@ -176,28 +177,28 @@ namespace RGB.NET.Devices.Corsair
return true;
}
private static IEnumerable<ICorsairRGBDevice> GetRGBDevice(CorsairRGBDeviceInfo info, int i, _CorsairDeviceInfo nativeDeviceInfo)
private static IEnumerable<ICorsairRGBDevice> GetRGBDevice(CorsairRGBDeviceInfo info, int i, _CorsairDeviceInfo nativeDeviceInfo, Dictionary<string, int> modelCounter)
{
switch (info.CorsairDeviceType)
{
case CorsairDeviceType.Keyboard:
yield return new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo));
yield return new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo, modelCounter));
break;
case CorsairDeviceType.Mouse:
yield return new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo));
yield return new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo, modelCounter));
break;
case CorsairDeviceType.Headset:
yield return new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo));
yield return new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo, modelCounter));
break;
case CorsairDeviceType.Mousepad:
yield return new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo));
yield return new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo, modelCounter));
break;
case CorsairDeviceType.HeadsetStand:
yield return new CorsairHeadsetStandRGBDevice(new CorsairHeadsetStandRGBDeviceInfo(i, nativeDeviceInfo));
yield return new CorsairHeadsetStandRGBDevice(new CorsairHeadsetStandRGBDeviceInfo(i, nativeDeviceInfo, modelCounter));
break;
case CorsairDeviceType.CommanderPro:
@ -220,7 +221,7 @@ namespace RGB.NET.Devices.Corsair
{
_CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo));
yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(info.CorsairDeviceIndex, nativeDeviceInfo, channelDeviceInfo, referenceLed));
yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(info.CorsairDeviceIndex, nativeDeviceInfo, channelDeviceInfo, referenceLed, modelCounter));
referenceLed += channelDeviceInfo.deviceLedCount;
channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize);

View File

@ -2,6 +2,7 @@
// ReSharper disable UnusedMember.Global
using System;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
@ -31,8 +32,10 @@ namespace RGB.NET.Devices.Corsair
/// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
/// <param name="channelDeviceInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairChannelDeviceInfo"/> representing this device.</param>
/// <param name="referenceCorsairLed">The id of the first led of this device.</param>
internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, CorsairLedId referenceCorsairLed)
: base(deviceIndex, channelDeviceInfo.type == CorsairChannelDeviceType.Strip ? RGBDeviceType.LedStripe : RGBDeviceType.Fan, nativeInfo, GetModelName(channelDeviceInfo.type))
internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo,
CorsairLedId referenceCorsairLed, Dictionary<string, int> modelCounter)
: base(deviceIndex, channelDeviceInfo.type == CorsairChannelDeviceType.Strip ? RGBDeviceType.LedStripe : RGBDeviceType.Fan, nativeInfo,
GetModelName(channelDeviceInfo.type), modelCounter)
{
this.ReferenceCorsairLed = referenceCorsairLed;

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using RGB.NET.Core;
@ -27,6 +28,9 @@ namespace RGB.NET.Devices.Corsair
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer => "Corsair";
@ -57,13 +61,16 @@ namespace RGB.NET.Devices.Corsair
/// <param name="deviceIndex">The index of the <see cref="CorsairRGBDevice{TDeviceInfo}"/>.</param>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo)
/// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo, Dictionary<string, int> modelCounter)
{
this.CorsairDeviceIndex = deviceIndex;
this.DeviceType = deviceType;
this.CorsairDeviceType = nativeInfo.type;
this.Model = nativeInfo.model == IntPtr.Zero ? null : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase);
this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask;
DeviceName = GetUniqueModelName(modelCounter);
}
/// <summary>
@ -73,13 +80,34 @@ namespace RGB.NET.Devices.Corsair
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="nativeInfo">The native <see cref="_CorsairDeviceInfo" />-struct</param>
/// <param name="modelName">The name of the device-model (overwrites the one provided with the device info).</param>
internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo, string modelName)
/// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
internal CorsairRGBDeviceInfo(int deviceIndex, RGBDeviceType deviceType, _CorsairDeviceInfo nativeInfo, string modelName, Dictionary<string, int> modelCounter)
{
this.CorsairDeviceIndex = deviceIndex;
this.DeviceType = deviceType;
this.CorsairDeviceType = nativeInfo.type;
this.Model = modelName;
this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask;
DeviceName = GetUniqueModelName(modelCounter);
}
#endregion
#region Methods
private string GetUniqueModelName(Dictionary<string, int> modelCounter)
{
if (modelCounter.TryGetValue(Model, out int counter))
{
counter = ++modelCounter[Model];
return $"{Manufacturer} {Model} {counter}";
}
else
{
modelCounter.Add(Model, 1);
return $"{Manufacturer} {Model}";
}
}
#endregion

View File

@ -1,4 +1,5 @@
using RGB.NET.Core;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
@ -17,8 +18,9 @@ namespace RGB.NET.Devices.Corsair
/// </summary>
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetRGBDevice" />.</param>
/// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
internal CorsairHeadsetRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, RGBDeviceType.Headset, nativeInfo)
/// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
internal CorsairHeadsetRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, Dictionary<string, int> modelCounter)
: base(deviceIndex, RGBDeviceType.Headset, nativeInfo, modelCounter)
{ }
#endregion

View File

@ -1,4 +1,5 @@
using RGB.NET.Core;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
@ -17,8 +18,9 @@ namespace RGB.NET.Devices.Corsair
/// </summary>
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairHeadsetStandRGBDevice" />.</param>
/// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
internal CorsairHeadsetStandRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, RGBDeviceType.HeadsetStand, nativeInfo)
/// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
internal CorsairHeadsetStandRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, Dictionary<string, int> modelCounter)
: base(deviceIndex, RGBDeviceType.HeadsetStand, nativeInfo, modelCounter)
{ }
#endregion

View File

@ -1,6 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
@ -34,8 +35,9 @@ namespace RGB.NET.Devices.Corsair
/// </summary>
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairKeyboardRGBDevice" />.</param>
/// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
internal CorsairKeyboardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, RGBDeviceType.Keyboard, nativeInfo)
/// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
internal CorsairKeyboardRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, Dictionary<string, int> modelCounter)
: base(deviceIndex, RGBDeviceType.Keyboard, nativeInfo, modelCounter)
{
this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout;
this.LogicalLayout = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout;

View File

@ -1,4 +1,5 @@
using RGB.NET.Core;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
@ -26,8 +27,9 @@ namespace RGB.NET.Devices.Corsair
/// </summary>
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Corsair.CorsairMouseRGBDevice" />.</param>
/// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
internal CorsairMouseRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, RGBDeviceType.Mouse, nativeInfo)
/// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
internal CorsairMouseRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, Dictionary<string, int> modelCounter)
: base(deviceIndex, RGBDeviceType.Mouse, nativeInfo, modelCounter)
{
this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout;
}

View File

@ -1,4 +1,5 @@
using RGB.NET.Core;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair
@ -17,8 +18,9 @@ namespace RGB.NET.Devices.Corsair
/// </summary>
/// <param name="deviceIndex">The index if the <see cref="T:RGB.NET.Devices.Corsair.CorsairMousepadRGBDevice" />.</param>
/// <param name="nativeInfo">The native <see cref="T:RGB.NET.Devices.Corsair.Native._CorsairDeviceInfo" />-struct</param>
internal CorsairMousepadRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, RGBDeviceType.Mousepad, nativeInfo)
/// <param name="modelCounter">A dictionary containing counters to create unique names for equal devices models.</param>
internal CorsairMousepadRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, Dictionary<string, int> modelCounter)
: base(deviceIndex, RGBDeviceType.Mousepad, nativeInfo, modelCounter)
{ }
#endregion

View File

@ -24,6 +24,9 @@ namespace RGB.NET.Devices.DMX.E131
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer { get; }
@ -78,6 +81,8 @@ namespace RGB.NET.Devices.DMX.E131
CID = new byte[CID_LENGTH];
new Random().NextBytes(CID);
}
DeviceName = $"{Manufacturer} {Model}";
}
#endregion

View File

@ -14,6 +14,9 @@ namespace RGB.NET.Devices.Debug
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer { get; }
@ -41,13 +44,15 @@ namespace RGB.NET.Devices.Debug
/// <param name="model">The model of the device.</param>
/// <param name="lighting">The <see cref="RGBDeviceLighting"/> of the device.</param>
/// <param name="supportsSyncBack">True if the device supports syncback; false if not.</param>
internal DebugRGBDeviceInfo(RGBDeviceType deviceType, string manufacturer, string model, RGBDeviceLighting lighting, bool supportsSyncBack)
internal DebugRGBDeviceInfo(RGBDeviceType deviceType, string manufacturer, string model, RGBDeviceLighting lighting, bool supportsSyncBack, string deviceName = null)
{
this.DeviceType = deviceType;
this.Manufacturer = manufacturer;
this.Model = model;
this.Lighting = lighting;
this.SupportsSyncBack = supportsSyncBack;
DeviceName = deviceName ?? $"{Manufacturer} {Model}";
}
#endregion

View File

@ -14,6 +14,9 @@ namespace RGB.NET.Devices.Logitech
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer => "Logitech";
@ -76,6 +79,8 @@ namespace RGB.NET.Devices.Logitech
this.DeviceCaps = deviceCaps;
this.ImageLayout = imageLayout;
this.LayoutPath = layoutPath;
DeviceName = $"{Manufacturer} {Model}";
}
#endregion

View File

@ -19,6 +19,9 @@ namespace RGB.NET.Devices.Msi
/// </summary>
public string MsiDeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer { get; }
@ -51,6 +54,8 @@ namespace RGB.NET.Devices.Msi
this.MsiDeviceType = msiDeviceType;
this.Manufacturer = manufacturer;
this.Model = model;
DeviceName = $"{Manufacturer} {Model}";
}
#endregion

View File

@ -14,6 +14,9 @@ namespace RGB.NET.Devices.Novation
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer => "Novation";
@ -56,6 +59,8 @@ namespace RGB.NET.Devices.Novation
this.Model = model;
this.DeviceId = deviceId;
this.ColorCapabilities = colorCapabilities;
DeviceName = $"{Manufacturer} {Model}";
}
#endregion

View File

@ -19,6 +19,9 @@ namespace RGB.NET.Devices.Razer
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer => "Razer";
@ -49,6 +52,8 @@ namespace RGB.NET.Devices.Razer
this.DeviceId = deviceId;
this.DeviceType = deviceType;
this.Model = model;
DeviceName = $"{Manufacturer} {Model}";
}
#endregion

View File

@ -14,6 +14,9 @@ namespace RGB.NET.Devices.SoIP.Client
/// <inheritdoc />
public RGBDeviceType DeviceType => RGBDeviceType.Unknown;
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer { get; }
@ -49,6 +52,8 @@ namespace RGB.NET.Devices.SoIP.Client
this.Model = deviceDefinition.Model;
this.Hostname = deviceDefinition.Hostname;
this.Port = deviceDefinition.Port;
DeviceName = $"{Manufacturer} {Model}";
}
#endregion

View File

@ -14,6 +14,9 @@ namespace RGB.NET.Devices.SoIP.Server
/// <inheritdoc />
public RGBDeviceType DeviceType => RGBDeviceType.Unknown;
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer { get; }
@ -43,6 +46,8 @@ namespace RGB.NET.Devices.SoIP.Server
this.Manufacturer = deviceDefinition.Manufacturer;
this.Model = deviceDefinition.Model;
this.Port = deviceDefinition.Port;
DeviceName = $"{Manufacturer} {Model}";
}
#endregion