diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index db4486bcd..1f6b22cd2 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -284,6 +284,7 @@ + diff --git a/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProM.cs b/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProM.cs new file mode 100644 index 000000000..580da1e0a --- /dev/null +++ b/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProM.cs @@ -0,0 +1,96 @@ +using System; +using System.Drawing; +using System.Linq; +using System.Threading; +using System.Windows; +using System.Windows.Forms; +using Artemis.DAL; +using Artemis.DeviceProviders.CoolerMaster.Utilities; +using Artemis.DeviceProviders.Logitech.Utilities; +using Artemis.Properties; +using Artemis.Settings; +using Artemis.Utilities; + +namespace Artemis.DeviceProviders.CoolerMaster +{ + public class MasterkeysProM : KeyboardProvider + { + private GeneralSettings _generalSettings; + + public MasterkeysProM() + { + Name = "CM Masterkeys Pro M"; + Slug = "cm-masterkeys-pro-m"; + + CantEnableText = "Couldn't connect to your CM Masterkeys Pro M.\n" + + "Please check your cables and try updating your CM software.\n\n" + + "If needed, you can select a different keyboard in Artemis under settings."; + + Height = 6; + Width = 19; + + PreviewSettings = new PreviewSettings(new Rect(11, 10, 634, 215), Resources.masterkeys_pro_m); + _generalSettings = SettingsProvider.Load(); + } + + public override void Disable() + { + CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_M); + CmSdk.EnableLedControl(false); + Thread.Sleep(500); + } + + public override bool CanEnable() + { + CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_M); + + // Doesn't seem reliable but better than nothing I suppose + return CmSdk.IsDevicePlug(); + } + + public override void Enable() + { + CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_M); + CmSdk.EnableLedControl(true); + } + + public override void DrawBitmap(Bitmap bitmap) + { + // Resize the bitmap + using (var b = ImageUtilities.ResizeImage(bitmap, Width, Height)) + { + // Create an empty matrix + var matrix = new COLOR_MATRIX {KeyColor = new KEY_COLOR[6, 22]}; + + // Map the bytes to the matix + for (var x = 0; x < Width; x++) + { + for (var y = 0; y < Height; y++) + { + var c = b.GetPixel(x, y); + if (c.R != 0) + Console.WriteLine(); + matrix.KeyColor[y, x] = new KEY_COLOR(c.R, c.G, c.B); + } + } + + // Send the matrix to the keyboard + CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_M); + CmSdk.SetAllLedColor(matrix); + } + } + + public override KeyMatch? GetKeyPosition(Keys keyCode) + { + switch (_generalSettings.Layout) + { + case "Qwerty": + return KeyMap.QwertyLayout.FirstOrDefault(k => k.KeyCode == keyCode); + case "Qwertz": + return KeyMap.QwertzLayout.FirstOrDefault(k => k.KeyCode == keyCode); + default: + return KeyMap.AzertyLayout.FirstOrDefault(k => k.KeyCode == keyCode); + } + } + } +} diff --git a/Artemis/Artemis/Properties/Resources.resx b/Artemis/Artemis/Properties/Resources.resx index 8518cab2e..9389819d1 100644 --- a/Artemis/Artemis/Properties/Resources.resx +++ b/Artemis/Artemis/Properties/Resources.resx @@ -220,6 +220,9 @@ ..\Resources\Keyboards\masterkeys-pro-s.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\Keyboards\masterkeys-pro-s.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\Keyboards\k95-platinum.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/Artemis/Artemis/Resources/Keyboards/default-profiles.zip b/Artemis/Artemis/Resources/Keyboards/default-profiles.zip index 7a0bb9f55..b61bb43d6 100644 Binary files a/Artemis/Artemis/Resources/Keyboards/default-profiles.zip and b/Artemis/Artemis/Resources/Keyboards/default-profiles.zip differ diff --git a/Artemis/Artemis/Resources/Keyboards/masterkeys-pro-m.png b/Artemis/Artemis/Resources/Keyboards/masterkeys-pro-m.png new file mode 100644 index 000000000..c3b2f87b4 Binary files /dev/null and b/Artemis/Artemis/Resources/Keyboards/masterkeys-pro-m.png differ