From 84523b47b420e18abb7b8444528f28c0b251789a Mon Sep 17 00:00:00 2001 From: Logan Saso Date: Thu, 28 Jan 2016 15:57:41 -0800 Subject: [PATCH 1/2] reduced min % of key highlighted for coloring to occur (fixes large buttons like shift and space) --- Artemis/Artemis/KeyboardProviders/Corsair/K95.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs b/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs index e8af77206..bbea70883 100644 --- a/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs +++ b/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs @@ -29,7 +29,7 @@ namespace Artemis.KeyboardProviders.Corsair _keyboard = CueSDK.KeyboardSDK; _keyboard.UpdateMode = UpdateMode.Manual; _keyboard.Brush = new SolidColorBrush(Color.Black); - _keyboard.Update(); + _keyboard.Update(true); } public override void Disable() @@ -51,10 +51,17 @@ namespace Artemis.KeyboardProviders.Corsair for (var y = 0; y < bitmap.Height; y++) { ledRectangles[x, y] = new RectangleF(_keyboard.KeyboardRectangle.X * (x*(_keyboard.KeyboardRectangle.Width / bitmap.Width / _keyboard.KeyboardRectangle.X)), _keyboard.KeyboardRectangle.Y*(y*(_keyboard.KeyboardRectangle.Height / bitmap.Height / _keyboard.KeyboardRectangle.Y)), _keyboard.KeyboardRectangle.Width / bitmap.Width, _keyboard.KeyboardRectangle.Height / bitmap.Height); - ledGroups[x, y] = new RectangleKeyGroup(_keyboard, ledRectangles[x, y], 0.1f) { Brush = new SolidColorBrush(bitmap.GetPixel(x, y)) }; + ledGroups[x, y] = new RectangleKeyGroup(_keyboard, ledRectangles[x, y], 0.01f) { Brush = new SolidColorBrush(bitmap.GetPixel(x, y)) }; } } - _keyboard.Update(true); + _keyboard.Update(); + for (var x = 0; x < bitmap.Width; x++) + { + for (var y = 0; y < bitmap.Height; y++) + { + _keyboard.DetachKeyGroup(ledGroups[x, y]); + } + } } } } \ No newline at end of file From 32315ebd11a2880e8b2d88f79bfc6bf67a3c622d Mon Sep 17 00:00:00 2001 From: Logan Saso Date: Thu, 28 Jan 2016 15:58:56 -0800 Subject: [PATCH 2/2] Updated K70 class to reflect the same working conditions for K95 --- .../Artemis/KeyboardProviders/Corsair/K70.cs | 77 ++++++++++++------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/Artemis/Artemis/KeyboardProviders/Corsair/K70.cs b/Artemis/Artemis/KeyboardProviders/Corsair/K70.cs index 1c9f2e719..60fcd0937 100644 --- a/Artemis/Artemis/KeyboardProviders/Corsair/K70.cs +++ b/Artemis/Artemis/KeyboardProviders/Corsair/K70.cs @@ -2,7 +2,9 @@ using CUE.NET; using CUE.NET.Devices.Generic.Enums; using CUE.NET.Devices.Keyboard; - +using CUE.NET.Brushes; +using CUE.NET.Devices.Keyboard.Keys; + namespace Artemis.KeyboardProviders.Corsair { internal class K70 : KeyboardProvider @@ -13,29 +15,52 @@ namespace Artemis.KeyboardProviders.Corsair { Name = "Corsair Gaming K70 RGB"; } - - public override void Enable() - { - _keyboard = CueSDK.KeyboardSDK; - _keyboard.UpdateMode = UpdateMode.Manual; - } - - public override void Disable() - { - } - - public override void DrawBitmap(Bitmap bitmap) - { - // TODO: Resize bitmap to keyboard's size - //if (bitmap.Width > width || bitmap.Height > height) - // bitmap = ResizeImage(bitmap, width, height); - - // One way of doing this, not sure at all if it's any good - for (var y = 0; y < bitmap.Height - 1; y++) - for (var x = 0; x < bitmap.Width - 1; x++) - _keyboard[new PointF(x, y)].Led.Color = bitmap.GetPixel(x, y); - - _keyboard.Update(true); - } - } + /// + /// Enables the SDK and sets updatemode to manual as well as the color of the background to black. + /// + public override void Enable() + { + try + { + CueSDK.Initialize(); + } + catch (CUE.NET.Exceptions.WrapperException) {/*CUE is already initialized*/} + _keyboard = CueSDK.KeyboardSDK; + _keyboard.UpdateMode = UpdateMode.Manual; + _keyboard.Brush = new SolidColorBrush(Color.Black); + _keyboard.Update(true); + } + + public override void Disable() + { + } + + /// + /// Properly resizes any size bitmap to the keyboard by creating a rectangle whose size is dependent on the bitmap size. + /// Does not reset the color each time. Uncomment line 48 for collor reset. + /// + /// + public override void DrawBitmap(Bitmap bitmap) + { + RectangleF[,] ledRectangles = new RectangleF[bitmap.Width, bitmap.Height]; + RectangleKeyGroup[,] ledGroups = new RectangleKeyGroup[bitmap.Width, bitmap.Height]; + //_keyboard.Brush = new SolidColorBrush(Color.Black); + for (var x = 0; x < bitmap.Width; x++) + { + for (var y = 0; y < bitmap.Height; y++) + { + ledRectangles[x, y] = new RectangleF(_keyboard.KeyboardRectangle.X * (x * (_keyboard.KeyboardRectangle.Width / bitmap.Width / _keyboard.KeyboardRectangle.X)), _keyboard.KeyboardRectangle.Y * (y * (_keyboard.KeyboardRectangle.Height / bitmap.Height / _keyboard.KeyboardRectangle.Y)), _keyboard.KeyboardRectangle.Width / bitmap.Width, _keyboard.KeyboardRectangle.Height / bitmap.Height); + ledGroups[x, y] = new RectangleKeyGroup(_keyboard, ledRectangles[x, y], 0.01f) { Brush = new SolidColorBrush(bitmap.GetPixel(x, y)) }; + } + } + _keyboard.Update(); + for (var x = 0; x < bitmap.Width; x++) + { + for (var y = 0; y < bitmap.Height; y++) + { + _keyboard.DetachKeyGroup(ledGroups[x, y]); + } + } + } + } } \ No newline at end of file