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

Added cm mouse support, removed update-overloads

This commit is contained in:
Darth Affe 2018-03-25 17:51:47 +02:00
parent 66d03cdf4f
commit c8a02b5f90
6 changed files with 79 additions and 29 deletions

View File

@ -117,6 +117,11 @@ namespace RGB.NET.Devices.CoolerMaster
CoolerMasterPhysicalKeyboardLayout physicalLayout = _CoolerMasterSDK.GetDeviceLayout();
device = new CoolerMasterKeyboardRGBDevice(new CoolerMasterKeyboardRGBDeviceInfo(index, physicalLayout, GetCulture()));
break;
case RGBDeviceType.Mouse:
device = new CoolerMasterMouseRGBDevice(new CoolerMasterMouseRGBDeviceInfo(index));
break;
default:
if (throwExceptions)
throw new RGBDeviceException("Unknown Device-Type");

View File

@ -1,7 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.CoolerMaster.Native;
namespace RGB.NET.Devices.CoolerMaster
{
@ -26,27 +24,6 @@ namespace RGB.NET.Devices.CoolerMaster
#region Methods
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
{
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
if (leds.Count > 0)
{
// 6 by 22 seems hard-coded but it's what the CM SDK expects regardless of keyboard size
_CoolerMasterColorMatrix colorMatrix = new _CoolerMasterColorMatrix { KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS] };
foreach (Led led in leds)
{
(int row, int column) = ((int, int))led.CustomData;
colorMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(led.Color.R, led.Color.G, led.Color.B);
}
_CoolerMasterSDK.SetControlDevice(DeviceInfo.DeviceIndex);
_CoolerMasterSDK.SetAllLedColor(colorMatrix);
_CoolerMasterSDK.RefreshLed(false);
}
}
/// <inheritdoc />
protected override void InitializeLayout()
{

View File

@ -20,18 +20,16 @@ namespace RGB.NET.Devices.CoolerMaster
{ CoolerMasterDevicesIndexes.MasterMouse_L, new Dictionary<LedId, (int row, int column)>
{
{ LedId.Mouse1, (0,0) },
{ LedId.Mouse2, (1,0) },
{ LedId.Mouse3, (2,0) },
{ LedId.Mouse4, (3,0) },
{ LedId.Mouse2, (0,1) },
{ LedId.Mouse3, (0,2) },
{ LedId.Mouse4, (0,3) }
}
},
{ CoolerMasterDevicesIndexes.MasterMouse_S, new Dictionary<LedId, (int row, int column)>
{
{ LedId.Mouse1, (0,0) },
{ LedId.Mouse2, (1,0) },
{ LedId.Mouse3, (2,0) },
{ LedId.Mouse4, (3,0) },
{ LedId.Mouse2, (0,1) }
}
},
};

View File

@ -0,0 +1,44 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.CoolerMaster
{
/// <inheritdoc />
/// <summary>
/// Represents a CoolerMaster mouse.
/// </summary>
public class CoolerMasterMouseRGBDevice : CoolerMasterRGBDevice<CoolerMasterMouseRGBDeviceInfo>
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by CoolerMaster for the mouse</param>
internal CoolerMasterMouseRGBDevice(CoolerMasterMouseRGBDeviceInfo info)
: base(info)
{ }
#endregion
#region Methods
/// <inheritdoc />
protected override void InitializeLayout()
{
Dictionary<LedId, (int row, int column)> mapping = CoolerMasterMouseLedMappings.Mapping[DeviceInfo.DeviceIndex];
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($@"Layouts\CoolerMaster\Mice\{model}.xml"), null);
}
/// <inheritdoc />
protected override object CreateLedCustomData(LedId ledId) => CoolerMasterMouseLedMappings.Mapping[DeviceInfo.DeviceIndex][ledId];
#endregion
}
}

View File

@ -0,0 +1,24 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.CoolerMaster
{
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDevice" />.
/// </summary>
public class CoolerMasterMouseRGBDeviceInfo : CoolerMasterRGBDeviceInfo
{
#region Constructors
/// <inheritdoc />
/// <summary>
/// Internal constructor of managed <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDeviceInfo" />.
/// </summary>
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.CoolerMaster.CoolerMasterMouseRGBDevice" />.</param>
internal CoolerMasterMouseRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex)
: base(RGBDeviceType.Mouse, deviceIndex)
{ }
#endregion
}
}

View File

@ -61,6 +61,8 @@
<Compile Include="Keyboard\CoolerMasterKeyboardRGBDevice.cs" />
<Compile Include="Keyboard\CoolerMasterKeyboardRGBDeviceInfo.cs" />
<Compile Include="Keyboard\CoolerMasterKeyboardLedMappings.cs" />
<Compile Include="Mouse\CoolerMasterMouseRGBDevice.cs" />
<Compile Include="Mouse\CoolerMasterMouseRGBDeviceInfo.cs" />
<Compile Include="Mouse\CoolerMasterMouseLedMappings.cs" />
<Compile Include="Native\_CoolerMasterColorMatrix.cs" />
<Compile Include="Native\_CoolerMasterSDK.cs" />