This commit is contained in:
DarthAffe committed 2021-11-23 23:22:54 +01:00
commit 02c4be2fa4
374 files changed
+35975 -35860

No files matched your search

@@ -4,15 +4,14 @@ using System;
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
[Flags]
public enum LogitechDeviceCaps
{
[Flags]
public enum LogitechDeviceCaps
{
None = 0,
Monochrome = 1 << 0,
DeviceRGB = 1 << 1,
PerKeyRGB = 1 << 2,
All = Monochrome | DeviceRGB | PerKeyRGB
}
}
None = 0,
Monochrome = 1 << 0,
DeviceRGB = 1 << 1,
PerKeyRGB = 1 << 2,
All = Monochrome | DeviceRGB | PerKeyRGB
}
@@ -1,16 +1,15 @@
#pragma warning disable 1591
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <summary>
/// Contains list of available logitech device types.
/// </summary>
public enum LogitechDeviceType
{
/// <summary>
/// Contains list of available logitech device types.
/// </summary>
public enum LogitechDeviceType
{
Keyboard = 0x0,
Mouse = 0x3,
Mousemat = 0x4,
Headset = 0x8,
Speaker = 0xE
}
}
Keyboard = 0x0,
Mouse = 0x3,
Mousemat = 0x4,
Headset = 0x8,
Speaker = 0xE
}
+124 -125
View File
@@ -1,129 +1,128 @@
// ReSharper disable InconsistentNaming
#pragma warning disable 1591
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <summary>
/// Contains a list of Logitech LED IDs
/// </summary>
public enum LogitechLedId
{
/// <summary>
/// Contains a list of Logitech LED IDs
/// </summary>
public enum LogitechLedId
{
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 = 0x145,
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 = 0x45,
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,
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,
ISO_BACKSLASH = 0x56,
ISO_TILDE = 0x5D,
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
};
}
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 = 0x145,
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 = 0x45,
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,
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,
ISO_BACKSLASH = 0x56,
ISO_TILDE = 0x5D,
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
};
@@ -3,30 +3,29 @@
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <summary>
/// Contains list of available logical layouts for logitech keyboards.
/// </summary>
public enum LogitechLogicalKeyboardLayout
{
/// <summary>
/// Contains list of available logical layouts for logitech keyboards.
/// </summary>
public enum LogitechLogicalKeyboardLayout
{
US_Int = 1,
NA = 2,
EU = 3,
UK = 4,
BE = 5,
BR = 6,
CH = 7,
CN = 8,
DE = 9,
ES = 10,
FR = 11,
IT = 12,
ND = 13,
RU = 14,
JP = 15,
KR = 16,
TW = 17,
MEX = 18
};
}
US_Int = 1,
NA = 2,
EU = 3,
UK = 4,
BE = 5,
BR = 6,
CH = 7,
CN = 8,
DE = 9,
ES = 10,
FR = 11,
IT = 12,
ND = 13,
RU = 14,
JP = 15,
KR = 16,
TW = 17,
MEX = 18
};
@@ -1,36 +1,35 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable InconsistentNaming
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <summary>
/// Contains list of available physical layouts for logitech keyboards.
/// </summary>
public enum LogitechPhysicalKeyboardLayout
{
/// <summary>
/// Contains list of available physical layouts for logitech keyboards.
/// US-Keyboard
/// </summary>
public enum LogitechPhysicalKeyboardLayout
{
/// <summary>
/// US-Keyboard
/// </summary>
US = 1,
US = 1,
/// <summary>
/// UK-Keyboard
/// </summary>
UK = 2,
/// <summary>
/// UK-Keyboard
/// </summary>
UK = 2,
/// <summary>
/// BR-Keyboard
/// </summary>
BR = 3,
/// <summary>
/// BR-Keyboard
/// </summary>
BR = 3,
/// <summary>
/// JP-Keyboard
/// </summary>
JP = 4,
/// <summary>
/// JP-Keyboard
/// </summary>
JP = 4,
/// <summary>
/// KR-Keyboard
/// </summary>
KR = 5
}
}
/// <summary>
/// KR-Keyboard
/// </summary>
KR = 5
}
@@ -1,10 +1,9 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
{
/// <summary>
/// Represents a logitech RGB-device.
/// </summary>
public interface ILogitechRGBDevice : IRGBDevice
{ }
}
namespace RGB.NET.Devices.Logitech;
/// <summary>
/// Represents a logitech RGB-device.
/// </summary>
public interface ILogitechRGBDevice : IRGBDevice
{ }
+324 -325
View File
@@ -1,343 +1,342 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <summary>
/// Contains mappings for <see cref="LedId"/> to <see cref="LogitechDeviceCaps"/>.
/// </summary>
public static class LedMappings
{
/// <summary>
/// Contains mappings for <see cref="LedId"/> to <see cref="LogitechDeviceCaps"/>.
/// Gets the mapping for per key devices.
/// </summary>
public static class LedMappings
public static LedMapping<LogitechLedId> PerKey { get; } = new()
{
/// <summary>
/// Gets the mapping for per key devices.
/// </summary>
public static LedMapping<LogitechLedId> PerKey { get; } = new()
{
{ 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_F12, LogitechLedId.F12 },
{ LedId.Keyboard_PrintScreen, LogitechLedId.PRINT_SCREEN },
{ LedId.Keyboard_ScrollLock, LogitechLedId.SCROLL_LOCK },
{ LedId.Keyboard_PauseBreak, LogitechLedId.PAUSE_BREAK },
{ 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_F12, LogitechLedId.F12 },
{ LedId.Keyboard_PrintScreen, LogitechLedId.PRINT_SCREEN },
{ LedId.Keyboard_ScrollLock, LogitechLedId.SCROLL_LOCK },
{ LedId.Keyboard_PauseBreak, LogitechLedId.PAUSE_BREAK },
{ 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_EqualsAndPlus, LogitechLedId.EQUALS },
{ LedId.Keyboard_Backspace, LogitechLedId.BACKSPACE },
{ LedId.Keyboard_Insert, LogitechLedId.INSERT },
{ LedId.Keyboard_Home, LogitechLedId.HOME },
{ LedId.Keyboard_PageUp, LogitechLedId.PAGE_UP },
{ 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_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_EqualsAndPlus, LogitechLedId.EQUALS },
{ LedId.Keyboard_Backspace, LogitechLedId.BACKSPACE },
{ LedId.Keyboard_Insert, LogitechLedId.INSERT },
{ LedId.Keyboard_Home, LogitechLedId.HOME },
{ LedId.Keyboard_PageUp, LogitechLedId.PAGE_UP },
{ 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_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_BracketRight, LogitechLedId.CLOSE_BRACKET },
{ LedId.Keyboard_Backslash, LogitechLedId.BACKSLASH },
{ LedId.Keyboard_Delete, LogitechLedId.KEYBOARD_DELETE },
{ LedId.Keyboard_End, LogitechLedId.END },
{ LedId.Keyboard_PageDown, LogitechLedId.PAGE_DOWN },
{ LedId.Keyboard_Num7, LogitechLedId.NUM_SEVEN },
{ LedId.Keyboard_Num8, LogitechLedId.NUM_EIGHT },
{ LedId.Keyboard_Num9, LogitechLedId.NUM_NINE },
{ LedId.Keyboard_NumPlus, LogitechLedId.NUM_PLUS },
{ 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_BracketRight, LogitechLedId.CLOSE_BRACKET },
{ LedId.Keyboard_Backslash, LogitechLedId.BACKSLASH },
{ LedId.Keyboard_Delete, LogitechLedId.KEYBOARD_DELETE },
{ LedId.Keyboard_End, LogitechLedId.END },
{ LedId.Keyboard_PageDown, LogitechLedId.PAGE_DOWN },
{ LedId.Keyboard_Num7, LogitechLedId.NUM_SEVEN },
{ LedId.Keyboard_Num8, LogitechLedId.NUM_EIGHT },
{ LedId.Keyboard_Num9, LogitechLedId.NUM_NINE },
{ LedId.Keyboard_NumPlus, LogitechLedId.NUM_PLUS },
{ 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_NonUsTilde, LogitechLedId.ISO_TILDE },
{ LedId.Keyboard_Enter, LogitechLedId.ENTER },
{ LedId.Keyboard_Num4, LogitechLedId.NUM_FOUR },
{ LedId.Keyboard_Num5, LogitechLedId.NUM_FIVE },
{ LedId.Keyboard_Num6, LogitechLedId.NUM_SIX },
{ 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_NonUsTilde, LogitechLedId.ISO_TILDE },
{ LedId.Keyboard_Enter, LogitechLedId.ENTER },
{ LedId.Keyboard_Num4, LogitechLedId.NUM_FOUR },
{ LedId.Keyboard_Num5, LogitechLedId.NUM_FIVE },
{ LedId.Keyboard_Num6, LogitechLedId.NUM_SIX },
{ LedId.Keyboard_LeftShift, LogitechLedId.LEFT_SHIFT },
{ LedId.Keyboard_NonUsBackslash, LogitechLedId.ISO_BACKSLASH },
{ 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_RightShift, LogitechLedId.RIGHT_SHIFT },
{ LedId.Keyboard_ArrowUp, LogitechLedId.ARROW_UP },
{ LedId.Keyboard_Num1, LogitechLedId.NUM_ONE },
{ LedId.Keyboard_Num2, LogitechLedId.NUM_TWO },
{ LedId.Keyboard_Num3, LogitechLedId.NUM_THREE },
{ LedId.Keyboard_NumEnter, LogitechLedId.NUM_ENTER },
{ LedId.Keyboard_LeftShift, LogitechLedId.LEFT_SHIFT },
{ LedId.Keyboard_NonUsBackslash, LogitechLedId.ISO_BACKSLASH },
{ 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_RightShift, LogitechLedId.RIGHT_SHIFT },
{ LedId.Keyboard_ArrowUp, LogitechLedId.ARROW_UP },
{ LedId.Keyboard_Num1, LogitechLedId.NUM_ONE },
{ LedId.Keyboard_Num2, LogitechLedId.NUM_TWO },
{ LedId.Keyboard_Num3, LogitechLedId.NUM_THREE },
{ LedId.Keyboard_NumEnter, LogitechLedId.NUM_ENTER },
{ 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_RightCtrl, LogitechLedId.RIGHT_CONTROL },
{ LedId.Keyboard_ArrowLeft, LogitechLedId.ARROW_LEFT },
{ LedId.Keyboard_ArrowDown, LogitechLedId.ARROW_DOWN },
{ LedId.Keyboard_ArrowRight, LogitechLedId.ARROW_RIGHT },
{ LedId.Keyboard_Num0, LogitechLedId.NUM_ZERO },
{ LedId.Keyboard_NumPeriodAndDelete, LogitechLedId.NUM_PERIOD },
{ 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_RightCtrl, LogitechLedId.RIGHT_CONTROL },
{ LedId.Keyboard_ArrowLeft, LogitechLedId.ARROW_LEFT },
{ LedId.Keyboard_ArrowDown, LogitechLedId.ARROW_DOWN },
{ LedId.Keyboard_ArrowRight, LogitechLedId.ARROW_RIGHT },
{ 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 },
};
{ 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 },
};
/// <summary>
/// Gets the mapping for per device devices.
/// </summary>
public static LedMapping<int> Device { get; } = new()
{
{ LedId.Custom1, 0 }
};
/// <summary>
/// Gets the mapping for per device devices.
/// </summary>
public static LedMapping<int> Device { get; } = new()
{
{ LedId.Custom1, 0 }
};
/// <summary>
/// Gets the mapping for per zone keyboards.
/// </summary>
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 },
};
/// <summary>
/// Gets the mapping for per zone keyboards.
/// </summary>
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 },
};
/// <summary>
/// Gets the mapping for per zone mice.
/// </summary>
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 },
};
/// <summary>
/// Gets the mapping for per zone mice.
/// </summary>
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 },
};
/// <summary>
/// Gets the mapping for per zone headsets.
/// </summary>
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 },
};
/// <summary>
/// Gets the mapping for per zone headsets.
/// </summary>
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 },
};
/// <summary>
/// Gets the mapping for per zone mousepads.
/// </summary>
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 },
};
/// <summary>
/// Gets the mapping for per zone mousepads.
/// </summary>
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 },
};
/// <summary>
/// Gets the mapping for per zone speakers.
/// </summary>
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 },
};
}
}
/// <summary>
/// Gets the mapping for per zone speakers.
/// </summary>
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,25 +1,24 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a generic Logitech-device. (keyboard, mouse, headset, mousepad).
/// </summary>
public abstract class LogitechRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, ILogitechRGBDevice
where TDeviceInfo : LogitechRGBDeviceInfo
{
/// <inheritdoc cref="AbstractRGBDevice{TDeviceInfo}" />
#region Constructors
/// <summary>
/// Represents a generic Logitech-device. (keyboard, mouse, headset, mousepad).
/// Initializes a new instance of the <see cref="LogitechRGBDevice{TDeviceInfo}"/> class.
/// </summary>
public abstract class LogitechRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceInfo>, ILogitechRGBDevice
where TDeviceInfo : LogitechRGBDeviceInfo
{
#region Constructors
/// <param name="info">The generic information provided by Logitech for the device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
protected LogitechRGBDevice(TDeviceInfo info, IUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="LogitechRGBDevice{TDeviceInfo}"/> class.
/// </summary>
/// <param name="info">The generic information provided by Logitech for the device.</param>
/// <param name="updateQueue">The queue used to update this device.</param>
protected LogitechRGBDevice(TDeviceInfo info, IUpdateQueue updateQueue)
: base(info, updateQueue)
{ }
#endregion
}
}
#endregion
}
@@ -1,68 +1,67 @@
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <inheritdoc />
/// <summary>
/// Represents a generic information for a Logitech-<see cref="T:RGB.NET.Core.IRGBDevice" />.
/// </summary>
public class LogitechRGBDeviceInfo : IRGBDeviceInfo
{
#region Properties & Fields
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer => "Logitech";
/// <inheritdoc />
public string Model { get; }
/// <inheritdoc />
public object? LayoutMetadata { get; set; }
/// <summary>
/// Represents a generic information for a Logitech-<see cref="T:RGB.NET.Core.IRGBDevice" />.
/// Gets a flag that describes device capabilities. (<see cref="LogitechDeviceCaps" />)
/// </summary>
public class LogitechRGBDeviceInfo : IRGBDeviceInfo
public LogitechDeviceCaps DeviceCaps { get; }
/// <summary>
/// Gets the amount of zones the <see cref="LogitechRGBDevice{TDeviceInfo}"/> is able to control (0 for single-color and per-key devices)
/// </summary>
public int Zones { get; }
/// <summary>
/// Gets the zone at which LEDs start being mapped
/// </summary>
public int ZoneOffset { get; }
#endregion
#region Constructors
/// <summary>
/// Internal constructor of managed <see cref="LogitechRGBDeviceInfo"/>.
/// </summary>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The represented device model.</param>
/// <param name="deviceCaps">The lighting-capabilities of the device.</param>
/// <param name="zones">The amount of zones the device is able to control.</param>
/// <param name="zoneOffset">The zone at which to start mapping LEDs.</param>
internal LogitechRGBDeviceInfo(RGBDeviceType deviceType, string model, LogitechDeviceCaps deviceCaps, int zones, int zoneOffset = 0)
{
#region Properties & Fields
this.DeviceType = deviceType;
this.Model = model;
this.DeviceCaps = deviceCaps;
this.Zones = zones;
this.ZoneOffset = zoneOffset;
/// <inheritdoc />
public RGBDeviceType DeviceType { get; }
/// <inheritdoc />
public string DeviceName { get; }
/// <inheritdoc />
public string Manufacturer => "Logitech";
/// <inheritdoc />
public string Model { get; }
/// <inheritdoc />
public object? LayoutMetadata { get; set; }
/// <summary>
/// Gets a flag that describes device capabilities. (<see cref="LogitechDeviceCaps" />)
/// </summary>
public LogitechDeviceCaps DeviceCaps { get; }
/// <summary>
/// Gets the amount of zones the <see cref="LogitechRGBDevice{TDeviceInfo}"/> is able to control (0 for single-color and per-key devices)
/// </summary>
public int Zones { get; }
/// <summary>
/// Gets the zone at which LEDs start being mapped
/// </summary>
public int ZoneOffset { get; }
#endregion
#region Constructors
/// <summary>
/// Internal constructor of managed <see cref="LogitechRGBDeviceInfo"/>.
/// </summary>
/// <param name="deviceType">The type of the <see cref="IRGBDevice"/>.</param>
/// <param name="model">The represented device model.</param>
/// <param name="deviceCaps">The lighting-capabilities of the device.</param>
/// <param name="zones">The amount of zones the device is able to control.</param>
/// <param name="zoneOffset">The zone at which to start mapping LEDs.</param>
internal LogitechRGBDeviceInfo(RGBDeviceType deviceType, string model, LogitechDeviceCaps deviceCaps, int zones, int zoneOffset = 0)
{
this.DeviceType = deviceType;
this.Model = model;
this.DeviceCaps = deviceCaps;
this.Zones = zones;
this.ZoneOffset = zoneOffset;
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
}
#endregion
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
}
}
#endregion
}
@@ -0,0 +1,49 @@
using HidSharp;
using HidSharp.Reports.Encodings;
using System;
using System.Linq;
using System.Runtime.InteropServices;
namespace RGB.NET.Devices.Logitech.HID;
internal static class Extensions
{
internal static Span<byte> AsSpan<T>(this ref T val)
where T : unmanaged
{
Span<T> valSpan = MemoryMarshal.CreateSpan(ref val, 1);
return MemoryMarshal.Cast<T, byte>(valSpan);
}
internal static uint GetUsagePage(this HidDevice device)
{
try
{
return device.GetItemByType(ItemType.Global)?.DataValue ?? uint.MaxValue;
}
catch
{
return uint.MaxValue;
}
}
internal static uint GetUsage(this HidDevice device)
{
try
{
return device.GetItemByType(ItemType.Local)?.DataValue ?? uint.MaxValue;
}
catch
{
return uint.MaxValue;
}
}
private static EncodedItem? GetItemByType(this HidDevice device, ItemType itemType)
{
byte[] descriptor = device.GetRawReportDescriptor();
return EncodedItem.DecodeItems(descriptor, 0, descriptor.Length)
.Where(de => (de.TagForLocal == LocalItemTag.Usage) && (de.TagForGlobal == GlobalItemTag.UsagePage))
.FirstOrDefault(de => de.ItemType == itemType);
}
}
@@ -0,0 +1,72 @@
using System.Runtime.InteropServices;
namespace RGB.NET.Devices.Logitech.HID;
[StructLayout(LayoutKind.Sequential, Pack = 0, Size = 64)]
internal struct FapResponse
{
public byte Command;
public byte DeviceIndex;
public byte FeatureIndex;
public byte FeatureCommand;
public byte Data00;
public byte Data01;
public byte Data02;
public byte Data03;
public byte Data04;
public byte Data05;
public byte Data06;
public byte Data07;
public byte Data08;
public byte Data09;
public byte Data10;
public byte Data11;
public byte Data12;
public byte Data13;
public byte Data14;
public byte Data15;
public byte Data16;
public byte Data17;
public byte Data18;
public byte Data19;
public byte Data20;
public byte Data21;
public byte Data22;
public byte Data23;
public byte Data24;
public byte Data25;
public byte Data26;
public byte Data27;
public byte Data28;
public byte Data29;
public byte Data30;
public byte Data31;
public byte Data32;
public byte Data33;
public byte Data34;
public byte Data35;
public byte Data36;
public byte Data37;
public byte Data38;
public byte Data39;
public byte Data40;
public byte Data41;
public byte Data42;
public byte Data43;
public byte Data44;
public byte Data45;
public byte Data46;
public byte Data47;
public byte Data48;
public byte Data49;
public byte Data50;
public byte Data51;
public byte Data52;
public byte Data53;
public byte Data54;
public byte Data55;
public byte Data56;
public byte Data57;
public byte Data58;
public byte Data59;
}
@@ -0,0 +1,41 @@
using System.Runtime.InteropServices;
namespace RGB.NET.Devices.Logitech.HID;
[StructLayout(LayoutKind.Sequential, Pack = 0, Size = 7)]
internal struct FapShortRequest
{
#region Constants
private const byte LOGITECH_SHORT_MESSAGE = 0x10;
#endregion
#region Properties & Fields
public byte ReportId;
public byte DeviceIndex;
public byte FeatureIndex;
public byte FeatureCommand;
public byte Data0;
public byte Data1;
public byte Data2;
#endregion
#region Constructors
public void Init(byte deviceIndex, byte featureIndex)
{
this.DeviceIndex = deviceIndex;
this.FeatureIndex = featureIndex;
ReportId = LOGITECH_SHORT_MESSAGE;
FeatureCommand = 0;
Data0 = 0;
Data1 = 0;
Data2 = 0;
}
#endregion
}
@@ -0,0 +1,181 @@
using HidSharp;
using RGB.NET.Core;
using RGB.NET.HID;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace RGB.NET.Devices.Logitech.HID;
/// <summary>
/// Represents a loaded for logitech HID-devices.
/// </summary>
/// <typeparam name="TLed">The type of the identifier leds are mapped to.</typeparam>
/// <typeparam name="TData">The type of the custom data added to the HID-device.</typeparam>
public class LightspeedHIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefinition<TLed, TData>>
where TLed : notnull
{
#region Constants
private const int VENDOR_ID = 0x046D;
// ReSharper disable once StaticMemberInGenericType - This is used like a const
private static readonly List<int> RECEIVER_PIDS = new()
{
0xC539,
0xC53A,
0xC541,
0xC545
};
#endregion
#region Properties & Fields
private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = new();
/// <summary>
/// Gets the vendor id used for this loader.
/// </summary>
public int VendorId => VENDOR_ID;
/// <summary>
/// Gets or sets the filter used to determine which devices should be loaded.
/// </summary>
public RGBDeviceType LoadFilter { get; set; } = RGBDeviceType.All;
#endregion
#region Methods
/// <summary>
/// Adds a new <see cref="HIDDeviceDefinition{TLed,TData}"/> to this loader.
/// </summary>
/// <param name="virtualPid">The virtual product id of the HID-device.</param>
/// <param name="deviceType">The type of the device.</param>
/// <param name="name">The name of the device.</param>
/// <param name="ledMapping">The mapping of the leds of the device.</param>
/// <param name="customData">Some custom data to attach to the device.</param>
public void Add(int virtualPid, RGBDeviceType deviceType, string name, LedMapping<TLed> ledMapping, TData customData)
=> _deviceDefinitions.Add(virtualPid, new HIDDeviceDefinition<TLed, TData>(virtualPid, deviceType, name, ledMapping, customData));
/// <summary>
/// Gets a enumerable containing all devices from the definition-list that are connected and match the <see cref="LoadFilter"/>.
/// </summary>
/// <returns>The enumerable containing the connected devices.</returns>
public IEnumerable<HIDDeviceDefinition<TLed, TData>> GetConnectedDevices()
{
foreach (int device in Detect())
{
if (_deviceDefinitions.TryGetValue(device, out HIDDeviceDefinition<TLed, TData>? definition))
if (LoadFilter.HasFlag(definition.DeviceType))
yield return definition;
}
}
/// <summary>
/// Gets a enumerable containing all the first device of each group of devices from the definition-list that are connected and match the <see cref="LoadFilter"/>.
/// The grouping is done by the specified function.
/// </summary>
/// <typeparam name="TKey">The type of the key used to group the devices.</typeparam>
/// <param name="groupBy">The function grouping the devices.</param>
/// <returns>The enumerable containing the selected devices.</returns>
public IEnumerable<HIDDeviceDefinition<TLed, TData>> GetConnectedDevices<TKey>(Func<HIDDeviceDefinition<TLed, TData>, TKey> groupBy)
=> GetConnectedDevices().GroupBy(groupBy)
.Select(group => group.First());
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
/// <inheritdoc />
public IEnumerator<HIDDeviceDefinition<TLed, TData>> GetEnumerator() => _deviceDefinitions.Values.GetEnumerator();
#endregion
#region Private Methods
private IEnumerable<int> Detect() => RECEIVER_PIDS.SelectMany(Detect);
private IEnumerable<int> Detect(int pid)
{
Dictionary<byte, HidDevice> deviceUsages = DeviceList.Local
.GetHidDevices(VendorId, pid)
.Where(d => d.DevicePath.Contains("mi_02"))
.ToDictionary(x => (byte)x.GetUsage(), x => x);
foreach ((int wirelessPid, byte _) in GetWirelessDevices(deviceUsages))
yield return wirelessPid;
}
private Dictionary<int, byte> GetWirelessDevices(IReadOnlyDictionary<byte, HidDevice> deviceUsages)
{
const byte LOGITECH_RECEIVER_ADDRESS = 0xFF;
const byte LOGITECH_SET_REGISTER_REQUEST = 0x80;
const byte LOGITECH_GET_REGISTER_REQUEST = 0x81;
Dictionary<int, byte> map = new();
if (deviceUsages.TryGetValue(1, out HidDevice? device))
{
HidStream? stream = device.Open();
FapResponse response = new();
FapShortRequest getConnectedDevices = new();
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_GET_REGISTER_REQUEST);
stream.Write(getConnectedDevices.AsSpan());
stream.Read(response.AsSpan());
bool wirelessNotifications = (response.Data01 & 1) == 1;
if (!wirelessNotifications)
{
response = new FapResponse();
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_SET_REGISTER_REQUEST);
getConnectedDevices.Data1 = 1;
stream.Write(getConnectedDevices.AsSpan());
stream.Read(response.AsSpan());
if (getConnectedDevices.FeatureIndex == 0x8f)
{
//error??
}
}
response = new FapResponse();
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_GET_REGISTER_REQUEST);
getConnectedDevices.FeatureCommand = 0x02;
stream.Write(getConnectedDevices.AsSpan());
stream.Read(response.AsSpan());
int deviceCount = response.Data01;
if (deviceCount > 0)
{
//log "Faking a reconnect to get device list"
deviceCount++;
getConnectedDevices.Init(LOGITECH_RECEIVER_ADDRESS, LOGITECH_SET_REGISTER_REQUEST);
getConnectedDevices.FeatureCommand = 0x02;
getConnectedDevices.Data0 = 0x02;
stream.Write(getConnectedDevices.AsSpan());
for (int i = 0; i < deviceCount; i++)
{
FapResponse devices = new();
stream.Read(devices.AsSpan());
int wirelessPid = (devices.Data02 << 8) | devices.Data01;
if (devices.DeviceIndex != 0xff)
map.Add(wirelessPid, devices.DeviceIndex);
}
}
}
return map;
}
#endregion
}
+219 -141
View File
@@ -7,186 +7,264 @@ using System.Linq;
using HidSharp;
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.Native;
using RGB.NET.Devices.Logitech.HID;
using RGB.NET.HID;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <inheritdoc />
/// <summary>
/// Represents a device provider responsible for logitech devices.
/// </summary>
public class LogitechDeviceProvider : AbstractRGBDeviceProvider
{
/// <inheritdoc />
#region Properties & Fields
private static LogitechDeviceProvider? _instance;
/// <summary>
/// Represents a device provider responsible for logitech devices.
/// Gets the singleton <see cref="LogitechDeviceProvider"/> instance.
/// </summary>
public class LogitechDeviceProvider : AbstractRGBDeviceProvider
public static LogitechDeviceProvider Instance => _instance ?? new LogitechDeviceProvider();
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/LogitechLedEnginesWrapper.dll" };
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/LogitechLedEnginesWrapper.dll" };
private LogitechPerDeviceUpdateQueue? _perDeviceUpdateQueue;
private LogitechPerKeyUpdateQueue? _perKeyUpdateQueue;
private const int VENDOR_ID = 0x046D;
/// <summary>
/// Gets the HID-definitions for wired per-key-devices.
/// </summary>
public static HIDLoader<LogitechLedId, int> PerKeyDeviceDefinitions { get; } = new(VENDOR_ID)
{
#region Properties & Fields
{ 0xC32B, RGBDeviceType.Keyboard, "G910", LedMappings.PerKey, 0 },
{ 0xC330, RGBDeviceType.Keyboard, "G410", LedMappings.PerKey, 0 },
{ 0xC331, RGBDeviceType.Keyboard, "G810", LedMappings.PerKey, 0 },
{ 0xC335, RGBDeviceType.Keyboard, "G910v2", LedMappings.PerKey, 0 },
{ 0xC337, RGBDeviceType.Keyboard, "G810", LedMappings.PerKey, 0 },
{ 0xC339, RGBDeviceType.Keyboard, "Pro", LedMappings.PerKey, 0 },
{ 0xC33C, RGBDeviceType.Keyboard, "G513", LedMappings.PerKey, 0 },
{ 0xC33E, RGBDeviceType.Keyboard, "G915", LedMappings.PerKey, 0 },
{ 0xC33F, RGBDeviceType.Keyboard, "G815", LedMappings.PerKey, 0 },
{ 0xC342, RGBDeviceType.Keyboard, "G512", LedMappings.PerKey, 0 },
{ 0xC343, RGBDeviceType.Keyboard, "G915 TKL", LedMappings.PerKey, 0 },
{ 0xC541, RGBDeviceType.Keyboard, "G915", LedMappings.PerKey, 0 },
private static LogitechDeviceProvider? _instance;
/// <summary>
/// Gets the singleton <see cref="LogitechDeviceProvider"/> instance.
/// </summary>
public static LogitechDeviceProvider Instance => _instance ?? new LogitechDeviceProvider();
//non-rgb
{ 0xC333, RGBDeviceType.Keyboard, "G610", LedMappings.PerKey, 0 },
{ 0xC338, RGBDeviceType.Keyboard, "G610", LedMappings.PerKey, 0 },
};
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/LogitechLedEnginesWrapper.dll" };
/// <summary>
/// Gets the HID-definitions for wireless per-key-devices.
/// </summary>
public static LightspeedHIDLoader<LogitechLedId, int> PerKeyWirelessDeviceDefinitions { get; } = new()
{
{ 0x407C, RGBDeviceType.Keyboard, "G915", LedMappings.PerKey, 0 },
{ 0x408E, RGBDeviceType.Keyboard, "G915 TKL", LedMappings.PerKey, 0 },
};
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/LogitechLedEnginesWrapper.dll" };
/// <summary>
/// Gets the HID-definitions for wired per-zone-devices.
/// </summary>
public static HIDLoader<int, (LogitechDeviceType deviceType, int zones)> PerZoneDeviceDefinitions { get; } = new(VENDOR_ID)
{
{ 0xC336, RGBDeviceType.Keyboard, "G213", LedMappings.ZoneKeyboard, (LogitechDeviceType.Keyboard, 5) },
private LogitechPerDeviceUpdateQueue? _perDeviceUpdateQueue;
private LogitechPerKeyUpdateQueue? _perKeyUpdateQueue;
{ 0xC092, RGBDeviceType.Mouse, "G203 Lightsync", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
{ 0xC080, RGBDeviceType.Mouse, "G303", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC081, RGBDeviceType.Mouse, "G900", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC082, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC083, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC084, RGBDeviceType.Mouse, "G203", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
{ 0xC085, RGBDeviceType.Mouse, "G Pro", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
{ 0xC086, RGBDeviceType.Mouse, "G903", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC087, RGBDeviceType.Mouse, "G703", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC088, RGBDeviceType.Mouse, "G Pro Wireless", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC08B, RGBDeviceType.Mouse, "G502 HERO", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC08C, RGBDeviceType.Mouse, "G Pro Hero", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
{ 0xC08D, RGBDeviceType.Mouse, "G502 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC08F, RGBDeviceType.Mouse, "G403 HERO", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC090, RGBDeviceType.Mouse, "G703 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC091, RGBDeviceType.Mouse, "G903 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0xC24A, RGBDeviceType.Mouse, "G600", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1) },
{ 0xC332, RGBDeviceType.Mouse, "G502", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
private const int VENDOR_ID = 0x046D;
{ 0xC53A, RGBDeviceType.Mousepad, "POWERPLAY", LedMappings.ZoneMousepad, (LogitechDeviceType.Mousemat, 1) },
/// <summary>
/// Gets the HID-definitions for per-key-devices.
/// </summary>
public static HIDLoader<LogitechLedId, 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 },
{ 0xC338, RGBDeviceType.Keyboard, "G610", LedMappings.PerKey, 0 },
{ 0xC342, RGBDeviceType.Keyboard, "G512 SE", LedMappings.PerKey, 0 },
{ 0xC33C, RGBDeviceType.Keyboard, "G513 Carbon", LedMappings.PerKey, 0 },
{ 0xC330, RGBDeviceType.Keyboard, "G410", 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 },
};
//G633 and G635 are wired headsets.
{ 0x0A5C, RGBDeviceType.Headset, "G633", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
{ 0x0A89, RGBDeviceType.Headset, "G635", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
/// <summary>
/// Gets the HID-definitions for per-zone-devices.
/// </summary>
public static HIDLoader<int, (LogitechDeviceType deviceType, int zones, int zoneOffset)> PerZoneDeviceDefinitions { get; } = new(VENDOR_ID)
{
{ 0xC336, RGBDeviceType.Keyboard, "G213", LedMappings.ZoneKeyboard, (LogitechDeviceType.Keyboard, 2, 0) },
{ 0xC086, RGBDeviceType.Mouse, "G903", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
{ 0xC081, RGBDeviceType.Mouse, "G900", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
{ 0xC539, RGBDeviceType.Mouse, "Lightspeed Mouse Dongle", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
{ 0xC087, RGBDeviceType.Mouse, "G703", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
{ 0xC08B, RGBDeviceType.Mouse, "G502 HERO", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
{ 0xC08D, RGBDeviceType.Mouse, "G502 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
{ 0xC332, RGBDeviceType.Mouse, "G502", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
{ 0xC083, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
{ 0xC080, RGBDeviceType.Mouse, "G303", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
{ 0xC084, RGBDeviceType.Mouse, "G203", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
{ 0xC085, RGBDeviceType.Mouse, "G Pro", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1, 1) },
{ 0xC088, RGBDeviceType.Mouse, "G Pro Wireless", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2, 0) },
{ 0xC08C, RGBDeviceType.Mouse, "G Pro Hero", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 1, 0) },
{ 0x0A5C, RGBDeviceType.Headset, "G633", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2, 0) },
{ 0x0A5B, RGBDeviceType.Headset, "G933", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2, 0) },
{ 0x0A87, RGBDeviceType.Headset, "G935", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2, 0) },
{ 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4, 0) },
};
//The other ones are wireless only. These PIDs correpond to the dongles.
{ 0x0A5B, RGBDeviceType.Headset, "G933", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
{ 0x0A87, RGBDeviceType.Headset, "G935", LedMappings.ZoneHeadset, (LogitechDeviceType.Headset, 2) },
/// <summary>
/// Gets the HID-definitions for per-device-devices.
/// </summary>
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 },
{ 0x0AB5, RGBDeviceType.Headset, "G733", LedMappings.Device, 0 },
};
{ 0x0A78, RGBDeviceType.Speaker, "G560", LedMappings.ZoneSpeaker, (LogitechDeviceType.Speaker, 4) },
};
#endregion
/// <summary>
/// Gets the HID-definitions for wireless per-zone-devices.
/// </summary>
public static LightspeedHIDLoader<int, (LogitechDeviceType deviceType, int zones)> PerZoneWirelessDeviceDefinitions { get; } = new()
{
{ 0x4053, RGBDeviceType.Mouse, "G900", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0x405D, RGBDeviceType.Mouse, "G403", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0x4067, RGBDeviceType.Mouse, "G903", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0x4070, RGBDeviceType.Mouse, "G703", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0x4079, RGBDeviceType.Mouse, "G Pro Wireless", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0x407F, RGBDeviceType.Mouse, "G502 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0x4086, RGBDeviceType.Mouse, "G703 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
{ 0x4087, RGBDeviceType.Mouse, "G903 Lightspeed", LedMappings.ZoneMouse, (LogitechDeviceType.Mouse, 2) },
};
#region Constructors
/// <summary>
/// Gets the HID-definitions for wired per-device-devices.
/// </summary>
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 },
{ 0x0AB5, RGBDeviceType.Headset, "G733", LedMappings.Device, 0 },
};
/// <summary>
/// Initializes a new instance of the <see cref="LogitechDeviceProvider"/> class.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public LogitechDeviceProvider()
{
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(LogitechDeviceProvider)}");
_instance = this;
}
/// <summary>
/// Gets the HID-definitions for wireless per-device-devices.
/// </summary>
public static LightspeedHIDLoader<int, int> PerDeviceWirelessDeviceDefinitions { get; } = new();
#endregion
#endregion
#region Methods
#region Constructors
/// <inheritdoc />
protected override void InitializeSDK()
{
_perDeviceUpdateQueue = new LogitechPerDeviceUpdateQueue(GetUpdateTrigger());
_perKeyUpdateQueue = new LogitechPerKeyUpdateQueue(GetUpdateTrigger());
/// <summary>
/// Initializes a new instance of the <see cref="LogitechDeviceProvider"/> class.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if this constructor is called even if there is already an instance of this class.</exception>
public LogitechDeviceProvider()
{
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(LogitechDeviceProvider)}");
_instance = this;
}
_LogitechGSDK.Reload();
if (!_LogitechGSDK.LogiLedInit()) Throw(new RGBDeviceException("Failed to initialize Logitech-SDK."), true);
#endregion
_LogitechGSDK.LogiLedSaveCurrentLighting();
}
#region Methods
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> GetLoadedDevices(RGBDeviceType loadFilter)
{
PerKeyDeviceDefinitions.LoadFilter = loadFilter;
PerZoneDeviceDefinitions.LoadFilter = loadFilter;
PerDeviceDeviceDefinitions.LoadFilter = loadFilter;
/// <inheritdoc />
protected override void InitializeSDK()
{
_perDeviceUpdateQueue = new LogitechPerDeviceUpdateQueue(GetUpdateTrigger());
_perKeyUpdateQueue = new LogitechPerKeyUpdateQueue(GetUpdateTrigger());
return base.GetLoadedDevices(loadFilter);
}
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> LoadDevices()
_LogitechGSDK.Reload();
if (!_LogitechGSDK.LogiLedInit()) Throw(new RGBDeviceException("Failed to initialize Logitech-SDK."), true);
_LogitechGSDK.LogiLedSaveCurrentLighting();
}
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> GetLoadedDevices(RGBDeviceType loadFilter)
{
PerKeyDeviceDefinitions.LoadFilter = loadFilter;
PerZoneDeviceDefinitions.LoadFilter = loadFilter;
PerDeviceDeviceDefinitions.LoadFilter = loadFilter;
return base.GetLoadedDevices(loadFilter);
}
/// <inheritdoc />
protected override IEnumerable<IRGBDevice> LoadDevices()
{
#region PerKey
if (_perKeyUpdateQueue != null)
{
(HIDDeviceDefinition<LogitechLedId, int> definition, HidDevice device) perKeyDevice = PerKeyDeviceDefinitions.GetConnectedDevices().FirstOrDefault();
if ((_perKeyUpdateQueue != null) && (perKeyDevice != default))
if (perKeyDevice != default)
{
(HIDDeviceDefinition<LogitechLedId, int> definition, _) = perKeyDevice;
yield return new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.PerKeyRGB, 0), _perKeyUpdateQueue, definition.LedMapping);
}
IEnumerable<(HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zoneOffset, int zones)> definition, HidDevice device)> perZoneDevices = PerZoneDeviceDefinitions.GetConnectedDevices(x => x.CustomData.deviceType);
foreach ((HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zoneOffset, int zones)> definition, _) in perZoneDevices)
else
{
LogitechZoneUpdateQueue updateQueue = new(GetUpdateTrigger(), definition.CustomData.deviceType);
yield return new LogitechZoneRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.DeviceRGB, definition.CustomData.zones, definition.CustomData.zoneOffset), updateQueue, definition.LedMapping);
HIDDeviceDefinition<LogitechLedId, int>? perKeyWirelessDevice = PerKeyWirelessDeviceDefinitions.GetConnectedDevices().FirstOrDefault();
if (perKeyWirelessDevice != null)
yield return new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(perKeyWirelessDevice.DeviceType, perKeyWirelessDevice.Name, LogitechDeviceCaps.PerKeyRGB, 0), _perKeyUpdateQueue, perKeyWirelessDevice.LedMapping);
}
}
#endregion
#region PerZone
IEnumerable<HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zoneOffset, int zones)>> wiredPerZoneDevices = PerZoneDeviceDefinitions.GetConnectedDevices().Select(x => x.definition);
IEnumerable<HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zoneOffset, int zones)>> wirelessPerZoneDevices = PerZoneWirelessDeviceDefinitions.GetConnectedDevices();
foreach (HIDDeviceDefinition<int, (LogitechDeviceType deviceType, int zoneOffset, int zones)> definition in wiredPerZoneDevices.Concat(wirelessPerZoneDevices)
.GroupBy(x => x.CustomData.deviceType)
.Select(group => group.First()))
{
LogitechZoneUpdateQueue updateQueue = new(GetUpdateTrigger(), definition.CustomData.deviceType);
yield return new LogitechZoneRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.DeviceRGB, definition.CustomData.zones, definition.CustomData.zoneOffset), updateQueue, definition.LedMapping);
}
#endregion
#region PerDevice
if (_perDeviceUpdateQueue != null)
{
(HIDDeviceDefinition<int, int> definition, HidDevice device) perDeviceDevice = PerDeviceDeviceDefinitions.GetConnectedDevices().FirstOrDefault();
if ((_perDeviceUpdateQueue != null) && (perDeviceDevice != default))
if (perDeviceDevice != default)
{
(HIDDeviceDefinition<int, int> definition, _) = perDeviceDevice;
yield return new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(definition.DeviceType, definition.Name, LogitechDeviceCaps.DeviceRGB, 0), _perDeviceUpdateQueue, definition.LedMapping);
}
}
/// <inheritdoc />
public override void Dispose()
{
base.Dispose();
try { _LogitechGSDK.LogiLedRestoreLighting(); }
catch { /* at least we tried */ }
try { _LogitechGSDK.UnloadLogitechGSDK(); }
catch { /* at least we tried */ }
GC.SuppressFinalize(this);
else
{
HIDDeviceDefinition<int, int>? perDeviceWirelessDevice = PerDeviceWirelessDeviceDefinitions.GetConnectedDevices().FirstOrDefault();
if (perDeviceWirelessDevice != null)
yield return new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(perDeviceWirelessDevice.DeviceType, perDeviceWirelessDevice.Name, LogitechDeviceCaps.DeviceRGB, 0), _perDeviceUpdateQueue, perDeviceWirelessDevice.LedMapping);
}
}
#endregion
}
}
/// <inheritdoc />
public override void Dispose()
{
base.Dispose();
try { _LogitechGSDK.LogiLedRestoreLighting(); }
catch { /* at least we tried */ }
try { _LogitechGSDK.UnloadLogitechGSDK(); }
catch { /* at least we tried */ }
GC.SuppressFinalize(this);
}
#endregion
}
+151 -152
View File
@@ -10,159 +10,158 @@ using System.Linq;
using System.Runtime.InteropServices;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech.Native
namespace RGB.NET.Devices.Logitech.Native;
// ReSharper disable once InconsistentNaming
internal class _LogitechGSDK
{
// ReSharper disable once InconsistentNaming
internal class _LogitechGSDK
{
#region Libary Management
#region Libary Management
private static IntPtr _dllHandle = IntPtr.Zero;
private static IntPtr _dllHandle = IntPtr.Zero;
/// <summary>
/// Reloads the SDK.
/// </summary>
internal static void Reload()
{
UnloadLogitechGSDK();
LoadLogitechGSDK();
}
private static void LoadLogitechGSDK()
{
if (_dllHandle != IntPtr.Zero) return;
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
List<string> possiblePathList = Environment.Is64BitProcess ? LogitechDeviceProvider.PossibleX64NativePaths : LogitechDeviceProvider.PossibleX86NativePaths;
string? dllPath = possiblePathList.FirstOrDefault(File.Exists);
if (dllPath == null) throw new RGBDeviceException($"Can't find the Logitech-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
_dllHandle = LoadLibrary(dllPath);
if (_dllHandle == IntPtr.Zero) throw new RGBDeviceException($"Logitech LoadLibrary failed with error code {Marshal.GetLastWin32Error()}");
_logiLedInitPointer = (LogiLedInitPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedInit"), typeof(LogiLedInitPointer));
_logiLedShutdownPointer = (LogiLedShutdownPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedShutdown"), typeof(LogiLedShutdownPointer));
_logiLedSetTargetDevicePointer = (LogiLedSetTargetDevicePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetTargetDevice"), typeof(LogiLedSetTargetDevicePointer));
_logiLedGetSdkVersionPointer = (LogiLedGetSdkVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedGetSdkVersion"), typeof(LogiLedGetSdkVersionPointer));
_lgiLedSaveCurrentLightingPointer = (LogiLedSaveCurrentLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSaveCurrentLighting"), typeof(LogiLedSaveCurrentLightingPointer));
_logiLedRestoreLightingPointer = (LogiLedRestoreLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedRestoreLighting"), typeof(LogiLedRestoreLightingPointer));
_logiLedSetLightingPointer = (LogiLedSetLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLighting"), typeof(LogiLedSetLightingPointer));
_logiLedSetLightingForKeyWithKeyNamePointer = (LogiLedSetLightingForKeyWithKeyNamePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingForKeyWithKeyName"), typeof(LogiLedSetLightingForKeyWithKeyNamePointer));
_logiLedSetLightingFromBitmapPointer = (LogiLedSetLightingFromBitmapPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingFromBitmap"), typeof(LogiLedSetLightingFromBitmapPointer));
_logiLedSetLightingForTargetZonePointer = (LogiLedSetLightingForTargetZonePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingForTargetZone"), typeof(LogiLedSetLightingForTargetZonePointer));
}
internal static void UnloadLogitechGSDK()
{
if (_dllHandle == IntPtr.Zero) return;
LogiLedShutdown();
// ReSharper disable once EmptyEmbeddedStatement - DarthAffe 20.02.2016: We might need to reduce the internal reference counter more than once to set the library free
while (FreeLibrary(_dllHandle)) ;
_dllHandle = IntPtr.Zero;
}
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr dllHandle);
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
#endregion
#region SDK-METHODS
#region Pointers
private static LogiLedInitPointer? _logiLedInitPointer;
private static LogiLedShutdownPointer? _logiLedShutdownPointer;
private static LogiLedSetTargetDevicePointer? _logiLedSetTargetDevicePointer;
private static LogiLedGetSdkVersionPointer? _logiLedGetSdkVersionPointer;
private static LogiLedSaveCurrentLightingPointer? _lgiLedSaveCurrentLightingPointer;
private static LogiLedRestoreLightingPointer? _logiLedRestoreLightingPointer;
private static LogiLedSetLightingPointer? _logiLedSetLightingPointer;
private static LogiLedSetLightingForKeyWithKeyNamePointer? _logiLedSetLightingForKeyWithKeyNamePointer;
private static LogiLedSetLightingFromBitmapPointer? _logiLedSetLightingFromBitmapPointer;
private static LogiLedSetLightingForTargetZonePointer? _logiLedSetLightingForTargetZonePointer;
#endregion
#region Delegates
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedInitPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void LogiLedShutdownPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetTargetDevicePointer(int targetDevice);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedGetSdkVersionPointer(ref int majorNum, ref int minorNum, ref int buildNum);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSaveCurrentLightingPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedRestoreLightingPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetLightingPointer(int redPercentage, int greenPercentage, int bluePercentage);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetLightingForKeyWithKeyNamePointer(int keyCode, int redPercentage, int greenPercentage, int bluePercentage);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetLightingFromBitmapPointer(byte[] bitmap);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetLightingForTargetZonePointer(LogitechDeviceType deviceType, int zone, int redPercentage, int greenPercentage, int bluePercentage);
#endregion
// ReSharper disable EventExceptionNotDocumented
internal static bool LogiLedInit() => (_logiLedInitPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static void LogiLedShutdown() => (_logiLedShutdownPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static bool LogiLedSetTargetDevice(LogitechDeviceCaps targetDevice) => (_logiLedSetTargetDevicePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke((int)targetDevice);
internal static string LogiLedGetSdkVersion()
{
int major = 0;
int minor = 0;
int build = 0;
LogiLedGetSdkVersion(ref major, ref minor, ref build);
return $"{major}.{minor}.{build}";
}
internal static bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum) =>
(_logiLedGetSdkVersionPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(ref majorNum, ref minorNum, ref buildNum);
internal static bool LogiLedSaveCurrentLighting() => (_lgiLedSaveCurrentLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static bool LogiLedRestoreLighting() => (_logiLedRestoreLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage) =>
(_logiLedSetLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(redPercentage, greenPercentage, bluePercentage);
internal static bool LogiLedSetLightingForKeyWithKeyName(int keyCode, int redPercentage, int greenPercentage, int bluePercentage)
=> (_logiLedSetLightingForKeyWithKeyNamePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(keyCode, redPercentage, greenPercentage, bluePercentage);
internal static bool LogiLedSetLightingFromBitmap(byte[] bitmap) => (_logiLedSetLightingFromBitmapPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(bitmap);
internal static bool LogiLedSetLightingForTargetZone(LogitechDeviceType deviceType, int zone, int redPercentage, int greenPercentage, int bluePercentage)
=> (_logiLedSetLightingForTargetZonePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(deviceType, zone, redPercentage, greenPercentage, bluePercentage);
// ReSharper restore EventExceptionNotDocumented
#endregion
/// <summary>
/// Reloads the SDK.
/// </summary>
internal static void Reload()
{
UnloadLogitechGSDK();
LoadLogitechGSDK();
}
}
private static void LoadLogitechGSDK()
{
if (_dllHandle != IntPtr.Zero) return;
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
List<string> possiblePathList = Environment.Is64BitProcess ? LogitechDeviceProvider.PossibleX64NativePaths : LogitechDeviceProvider.PossibleX86NativePaths;
string? dllPath = possiblePathList.FirstOrDefault(File.Exists);
if (dllPath == null) throw new RGBDeviceException($"Can't find the Logitech-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
_dllHandle = LoadLibrary(dllPath);
if (_dllHandle == IntPtr.Zero) throw new RGBDeviceException($"Logitech LoadLibrary failed with error code {Marshal.GetLastWin32Error()}");
_logiLedInitPointer = (LogiLedInitPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedInit"), typeof(LogiLedInitPointer));
_logiLedShutdownPointer = (LogiLedShutdownPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedShutdown"), typeof(LogiLedShutdownPointer));
_logiLedSetTargetDevicePointer = (LogiLedSetTargetDevicePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetTargetDevice"), typeof(LogiLedSetTargetDevicePointer));
_logiLedGetSdkVersionPointer = (LogiLedGetSdkVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedGetSdkVersion"), typeof(LogiLedGetSdkVersionPointer));
_lgiLedSaveCurrentLightingPointer = (LogiLedSaveCurrentLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSaveCurrentLighting"), typeof(LogiLedSaveCurrentLightingPointer));
_logiLedRestoreLightingPointer = (LogiLedRestoreLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedRestoreLighting"), typeof(LogiLedRestoreLightingPointer));
_logiLedSetLightingPointer = (LogiLedSetLightingPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLighting"), typeof(LogiLedSetLightingPointer));
_logiLedSetLightingForKeyWithKeyNamePointer = (LogiLedSetLightingForKeyWithKeyNamePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingForKeyWithKeyName"), typeof(LogiLedSetLightingForKeyWithKeyNamePointer));
_logiLedSetLightingFromBitmapPointer = (LogiLedSetLightingFromBitmapPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingFromBitmap"), typeof(LogiLedSetLightingFromBitmapPointer));
_logiLedSetLightingForTargetZonePointer = (LogiLedSetLightingForTargetZonePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingForTargetZone"), typeof(LogiLedSetLightingForTargetZonePointer));
}
internal static void UnloadLogitechGSDK()
{
if (_dllHandle == IntPtr.Zero) return;
LogiLedShutdown();
// ReSharper disable once EmptyEmbeddedStatement - DarthAffe 20.02.2016: We might need to reduce the internal reference counter more than once to set the library free
while (FreeLibrary(_dllHandle)) ;
_dllHandle = IntPtr.Zero;
}
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr dllHandle);
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
#endregion
#region SDK-METHODS
#region Pointers
private static LogiLedInitPointer? _logiLedInitPointer;
private static LogiLedShutdownPointer? _logiLedShutdownPointer;
private static LogiLedSetTargetDevicePointer? _logiLedSetTargetDevicePointer;
private static LogiLedGetSdkVersionPointer? _logiLedGetSdkVersionPointer;
private static LogiLedSaveCurrentLightingPointer? _lgiLedSaveCurrentLightingPointer;
private static LogiLedRestoreLightingPointer? _logiLedRestoreLightingPointer;
private static LogiLedSetLightingPointer? _logiLedSetLightingPointer;
private static LogiLedSetLightingForKeyWithKeyNamePointer? _logiLedSetLightingForKeyWithKeyNamePointer;
private static LogiLedSetLightingFromBitmapPointer? _logiLedSetLightingFromBitmapPointer;
private static LogiLedSetLightingForTargetZonePointer? _logiLedSetLightingForTargetZonePointer;
#endregion
#region Delegates
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedInitPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void LogiLedShutdownPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetTargetDevicePointer(int targetDevice);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedGetSdkVersionPointer(ref int majorNum, ref int minorNum, ref int buildNum);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSaveCurrentLightingPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedRestoreLightingPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetLightingPointer(int redPercentage, int greenPercentage, int bluePercentage);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetLightingForKeyWithKeyNamePointer(int keyCode, int redPercentage, int greenPercentage, int bluePercentage);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetLightingFromBitmapPointer(byte[] bitmap);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool LogiLedSetLightingForTargetZonePointer(LogitechDeviceType deviceType, int zone, int redPercentage, int greenPercentage, int bluePercentage);
#endregion
// ReSharper disable EventExceptionNotDocumented
internal static bool LogiLedInit() => (_logiLedInitPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static void LogiLedShutdown() => (_logiLedShutdownPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static bool LogiLedSetTargetDevice(LogitechDeviceCaps targetDevice) => (_logiLedSetTargetDevicePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke((int)targetDevice);
internal static string LogiLedGetSdkVersion()
{
int major = 0;
int minor = 0;
int build = 0;
LogiLedGetSdkVersion(ref major, ref minor, ref build);
return $"{major}.{minor}.{build}";
}
internal static bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum) =>
(_logiLedGetSdkVersionPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(ref majorNum, ref minorNum, ref buildNum);
internal static bool LogiLedSaveCurrentLighting() => (_lgiLedSaveCurrentLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static bool LogiLedRestoreLighting() => (_logiLedRestoreLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke();
internal static bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage) =>
(_logiLedSetLightingPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(redPercentage, greenPercentage, bluePercentage);
internal static bool LogiLedSetLightingForKeyWithKeyName(int keyCode, int redPercentage, int greenPercentage, int bluePercentage)
=> (_logiLedSetLightingForKeyWithKeyNamePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(keyCode, redPercentage, greenPercentage, bluePercentage);
internal static bool LogiLedSetLightingFromBitmap(byte[] bitmap) => (_logiLedSetLightingFromBitmapPointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(bitmap);
internal static bool LogiLedSetLightingForTargetZone(LogitechDeviceType deviceType, int zone, int redPercentage, int greenPercentage, int bluePercentage)
=> (_logiLedSetLightingForTargetZonePointer ?? throw new RGBDeviceException("The Logitech-GSDK is not initialized.")).Invoke(deviceType, zone, redPercentage, greenPercentage, bluePercentage);
// ReSharper restore EventExceptionNotDocumented
#endregion
}
@@ -2,49 +2,48 @@
using System.Linq;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <inheritdoc cref="LogitechRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a logitech per-device-lightable device.
/// </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
{
/// <inheritdoc cref="LogitechRGBDevice{TDeviceInfo}" />
#region Properties & Fields
private readonly LedMapping<int> _ledMapping;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Represents a logitech per-device-lightable device.
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechPerDeviceRGBDevice" /> class.
/// </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
internal LogitechPerDeviceRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue, LedMapping<int> ledMapping)
: base(info, updateQueue)
{
#region Properties & Fields
this._ledMapping = ledMapping;
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>
internal LogitechPerDeviceRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue, LedMapping<int> ledMapping)
: base(info, updateQueue)
{
this._ledMapping = ledMapping;
InitializeLayout();
}
#endregion
#region Methods
private void InitializeLayout()
{
AddLed(LedId.Custom1, new Point(0, 0), new Size(10, 10));
}
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId];
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate.Take(1)));
#endregion
InitializeLayout();
}
}
#endregion
#region Methods
private void InitializeLayout()
{
AddLed(LedId.Custom1, new Point(0, 0), new Size(10, 10));
}
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId];
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate.Take(1)));
#endregion
}
@@ -2,39 +2,38 @@
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.Native;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <inheritdoc />
/// <summary>
/// Represents the update-queue performing updates for logitech per-device devices.
/// </summary>
public class LogitechPerDeviceUpdateQueue : UpdateQueue
{
/// <inheritdoc />
#region Constructors
/// <summary>
/// Represents the update-queue performing updates for logitech per-device devices.
/// Initializes a new instance of the <see cref="LogitechPerDeviceUpdateQueue"/> class.
/// </summary>
public class LogitechPerDeviceUpdateQueue : UpdateQueue
/// <param name="updateTrigger">The update trigger used by this queue.</param>
public LogitechPerDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{ }
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{
#region Constructors
Color color = dataSet[0].color;
/// <summary>
/// Initializes a new instance of the <see cref="LogitechPerDeviceUpdateQueue"/> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
public LogitechPerDeviceUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{ }
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{
Color color = dataSet[0].color;
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.DeviceRGB);
_LogitechGSDK.LogiLedSetLighting((int)Math.Round(color.R * 100),
(int)Math.Round(color.G * 100),
(int)Math.Round(color.B * 100));
}
#endregion
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.DeviceRGB);
_LogitechGSDK.LogiLedSetLighting((int)Math.Round(color.R * 100),
(int)Math.Round(color.G * 100),
(int)Math.Round(color.B * 100));
}
}
#endregion
}
@@ -1,42 +1,41 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <inheritdoc cref="LogitechRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a logitech per-key-lightable device.
/// </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
{
/// <inheritdoc cref="LogitechRGBDevice{TDeviceInfo}" />
#region Properties & Fields
private readonly LedMapping<LogitechLedId> _ledMapping;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Represents a logitech per-key-lightable device.
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechPerKeyRGBDevice" /> class.
/// </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
internal LogitechPerKeyRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue, LedMapping<LogitechLedId> ledMapping)
: base(info, updateQueue)
{
#region Properties & Fields
private readonly LedMapping<LogitechLedId> _ledMapping;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechPerKeyRGBDevice" /> class.
/// </summary>
internal LogitechPerKeyRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue, LedMapping<LogitechLedId> ledMapping)
: base(info, updateQueue)
{
this._ledMapping = ledMapping;
}
#endregion
#region Methods
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => _ledMapping.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : -1;
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate));
#endregion
this._ledMapping = ledMapping;
}
}
#endregion
#region Methods
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => _ledMapping.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : -1;
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate));
#endregion
}
@@ -2,44 +2,43 @@
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.Native;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <summary>
/// Represents the update-queue performing updates for logitech per-key devices.
/// </summary>
public class LogitechPerKeyUpdateQueue : UpdateQueue
{
#region Constructors
/// <summary>
/// Represents the update-queue performing updates for logitech per-key devices.
/// Initializes a new instance of the <see cref="LogitechPerKeyUpdateQueue"/> class.
/// </summary>
public class LogitechPerKeyUpdateQueue : UpdateQueue
/// <param name="updateTrigger">The update trigger used by this queue.</param>
public LogitechPerKeyUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
{
#region Constructors
}
/// <summary>
/// Initializes a new instance of the <see cref="LogitechPerKeyUpdateQueue"/> class.
/// </summary>
/// <param name="updateTrigger">The update trigger used by this queue.</param>
public LogitechPerKeyUpdateQueue(IDeviceUpdateTrigger updateTrigger)
: base(updateTrigger)
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
foreach ((object key, Color color) in dataSet)
{
}
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.PerKeyRGB);
foreach ((object key, Color color) in dataSet)
{
// These will be LogitechLedId but the SDK expects an int and doesn't care about invalid values
int keyName = (int)key;
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(keyName,
// These will be LogitechLedId but the SDK expects an int and doesn't care about invalid values
int keyName = (int)key;
_LogitechGSDK.LogiLedSetLightingForKeyWithKeyName(keyName,
(int)MathF.Round(color.R * 100),
(int)MathF.Round(color.G * 100),
(int)MathF.Round(color.B * 100));
}
}
#endregion
}
}
#endregion
}
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5.0</TargetFrameworks>
<TargetFrameworks>net6.0;net5.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
@@ -1,50 +1,48 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <inheritdoc cref="LogitechRGBDevice{TDeviceInfo}" />
/// <summary>
/// Represents a logitech zone-lightable device.
/// </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
{
/// <inheritdoc cref="LogitechRGBDevice{TDeviceInfo}" />
#region Properties & Fields
private readonly LedMapping<int> _ledMapping;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Represents a logitech zone-lightable device.
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechZoneRGBDevice" /> class.
/// </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
internal LogitechZoneRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue, LedMapping<int> ledMapping)
: base(info, updateQueue)
{
#region Properties & Fields
this._ledMapping = ledMapping;
private readonly LedMapping<int> _ledMapping;
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Devices.Logitech.LogitechZoneRGBDevice" /> class.
/// </summary>
internal LogitechZoneRGBDevice(LogitechRGBDeviceInfo info, IUpdateQueue updateQueue, LedMapping<int> ledMapping)
: base(info, updateQueue)
{
this._ledMapping = ledMapping;
InitializeLayout();
}
#endregion
#region Methods
private void InitializeLayout()
{
for (int i = DeviceInfo.ZoneOffset; i < (DeviceInfo.ZoneOffset + DeviceInfo.Zones); i++)
AddLed(_ledMapping[i], new Point(i * 10, 0), new Size(10, 10));
}
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId];
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate));
#endregion
InitializeLayout();
}
}
#endregion
#region Methods
private void InitializeLayout()
{
for (int i = DeviceInfo.ZoneOffset; i < (DeviceInfo.ZoneOffset + DeviceInfo.Zones); i++)
AddLed(_ledMapping[i], new Point(i * 10, 0), new Size(10, 10));
}
/// <inheritdoc />
protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId];
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate));
#endregion
}
@@ -2,51 +2,50 @@
using RGB.NET.Core;
using RGB.NET.Devices.Logitech.Native;
namespace RGB.NET.Devices.Logitech
namespace RGB.NET.Devices.Logitech;
/// <summary>
/// Represents the update-queue performing updates for logitech zone devices.
/// </summary>
public class LogitechZoneUpdateQueue : UpdateQueue
{
#region Properties & Fields
private readonly LogitechDeviceType _deviceType;
#endregion
#region Constructors
/// <summary>
/// Represents the update-queue performing updates for logitech zone devices.
/// Initializes a new instance of the <see cref="LogitechZoneUpdateQueue"/> class.
/// </summary>
public class LogitechZoneUpdateQueue : UpdateQueue
/// <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, LogitechDeviceType deviceType)
: base(updateTrigger)
{
#region Properties & Fields
private readonly LogitechDeviceType _deviceType;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="LogitechZoneUpdateQueue"/> class.
/// </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, LogitechDeviceType deviceType)
: base(updateTrigger)
{
this._deviceType = deviceType;
}
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.All);
foreach ((object key, Color color) in dataSet)
{
int zone = (int)key;
_LogitechGSDK.LogiLedSetLightingForTargetZone(_deviceType, zone,
(int)MathF.Round(color.R * 100),
(int)MathF.Round(color.G * 100),
(int)MathF.Round(color.B * 100));
}
}
#endregion
this._deviceType = deviceType;
}
}
#endregion
#region Methods
/// <inheritdoc />
protected override void Update(in ReadOnlySpan<(object key, Color color)> dataSet)
{
_LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.All);
foreach ((object key, Color color) in dataSet)
{
int zone = (int)key;
_LogitechGSDK.LogiLedSetLightingForTargetZone(_deviceType, zone,
(int)MathF.Round(color.R * 100),
(int)MathF.Round(color.G * 100),
(int)MathF.Round(color.B * 100));
}
}
#endregion
}