diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index e04b70f19..8b5e5e92a 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -322,6 +322,7 @@ + @@ -695,6 +696,7 @@ Code + diff --git a/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProL.cs b/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProL.cs index e2e95528f..dbc939d47 100644 --- a/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProL.cs +++ b/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProL.cs @@ -58,7 +58,7 @@ namespace Artemis.DeviceProviders.CoolerMaster using (var b = ImageUtilities.ResizeImage(bitmap, Width, Height)) { // Create an empty matrix - var matrix = new COLOR_MATRIX {KeyColor = new KEY_COLOR[Height, Width]}; + var matrix = new COLOR_MATRIX {KeyColor = new KEY_COLOR[6, 22]}; // Map the bytes to the matix for (var x = 0; x < Width; x++) diff --git a/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProS.cs b/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProS.cs new file mode 100644 index 000000000..3b28d528e --- /dev/null +++ b/Artemis/Artemis/DeviceProviders/CoolerMaster/MasterkeysProS.cs @@ -0,0 +1,91 @@ +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 MasterkeysProS : KeyboardProvider + { + private GeneralSettings _generalSettings; + + public MasterkeysProS() + { + Name = "CM Masterkeys Pro S"; + Slug = "cm-masterkeys-pro-s"; + + CantEnableText = "Couldn't connect to your CM Masterkeys Pro S.\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 = 17; + + PreviewSettings = new PreviewSettings(683, 242, new Thickness(0, 0, 0, 0), Resources.masterkeys_pro_s); + _generalSettings = SettingsProvider.Load(); + } + + public override void Disable() + { + CmSdk.EnableLedControl(false); + Thread.Sleep(500); + } + + public override bool CanEnable() + { + CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_L); + + // Doesn't seem reliable but better than nothing I suppose + return CmSdk.IsDevicePlug(); + } + + public override void Enable() + { + CmSdk.SetControlDevice(DEVICE_INDEX.DEV_MKeys_S); + 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); + matrix.KeyColor[y, x] = new KEY_COLOR(c.R, c.G, c.B); + } + } + + // Send the matrix to the keyboard + 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); + } + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/InjectionModules/DeviceModules.cs b/Artemis/Artemis/InjectionModules/DeviceModules.cs index d250abf40..bc49d77bc 100644 --- a/Artemis/Artemis/InjectionModules/DeviceModules.cs +++ b/Artemis/Artemis/InjectionModules/DeviceModules.cs @@ -17,6 +17,7 @@ namespace Artemis.InjectionModules Bind().To().InSingletonScope(); Bind().To().InSingletonScope(); Bind().To().InSingletonScope(); + Bind().To().InSingletonScope(); // Mice Bind().To().InSingletonScope(); diff --git a/Artemis/Artemis/Properties/Resources.Designer.cs b/Artemis/Artemis/Properties/Resources.Designer.cs index 318b52e6b..467d52c81 100644 --- a/Artemis/Artemis/Properties/Resources.Designer.cs +++ b/Artemis/Artemis/Properties/Resources.Designer.cs @@ -338,6 +338,16 @@ namespace Artemis.Properties { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap masterkeys_pro_s { + get { + object obj = ResourceManager.GetObject("masterkeys_pro_s", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/Artemis/Artemis/Properties/Resources.resx b/Artemis/Artemis/Properties/Resources.resx index b2b934454..fe9b237c2 100644 --- a/Artemis/Artemis/Properties/Resources.resx +++ b/Artemis/Artemis/Properties/Resources.resx @@ -217,4 +217,7 @@ ..\Resources\Keyboards\masterkeys-pro-l.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 + \ No newline at end of file diff --git a/Artemis/Artemis/Resources/Keyboards/masterkeys-pro-s.png b/Artemis/Artemis/Resources/Keyboards/masterkeys-pro-s.png new file mode 100644 index 000000000..12ebf9a47 Binary files /dev/null and b/Artemis/Artemis/Resources/Keyboards/masterkeys-pro-s.png differ