1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 01:58:30 +00:00

Made logitech keyboards work (Layout and Images for G910 DE-Layout)

This commit is contained in:
Darth Affe 2017-03-26 20:23:41 +02:00
parent 9617771368
commit 726ec1443e
125 changed files with 829 additions and 18 deletions

View File

@ -26,6 +26,7 @@ namespace RGB.NET.Devices.Logitech
PRINT_SCREEN = 0x137,
SCROLL_LOCK = 0x46,
PAUSE_BREAK = 0x45,
TILDE = 0x29,
ONE = 0x02,
TWO = 0x03,
@ -47,6 +48,7 @@ namespace RGB.NET.Devices.Logitech
NUM_SLASH = 0x135,
NUM_ASTERISK = 0x37,
NUM_MINUS = 0x4A,
TAB = 0x0F,
Q = 0x10,
W = 0x11,
@ -68,6 +70,7 @@ namespace RGB.NET.Devices.Logitech
NUM_EIGHT = 0x48,
NUM_NINE = 0x49,
NUM_PLUS = 0x4E,
CAPS_LOCK = 0x3A,
A = 0x1E,
S = 0x1F,
@ -80,10 +83,12 @@ namespace RGB.NET.Devices.Logitech
L = 0x26,
SEMICOLON = 0x27,
APOSTROPHE = 0x28,
NonUsTilde = 0xFF, //TODO DarthAffe 26.03.2017: Find the real ID/Name of this key - it's not documented ...
ENTER = 0x1C,
NUM_FOUR = 0x4B,
NUM_FIVE = 0x4C,
NUM_SIX = 0x4D,
LEFT_SHIFT = 0x2A,
Z = 0x2C,
X = 0x2D,
@ -101,6 +106,7 @@ namespace RGB.NET.Devices.Logitech
NUM_TWO = 0x50,
NUM_THREE = 0x51,
NUM_ENTER = 0x11C,
LEFT_CONTROL = 0x1D,
LEFT_WINDOWS = 0x15B,
LEFT_ALT = 0x38,
@ -114,6 +120,7 @@ namespace RGB.NET.Devices.Logitech
ARROW_RIGHT = 0x14D,
NUM_ZERO = 0x52,
NUM_PERIOD = 0x53,
G_1 = 0xFFF1,
G_2 = 0xFFF2,
G_3 = 0xFFF3,

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Core.Layout;
@ -59,11 +60,15 @@ namespace RGB.NET.Devices.Logitech
/// Applies the given layout.
/// </summary>
/// <param name="layoutPath">The file containing the layout.</param>
protected void ApplyLayoutFromFile(string layoutPath)
/// <param name="imageLayout">The name of the layout used tp get the images of the leds.</param>
/// <param name="imageBasePath">The path images for this device are collected in.</param>
protected void ApplyLayoutFromFile(string layoutPath, string imageLayout, string imageBasePath)
{
DeviceLayout layout = DeviceLayout.Load(layoutPath);
if (layout != null)
{
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
InternalSize = new Size(layout.Width, layout.Height);
if (layout.Leds != null)
@ -83,6 +88,12 @@ namespace RGB.NET.Devices.Logitech
led.LedRectangle.Size.Height = layoutLed.Height;
led.Shape = layoutLed.Shape;
led.ShapeData = layoutLed.ShapeData;
LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id);
led.Image = (!string.IsNullOrEmpty(image?.Image))
? new Uri(Path.Combine(imageBasePath, image.Image), UriKind.Absolute)
: new Uri(Path.Combine(imageBasePath, "Missing.png"), UriKind.Absolute);
}
}
}
@ -91,13 +102,31 @@ namespace RGB.NET.Devices.Logitech
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
{
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
List<Led> leds = ledsToUpdate.Where(x => x.Color.A > 0).ToList();
byte[] bitmap = null;
foreach (Led led in leds)
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)((LogitechLedId)led.Id).LedId,
(int)Math.Round(led.Color.RPercent * 100),
(int)Math.Round(led.Color.GPercent * 100),
(int)Math.Round(led.Color.BPercent * 100));
{
//TODO DarthAffe 26.03.2017: This is only needed since update by name doesn't work as expected for all keys ...
int bitmapOffset;
if (BitmapMapping.BitmapOffset.TryGetValue(((LogitechLedId)led.Id).LedId, out bitmapOffset))
{
if (bitmap == null)
bitmap = BitmapMapping.CreateBitmap();
BitmapMapping.SetColor(ref bitmap, bitmapOffset, led.Color);
}
else
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)((LogitechLedId)led.Id).LedId,
(int)Math.Round(led.Color.RPercent * 100),
(int)Math.Round(led.Color.GPercent * 100),
(int)Math.Round(led.Color.BPercent * 100));
}
if (bitmap != null)
_LogitechGSDK.LogiLedSetLightingFromBitmap(bitmap);
}
#endregion

View File

@ -9,8 +9,8 @@ namespace RGB.NET.Devices.Logitech.HID
#region Constants
//TODO DarthAffe 04.02.2017: Add IDs
private const int VENDOR_ID = 0x0;
private const int G910_ID = 0x0;
private const int VENDOR_ID = 0x046D;
private const int G910_ID = 0xC32B;
private const int G810_ID = 0x0;
#endregion

View File

@ -0,0 +1,172 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
{
internal static class BitmapMapping
{
#region Constants
private const int BITMAP_SIZE = 21 * 6 * 4;
#endregion
#region Properties & Fields
internal static Dictionary<LogitechLedIds, int> BitmapOffset { get; } = new Dictionary<LogitechLedIds, int>
{
{ LogitechLedIds.ESC, 0 },
{ LogitechLedIds.F1, 4 },
{ LogitechLedIds.F2, 8 },
{ LogitechLedIds.F3, 12 },
{ LogitechLedIds.F4, 16 },
{ LogitechLedIds.F5, 20 },
{ LogitechLedIds.F6, 24 },
{ LogitechLedIds.F7, 28 },
{ LogitechLedIds.F8, 32 },
{ LogitechLedIds.F9, 36 },
{ LogitechLedIds.F10, 40 },
{ LogitechLedIds.F11, 44 },
{ LogitechLedIds.F12, 48 },
{ LogitechLedIds.PRINT_SCREEN, 52 },
{ LogitechLedIds.SCROLL_LOCK, 56 },
{ LogitechLedIds.PAUSE_BREAK, 60 },
// { LogitechLedIds.?, 64 },
// { LogitechLedIds.?, 68 },
// { LogitechLedIds.?, 72 },
// { LogitechLedIds.?, 76 },
// { LogitechLedIds.?, 80 },
{ LogitechLedIds.TILDE, 84 },
{ LogitechLedIds.ONE, 88 },
{ LogitechLedIds.TWO, 92 },
{ LogitechLedIds.THREE, 96 },
{ LogitechLedIds.FOUR, 100 },
{ LogitechLedIds.FIVE, 104 },
{ LogitechLedIds.SIX, 108 },
{ LogitechLedIds.SEVEN, 112 },
{ LogitechLedIds.EIGHT, 116 },
{ LogitechLedIds.NINE, 120 },
{ LogitechLedIds.ZERO, 124 },
{ LogitechLedIds.MINUS, 128 },
{ LogitechLedIds.EQUALS, 132 },
{ LogitechLedIds.BACKSPACE, 136 },
{ LogitechLedIds.INSERT, 140 },
{ LogitechLedIds.HOME, 144 },
{ LogitechLedIds.PAGE_UP, 148 },
{ LogitechLedIds.NUM_LOCK, 152 },
{ LogitechLedIds.NUM_SLASH, 156 },
{ LogitechLedIds.NUM_ASTERISK, 160 },
{ LogitechLedIds.NUM_MINUS, 164 },
{ LogitechLedIds.TAB, 168 },
{ LogitechLedIds.Q, 172 },
{ LogitechLedIds.W, 176 },
{ LogitechLedIds.E, 180 },
{ LogitechLedIds.R, 184 },
{ LogitechLedIds.T, 188 },
{ LogitechLedIds.Y, 192 },
{ LogitechLedIds.U, 196 },
{ LogitechLedIds.I, 200 },
{ LogitechLedIds.O, 204 },
{ LogitechLedIds.P, 208 },
{ LogitechLedIds.OPEN_BRACKET, 212 },
{ LogitechLedIds.CLOSE_BRACKET, 216 },
// { LogitechLedIds.?, 220 },
{ LogitechLedIds.KEYBOARD_DELETE, 224 },
{ LogitechLedIds.END, 228 },
{ LogitechLedIds.PAGE_DOWN, 232 },
{ LogitechLedIds.NUM_SEVEN, 236 },
{ LogitechLedIds.NUM_EIGHT, 240 },
{ LogitechLedIds.NUM_NINE, 244 },
{ LogitechLedIds.NUM_PLUS, 248 },
{ LogitechLedIds.CAPS_LOCK, 252 },
{ LogitechLedIds.A, 256 },
{ LogitechLedIds.S, 260 },
{ LogitechLedIds.D, 264 },
{ LogitechLedIds.F, 268 },
{ LogitechLedIds.G, 272 },
{ LogitechLedIds.H, 276 },
{ LogitechLedIds.J, 280 },
{ LogitechLedIds.K, 284 },
{ LogitechLedIds.L, 288 },
{ LogitechLedIds.SEMICOLON, 292 },
{ LogitechLedIds.APOSTROPHE, 296 },
{ LogitechLedIds.NonUsTilde, 300 }, //TODO DarthAffe 26.03.2017: Find the real ID/Name of this key - it's not documented ...
{ LogitechLedIds.ENTER, 304 },
// { LogitechLedIds.?, 308 },
// { LogitechLedIds.?, 312 },
// { LogitechLedIds.?, 316 },
{ LogitechLedIds.NUM_FOUR, 320 },
{ LogitechLedIds.NUM_FIVE, 324 },
{ LogitechLedIds.NUM_SIX, 328 },
// { LogitechLedIds.?, 332 },
{ LogitechLedIds.LEFT_SHIFT, 336 },
{ LogitechLedIds.BACKSLASH, 340 },
{ LogitechLedIds.Z, 344 },
{ LogitechLedIds.X, 348 },
{ LogitechLedIds.C, 352 },
{ LogitechLedIds.V, 356 },
{ LogitechLedIds.B, 360 },
{ LogitechLedIds.N, 364 },
{ LogitechLedIds.M, 368 },
{ LogitechLedIds.COMMA, 372 },
{ LogitechLedIds.PERIOD, 376 },
{ LogitechLedIds.FORWARD_SLASH, 380 },
{ LogitechLedIds.RIGHT_SHIFT, 388 },
// { LogitechLedIds.?, 392 },
{ LogitechLedIds.ARROW_UP, 396 },
// { LogitechLedIds.?, 400 },
{ LogitechLedIds.NUM_ONE, 404 },
{ LogitechLedIds.NUM_TWO, 408 },
{ LogitechLedIds.NUM_THREE, 412 },
{ LogitechLedIds.NUM_ENTER, 416 },
{ LogitechLedIds.LEFT_CONTROL, 420 },
{ LogitechLedIds.LEFT_WINDOWS, 424 },
{ LogitechLedIds.LEFT_ALT, 428 },
// { LogitechLedIds.?, 432 },
// { LogitechLedIds.?, 436 },
{ LogitechLedIds.SPACE, 440 },
// { LogitechLedIds.?, 444 },
// { LogitechLedIds.?, 448 },
// { LogitechLedIds.?, 452 },
// { LogitechLedIds.?, 456 },
// { LogitechLedIds.?, 460 },
{ LogitechLedIds.RIGHT_ALT, 464 },
{ LogitechLedIds.RIGHT_WINDOWS, 468 },
{ LogitechLedIds.APPLICATION_SELECT, 472 },
{ LogitechLedIds.RIGHT_CONTROL, 476 },
{ LogitechLedIds.ARROW_LEFT, 480 },
{ LogitechLedIds.ARROW_DOWN, 484 },
{ LogitechLedIds.ARROW_RIGHT, 488 },
{ LogitechLedIds.NUM_ZERO, 492 },
{ LogitechLedIds.NUM_PERIOD, 496 },
// { LogitechLedIds.?, 500 },
};
#endregion
#region Methods
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static byte[] CreateBitmap()
{
return new byte[BITMAP_SIZE];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void SetColor(ref byte[] bitmap, int offset, Color color)
{
bitmap[offset] = color.B;
bitmap[offset + 1] = color.G;
bitmap[offset + 2] = color.R;
bitmap[offset + 3] = color.A;
}
#endregion
}
}

View File

@ -0,0 +1,24 @@
using System.IO;
using System.Reflection;
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Offers some helper-methods for file-path related things.
/// </summary>
public static class PathHelper
{
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="relativePath">The relative path to convert.</param>
/// <returns>The absolute path.</returns>
public static string GetAbsolutePath(string relativePath)
{
string assemblyLocation = Assembly.GetEntryAssembly()?.Location;
if (assemblyLocation == null) return relativePath;
return Path.Combine(Path.GetDirectoryName(assemblyLocation), relativePath);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Some files were not shown because too many files have changed in this diff Show More