diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 1a11ea0fd..9604e7fd8 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -650,8 +650,11 @@ - + + + Always + PreserveNewest @@ -837,9 +840,6 @@ - - PreserveNewest - diff --git a/Artemis/Artemis/DeviceProviders/Logitech/G910.cs b/Artemis/Artemis/DeviceProviders/Logitech/G910.cs index 97bfda191..957d7ebd9 100644 --- a/Artemis/Artemis/DeviceProviders/Logitech/G910.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/G910.cs @@ -1,4 +1,6 @@ -using System.Linq; +using System; +using System.Drawing; +using System.Linq; using System.Windows; using System.Windows.Forms; using Artemis.DeviceProviders.Logitech.Utilities; @@ -16,8 +18,8 @@ namespace Artemis.DeviceProviders.Logitech "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; + Height = 7; + Width = 22; PreviewSettings = new PreviewSettings(540, 154, new Thickness(25, -80, 0, 0), Resources.g910); } @@ -25,5 +27,55 @@ namespace Artemis.DeviceProviders.Logitech { return KeyMap.QwertyLayout.FirstOrDefault(k => k.KeyCode == keyCode); } + + /// + /// The G910 also updates the G-logo, G-badge and G-keys + /// + /// + public override void DrawBitmap(Bitmap bitmap) + { + using (var croppedBitmap = new Bitmap(21*4, 6*4)) + { + // Deal with non-standard DPI + croppedBitmap.SetResolution(96, 96); + // Don't forget that the image is upscaled 4 times + using (var g = Graphics.FromImage(croppedBitmap)) + { + g.DrawImage(bitmap, new Rectangle(0, 0, 84, 24), new Rectangle(4, 4, 84, 24), GraphicsUnit.Pixel); + } + + base.DrawBitmap(croppedBitmap); + } + + using (var resized = OrionUtilities.ResizeImage(bitmap, 22, 7)) + { + // Color the extra keys on the left side of the keyboard + SetLogitechColorFromCoordinates(resized, KeyboardNames.G_LOGO, 0, 1); + SetLogitechColorFromCoordinates(resized, KeyboardNames.G_1, 0, 2); + SetLogitechColorFromCoordinates(resized, KeyboardNames.G_2, 0, 3); + SetLogitechColorFromCoordinates(resized, KeyboardNames.G_3, 0, 4); + SetLogitechColorFromCoordinates(resized, KeyboardNames.G_4, 0, 5); + SetLogitechColorFromCoordinates(resized, KeyboardNames.G_5, 0, 6); + + // Color the extra keys on the top of the keyboard + SetLogitechColorFromCoordinates(resized, KeyboardNames.G_6, 3, 0); + SetLogitechColorFromCoordinates(resized, KeyboardNames.G_7, 4, 0); + SetLogitechColorFromCoordinates(resized, KeyboardNames.G_8, 5, 0); + SetLogitechColorFromCoordinates(resized, KeyboardNames.G_9, 6, 0); + + // Color the G-badge + SetLogitechColorFromCoordinates(resized, KeyboardNames.G_BADGE, 5, 6); + } + } + + private void SetLogitechColorFromCoordinates(Bitmap bitmap, KeyboardNames key, int x, int y) + { + var color = bitmap.GetPixel(x, y); + var rPer = (int) Math.Round(color.R/2.55); + var gPer = (int) Math.Round(color.G/2.55); + var bPer = (int) Math.Round(color.B/2.55); + + LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(key, rPer, gPer, bPer); + } } } \ No newline at end of file diff --git a/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs b/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs index e04471a29..e5263ec7e 100644 --- a/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs @@ -58,10 +58,7 @@ namespace Artemis.DeviceProviders.Logitech Thread.Sleep(200); LogitechGSDK.LogiLedSaveCurrentLighting(); - - // Disable keys we can't color LogitechGSDK.LogiLedSetTargetDevice(LogitechGSDK.LOGI_DEVICETYPE_PERKEY_RGB); - LogitechGSDK.LogiLedSetLighting(0, 0, 0); } public override void Disable() diff --git a/Artemis/Artemis/DeviceProviders/Logitech/Utilities/KeyboardNames.cs b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/KeyboardNames.cs index 78f96b177..2d8758d5f 100644 --- a/Artemis/Artemis/DeviceProviders/Logitech/Utilities/KeyboardNames.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/KeyboardNames.cs @@ -106,6 +106,16 @@ namespace Artemis.DeviceProviders.Logitech.Utilities ARROW_RIGHT = 0x14D, NUM_ZERO = 0x52, NUM_PERIOD = 0x53, - TEST = 0x1 + G_1 = 0xFFF1, + G_2 = 0xFFF2, + G_3 = 0xFFF3, + G_4 = 0xFFF4, + G_5 = 0xFFF5, + G_6 = 0xFFF6, + G_7 = 0xFFF7, + G_8 = 0xFFF8, + G_9 = 0xFFF9, + G_LOGO = 0xFFFF1, + G_BADGE = 0xFFFF2 } } \ No newline at end of file diff --git a/Artemis/Artemis/DeviceProviders/Logitech/Utilities/LogitechGSDK.cs b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/LogitechGSDK.cs index 60f498b92..a5a81a558 100644 --- a/Artemis/Artemis/DeviceProviders/Logitech/Utilities/LogitechGSDK.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/LogitechGSDK.cs @@ -1,6 +1,5 @@ using System.Runtime.InteropServices; - -// ReSharper disable InconsistentNaming +using System.Text; namespace Artemis.DeviceProviders.Logitech.Utilities { @@ -26,6 +25,25 @@ namespace Artemis.DeviceProviders.Logitech.Utilities [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] public static extern bool LogiLedInit(); + //Config option functions + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedGetConfigOptionNumber([MarshalAs(UnmanagedType.LPWStr)] string configPath, + ref double defaultNumber); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedGetConfigOptionBool([MarshalAs(UnmanagedType.LPWStr)] string configPath, + ref bool defaultRed); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedGetConfigOptionColor([MarshalAs(UnmanagedType.LPWStr)] string configPath, + ref int defaultRed, ref int defaultGreen, ref int defaultBlue); + + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedGetConfigOptionKeyInput([MarshalAs(UnmanagedType.LPWStr)] string configPath, + StringBuilder buffer, int bufsize); + + ///////////////////// + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] public static extern bool LogiLedSetTargetDevice(int targetDevice); @@ -52,6 +70,9 @@ namespace Artemis.DeviceProviders.Logitech.Utilities [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] public static extern bool LogiLedStopEffects(); + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] + public static extern bool LogiLedExcludeKeysFromBitmap(KeyboardNames[] keyList, int listCount); + [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] public static extern bool LogiLedSetLightingFromBitmap(byte[] bitmap); @@ -68,7 +89,7 @@ namespace Artemis.DeviceProviders.Logitech.Utilities int greenPercentage, int bluePercentage); [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] - public static extern bool LogiLedSetLightingForKeyWithKeyName(int keyCode, int redPercentage, + public static extern bool LogiLedSetLightingForKeyWithKeyName(KeyboardNames keyCode, int redPercentage, int greenPercentage, int bluePercentage); [DllImport("LogitechLedEnginesWrapper ", CallingConvention = CallingConvention.Cdecl)] diff --git a/Artemis/Artemis/DeviceProviders/Logitech/Utilities/OrionUtilities.cs b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/OrionUtilities.cs index 048bd978e..370460b98 100644 --- a/Artemis/Artemis/DeviceProviders/Logitech/Utilities/OrionUtilities.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/Utilities/OrionUtilities.cs @@ -180,6 +180,7 @@ namespace Artemis.DeviceProviders.Logitech.Utilities remapped[firstTByte + j] = pixels[firstSByte + j]; } + b.Dispose(); return remapped; } diff --git a/Artemis/Artemis/LogitechLedEnginesWrapper.dll b/Artemis/Artemis/LogitechLedEnginesWrapper.dll index 37f959c2e..fb707e78a 100644 Binary files a/Artemis/Artemis/LogitechLedEnginesWrapper.dll and b/Artemis/Artemis/LogitechLedEnginesWrapper.dll differ