Refactored LedIds

Everything is now based on the same ids for all devices
This commit is contained in:
DarthAffe committed 2017-12-13 17:19:56 +01:00
1 parent 200e471e4d
commit c5a1825f50
80 files changed
+2923 -3657

No files matched your search

@@ -1,137 +0,0 @@
// ReSharper disable InconsistentNaming
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
namespace RGB.NET.Devices.CoolerMaster
{
/// <summary>
/// Contains list of all LEDs available for all CoolerMaster devices.
/// </summary>
public enum CoolerMasterLedIds
{
Invalid = -1,
Esc = 0,
F1 = 1,
F2 = 2,
F3 = 3,
F4 = 4,
F5 = 6,
F6 = 7,
F7 = 8,
F8 = 9,
F9 = 11,
F10 = 12,
F11 = 13,
F12 = 14,
Snapshot = 15,
ScrollLock = 16,
Pause = 17,
P1 = 18,
P2 = 19,
P3 = 20,
P4 = 21,
Gravis = 22,
D1 = 23,
D2 = 24,
D3 = 25,
D4 = 26,
D5 = 27,
D6 = 28,
D7 = 29,
D8 = 30,
D9 = 31,
D0 = 32,
Minus = 33,
Equals = 34,
Backspace = 36,
Insert = 37,
Home = 38,
PageUp = 39,
Numlock = 40,
KeypadSlash = 41,
KeypadAsterisk = 42,
KeypadMinus = 43,
Tab = 44,
Q = 45,
W = 46,
E = 47,
R = 48,
T = 49,
Y = 50,
U = 51,
I = 52,
O = 53,
P = 54,
BracketLeft = 55,
BracketRight = 56,
Backslash = 58,
Delete = 59,
End = 60,
PageDown = 61,
Keypad7 = 62,
Keypad8 = 63,
Keypad9 = 64,
KeypadPlus = 65,
CapsLock = 66,
A = 67,
S = 68,
D = 69,
F = 70,
G = 71,
H = 72,
J = 73,
K = 74,
L = 75,
Semicolon = 76,
Apostroph = 77,
CODEA2 = 78,
Enter = 80,
Keypad4 = 84,
Keypad5 = 85,
Keypad6 = 86,
LShift = 88,
CODEA5 = 89,
Z = 90,
X = 91,
C = 92,
V = 93,
B = 94,
N = 95,
M = 96,
Comma = 97,
Period = 98,
Slash = 99,
RShift = 102,
Up = 104,
Keypad1 = 106,
Keypad2 = 107,
Keypad3 = 108,
KeypadEnter = 109,
LCtrl = 110,
LWin = 111,
LAlt = 112,
Space = 116,
RAlt = 120,
RWin = 121,
App = 122,
RCtrl = 124,
Left = 125,
Down = 126,
Right = 127,
Keypad0 = 128,
Keypad00 = 129,
KeypadPeriod = 130,
Side1 = 132,
Side2 = 133,
Side3 = 134,
Back1 = 135,
Wheel = 136
}
}
@@ -1,126 +0,0 @@
using System.Diagnostics;
using RGB.NET.Core;
namespace RGB.NET.Devices.CoolerMaster
{
/// <inheritdoc />
/// <summary>
/// Represents a Id of a <see cref="T:RGB.NET.Core.Led" /> on a <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterRGBDevice" />.
/// </summary>
[DebuggerDisplay("{" + nameof(LedId) + "}")]
public class CoolerMasterLedId : ILedId
{
#region Properties & Fields
internal readonly CoolerMasterLedIds LedId;
internal readonly int Row;
internal readonly int Column;
/// <inheritdoc />
public IRGBDevice Device { get; }
/// <inheritdoc />
public bool IsValid => LedId != CoolerMasterLedIds.Invalid;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="CoolerMasterLedId"/> class.
/// </summary>
/// <param name="device">The <see cref="IRGBDevice"/> the <see cref="ILedId"/> belongs to.</param>
/// <param name="ledId">The <see cref="CoolerMasterLedId"/> of the represented <see cref="Led"/>.</param>
public CoolerMasterLedId(IRGBDevice device, CoolerMasterLedIds ledId)
{
this.Device = device;
this.LedId = ledId;
}
/// <summary>
/// Initializes a new instance of the <see cref="CoolerMasterLedId"/> class.
/// </summary>
/// <param name="device">The <see cref="IRGBDevice"/> the <see cref="ILedId"/> belongs to.</param>
/// <param name="ledId">The <see cref="CoolerMasterLedId"/> of the represented <see cref="Led"/>.</param>
/// <param name="row">The row in the mapping table of the device.</param>
/// <param name="column">The column in the mapping table of the device.</param>
public CoolerMasterLedId(IRGBDevice device, CoolerMasterLedIds ledId, int row, int column)
{
this.Device = device;
this.LedId = ledId;
this.Row = row;
this.Column = column;
}
#endregion
#region Methods
/// <summary>
/// Converts the Id of this <see cref="CoolerMasterLedId"/> to a human-readable string.
/// </summary>
/// <returns>A string that contains the Id of this <see cref="CoolerMasterLedId"/>. For example "Enter".</returns>
public override string ToString()
{
return LedId.ToString();
}
/// <summary>
/// Tests whether the specified object is a <see cref="CoolerMasterLedId" /> and is equivalent to this <see cref="CoolerMasterLedId" />.
/// </summary>
/// <param name="obj">The object to test.</param>
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="CoolerMasterLedId" /> equivalent to this <see cref="CoolerMasterLedId" />; otherwise, <c>false</c>.</returns>
public override bool Equals(object obj)
{
CoolerMasterLedId compareLedId = obj as CoolerMasterLedId;
if (ReferenceEquals(compareLedId, null))
return false;
if (ReferenceEquals(this, compareLedId))
return true;
if (GetType() != compareLedId.GetType())
return false;
return compareLedId.LedId == LedId;
}
/// <summary>
/// Returns a hash code for this <see cref="CoolerMasterLedId" />.
/// </summary>
/// <returns>An integer value that specifies the hash code for this <see cref="CoolerMasterLedId" />.</returns>
public override int GetHashCode()
{
return LedId.GetHashCode();
}
#endregion
#region Operators
/// <summary>
/// Returns a value that indicates whether two specified <see cref="CoolerMasterLedId" /> are equal.
/// </summary>
/// <param name="ledId1">The first <see cref="CoolerMasterLedId" /> to compare.</param>
/// <param name="ledId2">The second <see cref="CoolerMasterLedId" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="ledId1" /> and <paramref name="ledId2" /> are equal; otherwise, <c>false</c>.</returns>
public static bool operator ==(CoolerMasterLedId ledId1, CoolerMasterLedId ledId2)
{
return ReferenceEquals(ledId1, null) ? ReferenceEquals(ledId2, null) : ledId1.Equals(ledId2);
}
/// <summary>
/// Returns a value that indicates whether two specified <see cref="CoolerMasterLedId" /> are equal.
/// </summary>
/// <param name="ledId1">The first <see cref="CoolerMasterLedId" /> to compare.</param>
/// <param name="ledId2">The second <see cref="CoolerMasterLedId" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="ledId1" /> and <paramref name="ledId2" /> are not equal; otherwise, <c>false</c>.</returns>
public static bool operator !=(CoolerMasterLedId ledId1, CoolerMasterLedId ledId2)
{
return !(ledId1 == ledId2);
}
#endregion
}
}
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Core.Layout;
using RGB.NET.Devices.CoolerMaster.Native;
namespace RGB.NET.Devices.CoolerMaster
@@ -60,44 +58,6 @@ namespace RGB.NET.Devices.CoolerMaster
/// </summary>
protected abstract void InitializeLayout();
/// <summary>
/// Applies the given layout.
/// </summary>
/// <param name="layoutPath">The file containing the layout.</param>
/// <param name="imageLayout">The name of the layout used to get the images of the leds.</param>
/// <param name="imageBasePath">The path images for this device are collected in.</param>
protected void ApplyLayoutFromFile(string layoutPath, string imageLayout, string imageBasePath)
{
DeviceLayout layout = DeviceLayout.Load(layoutPath);
if (layout != null)
{
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
Size = new Size(layout.Width, layout.Height);
if (layout.Leds != null)
foreach (LedLayout layoutLed in layout.Leds)
{
if (Enum.TryParse(layoutLed.Id, true, out CoolerMasterLedIds ledId))
{
if (LedMapping.TryGetValue(new CoolerMasterLedId(this, ledId), out Led led))
{
led.LedRectangle.Location = new Point(layoutLed.X, layoutLed.Y);
led.LedRectangle.Size = new Size(layoutLed.Width, layoutLed.Height);
led.Shape = layoutLed.Shape;
led.ShapeData = layoutLed.ShapeData;
LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id);
led.Image = (!string.IsNullOrEmpty(image?.Image))
? new Uri(Path.Combine(imageBasePath, image.Image), UriKind.Absolute)
: new Uri(Path.Combine(imageBasePath, "Missing.png"), UriKind.Absolute);
}
}
}
}
}
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
{
@@ -109,8 +69,8 @@ namespace RGB.NET.Devices.CoolerMaster
foreach (Led led in leds)
{
CoolerMasterLedId ledId = (CoolerMasterLedId)led.Id;
_CoolerMasterSDK.SetLedColor(ledId.Row, ledId.Column, led.Color.R, led.Color.G, led.Color.B);
(int row, int column) = ((int, int))led.CustomData;
_CoolerMasterSDK.SetLedColor(row, column, led.Color.R, led.Color.G, led.Color.B);
}
_CoolerMasterSDK.RefreshLed(false);
File diff suppressed because it is too large. Load diff
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.CoolerMaster
@@ -28,11 +27,10 @@ namespace RGB.NET.Devices.CoolerMaster
/// <inheritdoc />
protected override void InitializeLayout()
{
Dictionary<CoolerMasterLedIds, Tuple<int, int>> mapping = CoolerMasterKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout];
Dictionary<LedId, (int row, int column)> mapping = CoolerMasterKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout];
foreach (KeyValuePair<CoolerMasterLedIds, Tuple<int, int>> led in mapping)
InitializeLed(new CoolerMasterLedId(this, led.Key, led.Value.Item1, led.Value.Item2),
new Rectangle(led.Value.Item2 * 19, led.Value.Item1 * 19, 19, 19));
foreach (KeyValuePair<LedId, (int row, int column)> led in mapping)
InitializeLed(led.Key, new Rectangle(led.Value.column * 19, led.Value.row * 19, 19, 19));
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath(
@@ -40,6 +38,9 @@ namespace RGB.NET.Devices.CoolerMaster
DeviceInfo.LogicalLayout.ToString(), PathHelper.GetAbsolutePath(@"Images\CoolerMaster\Keyboards"));
}
/// <inheritdoc />
protected override object CreateLedCustomData(LedId ledId) => CoolerMasterKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout][ledId];
#endregion
}
}
@@ -1,5 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.CoolerMaster
{
@@ -14,24 +14,24 @@ namespace RGB.NET.Devices.CoolerMaster
/// Contains all the hardware-id mappings for CoolerMaster devices.
/// </summary>
// ReSharper disable once InconsistentNaming
public static readonly Dictionary<CoolerMasterDevicesIndexes, Dictionary<CoolerMasterLedIds, Tuple<int, int>>> Mapping =
new Dictionary<CoolerMasterDevicesIndexes, Dictionary<CoolerMasterLedIds, Tuple<int, int>>>
public static readonly Dictionary<CoolerMasterDevicesIndexes, Dictionary<LedId, (int row, int column)>> Mapping =
new Dictionary<CoolerMasterDevicesIndexes, Dictionary<LedId, (int row, int column)>>
{
{ CoolerMasterDevicesIndexes.MasterMouse_L, new Dictionary<CoolerMasterLedIds, Tuple<int, int>>
{ CoolerMasterDevicesIndexes.MasterMouse_L, new Dictionary<LedId, (int row, int column)>
{
{ CoolerMasterLedIds.Side1, new Tuple<int, int>(0,0) },
{ CoolerMasterLedIds.Side2, new Tuple<int, int>(1,0) },
{ CoolerMasterLedIds.Side3, new Tuple<int, int>(2,0) },
{ CoolerMasterLedIds.Back1, new Tuple<int, int>(3,0) },
{ LedId.Mouse1, (0,0) },
{ LedId.Mouse2, (1,0) },
{ LedId.Mouse3, (2,0) },
{ LedId.Mouse4, (3,0) },
}
},
{ CoolerMasterDevicesIndexes.MasterMouse_S, new Dictionary<CoolerMasterLedIds, Tuple<int, int>>
{ CoolerMasterDevicesIndexes.MasterMouse_S, new Dictionary<LedId, (int row, int column)>
{
{ CoolerMasterLedIds.Back1, new Tuple<int, int>(0,0) },
{ CoolerMasterLedIds.Wheel, new Tuple<int, int>(1,0) },
{ CoolerMasterLedIds.Side3, new Tuple<int, int>(2,0) },
{ CoolerMasterLedIds.Back1, new Tuple<int, int>(3,0) },
{ LedId.Mouse1, (0,0) },
{ LedId.Mouse2, (1,0) },
{ LedId.Mouse3, (2,0) },
{ LedId.Mouse4, (3,0) },
}
},
};
@@ -48,12 +48,10 @@
<ItemGroup>
<Compile Include="Attributes\DeviceTypeAttribute.cs" />
<Compile Include="CoolerMasterDeviceProvider.cs" />
<Compile Include="Enum\CoolerMasterLedIds.cs" />
<Compile Include="Enum\CoolerMasterPhysicalKeyboardLayout.cs" />
<Compile Include="Enum\CoolerMasterDevicesIndexes.cs" />
<Compile Include="Enum\CoolerMasterEffects.cs" />
<Compile Include="Enum\CoolerMasterLogicalKeyboardLayout.cs" />
<Compile Include="Generic\CoolerMasterLedId.cs" />
<Compile Include="Generic\CoolerMasterRGBDevice.cs" />
<Compile Include="Generic\CoolerMasterRGBDeviceInfo.cs" />
<Compile Include="Generic\ICoolerMasterRGBDevice.cs" />