Added basic CoolerMaster support

This commit is contained in:
DarthAffe committed 2017-04-02 11:41:32 +02:00
1 parent 8446b9a47b
commit 8cc4688932
23 files changed
+1220 -2

No files matched your search

@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
namespace RGB.NET.Devices.CoolerMaster
{
/// <summary>
/// Contains all the hardware-id mappings for CoolerMaster devices.
/// </summary>
internal static class CoolerMasterKeyboardLedMappings
{
#region Properties & Fields
private static readonly Dictionary<CoolerMasterLedIds, Tuple<int, int>> MasterKeysL_US = new Dictionary<CoolerMasterLedIds, Tuple<int, int>>
{
{ CoolerMasterLedIds.A, new Tuple<int, int>(3,1) },
{ CoolerMasterLedIds.S, new Tuple<int, int>(3,2) },
{ CoolerMasterLedIds.D, new Tuple<int, int>(3,3) },
{ CoolerMasterLedIds.F, new Tuple<int, int>(3,4) },
};
private static readonly Dictionary<CoolerMasterLedIds, Tuple<int, int>> MasterKeysL_EU = new Dictionary<CoolerMasterLedIds, Tuple<int, int>>
{
{ CoolerMasterLedIds.A, new Tuple<int, int>(3,1) },
{ CoolerMasterLedIds.S, new Tuple<int, int>(3,2) },
{ CoolerMasterLedIds.D, new Tuple<int, int>(3,3) },
{ CoolerMasterLedIds.F, new Tuple<int, int>(3,4) },
};
private static readonly Dictionary<CoolerMasterLedIds, Tuple<int, int>> MasterKeysM_US = new Dictionary<CoolerMasterLedIds, Tuple<int, int>>
{
{ CoolerMasterLedIds.A, new Tuple<int, int>(3,1) },
{ CoolerMasterLedIds.S, new Tuple<int, int>(3,2) },
{ CoolerMasterLedIds.D, new Tuple<int, int>(3,3) },
{ CoolerMasterLedIds.F, new Tuple<int, int>(3,4) },
};
private static readonly Dictionary<CoolerMasterLedIds, Tuple<int, int>> MasterKeysM_EU = new Dictionary<CoolerMasterLedIds, Tuple<int, int>>
{
{ CoolerMasterLedIds.A, new Tuple<int, int>(3,1) },
{ CoolerMasterLedIds.S, new Tuple<int, int>(3,2) },
{ CoolerMasterLedIds.D, new Tuple<int, int>(3,3) },
{ CoolerMasterLedIds.F, new Tuple<int, int>(3,4) },
};
private static readonly Dictionary<CoolerMasterLedIds, Tuple<int, int>> MasterKeysS_US = new Dictionary<CoolerMasterLedIds, Tuple<int, int>>
{
{ CoolerMasterLedIds.A, new Tuple<int, int>(3,1) },
{ CoolerMasterLedIds.S, new Tuple<int, int>(3,2) },
{ CoolerMasterLedIds.D, new Tuple<int, int>(3,3) },
{ CoolerMasterLedIds.F, new Tuple<int, int>(3,4) },
};
private static readonly Dictionary<CoolerMasterLedIds, Tuple<int, int>> MasterKeysS_EU = new Dictionary<CoolerMasterLedIds, Tuple<int, int>>
{
{ CoolerMasterLedIds.A, new Tuple<int, int>(3,1) },
{ CoolerMasterLedIds.S, new Tuple<int, int>(3,2) },
{ CoolerMasterLedIds.D, new Tuple<int, int>(3,3) },
{ CoolerMasterLedIds.F, new Tuple<int, int>(3,4) },
};
/// <summary>
/// Contains all the hardware-id mappings for CoolerMaster devices.
/// </summary>
// ReSharper disable once InconsistentNaming
public static readonly Dictionary<CoolerMasterDevicesIndexes, Dictionary<CoolerMasterPhysicalKeyboardLayout, Dictionary<CoolerMasterLedIds, Tuple<int, int>>>> Mapping =
new Dictionary<CoolerMasterDevicesIndexes, Dictionary<CoolerMasterPhysicalKeyboardLayout, Dictionary<CoolerMasterLedIds, Tuple<int, int>>>>
{
{ CoolerMasterDevicesIndexes.MasterKeys_L, new Dictionary<CoolerMasterPhysicalKeyboardLayout, Dictionary<CoolerMasterLedIds, Tuple<int, int>>>
{
{ CoolerMasterPhysicalKeyboardLayout.US, MasterKeysL_US },
{ CoolerMasterPhysicalKeyboardLayout.EU, MasterKeysL_EU }
}
},
{ CoolerMasterDevicesIndexes.MasterKeys_M, new Dictionary<CoolerMasterPhysicalKeyboardLayout, Dictionary<CoolerMasterLedIds, Tuple<int, int>>>
{
{ CoolerMasterPhysicalKeyboardLayout.US, MasterKeysM_US },
{ CoolerMasterPhysicalKeyboardLayout.EU, MasterKeysM_EU }
}
},
{ CoolerMasterDevicesIndexes.MasterKeys_S, new Dictionary<CoolerMasterPhysicalKeyboardLayout, Dictionary<CoolerMasterLedIds, Tuple<int, int>>>
{
{ CoolerMasterPhysicalKeyboardLayout.US, MasterKeysS_US },
{ CoolerMasterPhysicalKeyboardLayout.EU, MasterKeysS_EU }
}
},
{ CoolerMasterDevicesIndexes.MasterKeys_L_White, new Dictionary<CoolerMasterPhysicalKeyboardLayout, Dictionary<CoolerMasterLedIds, Tuple<int, int>>>
{
{ CoolerMasterPhysicalKeyboardLayout.US, MasterKeysL_US },
{ CoolerMasterPhysicalKeyboardLayout.EU, MasterKeysL_EU }
}
},
{ CoolerMasterDevicesIndexes.MasterKeys_M_White, new Dictionary<CoolerMasterPhysicalKeyboardLayout, Dictionary<CoolerMasterLedIds, Tuple<int, int>>>
{
{ CoolerMasterPhysicalKeyboardLayout.US, MasterKeysM_US },
{ CoolerMasterPhysicalKeyboardLayout.EU, MasterKeysM_EU }
}
},
{ CoolerMasterDevicesIndexes.MasterKeys_S_White, new Dictionary<CoolerMasterPhysicalKeyboardLayout, Dictionary<CoolerMasterLedIds, Tuple<int, int>>>
{
{ CoolerMasterPhysicalKeyboardLayout.US, MasterKeysS_US },
{ CoolerMasterPhysicalKeyboardLayout.EU, MasterKeysS_EU }
}
},
};
#endregion
}
}
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.CoolerMaster.Helper;
namespace RGB.NET.Devices.CoolerMaster
{
/// <summary>
/// Represents a CoolerMaster keyboard.
/// </summary>
public class CoolerMasterKeyboardRGBDevice : CoolerMasterRGBDevice
{
#region Properties & Fields
/// <summary>
/// Gets information about the <see cref="CoolerMasterKeyboardRGBDevice"/>.
/// </summary>
public CoolerMasterKeyboardRGBDeviceInfo KeyboardDeviceInfo { get; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="CoolerMasterKeyboardRGBDevice"/> class.
/// </summary>
/// <param name="info">The specific information provided by CoolerMaster for the keyboard</param>
internal CoolerMasterKeyboardRGBDevice(CoolerMasterKeyboardRGBDeviceInfo info)
: base(info)
{
this.KeyboardDeviceInfo = info;
}
#endregion
#region Methods
/// <inheritdoc />
protected override void InitializeLayout()
{
Dictionary<CoolerMasterLedIds, Tuple<int, int>> mapping = CoolerMasterKeyboardLedMappings.Mapping[KeyboardDeviceInfo.DeviceIndex][KeyboardDeviceInfo.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));
string model = KeyboardDeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath(
$@"Layouts\CoolerMaster\Keyboards\{model}\{KeyboardDeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"),
KeyboardDeviceInfo.LogicalLayout.ToString(), PathHelper.GetAbsolutePath($@"Images\CoolerMaster\Keyboards"));
}
#endregion
}
}
@@ -0,0 +1,58 @@
using System;
using System.Globalization;
using RGB.NET.Core;
using RGB.NET.Devices.CoolerMaster.Helper;
namespace RGB.NET.Devices.CoolerMaster
{
/// <summary>
/// Represents a generic information for a <see cref="CoolerMasterKeyboardRGBDevice"/>.
/// </summary>
public class CoolerMasterKeyboardRGBDeviceInfo : CoolerMasterRGBDeviceInfo
{
#region Properties & Fields
/// <summary>
/// Gets the <see cref="CoolerMasterPhysicalKeyboardLayout"/> of the <see cref="CoolerMasterKeyboardRGBDevice"/>.
/// </summary>
public CoolerMasterPhysicalKeyboardLayout PhysicalLayout { get; private set; }
/// <summary>
/// Gets the <see cref="CoolerMasterLogicalKeyboardLayout"/> of the <see cref="CoolerMasterKeyboardRGBDevice"/>.
/// </summary>
public CoolerMasterLogicalKeyboardLayout LogicalLayout { get; private set; }
#endregion
#region Constructors
/// <summary>
/// Internal constructor of managed <see cref="CoolerMasterKeyboardRGBDeviceInfo"/>.
/// </summary>
/// <param name="deviceIndex">The index of the <see cref="CoolerMasterKeyboardRGBDevice"/>.</param>
/// <param name="physicalKeyboardLayout">The <see cref="CoolerMasterPhysicalKeyboardLayout" /> of the <see cref="CoolerMasterKeyboardRGBDevice"/>.</param>
/// <param name="culture">The <see cref="CultureInfo"/> of the layout this keyboard is using</param>
internal CoolerMasterKeyboardRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex, CoolerMasterPhysicalKeyboardLayout physicalKeyboardLayout, CultureInfo culture)
: base(RGBDeviceType.Keyboard, deviceIndex)
{
this.PhysicalLayout = physicalKeyboardLayout;
SetLayouts(culture.KeyboardLayoutId);
Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Logitech\Keyboards\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute);
}
private void SetLayouts(int keyboardLayoutId)
{
switch (keyboardLayoutId)
{
//TODO DarthAffe 02.04.2017: Check all available keyboards and there layout-ids
default:
LogicalLayout = CoolerMasterLogicalKeyboardLayout.DE;
break;
}
}
#endregion
}
}