1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Updated Logitech SDK for #174

This commit is contained in:
SpoinkyNL 2016-10-11 00:55:03 +02:00
parent 64e2d4b4c8
commit a12389f221
7 changed files with 95 additions and 14 deletions

View File

@ -650,8 +650,11 @@
</None>
<AppDesigner Include="Properties\" />
<Resource Include="Resources\bow.png" />
<Content Include="lib\ColorBox.dll" />
<Content Include="lib\CUE.NET.dll" />
<Content Include="lib\Ets2SdkClient.dll" />
<Content Include="LogitechLedEnginesWrapper.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="logo.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -837,9 +840,6 @@
</Page>
</ItemGroup>
<ItemGroup>
<Content Include="LogitechLedEnginesWrapper.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Modules\Games\UnrealTournament\Resources\redeemer.gif" />
<None Include="Modules\Games\EurotruckSimulator2\Resources\Win32\ets2-telemetry-server.dll" />
<None Include="Modules\Games\EurotruckSimulator2\Resources\Win64\ets2-telemetry-server.dll" />

View File

@ -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);
}
/// <summary>
/// The G910 also updates the G-logo, G-badge and G-keys
/// </summary>
/// <param name="bitmap"></param>
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);
}
}
}

View File

@ -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()

View File

@ -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
}
}

View File

@ -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)]

View File

@ -180,6 +180,7 @@ namespace Artemis.DeviceProviders.Logitech.Utilities
remapped[firstTByte + j] = pixels[firstSByte + j];
}
b.Dispose();
return remapped;
}