From 3a18ce4a5a74271c4fc863a9ed581535dd8d77d1 Mon Sep 17 00:00:00 2001 From: Robert Beekman Date: Thu, 19 May 2016 23:21:34 +0200 Subject: [PATCH] Started work on Corsair mouse support --- Artemis/Artemis/Artemis.csproj | 21 +- Artemis/Artemis/DAL/ProfileProvider.cs | 2 +- .../DeviceProviders/Corsair/CorsairMice.cs | 74 +++ .../Corsair/CorsairRGB.cs | 242 ++++----- .../Artemis/DeviceProviders/DeviceProvider.cs | 30 ++ .../KeyboardProvider.cs | 131 +++-- .../Logitech/Orion.cs | 164 ++++--- .../Logitech/Utilities/KeyMap.cs | 272 +++++------ .../Logitech/Utilities/KeyboardNames.cs | 220 ++++----- .../Logitech/Utilities/LogitechGSDK.cs | 188 +++---- .../Logitech/Utilities/OrionUtilities.cs | 458 +++++++++--------- .../Razer/BlackWidow.cs | 96 ++-- .../Razer/Utilities/RazerUtilities.cs | 42 +- .../Artemis/Events/ActiveKeyboardChanged.cs | 2 +- .../InjectionModules/ArtemisModules.cs | 8 +- .../KeyboardProviders/KeyboardRegion.cs | 21 - Artemis/Artemis/Managers/KeyboardManager.cs | 2 +- .../Modules/Effects/TypeWave/TypeWaveModel.cs | 4 +- .../Utilities/Keyboard/KeyboardRectangle.cs | 2 +- .../ViewModels/ProfileEditorViewModel.cs | 2 +- 20 files changed, 1029 insertions(+), 952 deletions(-) create mode 100644 Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs rename Artemis/Artemis/{KeyboardProviders => DeviceProviders}/Corsair/CorsairRGB.cs (95%) create mode 100644 Artemis/Artemis/DeviceProviders/DeviceProvider.cs rename Artemis/Artemis/{KeyboardProviders => DeviceProviders}/KeyboardProvider.cs (84%) rename Artemis/Artemis/{KeyboardProviders => DeviceProviders}/Logitech/Orion.cs (92%) rename Artemis/Artemis/{KeyboardProviders => DeviceProviders}/Logitech/Utilities/KeyMap.cs (96%) rename Artemis/Artemis/{KeyboardProviders => DeviceProviders}/Logitech/Utilities/KeyboardNames.cs (93%) rename Artemis/Artemis/{KeyboardProviders => DeviceProviders}/Logitech/Utilities/LogitechGSDK.cs (97%) rename Artemis/Artemis/{KeyboardProviders => DeviceProviders}/Logitech/Utilities/OrionUtilities.cs (96%) rename Artemis/Artemis/{KeyboardProviders => DeviceProviders}/Razer/BlackWidow.cs (91%) rename Artemis/Artemis/{KeyboardProviders => DeviceProviders}/Razer/Utilities/RazerUtilities.cs (89%) delete mode 100644 Artemis/Artemis/KeyboardProviders/KeyboardRegion.cs diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 8666ec87a..33a68535c 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -278,22 +278,23 @@ + + - - - - - - - - - - + + + + + + + + + diff --git a/Artemis/Artemis/DAL/ProfileProvider.cs b/Artemis/Artemis/DAL/ProfileProvider.cs index 5d89fd42c..df35270f5 100644 --- a/Artemis/Artemis/DAL/ProfileProvider.cs +++ b/Artemis/Artemis/DAL/ProfileProvider.cs @@ -4,7 +4,7 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Xml.Serialization; -using Artemis.KeyboardProviders; +using Artemis.DeviceProviders; using Artemis.Models; using Artemis.Models.Profiles; diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs new file mode 100644 index 000000000..1e2b9d57a --- /dev/null +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs @@ -0,0 +1,74 @@ +using System.Threading; +using System.Windows.Media; +using CUE.NET; +using CUE.NET.Devices.Generic.Enums; +using CUE.NET.Devices.Mouse; +using CUE.NET.Exceptions; + +namespace Artemis.DeviceProviders.Corsair +{ + internal class CorsairMice : DeviceProvider + { + private readonly CorsairRGB _corsairRgb; + private CorsairMouse _mouse; + + public CorsairMice(CorsairRGB corsairRgb) + { + _corsairRgb = corsairRgb; + UpdateCanUse(); + } + + private void UpdateCanUse() + { + if (!CanInitializeSdk()) + { + CanUse = false; + return; + } + + if (CueSDK.ProtocolDetails == null) + CueSDK.Initialize(true); + + _mouse = CueSDK.MouseSDK; + + } + + private static bool CanInitializeSdk() + { + // Try for about 10 seconds, in case CUE isn't started yet + var tries = 0; + while (tries < 9) + { + try + { + if (CueSDK.ProtocolDetails == null) + CueSDK.Initialize(); + } + catch (CUEException e) + { + if (e.Error == CorsairError.ServerNotFound) + { + tries++; + Thread.Sleep(1000); + continue; + } + } + catch (WrapperException) + { + CueSDK.Reinitialize(); + return true; + } + + return true; + } + + return false; + } + + public override void UpdateDevice(Brush brush) + { + if (!CanUse) + return; + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Corsair/CorsairRGB.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs similarity index 95% rename from Artemis/Artemis/KeyboardProviders/Corsair/CorsairRGB.cs rename to Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs index ccd01ceb4..cb2ff1e65 100644 --- a/Artemis/Artemis/KeyboardProviders/Corsair/CorsairRGB.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs @@ -1,122 +1,122 @@ -using System.Drawing; -using System.Threading; -using System.Windows; -using Artemis.Properties; -using Artemis.Utilities; -using CUE.NET; -using CUE.NET.Brushes; -using CUE.NET.Devices.Generic.Enums; -using CUE.NET.Devices.Keyboard; -using CUE.NET.Exceptions; - -namespace Artemis.KeyboardProviders.Corsair -{ - public class CorsairRGB : KeyboardProvider - { - private CorsairKeyboard _keyboard; - - public CorsairRGB() - { - Name = "Corsair RGB Keyboards"; - CantEnableText = "Couldn't connect to your Corsair keyboard.\n" + - "Please check your cables and/or drivers (could be outdated) and that Corsair Utility Engine is running.\n" + - "In CUE, make sure \"Enable SDK\" is checked under Settings > Program.\n\n" + - "If needed, you can select a different keyboard in Artemis under settings."; - } - - public override bool CanEnable() - { - // Try for about 10 seconds, in case CUE isn't started yet - var tries = 0; - while (tries < 9) - { - try - { - if (CueSDK.ProtocolDetails == null) - CueSDK.Initialize(); - } - catch (CUEException e) - { - if (e.Error == CorsairError.ServerNotFound) - { - tries++; - Thread.Sleep(1000); - continue; - } - } - catch (WrapperException) - { - CueSDK.Reinitialize(); - return true; - } - - return true; - } - - return false; - } - - /// - /// Enables the SDK and sets updatemode to manual as well as the color of the background to black. - /// - public override void Enable() - { - try - { - if (CueSDK.ProtocolDetails == null) - CueSDK.Initialize(true); - } - catch (WrapperException) - { - /*CUE is already initialized*/ - } - _keyboard = CueSDK.KeyboardSDK; - if (_keyboard.DeviceInfo.Model == "K95 RGB") - { - Height = 7; - Width = 25; - PreviewSettings = new PreviewSettings(626, 175, new Thickness(0, -15, 0, 0), Resources.k95); - } - else if (_keyboard.DeviceInfo.Model == "K70 RGB") - { - Height = 7; - Width = 21; - PreviewSettings = new PreviewSettings(626, 195, new Thickness(0, -25, 0, 0), Resources.k70); - } - else if (_keyboard.DeviceInfo.Model == "K65 RGB") - { - Height = 7; - Width = 18; - PreviewSettings = new PreviewSettings(610, 240, new Thickness(0, -30, 0, 0), Resources.k65); - } - else if (_keyboard.DeviceInfo.Model == "STRAFE RGB") - { - Height = 6; - Width = 22; - PreviewSettings = new PreviewSettings(620, 215, new Thickness(0, -15, 0, 0), Resources.strafe); - } - } - - public override void Disable() - { - CueSDK.Reinitialize(); - } - - /// - /// Properly resizes any size bitmap to the keyboard by creating a rectangle whose size is dependent on the bitmap - /// size. - /// - /// - public override void DrawBitmap(Bitmap bitmap) - { - var image = ImageUtilities.ResizeImage(bitmap, Width, Height); - var brush = new ImageBrush - { - Image = image - }; - - _keyboard.Brush = brush; - _keyboard.Update(); - } - } +using System.Drawing; +using System.Threading; +using System.Windows; +using Artemis.Properties; +using Artemis.Utilities; +using CUE.NET; +using CUE.NET.Brushes; +using CUE.NET.Devices.Generic.Enums; +using CUE.NET.Devices.Keyboard; +using CUE.NET.Exceptions; + +namespace Artemis.DeviceProviders.Corsair +{ + public class CorsairRGB : KeyboardProvider + { + private CorsairKeyboard _keyboard; + + public CorsairRGB() + { + Name = "Corsair RGB Keyboards"; + CantEnableText = "Couldn't connect to your Corsair keyboard.\n" + + "Please check your cables and/or drivers (could be outdated) and that Corsair Utility Engine is running.\n" + + "In CUE, make sure \"Enable SDK\" is checked under Settings > Program.\n\n" + + "If needed, you can select a different keyboard in Artemis under settings."; + } + + public override bool CanEnable() + { + // Try for about 10 seconds, in case CUE isn't started yet + var tries = 0; + while (tries < 9) + { + try + { + if (CueSDK.ProtocolDetails == null) + CueSDK.Initialize(); + } + catch (CUEException e) + { + if (e.Error == CorsairError.ServerNotFound) + { + tries++; + Thread.Sleep(1000); + continue; + } + } + catch (WrapperException) + { + CueSDK.Reinitialize(); + return true; + } + + return true; + } + + return false; + } + + /// + /// Enables the SDK and sets updatemode to manual as well as the color of the background to black. + /// + public override void Enable() + { + try + { + if (CueSDK.ProtocolDetails == null) + CueSDK.Initialize(true); + } + catch (WrapperException) + { + /*CUE is already initialized*/ + } + _keyboard = CueSDK.KeyboardSDK; + if (_keyboard.DeviceInfo.Model == "K95 RGB") + { + Height = 7; + Width = 25; + PreviewSettings = new PreviewSettings(626, 175, new Thickness(0, -15, 0, 0), Resources.k95); + } + else if (_keyboard.DeviceInfo.Model == "K70 RGB") + { + Height = 7; + Width = 21; + PreviewSettings = new PreviewSettings(626, 195, new Thickness(0, -25, 0, 0), Resources.k70); + } + else if (_keyboard.DeviceInfo.Model == "K65 RGB") + { + Height = 7; + Width = 18; + PreviewSettings = new PreviewSettings(610, 240, new Thickness(0, -30, 0, 0), Resources.k65); + } + else if (_keyboard.DeviceInfo.Model == "STRAFE RGB") + { + Height = 6; + Width = 22; + PreviewSettings = new PreviewSettings(620, 215, new Thickness(0, -15, 0, 0), Resources.strafe); + } + } + + public override void Disable() + { + CueSDK.Reinitialize(); + } + + /// + /// Properly resizes any size bitmap to the keyboard by creating a rectangle whose size is dependent on the bitmap + /// size. + /// + /// + public override void DrawBitmap(Bitmap bitmap) + { + var image = ImageUtilities.ResizeImage(bitmap, Width, Height); + var brush = new ImageBrush + { + Image = image + }; + + _keyboard.Brush = brush; + _keyboard.Update(); + } + } } \ No newline at end of file diff --git a/Artemis/Artemis/DeviceProviders/DeviceProvider.cs b/Artemis/Artemis/DeviceProviders/DeviceProvider.cs new file mode 100644 index 000000000..e2849d405 --- /dev/null +++ b/Artemis/Artemis/DeviceProviders/DeviceProvider.cs @@ -0,0 +1,30 @@ +using System.Windows.Media; + +namespace Artemis.DeviceProviders +{ + public abstract class DeviceProvider + { + /// + /// Indicates the device type + /// + public DeviceType Type { get; set; } + + /// + /// Indicates whether or not the device can be updated + /// + public bool CanUse { get; set; } + + /// + /// Updates a non-keyboard to take the colours of the provided brush + /// + /// + public abstract void UpdateDevice(Brush brush); + } + + public enum DeviceType + { + Keyboard, + Mouse, + Headset + } +} \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/KeyboardProvider.cs b/Artemis/Artemis/DeviceProviders/KeyboardProvider.cs similarity index 84% rename from Artemis/Artemis/KeyboardProviders/KeyboardProvider.cs rename to Artemis/Artemis/DeviceProviders/KeyboardProvider.cs index 0e28f4ccb..80ed57dce 100644 --- a/Artemis/Artemis/KeyboardProviders/KeyboardProvider.cs +++ b/Artemis/Artemis/DeviceProviders/KeyboardProvider.cs @@ -1,69 +1,64 @@ -using System.Drawing; -using System.Windows; -using Size = System.Windows.Size; - -namespace Artemis.KeyboardProviders -{ - public abstract class KeyboardProvider : DeviceProvider - { - protected KeyboardProvider() - { - Type = DeviceType.Keyboard; - } - - public string Name { get; set; } - public int Height { get; set; } - public int Width { get; set; } - public string CantEnableText { get; set; } - - public PreviewSettings PreviewSettings { get; set; } - - public abstract bool CanEnable(); - public abstract void Enable(); - // TODO: This should be done in a background thread with a callback mechanism as it causes UI lag - public abstract void Disable(); - public abstract void DrawBitmap(Bitmap bitmap); - - /// - /// Returns a bitmap matching the keyboard's dimensions - /// - /// - public Bitmap KeyboardBitmap() => new Bitmap(Width, Height); - - /// - /// Returns a bitmap matching the keyboard's dimensions using the provided scale - /// - /// - public Bitmap KeyboardBitmap(int scale) => new Bitmap(Width*scale, Height*scale); - - public Rect KeyboardRectangle(int scale) => new Rect(new Size(Width*scale, Height*scale)); - } - - public class DeviceProvider - { - public DeviceType Type { get; set; } - } - - public enum DeviceType - { - Keyboard, - Mouse, - Headset - } - - public struct PreviewSettings - { - public int Width { get; set; } - public int Height { get; set; } - public Thickness Margin { get; set; } - public Bitmap Image { get; set; } - - public PreviewSettings(int width, int height, Thickness margin, Bitmap image) - { - Width = width; - Height = height; - Margin = margin; - Image = image; - } - } +using System; +using System.Drawing; +using System.Windows; +using Brush = System.Windows.Media.Brush; +using Size = System.Windows.Size; + +namespace Artemis.DeviceProviders +{ + public abstract class KeyboardProvider : DeviceProvider + { + protected KeyboardProvider() + { + Type = DeviceType.Keyboard; + } + + public string Name { get; set; } + public int Height { get; set; } + public int Width { get; set; } + public string CantEnableText { get; set; } + + public PreviewSettings PreviewSettings { get; set; } + + public abstract bool CanEnable(); + public abstract void Enable(); + // TODO: This should be done in a background thread with a callback mechanism as it causes UI lag + public abstract void Disable(); + public abstract void DrawBitmap(Bitmap bitmap); + + /// + /// Returns a bitmap matching the keyboard's dimensions + /// + /// + public Bitmap KeyboardBitmap() => new Bitmap(Width, Height); + + /// + /// Returns a bitmap matching the keyboard's dimensions using the provided scale + /// + /// + public Bitmap KeyboardBitmap(int scale) => new Bitmap(Width*scale, Height*scale); + + public Rect KeyboardRectangle(int scale) => new Rect(new Size(Width*scale, Height*scale)); + + public override void UpdateDevice(Brush brush) + { + throw new NotImplementedException("KeyboardProvider doesn't implement UpdateDevice, use DrawBitmap instead."); + } + } + + public struct PreviewSettings + { + public int Width { get; set; } + public int Height { get; set; } + public Thickness Margin { get; set; } + public Bitmap Image { get; set; } + + public PreviewSettings(int width, int height, Thickness margin, Bitmap image) + { + Width = width; + Height = height; + Margin = margin; + Image = image; + } + } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs b/Artemis/Artemis/DeviceProviders/Logitech/Orion.cs similarity index 92% rename from Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs rename to Artemis/Artemis/DeviceProviders/Logitech/Orion.cs index e66c9d8e1..55ab6b0c3 100644 --- a/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/Orion.cs @@ -1,84 +1,82 @@ -using System.Collections.Generic; -using System.Drawing; -using System.Threading; -using System.Windows; -using Artemis.KeyboardProviders.Logitech.Utilities; -using Artemis.Properties; -using Artemis.Utilities; -using Point = System.Drawing.Point; - -namespace Artemis.KeyboardProviders.Logitech -{ - internal class Orion : KeyboardProvider - { - public Orion() - { - Name = "Logitech G910 RGB"; - CantEnableText = "Couldn't connect to your Logitech G910.\n" + - "Please check your cables and updating the Logitech Gaming Software\n" + - "A minimum version of 8.81.15 is required.\n\n" + - "If needed, you can select a different keyboard in Artemis under settings."; - Height = 6; - Width = 21; - PreviewSettings = new PreviewSettings(540, 154, new Thickness(25, -80, 0, 0), Resources.g910); - } - - public override bool CanEnable() - { - //if (DllManager.RestoreDll()) - // RestoreDll(); - int majorNum = 0, minorNum = 0, buildNum = 0; - - LogitechGSDK.LogiLedInit(); - LogitechGSDK.LogiLedGetSdkVersion(ref majorNum, ref minorNum, ref buildNum); - LogitechGSDK.LogiLedShutdown(); - - // Turn it into one long number... - var version = int.Parse($"{majorNum}{minorNum}{buildNum}"); - CantEnableText = "Couldn't connect to your Logitech G910.\n" + - "Please check your cables and updating the Logitech Gaming Software\n" + - $"A minimum version of 8.81.15 is required (detected {majorNum}.{minorNum}.{buildNum}).\n\n" + - "If the detected version differs from the version LGS is reporting, reinstall LGS or see the FAQ.\n\n" + - "If needed, you can select a different keyboard in Artemis under settings."; - - return version >= 88115; - } - - private void RestoreDll() - { - MessageBox.Show( - "Artemis couldn't enable your Logitech keyboard, because the required files are not in place.\n\n" + - "This happens when you run The Division and shut down Artemis before shutting down The Division\n" + - "It can be fixed automatically by clicking OK, but to avoid this message in the future please\n" + - "shut down The Division before shutting down Artemis.\n\n" + - "Click OK to fix the issue and restart Artemis"); - - GeneralHelpers.RunAsAdministrator(); - } - - public override void Enable() - { - // Initialize the SDK - LogitechGSDK.LogiLedInit(); - Thread.Sleep(200); - - LogitechGSDK.LogiLedSaveCurrentLighting(); - LogitechGSDK.LogiLedSetTargetDevice(LogitechGSDK.LOGI_DEVICETYPE_PERKEY_RGB); - - // Disable keys we can't color - LogitechGSDK.LogiLedSetLighting(0, 0, 0); - } - - public override void Disable() - { - // Shutdown the SDK - LogitechGSDK.LogiLedRestoreLighting(); - LogitechGSDK.LogiLedShutdown(); - } - - public override void DrawBitmap(Bitmap bitmap) - { - LogitechGSDK.LogiLedSetLightingFromBitmap(OrionUtilities.BitmapToByteArray(bitmap)); - } - } +using System.Drawing; +using System.Threading; +using System.Windows; +using Artemis.DeviceProviders.Logitech.Utilities; +using Artemis.Properties; +using Artemis.Utilities; + +namespace Artemis.DeviceProviders.Logitech +{ + internal class Orion : KeyboardProvider + { + public Orion() + { + Name = "Logitech G910 RGB"; + CantEnableText = "Couldn't connect to your Logitech G910.\n" + + "Please check your cables and updating the Logitech Gaming Software\n" + + "A minimum version of 8.81.15 is required.\n\n" + + "If needed, you can select a different keyboard in Artemis under settings."; + Height = 6; + Width = 21; + PreviewSettings = new PreviewSettings(540, 154, new Thickness(25, -80, 0, 0), Resources.g910); + } + + public override bool CanEnable() + { + //if (DllManager.RestoreDll()) + // RestoreDll(); + int majorNum = 0, minorNum = 0, buildNum = 0; + + LogitechGSDK.LogiLedInit(); + LogitechGSDK.LogiLedGetSdkVersion(ref majorNum, ref minorNum, ref buildNum); + LogitechGSDK.LogiLedShutdown(); + + // Turn it into one long number... + var version = int.Parse($"{majorNum}{minorNum}{buildNum}"); + CantEnableText = "Couldn't connect to your Logitech G910.\n" + + "Please check your cables and updating the Logitech Gaming Software\n" + + $"A minimum version of 8.81.15 is required (detected {majorNum}.{minorNum}.{buildNum}).\n\n" + + "If the detected version differs from the version LGS is reporting, reinstall LGS or see the FAQ.\n\n" + + "If needed, you can select a different keyboard in Artemis under settings."; + + return version >= 88115; + } + + private void RestoreDll() + { + MessageBox.Show( + "Artemis couldn't enable your Logitech keyboard, because the required files are not in place.\n\n" + + "This happens when you run The Division and shut down Artemis before shutting down The Division\n" + + "It can be fixed automatically by clicking OK, but to avoid this message in the future please\n" + + "shut down The Division before shutting down Artemis.\n\n" + + "Click OK to fix the issue and restart Artemis"); + + GeneralHelpers.RunAsAdministrator(); + } + + public override void Enable() + { + // Initialize the SDK + LogitechGSDK.LogiLedInit(); + Thread.Sleep(200); + + LogitechGSDK.LogiLedSaveCurrentLighting(); + LogitechGSDK.LogiLedSetTargetDevice(LogitechGSDK.LOGI_DEVICETYPE_PERKEY_RGB); + + // Disable keys we can't color + LogitechGSDK.LogiLedSetLighting(0, 0, 0); + } + + public override void Disable() + { + // Shutdown the SDK + LogitechGSDK.LogiLedRestoreLighting(); + LogitechGSDK.LogiLedShutdown(); + } + + public override void DrawBitmap(Bitmap bitmap) + { + LogitechGSDK.LogiLedSetLightingFromBitmap(OrionUtilities.BitmapToByteArray(bitmap)); + } + } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/KeyMap.cs b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/KeyMap.cs similarity index 96% rename from Artemis/Artemis/KeyboardProviders/Logitech/Utilities/KeyMap.cs rename to Artemis/Artemis/DeviceProviders/Logitech/Utilities/KeyMap.cs index d3d6f687a..f5ca002fc 100644 --- a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/KeyMap.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/KeyMap.cs @@ -1,137 +1,137 @@ -using System.Collections.Generic; -using System.Windows.Forms; -using Artemis.Utilities.Keyboard; - -namespace Artemis.KeyboardProviders.Logitech.Utilities -{ - public static class KeyMap - { - static KeyMap() - { - // There are several keyboard layouts - // TODO: Implemented more layouts and an option to select them - UsEnglishOrionKeys = new List - { - // Row 1 - new Key(Keys.Escape, 0, 0), - new Key(Keys.F1, 1, 0), - new Key(Keys.F2, 2, 0), - new Key(Keys.F3, 3, 0), - new Key(Keys.F4, 4, 0), - new Key(Keys.F5, 5, 0), - new Key(Keys.F6, 6, 0), - new Key(Keys.F7, 7, 0), - new Key(Keys.F8, 8, 0), - new Key(Keys.F9, 9, 0), - new Key(Keys.F10, 10, 0), - new Key(Keys.F11, 11, 0), - new Key(Keys.F12, 12, 0), - new Key(Keys.PrintScreen, 13, 0), - new Key(Keys.Scroll, 14, 0), - new Key(Keys.Pause, 15, 0), - - // Row 2 - new Key(Keys.Oemtilde, 0, 1), - new Key(Keys.D1, 1, 1), - new Key(Keys.D2, 2, 1), - new Key(Keys.D3, 3, 1), - new Key(Keys.D4, 4, 1), - new Key(Keys.D5, 5, 1), - new Key(Keys.D6, 6, 1), - new Key(Keys.D7, 7, 1), - new Key(Keys.D8, 8, 1), - new Key(Keys.D9, 9, 1), - new Key(Keys.D0, 10, 1), - new Key(Keys.OemMinus, 11, 1), - new Key(Keys.Oemplus, 12, 1), - new Key(Keys.Back, 13, 1), - new Key(Keys.Insert, 14, 1), - new Key(Keys.Home, 15, 1), - new Key(Keys.PageUp, 16, 1), - new Key(Keys.NumLock, 17, 1), - new Key(Keys.Divide, 18, 1), - new Key(Keys.Multiply, 19, 1), - new Key(Keys.Subtract, 20, 1), - - // Row 3 - new Key(Keys.Tab, 0, 2), - new Key(Keys.Q, 1, 2), - new Key(Keys.W, 2, 2), - new Key(Keys.E, 3, 2), - new Key(Keys.R, 4, 2), - new Key(Keys.T, 5, 2), - new Key(Keys.Y, 6, 2), - new Key(Keys.U, 7, 2), - new Key(Keys.I, 8, 2), - new Key(Keys.O, 9, 2), - new Key(Keys.P, 10, 2), - new Key(Keys.OemOpenBrackets, 11, 2), - new Key(Keys.Oem6, 12, 2), - new Key(Keys.Delete, 14, 2), - new Key(Keys.End, 15, 2), - new Key(Keys.Next, 16, 2), - new Key(Keys.NumPad7, 17, 2), - new Key(Keys.NumPad8, 18, 2), - new Key(Keys.NumPad9, 19, 2), - new Key(Keys.Add, 20, 2), - - // Row 4 - new Key(Keys.Capital, 0, 3), - new Key(Keys.A, 1, 3), - new Key(Keys.S, 2, 3), - new Key(Keys.D, 3, 3), - new Key(Keys.F, 4, 3), - new Key(Keys.G, 5, 3), - new Key(Keys.H, 6, 3), - new Key(Keys.J, 7, 3), - new Key(Keys.K, 8, 3), - new Key(Keys.L, 9, 3), - new Key(Keys.Oem1, 10, 3), - new Key(Keys.Oem7, 11, 3), - new Key(Keys.Oem5, 12, 3), - new Key(Keys.Return, 13, 3), - new Key(Keys.NumPad4, 17, 3), - new Key(Keys.NumPad5, 18, 3), - new Key(Keys.NumPad6, 19, 3), - - // Row 5 - new Key(Keys.LShiftKey, 1, 4), - new Key(Keys.OemBackslash, 2, 4), - new Key(Keys.Z, 2, 4), - new Key(Keys.X, 3, 4), - new Key(Keys.C, 4, 4), - new Key(Keys.V, 5, 4), - new Key(Keys.B, 6, 4), - new Key(Keys.N, 7, 4), - new Key(Keys.M, 8, 4), - new Key(Keys.Oemcomma, 9, 4), - new Key(Keys.OemPeriod, 10, 4), - new Key(Keys.OemQuestion, 11, 4), - new Key(Keys.RShiftKey, 13, 4), - new Key(Keys.Up, 15, 4), - new Key(Keys.NumPad1, 17, 4), - new Key(Keys.NumPad2, 18, 4), - new Key(Keys.NumPad3, 19, 4), - // Both returns return "Return" (Yes...) - // new OrionKey(System.Windows.Forms.Keys.Return, 20, 4), - - // Row 6 - new Key(Keys.LControlKey, 0, 5), - new Key(Keys.LWin, 1, 5), - new Key(Keys.LMenu, 2, 5), - new Key(Keys.Space, 5, 5), - new Key(Keys.RMenu, 11, 5), - new Key(Keys.RWin, 12, 5), - new Key(Keys.Apps, 13, 5), - new Key(Keys.RControlKey, 14, 5), - new Key(Keys.Left, 15, 5), - new Key(Keys.Down, 16, 5), - new Key(Keys.Right, 17, 5), - new Key(Keys.NumPad0, 18, 5), - new Key(Keys.Decimal, 19, 5) - }; - } - - public static List UsEnglishOrionKeys { get; set; } - } +using System.Collections.Generic; +using System.Windows.Forms; +using Artemis.Utilities.Keyboard; + +namespace Artemis.DeviceProviders.Logitech.Utilities +{ + public static class KeyMap + { + static KeyMap() + { + // There are several keyboard layouts + // TODO: Implemented more layouts and an option to select them + UsEnglishOrionKeys = new List + { + // Row 1 + new Key(Keys.Escape, 0, 0), + new Key(Keys.F1, 1, 0), + new Key(Keys.F2, 2, 0), + new Key(Keys.F3, 3, 0), + new Key(Keys.F4, 4, 0), + new Key(Keys.F5, 5, 0), + new Key(Keys.F6, 6, 0), + new Key(Keys.F7, 7, 0), + new Key(Keys.F8, 8, 0), + new Key(Keys.F9, 9, 0), + new Key(Keys.F10, 10, 0), + new Key(Keys.F11, 11, 0), + new Key(Keys.F12, 12, 0), + new Key(Keys.PrintScreen, 13, 0), + new Key(Keys.Scroll, 14, 0), + new Key(Keys.Pause, 15, 0), + + // Row 2 + new Key(Keys.Oemtilde, 0, 1), + new Key(Keys.D1, 1, 1), + new Key(Keys.D2, 2, 1), + new Key(Keys.D3, 3, 1), + new Key(Keys.D4, 4, 1), + new Key(Keys.D5, 5, 1), + new Key(Keys.D6, 6, 1), + new Key(Keys.D7, 7, 1), + new Key(Keys.D8, 8, 1), + new Key(Keys.D9, 9, 1), + new Key(Keys.D0, 10, 1), + new Key(Keys.OemMinus, 11, 1), + new Key(Keys.Oemplus, 12, 1), + new Key(Keys.Back, 13, 1), + new Key(Keys.Insert, 14, 1), + new Key(Keys.Home, 15, 1), + new Key(Keys.PageUp, 16, 1), + new Key(Keys.NumLock, 17, 1), + new Key(Keys.Divide, 18, 1), + new Key(Keys.Multiply, 19, 1), + new Key(Keys.Subtract, 20, 1), + + // Row 3 + new Key(Keys.Tab, 0, 2), + new Key(Keys.Q, 1, 2), + new Key(Keys.W, 2, 2), + new Key(Keys.E, 3, 2), + new Key(Keys.R, 4, 2), + new Key(Keys.T, 5, 2), + new Key(Keys.Y, 6, 2), + new Key(Keys.U, 7, 2), + new Key(Keys.I, 8, 2), + new Key(Keys.O, 9, 2), + new Key(Keys.P, 10, 2), + new Key(Keys.OemOpenBrackets, 11, 2), + new Key(Keys.Oem6, 12, 2), + new Key(Keys.Delete, 14, 2), + new Key(Keys.End, 15, 2), + new Key(Keys.Next, 16, 2), + new Key(Keys.NumPad7, 17, 2), + new Key(Keys.NumPad8, 18, 2), + new Key(Keys.NumPad9, 19, 2), + new Key(Keys.Add, 20, 2), + + // Row 4 + new Key(Keys.Capital, 0, 3), + new Key(Keys.A, 1, 3), + new Key(Keys.S, 2, 3), + new Key(Keys.D, 3, 3), + new Key(Keys.F, 4, 3), + new Key(Keys.G, 5, 3), + new Key(Keys.H, 6, 3), + new Key(Keys.J, 7, 3), + new Key(Keys.K, 8, 3), + new Key(Keys.L, 9, 3), + new Key(Keys.Oem1, 10, 3), + new Key(Keys.Oem7, 11, 3), + new Key(Keys.Oem5, 12, 3), + new Key(Keys.Return, 13, 3), + new Key(Keys.NumPad4, 17, 3), + new Key(Keys.NumPad5, 18, 3), + new Key(Keys.NumPad6, 19, 3), + + // Row 5 + new Key(Keys.LShiftKey, 1, 4), + new Key(Keys.OemBackslash, 2, 4), + new Key(Keys.Z, 2, 4), + new Key(Keys.X, 3, 4), + new Key(Keys.C, 4, 4), + new Key(Keys.V, 5, 4), + new Key(Keys.B, 6, 4), + new Key(Keys.N, 7, 4), + new Key(Keys.M, 8, 4), + new Key(Keys.Oemcomma, 9, 4), + new Key(Keys.OemPeriod, 10, 4), + new Key(Keys.OemQuestion, 11, 4), + new Key(Keys.RShiftKey, 13, 4), + new Key(Keys.Up, 15, 4), + new Key(Keys.NumPad1, 17, 4), + new Key(Keys.NumPad2, 18, 4), + new Key(Keys.NumPad3, 19, 4), + // Both returns return "Return" (Yes...) + // new OrionKey(System.Windows.Forms.Keys.Return, 20, 4), + + // Row 6 + new Key(Keys.LControlKey, 0, 5), + new Key(Keys.LWin, 1, 5), + new Key(Keys.LMenu, 2, 5), + new Key(Keys.Space, 5, 5), + new Key(Keys.RMenu, 11, 5), + new Key(Keys.RWin, 12, 5), + new Key(Keys.Apps, 13, 5), + new Key(Keys.RControlKey, 14, 5), + new Key(Keys.Left, 15, 5), + new Key(Keys.Down, 16, 5), + new Key(Keys.Right, 17, 5), + new Key(Keys.NumPad0, 18, 5), + new Key(Keys.Decimal, 19, 5) + }; + } + + public static List UsEnglishOrionKeys { get; set; } + } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/KeyboardNames.cs b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/KeyboardNames.cs similarity index 93% rename from Artemis/Artemis/KeyboardProviders/Logitech/Utilities/KeyboardNames.cs rename to Artemis/Artemis/DeviceProviders/Logitech/Utilities/KeyboardNames.cs index e2efcd880..78f96b177 100644 --- a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/KeyboardNames.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/KeyboardNames.cs @@ -1,111 +1,111 @@ -namespace Artemis.KeyboardProviders.Logitech.Utilities -{ - public enum KeyboardNames - { - ESC = 0x01, - F1 = 0x3b, - F2 = 0x3c, - F3 = 0x3d, - F4 = 0x3e, - F5 = 0x3f, - F6 = 0x40, - F7 = 0x41, - F8 = 0x42, - F9 = 0x43, - F10 = 0x44, - F11 = 0x57, - F12 = 0x58, - PRINT_SCREEN = 0x137, - SCROLL_LOCK = 0x46, - PAUSE_BREAK = 0x45, - TILDE = 0x29, - ONE = 0x02, - TWO = 0x03, - THREE = 0x04, - FOUR = 0x05, - FIVE = 0x06, - SIX = 0x07, - SEVEN = 0x08, - EIGHT = 0x09, - NINE = 0x0A, - ZERO = 0x0B, - MINUS = 0x0C, - EQUALS = 0x0D, - BACKSPACE = 0x0E, - INSERT = 0x152, - HOME = 0x147, - PAGE_UP = 0x149, - NUM_LOCK = 0x145, - NUM_SLASH = 0x135, - NUM_ASTERISK = 0x37, - NUM_MINUS = 0x4A, - TAB = 0x0F, - Q = 0x10, - W = 0x11, - E = 0x12, - R = 0x13, - T = 0x14, - Y = 0x15, - U = 0x16, - I = 0x17, - O = 0x18, - P = 0x19, - OPEN_BRACKET = 0x1A, - CLOSE_BRACKET = 0x1B, - BACKSLASH = 0x2B, - KEYBOARD_DELETE = 0x153, - END = 0x14F, - PAGE_DOWN = 0x151, - NUM_SEVEN = 0x47, - NUM_EIGHT = 0x48, - NUM_NINE = 0x49, - NUM_PLUS = 0x4E, - CAPS_LOCK = 0x3A, - A = 0x1E, - S = 0x1F, - D = 0x20, - F = 0x21, - G = 0x22, - H = 0x23, - J = 0x24, - K = 0x25, - L = 0x26, - SEMICOLON = 0x27, - APOSTROPHE = 0x28, - ENTER = 0x1C, - NUM_FOUR = 0x4B, - NUM_FIVE = 0x4C, - NUM_SIX = 0x4D, - LEFT_SHIFT = 0x2A, - Z = 0x2C, - X = 0x2D, - C = 0x2E, - V = 0x2F, - B = 0x30, - N = 0x31, - M = 0x32, - COMMA = 0x33, - PERIOD = 0x34, - FORWARD_SLASH = 0x35, - RIGHT_SHIFT = 0x36, - ARROW_UP = 0x148, - NUM_ONE = 0x4F, - NUM_TWO = 0x50, - NUM_THREE = 0x51, - NUM_ENTER = 0x11C, - LEFT_CONTROL = 0x1D, - LEFT_WINDOWS = 0x15B, - LEFT_ALT = 0x38, - SPACE = 0x39, - RIGHT_ALT = 0x138, - RIGHT_WINDOWS = 0x15C, - APPLICATION_SELECT = 0x15D, - RIGHT_CONTROL = 0x11D, - ARROW_LEFT = 0x14B, - ARROW_DOWN = 0x150, - ARROW_RIGHT = 0x14D, - NUM_ZERO = 0x52, - NUM_PERIOD = 0x53, - TEST = 0x1 - } +namespace Artemis.DeviceProviders.Logitech.Utilities +{ + public enum KeyboardNames + { + ESC = 0x01, + F1 = 0x3b, + F2 = 0x3c, + F3 = 0x3d, + F4 = 0x3e, + F5 = 0x3f, + F6 = 0x40, + F7 = 0x41, + F8 = 0x42, + F9 = 0x43, + F10 = 0x44, + F11 = 0x57, + F12 = 0x58, + PRINT_SCREEN = 0x137, + SCROLL_LOCK = 0x46, + PAUSE_BREAK = 0x45, + TILDE = 0x29, + ONE = 0x02, + TWO = 0x03, + THREE = 0x04, + FOUR = 0x05, + FIVE = 0x06, + SIX = 0x07, + SEVEN = 0x08, + EIGHT = 0x09, + NINE = 0x0A, + ZERO = 0x0B, + MINUS = 0x0C, + EQUALS = 0x0D, + BACKSPACE = 0x0E, + INSERT = 0x152, + HOME = 0x147, + PAGE_UP = 0x149, + NUM_LOCK = 0x145, + NUM_SLASH = 0x135, + NUM_ASTERISK = 0x37, + NUM_MINUS = 0x4A, + TAB = 0x0F, + Q = 0x10, + W = 0x11, + E = 0x12, + R = 0x13, + T = 0x14, + Y = 0x15, + U = 0x16, + I = 0x17, + O = 0x18, + P = 0x19, + OPEN_BRACKET = 0x1A, + CLOSE_BRACKET = 0x1B, + BACKSLASH = 0x2B, + KEYBOARD_DELETE = 0x153, + END = 0x14F, + PAGE_DOWN = 0x151, + NUM_SEVEN = 0x47, + NUM_EIGHT = 0x48, + NUM_NINE = 0x49, + NUM_PLUS = 0x4E, + CAPS_LOCK = 0x3A, + A = 0x1E, + S = 0x1F, + D = 0x20, + F = 0x21, + G = 0x22, + H = 0x23, + J = 0x24, + K = 0x25, + L = 0x26, + SEMICOLON = 0x27, + APOSTROPHE = 0x28, + ENTER = 0x1C, + NUM_FOUR = 0x4B, + NUM_FIVE = 0x4C, + NUM_SIX = 0x4D, + LEFT_SHIFT = 0x2A, + Z = 0x2C, + X = 0x2D, + C = 0x2E, + V = 0x2F, + B = 0x30, + N = 0x31, + M = 0x32, + COMMA = 0x33, + PERIOD = 0x34, + FORWARD_SLASH = 0x35, + RIGHT_SHIFT = 0x36, + ARROW_UP = 0x148, + NUM_ONE = 0x4F, + NUM_TWO = 0x50, + NUM_THREE = 0x51, + NUM_ENTER = 0x11C, + LEFT_CONTROL = 0x1D, + LEFT_WINDOWS = 0x15B, + LEFT_ALT = 0x38, + SPACE = 0x39, + RIGHT_ALT = 0x138, + RIGHT_WINDOWS = 0x15C, + APPLICATION_SELECT = 0x15D, + RIGHT_CONTROL = 0x11D, + ARROW_LEFT = 0x14B, + ARROW_DOWN = 0x150, + ARROW_RIGHT = 0x14D, + NUM_ZERO = 0x52, + NUM_PERIOD = 0x53, + TEST = 0x1 + } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/LogitechGSDK.cs b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/LogitechGSDK.cs similarity index 97% rename from Artemis/Artemis/KeyboardProviders/Logitech/Utilities/LogitechGSDK.cs rename to Artemis/Artemis/DeviceProviders/Logitech/Utilities/LogitechGSDK.cs index f41748402..60f498b92 100644 --- a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/LogitechGSDK.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/LogitechGSDK.cs @@ -1,95 +1,95 @@ -using System.Runtime.InteropServices; - -// ReSharper disable InconsistentNaming - -namespace Artemis.KeyboardProviders.Logitech.Utilities -{ - public class LogitechGSDK - { - //LED SDK - private const int LOGI_DEVICETYPE_MONOCHROME_ORD = 0; - private const int LOGI_DEVICETYPE_RGB_ORD = 1; - private const int LOGI_DEVICETYPE_PERKEY_RGB_ORD = 2; - - public const int LOGI_DEVICETYPE_MONOCHROME = 1 << LOGI_DEVICETYPE_MONOCHROME_ORD; - public const int LOGI_DEVICETYPE_RGB = 1 << LOGI_DEVICETYPE_RGB_ORD; - public const int LOGI_DEVICETYPE_PERKEY_RGB = 1 << LOGI_DEVICETYPE_PERKEY_RGB_ORD; - public const int LOGI_LED_BITMAP_WIDTH = 21; - public const int LOGI_LED_BITMAP_HEIGHT = 6; - public const int LOGI_LED_BITMAP_BYTES_PER_KEY = 4; - - public const int LOGI_LED_BITMAP_SIZE = - LOGI_LED_BITMAP_WIDTH*LOGI_LED_BITMAP_HEIGHT*LOGI_LED_BITMAP_BYTES_PER_KEY; - - public const int LOGI_LED_DURATION_INFINITE = 0; - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedInit(); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedSetTargetDevice(int targetDevice); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedSaveCurrentLighting(); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedRestoreLighting(); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedFlashLighting(int redPercentage, int greenPercentage, int bluePercentage, - int milliSecondsDuration, int milliSecondsInterval); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedPulseLighting(int redPercentage, int greenPercentage, int bluePercentage, - int milliSecondsDuration, int milliSecondsInterval); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedStopEffects(); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedSetLightingFromBitmap(byte[] bitmap); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedSetLightingForKeyWithScanCode(int keyCode, int redPercentage, - int greenPercentage, int bluePercentage); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedSetLightingForKeyWithHidCode(int keyCode, int redPercentage, - int greenPercentage, int bluePercentage); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedSetLightingForKeyWithQuartzCode(int keyCode, int redPercentage, - int greenPercentage, int bluePercentage); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedSetLightingForKeyWithKeyName(int keyCode, int redPercentage, - int greenPercentage, int bluePercentage); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedSaveLightingForKey(KeyboardNames keyName); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedRestoreLightingForKey(KeyboardNames keyName); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedFlashSingleKey(KeyboardNames keyName, int redPercentage, int greenPercentage, - int bluePercentage, int msDuration, int msInterval); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedPulseSingleKey(KeyboardNames keyName, int startRedPercentage, - int startGreenPercentage, int startBluePercentage, int finishRedPercentage, int finishGreenPercentage, - int finishBluePercentage, int msDuration, bool isInfinite); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedStopEffectsOnKey(KeyboardNames keyName); - - [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern void LogiLedShutdown(); - } +using System.Runtime.InteropServices; + +// ReSharper disable InconsistentNaming + +namespace Artemis.DeviceProviders.Logitech.Utilities +{ + public class LogitechGSDK + { + //LED SDK + private const int LOGI_DEVICETYPE_MONOCHROME_ORD = 0; + private const int LOGI_DEVICETYPE_RGB_ORD = 1; + private const int LOGI_DEVICETYPE_PERKEY_RGB_ORD = 2; + + public const int LOGI_DEVICETYPE_MONOCHROME = 1 << LOGI_DEVICETYPE_MONOCHROME_ORD; + public const int LOGI_DEVICETYPE_RGB = 1 << LOGI_DEVICETYPE_RGB_ORD; + public const int LOGI_DEVICETYPE_PERKEY_RGB = 1 << LOGI_DEVICETYPE_PERKEY_RGB_ORD; + public const int LOGI_LED_BITMAP_WIDTH = 21; + public const int LOGI_LED_BITMAP_HEIGHT = 6; + public const int LOGI_LED_BITMAP_BYTES_PER_KEY = 4; + + public const int LOGI_LED_BITMAP_SIZE = + LOGI_LED_BITMAP_WIDTH*LOGI_LED_BITMAP_HEIGHT*LOGI_LED_BITMAP_BYTES_PER_KEY; + + public const int LOGI_LED_DURATION_INFINITE = 0; + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedInit(); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedSetTargetDevice(int targetDevice); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedSaveCurrentLighting(); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedRestoreLighting(); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedFlashLighting(int redPercentage, int greenPercentage, int bluePercentage, + int milliSecondsDuration, int milliSecondsInterval); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedPulseLighting(int redPercentage, int greenPercentage, int bluePercentage, + int milliSecondsDuration, int milliSecondsInterval); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedStopEffects(); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedSetLightingFromBitmap(byte[] bitmap); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedSetLightingForKeyWithScanCode(int keyCode, int redPercentage, + int greenPercentage, int bluePercentage); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedSetLightingForKeyWithHidCode(int keyCode, int redPercentage, + int greenPercentage, int bluePercentage); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedSetLightingForKeyWithQuartzCode(int keyCode, int redPercentage, + int greenPercentage, int bluePercentage); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedSetLightingForKeyWithKeyName(int keyCode, int redPercentage, + int greenPercentage, int bluePercentage); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedSaveLightingForKey(KeyboardNames keyName); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedRestoreLightingForKey(KeyboardNames keyName); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedFlashSingleKey(KeyboardNames keyName, int redPercentage, int greenPercentage, + int bluePercentage, int msDuration, int msInterval); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedPulseSingleKey(KeyboardNames keyName, int startRedPercentage, + int startGreenPercentage, int startBluePercentage, int finishRedPercentage, int finishGreenPercentage, + int finishBluePercentage, int msDuration, bool isInfinite); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedStopEffectsOnKey(KeyboardNames keyName); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern void LogiLedShutdown(); + } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/OrionUtilities.cs b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/OrionUtilities.cs similarity index 96% rename from Artemis/Artemis/KeyboardProviders/Logitech/Utilities/OrionUtilities.cs rename to Artemis/Artemis/DeviceProviders/Logitech/Utilities/OrionUtilities.cs index 4016a271a..048bd978e 100644 --- a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/OrionUtilities.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/OrionUtilities.cs @@ -1,230 +1,230 @@ -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Imaging; -using System.Runtime.InteropServices; - -namespace Artemis.KeyboardProviders.Logitech.Utilities -{ - public static class OrionUtilities - { - public static KeyMapping[] Keymappings = - { - // First row - new KeyMapping(0, 0), - new KeyMapping(1, 1), - new KeyMapping(2, 1), - new KeyMapping(3, 2), - new KeyMapping(4, 3), - new KeyMapping(5, 4), - new KeyMapping(6, 5), - new KeyMapping(7, 6), - new KeyMapping(8, 7), - new KeyMapping(9, 8), - new KeyMapping(10, 9), - new KeyMapping(11, 9), - new KeyMapping(12, 10), - new KeyMapping(13, 11), - new KeyMapping(13, 12), - new KeyMapping(14, 13), - new KeyMapping(15, 14), - new KeyMapping(16, 15), - new KeyMapping(17, 16), - new KeyMapping(18, 17), - new KeyMapping(19, 18), - - // Second row - new KeyMapping(21, 21), - new KeyMapping(22, 22), - new KeyMapping(23, 23), - new KeyMapping(24, 24), - new KeyMapping(25, 25), - new KeyMapping(26, 26), - new KeyMapping(27, 27), - new KeyMapping(28, 28), - new KeyMapping(29, 29), - new KeyMapping(30, 30), - new KeyMapping(31, 31), - new KeyMapping(32, 32), - new KeyMapping(33, 33), - new KeyMapping(34, 34), - new KeyMapping(35, 35), - new KeyMapping(36, 36), - new KeyMapping(37, 37), - new KeyMapping(38, 38), - new KeyMapping(39, 39), - new KeyMapping(40, 40), - new KeyMapping(41, 41), - - // Third row - new KeyMapping(42, 42), - new KeyMapping(43, 43), - new KeyMapping(44, 44), - new KeyMapping(45, 45), - new KeyMapping(46, 46), - new KeyMapping(47, 46), - new KeyMapping(48, 47), - new KeyMapping(49, 48), - new KeyMapping(50, 49), - new KeyMapping(51, 50), - new KeyMapping(52, 51), - new KeyMapping(53, 52), - new KeyMapping(54, 53), - new KeyMapping(54, 54), - new KeyMapping(55, 55), - new KeyMapping(56, 56), - new KeyMapping(57, 57), - new KeyMapping(58, 58), - new KeyMapping(59, 59), - new KeyMapping(60, 60), - new KeyMapping(61, 61), - new KeyMapping(62, 62), - - // Fourth row - new KeyMapping(63, 63), - new KeyMapping(64, 64), - new KeyMapping(65, 65), - new KeyMapping(66, 65), - new KeyMapping(67, 66), - new KeyMapping(68, 67), - new KeyMapping(69, 68), - new KeyMapping(70, 69), - new KeyMapping(71, 70), - new KeyMapping(72, 71), - new KeyMapping(73, 72), - new KeyMapping(74, 73), - new KeyMapping(75, 74), - new KeyMapping(76, 75), - new KeyMapping(76, 76), - new KeyMapping(78, 77), - new KeyMapping(79, 78), - new KeyMapping(79, 79), - new KeyMapping(80, 80), - new KeyMapping(81, 81), - new KeyMapping(82, 82), - - // Fifth row - new KeyMapping(84, 84), - new KeyMapping(85, 85), - new KeyMapping(86, 86), - new KeyMapping(87, 87), - new KeyMapping(88, 88), - new KeyMapping(89, 89), - new KeyMapping(90, 90), - new KeyMapping(91, 91), - new KeyMapping(92, 92), - new KeyMapping(93, 93), - new KeyMapping(94, 94), - new KeyMapping(95, 95), - new KeyMapping(96, 96), - new KeyMapping(97, 97), - new KeyMapping(98, 98), - new KeyMapping(99, 99), - new KeyMapping(100, 100), - new KeyMapping(101, 101), - new KeyMapping(102, 102), - new KeyMapping(103, 103), - new KeyMapping(104, 104), - - // Sixth row - new KeyMapping(105, 105), - new KeyMapping(106, 106), - new KeyMapping(107, 107), - new KeyMapping(108, 107), - new KeyMapping(109, 109), - new KeyMapping(110, 110), - new KeyMapping(111, 110), - new KeyMapping(112, 111), - new KeyMapping(113, 112), - new KeyMapping(114, 113), - new KeyMapping(115, 114), - new KeyMapping(116, 115), - new KeyMapping(115, 116), // ALTGR - new KeyMapping(116, 117), - new KeyMapping(117, 118), - new KeyMapping(118, 119), - new KeyMapping(119, 120), - new KeyMapping(120, 121), - new KeyMapping(121, 122), - new KeyMapping(122, 123), - new KeyMapping(124, 124) - }; - - public static byte[] BitmapToByteArray(Bitmap b, bool remap = true) - { - if (b.Width > 21 || b.Height > 6) - b = ResizeImage(b, 21, 6); - - var rect = new Rectangle(0, 0, b.Width, b.Height); - var bitmapData = b.LockBits(rect, ImageLockMode.ReadWrite, b.PixelFormat); - - var depth = Image.GetPixelFormatSize(b.PixelFormat); - var step = depth/8; - var pixels = new byte[21*6*step]; - var iptr = bitmapData.Scan0; - - // Copy data from pointer to array - Marshal.Copy(iptr, pixels, 0, pixels.Length); - - if (!remap) - return pixels; - - var remapped = new byte[pixels.Length]; - - // Every key is 4 bytes - for (var i = 0; i <= pixels.Length/4; i++) - { - var firstSByte = Keymappings[i].Source*4; - var firstTByte = Keymappings[i].Target*4; - - for (var j = 0; j < 4; j++) - remapped[firstTByte + j] = pixels[firstSByte + j]; - } - - return remapped; - } - - /// - /// Resize the image to the specified width and height. - /// - /// The image to resize. - /// The width to resize to. - /// The height to resize to. - /// The resized image. - public static Bitmap ResizeImage(Image image, int width, int height) - { - var destRect = new Rectangle(0, 0, width, height); - var destImage = new Bitmap(width, height); - - destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); - - using (var graphics = Graphics.FromImage(destImage)) - { - graphics.CompositingMode = CompositingMode.SourceCopy; - graphics.CompositingQuality = CompositingQuality.HighQuality; - graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; - graphics.SmoothingMode = SmoothingMode.HighQuality; - graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; - - using (var wrapMode = new ImageAttributes()) - { - wrapMode.SetWrapMode(WrapMode.TileFlipXY); - graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode); - } - } - - return destImage; - } - - public struct KeyMapping - { - public KeyMapping(int source, int target) - { - Source = source; - Target = target; - } - - public int Source { get; set; } - public int Target { get; set; } - } - } +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; + +namespace Artemis.DeviceProviders.Logitech.Utilities +{ + public static class OrionUtilities + { + public static KeyMapping[] Keymappings = + { + // First row + new KeyMapping(0, 0), + new KeyMapping(1, 1), + new KeyMapping(2, 1), + new KeyMapping(3, 2), + new KeyMapping(4, 3), + new KeyMapping(5, 4), + new KeyMapping(6, 5), + new KeyMapping(7, 6), + new KeyMapping(8, 7), + new KeyMapping(9, 8), + new KeyMapping(10, 9), + new KeyMapping(11, 9), + new KeyMapping(12, 10), + new KeyMapping(13, 11), + new KeyMapping(13, 12), + new KeyMapping(14, 13), + new KeyMapping(15, 14), + new KeyMapping(16, 15), + new KeyMapping(17, 16), + new KeyMapping(18, 17), + new KeyMapping(19, 18), + + // Second row + new KeyMapping(21, 21), + new KeyMapping(22, 22), + new KeyMapping(23, 23), + new KeyMapping(24, 24), + new KeyMapping(25, 25), + new KeyMapping(26, 26), + new KeyMapping(27, 27), + new KeyMapping(28, 28), + new KeyMapping(29, 29), + new KeyMapping(30, 30), + new KeyMapping(31, 31), + new KeyMapping(32, 32), + new KeyMapping(33, 33), + new KeyMapping(34, 34), + new KeyMapping(35, 35), + new KeyMapping(36, 36), + new KeyMapping(37, 37), + new KeyMapping(38, 38), + new KeyMapping(39, 39), + new KeyMapping(40, 40), + new KeyMapping(41, 41), + + // Third row + new KeyMapping(42, 42), + new KeyMapping(43, 43), + new KeyMapping(44, 44), + new KeyMapping(45, 45), + new KeyMapping(46, 46), + new KeyMapping(47, 46), + new KeyMapping(48, 47), + new KeyMapping(49, 48), + new KeyMapping(50, 49), + new KeyMapping(51, 50), + new KeyMapping(52, 51), + new KeyMapping(53, 52), + new KeyMapping(54, 53), + new KeyMapping(54, 54), + new KeyMapping(55, 55), + new KeyMapping(56, 56), + new KeyMapping(57, 57), + new KeyMapping(58, 58), + new KeyMapping(59, 59), + new KeyMapping(60, 60), + new KeyMapping(61, 61), + new KeyMapping(62, 62), + + // Fourth row + new KeyMapping(63, 63), + new KeyMapping(64, 64), + new KeyMapping(65, 65), + new KeyMapping(66, 65), + new KeyMapping(67, 66), + new KeyMapping(68, 67), + new KeyMapping(69, 68), + new KeyMapping(70, 69), + new KeyMapping(71, 70), + new KeyMapping(72, 71), + new KeyMapping(73, 72), + new KeyMapping(74, 73), + new KeyMapping(75, 74), + new KeyMapping(76, 75), + new KeyMapping(76, 76), + new KeyMapping(78, 77), + new KeyMapping(79, 78), + new KeyMapping(79, 79), + new KeyMapping(80, 80), + new KeyMapping(81, 81), + new KeyMapping(82, 82), + + // Fifth row + new KeyMapping(84, 84), + new KeyMapping(85, 85), + new KeyMapping(86, 86), + new KeyMapping(87, 87), + new KeyMapping(88, 88), + new KeyMapping(89, 89), + new KeyMapping(90, 90), + new KeyMapping(91, 91), + new KeyMapping(92, 92), + new KeyMapping(93, 93), + new KeyMapping(94, 94), + new KeyMapping(95, 95), + new KeyMapping(96, 96), + new KeyMapping(97, 97), + new KeyMapping(98, 98), + new KeyMapping(99, 99), + new KeyMapping(100, 100), + new KeyMapping(101, 101), + new KeyMapping(102, 102), + new KeyMapping(103, 103), + new KeyMapping(104, 104), + + // Sixth row + new KeyMapping(105, 105), + new KeyMapping(106, 106), + new KeyMapping(107, 107), + new KeyMapping(108, 107), + new KeyMapping(109, 109), + new KeyMapping(110, 110), + new KeyMapping(111, 110), + new KeyMapping(112, 111), + new KeyMapping(113, 112), + new KeyMapping(114, 113), + new KeyMapping(115, 114), + new KeyMapping(116, 115), + new KeyMapping(115, 116), // ALTGR + new KeyMapping(116, 117), + new KeyMapping(117, 118), + new KeyMapping(118, 119), + new KeyMapping(119, 120), + new KeyMapping(120, 121), + new KeyMapping(121, 122), + new KeyMapping(122, 123), + new KeyMapping(124, 124) + }; + + public static byte[] BitmapToByteArray(Bitmap b, bool remap = true) + { + if (b.Width > 21 || b.Height > 6) + b = ResizeImage(b, 21, 6); + + var rect = new Rectangle(0, 0, b.Width, b.Height); + var bitmapData = b.LockBits(rect, ImageLockMode.ReadWrite, b.PixelFormat); + + var depth = Image.GetPixelFormatSize(b.PixelFormat); + var step = depth/8; + var pixels = new byte[21*6*step]; + var iptr = bitmapData.Scan0; + + // Copy data from pointer to array + Marshal.Copy(iptr, pixels, 0, pixels.Length); + + if (!remap) + return pixels; + + var remapped = new byte[pixels.Length]; + + // Every key is 4 bytes + for (var i = 0; i <= pixels.Length/4; i++) + { + var firstSByte = Keymappings[i].Source*4; + var firstTByte = Keymappings[i].Target*4; + + for (var j = 0; j < 4; j++) + remapped[firstTByte + j] = pixels[firstSByte + j]; + } + + return remapped; + } + + /// + /// Resize the image to the specified width and height. + /// + /// The image to resize. + /// The width to resize to. + /// The height to resize to. + /// The resized image. + public static Bitmap ResizeImage(Image image, int width, int height) + { + var destRect = new Rectangle(0, 0, width, height); + var destImage = new Bitmap(width, height); + + destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); + + using (var graphics = Graphics.FromImage(destImage)) + { + graphics.CompositingMode = CompositingMode.SourceCopy; + graphics.CompositingQuality = CompositingQuality.HighQuality; + graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; + graphics.SmoothingMode = SmoothingMode.HighQuality; + graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + + using (var wrapMode = new ImageAttributes()) + { + wrapMode.SetWrapMode(WrapMode.TileFlipXY); + graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode); + } + } + + return destImage; + } + + public struct KeyMapping + { + public KeyMapping(int source, int target) + { + Source = source; + Target = target; + } + + public int Source { get; set; } + public int Target { get; set; } + } + } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Razer/BlackWidow.cs b/Artemis/Artemis/DeviceProviders/Razer/BlackWidow.cs similarity index 91% rename from Artemis/Artemis/KeyboardProviders/Razer/BlackWidow.cs rename to Artemis/Artemis/DeviceProviders/Razer/BlackWidow.cs index 52a930dfd..b5e812495 100644 --- a/Artemis/Artemis/KeyboardProviders/Razer/BlackWidow.cs +++ b/Artemis/Artemis/DeviceProviders/Razer/BlackWidow.cs @@ -1,49 +1,49 @@ -using System.Drawing; -using Artemis.KeyboardProviders.Razer.Utilities; -using Corale.Colore.Core; -using Corale.Colore.Razer; -using Constants = Corale.Colore.Razer.Keyboard.Constants; - -namespace Artemis.KeyboardProviders.Razer -{ - public class BlackWidow : KeyboardProvider - { - public BlackWidow() - { - Name = "Razer BlackWidow Chroma"; - CantEnableText = "Couldn't connect to your Razer BlackWidow Chroma.\n" + - "Please check your cables and try updating Razer Synapse.\n\n" + - "If needed, you can select a different keyboard in Artemis under settings."; - } - - public override bool CanEnable() - { - if (!Chroma.IsSdkAvailable()) - return false; - - // Some people have Synapse installed, but not a Chroma keyboard, deal with this - var blackWidowFound = Chroma.Instance.Query(Devices.Blackwidow).Connected; - var blackWidowTeFound = Chroma.Instance.Query(Devices.BlackwidowTe).Connected; - return blackWidowFound || blackWidowTeFound; - } - - public override void Enable() - { - Chroma.Instance.Initialize(); - Height = Constants.MaxRows; - Width = Constants.MaxColumns; - } - - public override void Disable() - { - Chroma.Instance.Uninitialize(); - } - - public override void DrawBitmap(Bitmap bitmap) - { - var razerArray = RazerUtilities.BitmapColorArray(bitmap, Height, Width); - - Chroma.Instance.Keyboard.SetCustom(razerArray); - } - } +using System.Drawing; +using Artemis.DeviceProviders.Razer.Utilities; +using Corale.Colore.Core; +using Corale.Colore.Razer; +using Constants = Corale.Colore.Razer.Keyboard.Constants; + +namespace Artemis.DeviceProviders.Razer +{ + public class BlackWidow : KeyboardProvider + { + public BlackWidow() + { + Name = "Razer BlackWidow Chroma"; + CantEnableText = "Couldn't connect to your Razer BlackWidow Chroma.\n" + + "Please check your cables and try updating Razer Synapse.\n\n" + + "If needed, you can select a different keyboard in Artemis under settings."; + } + + public override bool CanEnable() + { + if (!Chroma.IsSdkAvailable()) + return false; + + // Some people have Synapse installed, but not a Chroma keyboard, deal with this + var blackWidowFound = Chroma.Instance.Query(Devices.Blackwidow).Connected; + var blackWidowTeFound = Chroma.Instance.Query(Devices.BlackwidowTe).Connected; + return blackWidowFound || blackWidowTeFound; + } + + public override void Enable() + { + Chroma.Instance.Initialize(); + Height = Constants.MaxRows; + Width = Constants.MaxColumns; + } + + public override void Disable() + { + Chroma.Instance.Uninitialize(); + } + + public override void DrawBitmap(Bitmap bitmap) + { + var razerArray = RazerUtilities.BitmapColorArray(bitmap, Height, Width); + + Chroma.Instance.Keyboard.SetCustom(razerArray); + } + } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Razer/Utilities/RazerUtilities.cs b/Artemis/Artemis/DeviceProviders/Razer/Utilities/RazerUtilities.cs similarity index 89% rename from Artemis/Artemis/KeyboardProviders/Razer/Utilities/RazerUtilities.cs rename to Artemis/Artemis/DeviceProviders/Razer/Utilities/RazerUtilities.cs index cdf025df9..b8a380416 100644 --- a/Artemis/Artemis/KeyboardProviders/Razer/Utilities/RazerUtilities.cs +++ b/Artemis/Artemis/DeviceProviders/Razer/Utilities/RazerUtilities.cs @@ -1,22 +1,22 @@ -using System.Drawing; -using Artemis.Utilities; -using Corale.Colore.Razer.Keyboard.Effects; - -namespace Artemis.KeyboardProviders.Razer.Utilities -{ - public static class RazerUtilities - { - public static Custom BitmapColorArray(Bitmap b, int height, int width) - { - var keyboardGrid = Custom.Create(); - if (b.Width > width || b.Height > height) - b = ImageUtilities.ResizeImage(b, width, height); - - for (var y = 0; y < b.Height; y++) - for (var x = 0; x < b.Width; x++) - keyboardGrid[y, x] = b.GetPixel(x, y); - - return keyboardGrid; - } - } +using System.Drawing; +using Artemis.Utilities; +using Corale.Colore.Razer.Keyboard.Effects; + +namespace Artemis.DeviceProviders.Razer.Utilities +{ + public static class RazerUtilities + { + public static Custom BitmapColorArray(Bitmap b, int height, int width) + { + var keyboardGrid = Custom.Create(); + if (b.Width > width || b.Height > height) + b = ImageUtilities.ResizeImage(b, width, height); + + for (var y = 0; y < b.Height; y++) + for (var x = 0; x < b.Width; x++) + keyboardGrid[y, x] = b.GetPixel(x, y); + + return keyboardGrid; + } + } } \ No newline at end of file diff --git a/Artemis/Artemis/Events/ActiveKeyboardChanged.cs b/Artemis/Artemis/Events/ActiveKeyboardChanged.cs index a6656802d..1557e2a99 100644 --- a/Artemis/Artemis/Events/ActiveKeyboardChanged.cs +++ b/Artemis/Artemis/Events/ActiveKeyboardChanged.cs @@ -1,4 +1,4 @@ -using Artemis.KeyboardProviders; +using Artemis.DeviceProviders; namespace Artemis.Events { diff --git a/Artemis/Artemis/InjectionModules/ArtemisModules.cs b/Artemis/Artemis/InjectionModules/ArtemisModules.cs index 4d981cdad..6d793db48 100644 --- a/Artemis/Artemis/InjectionModules/ArtemisModules.cs +++ b/Artemis/Artemis/InjectionModules/ArtemisModules.cs @@ -1,7 +1,7 @@ -using Artemis.KeyboardProviders; -using Artemis.KeyboardProviders.Corsair; -using Artemis.KeyboardProviders.Logitech; -using Artemis.KeyboardProviders.Razer; +using Artemis.DeviceProviders; +using Artemis.DeviceProviders.Corsair; +using Artemis.DeviceProviders.Logitech; +using Artemis.DeviceProviders.Razer; using Artemis.Modules.Effects.AudioVisualizer; using Artemis.Modules.Effects.Debug; using Artemis.Modules.Effects.TypeWave; diff --git a/Artemis/Artemis/KeyboardProviders/KeyboardRegion.cs b/Artemis/Artemis/KeyboardProviders/KeyboardRegion.cs deleted file mode 100644 index c82e98d77..000000000 --- a/Artemis/Artemis/KeyboardProviders/KeyboardRegion.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Drawing; - -namespace Artemis.KeyboardProviders -{ - public class KeyboardRegion - { - public KeyboardRegion(string regionName, Point topLeft, Point bottomRight) - { - RegionName = regionName; - TopLeft = topLeft; - BottomRight = bottomRight; - } - - public string RegionName { get; set; } - public Point TopLeft { get; set; } - public Point BottomRight { get; set; } - - public Rectangle GetRectangle() - => new Rectangle(TopLeft.X, TopLeft.Y, BottomRight.X - TopLeft.X, BottomRight.Y - TopLeft.Y); - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Managers/KeyboardManager.cs b/Artemis/Artemis/Managers/KeyboardManager.cs index 6ace41ecc..570b03af9 100644 --- a/Artemis/Artemis/Managers/KeyboardManager.cs +++ b/Artemis/Artemis/Managers/KeyboardManager.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using Artemis.DeviceProviders; using Artemis.Events; -using Artemis.KeyboardProviders; using Artemis.Services; using Artemis.Settings; using Caliburn.Micro; diff --git a/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs b/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs index 22f115f0e..fdafa0eb5 100644 --- a/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs +++ b/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs @@ -3,8 +3,8 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Windows.Forms; -using Artemis.KeyboardProviders.Corsair; -using Artemis.KeyboardProviders.Logitech.Utilities; +using Artemis.DeviceProviders.Corsair; +using Artemis.DeviceProviders.Logitech.Utilities; using Artemis.Managers; using Artemis.Models; using Artemis.Utilities; diff --git a/Artemis/Artemis/Utilities/Keyboard/KeyboardRectangle.cs b/Artemis/Artemis/Utilities/Keyboard/KeyboardRectangle.cs index 16c351d89..8081ab8e6 100644 --- a/Artemis/Artemis/Utilities/Keyboard/KeyboardRectangle.cs +++ b/Artemis/Artemis/Utilities/Keyboard/KeyboardRectangle.cs @@ -5,7 +5,7 @@ using System.Drawing.Drawing2D; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Artemis.KeyboardProviders; +using Artemis.DeviceProviders; namespace Artemis.Utilities.Keyboard { diff --git a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs index 2292238eb..1172b0d2d 100644 --- a/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs +++ b/Artemis/Artemis/ViewModels/ProfileEditorViewModel.cs @@ -9,8 +9,8 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Threading; using Artemis.DAL; +using Artemis.DeviceProviders; using Artemis.Events; -using Artemis.KeyboardProviders; using Artemis.Managers; using Artemis.Models; using Artemis.Models.Profiles;