Added Led-Mapping base class and centralized HID-device-detection

This commit is contained in:
DarthAffe committed 2021-04-02 00:32:22 +02:00
1 parent eb3b91d8d8
commit 7f3abaefec
24 files changed
+1246 -1296

No files matched your search

@@ -1,138 +0,0 @@
// ReSharper disable InconsistentNaming
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Contains list of all LEDs available for all logitech devices.
/// </summary>
public enum LogitechLedId
{
Invalid = 0,
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,
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,
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,
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,
DEVICE = 0xFFFFFFF
}
}
@@ -0,0 +1,326 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
{
public static class LedMappings
{
public static LedMapping<int> PerKey { get; } = new()
{
{ LedId.Keyboard_Escape, 0 },
{ LedId.Keyboard_F1, 4 },
{ LedId.Keyboard_F2, 8 },
{ LedId.Keyboard_F3, 12 },
{ LedId.Keyboard_F4, 16 },
{ LedId.Keyboard_F5, 20 },
{ LedId.Keyboard_F6, 24 },
{ LedId.Keyboard_F7, 28 },
{ LedId.Keyboard_F8, 32 },
{ LedId.Keyboard_F9, 36 },
{ LedId.Keyboard_F10, 40 },
{ LedId.Keyboard_F11, 44 },
{ LedId.Keyboard_F12, 48 },
{ LedId.Keyboard_PrintScreen, 52 },
{ LedId.Keyboard_ScrollLock, 56 },
{ LedId.Keyboard_PauseBreak, 60 },
// { LedId.Keyboard_?, 64 },
// { LedId.Keyboard_?, 68 },
// { LedId.Keyboard_?, 72 },
// { LedId.Keyboard_?, 76 },
// { LedId.Keyboard_?, 80 },
{ LedId.Keyboard_GraveAccentAndTilde, 84 },
{ LedId.Keyboard_1, 88 },
{ LedId.Keyboard_2, 92 },
{ LedId.Keyboard_3, 96 },
{ LedId.Keyboard_4, 100 },
{ LedId.Keyboard_5, 104 },
{ LedId.Keyboard_6, 108 },
{ LedId.Keyboard_7, 112 },
{ LedId.Keyboard_8, 116 },
{ LedId.Keyboard_9, 120 },
{ LedId.Keyboard_0, 124 },
{ LedId.Keyboard_MinusAndUnderscore, 128 },
{ LedId.Keyboard_EqualsAndPlus, 132 },
{ LedId.Keyboard_Backspace, 136 },
{ LedId.Keyboard_Insert, 140 },
{ LedId.Keyboard_Home, 144 },
{ LedId.Keyboard_PageUp, 148 },
{ LedId.Keyboard_NumLock, 152 },
{ LedId.Keyboard_NumSlash, 156 },
{ LedId.Keyboard_NumAsterisk, 160 },
{ LedId.Keyboard_NumMinus, 164 },
{ LedId.Keyboard_Tab, 168 },
{ LedId.Keyboard_Q, 172 },
{ LedId.Keyboard_W, 176 },
{ LedId.Keyboard_E, 180 },
{ LedId.Keyboard_R, 184 },
{ LedId.Keyboard_T, 188 },
{ LedId.Keyboard_Y, 192 },
{ LedId.Keyboard_U, 196 },
{ LedId.Keyboard_I, 200 },
{ LedId.Keyboard_O, 204 },
{ LedId.Keyboard_P, 208 },
{ LedId.Keyboard_BracketLeft, 212 },
{ LedId.Keyboard_BracketRight, 216 },
{ LedId.Keyboard_Backslash, 220 },
{ LedId.Keyboard_Delete, 224 },
{ LedId.Keyboard_End, 228 },
{ LedId.Keyboard_PageDown, 232 },
{ LedId.Keyboard_Num7, 236 },
{ LedId.Keyboard_Num8, 240 },
{ LedId.Keyboard_Num9, 244 },
{ LedId.Keyboard_NumPlus, 248 },
{ LedId.Keyboard_CapsLock, 252 },
{ LedId.Keyboard_A, 256 },
{ LedId.Keyboard_S, 260 },
{ LedId.Keyboard_D, 264 },
{ LedId.Keyboard_F, 268 },
{ LedId.Keyboard_G, 272 },
{ LedId.Keyboard_H, 276 },
{ LedId.Keyboard_J, 280 },
{ LedId.Keyboard_K, 284 },
{ LedId.Keyboard_L, 288 },
{ LedId.Keyboard_SemicolonAndColon, 292 },
{ LedId.Keyboard_ApostropheAndDoubleQuote, 296 },
{ LedId.Keyboard_NonUsTilde, 300 }, //TODO DarthAffe 26.03.2017: Find the real ID/Name of this key - it's not documented ...
{ LedId.Keyboard_Enter, 304 },
// { LedId.Keyboard_?, 308 },
// { LedId.Keyboard_?, 312 },
// { LedId.Keyboard_?, 316 },
{ LedId.Keyboard_Num4, 320 },
{ LedId.Keyboard_Num5, 324 },
{ LedId.Keyboard_Num6, 328 },
// { LedId.Keyboard_?, 332 },
{ LedId.Keyboard_LeftShift, 336 },
{ LedId.Keyboard_NonUsBackslash, 340 },
{ LedId.Keyboard_Z, 344 },
{ LedId.Keyboard_X, 348 },
{ LedId.Keyboard_C, 352 },
{ LedId.Keyboard_V, 356 },
{ LedId.Keyboard_B, 360 },
{ LedId.Keyboard_N, 364 },
{ LedId.Keyboard_M, 368 },
{ LedId.Keyboard_CommaAndLessThan, 372 },
{ LedId.Keyboard_PeriodAndBiggerThan, 376 },
{ LedId.Keyboard_SlashAndQuestionMark, 380 },
{ LedId.Keyboard_RightShift, 388 },
// { LedId.Keyboard_?, 392 },
{ LedId.Keyboard_ArrowUp, 396 },
// { LedId.Keyboard_?, 400 },
{ LedId.Keyboard_Num1, 404 },
{ LedId.Keyboard_Num2, 408 },
{ LedId.Keyboard_Num3, 412 },
{ LedId.Keyboard_NumEnter, 416 },
{ LedId.Keyboard_LeftCtrl, 420 },
{ LedId.Keyboard_LeftGui, 424 },
{ LedId.Keyboard_LeftAlt, 428 },
// { LedId.Keyboard_?, 432 },
// { LedId.Keyboard_?, 436 },
{ LedId.Keyboard_Space, 440 },
// { LedId.Keyboard_?, 444 },
// { LedId.Keyboard_?, 448 },
// { LedId.Keyboard_?, 452 },
// { LedId.Keyboard_?, 456 },
// { LedId.Keyboard_?, 460 },
{ LedId.Keyboard_RightAlt, 464 },
{ LedId.Keyboard_RightGui, 468 },
{ LedId.Keyboard_Application, 472 },
{ LedId.Keyboard_RightCtrl, 476 },
{ LedId.Keyboard_ArrowLeft, 480 },
{ LedId.Keyboard_ArrowDown, 484 },
{ LedId.Keyboard_ArrowRight, 488 },
{ LedId.Keyboard_Num0, 492 },
{ LedId.Keyboard_NumPeriodAndDelete, 496 },
// { LedId.Keyboard_?, 500 },
};
public static LedMapping<int> Device { get; } = new()
{
{ LedId.Custom1, 0 }
};
public static LedMapping<int> ZoneKeyboard { get; } = new()
{
{ LedId.Keyboard_Programmable1, 0 },
{ LedId.Keyboard_Programmable2, 1 },
{ LedId.Keyboard_Programmable3, 2 },
{ LedId.Keyboard_Programmable4, 3 },
{ LedId.Keyboard_Programmable5, 4 },
{ LedId.Keyboard_Programmable6, 5 },
{ LedId.Keyboard_Programmable7, 6 },
{ LedId.Keyboard_Programmable8, 7 },
{ LedId.Keyboard_Programmable9, 8 },
{ LedId.Keyboard_Programmable10, 9 },
{ LedId.Keyboard_Programmable11, 10 },
{ LedId.Keyboard_Programmable12, 11 },
{ LedId.Keyboard_Programmable13, 12 },
{ LedId.Keyboard_Programmable14, 13 },
{ LedId.Keyboard_Programmable15, 14 },
{ LedId.Keyboard_Programmable16, 15 },
{ LedId.Keyboard_Programmable17, 16 },
{ LedId.Keyboard_Programmable18, 17 },
{ LedId.Keyboard_Programmable19, 18 },
{ LedId.Keyboard_Programmable20, 19 },
{ LedId.Keyboard_Programmable21, 20 },
{ LedId.Keyboard_Programmable22, 21 },
{ LedId.Keyboard_Programmable23, 22 },
{ LedId.Keyboard_Programmable24, 23 },
{ LedId.Keyboard_Programmable25, 24 },
{ LedId.Keyboard_Programmable26, 25 },
{ LedId.Keyboard_Programmable27, 26 },
{ LedId.Keyboard_Programmable28, 27 },
{ LedId.Keyboard_Programmable29, 28 },
{ LedId.Keyboard_Programmable30, 29 },
{ LedId.Keyboard_Programmable31, 30 },
{ LedId.Keyboard_Programmable32, 31 },
};
public static LedMapping<int> ZoneMouse { get; } = new()
{
{ LedId.Mouse1, 0 },
{ LedId.Mouse2, 1 },
{ LedId.Mouse3, 2 },
{ LedId.Mouse4, 3 },
{ LedId.Mouse5, 4 },
{ LedId.Mouse6, 5 },
{ LedId.Mouse7, 6 },
{ LedId.Mouse8, 7 },
{ LedId.Mouse9, 8 },
{ LedId.Mouse10, 9 },
{ LedId.Mouse11, 10 },
{ LedId.Mouse12, 11 },
{ LedId.Mouse13, 12 },
{ LedId.Mouse14, 13 },
{ LedId.Mouse15, 14 },
{ LedId.Mouse16, 15 },
{ LedId.Mouse17, 16 },
{ LedId.Mouse18, 17 },
{ LedId.Mouse19, 18 },
{ LedId.Mouse20, 19 },
{ LedId.Mouse21, 20 },
{ LedId.Mouse22, 21 },
{ LedId.Mouse23, 22 },
{ LedId.Mouse24, 23 },
{ LedId.Mouse25, 24 },
{ LedId.Mouse26, 25 },
{ LedId.Mouse27, 26 },
{ LedId.Mouse28, 27 },
{ LedId.Mouse29, 28 },
{ LedId.Mouse30, 29 },
{ LedId.Mouse31, 30 },
{ LedId.Mouse32, 31 },
};
public static LedMapping<int> ZoneHeadset { get; } = new()
{
{ LedId.Headset1, 0 },
{ LedId.Headset2, 1 },
{ LedId.Headset3, 2 },
{ LedId.Headset4, 3 },
{ LedId.Headset5, 4 },
{ LedId.Headset6, 5 },
{ LedId.Headset7, 6 },
{ LedId.Headset8, 7 },
{ LedId.Headset9, 8 },
{ LedId.Headset10, 9 },
{ LedId.Headset11, 10 },
{ LedId.Headset12, 11 },
{ LedId.Headset13, 12 },
{ LedId.Headset14, 13 },
{ LedId.Headset15, 14 },
{ LedId.Headset16, 15 },
{ LedId.Headset17, 16 },
{ LedId.Headset18, 17 },
{ LedId.Headset19, 18 },
{ LedId.Headset20, 19 },
{ LedId.Headset21, 20 },
{ LedId.Headset22, 21 },
{ LedId.Headset23, 22 },
{ LedId.Headset24, 23 },
{ LedId.Headset25, 24 },
{ LedId.Headset26, 25 },
{ LedId.Headset27, 26 },
{ LedId.Headset28, 27 },
{ LedId.Headset29, 28 },
{ LedId.Headset30, 29 },
{ LedId.Headset31, 30 },
{ LedId.Headset32, 31 },
};
public static LedMapping<int> ZoneMousepad { get; } = new()
{
{ LedId.Mousepad1, 0 },
{ LedId.Mousepad2, 1 },
{ LedId.Mousepad3, 2 },
{ LedId.Mousepad4, 3 },
{ LedId.Mousepad5, 4 },
{ LedId.Mousepad6, 5 },
{ LedId.Mousepad7, 6 },
{ LedId.Mousepad8, 7 },
{ LedId.Mousepad9, 8 },
{ LedId.Mousepad10, 9 },
{ LedId.Mousepad11, 10 },
{ LedId.Mousepad12, 11 },
{ LedId.Mousepad13, 12 },
{ LedId.Mousepad14, 13 },
{ LedId.Mousepad15, 14 },
{ LedId.Mousepad16, 15 },
{ LedId.Mousepad17, 16 },
{ LedId.Mousepad18, 17 },
{ LedId.Mousepad19, 18 },
{ LedId.Mousepad20, 19 },
{ LedId.Mousepad21, 20 },
{ LedId.Mousepad22, 21 },
{ LedId.Mousepad23, 22 },
{ LedId.Mousepad24, 23 },
{ LedId.Mousepad25, 24 },
{ LedId.Mousepad26, 25 },
{ LedId.Mousepad27, 26 },
{ LedId.Mousepad28, 27 },
{ LedId.Mousepad29, 28 },
{ LedId.Mousepad30, 29 },
{ LedId.Mousepad31, 30 },
{ LedId.Mousepad32, 31 },
};
public static LedMapping<int> ZoneSpeaker { get; } = new()
{
{ LedId.Speaker1, 0 },
{ LedId.Speaker2, 1 },
{ LedId.Speaker3, 2 },
{ LedId.Speaker4, 3 },
{ LedId.Speaker5, 4 },
{ LedId.Speaker6, 5 },
{ LedId.Speaker7, 6 },
{ LedId.Speaker8, 7 },
{ LedId.Speaker9, 8 },
{ LedId.Speaker10, 9 },
{ LedId.Speaker11, 10 },
{ LedId.Speaker12, 11 },
{ LedId.Speaker13, 12 },
{ LedId.Speaker14, 13 },
{ LedId.Speaker15, 14 },
{ LedId.Speaker16, 15 },
{ LedId.Speaker17, 16 },
{ LedId.Speaker18, 17 },
{ LedId.Speaker19, 18 },
{ LedId.Speaker20, 19 },
{ LedId.Speaker21, 20 },
{ LedId.Speaker22, 21 },
{ LedId.Speaker23, 22 },
{ LedId.Speaker24, 23 },
{ LedId.Speaker25, 24 },
{ LedId.Speaker26, 25 },
{ LedId.Speaker27, 26 },
{ LedId.Speaker28, 27 },
{ LedId.Speaker29, 28 },
{ LedId.Speaker30, 29 },
{ LedId.Speaker31, 30 },
{ LedId.Speaker32, 31 },
};
}
}
@@ -1,133 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using HidSharp;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech.HID
{
internal static class DeviceChecker
{
#region Constants
private const int VENDOR_ID = 0x046D;
private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones)> PER_KEY_DEVICES
= new()
{
("G910", RGBDeviceType.Keyboard, 0xC32B, 0),
("G910v2", RGBDeviceType.Keyboard, 0xC335, 0),
("G915", RGBDeviceType.Keyboard, 0xC541, 0),
("G815", RGBDeviceType.Keyboard, 0xC33F, 0),
("G810", RGBDeviceType.Keyboard, 0xC337, 0),
("G810", RGBDeviceType.Keyboard, 0xC331, 0),
("G610", RGBDeviceType.Keyboard, 0xC333, 0),
("G512", RGBDeviceType.Keyboard, 0xC33C, 0),
("G512 SE", RGBDeviceType.Keyboard, 0xC342, 0),
("G410", RGBDeviceType.Keyboard, 0xC330, 0),
("G213", RGBDeviceType.Keyboard, 0xC336, 0),
("Pro", RGBDeviceType.Keyboard, 0xC339, 0),
("G915 TKL", RGBDeviceType.Keyboard, 0xC343, 0),
("Lightspeed Keyboard Dongle", RGBDeviceType.Keyboard, 0xC545, 0),
};
private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones)> PER_DEVICE_DEVICES
= new()
{
("G19", RGBDeviceType.Keyboard, 0xC228, 0),
("G19s", RGBDeviceType.Keyboard, 0xC229, 0),
("G600", RGBDeviceType.Mouse, 0xC24A, 0),
("G300s", RGBDeviceType.Mouse, 0xC246, 0),
("G510", RGBDeviceType.Keyboard, 0xC22D, 0),
("G510s", RGBDeviceType.Keyboard, 0xC22E, 0),
("G13", RGBDeviceType.Keypad, 0xC21C, 0),
("G110", RGBDeviceType.Keyboard, 0xC22B, 0),
("G710+", RGBDeviceType.Keyboard, 0xC24D, 0),
("G105", RGBDeviceType.Keyboard, 0xC248, 0),
("G15", RGBDeviceType.Keyboard, 0xC222, 0),
("G11", RGBDeviceType.Keyboard, 0xC225, 0),
};
private static readonly List<(string model, RGBDeviceType deviceType, int id, int zones)> ZONE_DEVICES
= new()
{
("G213", RGBDeviceType.Keyboard, 0xC336, 5),
("G903", RGBDeviceType.Mouse, 0xC086, 2),
("Lightspeed Mouse Dongle", RGBDeviceType.Mouse, 0xC539, 2),
("G703", RGBDeviceType.Mouse, 0xC087, 2),
("G502 HERO", RGBDeviceType.Mouse, 0xC08B, 2),
("G502 Lightspeed", RGBDeviceType.Mouse, 0xC08D, 2),
("G502", RGBDeviceType.Mouse, 0xC332, 2),
("G403", RGBDeviceType.Mouse, 0xC083, 2),
("G303", RGBDeviceType.Mouse, 0xC080, 2),
("G203", RGBDeviceType.Mouse, 0xC084, 1),
("G Pro", RGBDeviceType.Mouse, 0xC085, 1),
("G Pro Wireless", RGBDeviceType.Mouse, 0xC088, 2),
("G Pro Hero", RGBDeviceType.Mouse, 0xC08C, 1),
("G633", RGBDeviceType.Headset, 0x0A5C, 2),
("G933", RGBDeviceType.Headset, 0x0A5B, 2),
("G935", RGBDeviceType.Headset, 0x0A87, 2),
("G560", RGBDeviceType.Speaker, 0x0A78, 4),
("G733", RGBDeviceType.Speaker, 0xAB5, 2),
};
#endregion
#region Properties & Fields
public static bool IsPerKeyDeviceConnected { get; private set; }
public static (string model, RGBDeviceType deviceType, int id, int zones) PerKeyDeviceData { get; private set; }
public static bool IsPerDeviceDeviceConnected { get; private set; }
public static (string model, RGBDeviceType deviceType, int id, int zones) PerDeviceDeviceData { get; private set; }
public static bool IsZoneDeviceConnected { get; private set; }
public static IEnumerable<(string model, RGBDeviceType deviceType, int id, int zones)> ZoneDeviceData { get; private set; } = Enumerable.Empty<(string model, RGBDeviceType deviceType, int id, int zones)>();
#endregion
#region Methods
internal static void LoadDeviceList()
{
List<int> ids = DeviceList.Local.GetHidDevices(VENDOR_ID).Select(x => x.ProductID).Distinct().ToList();
foreach ((string model, RGBDeviceType deviceType, int id, int zones) deviceData in PER_KEY_DEVICES)
if (ids.Contains(deviceData.id))
{
IsPerKeyDeviceConnected = true;
PerKeyDeviceData = deviceData;
break;
}
foreach ((string model, RGBDeviceType deviceType, int id, int zones) deviceData in PER_DEVICE_DEVICES)
if (ids.Contains(deviceData.id))
{
IsPerDeviceDeviceConnected = true;
PerDeviceDeviceData = deviceData;
break;
}
Dictionary<RGBDeviceType, List<(string model, RGBDeviceType deviceType, int id, int zones)>> connectedZoneDevices = new();
foreach ((string model, RGBDeviceType deviceType, int id, int zones) deviceData in ZONE_DEVICES)
{
if (ids.Contains(deviceData.id))
{
IsZoneDeviceConnected = true;
if (!connectedZoneDevices.TryGetValue(deviceData.deviceType, out List<(string model, RGBDeviceType deviceType, int id, int zones)>? deviceList))
connectedZoneDevices.Add(deviceData.deviceType, deviceList = new List<(string model, RGBDeviceType deviceType, int id, int zones)>());
deviceList.Add(deviceData);
}
}
List<(string model, RGBDeviceType deviceType, int id, int zones)> zoneDeviceData = new();
foreach (KeyValuePair<RGBDeviceType, List<(string model, RGBDeviceType deviceType, int id, int zones)>> connectedZoneDevice in connectedZoneDevices)
{
int maxZones = connectedZoneDevice.Value.Max(x => x.zones);
zoneDeviceData.Add(connectedZoneDevice.Value.First(x => x.zones == maxZones));
}
ZoneDeviceData = zoneDeviceData;
}
#endregion
}
}
@@ -3,9 +3,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HidSharp;
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.HID;
using RGB.NET.Devices.Logitech.Native;
using RGB.NET.HID;
namespace RGB.NET.Devices.Logitech
{
@@ -38,6 +40,64 @@ namespace RGB.NET.Devices.Logitech
private LogitechPerDeviceUpdateQueue? _perDeviceUpdateQueue;
private LogitechPerKeyUpdateQueue? _perKeyUpdateQueue;
private const int VENDOR_ID = 0x046D;
public static HIDLoader<int, int> PerKeyDeviceDefinitions { get; } = new(VENDOR_ID)
{
{ 0xC32B, RGBDeviceType.Keyboard, "G910", LedMappings.PerKey, 0 },
{ 0xC335, RGBDeviceType.Keyboard, "G910v2", LedMappings.PerKey, 0 },
{ 0xC541, RGBDeviceType.Keyboard, "G915", LedMappings.PerKey, 0 },
{ 0xC33F, RGBDeviceType.Keyboard, "G815", LedMappings.PerKey, 0 },
{ 0xC337, RGBDeviceType.Keyboard, "G810", LedMappings.PerKey, 0 },
{ 0xC331, RGBDeviceType.Keyboard, "G810", LedMappings.PerKey, 0 },
{ 0xC333, RGBDeviceType.Keyboard, "G610", LedMappings.PerKey, 0 },
{ 0xC33C, RGBDeviceType.Keyboard, "G512", LedMappings.PerKey, 0 },
{ 0xC342, RGBDeviceType.Keyboard, "G512 SE", LedMappings.PerKey, 0 },
{ 0xC330, RGBDeviceType.Keyboard, "G410", LedMappings.PerKey, 0 },
{ 0xC336, RGBDeviceType.Keyboard, "G213", LedMappings.PerKey, 0 },
{ 0xC339, RGBDeviceType.Keyboard, "Pro", LedMappings.PerKey, 0 },
{ 0xC343, RGBDeviceType.Keyboard, "G915 TKL", LedMappings.PerKey, 0 },
{ 0xC545, RGBDeviceType.Keyboard, "Lightspeed Keyboard Dongle", LedMappings.PerKey, 0 },
};
public static HIDLoader<int, (LogitechDeviceType deviceType, int zones)> PerZoneDeviceDefinitions { get; } = new(VENDOR_ID)
{
{ 0xC336, RGBDeviceType.Keyboard, "G213", LedMappings.ZoneKeyboard, (LogitechDeviceType.Keyboard, 2) },
{ 0xC086, RGBDeviceType.Mouse, "G903", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC539, RGBDeviceType.Mouse, "Lightspeed Mouse Dongle", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC087, RGBDeviceType.Mouse, "G703", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC08B, RGBDeviceType.Mouse, "G502 HERO", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC08D, RGBDeviceType.Mouse, "G502 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC332, RGBDeviceType.Mouse, "G502", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC083, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC080, RGBDeviceType.Mouse, "G303", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC084, RGBDeviceType.Mouse, "G203", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
{ 0xC085, RGBDeviceType.Mouse, "G Pro", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
{ 0xC088, RGBDeviceType.Mouse, "G Pro Wireless", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC08C, RGBDeviceType.Mouse, "G Pro Hero", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
{ 0x0A5C, RGBDeviceType.Headset, "G633", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
{ 0x0A5B, RGBDeviceType.Headset, "G933", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
{ 0x0A87, RGBDeviceType.Headset, "G935", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
{ 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneHeadset, (LogitechDeviceType.Speaker, 4) },
{ 0xAB5, RGBDeviceType.Speaker, "G733", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 2) },
};
public static HIDLoader<int, int> PerDeviceDeviceDefinitions { get; } = new(VENDOR_ID)
{
{ 0xC228, RGBDeviceType.Keyboard, "G19", LedMappings.Device, 0 },
{ 0xC229, RGBDeviceType.Keyboard, "G19s", LedMappings.Device, 0 },
{ 0xC24A, RGBDeviceType.Mouse, "G600", LedMappings.Device, 0 },
{ 0xC246, RGBDeviceType.Mouse, "G300s", LedMappings.Device, 0 },
{ 0xC22D, RGBDeviceType.Keyboard, "G510", LedMappings.Device, 0 },
{ 0xC22E, RGBDeviceType.Keyboard, "G510s", LedMappings.Device, 0 },
{ 0xC21C, RGBDeviceType.Keypad, "G13", LedMappings.Device, 0 },
{ 0xC22B, RGBDeviceType.Keyboard, "G110", LedMappings.Device, 0 },
{ 0xC24D, RGBDeviceType.Keyboard, "G710+", LedMappings.Device, 0 },
{ 0xC248, RGBDeviceType.Keyboard, "G105", LedMappings.Device, 0 },
{ 0xC222, RGBDeviceType.Keyboard, "G15", LedMappings.Device, 0 },
{ 0xC225, RGBDeviceType.Keyboard, "G11", LedMappings.Device, 0 },
};
#endregion
#region Constructors
@@ -67,30 +127,37 @@ namespace RGB.NET.Devices.Logitech
_LogitechGSDK.LogiLedSaveCurrentLighting();
}
protected override IEnumerable<IRGBDevice> GetLoadedDevices(RGBDeviceType loadFilter)
{
PerKeyDeviceDefinitions.LoadFilter = loadFilter;
PerZoneDeviceDefinitions.LoadFilter = loadFilter;
PerDeviceDeviceDefinitions.LoadFilter = loadFilter;
return base.GetLoadedDevices(loadFilter);
}
//TODO DarthAffe 04.03.2021: Rework device selection and configuration for HID-based providers
protected override IEnumerable<IRGBDevice> LoadDevices()
{
DeviceChecker.LoadDeviceList();
if (DeviceChecker.IsPerKeyDeviceConnected && (_perKeyUpdateQueue != null))
IEnumerable<(HIDDeviceDefinition<int, int> definition, HidDevice device)> perKeyDevices = PerKeyDeviceDefinitions.GetConnectedDevices();
if ((_perKeyUpdateQueue != null) && perKeyDevices.Any())
{
(string model, RGBDeviceType deviceType, int _, int _) = DeviceChecker.PerKeyDeviceData;
yield return new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.PerKeyRGB, 0), _perKeyUpdateQueue);
(HIDDeviceDefinition<int, int> definition, _) = perKeyDevices.First();
yield return new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.PerKeyRGB, 0), _perKeyUpdateQueue, definition.LedMapping);
}
if (DeviceChecker.IsPerDeviceDeviceConnected && (_perDeviceUpdateQueue != null))
IEnumerable<(HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones)> definition, HidDevice device)> perZoneDevices = PerZoneDeviceDefinitions.GetConnectedDevices(x => x.CustomData.deviceType);
foreach ((HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zones)> definition, _) in perZoneDevices)
{
(string model, RGBDeviceType deviceType, int _, int _) = DeviceChecker.PerDeviceDeviceData;
yield return new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, 0), _perDeviceUpdateQueue);
LogitechZoneUpdateQueue updateQueue = new(GetUpdateTrigger(), definition.CustomData.deviceType);
yield return new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.DeviceRGB, definition.CustomData.zones), updateQueue, definition.LedMapping);
}
if (DeviceChecker.IsZoneDeviceConnected)
IEnumerable<(HIDDeviceDefinition<int, int> definition, HidDevice device)> perDeviceDevices = PerDeviceDeviceDefinitions.GetConnectedDevices();
if ((_perDeviceUpdateQueue != null) && perDeviceDevices.Any())
{
foreach ((string model, RGBDeviceType deviceType, int _, int zones) in DeviceChecker.ZoneDeviceData)
{
LogitechZoneUpdateQueue updateQueue = new(GetUpdateTrigger(), deviceType);
yield return new LogitechZoneRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, zones), updateQueue);
}
(HIDDeviceDefinition<int, int> definition, _) = perDeviceDevices.First();
yield return new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.DeviceRGB, 0), _perDeviceUpdateQueue, definition.LedMapping);
}
}
@@ -10,16 +10,23 @@ namespace RGB.NET.Devices.Logitech
/// </summary>
public class LogitechPerDeviceRGBDevice : LogitechRGBDevice<LogitechRGBDeviceInfo>, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated
{
#region Properties & Fields
private readonly LedMapping<int> _ledMapping;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechPerDeviceRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by logitech for the per-device-lightable device</param>
internal LogitechPerDeviceRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue)
internal LogitechPerDeviceRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue, LedMapping<int> ledMapping)
: base(info, updateQueue)
{
this._ledMapping = ledMapping;
InitializeLayout();
}
@@ -31,8 +38,9 @@ namespace RGB.NET.Devices.Logitech
{
AddLed(LedId.Custom1, new Point(0, 0), new Size(10, 10));
}
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => (ledId, LogitechLedId.DEVICE);
protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId];
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate.Take(1)));
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.CompilerServices;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
@@ -11,145 +10,7 @@ namespace RGB.NET.Devices.Logitech
private const int BITMAP_SIZE = 21 * 6 * 4;
#endregion
#region Properties & Fields
internal static Dictionary<LedId, int> BitmapOffset { get; } = new()
{
{ LedId.Keyboard_Escape, 0 },
{ LedId.Keyboard_F1, 4 },
{ LedId.Keyboard_F2, 8 },
{ LedId.Keyboard_F3, 12 },
{ LedId.Keyboard_F4, 16 },
{ LedId.Keyboard_F5, 20 },
{ LedId.Keyboard_F6, 24 },
{ LedId.Keyboard_F7, 28 },
{ LedId.Keyboard_F8, 32 },
{ LedId.Keyboard_F9, 36 },
{ LedId.Keyboard_F10, 40 },
{ LedId.Keyboard_F11, 44 },
{ LedId.Keyboard_F12, 48 },
{ LedId.Keyboard_PrintScreen, 52 },
{ LedId.Keyboard_ScrollLock, 56 },
{ LedId.Keyboard_PauseBreak, 60 },
// { LedId.Keyboard_?, 64 },
// { LedId.Keyboard_?, 68 },
// { LedId.Keyboard_?, 72 },
// { LedId.Keyboard_?, 76 },
// { LedId.Keyboard_?, 80 },
{ LedId.Keyboard_GraveAccentAndTilde, 84 },
{ LedId.Keyboard_1, 88 },
{ LedId.Keyboard_2, 92 },
{ LedId.Keyboard_3, 96 },
{ LedId.Keyboard_4, 100 },
{ LedId.Keyboard_5, 104 },
{ LedId.Keyboard_6, 108 },
{ LedId.Keyboard_7, 112 },
{ LedId.Keyboard_8, 116 },
{ LedId.Keyboard_9, 120 },
{ LedId.Keyboard_0, 124 },
{ LedId.Keyboard_MinusAndUnderscore, 128 },
{ LedId.Keyboard_EqualsAndPlus, 132 },
{ LedId.Keyboard_Backspace, 136 },
{ LedId.Keyboard_Insert, 140 },
{ LedId.Keyboard_Home, 144 },
{ LedId.Keyboard_PageUp, 148 },
{ LedId.Keyboard_NumLock, 152 },
{ LedId.Keyboard_NumSlash, 156 },
{ LedId.Keyboard_NumAsterisk, 160 },
{ LedId.Keyboard_NumMinus, 164 },
{ LedId.Keyboard_Tab, 168 },
{ LedId.Keyboard_Q, 172 },
{ LedId.Keyboard_W, 176 },
{ LedId.Keyboard_E, 180 },
{ LedId.Keyboard_R, 184 },
{ LedId.Keyboard_T, 188 },
{ LedId.Keyboard_Y, 192 },
{ LedId.Keyboard_U, 196 },
{ LedId.Keyboard_I, 200 },
{ LedId.Keyboard_O, 204 },
{ LedId.Keyboard_P, 208 },
{ LedId.Keyboard_BracketLeft, 212 },
{ LedId.Keyboard_BracketRight, 216 },
{ LedId.Keyboard_Backslash, 220 },
{ LedId.Keyboard_Delete, 224 },
{ LedId.Keyboard_End, 228 },
{ LedId.Keyboard_PageDown, 232 },
{ LedId.Keyboard_Num7, 236 },
{ LedId.Keyboard_Num8, 240 },
{ LedId.Keyboard_Num9, 244 },
{ LedId.Keyboard_NumPlus, 248 },
{ LedId.Keyboard_CapsLock, 252 },
{ LedId.Keyboard_A, 256 },
{ LedId.Keyboard_S, 260 },
{ LedId.Keyboard_D, 264 },
{ LedId.Keyboard_F, 268 },
{ LedId.Keyboard_G, 272 },
{ LedId.Keyboard_H, 276 },
{ LedId.Keyboard_J, 280 },
{ LedId.Keyboard_K, 284 },
{ LedId.Keyboard_L, 288 },
{ LedId.Keyboard_SemicolonAndColon, 292 },
{ LedId.Keyboard_ApostropheAndDoubleQuote, 296 },
{ LedId.Keyboard_NonUsTilde, 300 }, //TODO DarthAffe 26.03.2017: Find the real ID/Name of this key - it's not documented ...
{ LedId.Keyboard_Enter, 304 },
// { LedId.Keyboard_?, 308 },
// { LedId.Keyboard_?, 312 },
// { LedId.Keyboard_?, 316 },
{ LedId.Keyboard_Num4, 320 },
{ LedId.Keyboard_Num5, 324 },
{ LedId.Keyboard_Num6, 328 },
// { LedId.Keyboard_?, 332 },
{ LedId.Keyboard_LeftShift, 336 },
{ LedId.Keyboard_NonUsBackslash, 340 },
{ LedId.Keyboard_Z, 344 },
{ LedId.Keyboard_X, 348 },
{ LedId.Keyboard_C, 352 },
{ LedId.Keyboard_V, 356 },
{ LedId.Keyboard_B, 360 },
{ LedId.Keyboard_N, 364 },
{ LedId.Keyboard_M, 368 },
{ LedId.Keyboard_CommaAndLessThan, 372 },
{ LedId.Keyboard_PeriodAndBiggerThan, 376 },
{ LedId.Keyboard_SlashAndQuestionMark, 380 },
{ LedId.Keyboard_RightShift, 388 },
// { LedId.Keyboard_?, 392 },
{ LedId.Keyboard_ArrowUp, 396 },
// { LedId.Keyboard_?, 400 },
{ LedId.Keyboard_Num1, 404 },
{ LedId.Keyboard_Num2, 408 },
{ LedId.Keyboard_Num3, 412 },
{ LedId.Keyboard_NumEnter, 416 },
{ LedId.Keyboard_LeftCtrl, 420 },
{ LedId.Keyboard_LeftGui, 424 },
{ LedId.Keyboard_LeftAlt, 428 },
// { LedId.Keyboard_?, 432 },
// { LedId.Keyboard_?, 436 },
{ LedId.Keyboard_Space, 440 },
// { LedId.Keyboard_?, 444 },
// { LedId.Keyboard_?, 448 },
// { LedId.Keyboard_?, 452 },
// { LedId.Keyboard_?, 456 },
// { LedId.Keyboard_?, 460 },
{ LedId.Keyboard_RightAlt, 464 },
{ LedId.Keyboard_RightGui, 468 },
{ LedId.Keyboard_Application, 472 },
{ LedId.Keyboard_RightCtrl, 476 },
{ LedId.Keyboard_ArrowLeft, 480 },
{ LedId.Keyboard_ArrowDown, 484 },
{ LedId.Keyboard_ArrowRight, 488 },
{ LedId.Keyboard_Num0, 492 },
{ LedId.Keyboard_NumPeriodAndDelete, 496 },
// { LedId.Keyboard_?, 500 },
};
#endregion
#region Methods
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -9,23 +9,30 @@ namespace RGB.NET.Devices.Logitech
/// </summary>
public class LogitechPerKeyRGBDevice : LogitechRGBDevice<LogitechRGBDeviceInfo>, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated
{
#region Properties & Fields
private readonly LedMapping<int> _ledMapping;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechPerKeyRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by logitech for the per-key-lightable device</param>
internal LogitechPerKeyRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue)
internal LogitechPerKeyRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue, LedMapping<int> ledMapping)
: base(info, updateQueue)
{ }
{
this._ledMapping = ledMapping;
}
#endregion
#region Methods
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => (ledId, PerKeyIdMapping.DEFAULT.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : LogitechLedId.Invalid);
protected override object GetLedCustomData(LedId ledId) => _ledMapping.TryGetValue(ledId, out int logitechLedId) ? logitechLedId : -1;
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate));
@@ -37,26 +37,10 @@ namespace RGB.NET.Devices.Logitech
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
Array.Clear(_bitmap, 0, _bitmap.Length);
bool usesBitmap = false;
foreach ((object key, Color color) in dataSet)
{
(LedId id, LogitechLedId customData) = ((LedId, LogitechLedId))key;
BitmapMapping.SetColor(_bitmap, (int)key, color);
// DarthAffe 26.03.2017: This is only needed since update by name doesn't work as expected for all keys ...
if (BitmapMapping.BitmapOffset.TryGetValue(id, out int bitmapOffset))
{
BitmapMapping.SetColor(_bitmap, bitmapOffset, color);
usesBitmap = true;
}
else
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)customData,
(int)MathF.Round(color.R * 100),
(int)MathF.Round(color.G * 100),
(int)MathF.Round(color.B * 100));
}
if (usesBitmap)
_LogitechGSDK.LogiLedSetLightingFromBitmap(_bitmap);
_LogitechGSDK.LogiLedSetLightingFromBitmap(_bitmap);
}
#endregion
@@ -1,130 +0,0 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
{
internal static class PerKeyIdMapping
{
internal static readonly Dictionary<LedId, LogitechLedId> DEFAULT = new()
{
{ LedId.Invalid, LogitechLedId.Invalid },
{ LedId.Keyboard_Escape, LogitechLedId.ESC },
{ LedId.Keyboard_F1, LogitechLedId.F1 },
{ LedId.Keyboard_F2, LogitechLedId.F2 },
{ LedId.Keyboard_F3, LogitechLedId.F3 },
{ LedId.Keyboard_F4, LogitechLedId.F4 },
{ LedId.Keyboard_F5, LogitechLedId.F5 },
{ LedId.Keyboard_F6, LogitechLedId.F6 },
{ LedId.Keyboard_F7, LogitechLedId.F7 },
{ LedId.Keyboard_F8, LogitechLedId.F8 },
{ LedId.Keyboard_F9, LogitechLedId.F9 },
{ LedId.Keyboard_F10, LogitechLedId.F10 },
{ LedId.Keyboard_F11, LogitechLedId.F11 },
{ LedId.Keyboard_GraveAccentAndTilde, LogitechLedId.TILDE },
{ LedId.Keyboard_1, LogitechLedId.ONE },
{ LedId.Keyboard_2, LogitechLedId.TWO },
{ LedId.Keyboard_3, LogitechLedId.THREE },
{ LedId.Keyboard_4, LogitechLedId.FOUR },
{ LedId.Keyboard_5, LogitechLedId.FIVE },
{ LedId.Keyboard_6, LogitechLedId.SIX },
{ LedId.Keyboard_7, LogitechLedId.SEVEN },
{ LedId.Keyboard_8, LogitechLedId.EIGHT },
{ LedId.Keyboard_9, LogitechLedId.NINE },
{ LedId.Keyboard_0, LogitechLedId.ZERO },
{ LedId.Keyboard_MinusAndUnderscore, LogitechLedId.MINUS },
{ LedId.Keyboard_Tab, LogitechLedId.TAB },
{ LedId.Keyboard_Q, LogitechLedId.Q },
{ LedId.Keyboard_W, LogitechLedId.W },
{ LedId.Keyboard_E, LogitechLedId.E },
{ LedId.Keyboard_R, LogitechLedId.R },
{ LedId.Keyboard_T, LogitechLedId.T },
{ LedId.Keyboard_Y, LogitechLedId.Y },
{ LedId.Keyboard_U, LogitechLedId.U },
{ LedId.Keyboard_I, LogitechLedId.I },
{ LedId.Keyboard_O, LogitechLedId.O },
{ LedId.Keyboard_P, LogitechLedId.P },
{ LedId.Keyboard_BracketLeft, LogitechLedId.OPEN_BRACKET },
{ LedId.Keyboard_CapsLock, LogitechLedId.CAPS_LOCK },
{ LedId.Keyboard_A, LogitechLedId.A },
{ LedId.Keyboard_S, LogitechLedId.S },
{ LedId.Keyboard_D, LogitechLedId.D },
{ LedId.Keyboard_F, LogitechLedId.F },
{ LedId.Keyboard_G, LogitechLedId.G },
{ LedId.Keyboard_H, LogitechLedId.H },
{ LedId.Keyboard_J, LogitechLedId.J },
{ LedId.Keyboard_K, LogitechLedId.K },
{ LedId.Keyboard_L, LogitechLedId.L },
{ LedId.Keyboard_SemicolonAndColon, LogitechLedId.SEMICOLON },
{ LedId.Keyboard_ApostropheAndDoubleQuote, LogitechLedId.APOSTROPHE },
{ LedId.Keyboard_LeftShift, LogitechLedId.LEFT_SHIFT },
{ LedId.Keyboard_Z, LogitechLedId.Z },
{ LedId.Keyboard_X, LogitechLedId.X },
{ LedId.Keyboard_C, LogitechLedId.C },
{ LedId.Keyboard_V, LogitechLedId.V },
{ LedId.Keyboard_B, LogitechLedId.B },
{ LedId.Keyboard_N, LogitechLedId.N },
{ LedId.Keyboard_M, LogitechLedId.M },
{ LedId.Keyboard_CommaAndLessThan, LogitechLedId.COMMA },
{ LedId.Keyboard_PeriodAndBiggerThan, LogitechLedId.PERIOD },
{ LedId.Keyboard_SlashAndQuestionMark, LogitechLedId.FORWARD_SLASH },
{ LedId.Keyboard_LeftCtrl, LogitechLedId.LEFT_CONTROL },
{ LedId.Keyboard_LeftGui, LogitechLedId.LEFT_WINDOWS },
{ LedId.Keyboard_LeftAlt, LogitechLedId.LEFT_ALT },
{ LedId.Keyboard_Space, LogitechLedId.SPACE },
{ LedId.Keyboard_RightAlt, LogitechLedId.RIGHT_ALT },
{ LedId.Keyboard_RightGui, LogitechLedId.RIGHT_WINDOWS },
{ LedId.Keyboard_Application, LogitechLedId.APPLICATION_SELECT },
{ LedId.Keyboard_F12, LogitechLedId.F12 },
{ LedId.Keyboard_PrintScreen, LogitechLedId.PRINT_SCREEN },
{ LedId.Keyboard_ScrollLock, LogitechLedId.SCROLL_LOCK },
{ LedId.Keyboard_PauseBreak, LogitechLedId.PAUSE_BREAK },
{ LedId.Keyboard_Insert, LogitechLedId.INSERT },
{ LedId.Keyboard_Home, LogitechLedId.HOME },
{ LedId.Keyboard_PageUp, LogitechLedId.PAGE_UP },
{ LedId.Keyboard_BracketRight, LogitechLedId.CLOSE_BRACKET },
{ LedId.Keyboard_NonUsBackslash, LogitechLedId.BACKSLASH },
{ LedId.Keyboard_Backslash, LogitechLedId.BACKSLASH },
{ LedId.Keyboard_NonUsTilde, LogitechLedId.NonUsTilde },
{ LedId.Keyboard_Enter, LogitechLedId.ENTER },
{ LedId.Keyboard_EqualsAndPlus, LogitechLedId.EQUALS },
{ LedId.Keyboard_Backspace, LogitechLedId.BACKSPACE },
{ LedId.Keyboard_Delete, LogitechLedId.KEYBOARD_DELETE },
{ LedId.Keyboard_End, LogitechLedId.END },
{ LedId.Keyboard_PageDown, LogitechLedId.PAGE_DOWN },
{ LedId.Keyboard_RightShift, LogitechLedId.RIGHT_SHIFT },
{ LedId.Keyboard_RightCtrl, LogitechLedId.RIGHT_CONTROL },
{ LedId.Keyboard_ArrowUp, LogitechLedId.ARROW_UP },
{ LedId.Keyboard_ArrowLeft, LogitechLedId.ARROW_LEFT },
{ LedId.Keyboard_ArrowDown, LogitechLedId.ARROW_DOWN },
{ LedId.Keyboard_ArrowRight, LogitechLedId.ARROW_RIGHT },
{ LedId.Keyboard_NumLock, LogitechLedId.NUM_LOCK },
{ LedId.Keyboard_NumSlash, LogitechLedId.NUM_SLASH },
{ LedId.Keyboard_NumAsterisk, LogitechLedId.NUM_ASTERISK },
{ LedId.Keyboard_NumMinus, LogitechLedId.NUM_MINUS },
{ LedId.Keyboard_NumPlus, LogitechLedId.NUM_PLUS },
{ LedId.Keyboard_NumEnter, LogitechLedId.NUM_ENTER },
{ LedId.Keyboard_Num7, LogitechLedId.NUM_SEVEN },
{ LedId.Keyboard_Num8, LogitechLedId.NUM_EIGHT },
{ LedId.Keyboard_Num9, LogitechLedId.NUM_NINE },
{ LedId.Keyboard_Num4, LogitechLedId.NUM_FOUR },
{ LedId.Keyboard_Num5, LogitechLedId.NUM_FIVE },
{ LedId.Keyboard_Num6, LogitechLedId.NUM_SIX },
{ LedId.Keyboard_Num1, LogitechLedId.NUM_ONE },
{ LedId.Keyboard_Num2, LogitechLedId.NUM_TWO },
{ LedId.Keyboard_Num3, LogitechLedId.NUM_THREE },
{ LedId.Keyboard_Num0, LogitechLedId.NUM_ZERO },
{ LedId.Keyboard_NumPeriodAndDelete, LogitechLedId.NUM_PERIOD },
{ LedId.Keyboard_Programmable1, LogitechLedId.G_1 },
{ LedId.Keyboard_Programmable2, LogitechLedId.G_2 },
{ LedId.Keyboard_Programmable3, LogitechLedId.G_3 },
{ LedId.Keyboard_Programmable4, LogitechLedId.G_4 },
{ LedId.Keyboard_Programmable5, LogitechLedId.G_5 },
{ LedId.Keyboard_Programmable6, LogitechLedId.G_6 },
{ LedId.Keyboard_Programmable7, LogitechLedId.G_7 },
{ LedId.Keyboard_Programmable8, LogitechLedId.G_8 },
{ LedId.Keyboard_Programmable9, LogitechLedId.G_9 },
{ LedId.Logo, LogitechLedId.G_LOGO },
{ LedId.Keyboard_Custom1, LogitechLedId.G_BADGE },
};
}
}
@@ -52,6 +52,6 @@
<ItemGroup>
<ProjectReference Include="..\RGB.NET.Core\RGB.NET.Core.csproj" />
<PackageReference Include="HidSharp" Version="2.1.0" />
<ProjectReference Include="..\RGB.NET.HID\RGB.NET.HID.csproj" />
</ItemGroup>
</Project>
@@ -9,22 +9,9 @@ namespace RGB.NET.Devices.Logitech
/// </summary>
public class LogitechZoneRGBDevice : LogitechRGBDevice<LogitechRGBDeviceInfo>, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated
{
#region Constants
private static readonly Dictionary<RGBDeviceType, LedId> BASE_LED_MAPPING = new()
{
{ RGBDeviceType.Keyboard, LedId.Keyboard_Programmable1 },
{ RGBDeviceType.Mouse, LedId.Mouse1 },
{ RGBDeviceType.Headset, LedId.Headset1 },
{ RGBDeviceType.Mousepad, LedId.Mousepad1 },
{ RGBDeviceType.Speaker, LedId.Speaker1 }
};
#endregion
#region Properties & Fields
private LedId _baseLedId;
private readonly LedMapping<int> _ledMapping;
#endregion
@@ -34,11 +21,10 @@ namespace RGB.NET.Devices.Logitech
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechZoneRGBDevice" /> class.
/// </summary>
/// <param name="info">The specific information provided by logitech for the zone-lightable device</param>
internal LogitechZoneRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue)
internal LogitechZoneRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue, LedMapping<int> ledMapping)
: base(info, updateQueue)
{
_baseLedId = BASE_LED_MAPPING.TryGetValue(info.DeviceType, out LedId id) ? id : LedId.Custom1;
this._ledMapping = ledMapping;
InitializeLayout();
}
@@ -50,11 +36,11 @@ namespace RGB.NET.Devices.Logitech
private void InitializeLayout()
{
for (int i = 0; i < DeviceInfo.Zones; i++)
AddLed(_baseLedId + i, new Point(i * 10, 0), new Size(10, 10));
AddLed(_ledMapping[i], new Point(i * 10, 0), new Size(10, 10));
}
/// <inheritdoc />
protected override object? GetLedCustomData(LedId ledId) => (int)(ledId - _baseLedId);
protected override object? GetLedCustomData(LedId ledId) => _ledMapping[ledId];
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate));
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.Native;
@@ -10,19 +9,6 @@ namespace RGB.NET.Devices.Logitech
/// </summary>
public class LogitechZoneUpdateQueue : UpdateQueue
{
#region Constants
private static readonly Dictionary<RGBDeviceType, LogitechDeviceType> DEVICE_TYPE_MAPPING = new()
{
{ RGBDeviceType.Keyboard, LogitechDeviceType.Keyboard },
{ RGBDeviceType.Mouse, LogitechDeviceType.Mouse },
{ RGBDeviceType.Headset, LogitechDeviceType.Headset },
{ RGBDeviceType.Mousepad, LogitechDeviceType.Mousemat },
{ RGBDeviceType.Speaker, LogitechDeviceType.Speaker }
};
#endregion
#region Properties & Fields
private readonly LogitechDeviceType _deviceType;
@@ -36,11 +22,10 @@ namespace RGB.NET.Devices.Logitech
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
/// <param name="deviceType">The tpye of the device this queue is updating.</param>
public LogitechZoneUpdateQueue(IDeviceUpdateTrigger updateTrigger, RGBDeviceType deviceType)
public LogitechZoneUpdateQueue(IDeviceUpdateTrigger updateTrigger, LogitechDeviceType deviceType)
: base(updateTrigger)
{
if (!DEVICE_TYPE_MAPPING.TryGetValue(deviceType, out _deviceType))
throw new ArgumentException($"Invalid type '{deviceType.ToString()}'", nameof(deviceType));
this._deviceType = deviceType;
}
#endregion