From 03c8d3542164066fd467762d3e39b04661026bcd Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 28 Dec 2019 13:19:21 +0100 Subject: [PATCH 01/51] Device Support Asus strix scope tested Asus strix flare not tested Signed-off-by: Alex --- .../Generic/AsusUpdateQueue.cs | 59 +++- .../Keyboard/AsusKeyboardRGBDevice.cs | 264 +++++++++++++++++- .../Keyboard/AsusKeyboardRGBDeviceInfo.cs | 2 +- 3 files changed, 309 insertions(+), 16 deletions(-) diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs index fb32a3e..48f2b0d 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs @@ -48,14 +48,58 @@ namespace RGB.NET.Devices.Asus { try { - foreach (KeyValuePair data in dataSet) + if (Device.Type == 0x00080000 || Device.Type == 0x00081000)//Keyboard { - int index = (int)data.Key; - IAuraRgbLight light = Device.Lights[index]; - (_, byte r, byte g, byte b) = data.Value.GetRGBBytes(); - light.Red = r; - light.Green = g; - light.Blue = b; + foreach (KeyValuePair data in dataSet) + { + ushort index = (ushort)data.Key; + IAuraSyncKeyboard keyboard = (IAuraSyncKeyboard)Device; + if (keyboard != null) + { + IAuraRgbLight light; + //UK keyboard Layout + if (index == 0x56) + { + light = keyboard.Lights[(int)(3 * keyboard.Width + 13)]; + } + else if (index == 0x59) + { + light = keyboard.Lights[(int)(4 * keyboard.Width + 1)]; + } + else + { + light = keyboard.Key[index]; + } + // Asus Strix Scope + if (keyboard.Name == "Charm") + { + if (index == 0XDB) + { + light = keyboard.Lights[(int)(5 * keyboard.Width + 2)]; + } + else if (index == 0x38) + { + light = keyboard.Lights[(int)(5 * keyboard.Width + 3)]; + } + } + (_, byte r, byte g, byte b) = data.Value.GetRGBBytes(); + light.Red = r; + light.Green = g; + light.Blue = b; + } + } + } + else + { + foreach (KeyValuePair data in dataSet) + { + int index = (int)data.Key; + IAuraRgbLight light = Device.Lights[index]; + (_, byte r, byte g, byte b) = data.Value.GetRGBBytes(); + light.Red = r; + light.Green = g; + light.Blue = b; + } } Device.Apply(); @@ -63,7 +107,6 @@ namespace RGB.NET.Devices.Asus catch (Exception ex) { /* "The server threw an exception." seems to be a thing here ... */ } } - #endregion } } diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs index f16acf4..f3d1b6a 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs @@ -1,4 +1,5 @@ -using RGB.NET.Core; +using AuraServiceLib; +using RGB.NET.Core; namespace RGB.NET.Devices.Asus { @@ -22,22 +23,271 @@ namespace RGB.NET.Devices.Asus #endregion #region Methods - + private ushort asusCode; /// protected override void InitializeLayout() { - //TODO DarthAffe 07.10.2017: This doesn't make sense at all ... Find someone with such a keyboard! - int ledCount = DeviceInfo.Device.Lights.Count; - for (int i = 0; i < ledCount; i++) - InitializeLed(LedId.Keyboard_Escape + i, new Rectangle(i * 19, 0, 19, 19)); + if (DeviceInfo.Device.Type != 0x00081001) + { + int pos = 0; + foreach (IAuraRgbKey key in ((IAuraSyncKeyboard)DeviceInfo.Device).Keys) + { + asusCode = key.Code; + InitializeLed(AsusLedIdMapper(key.Code), new Rectangle(pos++ * 19, 0, 19, 19)); + } + //UK Layout + asusCode = 0x56; + InitializeLed(AsusLedIdMapper(asusCode), new Rectangle(pos++ * 19, 0, 19, 19)); + asusCode = 0x59; + InitializeLed(AsusLedIdMapper(asusCode), new Rectangle(pos++ * 19, 0, 19, 19)); + } + else + { + int ledCount = DeviceInfo.Device.Lights.Count; + for (int i = 0; i < ledCount; i++) + { + asusCode = (ushort)i; + InitializeLed(LedId.Keyboard_Custom1 + i, new Rectangle(i * 19, 0, 19, 19)); + } + + } string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, $@"Layouts\Asus\Keyboards\{model}", $"{DeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"), DeviceInfo.LogicalLayout.ToString()); } /// - protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Keyboard_Escape; + protected override object CreateLedCustomData(LedId ledId) => asusCode; + /// + private LedId AsusLedIdMapper(ushort asusKey) + { + switch (asusKey) + { + case 0x01: + return LedId.Keyboard_Escape; + case 0x3B: + return LedId.Keyboard_F1; + case 0x3C: + return LedId.Keyboard_F2; + case 0x3D: + return LedId.Keyboard_F3; + case 0x3E: + return LedId.Keyboard_F4; + case 0x3F: + return LedId.Keyboard_F5; + case 0x40: + return LedId.Keyboard_F6; + case 0x41: + return LedId.Keyboard_F7; + case 0x42: + return LedId.Keyboard_F8; + case 0x43: + return LedId.Keyboard_F9; + case 0x44: + return LedId.Keyboard_F10; + case 0x57: + return LedId.Keyboard_F11; + case 0x58: + return LedId.Keyboard_F12; + case 0x02: + return LedId.Keyboard_1; + case 0x03: + return LedId.Keyboard_2; + case 0x04: + return LedId.Keyboard_3; + case 0x05: + return LedId.Keyboard_4; + case 0x06: + return LedId.Keyboard_5; + case 0x07: + return LedId.Keyboard_6; + case 0x08: + return LedId.Keyboard_7; + case 0x09: + return LedId.Keyboard_8; + case 0x0A: + return LedId.Keyboard_9; + case 0x0B: + return LedId.Keyboard_0; + case 0x0C: + return LedId.Keyboard_MinusAndUnderscore; + case 0x0D: + return LedId.Keyboard_EqualsAndPlus; + case 0x0E: + return LedId.Keyboard_Backspace; + case 0x0F: + return LedId.Keyboard_Tab; + case 0x10: + return LedId.Keyboard_Q; + case 0x11: + return LedId.Keyboard_W; + case 0x12: + return LedId.Keyboard_E; + case 0x13: + return LedId.Keyboard_R; + case 0x14: + return LedId.Keyboard_T; + case 0x15: + return LedId.Keyboard_Y; + case 0x16: + return LedId.Keyboard_U; + case 0x17: + return LedId.Keyboard_I; + case 0x18: + return LedId.Keyboard_O; + case 0x19: + return LedId.Keyboard_P; + case 0x1A: + return LedId.Keyboard_BracketLeft; + case 0x1B: + return LedId.Keyboard_BracketRight; + case 0x1C: + return LedId.Keyboard_Enter; + case 0x3A: + return LedId.Keyboard_CapsLock; + case 0x1E: + return LedId.Keyboard_A; + case 0x1F: + return LedId.Keyboard_S; + case 0x20: + return LedId.Keyboard_D; + case 0x21: + return LedId.Keyboard_F; + case 0x22: + return LedId.Keyboard_G; + case 0x23: + return LedId.Keyboard_H; + case 0x24: + return LedId.Keyboard_J; + case 0x25: + return LedId.Keyboard_K; + case 0x26: + return LedId.Keyboard_L; + case 0x27: + return LedId.Keyboard_SemicolonAndColon; + case 0x28: + return LedId.Keyboard_ApostropheAndDoubleQuote; + case 0x29: + return LedId.Keyboard_GraveAccentAndTilde; + case 0x2A: + return LedId.Keyboard_LeftShift; + case 0x2B: + return LedId.Keyboard_Backslash; + case 0x2C: + return LedId.Keyboard_Z; + case 0x2D: + return LedId.Keyboard_X; + case 0x2E: + return LedId.Keyboard_C; + case 0x2F: + return LedId.Keyboard_V; + case 0x30: + return LedId.Keyboard_B; + case 0x31: + return LedId.Keyboard_N; + case 0x32: + return LedId.Keyboard_M; + case 0x33: + return LedId.Keyboard_CommaAndLessThan; + case 0x34: + return LedId.Keyboard_PeriodAndBiggerThan; + case 0x35: + return LedId.Keyboard_SlashAndQuestionMark; + case 0x36: + return LedId.Keyboard_RightShift; + case 0x1D: + return LedId.Keyboard_LeftCtrl; + case 0xDB: + return LedId.Keyboard_LeftGui; + case 0x38: + return LedId.Keyboard_LeftAlt; + case 0x39: + return LedId.Keyboard_Space; + case 0xB8: + return LedId.Keyboard_RightAlt; + case 0x100: + return LedId.Keyboard_RightGui; + case 0xDD: + return LedId.Keyboard_Application; + case 0x9D: + return LedId.Keyboard_RightCtrl; + case 0xB7: + return LedId.Keyboard_PrintScreen; + case 0x46: + return LedId.Keyboard_ScrollLock; + case 0xC5: + return LedId.Keyboard_PauseBreak; + case 0xD2: + return LedId.Keyboard_Insert; + case 0xC7: + return LedId.Keyboard_Home; + case 0xC9: + return LedId.Keyboard_PageUp; + case 0xD3: + return LedId.Keyboard_Delete; + case 0xCF: + return LedId.Keyboard_End; + case 0xD1: + return LedId.Keyboard_PageDown; + case 0xC8: + return LedId.Keyboard_ArrowUp; + case 0xCB: + return LedId.Keyboard_ArrowLeft; + case 0xD0: + return LedId.Keyboard_ArrowDown; + case 0xCD: + return LedId.Keyboard_ArrowRight; + case 0x45: + return LedId.Keyboard_NumLock; + case 0xB5: + return LedId.Keyboard_NumSlash; + case 0x37: + return LedId.Keyboard_NumAsterisk; + case 0x4A: + return LedId.Keyboard_NumMinus; + case 0x47: + return LedId.Keyboard_Num7; + case 0x48: + return LedId.Keyboard_Num8; + case 0x49: + return LedId.Keyboard_Num9; + case 0x53: + return LedId.Keyboard_NumPeriodAndDelete; + case 0x4E: + return LedId.Keyboard_NumPlus; + case 0x4B: + return LedId.Keyboard_Num4; + case 0x4C: + return LedId.Keyboard_Num5; + case 0x4D: + return LedId.Keyboard_Num6; + case 0x4F: + return LedId.Keyboard_Num1; + case 0x50: + return LedId.Keyboard_Num2; + case 0x51: + return LedId.Keyboard_Num3; + case 0x52: + return LedId.Keyboard_Num0; + case 0x9C: + return LedId.Keyboard_NumEnter; + case 0x59: + return LedId.Keyboard_NonUsBackslash; + case 0x56: + return LedId.Keyboard_NonUsTilde; + case 0xB3: + return LedId.Keyboard_NumComma; + case 0x101: + return LedId.Logo; + case 0x102: + return LedId.Keyboard_Custom1; + case 0x103: + return LedId.Keyboard_Custom2; + default: + return LedId.Invalid; + } + } #endregion } } diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs index bf020a6..5b8a55e 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs @@ -33,7 +33,7 @@ namespace RGB.NET.Devices.Asus /// The backing this RGB.NET device. /// The of the layout this keyboard is using. internal AsusKeyboardRGBDeviceInfo(IAuraSyncDevice device, CultureInfo culture) - : base(RGBDeviceType.Keyboard, device, "Claymore") + : base(RGBDeviceType.Keyboard, device, device.Name) { SetLayouts(culture.KeyboardLayoutId); } From 5b3a0775577cddd4a509f8e7c3dc63927261439c Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 22 Feb 2020 15:11:27 +0100 Subject: [PATCH 02/51] Started Asus refactoring (WIP) --- RGB.NET.Devices.Asus/Enum/AsusDeviceTypes.cs | 25 +++ RGB.NET.Devices.Asus/Enum/AsusLedIds.cs | 153 ++++++++++++++++++ .../Generic/AsusUpdateQueue.cs | 2 +- .../Keyboard/AsusKeyboardLedMappings.cs | 138 ++++++++++++++++ .../Keyboard/AsusKeyboardRGBDevice.cs | 1 - 5 files changed, 317 insertions(+), 2 deletions(-) create mode 100644 RGB.NET.Devices.Asus/Enum/AsusDeviceTypes.cs create mode 100644 RGB.NET.Devices.Asus/Enum/AsusLedIds.cs create mode 100644 RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMappings.cs diff --git a/RGB.NET.Devices.Asus/Enum/AsusDeviceTypes.cs b/RGB.NET.Devices.Asus/Enum/AsusDeviceTypes.cs new file mode 100644 index 0000000..a86ac4c --- /dev/null +++ b/RGB.NET.Devices.Asus/Enum/AsusDeviceTypes.cs @@ -0,0 +1,25 @@ +// ReSharper disable InconsistentNaming + +namespace RGB.NET.Devices.Asus +{ + internal enum AsusDeviceTypes + { + ALL = 0, + MB_RGB = 0x10000, + MB_ADDRESABLE = 0x11000, + DESKTOP_RGB = 0x12000, + VGA_RGB = 0x20000, + DISPLAY_RGB = 0x30000, + HEADSET_RGB = 0x40000, + MICROPHONE_RGB = 0x50000, + EXTERNAL_HARD_DRIVER_RGB = 0x60000, + EXTERNAL_BLUE_RAY_RGB = 0x61000, + DRAM_RGB = 0x70000, + KEYBOARD_RGB = 0x80000, + NB_KB_RGB = 0x81000, + NB_KB_4ZONE_RGB = 0x81001, + MOUSE_RGB = 0x90000, + CHASSIS_RGB = 0xB0000, + PROJECTOR_RGB = 0xC0000 + } +} diff --git a/RGB.NET.Devices.Asus/Enum/AsusLedIds.cs b/RGB.NET.Devices.Asus/Enum/AsusLedIds.cs new file mode 100644 index 0000000..665015f --- /dev/null +++ b/RGB.NET.Devices.Asus/Enum/AsusLedIds.cs @@ -0,0 +1,153 @@ +// ReSharper disable InconsistentNaming + +namespace RGB.NET.Devices.Asus +{ + internal enum AsusLedIds + { + KEY_ESCAPE = 0x01, + KEY_1 = 0x02, + KEY_2 = 0x03, + KEY_3 = 0x04, + KEY_4 = 0x05, + KEY_5 = 0x06, + KEY_6 = 0x07, + KEY_7 = 0x08, + KEY_8 = 0x09, + KEY_9 = 0x0A, + KEY_0 = 0x0B, + KEY_MINUS = 0x0C, // - on main keyboard + KEY_EQUALS = 0x0D, + KEY_BACK = 0x0E, // backspace + KEY_TAB = 0x0F, + KEY_Q = 0x10, + KEY_W = 0x11, + KEY_E = 0x12, + KEY_R = 0x13, + KEY_T = 0x14, + KEY_Y = 0x15, + KEY_U = 0x16, + KEY_I = 0x17, + KEY_O = 0x18, + KEY_P = 0x19, + KEY_LBRACKET = 0x1A, + KEY_RBRACKET = 0x1B, + KEY_RETURN = 0x1C, // Enter on main keyboard + KEY_LCONTROL = 0x1D, + KEY_A = 0x1E, + KEY_S = 0x1F, + KEY_D = 0x20, + KEY_F = 0x21, + KEY_G = 0x22, + KEY_H = 0x23, + KEY_J = 0x24, + KEY_K = 0x25, + KEY_L = 0x26, + KEY_SEMICOLON = 0x27, + KEY_APOSTROPHE = 0x28, + KEY_GRAVE = 0x29, // accent grave + KEY_LSHIFT = 0x2A, + KEY_BACKSLASH = 0x2B, + KEY_Z = 0x2C, + KEY_X = 0x2D, + KEY_C = 0x2E, + KEY_V = 0x2F, + KEY_B = 0x30, + KEY_N = 0x31, + KEY_M = 0x32, + KEY_COMMA = 0x33, + KEY_PERIOD = 0x34, // . on main keyboard + KEY_SLASH = 0x35, // / on main keyboard + KEY_RSHIFT = 0x36, + KEY_MULTIPLY = 0x37, // * on numeric keypad + KEY_LMENU = 0x38, // left Alt + KEY_SPACE = 0x39, + KEY_CAPITAL = 0x3A, + KEY_F1 = 0x3B, + KEY_F2 = 0x3C, + KEY_F3 = 0x3D, + KEY_F4 = 0x3E, + KEY_F5 = 0x3F, + KEY_F6 = 0x40, + KEY_F7 = 0x41, + KEY_F8 = 0x42, + KEY_F9 = 0x43, + KEY_F10 = 0x44, + KEY_NUMLOCK = 0x45, + KEY_SCROLL = 0x46, // Scroll Lock + KEY_NUMPAD7 = 0x47, + KEY_NUMPAD8 = 0x48, + KEY_NUMPAD9 = 0x49, + KEY_SUBTRACT = 0x4A, // - on numeric keypad + KEY_NUMPAD4 = 0x4B, + KEY_NUMPAD5 = 0x4C, + KEY_NUMPAD6 = 0x4D, + KEY_ADD = 0x4E, // + on numeric keypad + KEY_NUMPAD1 = 0x4F, + KEY_NUMPAD2 = 0x50, + KEY_NUMPAD3 = 0x51, + KEY_NUMPAD0 = 0x52, + KEY_DECIMAL = 0x53, // . on numeric keypad + KEY_OEM_102 = 0x56, // < > | on UK/Germany keyboards + KEY_F11 = 0x57, + KEY_F12 = 0x58, + KEY_F13 = 0x64, // (NEC PC98) + KEY_F14 = 0x65, // (NEC PC98) + KEY_F15 = 0x66, // (NEC PC98) + KEY_KANA = 0x70, // (Japanese keyboard) + KEY_ABNT_C1 = 0x73, // / ? on Portugese (Brazilian) keyboards + KEY_CONVERT = 0x79, // (Japanese keyboard) + KEY_NOCONVERT = 0x7B, // (Japanese keyboard) + KEY_YEN = 0x7D, // (Japanese keyboard) + KEY_ABNT_C2 = 0x7E, // Numpad . on Portugese (Brazilian) keyboards + KEY_NUMPADEQUALS = 0x8D, // = on numeric keypad (NEC PC98) + KEY_CIRCUMFLEX = 0x90, // (Japanese keyboard) + KEY_AT = 0x91, // (NEC PC98) + KEY_COLON = 0x92, // (NEC PC98) + KEY_UNDERLINE = 0x93, // (NEC PC98) + KEY_KANJI = 0x94, // (Japanese keyboard) + KEY_STOP = 0x95, // (NEC PC98) + KEY_AX = 0x96, // (Japan AX) + KEY_UNLABELED = 0x97, // (J3100) + KEY_NEXTTRACK = 0x99, // Next Track + KEY_NUMPADENTER = 0x9C, // Enter on numeric keypad + KEY_RCONTROL = 0x9D, // + KEY_MUTE = 0xA0, // Mute + KEY_CALCULATOR = 0xA1, // Calculator + KEY_PLAYPAUSE = 0xA2, // Play / Pause + KEY_MEDIASTOP = 0xA4, // Media Stop + KEY_VOLUMEDOWN = 0xAE, // Volume - + KEY_VOLUMEUP = 0xB0, // Volume + + KEY_WEBHOME = 0xB2, // Web home + KEY_NUMPADCOMMA = 0xB3, // , on numeric keypad (NEC PC98) + KEY_DIVIDE = 0xB5, // / on numeric keypad + KEY_SYSRQ = 0xB7, // + KEY_RMENU = 0xB8, // right Alt + KEY_PAUSE = 0xC5, // Pause + KEY_HOME = 0xC7, // Home on arrow keypad + KEY_UP = 0xC8, // UpArrow on arrow keypad + KEY_PRIOR = 0xC9, // PgUp on arrow keypad + KEY_LEFT = 0xCB, // LeftArrow on arrow keypad + KEY_RIGHT = 0xCD, // RightArrow on arrow keypad + KEY_END = 0xCF, // End on arrow keypad + KEY_DOWN = 0xD0, // DownArrow on arrow keypad + KEY_NEXT = 0xD1, // PgDn on arrow keypad + KEY_INSERT = 0xD2, // Insert on arrow keypad + KEY_DELETE = 0xD3, // Delete on arrow keypad + KEY_LWIN = 0xDB, // Left Windows key + KEY_RWIN = 0xDC, // Right Windows key + KEY_APPS = 0xDD, // AppMenu key + KEY_POWER = 0xDE, // + KEY_SLEEP = 0xDF, // + KEY_WAKE = 0xE3, // System Wake + KEY_WEBSEARCH = 0xE5, // Web Search + KEY_WEBFAVORITES = 0xE6, // Web Favorites + KEY_WEBREFRESH = 0xE7, // Web Refresh + KEY_WEBSTOP = 0xE8, // Web Stop + KEY_WEBFORWARD = 0xE9, // Web Forward + KEY_WEBBACK = 0xEA, // Web Back + KEY_MYCOMPUTER = 0xEB, // My Computer + KEY_MAIL = 0xEC, // Mail + KEY_MEDIASELECT = 0xED, // Media Select + KEY_FN = 0x100, // Function key + } +} diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs index 48f2b0d..4328dc1 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs @@ -48,7 +48,7 @@ namespace RGB.NET.Devices.Asus { try { - if (Device.Type == 0x00080000 || Device.Type == 0x00081000)//Keyboard + if ((Device.Type == 0x00080000) || (Device.Type == 0x00081000)) //Keyboard { foreach (KeyValuePair data in dataSet) { diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMappings.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMappings.cs new file mode 100644 index 0000000..7c336ac --- /dev/null +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMappings.cs @@ -0,0 +1,138 @@ +using System.Collections.Generic; +using RGB.NET.Core; + +namespace RGB.NET.Devices.Asus +{ + internal static class AsusKeyboardLedMappings + { + private static readonly Dictionary MasterKeysL_US = new Dictionary + { + { LedId.Keyboard_Escape, (0,0) }, + { LedId.Keyboard_F1, (0,1) }, + { LedId.Keyboard_F2, (0,2) }, + { LedId.Keyboard_F3, (0,3) }, + { LedId.Keyboard_F4, (0,4) }, + { LedId.Keyboard_F5, (0,6) }, + { LedId.Keyboard_F6, (0,7) }, + { LedId.Keyboard_F7, (0,8) }, + { LedId.Keyboard_F8, (0,9) }, + { LedId.Keyboard_F9, (0,11) }, + { LedId.Keyboard_F10, (0,12) }, + { LedId.Keyboard_F11, (0,13) }, + { LedId.Keyboard_F12, (0,14) }, + { LedId.Keyboard_PrintScreen, (0,15) }, + { LedId.Keyboard_ScrollLock, (0,16) }, + { LedId.Keyboard_PauseBreak, (0,17) }, + { LedId.Keyboard_Programmable1, (0,18) }, + { LedId.Keyboard_Programmable2, (0,19) }, + { LedId.Keyboard_Programmable3, (0,20) }, + { LedId.Keyboard_Programmable4, (0,21) }, + + { LedId.Keyboard_GraveAccentAndTilde, (1,0) }, + { LedId.Keyboard_1, (1,1) }, + { LedId.Keyboard_2, (1,2) }, + { LedId.Keyboard_3, (1,3) }, + { LedId.Keyboard_4, (1,4) }, + { LedId.Keyboard_5, (1,5) }, + { LedId.Keyboard_6, (1,6) }, + { LedId.Keyboard_7, (1,7) }, + { LedId.Keyboard_8, (1,8) }, + { LedId.Keyboard_9, (1,9) }, + { LedId.Keyboard_0, (1,10) }, + { LedId.Keyboard_MinusAndUnderscore, (1,11) }, + { LedId.Keyboard_EqualsAndPlus, (1,12) }, + { LedId.Keyboard_Backspace, (1,14) }, + { LedId.Keyboard_Insert, (1,15) }, + { LedId.Keyboard_Home, (1,16) }, + { LedId.Keyboard_PageUp, (1,17) }, + { LedId.Keyboard_NumLock, (1,18) }, + { LedId.Keyboard_NumSlash, (1,19) }, + { LedId.Keyboard_NumAsterisk, (1,20) }, + { LedId.Keyboard_NumMinus, (1,21) }, + + { LedId.Keyboard_Tab, (2,0) }, + { LedId.Keyboard_Q, (2,1) }, + { LedId.Keyboard_W, (2,2) }, + { LedId.Keyboard_E, (2,3) }, + { LedId.Keyboard_R, (2,4) }, + { LedId.Keyboard_T, (2,5) }, + { LedId.Keyboard_Y, (2,6) }, + { LedId.Keyboard_U, (2,7) }, + { LedId.Keyboard_I, (2,8) }, + { LedId.Keyboard_O, (2,9) }, + { LedId.Keyboard_P, (2,10) }, + { LedId.Keyboard_BracketLeft, (2,11) }, + { LedId.Keyboard_BracketRight, (2,12) }, + { LedId.Keyboard_Backslash, (2,14) }, + { LedId.Keyboard_Delete, (2,15) }, + { LedId.Keyboard_End, (2,16) }, + { LedId.Keyboard_PageDown, (2,17) }, + { LedId.Keyboard_Num7, (2,18) }, + { LedId.Keyboard_Num8, (2,19) }, + { LedId.Keyboard_Num9, (2,20) }, + { LedId.Keyboard_NumPlus, (2,21) }, + + { LedId.Keyboard_CapsLock, (3,0) }, + { LedId.Keyboard_A, (3,1) }, + { LedId.Keyboard_S, (3,2) }, + { LedId.Keyboard_D, (3,3) }, + { LedId.Keyboard_F, (3,4) }, + { LedId.Keyboard_G, (3,5) }, + { LedId.Keyboard_H, (3,6) }, + { LedId.Keyboard_J, (3,7) }, + { LedId.Keyboard_K, (3,8) }, + { LedId.Keyboard_L, (3,9) }, + { LedId.Keyboard_SemicolonAndColon, (3,10) }, + { LedId.Keyboard_ApostropheAndDoubleQuote, (3,11) }, + { LedId.Keyboard_Enter, (3,14) }, + { LedId.Keyboard_Num4, (3,18) }, + { LedId.Keyboard_Num5, (3,19) }, + { LedId.Keyboard_Num6, (3,20) }, + + { LedId.Keyboard_LeftShift, (4,0) }, + { LedId.Keyboard_Z, (4,2) }, + { LedId.Keyboard_X, (4,3) }, + { LedId.Keyboard_C, (4,4) }, + { LedId.Keyboard_V, (4,5) }, + { LedId.Keyboard_B, (4,6) }, + { LedId.Keyboard_N, (4,7) }, + { LedId.Keyboard_M, (4,8) }, + { LedId.Keyboard_CommaAndLessThan, (4,9) }, + { LedId.Keyboard_PeriodAndBiggerThan, (4,10) }, + { LedId.Keyboard_SlashAndQuestionMark, (4,11) }, + { LedId.Keyboard_RightShift, (4,14) }, + { LedId.Keyboard_ArrowUp, (4,16) }, + { LedId.Keyboard_Num1, (4,18) }, + { LedId.Keyboard_Num2, (4,19) }, + { LedId.Keyboard_Num3, (4,20) }, + { LedId.Keyboard_NumEnter, (4,21) }, + + { LedId.Keyboard_LeftCtrl, (5,0) }, + { LedId.Keyboard_LeftGui, (5,1) }, + { LedId.Keyboard_LeftAlt, (5,2) }, + { LedId.Keyboard_Space, (5,6) }, + { LedId.Keyboard_RightAlt, (5,10) }, + { LedId.Keyboard_RightGui, (5,11) }, + { LedId.Keyboard_Application, (5,12) }, + { LedId.Keyboard_RightCtrl, (5,14) }, + { LedId.Keyboard_ArrowLeft, (5,15) }, + { LedId.Keyboard_ArrowDown, (5,16) }, + { LedId.Keyboard_ArrowRight, (5,17) }, + { LedId.Keyboard_Num0, (5,18) }, + { LedId.Keyboard_NumPeriodAndDelete, (5,20) } + }; + + /// + /// Contains all the hardware-id mappings for CoolerMaster devices. + /// + public static readonly Dictionary>> Mapping = + new Dictionary>> + { + { "", new Dictionary> + { + { AsusPhysicalKeyboardLayout.TODO, MasterKeysL_US } + } + }, + }; + } +} diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs index f3d1b6a..46a7a21 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs @@ -59,7 +59,6 @@ namespace RGB.NET.Devices.Asus /// protected override object CreateLedCustomData(LedId ledId) => asusCode; - /// private LedId AsusLedIdMapper(ushort asusKey) { switch (asusKey) From 2f3bf99acbef8665e85c3f89dcd817793f107bad Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Tue, 25 Feb 2020 22:31:14 +0100 Subject: [PATCH 03/51] Encapsulation --- .../Generic/WootingUpdateQueue.cs | 2 +- .../Native/_WootingDeviceInfo.cs | 14 +++++++------- RGB.NET.Devices.Wooting/Native/_WootingSDK.cs | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs b/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs index 8342768..8f89610 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingUpdateQueue.cs @@ -36,7 +36,7 @@ namespace RGB.NET.Devices.Wooting.Generic _WootingSDK.ArrayUpdateKeyboard(); } - + #endregion } } diff --git a/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs b/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs index 5855a7b..d22a518 100644 --- a/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs +++ b/RGB.NET.Devices.Wooting/Native/_WootingDeviceInfo.cs @@ -4,18 +4,18 @@ using RGB.NET.Devices.Wooting.Enum; namespace RGB.NET.Devices.Wooting.Native { [StructLayout(LayoutKind.Sequential)] - public struct _WootingDeviceInfo + internal struct _WootingDeviceInfo { - public bool Connected { get; private set; } + internal bool Connected { get; private set; } - public string Model { get; private set; } + internal string Model { get; private set; } - public byte MaxRows { get; private set; } + internal byte MaxRows { get; private set; } - public byte MaxColumns { get; private set; } + internal byte MaxColumns { get; private set; } - public byte KeycodeLimit { get; private set; } + internal byte KeycodeLimit { get; private set; } - public WootingDeviceType DeviceType { get; private set; } + internal WootingDeviceType DeviceType { get; private set; } } } diff --git a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs index a9017f3..3ba5380 100644 --- a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs +++ b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs @@ -6,13 +6,12 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; -using System.Text; using RGB.NET.Core; namespace RGB.NET.Devices.Wooting.Native { // ReSharper disable once InconsistentNaming - public class _WootingSDK + internal static class _WootingSDK { #region Library management From 6a18a1209e884191f4008c27135ba127bbb6a1c5 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Tue, 25 Feb 2020 22:40:51 +0100 Subject: [PATCH 04/51] Added LS100 strips support, detecting any iCUE configuration --- .../CorsairDeviceProvider.cs | 2 +- .../Custom/CorsairCustomRGBDeviceInfo.cs | 29 ++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index d048397..43a740c 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -227,7 +227,7 @@ namespace RGB.NET.Devices.Corsair { _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo)); - yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(info.CorsairDeviceIndex, nativeDeviceInfo, channelDeviceInfo, referenceLed, modelCounter)); + yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(info, nativeDeviceInfo, channelDeviceInfo, referenceLed, modelCounter)); referenceLed += channelDeviceInfo.deviceLedCount; channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize); diff --git a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs index 4fa6b07..424776e 100644 --- a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDeviceInfo.cs @@ -28,15 +28,16 @@ namespace RGB.NET.Devices.Corsair /// /// Internal constructor of managed . /// - /// The index of the . + /// The info describing the the . /// The native -struct /// The native representing this device. /// The id of the first led of this device. /// A dictionary containing counters to create unique names for equal devices models. - internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, + internal CorsairCustomRGBDeviceInfo(CorsairRGBDeviceInfo info, _CorsairDeviceInfo nativeInfo, + _CorsairChannelDeviceInfo channelDeviceInfo, CorsairLedId referenceCorsairLed, Dictionary modelCounter) - : base(deviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo, - GetModelName(channelDeviceInfo.type), modelCounter) + : base(info.CorsairDeviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo, + GetModelName(info, channelDeviceInfo), modelCounter) { this.ReferenceCorsairLed = referenceCorsairLed; @@ -72,9 +73,9 @@ namespace RGB.NET.Devices.Corsair } } - private static string GetModelName(CorsairChannelDeviceType deviceType) + private static string GetModelName(IRGBDeviceInfo info, _CorsairChannelDeviceInfo channelDeviceInfo) { - switch (deviceType) + switch (channelDeviceInfo.type) { case CorsairChannelDeviceType.Invalid: return "Invalid"; @@ -92,7 +93,19 @@ namespace RGB.NET.Devices.Corsair return "ML Fan"; case CorsairChannelDeviceType.Strip: - return "Led Strip"; + // LS100 Led Strips are reported as one big strip if configured in monitor mode in iCUE, 138 LEDs for dual monitor, 84 for single + if ((info.Model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 138)) + return "LS100 Led Strip (dual monitor)"; + else if ((info.Model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 84)) + return "LS100 Led Strip (single monitor)"; + // Any other value means an "External LED Strip" in iCUE, these are reported per-strip, 15 for short strips, 27 for long + else if ((info.Model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 15)) + return "LS100 Led Strip (short)"; + else if ((info.Model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 27)) + return "LS100 Led Strip (long)"; + // Device model is "Commander Pro" for regular LED strips + else + return "Led Strip"; case CorsairChannelDeviceType.DAP: return "DAP Fan"; @@ -101,7 +114,7 @@ namespace RGB.NET.Devices.Corsair return "Pump"; default: - throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null); + throw new ArgumentOutOfRangeException(nameof(channelDeviceInfo.type), channelDeviceInfo.type, null); } } From c6d9d993d41a1acf54a6820bce4f02705e092cfd Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Sat, 29 Feb 2020 22:07:35 +0000 Subject: [PATCH 05/51] Added g810-intl PID --- RGB.NET.Devices.Logitech/HID/DeviceChecker.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs b/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs index 5ec7a69..44a1d99 100644 --- a/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs +++ b/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs @@ -19,6 +19,7 @@ namespace RGB.NET.Devices.Logitech.HID ("G910", RGBDeviceType.Keyboard, 0xC32B, 0, "DE", @"Keyboards\G910\UK"), //TODO DarthAffe 15.11.2017: Somehow detect the current layout ("G910v2", RGBDeviceType.Keyboard, 0xC335, 0, "DE", @"Keyboards\G910\UK"), ("G810", RGBDeviceType.Keyboard, 0xC337, 0, "DE", @"Keyboards\G810\UK"), + ("G810", RGBDeviceType.Keyboard, 0xC331, 0, "DE", @"Keyboards\G810\UK"), ("G610", RGBDeviceType.Keyboard, 0xC333, 0, "DE", @"Keyboards\G610\UK"), ("G512", RGBDeviceType.Keyboard, 0xC33C, 0, "DE", @"Keyboards\G512\UK"), ("G410", RGBDeviceType.Keyboard, 0xC330, 0, "DE", @"Keyboards\G410\UK"), From c98ffd2dbf1d8081dc6bb6a719907a20eede67ec Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 3 Mar 2020 14:29:49 +0100 Subject: [PATCH 06/51] Correctly implemented Dispose for update-triggers --- RGB.NET.Core/RGBSurface.cs | 4 ++++ RGB.NET.Core/Update/AbstractUpdateTrigger.cs | 5 ++--- RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs | 3 +++ RGB.NET.Core/Update/TimerUpdateTrigger.cs | 3 +++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index 7ba3183..9528f78 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -139,6 +139,10 @@ namespace RGB.NET.Core try { deviceProvider.Dispose(); } catch { /* We do what we can */ } + foreach (IUpdateTrigger updateTrigger in _updateTriggers) + try { updateTrigger.Dispose(); } + catch { /* We do what we can */ } + _ledGroups.Clear(); _devices = null; _deviceProvider = null; diff --git a/RGB.NET.Core/Update/AbstractUpdateTrigger.cs b/RGB.NET.Core/Update/AbstractUpdateTrigger.cs index 3ac5d46..e311037 100644 --- a/RGB.NET.Core/Update/AbstractUpdateTrigger.cs +++ b/RGB.NET.Core/Update/AbstractUpdateTrigger.cs @@ -5,7 +5,7 @@ namespace RGB.NET.Core /// /// Represents a generic update trigger. /// - public class AbstractUpdateTrigger : AbstractBindable, IUpdateTrigger + public abstract class AbstractUpdateTrigger : AbstractBindable, IUpdateTrigger { #region Events @@ -31,8 +31,7 @@ namespace RGB.NET.Core protected virtual void OnUpdate(CustomUpdateData updateData = null) => Update?.Invoke(this, updateData); /// - public virtual void Dispose() - { } + public abstract void Dispose(); #endregion } diff --git a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs index 04cfb92..8f4beba 100644 --- a/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs +++ b/RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs @@ -144,6 +144,9 @@ namespace RGB.NET.Core UpdateFrequency = UpdateRateHardLimit; } + /// + public override void Dispose() => Stop(); + #endregion } } diff --git a/RGB.NET.Core/Update/TimerUpdateTrigger.cs b/RGB.NET.Core/Update/TimerUpdateTrigger.cs index 23eaa96..0171ffb 100644 --- a/RGB.NET.Core/Update/TimerUpdateTrigger.cs +++ b/RGB.NET.Core/Update/TimerUpdateTrigger.cs @@ -106,6 +106,9 @@ namespace RGB.NET.Core } } + /// + public override void Dispose() => Stop(); + #endregion } } From 1cfdeefde1f03300c4bd635099fa9929e55ce1e7 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 3 Mar 2020 14:30:12 +0100 Subject: [PATCH 07/51] Added native-unload to all deviceprovider-disposes --- RGB.NET.Devices.Asus_Legacy/AsusDeviceProvider.cs | 7 +++++-- RGB.NET.Devices.Asus_Legacy/Native/_AsusSDK.cs | 2 +- .../CoolerMasterDeviceProvider.cs | 5 ++++- .../Native/_CoolerMasterSDK.cs | 2 +- RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs | 5 ++++- RGB.NET.Devices.Corsair/Native/_CUESDK.cs | 8 ++++---- RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs | 9 ++++++++- RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs | 2 +- RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 5 ++++- RGB.NET.Devices.Msi/Native/_MsiSDK.cs | 2 +- RGB.NET.Devices.Razer/Native/_RazerSDK.cs | 2 +- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 8 +++++++- RGB.NET.Devices.Roccat/Native/_ROCCATSDK.cs | 8 ++++---- RGB.NET.Devices.Roccat/RoccatDeviceProvider.cs | 3 +++ RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs | 4 +++- RGB.NET.Devices.Wooting/Native/_WootingSDK.cs | 6 +++--- RGB.NET.Devices.Wooting/WootingDeviceProvider.cs | 11 ++++++----- 17 files changed, 60 insertions(+), 29 deletions(-) diff --git a/RGB.NET.Devices.Asus_Legacy/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus_Legacy/AsusDeviceProvider.cs index 4ca979a..946125d 100644 --- a/RGB.NET.Devices.Asus_Legacy/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus_Legacy/AsusDeviceProvider.cs @@ -228,7 +228,7 @@ namespace RGB.NET.Devices.Asus catch { if (throwExceptions) throw; } #endregion - + UpdateTrigger?.Start(); Devices = new ReadOnlyCollection(devices); @@ -267,7 +267,10 @@ namespace RGB.NET.Devices.Asus /// public void Dispose() - { } + { + try { _AsusSDK.UnloadAsusSDK(); } + catch { /* at least we tried */ } + } #endregion } diff --git a/RGB.NET.Devices.Asus_Legacy/Native/_AsusSDK.cs b/RGB.NET.Devices.Asus_Legacy/Native/_AsusSDK.cs index 830dadd..437a3ea 100644 --- a/RGB.NET.Devices.Asus_Legacy/Native/_AsusSDK.cs +++ b/RGB.NET.Devices.Asus_Legacy/Native/_AsusSDK.cs @@ -75,7 +75,7 @@ namespace RGB.NET.Devices.Asus.Native //_getDramColorPointer = (GetDramColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "GetDramColor"), typeof(GetDramColorPointer)); } - private static void UnloadAsusSDK() + internal static void UnloadAsusSDK() { if (_dllHandle == IntPtr.Zero) return; diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index f091ed3..e676ca1 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -108,7 +108,7 @@ namespace RGB.NET.Devices.CoolerMaster { RGBDeviceType deviceType = index.GetDeviceType(); if (deviceType == RGBDeviceType.None) continue; - + if (_CoolerMasterSDK.IsDevicePlugged(index)) { if (!loadFilter.HasFlag(deviceType)) continue; @@ -185,6 +185,9 @@ namespace RGB.NET.Devices.CoolerMaster } catch {/* shit happens */} } + + try { _CoolerMasterSDK.UnloadCMSDK(); } + catch { /* at least we tried */ } } #endregion diff --git a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs index 00e89c8..ac23587 100644 --- a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs +++ b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs @@ -52,7 +52,7 @@ namespace RGB.NET.Devices.CoolerMaster.Native _setAllLedColorPointer = (SetAllLedColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetAllLedColor"), typeof(SetAllLedColorPointer)); } - private static void UnloadCMSDK() + internal static void UnloadCMSDK() { if (_dllHandle == IntPtr.Zero) return; diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index d048397..330be29 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -292,7 +292,10 @@ namespace RGB.NET.Devices.Corsair /// public void Dispose() - { } + { + try { _CUESDK.UnloadCUESDK(); } + catch { /* at least we tried */ } + } #endregion } diff --git a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs index 0e319ff..9b217e4 100644 --- a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs +++ b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs @@ -56,7 +56,7 @@ namespace RGB.NET.Devices.Corsair.Native _corsairGetLastErrorPointer = (CorsairGetLastErrorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLastError"), typeof(CorsairGetLastErrorPointer)); } - private static void UnloadCUESDK() + internal static void UnloadCUESDK() { if (_dllHandle == IntPtr.Zero) return; @@ -136,7 +136,7 @@ namespace RGB.NET.Devices.Corsair.Native #endregion // ReSharper disable EventExceptionNotDocumented - + /// /// CUE-SDK: set specified LEDs to some colors. /// This function set LEDs colors in the buffer which is written to the devices via CorsairSetLedsColorsFlushBuffer or CorsairSetLedsColorsFlushBufferAsync. @@ -151,7 +151,7 @@ namespace RGB.NET.Devices.Corsair.Native /// This function executes synchronously, if you are concerned about delays consider using CorsairSetLedsColorsFlushBufferAsync /// internal static bool CorsairSetLedsColorsFlushBuffer() => _corsairSetLedsColorsFlushBufferPointer(); - + /// /// CUE-SDK: get current color for the list of requested LEDs. /// The color should represent the actual state of the hardware LED, which could be a combination of SDK and/or CUE input. @@ -175,7 +175,7 @@ namespace RGB.NET.Devices.Corsair.Native /// CUE-SDK: returns information about device at provided index. /// internal static IntPtr CorsairGetDeviceInfo(int deviceIndex) => _corsairGetDeviceInfoPointer(deviceIndex); - + /// /// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions. /// diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs index 991fc01..eaab179 100644 --- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs +++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs @@ -182,7 +182,14 @@ namespace RGB.NET.Devices.Logitech public void ResetDevices() => _LogitechGSDK.LogiLedRestoreLighting(); /// - public void Dispose() => _LogitechGSDK.LogiLedRestoreLighting(); + public void Dispose() + { + try { _LogitechGSDK.LogiLedRestoreLighting(); } + catch { /* at least we tried */ } + + try { _LogitechGSDK.UnloadLogitechGSDK(); } + catch { /* at least we tried */ } + } #endregion } diff --git a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs index 39d0968..8f1b826 100644 --- a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs +++ b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs @@ -55,7 +55,7 @@ namespace RGB.NET.Devices.Logitech.Native _logiLedSetLightingForTargetZonePointer = (LogiLedSetLightingForTargetZonePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingForTargetZone"), typeof(LogiLedSetLightingForTargetZonePointer)); } - private static void UnloadLogitechGSDK() + internal static void UnloadLogitechGSDK() { if (_dllHandle == IntPtr.Zero) return; diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index 59a3980..f5bf830 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -163,7 +163,10 @@ namespace RGB.NET.Devices.Msi /// public void Dispose() - { } + { + try { _MsiSDK.UnloadMsiSDK(); } + catch { /* at least we tried */ } + } #endregion } diff --git a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs index a67aa94..930352f 100644 --- a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs +++ b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs @@ -60,7 +60,7 @@ namespace RGB.NET.Devices.Msi.Native _getErrorMessagePointer = (GetErrorMessagePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "MLAPI_GetErrorMessage"), typeof(GetErrorMessagePointer)); } - private static void UnloadMsiSDK() + internal static void UnloadMsiSDK() { if (_dllHandle == IntPtr.Zero) return; diff --git a/RGB.NET.Devices.Razer/Native/_RazerSDK.cs b/RGB.NET.Devices.Razer/Native/_RazerSDK.cs index 17742b3..4802196 100644 --- a/RGB.NET.Devices.Razer/Native/_RazerSDK.cs +++ b/RGB.NET.Devices.Razer/Native/_RazerSDK.cs @@ -52,7 +52,7 @@ namespace RGB.NET.Devices.Razer.Native _deleteEffectPointer = (DeleteEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "DeleteEffect"), typeof(DeleteEffectPointer)); } - private static void UnloadRazerSDK() + internal static void UnloadRazerSDK() { if (_dllHandle == IntPtr.Zero) return; diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 5c9f88b..2172491 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -222,7 +222,13 @@ namespace RGB.NET.Devices.Razer } /// - public void Dispose() => TryUnInit(); + public void Dispose() + { + TryUnInit(); + + try { _RazerSDK.UnloadRazerSDK(); } + catch { /* at least we tried */ } + } #endregion } diff --git a/RGB.NET.Devices.Roccat/Native/_ROCCATSDK.cs b/RGB.NET.Devices.Roccat/Native/_ROCCATSDK.cs index aa59118..21e1644 100644 --- a/RGB.NET.Devices.Roccat/Native/_ROCCATSDK.cs +++ b/RGB.NET.Devices.Roccat/Native/_ROCCATSDK.cs @@ -27,11 +27,11 @@ namespace RGB.NET.Devices.Roccat.Native /// internal static void Reload() { - UnloadCUESDK(); - LoadCUESDK(); + UnloadRoccatSDK(); + LoadRoccatSDK(); } - private static void LoadCUESDK() + private static void LoadRoccatSDK() { if (_dllHandle != IntPtr.Zero) return; @@ -57,7 +57,7 @@ namespace RGB.NET.Devices.Roccat.Native _setAllLedSfxPointer = (SetAllLedSfxPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "Set_all_LEDSFX"), typeof(SetAllLedSfxPointer)); } - private static void UnloadCUESDK() + internal static void UnloadRoccatSDK() { if (_dllHandle == IntPtr.Zero) return; diff --git a/RGB.NET.Devices.Roccat/RoccatDeviceProvider.cs b/RGB.NET.Devices.Roccat/RoccatDeviceProvider.cs index 391a0da..4ad9a9e 100644 --- a/RGB.NET.Devices.Roccat/RoccatDeviceProvider.cs +++ b/RGB.NET.Devices.Roccat/RoccatDeviceProvider.cs @@ -114,6 +114,9 @@ namespace RGB.NET.Devices.Roccat try { _RoccatSDK.UnloadSDK(_sdkHandle); } catch { /* We tried our best */} } + + try { _RoccatSDK.UnloadRoccatSDK(); } + catch { /* at least we tried */ } } #endregion diff --git a/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs b/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs index be7f5ac..8b3d84d 100644 --- a/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs +++ b/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs @@ -85,7 +85,9 @@ namespace RGB.NET.Devices.SteelSeries.API internal static void Dispose() { - ResetLeds(); + if (IsInitialized) + ResetLeds(); + _client.Dispose(); } diff --git a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs index a9017f3..b90e4f7 100644 --- a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs +++ b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs @@ -52,7 +52,7 @@ namespace RGB.NET.Devices.Wooting.Native _arraySetSinglePointer = (ArraySetSinglePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_array_set_single"), typeof(ArraySetSinglePointer)); } - private static void UnloadWootingSDK() + internal static void UnloadWootingSDK() { if (_dllHandle == IntPtr.Zero) return; @@ -91,13 +91,13 @@ namespace RGB.NET.Devices.Wooting.Native [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate IntPtr GetDeviceInfoPointer(); - + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate bool KeyboardConnectedPointer(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate bool ResetPointer(); - + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate bool ArrayUpdateKeyboardPointer(); diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 5a1113c..4635f74 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -28,13 +28,13 @@ namespace RGB.NET.Devices.Wooting /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// The first match will be used. /// - public static List PossibleX86NativePaths { get; } = new List {"x86/wooting-rgb-sdk.dll"}; + public static List PossibleX86NativePaths { get; } = new List { "x86/wooting-rgb-sdk.dll" }; /// /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// The first match will be used. /// - public static List PossibleX64NativePaths { get; } = new List {"x64/wooting-rgb-sdk64.dll"}; + public static List PossibleX64NativePaths { get; } = new List { "x64/wooting-rgb-sdk64.dll" }; /// /// @@ -144,9 +144,10 @@ namespace RGB.NET.Devices.Wooting public void Dispose() { try { _WootingSDK.Reset(); } - catch - { /* Unlucky.. */ - } + catch { /* Unlucky.. */ } + + try { _WootingSDK.UnloadWootingSDK(); } + catch { /* at least we tried */ } } #endregion From 83edbc6eac83804876ceb23d6744b3fb7748ecfb Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 3 Mar 2020 14:50:31 +0100 Subject: [PATCH 08/51] Fully implemented disposing on devices --- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 8 +++++-- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 7 +++++- RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs | 9 ++++++++ .../AsusDeviceProvider.cs | 3 +++ .../Generic/AsusRGBDevice.cs | 3 +++ .../CoolerMasterDeviceProvider.cs | 3 +++ .../Generic/CoolerMasterRGBDevice.cs | 3 +++ .../CorsairDeviceProvider.cs | 3 +++ .../Generic/CorsairRGBDevice.cs | 9 ++++++++ RGB.NET.Devices.DMX/DMXDeviceProvider.cs | 5 +++- RGB.NET.Devices.DMX/E131/E131Device.cs | 9 ++++++++ .../Generic/LogitechRGBDevice.cs | 9 ++++++++ .../LogitechDeviceProvider.cs | 3 +++ RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs | 9 ++++++++ RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 3 +++ .../Generic/NovationRGBDevice.cs | 5 +++- .../NovationDeviceProvider.cs | 5 +++- .../Generic/RazerRGBDevice.cs | 9 ++++++++ RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 3 +++ .../Server/SoIPServerRGBDevice.cs | 3 +++ RGB.NET.Devices.SoIP/SoIPDeviceProvider.cs | 6 ++--- .../Generic/SteelSeriesRGBDevice.cs | 9 ++++++++ .../SteelSeriesDeviceProvider.cs | 10 ++++---- .../Arduino/ArduinoWS2812USBDevice.cs | 9 ++++++++ .../Arduino/ArduinoWS281XDeviceDefinition.cs | 8 ++----- .../Bitwizard/BitwizardWS2812USBDevice.cs | 9 ++++++++ .../BitwizardWS281XDeviceDefinition.cs | 8 ++----- .../Generic/IWS281XDeviceDefinition.cs | 2 +- .../WS281XDeviceProvider.cs | 23 ++++++++++++++----- .../Generic/WootingRGBDevice.cs | 9 ++++++++ .../WootingDeviceProvider.cs | 3 +++ 31 files changed, 174 insertions(+), 33 deletions(-) diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index 2ed8377..a737f29 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -157,8 +157,12 @@ namespace RGB.NET.Core /// public virtual void Dispose() { - SpecialDeviceParts.Clear(); - LedMapping.Clear(); + try + { + SpecialDeviceParts.Clear(); + LedMapping.Clear(); + } + catch { /* this really shouldn't happen */ } } /// diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index f8e3834..cf19d8c 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -172,7 +172,12 @@ namespace RGB.NET.Devices.Asus /// public void Dispose() { - _sdk?.ReleaseControl(0); + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } + + try { _sdk?.ReleaseControl(0); } + catch { /* at least we tried */ } + _sdk = null; } diff --git a/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs b/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs index 0241828..42caff9 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs @@ -80,6 +80,15 @@ namespace RGB.NET.Devices.Asus //} } + /// + public override void Dispose() + { + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + + base.Dispose(); + } + #endregion } } diff --git a/RGB.NET.Devices.Asus_Legacy/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus_Legacy/AsusDeviceProvider.cs index 946125d..6dbae09 100644 --- a/RGB.NET.Devices.Asus_Legacy/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus_Legacy/AsusDeviceProvider.cs @@ -268,6 +268,9 @@ namespace RGB.NET.Devices.Asus /// public void Dispose() { + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } + try { _AsusSDK.UnloadAsusSDK(); } catch { /* at least we tried */ } } diff --git a/RGB.NET.Devices.Asus_Legacy/Generic/AsusRGBDevice.cs b/RGB.NET.Devices.Asus_Legacy/Generic/AsusRGBDevice.cs index 083cafd..011383b 100644 --- a/RGB.NET.Devices.Asus_Legacy/Generic/AsusRGBDevice.cs +++ b/RGB.NET.Devices.Asus_Legacy/Generic/AsusRGBDevice.cs @@ -80,6 +80,9 @@ namespace RGB.NET.Devices.Asus /// public override void Dispose() { + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + if ((DeviceInfo is AsusRGBDeviceInfo deviceInfo) && (deviceInfo.Handle != IntPtr.Zero)) Marshal.FreeHGlobal(deviceInfo.Handle); diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index e676ca1..0e4b6c0 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -175,6 +175,9 @@ namespace RGB.NET.Devices.CoolerMaster /// public void Dispose() { + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } + if (IsInitialized) foreach (IRGBDevice device in Devices) { diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs index c35676e..d33351f 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs @@ -74,6 +74,9 @@ namespace RGB.NET.Devices.CoolerMaster /// public override void Dispose() { + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + _CoolerMasterSDK.EnableLedControl(false, DeviceInfo.DeviceIndex); base.Dispose(); diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 330be29..166662d 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -293,6 +293,9 @@ namespace RGB.NET.Devices.Corsair /// public void Dispose() { + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } + try { _CUESDK.UnloadCUESDK(); } catch { /* at least we tried */ } } diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs index bb0c479..650a61e 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs @@ -122,6 +122,15 @@ namespace RGB.NET.Devices.Corsair Marshal.FreeHGlobal(ptr); } + /// + public override void Dispose() + { + try { DeviceUpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + + base.Dispose(); + } + #endregion } } diff --git a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs index 3e7d889..a151778 100644 --- a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs +++ b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs @@ -116,7 +116,10 @@ namespace RGB.NET.Devices.DMX /// public void Dispose() - { } + { + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } + } #endregion } diff --git a/RGB.NET.Devices.DMX/E131/E131Device.cs b/RGB.NET.Devices.DMX/E131/E131Device.cs index 871466e..1b199dd 100644 --- a/RGB.NET.Devices.DMX/E131/E131Device.cs +++ b/RGB.NET.Devices.DMX/E131/E131Device.cs @@ -59,6 +59,15 @@ namespace RGB.NET.Devices.DMX.E131 /// protected override void UpdateLeds(IEnumerable ledsToUpdate) => _updateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + /// + public override void Dispose() + { + try { _updateQueue?.Dispose(); } + catch { /* at least we tried */ } + + base.Dispose(); + } + #endregion } } diff --git a/RGB.NET.Devices.Logitech/Generic/LogitechRGBDevice.cs b/RGB.NET.Devices.Logitech/Generic/LogitechRGBDevice.cs index 02a8373..74104fa 100644 --- a/RGB.NET.Devices.Logitech/Generic/LogitechRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/Generic/LogitechRGBDevice.cs @@ -70,6 +70,15 @@ namespace RGB.NET.Devices.Logitech ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Logitech", $"{layoutPath}.xml"), layout, true); } + /// + public override void Dispose() + { + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + + base.Dispose(); + } + #endregion } } diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs index eaab179..5169eb3 100644 --- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs +++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs @@ -184,6 +184,9 @@ namespace RGB.NET.Devices.Logitech /// public void Dispose() { + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } + try { _LogitechGSDK.LogiLedRestoreLighting(); } catch { /* at least we tried */ } diff --git a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs index e6a5210..258bf84 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs @@ -68,6 +68,15 @@ namespace RGB.NET.Devices.Msi protected override void UpdateLeds(IEnumerable ledsToUpdate) => DeviceUpdateQueue.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is int))); + /// + public override void Dispose() + { + try { DeviceUpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + + base.Dispose(); + } + #endregion } } diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index f5bf830..dc46a01 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -164,6 +164,9 @@ namespace RGB.NET.Devices.Msi /// public void Dispose() { + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } + try { _MsiSDK.UnloadMsiSDK(); } catch { /* at least we tried */ } } diff --git a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs index c1904eb..8152ebe 100644 --- a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs +++ b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs @@ -78,8 +78,11 @@ namespace RGB.NET.Devices.Novation /// public override void Dispose() { + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + Reset(); - UpdateQueue.Dispose(); + base.Dispose(); } diff --git a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs index 5ad614f..b7890e8 100644 --- a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs +++ b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs @@ -122,7 +122,10 @@ namespace RGB.NET.Devices.Novation /// public void Dispose() - { } + { + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } + } #endregion } diff --git a/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs b/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs index 525dd58..e537caf 100644 --- a/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs @@ -81,6 +81,15 @@ namespace RGB.NET.Devices.Razer /// public void Reset() => UpdateQueue.Reset(); + /// + public override void Dispose() + { + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + + base.Dispose(); + } + #endregion } } diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 2172491..0f711bb 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -224,6 +224,9 @@ namespace RGB.NET.Devices.Razer /// public void Dispose() { + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } + TryUnInit(); try { _RazerSDK.UnloadRazerSDK(); } diff --git a/RGB.NET.Devices.SoIP/Server/SoIPServerRGBDevice.cs b/RGB.NET.Devices.SoIP/Server/SoIPServerRGBDevice.cs index 5a5285e..ca72447 100644 --- a/RGB.NET.Devices.SoIP/Server/SoIPServerRGBDevice.cs +++ b/RGB.NET.Devices.SoIP/Server/SoIPServerRGBDevice.cs @@ -66,6 +66,9 @@ namespace RGB.NET.Devices.SoIP.Server /// public override void Dispose() { + try { _updateQueue?.Dispose(); } + catch { /* at least we tried */ } + base.Dispose(); _tcpServer.Stop(); diff --git a/RGB.NET.Devices.SoIP/SoIPDeviceProvider.cs b/RGB.NET.Devices.SoIP/SoIPDeviceProvider.cs index 9152b9a..9755cc2 100644 --- a/RGB.NET.Devices.SoIP/SoIPDeviceProvider.cs +++ b/RGB.NET.Devices.SoIP/SoIPDeviceProvider.cs @@ -56,7 +56,7 @@ namespace RGB.NET.Devices.SoIP { if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SoIPDeviceProvider)}"); _instance = this; - + UpdateTrigger = new DeviceUpdateTrigger(); } @@ -130,8 +130,8 @@ namespace RGB.NET.Devices.SoIP /// public void Dispose() { - foreach (IRGBDevice device in Devices) - device.Dispose(); + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } } #endregion diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs index f13d918..78a65eb 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs @@ -83,6 +83,15 @@ namespace RGB.NET.Devices.SteelSeries ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\SteelSeries", $"{layoutPath}.xml"), layout, true); } + /// + public override void Dispose() + { + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + + base.Dispose(); + } + #endregion } } diff --git a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs index 9f59d7d..21402dd 100644 --- a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs +++ b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs @@ -117,11 +117,11 @@ namespace RGB.NET.Devices.SteelSeries /// public void Dispose() { - try - { - SteelSeriesSDK.Dispose(); - } - catch {/* shit happens */} + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } + + try { SteelSeriesSDK.Dispose(); } + catch { /* shit happens */ } } #endregion diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs index 5fa3c85..f8b9d4f 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs @@ -73,6 +73,15 @@ namespace RGB.NET.Devices.WS281X.Arduino /// protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + /// + public override void Dispose() + { + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + + base.Dispose(); + } + #endregion } } diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs index dc28760..0690926 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs @@ -39,7 +39,7 @@ namespace RGB.NET.Devices.WS281X.Arduino /// /// Initializes a new instance of the class. /// - /// The name of the serial-port to connect to. + /// The name of the serial-port to connect to. public ArduinoWS281XDeviceDefinition(string port) { this.Port = port; @@ -50,10 +50,8 @@ namespace RGB.NET.Devices.WS281X.Arduino #region Methods /// - public IEnumerable CreateDevices() + public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger) { - DeviceUpdateTrigger updateTrigger = new DeviceUpdateTrigger(); - ArduinoWS2812USBUpdateQueue queue = new ArduinoWS2812USBUpdateQueue(updateTrigger, Port, BaudRate); IEnumerable<(int channel, int ledCount)> channels = queue.GetChannels(); int counter = 0; @@ -64,8 +62,6 @@ namespace RGB.NET.Devices.WS281X.Arduino device.Initialize(ledCount); yield return device; } - - updateTrigger.Start(); } #endregion diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs index 0e4f7a9..74d52ee 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs @@ -63,6 +63,15 @@ namespace RGB.NET.Devices.WS281X.Bitwizard /// protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + /// + public override void Dispose() + { + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + + base.Dispose(); + } + #endregion } } diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs index d8bc4f3..b769519 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs @@ -43,7 +43,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard /// /// Initializes a new instance of the class. /// - /// The name of the serial-port to connect to. + /// The name of the serial-port to connect to. public BitwizardWS281XDeviceDefinition(string port) { this.Port = port; @@ -54,17 +54,13 @@ namespace RGB.NET.Devices.WS281X.Bitwizard #region Methods /// - public IEnumerable CreateDevices() + public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger) { - DeviceUpdateTrigger updateTrigger = new DeviceUpdateTrigger(); - BitwizardWS2812USBUpdateQueue queue = new BitwizardWS2812USBUpdateQueue(updateTrigger, Port, BaudRate); string name = Name ?? $"Bitwizard WS2812 USB ({Port})"; BitwizardWS2812USBDevice device = new BitwizardWS2812USBDevice(new BitwizardWS2812USBDeviceInfo(name), queue); device.Initialize(StripLength); yield return device; - - updateTrigger.Start(); } #endregion diff --git a/RGB.NET.Devices.WS281X/Generic/IWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Generic/IWS281XDeviceDefinition.cs index 8ff5fa9..a6f375e 100644 --- a/RGB.NET.Devices.WS281X/Generic/IWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/Generic/IWS281XDeviceDefinition.cs @@ -13,6 +13,6 @@ namespace RGB.NET.Devices.WS281X /// Gets the devices defined by this definition. /// /// The initialized devices defined by this definition. - IEnumerable CreateDevices(); + IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger); } } diff --git a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs index 127e54b..89ad1cc 100644 --- a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs +++ b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using RGB.NET.Core; namespace RGB.NET.Devices.WS281X @@ -37,6 +38,11 @@ namespace RGB.NET.Devices.WS281X // ReSharper disable once ReturnTypeCanBeEnumerable.Global public List DeviceDefinitions { get; } = new List(); + /// + /// The used to trigger the updates for corsair devices. + /// + public DeviceUpdateTrigger UpdateTrigger { get; } + #endregion #region Constructors @@ -49,6 +55,8 @@ namespace RGB.NET.Devices.WS281X { if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(WS281XDeviceProvider)}"); _instance = this; + + UpdateTrigger = new DeviceUpdateTrigger(); } #endregion @@ -69,17 +77,20 @@ namespace RGB.NET.Devices.WS281X try { + UpdateTrigger?.Stop(); + List devices = new List(); foreach (IWS281XDeviceDefinition deviceDefinition in DeviceDefinitions) { try { - devices.AddRange(deviceDefinition.CreateDevices()); + devices.AddRange(deviceDefinition.CreateDevices(UpdateTrigger)); } catch { if (throwExceptions) throw; } } - Devices = devices; + UpdateTrigger?.Start(); + Devices = new ReadOnlyCollection(devices); IsInitialized = true; } catch @@ -99,10 +110,10 @@ namespace RGB.NET.Devices.WS281X /// public void Dispose() { - if (IsInitialized) - foreach (IRGBDevice device in Devices) - if (device is IDisposable disposable) - disposable.Dispose(); + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */} + + DeviceDefinitions.Clear(); } #endregion diff --git a/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs b/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs index 7647a3d..b766da8 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingRGBDevice.cs @@ -63,6 +63,15 @@ namespace RGB.NET.Devices.Wooting.Generic /// protected abstract void InitializeLayout(); + /// + public override void Dispose() + { + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + + base.Dispose(); + } + #endregion } } diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 4635f74..638949a 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -143,6 +143,9 @@ namespace RGB.NET.Devices.Wooting /// public void Dispose() { + try { UpdateTrigger?.Dispose(); } + catch { /* at least we tried */ } + try { _WootingSDK.Reset(); } catch { /* Unlucky.. */ } From ad253fbeaaf7a3a9cb6ffa2e877c49ce8e339172 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 3 Mar 2020 15:08:01 +0100 Subject: [PATCH 09/51] Added locks for devices and device-providers --- RGB.NET.Core/RGBSurface.cs | 99 ++++++++++++++++---------- RGB.NET.Core/RGBSurfaceDeviceLoader.cs | 33 +++++---- 2 files changed, 79 insertions(+), 53 deletions(-) diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index 9528f78..74bc882 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -38,7 +38,14 @@ namespace RGB.NET.Core /// /// Gets a readonly list containing all loaded . /// - public IEnumerable Devices => new ReadOnlyCollection(_devices); + public IEnumerable Devices + { + get + { + lock (_devices) + return new ReadOnlyCollection(_devices); + } + } /// /// Gets a readonly list containing all registered . @@ -53,7 +60,14 @@ namespace RGB.NET.Core /// /// Gets a list of all on this . /// - public IEnumerable Leds => _devices.SelectMany(x => x); + public IEnumerable Leds + { + get + { + lock (_devices) + return _devices.SelectMany(x => x); + } + } #endregion @@ -92,32 +106,33 @@ namespace RGB.NET.Core bool updateDevices = customData["updateDevices"] as bool? ?? true; lock (_updateTriggers) - { - OnUpdating(updateTrigger, customData); + lock (_devices) + { + OnUpdating(updateTrigger, customData); - if (syncBack) - foreach (IRGBDevice device in Devices) - if (device.UpdateMode.HasFlag(DeviceUpdateMode.SyncBack) && device.DeviceInfo.SupportsSyncBack) - try { device.SyncBack(); } - catch (Exception ex) { OnException(ex); } + if (syncBack) + foreach (IRGBDevice device in _devices) + if (device.UpdateMode.HasFlag(DeviceUpdateMode.SyncBack) && device.DeviceInfo.SupportsSyncBack) + try { device.SyncBack(); } + catch (Exception ex) { OnException(ex); } - if (render) - lock (_ledGroups) - { - // Render brushes - foreach (ILedGroup ledGroup in _ledGroups.OrderBy(x => x.ZIndex)) - try { Render(ledGroup); } - catch (Exception ex) { OnException(ex); } - } + if (render) + lock (_ledGroups) + { + // Render brushes + foreach (ILedGroup ledGroup in _ledGroups.OrderBy(x => x.ZIndex)) + try { Render(ledGroup); } + catch (Exception ex) { OnException(ex); } + } - if (updateDevices) - foreach (IRGBDevice device in Devices) - if (!device.UpdateMode.HasFlag(DeviceUpdateMode.NoUpdate)) - try { device.Update(flushLeds); } - catch (Exception ex) { OnException(ex); } + if (updateDevices) + foreach (IRGBDevice device in _devices) + if (!device.UpdateMode.HasFlag(DeviceUpdateMode.NoUpdate)) + try { device.Update(flushLeds); } + catch (Exception ex) { OnException(ex); } - OnUpdated(); - } + OnUpdated(); + } } catch (Exception ex) { @@ -128,20 +143,19 @@ namespace RGB.NET.Core /// public void Dispose() { - //if (_updateTokenSource?.IsCancellationRequested == false) - // _updateTokenSource.Cancel(); + lock (_devices) + foreach (IRGBDevice device in _devices) + try { device.Dispose(); } + catch { /* We do what we can */} - foreach (IRGBDevice device in _devices) - try { device.Dispose(); } - catch { /* We do what we can */ } - - foreach (IRGBDeviceProvider deviceProvider in _deviceProvider) - try { deviceProvider.Dispose(); } - catch { /* We do what we can */ } + lock (_deviceProvider) + foreach (IRGBDeviceProvider deviceProvider in _deviceProvider) + try { deviceProvider.Dispose(); } + catch { /* We do what we can */} foreach (IUpdateTrigger updateTrigger in _updateTriggers) try { updateTrigger.Dispose(); } - catch { /* We do what we can */ } + catch { /* We do what we can */} _ledGroups.Clear(); _devices = null; @@ -224,8 +238,11 @@ namespace RGB.NET.Core private void UpdateSurfaceRectangle() { - Rectangle devicesRectangle = new Rectangle(_devices.Select(d => d.DeviceRectangle)); - SurfaceRectangle = SurfaceRectangle.SetSize(new Size(devicesRectangle.Location.X + devicesRectangle.Size.Width, devicesRectangle.Location.Y + devicesRectangle.Size.Height)); + lock (_devices) + { + Rectangle devicesRectangle = new Rectangle(_devices.Select(d => d.DeviceRectangle)); + SurfaceRectangle = SurfaceRectangle.SetSize(new Size(devicesRectangle.Location.X + devicesRectangle.Size.Width, devicesRectangle.Location.Y + devicesRectangle.Size.Height)); + } } /// @@ -235,7 +252,10 @@ namespace RGB.NET.Core /// A list of devices with the specified type. public IList GetDevices() where T : class - => new ReadOnlyCollection(_devices.Select(x => x as T).Where(x => x != null).ToList()); + { + lock (_devices) + return new ReadOnlyCollection(_devices.Select(x => x as T).Where(x => x != null).ToList()); + } /// /// Gets all devices of the specified . @@ -243,7 +263,10 @@ namespace RGB.NET.Core /// The of the devices to get. /// a list of devices matching the specified . public IList GetDevices(RGBDeviceType deviceType) - => new ReadOnlyCollection(_devices.Where(d => deviceType.HasFlag(d.DeviceInfo.DeviceType)).ToList()); + { + lock (_devices) + return new ReadOnlyCollection(_devices.Where(d => deviceType.HasFlag(d.DeviceInfo.DeviceType)).ToList()); + } /// /// Registers the provided . diff --git a/RGB.NET.Core/RGBSurfaceDeviceLoader.cs b/RGB.NET.Core/RGBSurfaceDeviceLoader.cs index f233282..df760c3 100644 --- a/RGB.NET.Core/RGBSurfaceDeviceLoader.cs +++ b/RGB.NET.Core/RGBSurfaceDeviceLoader.cs @@ -29,28 +29,31 @@ namespace RGB.NET.Core /// Specifies whether exception during the initialization sequence should be thrown or not. public void LoadDevices(IRGBDeviceProvider deviceProvider, RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) { - if (_deviceProvider.Contains(deviceProvider) || _deviceProvider.Any(x => x.GetType() == deviceProvider.GetType())) return; - - List addedDevices = new List(); - if (deviceProvider.IsInitialized || deviceProvider.Initialize(loadFilter, exclusiveAccessIfPossible, throwExceptions)) + lock (_deviceProvider) { - _deviceProvider.Add(deviceProvider); + if (_deviceProvider.Contains(deviceProvider) || _deviceProvider.Any(x => x.GetType() == deviceProvider.GetType())) return; - foreach (IRGBDevice device in deviceProvider.Devices) + List addedDevices = new List(); + if (deviceProvider.IsInitialized || deviceProvider.Initialize(loadFilter, exclusiveAccessIfPossible, throwExceptions)) { - if (_devices.Contains(device)) continue; + _deviceProvider.Add(deviceProvider); + lock (_devices) + foreach (IRGBDevice device in deviceProvider.Devices) + { + if (_devices.Contains(device)) continue; - addedDevices.Add(device); + addedDevices.Add(device); - device.PropertyChanged += DeviceOnPropertyChanged; - _devices.Add(device); + device.PropertyChanged += DeviceOnPropertyChanged; + _devices.Add(device); + } } - } - if (addedDevices.Any()) - { - UpdateSurfaceRectangle(); - SurfaceLayoutChanged?.Invoke(new SurfaceLayoutChangedEventArgs(addedDevices, true, false)); + if (addedDevices.Any()) + { + UpdateSurfaceRectangle(); + SurfaceLayoutChanged?.Invoke(new SurfaceLayoutChangedEventArgs(addedDevices, true, false)); + } } } From 9de6a43907bd08967fee0591d18285fe7c0dda6b Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 3 Mar 2020 15:20:39 +0100 Subject: [PATCH 10/51] Added locks for groups --- RGB.NET.Core/Groups/AbstractLedGroup.cs | 2 +- RGB.NET.Core/Groups/ILedGroup.cs | 2 +- RGB.NET.Groups/Groups/ListLedGroup.cs | 33 ++++++++++++++-------- RGB.NET.Groups/Groups/RectangleLedGroup.cs | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/RGB.NET.Core/Groups/AbstractLedGroup.cs b/RGB.NET.Core/Groups/AbstractLedGroup.cs index 7007152..eab6803 100644 --- a/RGB.NET.Core/Groups/AbstractLedGroup.cs +++ b/RGB.NET.Core/Groups/AbstractLedGroup.cs @@ -36,7 +36,7 @@ namespace RGB.NET.Core #region Methods /// - public abstract IEnumerable GetLeds(); + public abstract IList GetLeds(); /// public virtual void OnAttach() diff --git a/RGB.NET.Core/Groups/ILedGroup.cs b/RGB.NET.Core/Groups/ILedGroup.cs index 638f146..5db5e63 100644 --- a/RGB.NET.Core/Groups/ILedGroup.cs +++ b/RGB.NET.Core/Groups/ILedGroup.cs @@ -25,7 +25,7 @@ namespace RGB.NET.Core /// Gets a list containing all of this . /// /// The list containing all of this . - IEnumerable GetLeds(); + IList GetLeds(); /// /// Called when the is attached to the . diff --git a/RGB.NET.Groups/Groups/ListLedGroup.cs b/RGB.NET.Groups/Groups/ListLedGroup.cs index a5fed36..eb833d8 100644 --- a/RGB.NET.Groups/Groups/ListLedGroup.cs +++ b/RGB.NET.Groups/Groups/ListLedGroup.cs @@ -92,9 +92,10 @@ namespace RGB.NET.Groups { if (leds == null) return; - foreach (Led led in leds) - if ((led != null) && !ContainsLed(led)) - GroupLeds.Add(led); + lock (GroupLeds) + foreach (Led led in leds) + if ((led != null) && !ContainsLed(led)) + GroupLeds.Add(led); } /// @@ -111,9 +112,10 @@ namespace RGB.NET.Groups { if (leds == null) return; - foreach (Led led in leds) - if (led != null) - GroupLeds.Remove(led); + lock (GroupLeds) + foreach (Led led in leds) + if (led != null) + GroupLeds.Remove(led); } /// @@ -121,7 +123,11 @@ namespace RGB.NET.Groups /// /// The LED which should be checked. /// true if the LED is contained by this ledgroup; otherwise, false. - public bool ContainsLed(Led led) => (led != null) && GroupLeds.Contains(led); + public bool ContainsLed(Led led) + { + lock (GroupLeds) + return (led != null) && GroupLeds.Contains(led); + } /// /// Merges the from the given ledgroup in this ledgroup. @@ -129,9 +135,10 @@ namespace RGB.NET.Groups /// The ledgroup to merge. public void MergeLeds(ILedGroup groupToMerge) { - foreach (Led led in groupToMerge.GetLeds()) - if (!GroupLeds.Contains(led)) - GroupLeds.Add(led); + lock (GroupLeds) + foreach (Led led in groupToMerge.GetLeds()) + if (!GroupLeds.Contains(led)) + GroupLeds.Add(led); } /// @@ -139,7 +146,11 @@ namespace RGB.NET.Groups /// Gets a list containing the from this group. /// /// The list containing the . - public override IEnumerable GetLeds() => GroupLeds; + public override IList GetLeds() + { + lock (GroupLeds) + return new List(GroupLeds); + } #endregion } diff --git a/RGB.NET.Groups/Groups/RectangleLedGroup.cs b/RGB.NET.Groups/Groups/RectangleLedGroup.cs index 1b23c26..90bb88c 100644 --- a/RGB.NET.Groups/Groups/RectangleLedGroup.cs +++ b/RGB.NET.Groups/Groups/RectangleLedGroup.cs @@ -105,7 +105,7 @@ namespace RGB.NET.Groups /// Gets a list containing all of this . /// /// The list containing all of this . - public override IEnumerable GetLeds() => _ledCache ??= RGBSurface.Instance.Leds.Where(led => led.AbsoluteLedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList(); + public override IList GetLeds() => _ledCache ??= RGBSurface.Instance.Leds.Where(led => led.AbsoluteLedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList(); private void InvalidateCache() => _ledCache = null; From 6d2acbdcbf75bf0dd90ad7e74e4c8ea108e5786d Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 3 Mar 2020 15:45:15 +0100 Subject: [PATCH 11/51] Add Launchpad Mini support --- RGB.NET.Devices.Novation/Enum/NovationDevices.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RGB.NET.Devices.Novation/Enum/NovationDevices.cs b/RGB.NET.Devices.Novation/Enum/NovationDevices.cs index ca16a62..c9cf763 100644 --- a/RGB.NET.Devices.Novation/Enum/NovationDevices.cs +++ b/RGB.NET.Devices.Novation/Enum/NovationDevices.cs @@ -13,6 +13,9 @@ namespace RGB.NET.Devices.Novation { [DeviceId("Launchpad S")] [ColorCapability(NovationColorCapabilities.LimitedRG)] - LaunchpadS + LaunchpadS, + [DeviceId("Launchpad Mini")] + [ColorCapability(NovationColorCapabilities.LimitedRG)] + LaunchpadMini } } From bc9ff70975b1eb7b0a1067fc84d7f70bf62cfc2f Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 3 Mar 2020 16:00:36 +0100 Subject: [PATCH 12/51] Fixed use after dispose for novation devices --- RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs index 8152ebe..a66fb03 100644 --- a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs +++ b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs @@ -78,11 +78,11 @@ namespace RGB.NET.Devices.Novation /// public override void Dispose() { - try { UpdateQueue?.Dispose(); } - catch { /* at least we tried */ } - Reset(); + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + base.Dispose(); } From 276c1687a37269e58f39915b6e6e1b46d9dd095e Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 3 Mar 2020 17:17:42 +0100 Subject: [PATCH 13/51] Workarounded some unload-issues (still there but late enough to not cause too much issues) --- RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs | 5 +++-- RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index 0e4b6c0..0f34084 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -189,8 +189,9 @@ namespace RGB.NET.Devices.CoolerMaster catch {/* shit happens */} } - try { _CoolerMasterSDK.UnloadCMSDK(); } - catch { /* at least we tried */ } + // DarthAffe 03.03.2020: Should be done but isn't possible due to an weird winodws-hook inside the sdk which corrupts the stack when unloading the dll + //try { _CoolerMasterSDK.UnloadCMSDK(); } + //catch { /* at least we tried */ } } #endregion diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 0f711bb..c49cfcb 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -229,8 +229,9 @@ namespace RGB.NET.Devices.Razer TryUnInit(); - try { _RazerSDK.UnloadRazerSDK(); } - catch { /* at least we tried */ } + // DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit + //try { _RazerSDK.UnloadRazerSDK(); } + //catch { /* at least we tried */ } } #endregion From ad4e281dfa67a6bd455be4610eb5042cde881a25 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Thu, 12 Mar 2020 15:37:31 +0000 Subject: [PATCH 14/51] Added razer chroma uuids --- RGB.NET.Devices.Razer/Generic/Devices.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Devices.Razer/Generic/Devices.cs b/RGB.NET.Devices.Razer/Generic/Devices.cs index 76b5923..a1eeeff 100644 --- a/RGB.NET.Devices.Razer/Generic/Devices.cs +++ b/RGB.NET.Devices.Razer/Generic/Devices.cs @@ -17,7 +17,9 @@ namespace RGB.NET.Devices.Razer (new Guid("C83BDFE8-E7FC-40E0-99DB-872E23F19891"), "Razer Blade Stealth"), (new Guid("F2BEDFAF-A0FE-4651-9D41-B6CE603A3DDD"), "Razer Blade"), (new Guid("A73AC338-F0E5-4BF7-91AE-DD1F7E1737A5"), "Razer Blade Pro"), - (new Guid("608E743F-B402-44BD-A7A6-7AA9F574ECF4"), "Razer Blackwidow Chroma v2") + (new Guid("608E743F-B402-44BD-A7A6-7AA9F574ECF4"), "Razer Blackwidow Chroma v2"), + (new Guid("F85E7473-8F03-45B6-A16E-CE26CB8D2441"), "Razer Huntsman"), + (new Guid("16BB5ABD-C1CD-4CB3-BDF7-62438748BD98"), "Razer Blackwidow Elite") }; public static readonly List<(Guid guid, string model)> MICE = new List<(Guid guid, string model)> @@ -37,7 +39,8 @@ namespace RGB.NET.Devices.Razer { (new Guid("DF3164D7-5408-4A0E-8A7F-A7412F26BEBF"), "Razer ManO'War"), (new Guid("CD1E09A5-D5E6-4A6C-A93B-E6D9BF1D2092"), "Razer Kraken 7.1 Chroma"), - (new Guid("7FB8A36E-9E74-4BB3-8C86-CAC7F7891EBD"), "Razer Kraken 7.1 Chroma Refresh") + (new Guid("7FB8A36E-9E74-4BB3-8C86-CAC7F7891EBD"), "Razer Kraken 7.1 Chroma Refresh"), + (new Guid("FB357780-4617-43A7-960F-D1190ED54806"), "Razer Kraken Kitty") }; public static readonly List<(Guid guid, string model)> MOUSEMATS = new List<(Guid guid, string model)> From 46960200accd4fc9e2776ce3fbcf3ba670879aee Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 18 Apr 2020 14:22:52 +0200 Subject: [PATCH 15/51] Small Performance-improvements in Brush-Color-Finalization --- RGB.NET.Core/Brushes/AbstractBrush.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/RGB.NET.Core/Brushes/AbstractBrush.cs b/RGB.NET.Core/Brushes/AbstractBrush.cs index 7e36afc..7521bf2 100644 --- a/RGB.NET.Core/Brushes/AbstractBrush.cs +++ b/RGB.NET.Core/Brushes/AbstractBrush.cs @@ -110,14 +110,20 @@ namespace RGB.NET.Core /// The finalized color. protected virtual Color FinalizeColor(Color color) { - foreach (IColorCorrection colorCorrection in ColorCorrections) - color = colorCorrection.ApplyTo(color); + if (ColorCorrections.Count > 0) + foreach (IColorCorrection colorCorrection in ColorCorrections) + color = colorCorrection.ApplyTo(color); // Since we use HSV to calculate there is no way to make a color 'brighter' than 100% // Be carefull with the naming: Since we use HSV the correct term is 'value' but outside we call it 'brightness' // THIS IS NOT A HSB CALCULATION!!! - return color.MultiplyHSV(value: Brightness.Clamp(0, 1)) - .MultiplyA(Opacity.Clamp(0, 1)); + if (Brightness < 1) + color = color.MultiplyHSV(value: Brightness.Clamp(0, 1)); + + if (Opacity < 1) + color = color.MultiplyA(Opacity.Clamp(0, 1)); + + return color; } #endregion From 2488cfa52aecb6021e7f9a742d3c1c99761bd712 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 18 Apr 2020 14:55:11 +0200 Subject: [PATCH 16/51] Added logitech HIDs from #110 --- RGB.NET.Devices.Logitech/HID/DeviceChecker.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs b/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs index 44a1d99..1387891 100644 --- a/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs +++ b/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs @@ -18,6 +18,7 @@ namespace RGB.NET.Devices.Logitech.HID { ("G910", RGBDeviceType.Keyboard, 0xC32B, 0, "DE", @"Keyboards\G910\UK"), //TODO DarthAffe 15.11.2017: Somehow detect the current layout ("G910v2", RGBDeviceType.Keyboard, 0xC335, 0, "DE", @"Keyboards\G910\UK"), + ("G915", RGBDeviceType.Keyboard, 0xC541, 0, "DE", @"Keyboards\G915\UK"), ("G810", RGBDeviceType.Keyboard, 0xC337, 0, "DE", @"Keyboards\G810\UK"), ("G810", RGBDeviceType.Keyboard, 0xC331, 0, "DE", @"Keyboards\G810\UK"), ("G610", RGBDeviceType.Keyboard, 0xC333, 0, "DE", @"Keyboards\G610\UK"), @@ -57,6 +58,7 @@ namespace RGB.NET.Devices.Logitech.HID ("G303", RGBDeviceType.Mouse, 0xC080, 2, "default", @"Mice\G303"), ("G203", RGBDeviceType.Mouse, 0xC084, 1, "default", @"Mice\G203"), ("G Pro", RGBDeviceType.Mouse, 0xC085, 1, "default", @"Mice\GPro"), + ("G Pro Hero", RGBDeviceType.Mouse, 0xC08C, 1, "default", @"Mice\GProHero"), ("G633", RGBDeviceType.Headset, 0x0A5C, 2, "default", @"Headsets\G633"), ("G933", RGBDeviceType.Headset, 0x0A5B, 2, "default", @"Headsets\G933"), ("G935", RGBDeviceType.Headset, 0x0A87, 2, "default", @"Headsets\G935"), From f764c3dc8fbafaa367320866b5d71a5899070518 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 18 Apr 2020 15:12:09 +0200 Subject: [PATCH 17/51] Added device-interfaces --- RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/IFan.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/IKeyboard.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs | 8 ++++++++ RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs | 8 ++++++++ RGB.NET.Core/RGB.NET.Core.csproj.DotSettings | 1 + 16 files changed, 121 insertions(+) create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IFan.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IKeyboard.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs create mode 100644 RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs b/RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs new file mode 100644 index 0000000..6053c40 --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/ICooler.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a cooler-device + /// + public interface ICooler : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs b/RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs new file mode 100644 index 0000000..6734e16 --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IDRAM.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a DRAM-device + /// + public interface IDRAM : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IFan.cs b/RGB.NET.Core/Devices/TypeInterfaces/IFan.cs new file mode 100644 index 0000000..3f9eb57 --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IFan.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// represents a fan-device + /// + public interface IFan : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs b/RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs new file mode 100644 index 0000000..30fc9d4 --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IGraphicsCard.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a graphics-card-device + /// + public interface IGraphicsCard : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs b/RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs new file mode 100644 index 0000000..25cde5c --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IHeadset.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a headset-device + /// + public interface IHeadset : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs b/RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs new file mode 100644 index 0000000..9c5c81a --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IHeadsetStand.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a headset-stand-device + /// + public interface IHeadsetStand : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IKeyboard.cs b/RGB.NET.Core/Devices/TypeInterfaces/IKeyboard.cs new file mode 100644 index 0000000..7e32e96 --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IKeyboard.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a keyboard-device + /// + public interface IKeyboard : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs b/RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs new file mode 100644 index 0000000..3030492 --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IKeypad.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a keypad-device + /// + public interface IKeypad : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs b/RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs new file mode 100644 index 0000000..2ba759d --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/ILedMatrix.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a led-matrix-device + /// + public interface ILedMatrix : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs b/RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs new file mode 100644 index 0000000..9c97ab5 --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/ILedStripe.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a led-stripe-device + /// + public interface ILedStripe : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs b/RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs new file mode 100644 index 0000000..e043c6f --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IMainboard.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a mainboard-device + /// + public interface IMainboard : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs b/RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs new file mode 100644 index 0000000..6064012 --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IMouse.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a mouse-device + /// + public interface IMouse : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs b/RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs new file mode 100644 index 0000000..e6812fc --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IMousepad.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a mousepad-device + /// + public interface IMousepad : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs b/RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs new file mode 100644 index 0000000..6670297 --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/ISpeaker.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a speaker-device + /// + public interface ISpeaker : IRGBDevice + { } +} diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs b/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs new file mode 100644 index 0000000..46e9740 --- /dev/null +++ b/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a device with unkown or not specified type. + /// + public interface IInknownDevice : IRGBDevice + { } +} diff --git a/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings b/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings index d216495..9555e90 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings +++ b/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings @@ -5,6 +5,7 @@ True True True + True True True True From 49de32724a657cd70b8c90ddb512086ee7851185 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 18 Apr 2020 15:13:48 +0200 Subject: [PATCH 18/51] Typo --- RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs b/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs index 46e9740..724dc4d 100644 --- a/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs +++ b/RGB.NET.Core/Devices/TypeInterfaces/IUnknownDevice.cs @@ -3,6 +3,6 @@ /// /// Represents a device with unkown or not specified type. /// - public interface IInknownDevice : IRGBDevice + public interface IUnknownDevice : IRGBDevice { } } From b0dc472fa7156e20526163a34c7d2c5767b6c54b Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 18 Apr 2020 15:29:11 +0200 Subject: [PATCH 19/51] Applied device-interfaces --- RGB.NET.Devices.Asus/Dram/AsusDramRGBDevice.cs | 4 ++-- RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs | 4 ++-- .../GraphicsCard/AsusGraphicsCardRGBDevice.cs | 4 ++-- RGB.NET.Devices.Asus/Headset/AsusHeadsetRGBDevice.cs | 4 ++-- RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs | 4 ++-- RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs | 4 ++-- RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDevice.cs | 4 ++-- .../GraphicsCard/AsusGraphicsCardRGBDevice.cs | 4 ++-- RGB.NET.Devices.Asus_Legacy/Keyboard/AsusKeyboardRGBDevice.cs | 4 ++-- .../Mainboard/AsusMainboardRGBDevice.cs | 4 ++-- RGB.NET.Devices.Asus_Legacy/Mouse/AsusMouseRGBDevice.cs | 4 ++-- .../Keyboard/CoolerMasterKeyboardRGBDevice.cs | 4 ++-- .../Mouse/CoolerMasterMouseRGBDevice.cs | 4 ++-- RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs | 4 ++-- RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs | 4 ++-- .../HeadsetStand/CorsairHeadsetStandRGBDevice.cs | 4 ++-- RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs | 4 ++-- RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs | 4 ++-- RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs | 4 ++-- RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs | 4 ++-- RGB.NET.Devices.DMX/E131/E131Device.cs | 2 +- RGB.NET.Devices.Debug/DebugRGBDevice.cs | 4 ++-- .../PerDevice/LogitechPerDeviceRGBDevice.cs | 4 ++-- RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs | 4 ++-- RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs | 4 ++-- RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs | 4 ++-- RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs | 4 ++-- .../Launchpad/NovationLaunchpadRGBDevice.cs | 4 ++-- RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkRGBDevice.cs | 4 ++-- RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDevice.cs | 4 ++-- RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDevice.cs | 4 ++-- RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDevice.cs | 4 ++-- RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDevice.cs | 4 ++-- RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDevice.cs | 4 ++-- RGB.NET.Devices.SoIP/Client/SoIPClientRGBDevice.cs | 2 +- RGB.NET.Devices.SoIP/Server/SoIPServerRGBDevice.cs | 2 +- RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs | 2 +- RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs | 2 +- RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs | 2 +- RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs | 4 ++-- 40 files changed, 74 insertions(+), 74 deletions(-) diff --git a/RGB.NET.Devices.Asus/Dram/AsusDramRGBDevice.cs b/RGB.NET.Devices.Asus/Dram/AsusDramRGBDevice.cs index 315b1ed..7ee2183 100644 --- a/RGB.NET.Devices.Asus/Dram/AsusDramRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Dram/AsusDramRGBDevice.cs @@ -2,11 +2,11 @@ namespace RGB.NET.Devices.Asus { - /// + /// /// /// Represents a Asus dram. /// - public class AsusDramRGBDevice : AsusRGBDevice + public class AsusDramRGBDevice : AsusRGBDevice, IDRAM { #region Constructors diff --git a/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs b/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs index 3515596..40eb602 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUnspecifiedRGBDevice.cs @@ -2,11 +2,11 @@ namespace RGB.NET.Devices.Asus { - /// + /// /// /// Represents a Asus headset. /// - public class AsusUnspecifiedRGBDevice : AsusRGBDevice + public class AsusUnspecifiedRGBDevice : AsusRGBDevice, IUnknownDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDevice.cs index de925fb..f50f70f 100644 --- a/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/GraphicsCard/AsusGraphicsCardRGBDevice.cs @@ -2,11 +2,11 @@ namespace RGB.NET.Devices.Asus { - /// + /// /// /// Represents a Asus graphicsCard. /// - public class AsusGraphicsCardRGBDevice : AsusRGBDevice + public class AsusGraphicsCardRGBDevice : AsusRGBDevice, IGraphicsCard { #region Constructors diff --git a/RGB.NET.Devices.Asus/Headset/AsusHeadsetRGBDevice.cs b/RGB.NET.Devices.Asus/Headset/AsusHeadsetRGBDevice.cs index e762d97..a3727d1 100644 --- a/RGB.NET.Devices.Asus/Headset/AsusHeadsetRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Headset/AsusHeadsetRGBDevice.cs @@ -2,11 +2,11 @@ namespace RGB.NET.Devices.Asus { - /// + /// /// /// Represents a Asus headset. /// - public class AsusHeadsetRGBDevice : AsusRGBDevice + public class AsusHeadsetRGBDevice : AsusRGBDevice, IHeadset { #region Constructors diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs index f16acf4..95e3140 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs @@ -2,11 +2,11 @@ namespace RGB.NET.Devices.Asus { - /// + /// /// /// Represents a Asus keyboard. /// - public class AsusKeyboardRGBDevice : AsusRGBDevice + public class AsusKeyboardRGBDevice : AsusRGBDevice, IKeyboard { #region Constructors diff --git a/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs b/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs index df7d419..2109aee 100644 --- a/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Mainboard/AsusMainboardRGBDevice.cs @@ -2,11 +2,11 @@ namespace RGB.NET.Devices.Asus { - /// + /// /// /// Represents a Asus mainboard. /// - public class AsusMainboardRGBDevice : AsusRGBDevice + public class AsusMainboardRGBDevice : AsusRGBDevice, IKeyboard { #region Constructors diff --git a/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDevice.cs b/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDevice.cs index a6a7ea3..030e547 100644 --- a/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Mouse/AsusMouseRGBDevice.cs @@ -2,11 +2,11 @@ namespace RGB.NET.Devices.Asus { - /// + /// /// /// Represents a Asus mouse. /// - public class AsusMouseRGBDevice : AsusRGBDevice + public class AsusMouseRGBDevice : AsusRGBDevice, IMouse { #region Constructors diff --git a/RGB.NET.Devices.Asus_Legacy/GraphicsCard/AsusGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Asus_Legacy/GraphicsCard/AsusGraphicsCardRGBDevice.cs index be0c0b2..67a4988 100644 --- a/RGB.NET.Devices.Asus_Legacy/GraphicsCard/AsusGraphicsCardRGBDevice.cs +++ b/RGB.NET.Devices.Asus_Legacy/GraphicsCard/AsusGraphicsCardRGBDevice.cs @@ -4,11 +4,11 @@ using RGB.NET.Devices.Asus.Native; namespace RGB.NET.Devices.Asus { - /// + /// /// /// Represents a Asus graphicsCard. /// - public class AsusGraphicsCardRGBDevice : AsusRGBDevice + public class AsusGraphicsCardRGBDevice : AsusRGBDevice, IGraphicsCard { #region Constructors diff --git a/RGB.NET.Devices.Asus_Legacy/Keyboard/AsusKeyboardRGBDevice.cs b/RGB.NET.Devices.Asus_Legacy/Keyboard/AsusKeyboardRGBDevice.cs index d92d4d7..8b72fb5 100644 --- a/RGB.NET.Devices.Asus_Legacy/Keyboard/AsusKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus_Legacy/Keyboard/AsusKeyboardRGBDevice.cs @@ -4,11 +4,11 @@ using RGB.NET.Devices.Asus.Native; namespace RGB.NET.Devices.Asus { - /// + /// /// /// Represents a Asus keyboard. /// - public class AsusKeyboardRGBDevice : AsusRGBDevice + public class AsusKeyboardRGBDevice : AsusRGBDevice, IKeyboard { #region Constructors diff --git a/RGB.NET.Devices.Asus_Legacy/Mainboard/AsusMainboardRGBDevice.cs b/RGB.NET.Devices.Asus_Legacy/Mainboard/AsusMainboardRGBDevice.cs index 4ea1c60..52035f0 100644 --- a/RGB.NET.Devices.Asus_Legacy/Mainboard/AsusMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus_Legacy/Mainboard/AsusMainboardRGBDevice.cs @@ -4,11 +4,11 @@ using RGB.NET.Devices.Asus.Native; namespace RGB.NET.Devices.Asus { - /// + /// /// /// Represents a Asus mainboard. /// - public class AsusMainboardRGBDevice : AsusRGBDevice + public class AsusMainboardRGBDevice : AsusRGBDevice, IMainboard { #region Constructors diff --git a/RGB.NET.Devices.Asus_Legacy/Mouse/AsusMouseRGBDevice.cs b/RGB.NET.Devices.Asus_Legacy/Mouse/AsusMouseRGBDevice.cs index d318cae..e238b0c 100644 --- a/RGB.NET.Devices.Asus_Legacy/Mouse/AsusMouseRGBDevice.cs +++ b/RGB.NET.Devices.Asus_Legacy/Mouse/AsusMouseRGBDevice.cs @@ -4,11 +4,11 @@ using RGB.NET.Devices.Asus.Native; namespace RGB.NET.Devices.Asus { - /// + /// /// /// Represents a Asus mouse. /// - public class AsusMouseRGBDevice : AsusRGBDevice + public class AsusMouseRGBDevice : AsusRGBDevice, IMouse { #region Constructors diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs index e8906e3..ab02892 100644 --- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs @@ -3,11 +3,11 @@ using RGB.NET.Core; namespace RGB.NET.Devices.CoolerMaster { - /// + /// /// /// Represents a CoolerMaster keyboard. /// - public class CoolerMasterKeyboardRGBDevice : CoolerMasterRGBDevice + public class CoolerMasterKeyboardRGBDevice : CoolerMasterRGBDevice, IKeyboard { #region Constructors diff --git a/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDevice.cs index 4281706..a59b1ce 100644 --- a/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Mouse/CoolerMasterMouseRGBDevice.cs @@ -3,11 +3,11 @@ using RGB.NET.Core; namespace RGB.NET.Devices.CoolerMaster { - /// + /// /// /// Represents a CoolerMaster mouse. /// - public class CoolerMasterMouseRGBDevice : CoolerMasterRGBDevice + public class CoolerMasterMouseRGBDevice : CoolerMasterRGBDevice, IMouse { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs index 711d97c..5854623 100644 --- a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs @@ -6,11 +6,11 @@ using RGB.NET.Core; namespace RGB.NET.Devices.Corsair { - /// + /// /// /// Represents a corsair custom. /// - public class CorsairCustomRGBDevice : CorsairRGBDevice + public class CorsairCustomRGBDevice : CorsairRGBDevice, IUnknownDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs index 1ecbe9b..8152a2c 100644 --- a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs @@ -5,11 +5,11 @@ using RGB.NET.Core; namespace RGB.NET.Devices.Corsair { - /// + /// /// /// Represents a corsair headset. /// - public class CorsairHeadsetRGBDevice : CorsairRGBDevice + public class CorsairHeadsetRGBDevice : CorsairRGBDevice, IHeadset { #region Constructors diff --git a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs index ed25ad7..d7e28c9 100644 --- a/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/HeadsetStand/CorsairHeadsetStandRGBDevice.cs @@ -10,11 +10,11 @@ using RGB.NET.Devices.Corsair.Native; namespace RGB.NET.Devices.Corsair { - /// + /// /// /// Represents a corsair headset stand. /// - public class CorsairHeadsetStandRGBDevice : CorsairRGBDevice + public class CorsairHeadsetStandRGBDevice : CorsairRGBDevice, IHeadsetStand { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs index 4fdd829..c1bb52a 100644 --- a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs @@ -9,11 +9,11 @@ using RGB.NET.Devices.Corsair.Native; namespace RGB.NET.Devices.Corsair { - /// + /// /// /// Represents a corsair keyboard. /// - public class CorsairKeyboardRGBDevice : CorsairRGBDevice + public class CorsairKeyboardRGBDevice : CorsairRGBDevice, IKeyboard { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs b/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs index ed2c2fb..836e055 100644 --- a/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Memory/CorsairMemoryRGBDevice.cs @@ -9,11 +9,11 @@ using RGB.NET.Devices.Corsair.Native; namespace RGB.NET.Devices.Corsair { - /// + /// /// /// Represents a corsair memory. /// - public class CorsairMemoryRGBDevice : CorsairRGBDevice + public class CorsairMemoryRGBDevice : CorsairRGBDevice, IDRAM { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs index 479b771..292d7d8 100644 --- a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs @@ -6,11 +6,11 @@ using RGB.NET.Core; namespace RGB.NET.Devices.Corsair { - /// + /// /// /// Represents a corsair mouse. /// - public class CorsairMouseRGBDevice : CorsairRGBDevice + public class CorsairMouseRGBDevice : CorsairRGBDevice, IMouse { #region Constructors diff --git a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs index e918b58..b245ca1 100644 --- a/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mousepad/CorsairMousepadRGBDevice.cs @@ -10,11 +10,11 @@ using RGB.NET.Devices.Corsair.Native; namespace RGB.NET.Devices.Corsair { - /// + /// /// /// Represents a corsair mousepad. /// - public class CorsairMousepadRGBDevice : CorsairRGBDevice + public class CorsairMousepadRGBDevice : CorsairRGBDevice, IMousepad { #region Constructors diff --git a/RGB.NET.Devices.DMX/E131/E131Device.cs b/RGB.NET.Devices.DMX/E131/E131Device.cs index 1b199dd..a4a69d2 100644 --- a/RGB.NET.Devices.DMX/E131/E131Device.cs +++ b/RGB.NET.Devices.DMX/E131/E131Device.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.DMX.E131 /// /// Represents a E1.31-DXM-device. /// - public class E131Device : AbstractRGBDevice + public class E131Device : AbstractRGBDevice, IUnknownDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.Debug/DebugRGBDevice.cs b/RGB.NET.Devices.Debug/DebugRGBDevice.cs index 4c71688..2ed6700 100644 --- a/RGB.NET.Devices.Debug/DebugRGBDevice.cs +++ b/RGB.NET.Devices.Debug/DebugRGBDevice.cs @@ -5,11 +5,11 @@ using RGB.NET.Core.Layout; namespace RGB.NET.Devices.Debug { - /// + /// /// /// Represents a debug device. /// - public class DebugRGBDevice : AbstractRGBDevice + public class DebugRGBDevice : AbstractRGBDevice, IUnknownDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs index 471b438..42ff262 100644 --- a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs @@ -4,11 +4,11 @@ using RGB.NET.Core; namespace RGB.NET.Devices.Logitech { - /// + /// /// /// Represents a logitech per-device-lightable device. /// - public class LogitechPerDeviceRGBDevice : LogitechRGBDevice + public class LogitechPerDeviceRGBDevice : LogitechRGBDevice, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated { #region Constructors diff --git a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs index cdf10bf..e5e3f40 100644 --- a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs @@ -4,11 +4,11 @@ using RGB.NET.Core; namespace RGB.NET.Devices.Logitech { - /// + /// /// /// Represents a logitech per-key-lightable device. /// - public class LogitechPerKeyRGBDevice : LogitechRGBDevice + public class LogitechPerKeyRGBDevice : LogitechRGBDevice, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated { #region Constructors diff --git a/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs b/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs index c7263ae..419e796 100644 --- a/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs @@ -4,11 +4,11 @@ using RGB.NET.Core; namespace RGB.NET.Devices.Logitech { - /// + /// /// /// Represents a logitech zone-lightable device. /// - public class LogitechZoneRGBDevice : LogitechRGBDevice + public class LogitechZoneRGBDevice : LogitechRGBDevice, IUnknownDevice //TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated { #region Constants diff --git a/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs index ee0800a..f5cf4e4 100644 --- a/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs +++ b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs @@ -3,11 +3,11 @@ using RGB.NET.Devices.Msi.Native; namespace RGB.NET.Devices.Msi { - /// + /// /// /// Represents MSI VGA adapters. /// - public class MsiGraphicsCardRGBDevice : MsiRGBDevice + public class MsiGraphicsCardRGBDevice : MsiRGBDevice, IGraphicsCard { #region Constructors diff --git a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs index f80dab0..a7e11cb 100644 --- a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs @@ -3,11 +3,11 @@ using RGB.NET.Devices.Msi.Native; namespace RGB.NET.Devices.Msi { - /// + /// /// /// Represents a MSI mainboard. /// - public class MsiMainboardRGBDevice : MsiRGBDevice + public class MsiMainboardRGBDevice : MsiRGBDevice, IMainboard { #region Constructors diff --git a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs index 6f58e93..3eabdf5 100644 --- a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs +++ b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs @@ -4,11 +4,11 @@ using RGB.NET.Core; namespace RGB.NET.Devices.Novation { - /// + /// /// /// Represents a Novation launchpad. /// - public class NovationLaunchpadRGBDevice : NovationRGBDevice + public class NovationLaunchpadRGBDevice : NovationRGBDevice, ILedMatrix { #region Constructors diff --git a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkRGBDevice.cs b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkRGBDevice.cs index 79745d4..853b222 100644 --- a/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkRGBDevice.cs +++ b/RGB.NET.Devices.Razer/ChromaLink/RazerChromaLinkRGBDevice.cs @@ -6,11 +6,11 @@ using RGB.NET.Devices.Razer.Native; namespace RGB.NET.Devices.Razer { - /// + /// /// /// Represents a razer chroma link. /// - public class RazerChromaLinkRGBDevice : RazerRGBDevice + public class RazerChromaLinkRGBDevice : RazerRGBDevice, ILedStripe { #region Constructors diff --git a/RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDevice.cs b/RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDevice.cs index fb332dc..25fbfd4 100644 --- a/RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Headset/RazerHeadsetRGBDevice.cs @@ -6,11 +6,11 @@ using RGB.NET.Devices.Razer.Native; namespace RGB.NET.Devices.Razer { - /// + /// /// /// Represents a razer headset. /// - public class RazerHeadsetRGBDevice : RazerRGBDevice + public class RazerHeadsetRGBDevice : RazerRGBDevice, IHeadset { #region Constructors diff --git a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDevice.cs b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDevice.cs index 763fd47..8c6aab6 100644 --- a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDevice.cs @@ -6,11 +6,11 @@ using RGB.NET.Devices.Razer.Native; namespace RGB.NET.Devices.Razer { - /// + /// /// /// Represents a razer keyboard. /// - public class RazerKeyboardRGBDevice : RazerRGBDevice + public class RazerKeyboardRGBDevice : RazerRGBDevice, IKeyboard { #region Constructors diff --git a/RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDevice.cs b/RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDevice.cs index 01f1820..be86e2d 100644 --- a/RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Keypad/RazerKeypadRGBDevice.cs @@ -6,11 +6,11 @@ using RGB.NET.Devices.Razer.Native; namespace RGB.NET.Devices.Razer { - /// + /// /// /// Represents a razer keypad. /// - public class RazerKeypadRGBDevice : RazerRGBDevice + public class RazerKeypadRGBDevice : RazerRGBDevice, IKeypad { #region Constructors diff --git a/RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDevice.cs b/RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDevice.cs index 4516f15..6562467 100644 --- a/RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Mouse/RazerMouseRGBDevice.cs @@ -6,11 +6,11 @@ using RGB.NET.Devices.Razer.Native; namespace RGB.NET.Devices.Razer { - /// + /// /// /// Represents a razer mouse. /// - public class RazerMouseRGBDevice : RazerRGBDevice + public class RazerMouseRGBDevice : RazerRGBDevice, IMouse { #region Constructors diff --git a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDevice.cs b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDevice.cs index 869c67b..d9c4d81 100644 --- a/RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Mousepad/RazerMousepadRGBDevice.cs @@ -6,11 +6,11 @@ using RGB.NET.Devices.Razer.Native; namespace RGB.NET.Devices.Razer { - /// + /// /// /// Represents a razer mousepad. /// - public class RazerMousepadRGBDevice : RazerRGBDevice + public class RazerMousepadRGBDevice : RazerRGBDevice, IMousepad { #region Constructors diff --git a/RGB.NET.Devices.SoIP/Client/SoIPClientRGBDevice.cs b/RGB.NET.Devices.SoIP/Client/SoIPClientRGBDevice.cs index c3bec0f..38ef9a8 100644 --- a/RGB.NET.Devices.SoIP/Client/SoIPClientRGBDevice.cs +++ b/RGB.NET.Devices.SoIP/Client/SoIPClientRGBDevice.cs @@ -7,7 +7,7 @@ using SimpleTCP; namespace RGB.NET.Devices.SoIP.Client { - public class SoIPClientRGBDevice : AbstractRGBDevice, ISoIPRGBDevice + public class SoIPClientRGBDevice : AbstractRGBDevice, ISoIPRGBDevice, IUnknownDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.SoIP/Server/SoIPServerRGBDevice.cs b/RGB.NET.Devices.SoIP/Server/SoIPServerRGBDevice.cs index ca72447..5908a1b 100644 --- a/RGB.NET.Devices.SoIP/Server/SoIPServerRGBDevice.cs +++ b/RGB.NET.Devices.SoIP/Server/SoIPServerRGBDevice.cs @@ -7,7 +7,7 @@ using SimpleTCP; namespace RGB.NET.Devices.SoIP.Server { - public class SoIPServerRGBDevice : AbstractRGBDevice, ISoIPRGBDevice + public class SoIPServerRGBDevice : AbstractRGBDevice, ISoIPRGBDevice, IUnknownDevice { #region Properties & Fields diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs index 78a65eb..ec59fd3 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Devices.SteelSeries /// /// Represents a SteelSeries-device. (keyboard, mouse, headset, mousepad). /// - public class SteelSeriesRGBDevice : AbstractRGBDevice, ISteelSeriesRGBDevice + public class SteelSeriesRGBDevice : AbstractRGBDevice, ISteelSeriesRGBDevice, IUnknownDevice//TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated { #region Properties & Fields diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs index f8b9d4f..c940db4 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.WS281X.Arduino /// /// Represents an arduino WS2812 device. /// - public class ArduinoWS2812USBDevice : AbstractRGBDevice + public class ArduinoWS2812USBDevice : AbstractRGBDevice, ILedStripe { #region Properties & Fields diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs index 74d52ee..b9e5cf6 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs @@ -12,7 +12,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard /// /// Represents an bitwizard WS2812 USB device. /// - public class BitwizardWS2812USBDevice : AbstractRGBDevice + public class BitwizardWS2812USBDevice : AbstractRGBDevice, ILedStripe { #region Properties & Fields diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs index 0b3334a..3ccc35a 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs @@ -5,11 +5,11 @@ using RGB.NET.Devices.Wooting.Generic; namespace RGB.NET.Devices.Wooting.Keyboard { - /// + /// /// /// Represents a Wooting keyboard. /// - public class WootingKeyboardRGBDevice : WootingRGBDevice + public class WootingKeyboardRGBDevice : WootingRGBDevice, IKeyboard { #region Constructors From 19d81d79c378ddbb2e75326876f76b366f134f5b Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sun, 19 Apr 2020 23:00:31 +0200 Subject: [PATCH 20/51] CoolerMaster - Throw more detailed error when missing LED mappings --- .../Keyboard/CoolerMasterKeyboardRGBDevice.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs index ab02892..9b9ed0b 100644 --- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs @@ -27,8 +27,14 @@ namespace RGB.NET.Devices.CoolerMaster /// protected override void InitializeLayout() { - Dictionary mapping = CoolerMasterKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout]; - + Dictionary> deviceMappings; + Dictionary mapping; + + if (!CoolerMasterKeyboardLedMappings.Mapping.TryGetValue(DeviceInfo.DeviceIndex, out deviceMappings)) + throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex}"); + if (!deviceMappings.TryGetValue(DeviceInfo.PhysicalLayout, out mapping)) + throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex} with physical layout {DeviceInfo.PhysicalLayout}"); + foreach (KeyValuePair led in mapping) InitializeLed(led.Key, new Rectangle(led.Value.column * 19, led.Value.row * 19, 19, 19)); From a7dcf3d867eec15600decdf617bc1de95a80f051 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Mon, 20 Apr 2020 19:26:26 +0200 Subject: [PATCH 21/51] Inlined variables --- .../Keyboard/CoolerMasterKeyboardRGBDevice.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs index 9b9ed0b..8a8c17a 100644 --- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDevice.cs @@ -27,12 +27,9 @@ namespace RGB.NET.Devices.CoolerMaster /// protected override void InitializeLayout() { - Dictionary> deviceMappings; - Dictionary mapping; - - if (!CoolerMasterKeyboardLedMappings.Mapping.TryGetValue(DeviceInfo.DeviceIndex, out deviceMappings)) + if (!CoolerMasterKeyboardLedMappings.Mapping.TryGetValue(DeviceInfo.DeviceIndex, out Dictionary> deviceMappings)) throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex}"); - if (!deviceMappings.TryGetValue(DeviceInfo.PhysicalLayout, out mapping)) + if (!deviceMappings.TryGetValue(DeviceInfo.PhysicalLayout, out Dictionary mapping)) throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex} with physical layout {DeviceInfo.PhysicalLayout}"); foreach (KeyValuePair led in mapping) From 19a009c9aa0023dbe66a11260d0fd1c170b9e94f Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 20 Apr 2020 23:01:56 +0200 Subject: [PATCH 22/51] Updated all nuget-references --- RGB.NET.Brushes/RGB.NET.Brushes.csproj | 2 +- RGB.NET.Core/RGB.NET.Core.csproj | 2 +- RGB.NET.Decorators/RGB.NET.Decorators.csproj | 2 +- .../RGB.NET.Devices.Asus.csproj | 4 +- .../RGB.NET.Devices.Asus_Legacy.csproj | 4 +- .../RGB.NET.Devices.CoolerMaster.csproj | 2 +- .../RGB.NET.Devices.Corsair.csproj | 2 +- .../RGB.NET.Devices.DMX.csproj | 2 +- .../RGB.NET.Devices.Debug.csproj | 2 +- .../RGB.NET.Devices.Logitech.csproj | 4 +- .../RGB.NET.Devices.Msi.csproj | 2 +- .../RGB.NET.Devices.Novation.csproj | 2 +- .../RGB.NET.Devices.Razer.csproj | 2 +- .../RGB.NET.Devices.Roccat.csproj | 2 +- RGB.NET.Devices.SoIP/FodyWeavers.xml | 6 +- RGB.NET.Devices.SoIP/FodyWeavers.xsd | 111 ++++++++++++++++++ .../RGB.NET.Devices.SoIP.csproj | 6 +- .../RGB.NET.Devices.SteelSeries.csproj | 4 +- .../RGB.NET.Devices.WS281X.csproj | 4 +- .../RGB.NET.Devices.Wooting.csproj | 2 +- RGB.NET.Groups/RGB.NET.Groups.csproj | 2 +- .../RGB.NET.Core.Tests.csproj | 6 +- 22 files changed, 143 insertions(+), 32 deletions(-) create mode 100644 RGB.NET.Devices.SoIP/FodyWeavers.xsd diff --git a/RGB.NET.Brushes/RGB.NET.Brushes.csproj b/RGB.NET.Brushes/RGB.NET.Brushes.csproj index 5264906..85e276f 100644 --- a/RGB.NET.Brushes/RGB.NET.Brushes.csproj +++ b/RGB.NET.Brushes/RGB.NET.Brushes.csproj @@ -63,6 +63,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj index 5415d59..d3f2d5b 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj +++ b/RGB.NET.Core/RGB.NET.Core.csproj @@ -59,6 +59,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Decorators/RGB.NET.Decorators.csproj b/RGB.NET.Decorators/RGB.NET.Decorators.csproj index 6356878..1703f74 100644 --- a/RGB.NET.Decorators/RGB.NET.Decorators.csproj +++ b/RGB.NET.Decorators/RGB.NET.Decorators.csproj @@ -64,6 +64,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj index f941ad4..fac923c 100644 --- a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj +++ b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj @@ -77,8 +77,8 @@ - - + + diff --git a/RGB.NET.Devices.Asus_Legacy/RGB.NET.Devices.Asus_Legacy.csproj b/RGB.NET.Devices.Asus_Legacy/RGB.NET.Devices.Asus_Legacy.csproj index 3be7e47..fbfe63a 100644 --- a/RGB.NET.Devices.Asus_Legacy/RGB.NET.Devices.Asus_Legacy.csproj +++ b/RGB.NET.Devices.Asus_Legacy/RGB.NET.Devices.Asus_Legacy.csproj @@ -63,7 +63,7 @@ - - + + \ No newline at end of file diff --git a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj index a471d52..c227751 100644 --- a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj +++ b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj @@ -63,6 +63,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj index 56519a3..0d023b4 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj @@ -63,6 +63,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj index ce4cc51..df61269 100644 --- a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj +++ b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj @@ -63,6 +63,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj index 1d68681..1974cea 100644 --- a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj +++ b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj @@ -63,6 +63,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj index b231942..b387096 100644 --- a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj +++ b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj @@ -60,10 +60,10 @@ - + - + \ No newline at end of file diff --git a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj index cb86295..7050174 100644 --- a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj +++ b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj @@ -63,6 +63,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj index 476f0ad..cbcad32 100644 --- a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj +++ b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj @@ -64,6 +64,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj index b1ec9e6..2bc40c0 100644 --- a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj +++ b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj @@ -63,6 +63,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Devices.Roccat/RGB.NET.Devices.Roccat.csproj b/RGB.NET.Devices.Roccat/RGB.NET.Devices.Roccat.csproj index 51a7d42..2671d40 100644 --- a/RGB.NET.Devices.Roccat/RGB.NET.Devices.Roccat.csproj +++ b/RGB.NET.Devices.Roccat/RGB.NET.Devices.Roccat.csproj @@ -63,6 +63,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Devices.SoIP/FodyWeavers.xml b/RGB.NET.Devices.SoIP/FodyWeavers.xml index ba40f91..7e25d14 100644 --- a/RGB.NET.Devices.SoIP/FodyWeavers.xml +++ b/RGB.NET.Devices.SoIP/FodyWeavers.xml @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/RGB.NET.Devices.SoIP/FodyWeavers.xsd b/RGB.NET.Devices.SoIP/FodyWeavers.xsd new file mode 100644 index 0000000..44a5374 --- /dev/null +++ b/RGB.NET.Devices.SoIP/FodyWeavers.xsd @@ -0,0 +1,111 @@ + + + + + + + + + + + + A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks + + + + + A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. + + + + + A list of unmanaged 32 bit assembly names to include, delimited with line breaks. + + + + + A list of unmanaged 64 bit assembly names to include, delimited with line breaks. + + + + + The order of preloaded assemblies, delimited with line breaks. + + + + + + This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. + + + + + Controls if .pdbs for reference assemblies are also embedded. + + + + + Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. + + + + + As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. + + + + + Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. + + + + + Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. + + + + + A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | + + + + + A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. + + + + + A list of unmanaged 32 bit assembly names to include, delimited with |. + + + + + A list of unmanaged 64 bit assembly names to include, delimited with |. + + + + + The order of preloaded assemblies, delimited with |. + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/RGB.NET.Devices.SoIP/RGB.NET.Devices.SoIP.csproj b/RGB.NET.Devices.SoIP/RGB.NET.Devices.SoIP.csproj index 6fd43e8..812ab70 100644 --- a/RGB.NET.Devices.SoIP/RGB.NET.Devices.SoIP.csproj +++ b/RGB.NET.Devices.SoIP/RGB.NET.Devices.SoIP.csproj @@ -59,8 +59,8 @@ - - + + all runtime; build; native; contentfiles; analyzers @@ -72,6 +72,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj index bfe4e06..f48998b 100644 --- a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj +++ b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj @@ -56,7 +56,7 @@ - - + + \ No newline at end of file diff --git a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj index a2d0f40..cbbc0cb 100644 --- a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj +++ b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj @@ -63,10 +63,10 @@ - + - + \ No newline at end of file diff --git a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj index 128556f..946705a 100644 --- a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj +++ b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj @@ -63,6 +63,6 @@ - + \ No newline at end of file diff --git a/RGB.NET.Groups/RGB.NET.Groups.csproj b/RGB.NET.Groups/RGB.NET.Groups.csproj index de52c4a..4aa5532 100644 --- a/RGB.NET.Groups/RGB.NET.Groups.csproj +++ b/RGB.NET.Groups/RGB.NET.Groups.csproj @@ -63,6 +63,6 @@ - + \ No newline at end of file diff --git a/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj b/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj index 49bf8e9..1a1ca5b 100644 --- a/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj +++ b/Tests/RGB.NET.Core.Tests/RGB.NET.Core.Tests.csproj @@ -7,9 +7,9 @@ - - - + + + From 04b78f7fd5d9ef0b2cb62b59056dd776b14e89bf Mon Sep 17 00:00:00 2001 From: Hex3l Date: Sun, 26 Apr 2020 21:45:16 +0200 Subject: [PATCH 23/51] adds MSI_MOUSE support --- .../Mouse/MsiMouseRGBDevice.cs | 54 +++++++++++++++++++ RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 14 ++++- 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs diff --git a/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs b/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs new file mode 100644 index 0000000..a153190 --- /dev/null +++ b/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs @@ -0,0 +1,54 @@ +using RGB.NET.Core; +using RGB.NET.Devices.Msi.Native; + +namespace RGB.NET.Devices.Msi +{ + /// + /// + /// Represents a MSI mouse. + /// + public class MsiMouseRGBDevice : MsiRGBDevice + { + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The specific information provided by MSI for the mouse. + internal MsiMouseRGBDevice(MsiRGBDeviceInfo info) + : base(info) + { } + + #endregion + + #region Methods + + /// + protected override void InitializeLayout(int ledCount) + { + for (int i = 0; i < ledCount; i++) + { + //Hex3l: Should it be configurable in order to provide style access? + //Hex3l: Sets led style to "Steady" in order to have a solid color output therefore a controllable led color + //Hex3l: This is a string defined by the output of _MsiSDK.GetLedStyle, "Steady" should be always present + const string LED_STYLE = "Steady"; + + _MsiSDK.SetLedStyle(DeviceInfo.MsiDeviceType, i, LED_STYLE); + InitializeLed(LedId.Mouse1 + i, new Rectangle(i * 10, 0, 10, 10)); + } + + //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? + ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\MSI\Mouses\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); + } + + /// + protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Mouse1; + + /// + public override void SyncBack() + { } + + #endregion + } +} diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index 59a3980..552dd25 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -118,7 +118,7 @@ namespace RGB.NET.Devices.Msi if (deviceType.Equals("MSI_MB")) { MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType); - IMsiRGBDevice motherboard = new MsiMainboardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mainboard, deviceType, "Msi", "Motherboard")); + IMsiRGBDevice motherboard = new MsiMainboardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mainboard, deviceType, "MSI", "Motherboard")); motherboard.Initialize(updateQueue, ledCount); devices.Add(motherboard); } @@ -128,10 +128,20 @@ namespace RGB.NET.Devices.Msi //Hex3l: The led name is the name of the card (e.g. NVIDIA GeForce RTX 2080 Ti) we could provide it in device info. MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType); - IMsiRGBDevice graphicscard = new MsiGraphicsCardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.GraphicsCard, deviceType, "Msi", "GraphicsCard")); + IMsiRGBDevice graphicscard = new MsiGraphicsCardRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.GraphicsCard, deviceType, "MSI", "GraphicsCard")); graphicscard.Initialize(updateQueue, ledCount); devices.Add(graphicscard); } + else if (deviceType.Equals("MSI_MOUSE")) + { + //Hex3l: Every led under MSI_MOUSE should be a different mouse. Handling all the mouses together seems a good way to avoid overlapping of leds + //Hex3l: The led name is the name of the mouse (e.g. msi CLUTCH GM11) we could provide it in device info. + + MsiDeviceUpdateQueue updateQueue = new MsiDeviceUpdateQueue(UpdateTrigger, deviceType); + IMsiRGBDevice mouses = new MsiMouseRGBDevice(new MsiRGBDeviceInfo(RGBDeviceType.Mouse, deviceType, "MSI", "Mouse")); + mouses.Initialize(updateQueue, ledCount); + devices.Add(mouses); + } //TODO DarthAffe 22.02.2020: Add other devices } From d7194bad9a054908b003c939a69ca868db582ab9 Mon Sep 17 00:00:00 2001 From: Hex3l Date: Mon, 27 Apr 2020 18:54:46 +0200 Subject: [PATCH 24/51] changes generic manufacturer 'Msi' to 'MSI' --- RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs b/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs index d846266..269d34e 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs @@ -48,7 +48,7 @@ namespace RGB.NET.Devices.Msi /// The internal type of the . /// The manufacturer-name of the . /// The model-name of the . - internal MsiRGBDeviceInfo(RGBDeviceType deviceType, string msiDeviceType, string manufacturer = "Msi", string model = "Generic Msi-Device") + internal MsiRGBDeviceInfo(RGBDeviceType deviceType, string msiDeviceType, string manufacturer = "MSI", string model = "Generic Msi-Device") { this.DeviceType = deviceType; this.MsiDeviceType = msiDeviceType; From 8209fbf89a19abd4d7e78ae70925201b59b569f1 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 1 Jun 2020 20:09:10 +0200 Subject: [PATCH 25/51] Added more logitech HIDs --- RGB.NET.Devices.Logitech/HID/DeviceChecker.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs b/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs index 1387891..4e8d551 100644 --- a/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs +++ b/RGB.NET.Devices.Logitech/HID/DeviceChecker.cs @@ -23,6 +23,7 @@ namespace RGB.NET.Devices.Logitech.HID ("G810", RGBDeviceType.Keyboard, 0xC331, 0, "DE", @"Keyboards\G810\UK"), ("G610", RGBDeviceType.Keyboard, 0xC333, 0, "DE", @"Keyboards\G610\UK"), ("G512", RGBDeviceType.Keyboard, 0xC33C, 0, "DE", @"Keyboards\G512\UK"), + ("G512 SE", RGBDeviceType.Keyboard, 0xC342, 0, "DE", @"Keyboards\G512SE\UK"), ("G410", RGBDeviceType.Keyboard, 0xC330, 0, "DE", @"Keyboards\G410\UK"), ("G213", RGBDeviceType.Keyboard, 0xC336, 0, "DE", @"Keyboards\G213\UK"), ("Pro", RGBDeviceType.Keyboard, 0xC339, 0, "DE", @"Keyboards\Pro\UK"), @@ -58,6 +59,7 @@ namespace RGB.NET.Devices.Logitech.HID ("G303", RGBDeviceType.Mouse, 0xC080, 2, "default", @"Mice\G303"), ("G203", RGBDeviceType.Mouse, 0xC084, 1, "default", @"Mice\G203"), ("G Pro", RGBDeviceType.Mouse, 0xC085, 1, "default", @"Mice\GPro"), + ("G Pro Wireless", RGBDeviceType.Mouse, 0xC088, 1, "default", @"Mice\GPro"), ("G Pro Hero", RGBDeviceType.Mouse, 0xC08C, 1, "default", @"Mice\GProHero"), ("G633", RGBDeviceType.Headset, 0x0A5C, 2, "default", @"Headsets\G633"), ("G933", RGBDeviceType.Headset, 0x0A5B, 2, "default", @"Headsets\G933"), From 9175887327308d05337a48f190008fec186325fb Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sat, 20 Jun 2020 22:30:55 +0200 Subject: [PATCH 26/51] Throw on LED control enable fail Added devices indices for MM830, CK530 and MK850 --- .../CoolerMasterDeviceProvider.cs | 3 ++- .../Enum/CoolerMasterDevicesIndexes.cs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index 0f34084..05546aa 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -132,7 +132,8 @@ namespace RGB.NET.Devices.CoolerMaster continue; } - _CoolerMasterSDK.EnableLedControl(true, index); + if (!_CoolerMasterSDK.EnableLedControl(true, index)) + throw new RGBDeviceException("Failed to enable LED control for device " + index); device.Initialize(UpdateTrigger); devices.Add(device); diff --git a/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterDevicesIndexes.cs b/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterDevicesIndexes.cs index cf84cbc..45d8ae2 100644 --- a/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterDevicesIndexes.cs +++ b/RGB.NET.Devices.CoolerMaster/Enum/CoolerMasterDevicesIndexes.cs @@ -69,6 +69,18 @@ namespace RGB.NET.Devices.CoolerMaster [DeviceType(RGBDeviceType.Keyboard)] CK551 = 13, + [Description("MM830")] + [DeviceType(RGBDeviceType.Mouse)] + MM830 = 14, + + [Description("CK530")] + [DeviceType(RGBDeviceType.Keyboard)] + CK530 = 15, + + [Description("MK850")] + [DeviceType(RGBDeviceType.Keyboard)] + MK850 = 16, + [DeviceType(RGBDeviceType.None)] Default = 0xFFFF } From 52fd670ba7ed5e92d6e1a2c94561001eea1d0f8c Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 8 Jul 2020 21:24:56 +0200 Subject: [PATCH 27/51] Improved usabillity of decorators a bit --- .../Decorators/AbstractDecorateable.cs | 17 +++++++---------- RGB.NET.Core/Decorators/AbstractDecorator.cs | 19 +++++++++++-------- RGB.NET.Core/Decorators/IDecoratable.cs | 10 ++++++++-- RGB.NET.Decorators/Brush/FlashDecorator.cs | 2 +- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/RGB.NET.Core/Decorators/AbstractDecorateable.cs b/RGB.NET.Core/Decorators/AbstractDecorateable.cs index 94b8f05..d12afcd 100644 --- a/RGB.NET.Core/Decorators/AbstractDecorateable.cs +++ b/RGB.NET.Core/Decorators/AbstractDecorateable.cs @@ -12,18 +12,15 @@ namespace RGB.NET.Core #region Properties & Fields private readonly List _decorators = new List(); - /// - /// Gets a readonly-list of all attached to this . - /// - protected IReadOnlyCollection Decorators { get; } - #endregion - - #region Constructors - - protected AbstractDecoratable() + /// + public IReadOnlyCollection Decorators { - Decorators = new ReadOnlyCollection(_decorators); + get + { + lock (_decorators) + return new ReadOnlyCollection(_decorators); + } } #endregion diff --git a/RGB.NET.Core/Decorators/AbstractDecorator.cs b/RGB.NET.Core/Decorators/AbstractDecorator.cs index 381f4f5..50e007c 100644 --- a/RGB.NET.Core/Decorators/AbstractDecorator.cs +++ b/RGB.NET.Core/Decorators/AbstractDecorator.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; namespace RGB.NET.Core { @@ -42,16 +44,17 @@ namespace RGB.NET.Core /// /// Detaches the decorator from all it is currently attached to. /// - /// The type of the this decorator is attached to. - /// The type of this . - protected virtual void Detach() - where TDecoratable : IDecoratable - where TDecorator : AbstractDecorator + protected virtual void Detach() { List decoratables = new List(DecoratedObjects); foreach (IDecoratable decoratable in decoratables) - if (decoratable is TDecoratable typedDecoratable) - typedDecoratable.RemoveDecorator((TDecorator)this); + { + IEnumerable types = decoratable.GetType().GetInterfaces().Where(t => t.IsGenericType + && (t.Name == typeof(IDecoratable<>).Name) + && t.GenericTypeArguments[0].IsInstanceOfType(this)); + foreach (Type decoratableType in types) + decoratableType.GetMethod(nameof(IDecoratable.RemoveDecorator))?.Invoke(decoratable, new object[] { this }); + } } #endregion diff --git a/RGB.NET.Core/Decorators/IDecoratable.cs b/RGB.NET.Core/Decorators/IDecoratable.cs index 9e2a32c..781d9f1 100644 --- a/RGB.NET.Core/Decorators/IDecoratable.cs +++ b/RGB.NET.Core/Decorators/IDecoratable.cs @@ -1,4 +1,5 @@ -using System.ComponentModel; +using System.Collections.Generic; +using System.ComponentModel; namespace RGB.NET.Core { @@ -13,9 +14,14 @@ namespace RGB.NET.Core /// Represents a basic decoratable for a specific type of /// /// - public interface IDecoratable : IDecoratable + public interface IDecoratable : IDecoratable where T : IDecorator { + /// + /// Gets a readonly-list of all attached to this . + /// + IReadOnlyCollection Decorators { get; } + /// /// Adds an to the . /// diff --git a/RGB.NET.Decorators/Brush/FlashDecorator.cs b/RGB.NET.Decorators/Brush/FlashDecorator.cs index 618b243..580fce4 100644 --- a/RGB.NET.Decorators/Brush/FlashDecorator.cs +++ b/RGB.NET.Decorators/Brush/FlashDecorator.cs @@ -129,7 +129,7 @@ namespace RGB.NET.Decorators.Brush else { if ((++_repetitionCount >= Repetitions) && (Repetitions > 0)) - Detach(); + Detach(); _currentPhaseValue = Attack; _currentPhase = ADSRPhase.Attack; } From 6696f2278aa7b68f1228b82a516f7741d027ccdd Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Wed, 8 Jul 2020 22:52:17 +0200 Subject: [PATCH 28/51] MSI - Provide sender when calling PathHelper.GetAbsolutePath --- RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs | 2 +- RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs | 2 +- RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs index f5cf4e4..74bd673 100644 --- a/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs +++ b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs @@ -41,7 +41,7 @@ namespace RGB.NET.Devices.Msi } //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? - ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\MSI\GraphicsCard\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, $@"Layouts\MSI\GraphicsCard\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); } /// diff --git a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs index a7e11cb..455e63a 100644 --- a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs @@ -39,7 +39,7 @@ namespace RGB.NET.Devices.Msi } //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? - ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\MSI\Mainboards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, $@"Layouts\MSI\Mainboards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); } /// diff --git a/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs b/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs index a153190..bbcbd57 100644 --- a/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs @@ -39,7 +39,7 @@ namespace RGB.NET.Devices.Msi } //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? - ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\MSI\Mouses\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, $@"Layouts\MSI\Mouses\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); } /// From 567247de592396c236bc8e23491e6d58bb4d79d7 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Wed, 8 Jul 2020 22:52:17 +0200 Subject: [PATCH 29/51] MSI - Provide sender when calling PathHelper.GetAbsolutePath --- RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs | 2 +- RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs | 2 +- RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs index f5cf4e4..74bd673 100644 --- a/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs +++ b/RGB.NET.Devices.Msi/GraphicsCard/MsiGraphicsCardRGBDevice.cs @@ -41,7 +41,7 @@ namespace RGB.NET.Devices.Msi } //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? - ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\MSI\GraphicsCard\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, $@"Layouts\MSI\GraphicsCard\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); } /// diff --git a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs index a7e11cb..455e63a 100644 --- a/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Mainboard/MsiMainboardRGBDevice.cs @@ -39,7 +39,7 @@ namespace RGB.NET.Devices.Msi } //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? - ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\MSI\Mainboards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, $@"Layouts\MSI\Mainboards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); } /// diff --git a/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs b/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs index a153190..bbcbd57 100644 --- a/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Mouse/MsiMouseRGBDevice.cs @@ -39,7 +39,7 @@ namespace RGB.NET.Devices.Msi } //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? - ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\MSI\Mouses\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, $@"Layouts\MSI\Mouses\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); } /// From af15c645f810023b7e59c42b86fbcdc63cfe6500 Mon Sep 17 00:00:00 2001 From: Hex3l Date: Thu, 9 Jul 2020 17:17:07 +0200 Subject: [PATCH 30/51] fixes per-key-zone devices, fixes Rival600 pid, adds Apex 7 tkl --- .../API/SteelSeriesSDK.cs | 3 +- .../HID/DeviceChecker.cs | 98 ++++++++++++++++++- 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs b/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs index 8b3d84d..2cb0d5f 100644 --- a/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs +++ b/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs @@ -25,7 +25,8 @@ namespace RGB.NET.Devices.SteelSeries.API ((nil? zoneDo)) (let* ((zone (car zoneDo)) (color (get-slot zoneData zone))) - (on-device device show-on-zone: color zone))))))"; + (on-device device show-on-zone: color zone)))))) +(add-event-per-key-zone-use """ + EVENT_NAME + @""" ""all"")"; private const string CORE_PROPS_WINDOWS = "%PROGRAMDATA%/SteelSeries/SteelSeries Engine 3/coreProps.json"; private const string CORE_PROPS_OSX = "/Library/Application Support/SteelSeries Engine 3/coreProps.json"; diff --git a/RGB.NET.Devices.SteelSeries/HID/DeviceChecker.cs b/RGB.NET.Devices.SteelSeries/HID/DeviceChecker.cs index 0c4b26f..4926d06 100644 --- a/RGB.NET.Devices.SteelSeries/HID/DeviceChecker.cs +++ b/RGB.NET.Devices.SteelSeries/HID/DeviceChecker.cs @@ -121,6 +121,99 @@ namespace RGB.NET.Devices.SteelSeries.HID { LedId.Keyboard_NumPeriodAndDelete, SteelSeriesLedId.KeypadPeriod } }; + private static readonly LedMapping KEYBOARD_TKL_MAPPING_UK = new LedMapping + { + { LedId.Logo, SteelSeriesLedId.Logo }, + { LedId.Keyboard_Escape, SteelSeriesLedId.Escape }, + { LedId.Keyboard_F1, SteelSeriesLedId.F1 }, + { LedId.Keyboard_F2, SteelSeriesLedId.F2 }, + { LedId.Keyboard_F3, SteelSeriesLedId.F3 }, + { LedId.Keyboard_F4, SteelSeriesLedId.F4 }, + { LedId.Keyboard_F5, SteelSeriesLedId.F5 }, + { LedId.Keyboard_F6, SteelSeriesLedId.F6 }, + { LedId.Keyboard_F7, SteelSeriesLedId.F7 }, + { LedId.Keyboard_F8, SteelSeriesLedId.F8 }, + { LedId.Keyboard_F9, SteelSeriesLedId.F9 }, + { LedId.Keyboard_F10, SteelSeriesLedId.F10 }, + { LedId.Keyboard_F11, SteelSeriesLedId.F11 }, + { LedId.Keyboard_GraveAccentAndTilde, SteelSeriesLedId.Backqoute }, + { LedId.Keyboard_1, SteelSeriesLedId.Keyboard1 }, + { LedId.Keyboard_2, SteelSeriesLedId.Keyboard2 }, + { LedId.Keyboard_3, SteelSeriesLedId.Keyboard3 }, + { LedId.Keyboard_4, SteelSeriesLedId.Keyboard4 }, + { LedId.Keyboard_5, SteelSeriesLedId.Keyboard5 }, + { LedId.Keyboard_6, SteelSeriesLedId.Keyboard6 }, + { LedId.Keyboard_7, SteelSeriesLedId.Keyboard7 }, + { LedId.Keyboard_8, SteelSeriesLedId.Keyboard8 }, + { LedId.Keyboard_9, SteelSeriesLedId.Keyboard9 }, + { LedId.Keyboard_0, SteelSeriesLedId.Keyboard0 }, + { LedId.Keyboard_MinusAndUnderscore, SteelSeriesLedId.Dash }, + { LedId.Keyboard_Tab, SteelSeriesLedId.Tab }, + { LedId.Keyboard_Q, SteelSeriesLedId.Q }, + { LedId.Keyboard_W, SteelSeriesLedId.W }, + { LedId.Keyboard_E, SteelSeriesLedId.E }, + { LedId.Keyboard_R, SteelSeriesLedId.R }, + { LedId.Keyboard_T, SteelSeriesLedId.T }, + { LedId.Keyboard_Y, SteelSeriesLedId.Y }, + { LedId.Keyboard_U, SteelSeriesLedId.U }, + { LedId.Keyboard_I, SteelSeriesLedId.I }, + { LedId.Keyboard_O, SteelSeriesLedId.O }, + { LedId.Keyboard_P, SteelSeriesLedId.P }, + { LedId.Keyboard_BracketLeft, SteelSeriesLedId.LBracket }, + { LedId.Keyboard_CapsLock, SteelSeriesLedId.Caps }, + { LedId.Keyboard_A, SteelSeriesLedId.A }, + { LedId.Keyboard_S, SteelSeriesLedId.S }, + { LedId.Keyboard_D, SteelSeriesLedId.D }, + { LedId.Keyboard_F, SteelSeriesLedId.F }, + { LedId.Keyboard_G, SteelSeriesLedId.G }, + { LedId.Keyboard_H, SteelSeriesLedId.H }, + { LedId.Keyboard_J, SteelSeriesLedId.J }, + { LedId.Keyboard_K, SteelSeriesLedId.K }, + { LedId.Keyboard_L, SteelSeriesLedId.L }, + { LedId.Keyboard_SemicolonAndColon, SteelSeriesLedId.Semicolon }, + { LedId.Keyboard_ApostropheAndDoubleQuote, SteelSeriesLedId.Quote }, + { LedId.Keyboard_LeftShift, SteelSeriesLedId.LShift }, + { LedId.Keyboard_NonUsTilde, SteelSeriesLedId.Pound }, + { LedId.Keyboard_Z, SteelSeriesLedId.Z }, + { LedId.Keyboard_X, SteelSeriesLedId.X }, + { LedId.Keyboard_C, SteelSeriesLedId.C }, + { LedId.Keyboard_V, SteelSeriesLedId.V }, + { LedId.Keyboard_B, SteelSeriesLedId.B }, + { LedId.Keyboard_N, SteelSeriesLedId.N }, + { LedId.Keyboard_M, SteelSeriesLedId.M }, + { LedId.Keyboard_CommaAndLessThan, SteelSeriesLedId.Comma }, + { LedId.Keyboard_PeriodAndBiggerThan, SteelSeriesLedId.Period }, + { LedId.Keyboard_SlashAndQuestionMark, SteelSeriesLedId.Slash }, + { LedId.Keyboard_LeftCtrl, SteelSeriesLedId.LCtrl }, + { LedId.Keyboard_LeftGui, SteelSeriesLedId.LWin }, + { LedId.Keyboard_LeftAlt, SteelSeriesLedId.LAlt }, + { LedId.Keyboard_Space, SteelSeriesLedId.Spacebar }, + { LedId.Keyboard_RightAlt, SteelSeriesLedId.RAlt }, + { LedId.Keyboard_RightGui, SteelSeriesLedId.RWin }, + { LedId.Keyboard_Application, SteelSeriesLedId.SSKey }, + { LedId.Keyboard_F12, SteelSeriesLedId.F12 }, + { LedId.Keyboard_PrintScreen, SteelSeriesLedId.PrintScreen }, + { LedId.Keyboard_ScrollLock, SteelSeriesLedId.ScrollLock }, + { LedId.Keyboard_PauseBreak, SteelSeriesLedId.Pause }, + { LedId.Keyboard_Insert, SteelSeriesLedId.Insert }, + { LedId.Keyboard_Home, SteelSeriesLedId.Home }, + { LedId.Keyboard_PageUp, SteelSeriesLedId.PageUp }, + { LedId.Keyboard_BracketRight, SteelSeriesLedId.RBracket }, + { LedId.Keyboard_Backslash, SteelSeriesLedId.Backslash }, + { LedId.Keyboard_Enter, SteelSeriesLedId.Return }, + { LedId.Keyboard_EqualsAndPlus, SteelSeriesLedId.Equal }, + { LedId.Keyboard_Backspace, SteelSeriesLedId.Backspace }, + { LedId.Keyboard_Delete, SteelSeriesLedId.Delete }, + { LedId.Keyboard_End, SteelSeriesLedId.End }, + { LedId.Keyboard_PageDown, SteelSeriesLedId.PageDown }, + { LedId.Keyboard_RightShift, SteelSeriesLedId.RShift }, + { LedId.Keyboard_RightCtrl, SteelSeriesLedId.RCtrl }, + { LedId.Keyboard_ArrowUp, SteelSeriesLedId.UpArrow }, + { LedId.Keyboard_ArrowLeft, SteelSeriesLedId.LeftArrow }, + { LedId.Keyboard_ArrowDown, SteelSeriesLedId.DownArrow }, + { LedId.Keyboard_ArrowRight, SteelSeriesLedId.RightArrow } + }; + private static readonly LedMapping MOUSE_TWO_ZONE = new LedMapping { {LedId.Mouse1, SteelSeriesLedId.ZoneOne}, @@ -144,11 +237,12 @@ namespace RGB.NET.Devices.SteelSeries.HID //TODO DarthAffe 16.02.2019: Add devices private static readonly DeviceDataList DEVICES = new DeviceDataList { - ("Rival 600", RGBDeviceType.Mouse, 0x0616, SteelSeriesDeviceType.EightZone, "default", @"Mice\Rival600", MOUSE_EIGHT_ZONE), + ("Rival 600", RGBDeviceType.Mouse, 0x1724, SteelSeriesDeviceType.EightZone, "default", @"Mice\Rival600", MOUSE_EIGHT_ZONE), ("Rival 500", RGBDeviceType.Mouse, 0x170E, SteelSeriesDeviceType.TwoZone, "default", @"Mice\Rival500", MOUSE_TWO_ZONE), ("Rival 310", RGBDeviceType.Mouse, 0x1720, SteelSeriesDeviceType.TwoZone, "default", @"Mice\Rival310", MOUSE_TWO_ZONE), - ("Apex M750", RGBDeviceType.Keyboard, 0x1724, SteelSeriesDeviceType.PerKey, "UK", @"Keyboards\M750\UK", KEYBOARD_MAPPING_UK), + ("Apex 7 TKL", RGBDeviceType.Keyboard, 0x1618, SteelSeriesDeviceType.PerKey, "UK", @"Keyboards\7TKL\UK", KEYBOARD_TKL_MAPPING_UK), + ("Apex M750", RGBDeviceType.Keyboard, 0x0616, SteelSeriesDeviceType.PerKey, "UK", @"Keyboards\M750\UK", KEYBOARD_MAPPING_UK), }; #endregion From 7b5013c4f8826122be36f9e413d539bcc249d483 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 9 Jul 2020 21:03:26 +0200 Subject: [PATCH 31/51] Fixed device-initialization in lisp-handler --- .../API/SteelSeriesSDK.cs | 19 ++++++++++++++++--- .../Enum/SteelSeriesDeviceType.cs | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs b/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs index 8b3d84d..f6c1783 100644 --- a/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs +++ b/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs @@ -16,7 +16,7 @@ namespace RGB.NET.Devices.SteelSeries.API private const string GAME_NAME = "RGBNET"; private const string GAME_DISPLAYNAME = "RGB.NET"; private const string EVENT_NAME = "UPDATELEDS"; - private const string HANDLER = @"(handler """ + EVENT_NAME + @""" + private static readonly string HANDLER = $@"(handler ""{EVENT_NAME}"" (lambda (data) (let* ((device (value: data)) (zoneData (frame: data)) @@ -25,8 +25,21 @@ namespace RGB.NET.Devices.SteelSeries.API ((nil? zoneDo)) (let* ((zone (car zoneDo)) (color (get-slot zoneData zone))) - (on-device device show-on-zone: color zone))))))"; - + (on-device device show-on-zone: color zone)))))) +(add-event-per-key-zone-use ""{EVENT_NAME}"" ""all"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-1-zone"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-2-zone"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-3-zone"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-4-zone"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-5-zone"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-6-zone"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-7-zone"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-8-zone"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-12-zone"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-17-zone"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-24-zone"") +(add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-103-zone"")"; + private const string CORE_PROPS_WINDOWS = "%PROGRAMDATA%/SteelSeries/SteelSeries Engine 3/coreProps.json"; private const string CORE_PROPS_OSX = "/Library/Application Support/SteelSeries Engine 3/coreProps.json"; diff --git a/RGB.NET.Devices.SteelSeries/Enum/SteelSeriesDeviceType.cs b/RGB.NET.Devices.SteelSeries/Enum/SteelSeriesDeviceType.cs index 65ee724..3e68226 100644 --- a/RGB.NET.Devices.SteelSeries/Enum/SteelSeriesDeviceType.cs +++ b/RGB.NET.Devices.SteelSeries/Enum/SteelSeriesDeviceType.cs @@ -1,5 +1,6 @@ namespace RGB.NET.Devices.SteelSeries { + // DarthAffe 09.07.2020: Review the LISP-Handler in SteelSeriesSDK after adding new device-types! They need to be initialized. public enum SteelSeriesDeviceType { [APIName("rgb-per-key-zones")] From 5a4294499aa40d8dbe1c9162eaaccc0c96662d3f Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 11 Jul 2020 21:14:21 +0200 Subject: [PATCH 32/51] Rewrote lisp-handler to greatly improve performance for bigger devices (like keyboards) --- .../API/SteelSeriesSDK.cs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs b/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs index 70c82e2..bf82309 100644 --- a/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs +++ b/RGB.NET.Devices.SteelSeries/API/SteelSeriesSDK.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net.Http; using System.Runtime.InteropServices; using System.Text; @@ -16,16 +17,21 @@ namespace RGB.NET.Devices.SteelSeries.API private const string GAME_NAME = "RGBNET"; private const string GAME_DISPLAYNAME = "RGB.NET"; private const string EVENT_NAME = "UPDATELEDS"; - private static readonly string HANDLER = $@"(handler ""{EVENT_NAME}"" + private static readonly string HANDLER = $@"(define (getZone x) + (case x + {string.Join(Environment.NewLine, Enum.GetValues(typeof(SteelSeriesLedId)) + .Cast() + .Select(x => x.GetAPIName()) + .Select(ledId => $" ((\"{ledId}\") {ledId}:)"))} + )) + +(handler ""{EVENT_NAME}"" (lambda (data) (let* ((device (value: data)) - (zoneData (frame: data)) - (zones (frame-keys zoneData))) - (do ((zoneDo zones (cdr zoneDo))) - ((nil? zoneDo)) - (let* ((zone (car zoneDo)) - (color (get-slot zoneData zone))) - (on-device device show-on-zone: color zone)))))) + (zones (zones: data)) + (colors (colors: data))) + (on-device device show-on-zones: colors (map (lambda (x) (getZone x)) zones))))) + (add-event-per-key-zone-use ""{EVENT_NAME}"" ""all"") (add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-1-zone"") (add-event-zone-use-with-specifier ""{EVENT_NAME}"" ""all"" ""rgb-2-zone"") @@ -87,7 +93,8 @@ namespace RGB.NET.Devices.SteelSeries.API { _event.Data.Clear(); _event.Data.Add("value", device); - _event.Data.Add("frame", data); + _event.Data.Add("colors", data.Values.ToList()); + _event.Data.Add("zones", data.Keys.ToList()); TriggerEvent(_event); } From f4d2e59831b111a5da51db04e9ac618d0b3f3177 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 11 Jul 2020 21:14:40 +0200 Subject: [PATCH 33/51] Replaced refresh-update with heartbeat --- .../Generic/SteelSeriesDeviceUpdateQueue.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs index fe3d576..c2befb6 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesDeviceUpdateQueue.cs @@ -15,7 +15,6 @@ namespace RGB.NET.Devices.SteelSeries #region Properties & Fields private string _deviceType; - private Dictionary _lastDataSet; #endregion @@ -39,20 +38,14 @@ namespace RGB.NET.Devices.SteelSeries protected override void OnUpdate(object sender, CustomUpdateData customData) { if ((customData != null) && (customData["refresh"] as bool? ?? false)) - { - if ((_lastDataSet != null) && (_lastDataSet.Count != 0)) - Update(_lastDataSet); - } + SteelSeriesSDK.SendHeartbeat(); else base.OnUpdate(sender, customData); } /// protected override void Update(Dictionary dataSet) - { - _lastDataSet = dataSet; - SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.ToDictionary(x => ((SteelSeriesLedId)x.Key).GetAPIName(), x => x.Value.ToIntArray())); - } + => SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.ToDictionary(x => ((SteelSeriesLedId)x.Key).GetAPIName(), x => x.Value.ToIntArray())); #endregion } From acdd7c19aa1717cb403b3a94003108a8e7d7b7c3 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 11 Jul 2020 23:50:18 +0200 Subject: [PATCH 34/51] Added additional custom-keyboard-keys --- RGB.NET.Core/Leds/LedId.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/RGB.NET.Core/Leds/LedId.cs b/RGB.NET.Core/Leds/LedId.cs index 6278aae..536263e 100644 --- a/RGB.NET.Core/Leds/LedId.cs +++ b/RGB.NET.Core/Leds/LedId.cs @@ -213,6 +213,38 @@ namespace RGB.NET.Core Keyboard_Custom30 = 0x0000701E, Keyboard_Custom31 = 0x0000701F, Keyboard_Custom32 = 0x00007020, + Keyboard_Custom33 = 0x00007021, + Keyboard_Custom34 = 0x00007022, + Keyboard_Custom35 = 0x00007023, + Keyboard_Custom36 = 0x00007024, + Keyboard_Custom37 = 0x00007025, + Keyboard_Custom38 = 0x00007026, + Keyboard_Custom39 = 0x00007027, + Keyboard_Custom40 = 0x00007028, + Keyboard_Custom41 = 0x00007029, + Keyboard_Custom42 = 0x0000702A, + Keyboard_Custom43 = 0x0000702B, + Keyboard_Custom44 = 0x0000702C, + Keyboard_Custom45 = 0x0000702D, + Keyboard_Custom46 = 0x0000702E, + Keyboard_Custom47 = 0x0000702F, + Keyboard_Custom48 = 0x00007030, + Keyboard_Custom49 = 0x00007031, + Keyboard_Custom50 = 0x00007032, + Keyboard_Custom51 = 0x00007033, + Keyboard_Custom52 = 0x00007034, + Keyboard_Custom53 = 0x00007035, + Keyboard_Custom54 = 0x00007036, + Keyboard_Custom55 = 0x00007037, + Keyboard_Custom56 = 0x00007038, + Keyboard_Custom57 = 0x00007039, + Keyboard_Custom58 = 0x0000703A, + Keyboard_Custom59 = 0x0000703B, + Keyboard_Custom60 = 0x0000703C, + Keyboard_Custom61 = 0x0000703D, + Keyboard_Custom62 = 0x0000703E, + Keyboard_Custom63 = 0x0000703F, + Keyboard_Custom64 = 0x00007040, /*### Mouse ###*/ Mouse1 = 0x00100001, From ca29490f0228ebc3e66311add11f4f6738cb04d9 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 11 Jul 2020 23:50:33 +0200 Subject: [PATCH 35/51] Refactored asus keyboard implementation --- .../{AsusDeviceTypes.cs => AsusDeviceType.cs} | 2 +- .../Enum/{AsusLedIds.cs => AsusLedId.cs} | 9 +- .../Generic/AsusUpdateQueue.cs | 45 ++- .../Keyboard/AsusKeyboardLedMapping.cs | 161 +++++++++++ .../Keyboard/AsusKeyboardLedMappings.cs | 138 --------- .../Keyboard/AsusKeyboardRGBDevice.cs | 263 ++---------------- 6 files changed, 207 insertions(+), 411 deletions(-) rename RGB.NET.Devices.Asus/Enum/{AsusDeviceTypes.cs => AsusDeviceType.cs} (93%) rename RGB.NET.Devices.Asus/Enum/{AsusLedIds.cs => AsusLedId.cs} (96%) create mode 100644 RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMapping.cs delete mode 100644 RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMappings.cs diff --git a/RGB.NET.Devices.Asus/Enum/AsusDeviceTypes.cs b/RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs similarity index 93% rename from RGB.NET.Devices.Asus/Enum/AsusDeviceTypes.cs rename to RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs index a86ac4c..7990bce 100644 --- a/RGB.NET.Devices.Asus/Enum/AsusDeviceTypes.cs +++ b/RGB.NET.Devices.Asus/Enum/AsusDeviceType.cs @@ -2,7 +2,7 @@ namespace RGB.NET.Devices.Asus { - internal enum AsusDeviceTypes + internal enum AsusDeviceType : uint { ALL = 0, MB_RGB = 0x10000, diff --git a/RGB.NET.Devices.Asus/Enum/AsusLedIds.cs b/RGB.NET.Devices.Asus/Enum/AsusLedId.cs similarity index 96% rename from RGB.NET.Devices.Asus/Enum/AsusLedIds.cs rename to RGB.NET.Devices.Asus/Enum/AsusLedId.cs index 665015f..f56d64a 100644 --- a/RGB.NET.Devices.Asus/Enum/AsusLedIds.cs +++ b/RGB.NET.Devices.Asus/Enum/AsusLedId.cs @@ -2,7 +2,7 @@ namespace RGB.NET.Devices.Asus { - internal enum AsusLedIds + internal enum AsusLedId : ushort { KEY_ESCAPE = 0x01, KEY_1 = 0x02, @@ -149,5 +149,12 @@ namespace RGB.NET.Devices.Asus KEY_MAIL = 0xEC, // Mail KEY_MEDIASELECT = 0xED, // Media Select KEY_FN = 0x100, // Function key + + // Undocumented + UNDOCUMENTED_1 = 0x59, + UNDOCUMENTED_2 = 0x56, + UNDOCUMENTED_3 = 0x101, + UNDOCUMENTED_4 = 0x102, + UNDOCUMENTED_5 = 0x103, } } diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs index 4328dc1..9a3b260 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using AuraServiceLib; using RGB.NET.Core; @@ -48,40 +47,31 @@ namespace RGB.NET.Devices.Asus { try { - if ((Device.Type == 0x00080000) || (Device.Type == 0x00081000)) //Keyboard + if ((Device.Type == (uint)AsusDeviceType.KEYBOARD_RGB) || (Device.Type == (uint)AsusDeviceType.NB_KB_RGB)) { foreach (KeyValuePair data in dataSet) { - ushort index = (ushort)data.Key; + AsusLedId index = (AsusLedId)data.Key; IAuraSyncKeyboard keyboard = (IAuraSyncKeyboard)Device; if (keyboard != null) { - IAuraRgbLight light; - //UK keyboard Layout - if (index == 0x56) + IAuraRgbLight light = index switch { - light = keyboard.Lights[(int)(3 * keyboard.Width + 13)]; - } - else if (index == 0x59) - { - light = keyboard.Lights[(int)(4 * keyboard.Width + 1)]; - } - else - { - light = keyboard.Key[index]; - } + //UK keyboard Layout + AsusLedId.KEY_OEM_102 => keyboard.Lights[(int)((3 * keyboard.Width) + 13)], + AsusLedId.UNDOCUMENTED_1 => keyboard.Lights[(int)((4 * keyboard.Width) + 1)], + _ => keyboard.Key[(ushort)index] + }; + // Asus Strix Scope if (keyboard.Name == "Charm") - { - if (index == 0XDB) + light = index switch { - light = keyboard.Lights[(int)(5 * keyboard.Width + 2)]; - } - else if (index == 0x38) - { - light = keyboard.Lights[(int)(5 * keyboard.Width + 3)]; - } - } + AsusLedId.KEY_LWIN => keyboard.Lights[(int)((5 * keyboard.Width) + 2)], + AsusLedId.KEY_LMENU => keyboard.Lights[(int)((5 * keyboard.Width) + 3)], + _ => light + }; + (_, byte r, byte g, byte b) = data.Value.GetRGBBytes(); light.Red = r; light.Green = g; @@ -95,6 +85,7 @@ namespace RGB.NET.Devices.Asus { int index = (int)data.Key; IAuraRgbLight light = Device.Lights[index]; + (_, byte r, byte g, byte b) = data.Value.GetRGBBytes(); light.Red = r; light.Green = g; @@ -104,7 +95,7 @@ namespace RGB.NET.Devices.Asus Device.Apply(); } - catch (Exception ex) + catch { /* "The server threw an exception." seems to be a thing here ... */ } } #endregion diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMapping.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMapping.cs new file mode 100644 index 0000000..2b48961 --- /dev/null +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMapping.cs @@ -0,0 +1,161 @@ +using System.Collections.Generic; +using RGB.NET.Core; + +namespace RGB.NET.Devices.Asus +{ + internal static class AsusKeyboardLedMapping + { + public static readonly Dictionary MAPPING = new Dictionary + { + { LedId.Keyboard_Escape, AsusLedId.KEY_ESCAPE }, + { LedId.Keyboard_F1, AsusLedId.KEY_F1 }, + { LedId.Keyboard_F2, AsusLedId.KEY_F2 }, + { LedId.Keyboard_F3, AsusLedId.KEY_F3 }, + { LedId.Keyboard_F4, AsusLedId.KEY_F4 }, + { LedId.Keyboard_F5, AsusLedId.KEY_F5 }, + { LedId.Keyboard_F6, AsusLedId.KEY_F6 }, + { LedId.Keyboard_F7, AsusLedId.KEY_F7 }, + { LedId.Keyboard_F8, AsusLedId.KEY_F8 }, + { LedId.Keyboard_F9, AsusLedId.KEY_F9 }, + { LedId.Keyboard_F10, AsusLedId.KEY_F10 }, + { LedId.Keyboard_F11, AsusLedId.KEY_F11 }, + { LedId.Keyboard_F12, AsusLedId.KEY_F12 }, + { LedId.Keyboard_1, AsusLedId.KEY_1 }, + { LedId.Keyboard_2, AsusLedId.KEY_2 }, + { LedId.Keyboard_3, AsusLedId.KEY_3 }, + { LedId.Keyboard_4, AsusLedId.KEY_4 }, + { LedId.Keyboard_5, AsusLedId.KEY_5 }, + { LedId.Keyboard_6, AsusLedId.KEY_6 }, + { LedId.Keyboard_7, AsusLedId.KEY_7 }, + { LedId.Keyboard_8, AsusLedId.KEY_8 }, + { LedId.Keyboard_9, AsusLedId.KEY_9 }, + { LedId.Keyboard_0, AsusLedId.KEY_0 }, + { LedId.Keyboard_MinusAndUnderscore, AsusLedId.KEY_MINUS }, + { LedId.Keyboard_EqualsAndPlus, AsusLedId.KEY_EQUALS }, + { LedId.Keyboard_Backspace, AsusLedId.KEY_BACK }, + { LedId.Keyboard_Tab, AsusLedId.KEY_TAB }, + { LedId.Keyboard_Q, AsusLedId.KEY_Q }, + { LedId.Keyboard_W, AsusLedId.KEY_W }, + { LedId.Keyboard_E, AsusLedId.KEY_E }, + { LedId.Keyboard_R, AsusLedId.KEY_R }, + { LedId.Keyboard_T, AsusLedId.KEY_T }, + { LedId.Keyboard_Y, AsusLedId.KEY_Y }, + { LedId.Keyboard_U, AsusLedId.KEY_U }, + { LedId.Keyboard_I, AsusLedId.KEY_I }, + { LedId.Keyboard_O, AsusLedId.KEY_O }, + { LedId.Keyboard_P, AsusLedId.KEY_P }, + { LedId.Keyboard_BracketLeft, AsusLedId.KEY_LBRACKET }, + { LedId.Keyboard_BracketRight, AsusLedId.KEY_RBRACKET }, + { LedId.Keyboard_Enter, AsusLedId.KEY_RETURN }, + { LedId.Keyboard_CapsLock, AsusLedId.KEY_CAPITAL }, + { LedId.Keyboard_A, AsusLedId.KEY_A }, + { LedId.Keyboard_S, AsusLedId.KEY_S }, + { LedId.Keyboard_D, AsusLedId.KEY_D }, + { LedId.Keyboard_F, AsusLedId.KEY_F }, + { LedId.Keyboard_G, AsusLedId.KEY_G }, + { LedId.Keyboard_H, AsusLedId.KEY_H }, + { LedId.Keyboard_J, AsusLedId.KEY_J }, + { LedId.Keyboard_K, AsusLedId.KEY_K }, + { LedId.Keyboard_L, AsusLedId.KEY_L }, + { LedId.Keyboard_SemicolonAndColon, AsusLedId.KEY_SEMICOLON }, + { LedId.Keyboard_ApostropheAndDoubleQuote, AsusLedId.KEY_APOSTROPHE }, + { LedId.Keyboard_GraveAccentAndTilde, AsusLedId.KEY_GRAVE }, + { LedId.Keyboard_LeftShift, AsusLedId.KEY_LSHIFT }, + { LedId.Keyboard_Backslash, AsusLedId.KEY_BACKSLASH }, + { LedId.Keyboard_Z, AsusLedId.KEY_Z }, + { LedId.Keyboard_X, AsusLedId.KEY_X }, + { LedId.Keyboard_C, AsusLedId.KEY_C }, + { LedId.Keyboard_V, AsusLedId.KEY_V }, + { LedId.Keyboard_B, AsusLedId.KEY_B }, + { LedId.Keyboard_N, AsusLedId.KEY_N }, + { LedId.Keyboard_M, AsusLedId.KEY_M }, + { LedId.Keyboard_CommaAndLessThan, AsusLedId.KEY_COMMA }, + { LedId.Keyboard_PeriodAndBiggerThan, AsusLedId.KEY_PERIOD }, + { LedId.Keyboard_SlashAndQuestionMark, AsusLedId.KEY_SLASH }, + { LedId.Keyboard_RightShift, AsusLedId.KEY_RSHIFT }, + { LedId.Keyboard_LeftCtrl, AsusLedId.KEY_LCONTROL }, + { LedId.Keyboard_LeftGui, AsusLedId.KEY_LWIN }, + { LedId.Keyboard_LeftAlt, AsusLedId.KEY_LMENU }, + { LedId.Keyboard_Space, AsusLedId.KEY_SPACE }, + { LedId.Keyboard_RightAlt, AsusLedId.KEY_RMENU }, + { LedId.Keyboard_RightGui, AsusLedId.KEY_RWIN }, + { LedId.Keyboard_Application, AsusLedId.KEY_APPS }, + { LedId.Keyboard_RightCtrl, AsusLedId.KEY_RCONTROL }, + { LedId.Keyboard_PrintScreen, AsusLedId.KEY_SYSRQ }, + { LedId.Keyboard_ScrollLock, AsusLedId.KEY_SCROLL }, + { LedId.Keyboard_PauseBreak, AsusLedId.KEY_PAUSE }, + { LedId.Keyboard_Insert, AsusLedId.KEY_INSERT }, + { LedId.Keyboard_Home, AsusLedId.KEY_HOME }, + { LedId.Keyboard_PageUp, AsusLedId.KEY_PRIOR }, + { LedId.Keyboard_Delete, AsusLedId.KEY_DELETE }, + { LedId.Keyboard_End, AsusLedId.KEY_END }, + { LedId.Keyboard_PageDown, AsusLedId.KEY_NEXT }, + { LedId.Keyboard_ArrowUp, AsusLedId.KEY_UP }, + { LedId.Keyboard_ArrowLeft, AsusLedId.KEY_LEFT }, + { LedId.Keyboard_ArrowDown, AsusLedId.KEY_DOWN }, + { LedId.Keyboard_ArrowRight, AsusLedId.KEY_RIGHT }, + { LedId.Keyboard_NumLock, AsusLedId.KEY_NUMLOCK }, + { LedId.Keyboard_NumSlash, AsusLedId.KEY_DIVIDE }, + { LedId.Keyboard_NumAsterisk, AsusLedId.KEY_MULTIPLY }, + { LedId.Keyboard_NumMinus, AsusLedId.KEY_SUBTRACT }, + { LedId.Keyboard_Num7, AsusLedId.KEY_NUMPAD7 }, + { LedId.Keyboard_Num8, AsusLedId.KEY_NUMPAD8 }, + { LedId.Keyboard_Num9, AsusLedId.KEY_NUMPAD9 }, + { LedId.Keyboard_NumPeriodAndDelete, AsusLedId.KEY_DECIMAL }, + { LedId.Keyboard_NumPlus, AsusLedId.KEY_ADD }, + { LedId.Keyboard_Num4, AsusLedId.KEY_NUMPAD4 }, + { LedId.Keyboard_Num5, AsusLedId.KEY_NUMPAD5 }, + { LedId.Keyboard_Num6, AsusLedId.KEY_NUMPAD6 }, + { LedId.Keyboard_Num1, AsusLedId.KEY_NUMPAD1 }, + { LedId.Keyboard_Num2, AsusLedId.KEY_NUMPAD2 }, + { LedId.Keyboard_Num3, AsusLedId.KEY_NUMPAD3 }, + { LedId.Keyboard_Num0, AsusLedId.KEY_NUMPAD0 }, + { LedId.Keyboard_NumEnter, AsusLedId.KEY_NUMPADENTER }, + { LedId.Keyboard_NonUsBackslash, AsusLedId.UNDOCUMENTED_1 }, + { LedId.Keyboard_NonUsTilde, AsusLedId.UNDOCUMENTED_2 }, + { LedId.Keyboard_NumComma, AsusLedId.KEY_NUMPADCOMMA }, + { LedId.Logo, AsusLedId.UNDOCUMENTED_3 }, + { LedId.Keyboard_Custom1, AsusLedId.UNDOCUMENTED_4 }, + { LedId.Keyboard_Custom2, AsusLedId.UNDOCUMENTED_5 }, + { LedId.Keyboard_Custom3, AsusLedId.KEY_F13 }, + { LedId.Keyboard_Custom4, AsusLedId.KEY_F14 }, + { LedId.Keyboard_Custom5, AsusLedId.KEY_F15 }, + { LedId.Keyboard_Custom6, AsusLedId.KEY_KANA }, + { LedId.Keyboard_Custom7, AsusLedId.KEY_ABNT_C1 }, + { LedId.Keyboard_Custom8, AsusLedId.KEY_CONVERT }, + { LedId.Keyboard_Custom9, AsusLedId.KEY_NOCONVERT }, + { LedId.Keyboard_Custom10, AsusLedId.KEY_YEN }, + { LedId.Keyboard_Custom11, AsusLedId.KEY_ABNT_C2 }, + { LedId.Keyboard_Custom12, AsusLedId.KEY_NUMPADEQUALS }, + { LedId.Keyboard_Custom13, AsusLedId.KEY_CIRCUMFLEX }, + { LedId.Keyboard_Custom14, AsusLedId.KEY_AT }, + { LedId.Keyboard_Custom15, AsusLedId.KEY_COLON }, + { LedId.Keyboard_Custom16, AsusLedId.KEY_UNDERLINE }, + { LedId.Keyboard_Custom17, AsusLedId.KEY_KANJI }, + { LedId.Keyboard_Custom18, AsusLedId.KEY_STOP }, + { LedId.Keyboard_Custom19, AsusLedId.KEY_AX }, + { LedId.Keyboard_Custom20, AsusLedId.KEY_UNLABELED }, + { LedId.Keyboard_Custom21, AsusLedId.KEY_NEXTTRACK }, + { LedId.Keyboard_Custom22, AsusLedId.KEY_CALCULATOR }, + { LedId.Keyboard_Custom23, AsusLedId.KEY_POWER }, + { LedId.Keyboard_Custom24, AsusLedId.KEY_SLEEP }, + { LedId.Keyboard_Custom25, AsusLedId.KEY_WAKE }, + { LedId.Keyboard_Custom26, AsusLedId.KEY_WEBSEARCH }, + { LedId.Keyboard_Custom27, AsusLedId.KEY_WEBFAVORITES }, + { LedId.Keyboard_Custom28, AsusLedId.KEY_WEBREFRESH }, + { LedId.Keyboard_Custom29, AsusLedId.KEY_WEBSTOP }, + { LedId.Keyboard_Custom30, AsusLedId.KEY_WEBFORWARD }, + { LedId.Keyboard_Custom31, AsusLedId.KEY_WEBHOME }, + { LedId.Keyboard_Custom32, AsusLedId.KEY_WEBBACK }, + { LedId.Keyboard_Custom33, AsusLedId.KEY_MYCOMPUTER }, + { LedId.Keyboard_Custom34, AsusLedId.KEY_MAIL }, + { LedId.Keyboard_Custom35, AsusLedId.KEY_MEDIASELECT }, + { LedId.Keyboard_Custom36, AsusLedId.KEY_FN }, + { LedId.Keyboard_MediaMute, AsusLedId.KEY_MUTE }, + { LedId.Keyboard_MediaPlay, AsusLedId.KEY_PLAYPAUSE }, + { LedId.Keyboard_MediaStop, AsusLedId.KEY_MEDIASTOP }, + { LedId.Keyboard_MediaVolumeDown, AsusLedId.KEY_VOLUMEDOWN }, + { LedId.Keyboard_MediaVolumeUp, AsusLedId.KEY_VOLUMEUP }, + }; + } +} diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMappings.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMappings.cs deleted file mode 100644 index 7c336ac..0000000 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardLedMappings.cs +++ /dev/null @@ -1,138 +0,0 @@ -using System.Collections.Generic; -using RGB.NET.Core; - -namespace RGB.NET.Devices.Asus -{ - internal static class AsusKeyboardLedMappings - { - private static readonly Dictionary MasterKeysL_US = new Dictionary - { - { LedId.Keyboard_Escape, (0,0) }, - { LedId.Keyboard_F1, (0,1) }, - { LedId.Keyboard_F2, (0,2) }, - { LedId.Keyboard_F3, (0,3) }, - { LedId.Keyboard_F4, (0,4) }, - { LedId.Keyboard_F5, (0,6) }, - { LedId.Keyboard_F6, (0,7) }, - { LedId.Keyboard_F7, (0,8) }, - { LedId.Keyboard_F8, (0,9) }, - { LedId.Keyboard_F9, (0,11) }, - { LedId.Keyboard_F10, (0,12) }, - { LedId.Keyboard_F11, (0,13) }, - { LedId.Keyboard_F12, (0,14) }, - { LedId.Keyboard_PrintScreen, (0,15) }, - { LedId.Keyboard_ScrollLock, (0,16) }, - { LedId.Keyboard_PauseBreak, (0,17) }, - { LedId.Keyboard_Programmable1, (0,18) }, - { LedId.Keyboard_Programmable2, (0,19) }, - { LedId.Keyboard_Programmable3, (0,20) }, - { LedId.Keyboard_Programmable4, (0,21) }, - - { LedId.Keyboard_GraveAccentAndTilde, (1,0) }, - { LedId.Keyboard_1, (1,1) }, - { LedId.Keyboard_2, (1,2) }, - { LedId.Keyboard_3, (1,3) }, - { LedId.Keyboard_4, (1,4) }, - { LedId.Keyboard_5, (1,5) }, - { LedId.Keyboard_6, (1,6) }, - { LedId.Keyboard_7, (1,7) }, - { LedId.Keyboard_8, (1,8) }, - { LedId.Keyboard_9, (1,9) }, - { LedId.Keyboard_0, (1,10) }, - { LedId.Keyboard_MinusAndUnderscore, (1,11) }, - { LedId.Keyboard_EqualsAndPlus, (1,12) }, - { LedId.Keyboard_Backspace, (1,14) }, - { LedId.Keyboard_Insert, (1,15) }, - { LedId.Keyboard_Home, (1,16) }, - { LedId.Keyboard_PageUp, (1,17) }, - { LedId.Keyboard_NumLock, (1,18) }, - { LedId.Keyboard_NumSlash, (1,19) }, - { LedId.Keyboard_NumAsterisk, (1,20) }, - { LedId.Keyboard_NumMinus, (1,21) }, - - { LedId.Keyboard_Tab, (2,0) }, - { LedId.Keyboard_Q, (2,1) }, - { LedId.Keyboard_W, (2,2) }, - { LedId.Keyboard_E, (2,3) }, - { LedId.Keyboard_R, (2,4) }, - { LedId.Keyboard_T, (2,5) }, - { LedId.Keyboard_Y, (2,6) }, - { LedId.Keyboard_U, (2,7) }, - { LedId.Keyboard_I, (2,8) }, - { LedId.Keyboard_O, (2,9) }, - { LedId.Keyboard_P, (2,10) }, - { LedId.Keyboard_BracketLeft, (2,11) }, - { LedId.Keyboard_BracketRight, (2,12) }, - { LedId.Keyboard_Backslash, (2,14) }, - { LedId.Keyboard_Delete, (2,15) }, - { LedId.Keyboard_End, (2,16) }, - { LedId.Keyboard_PageDown, (2,17) }, - { LedId.Keyboard_Num7, (2,18) }, - { LedId.Keyboard_Num8, (2,19) }, - { LedId.Keyboard_Num9, (2,20) }, - { LedId.Keyboard_NumPlus, (2,21) }, - - { LedId.Keyboard_CapsLock, (3,0) }, - { LedId.Keyboard_A, (3,1) }, - { LedId.Keyboard_S, (3,2) }, - { LedId.Keyboard_D, (3,3) }, - { LedId.Keyboard_F, (3,4) }, - { LedId.Keyboard_G, (3,5) }, - { LedId.Keyboard_H, (3,6) }, - { LedId.Keyboard_J, (3,7) }, - { LedId.Keyboard_K, (3,8) }, - { LedId.Keyboard_L, (3,9) }, - { LedId.Keyboard_SemicolonAndColon, (3,10) }, - { LedId.Keyboard_ApostropheAndDoubleQuote, (3,11) }, - { LedId.Keyboard_Enter, (3,14) }, - { LedId.Keyboard_Num4, (3,18) }, - { LedId.Keyboard_Num5, (3,19) }, - { LedId.Keyboard_Num6, (3,20) }, - - { LedId.Keyboard_LeftShift, (4,0) }, - { LedId.Keyboard_Z, (4,2) }, - { LedId.Keyboard_X, (4,3) }, - { LedId.Keyboard_C, (4,4) }, - { LedId.Keyboard_V, (4,5) }, - { LedId.Keyboard_B, (4,6) }, - { LedId.Keyboard_N, (4,7) }, - { LedId.Keyboard_M, (4,8) }, - { LedId.Keyboard_CommaAndLessThan, (4,9) }, - { LedId.Keyboard_PeriodAndBiggerThan, (4,10) }, - { LedId.Keyboard_SlashAndQuestionMark, (4,11) }, - { LedId.Keyboard_RightShift, (4,14) }, - { LedId.Keyboard_ArrowUp, (4,16) }, - { LedId.Keyboard_Num1, (4,18) }, - { LedId.Keyboard_Num2, (4,19) }, - { LedId.Keyboard_Num3, (4,20) }, - { LedId.Keyboard_NumEnter, (4,21) }, - - { LedId.Keyboard_LeftCtrl, (5,0) }, - { LedId.Keyboard_LeftGui, (5,1) }, - { LedId.Keyboard_LeftAlt, (5,2) }, - { LedId.Keyboard_Space, (5,6) }, - { LedId.Keyboard_RightAlt, (5,10) }, - { LedId.Keyboard_RightGui, (5,11) }, - { LedId.Keyboard_Application, (5,12) }, - { LedId.Keyboard_RightCtrl, (5,14) }, - { LedId.Keyboard_ArrowLeft, (5,15) }, - { LedId.Keyboard_ArrowDown, (5,16) }, - { LedId.Keyboard_ArrowRight, (5,17) }, - { LedId.Keyboard_Num0, (5,18) }, - { LedId.Keyboard_NumPeriodAndDelete, (5,20) } - }; - - /// - /// Contains all the hardware-id mappings for CoolerMaster devices. - /// - public static readonly Dictionary>> Mapping = - new Dictionary>> - { - { "", new Dictionary> - { - { AsusPhysicalKeyboardLayout.TODO, MasterKeysL_US } - } - }, - }; - } -} diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs index 46a7a21..ce44e12 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs @@ -1,4 +1,6 @@ -using AuraServiceLib; +using System.Collections.Generic; +using System.Linq; +using AuraServiceLib; using RGB.NET.Core; namespace RGB.NET.Devices.Asus @@ -23,33 +25,28 @@ namespace RGB.NET.Devices.Asus #endregion #region Methods - private ushort asusCode; + /// protected override void InitializeLayout() { - if (DeviceInfo.Device.Type != 0x00081001) + Dictionary reversedMapping = AsusKeyboardLedMapping.MAPPING.ToDictionary(x => x.Value, x => x.Key); + + if (DeviceInfo.Device.Type != (uint)AsusDeviceType.NB_KB_4ZONE_RGB) { int pos = 0; foreach (IAuraRgbKey key in ((IAuraSyncKeyboard)DeviceInfo.Device).Keys) - { - asusCode = key.Code; - InitializeLed(AsusLedIdMapper(key.Code), new Rectangle(pos++ * 19, 0, 19, 19)); - } + InitializeLed(reversedMapping[(AsusLedId)key.Code], new Point(pos++ * 19, 0), new Size(19, 19)); + //UK Layout - asusCode = 0x56; - InitializeLed(AsusLedIdMapper(asusCode), new Rectangle(pos++ * 19, 0, 19, 19)); - asusCode = 0x59; - InitializeLed(AsusLedIdMapper(asusCode), new Rectangle(pos++ * 19, 0, 19, 19)); + InitializeLed(reversedMapping[AsusLedId.KEY_OEM_102], new Point(pos++ * 19, 0), new Size(19, 19)); + + InitializeLed(reversedMapping[AsusLedId.UNDOCUMENTED_1], new Point(pos * 19, 0), new Size(19, 19)); } else { int ledCount = DeviceInfo.Device.Lights.Count; for (int i = 0; i < ledCount; i++) - { - asusCode = (ushort)i; - InitializeLed(LedId.Keyboard_Custom1 + i, new Rectangle(i * 19, 0, 19, 19)); - } - + InitializeLed(LedId.Keyboard_Custom1 + i, new Point(i * 19, 0), new Size(19, 19)); } string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); @@ -57,236 +54,14 @@ namespace RGB.NET.Devices.Asus } /// - protected override object CreateLedCustomData(LedId ledId) => asusCode; - - private LedId AsusLedIdMapper(ushort asusKey) + protected override object CreateLedCustomData(LedId ledId) { - switch (asusKey) - { - case 0x01: - return LedId.Keyboard_Escape; - case 0x3B: - return LedId.Keyboard_F1; - case 0x3C: - return LedId.Keyboard_F2; - case 0x3D: - return LedId.Keyboard_F3; - case 0x3E: - return LedId.Keyboard_F4; - case 0x3F: - return LedId.Keyboard_F5; - case 0x40: - return LedId.Keyboard_F6; - case 0x41: - return LedId.Keyboard_F7; - case 0x42: - return LedId.Keyboard_F8; - case 0x43: - return LedId.Keyboard_F9; - case 0x44: - return LedId.Keyboard_F10; - case 0x57: - return LedId.Keyboard_F11; - case 0x58: - return LedId.Keyboard_F12; - case 0x02: - return LedId.Keyboard_1; - case 0x03: - return LedId.Keyboard_2; - case 0x04: - return LedId.Keyboard_3; - case 0x05: - return LedId.Keyboard_4; - case 0x06: - return LedId.Keyboard_5; - case 0x07: - return LedId.Keyboard_6; - case 0x08: - return LedId.Keyboard_7; - case 0x09: - return LedId.Keyboard_8; - case 0x0A: - return LedId.Keyboard_9; - case 0x0B: - return LedId.Keyboard_0; - case 0x0C: - return LedId.Keyboard_MinusAndUnderscore; - case 0x0D: - return LedId.Keyboard_EqualsAndPlus; - case 0x0E: - return LedId.Keyboard_Backspace; - case 0x0F: - return LedId.Keyboard_Tab; - case 0x10: - return LedId.Keyboard_Q; - case 0x11: - return LedId.Keyboard_W; - case 0x12: - return LedId.Keyboard_E; - case 0x13: - return LedId.Keyboard_R; - case 0x14: - return LedId.Keyboard_T; - case 0x15: - return LedId.Keyboard_Y; - case 0x16: - return LedId.Keyboard_U; - case 0x17: - return LedId.Keyboard_I; - case 0x18: - return LedId.Keyboard_O; - case 0x19: - return LedId.Keyboard_P; - case 0x1A: - return LedId.Keyboard_BracketLeft; - case 0x1B: - return LedId.Keyboard_BracketRight; - case 0x1C: - return LedId.Keyboard_Enter; - case 0x3A: - return LedId.Keyboard_CapsLock; - case 0x1E: - return LedId.Keyboard_A; - case 0x1F: - return LedId.Keyboard_S; - case 0x20: - return LedId.Keyboard_D; - case 0x21: - return LedId.Keyboard_F; - case 0x22: - return LedId.Keyboard_G; - case 0x23: - return LedId.Keyboard_H; - case 0x24: - return LedId.Keyboard_J; - case 0x25: - return LedId.Keyboard_K; - case 0x26: - return LedId.Keyboard_L; - case 0x27: - return LedId.Keyboard_SemicolonAndColon; - case 0x28: - return LedId.Keyboard_ApostropheAndDoubleQuote; - case 0x29: - return LedId.Keyboard_GraveAccentAndTilde; - case 0x2A: - return LedId.Keyboard_LeftShift; - case 0x2B: - return LedId.Keyboard_Backslash; - case 0x2C: - return LedId.Keyboard_Z; - case 0x2D: - return LedId.Keyboard_X; - case 0x2E: - return LedId.Keyboard_C; - case 0x2F: - return LedId.Keyboard_V; - case 0x30: - return LedId.Keyboard_B; - case 0x31: - return LedId.Keyboard_N; - case 0x32: - return LedId.Keyboard_M; - case 0x33: - return LedId.Keyboard_CommaAndLessThan; - case 0x34: - return LedId.Keyboard_PeriodAndBiggerThan; - case 0x35: - return LedId.Keyboard_SlashAndQuestionMark; - case 0x36: - return LedId.Keyboard_RightShift; - case 0x1D: - return LedId.Keyboard_LeftCtrl; - case 0xDB: - return LedId.Keyboard_LeftGui; - case 0x38: - return LedId.Keyboard_LeftAlt; - case 0x39: - return LedId.Keyboard_Space; - case 0xB8: - return LedId.Keyboard_RightAlt; - case 0x100: - return LedId.Keyboard_RightGui; - case 0xDD: - return LedId.Keyboard_Application; - case 0x9D: - return LedId.Keyboard_RightCtrl; - case 0xB7: - return LedId.Keyboard_PrintScreen; - case 0x46: - return LedId.Keyboard_ScrollLock; - case 0xC5: - return LedId.Keyboard_PauseBreak; - case 0xD2: - return LedId.Keyboard_Insert; - case 0xC7: - return LedId.Keyboard_Home; - case 0xC9: - return LedId.Keyboard_PageUp; - case 0xD3: - return LedId.Keyboard_Delete; - case 0xCF: - return LedId.Keyboard_End; - case 0xD1: - return LedId.Keyboard_PageDown; - case 0xC8: - return LedId.Keyboard_ArrowUp; - case 0xCB: - return LedId.Keyboard_ArrowLeft; - case 0xD0: - return LedId.Keyboard_ArrowDown; - case 0xCD: - return LedId.Keyboard_ArrowRight; - case 0x45: - return LedId.Keyboard_NumLock; - case 0xB5: - return LedId.Keyboard_NumSlash; - case 0x37: - return LedId.Keyboard_NumAsterisk; - case 0x4A: - return LedId.Keyboard_NumMinus; - case 0x47: - return LedId.Keyboard_Num7; - case 0x48: - return LedId.Keyboard_Num8; - case 0x49: - return LedId.Keyboard_Num9; - case 0x53: - return LedId.Keyboard_NumPeriodAndDelete; - case 0x4E: - return LedId.Keyboard_NumPlus; - case 0x4B: - return LedId.Keyboard_Num4; - case 0x4C: - return LedId.Keyboard_Num5; - case 0x4D: - return LedId.Keyboard_Num6; - case 0x4F: - return LedId.Keyboard_Num1; - case 0x50: - return LedId.Keyboard_Num2; - case 0x51: - return LedId.Keyboard_Num3; - case 0x52: - return LedId.Keyboard_Num0; - case 0x9C: - return LedId.Keyboard_NumEnter; - case 0x59: - return LedId.Keyboard_NonUsBackslash; - case 0x56: - return LedId.Keyboard_NonUsTilde; - case 0xB3: - return LedId.Keyboard_NumComma; - case 0x101: - return LedId.Logo; - case 0x102: - return LedId.Keyboard_Custom1; - case 0x103: - return LedId.Keyboard_Custom2; - default: - return LedId.Invalid; - } + if (DeviceInfo.Device.Type == (uint)AsusDeviceType.NB_KB_4ZONE_RGB) + return ledId - LedId.Keyboard_Custom1; + + return AsusKeyboardLedMapping.MAPPING[ledId]; } + #endregion } } From 93eae1d859436a048c3e343cbbc55db85b69b746 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 12 Jul 2020 00:01:35 +0200 Subject: [PATCH 36/51] Updated copyright information --- RGB.NET.Brushes/RGB.NET.Brushes.csproj | 4 ++-- RGB.NET.Core/RGB.NET.Core.csproj | 4 ++-- RGB.NET.Decorators/RGB.NET.Decorators.csproj | 4 ++-- RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj | 4 ++-- .../RGB.NET.Devices.Asus_Legacy.csproj | 4 ++-- .../RGB.NET.Devices.CoolerMaster.csproj | 4 ++-- RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj | 4 ++-- RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj | 4 ++-- RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj | 4 ++-- RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj | 4 ++-- RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj | 4 ++-- RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj | 4 ++-- RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj | 4 ++-- RGB.NET.Devices.Roccat/RGB.NET.Devices.Roccat.csproj | 4 ++-- RGB.NET.Devices.SoIP/RGB.NET.Devices.SoIP.csproj | 4 ++-- .../RGB.NET.Devices.SteelSeries.csproj | 4 ++-- RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj | 4 ++-- RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj | 6 +++--- RGB.NET.Groups/RGB.NET.Groups.csproj | 4 ++-- 19 files changed, 39 insertions(+), 39 deletions(-) diff --git a/RGB.NET.Brushes/RGB.NET.Brushes.csproj b/RGB.NET.Brushes/RGB.NET.Brushes.csproj index 85e276f..d016193 100644 --- a/RGB.NET.Brushes/RGB.NET.Brushes.csproj +++ b/RGB.NET.Brushes/RGB.NET.Brushes.csproj @@ -14,8 +14,8 @@ RGB.NET.Brushes Brushes-Presets of RGB.NET Brushes-Presets of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj index d3f2d5b..6fab932 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj +++ b/RGB.NET.Core/RGB.NET.Core.csproj @@ -14,8 +14,8 @@ RGB.NET.Core Core-Module of RGB.NET Core-Module of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Decorators/RGB.NET.Decorators.csproj b/RGB.NET.Decorators/RGB.NET.Decorators.csproj index 1703f74..f76251d 100644 --- a/RGB.NET.Decorators/RGB.NET.Decorators.csproj +++ b/RGB.NET.Decorators/RGB.NET.Decorators.csproj @@ -14,8 +14,8 @@ RGB.NET.Decorators Decorators-Presets of RGB.NET Decorators-Presets of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj index fac923c..fb26c95 100644 --- a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj +++ b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.Asus Asus-Device-Implementations of RGB.NET Asus-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.Asus_Legacy/RGB.NET.Devices.Asus_Legacy.csproj b/RGB.NET.Devices.Asus_Legacy/RGB.NET.Devices.Asus_Legacy.csproj index fbfe63a..dacc703 100644 --- a/RGB.NET.Devices.Asus_Legacy/RGB.NET.Devices.Asus_Legacy.csproj +++ b/RGB.NET.Devices.Asus_Legacy/RGB.NET.Devices.Asus_Legacy.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.Asus Asus-Device-Implementations of RGB.NET based on the v2-SDK Asus-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj index c227751..aa5d87f 100644 --- a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj +++ b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.CoolerMaster Cooler Master-Device-Implementations of RGB.NET Cooler Master-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj index 0d023b4..e334b6b 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.Corsair Corsair-Device-Implementations of RGB.NET Corsair-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj index df61269..96c1089 100644 --- a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj +++ b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.DMX DMX-Device-Implementations of RGB.NET DMX-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj index 1974cea..0ad819b 100644 --- a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj +++ b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.Debug Debug-Device-Implementations of RGB.NET Debug-Device-Implementations of RGB.NET, a C# (.NET) library - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj index b387096..220b205 100644 --- a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj +++ b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.Logitech Logitech-Device-Implementations of RGB.NET Logitech-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj index 7050174..ba24290 100644 --- a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj +++ b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.Msi Msi-Device-Implementations of RGB.NET Msi-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj index cbcad32..abd09fa 100644 --- a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj +++ b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.Novation Novation-Device-Implementations of RGB.NET Novation-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj index 2bc40c0..7ed66a5 100644 --- a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj +++ b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.Razer Razer-Device-Implementations of RGB.NET Razer-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.Roccat/RGB.NET.Devices.Roccat.csproj b/RGB.NET.Devices.Roccat/RGB.NET.Devices.Roccat.csproj index 2671d40..f83e1c4 100644 --- a/RGB.NET.Devices.Roccat/RGB.NET.Devices.Roccat.csproj +++ b/RGB.NET.Devices.Roccat/RGB.NET.Devices.Roccat.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.Roccat Roccat-Device-Implementations of RGB.NET Roccat-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.SoIP/RGB.NET.Devices.SoIP.csproj b/RGB.NET.Devices.SoIP/RGB.NET.Devices.SoIP.csproj index 812ab70..0816d25 100644 --- a/RGB.NET.Devices.SoIP/RGB.NET.Devices.SoIP.csproj +++ b/RGB.NET.Devices.SoIP/RGB.NET.Devices.SoIP.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.SoIP SoIP-Device-Implementations of RGB.NET SoIP-Device-Implementations of RGB.NET, a C# (.NET) library - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj index f48998b..bf4b1e5 100644 --- a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj +++ b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.SteelSeries SteelSeries-Device-Implementations of RGB.NET SteelSeries-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj index cbbc0cb..d2ce907 100644 --- a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj +++ b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj @@ -14,8 +14,8 @@ RGB.NET.Devices.WS281X WS281X-Device-Implementations of RGB.NET WS281X-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2018 - Copyright © Wyrez 2018 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE diff --git a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj index 946705a..4efa935 100644 --- a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj +++ b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj @@ -14,14 +14,14 @@ RGB.NET.Devices.Wooting Wooting-Device-Implementations of RGB.NET Wooting-Device-Implementations of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE Github https://github.com/DarthAffe/RGB.NET - False + True diff --git a/RGB.NET.Groups/RGB.NET.Groups.csproj b/RGB.NET.Groups/RGB.NET.Groups.csproj index 4aa5532..59c8c35 100644 --- a/RGB.NET.Groups/RGB.NET.Groups.csproj +++ b/RGB.NET.Groups/RGB.NET.Groups.csproj @@ -14,8 +14,8 @@ RGB.NET.Groups Group-Presets of RGB.NET Group-Presets of RGB.NET, a C# (.NET) library for accessing various RGB-peripherals - Copyright © Wyrez 2017 - Copyright © Wyrez 2017 + Copyright © Darth Affe 2020 + Copyright © Darth Affe 2020 http://lib.arge.be/icon.png https://github.com/DarthAffe/RGB.NET https://raw.githubusercontent.com/DarthAffe/RGB.NET/master/LICENSE From 7c6db8738c58c11777cc4fe105f83c6a74d04db2 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 12 Jul 2020 16:06:54 +0200 Subject: [PATCH 37/51] Added device-provider for NodeMCU based WS281X-leds --- .../NodeMCU/NodeMCUWS2812USBDevice.cs | 87 ++++++++ .../NodeMCU/NodeMCUWS2812USBDeviceInfo.cs | 51 +++++ .../NodeMCU/NodeMCUWS2812USBUpdateQueue.cs | 106 +++++++++ .../NodeMCU/NodeMCUWS281XDeviceDefinition.cs | 71 ++++++ .../Sketches/RGB.NET_udp.ino | 210 ++++++++++++++++++ 5 files changed, 525 insertions(+) create mode 100644 RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs create mode 100644 RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs create mode 100644 RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs create mode 100644 RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs create mode 100644 RGB.NET.Devices.WS281X/Sketches/RGB.NET_udp.ino diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs new file mode 100644 index 0000000..4b03b81 --- /dev/null +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs @@ -0,0 +1,87 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global + +using System.Collections.Generic; +using System.Linq; +using RGB.NET.Core; + +namespace RGB.NET.Devices.WS281X.NodeMCU +{ + // ReSharper disable once InconsistentNaming + /// + /// + /// Represents an NodeMCU WS2812 device. + /// + public class NodeMCUWS2812USBDevice : AbstractRGBDevice, ILedStripe + { + #region Properties & Fields + + /// + /// Gets the update queue performing updates for this device. + /// + public NodeMCUWS2812USBUpdateQueue UpdateQueue { get; } + + /// + public override NodeMCUWS2812USBDeviceInfo DeviceInfo { get; } + + /// + /// Gets the channel (as defined in the NodeMCU-sketch) this device is attached to. + /// + public int Channel { get; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The update trigger used by this queue. + /// The update queue performing updates for this device. + /// The channel (as defined in the NodeMCU-sketch) this device is attached to. + public NodeMCUWS2812USBDevice(NodeMCUWS2812USBDeviceInfo deviceInfo, NodeMCUWS2812USBUpdateQueue updateQueue, int channel) + { + this.DeviceInfo = deviceInfo; + this.UpdateQueue = updateQueue; + this.Channel = channel; + } + + #endregion + + #region Methods + + internal void Initialize(int ledCount) + { + for (int i = 0; i < ledCount; i++) + InitializeLed(LedId.LedStripe1 + i, new Point(i * 10, 0), new Size(10, 10)); + + //TODO DarthAffe 23.12.2018: Allow to load a layout. + + if (Size == Size.Invalid) + { + Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle)); + Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y); + } + } + + /// + protected override object CreateLedCustomData(LedId ledId) => (Channel, (int)ledId - (int)LedId.LedStripe1); + + /// + protected override IEnumerable GetLedsToUpdate(bool flushLeds) => (flushLeds || LedMapping.Values.Any(x => x.IsDirty)) ? LedMapping.Values : null; + + /// + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + + /// + public override void Dispose() + { + try { UpdateQueue?.Dispose(); } + catch { /* at least we tried */ } + + base.Dispose(); + } + + #endregion + } +} diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs new file mode 100644 index 0000000..916f516 --- /dev/null +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs @@ -0,0 +1,51 @@ +using System; +using RGB.NET.Core; + +namespace RGB.NET.Devices.WS281X.NodeMCU +{ + // ReSharper disable once InconsistentNaming + /// + /// + /// Represents a generic information for a . + /// + public class NodeMCUWS2812USBDeviceInfo : IRGBDeviceInfo + { + #region Properties & Fields + + /// + public string DeviceName { get; } + + /// + public RGBDeviceType DeviceType => RGBDeviceType.LedStripe; + + /// + public string Manufacturer => "NodeMCU"; + + /// + public string Model => "WS2812 WLAN"; + + /// + public RGBDeviceLighting Lighting => RGBDeviceLighting.Key; + + /// + public bool SupportsSyncBack => false; + + /// + public Uri Image { get; set; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The name of this device. + public NodeMCUWS2812USBDeviceInfo(string name) + { + this.DeviceName = name; + } + + #endregion + } +} diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs new file mode 100644 index 0000000..cb4424e --- /dev/null +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs @@ -0,0 +1,106 @@ +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using RGB.NET.Core; + +namespace RGB.NET.Devices.WS281X.NodeMCU +{ + // ReSharper disable once InconsistentNaming + /// + /// + /// Represents the update-queue performing updates for NodeMCU WS2812 devices. + /// + public class NodeMCUWS2812USBUpdateQueue : UpdateQueue + { + #region Constants + + private static readonly byte UPDATE_COMMAND = 0x02; + + #endregion + + #region Properties & Fields + + private readonly string _hostname; + + private readonly UdpClient _udpClient; + private readonly Dictionary _dataBuffer = new Dictionary(); + private readonly Dictionary _sequenceNumbers = new Dictionary(); + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The update trigger used by this queue. + /// The hostname to connect to. + /// The port used by the web-connection. + public NodeMCUWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, string hostname, int port) + : base(updateTrigger) + { + this._hostname = hostname; + + _udpClient = new UdpClient(_hostname, port); + _udpClient.Connect(_hostname, port); + } + + #endregion + + #region Methods + + /// + protected override void Update(Dictionary dataSet) + { + foreach (IGrouping channelData in dataSet.Select(x => (((int channel, int key))x.Key, x.Value)) + .GroupBy(x => x.Item1.channel)) + { + int channel = channelData.Key; + byte[] buffer = _dataBuffer[channel]; + + buffer[0] = GetSequenceNumber(channel); + buffer[1] = (byte)((channel << 4) | UPDATE_COMMAND); + int i = 2; + foreach ((byte _, byte r, byte g, byte b) in channelData.OrderBy(x => x.Item1.key) + .Select(x => x.Value.GetRGBBytes())) + { + buffer[i++] = r; + buffer[i++] = g; + buffer[i++] = b; + } + + Send(buffer); + } + } + + internal IEnumerable<(int channel, int ledCount)> GetChannels() + { + WebClient webClient = new WebClient(); + webClient.DownloadString($"http://{_hostname}/reset"); + + int channelCount = int.Parse(webClient.DownloadString($"http://{_hostname}/channels")); + for (int channel = 1; channel <= channelCount; channel++) + { + int ledCount = int.Parse(webClient.DownloadString($"http://{_hostname}/channel/{channel}")); + if (ledCount > 0) + { + _dataBuffer[channel] = new byte[(ledCount * 3) + 2]; + _sequenceNumbers[channel] = 0; + yield return (channel, ledCount); + } + } + } + + private void Send(byte[] data) => _udpClient.Send(data, data.Length); + + private byte GetSequenceNumber(int channel) + { + byte sequenceNumber = (byte)((_sequenceNumbers[channel] + 1) % byte.MaxValue); + _sequenceNumbers[channel] = sequenceNumber; + return sequenceNumber; + } + + #endregion + } +} diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs new file mode 100644 index 0000000..14d5a05 --- /dev/null +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs @@ -0,0 +1,71 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedMember.Global +// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global + +using System.Collections.Generic; +using RGB.NET.Core; + +namespace RGB.NET.Devices.WS281X.NodeMCU +{ + // ReSharper disable once InconsistentNaming + /// + /// + /// Represents a definition of an NodeMCU WS2812 devices. + /// + public class NodeMCUWS281XDeviceDefinition : IWS281XDeviceDefinition + { + #region Properties & Fields + + /// + /// Gets the hostname to connect to. + /// + public string Hostname { get; } + + /// + /// Gets the port of the UDP connection. + /// + public int Port { get; } + + /// + /// Gets or sets the name used by this device. + /// This allows to use {0} as a placeholder for a incrementing number if multiple devices are created. + /// + public string Name { get; set; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The hostname to connect to. + /// The port of the UDP connection. + public NodeMCUWS281XDeviceDefinition(string hostname, int port = 1872) + { + this.Hostname = hostname; + this.Port = port; + } + + #endregion + + #region Methods + + /// + public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger) + { + NodeMCUWS2812USBUpdateQueue queue = new NodeMCUWS2812USBUpdateQueue(updateTrigger, Hostname, Port); + IEnumerable<(int channel, int ledCount)> channels = queue.GetChannels(); + int counter = 0; + foreach ((int channel, int ledCount) in channels) + { + string name = string.Format(Name ?? $"NodeMCU WS2812 WIFI ({Hostname}) [{{0}}]", ++counter); + NodeMCUWS2812USBDevice device = new NodeMCUWS2812USBDevice(new NodeMCUWS2812USBDeviceInfo(name), queue, channel); + device.Initialize(ledCount); + yield return device; + } + } + + #endregion + } +} diff --git a/RGB.NET.Devices.WS281X/Sketches/RGB.NET_udp.ino b/RGB.NET.Devices.WS281X/Sketches/RGB.NET_udp.ino new file mode 100644 index 0000000..91f03d2 --- /dev/null +++ b/RGB.NET.Devices.WS281X/Sketches/RGB.NET_udp.ino @@ -0,0 +1,210 @@ +#define FASTLED_ESP8266_RAW_PIN_ORDER + +#include "FastLED.h" +#include +#include + +//#### CONFIGURATION #### + +// WLAN settings +const char* ssid = ""; // WLAN-network-name +const char* password = ""; // WLAN-password + +#define CHANNELS 4 // change this only if you add or remove channels in the implementation-part. To disable channels set them to 0 leds. + +// should not exceed 168 leds, since that results in the maximum paket size that is safe to transmit. Everything above could potentially be dropped. +// no more than 255 leds per channel (hard limit) +#define LEDS_CHANNEL_1 3 +#define LEDS_CHANNEL_2 0 +#define LEDS_CHANNEL_3 0 +#define LEDS_CHANNEL_4 0 + +#define PIN_CHANNEL_1 15 // D8 +#define PIN_CHANNEL_2 13 // D7 +#define PIN_CHANNEL_3 12 // D6 +#define PIN_CHANNEL_4 14 // D5 + +#define PORT 1872 // if changed needs to be configured in RGB.NET (default: 1872) + +#define WEBSERVER_PORT 80 + +//####################### + +CRGB leds_channel_1[LEDS_CHANNEL_1]; +CRGB leds_channel_2[LEDS_CHANNEL_2]; +CRGB leds_channel_3[LEDS_CHANNEL_3]; +CRGB leds_channel_4[LEDS_CHANNEL_4]; + +WiFiServer server(WEBSERVER_PORT); +WiFiUDP Udp; + +byte incomingPacket[767]; // 255 (max leds) * 3 + 2 (header) +byte lastSequenceNumbers[CHANNELS]; + +String header; + +void setup() { + if(LEDS_CHANNEL_1 > 0) { FastLED.addLeds(leds_channel_1, LEDS_CHANNEL_1); } + if(LEDS_CHANNEL_2 > 0) { FastLED.addLeds(leds_channel_2, LEDS_CHANNEL_2); } + if(LEDS_CHANNEL_3 > 0) { FastLED.addLeds(leds_channel_3, LEDS_CHANNEL_3); } + if(LEDS_CHANNEL_4 > 0) { FastLED.addLeds(leds_channel_4, LEDS_CHANNEL_4); } + + for(int i = 0; i < CHANNELS; i++) + { + lastSequenceNumbers[i] = 255; + } + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) + { + delay(500); + } + delay(100); + + Udp.begin(PORT); + server.begin(); +} + +bool checkSequenceNumber(int channel, byte currentSequenceNumber) +{ + bool isValid = (currentSequenceNumber > lastSequenceNumbers[channel]) || ((lastSequenceNumbers[channel] > 200) && (currentSequenceNumber < 50)); + if(isValid) + { + lastSequenceNumbers[channel] = currentSequenceNumber; + } + return isValid; +} + +void loop() { + // Web client + WiFiClient client = server.available(); + if (client) + { + String currentLine = ""; + while (client.connected()) + { + if (client.available()) + { + char c = client.read(); + header += c; + if (c == '\n') { + if (currentLine.length() == 0) { + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println("Connection: close"); + client.println(); + + if (header.indexOf("GET /reset") >= 0) + { + for(int i = 0; i < CHANNELS; i++) + { + lastSequenceNumbers[i] = 255; + } + for(int i = 0; i < LEDS_CHANNEL_1; i++) + { + leds_channel_1[i] = CRGB::Black; + } + for(int i = 0; i < LEDS_CHANNEL_2; i++) + { + leds_channel_2[i] = CRGB::Black; + } + for(int i = 0; i < LEDS_CHANNEL_3; i++) + { + leds_channel_3[i] = CRGB::Black; + } + for(int i = 0; i < LEDS_CHANNEL_4; i++) + { + leds_channel_4[i] = CRGB::Black; + } + FastLED.show(); + } + else if (header.indexOf("GET /channels") >= 0) + { + client.println(CHANNELS); + } + else if (header.indexOf("GET /channel/1") >= 0) + { + client.println(LEDS_CHANNEL_1); + } + else if (header.indexOf("GET /channel/2") >= 0) + { + client.println(LEDS_CHANNEL_2); + } + else if (header.indexOf("GET /channel/3") >= 0) + { + client.println(LEDS_CHANNEL_3); + } + else if (header.indexOf("GET /channel/4") >= 0) + { + client.println(LEDS_CHANNEL_4); + } + client.println(); + + break; + } + else + { + currentLine = ""; + } + } + else if (c != '\r') + { + currentLine += c; + } + } + } + header = ""; + client.stop(); + } + + // Color update + int packetSize = Udp.parsePacket(); + if (packetSize) + { + // receive incoming UDP packets + byte sequenceNumber = Udp.read(); + byte command = Udp.read(); + switch(command) + { + // ### channel 1 ### + case 0x12: // set leds of channel 1 + if(checkSequenceNumber(0, sequenceNumber)) + { + Udp.read(((uint8_t*)leds_channel_1), (LEDS_CHANNEL_1 * 3)); + FastLED.show(); + } + break; + + // ### channel 2 ### + case 0x22: // set leds of channel 2 + if(checkSequenceNumber(1, sequenceNumber)) + { + Udp.read(((uint8_t*)leds_channel_2), (LEDS_CHANNEL_2 * 3)); + FastLED.show(); + } + break; + + // ### channel 3 ### + case 0x32: // set leds of channel 3 + if(checkSequenceNumber(2, sequenceNumber)) + { + Udp.read(((uint8_t*)leds_channel_3), (LEDS_CHANNEL_3 * 3)); + FastLED.show(); + } + break; + + // ### channel 4 ### + case 0x42: // set leds of channel 4 + if(checkSequenceNumber(3, sequenceNumber)) + { + Udp.read(((uint8_t*)leds_channel_4), (LEDS_CHANNEL_4 * 3)); + FastLED.show(); + } + break; + + // ### default ### + default: + break; + } + } +} From dd5fb6db890f30e214f29625f8e1c42604f8caaf Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 13 Jul 2020 23:42:07 +0200 Subject: [PATCH 38/51] Changed UpdateQueue.Dispose to be virtual --- RGB.NET.Core/Update/Devices/UpdateQueue.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index 05aff8d..da5c82c 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -100,7 +100,8 @@ namespace RGB.NET.Core _currentDataSet = null; } - public void Dispose() + /// + public virtual void Dispose() { _updateTrigger.Starting -= OnStartup; _updateTrigger.Update -= OnUpdate; From b8a3593792761ca74f43613af1647bb6d33603f2 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 13 Jul 2020 23:52:08 +0200 Subject: [PATCH 39/51] Added a REST-API to NodeMCU devices and added using it as an optional update-mode --- .../NodeMCU/NodeMCUUpdateMode.cs | 21 ++ .../NodeMCU/NodeMCUWS2812USBUpdateQueue.cs | 154 ++++++--- .../NodeMCU/NodeMCUWS281XDeviceDefinition.cs | 24 +- .../RGB.NET.Devices.WS281X.csproj | 1 + .../Sketches/RGB.NET_NodeMCU.ino | 295 ++++++++++++++++++ .../Sketches/RGB.NET_udp.ino | 210 ------------- .../WS281XDeviceProvider.cs | 7 +- 7 files changed, 457 insertions(+), 255 deletions(-) create mode 100644 RGB.NET.Devices.WS281X/NodeMCU/NodeMCUUpdateMode.cs create mode 100644 RGB.NET.Devices.WS281X/Sketches/RGB.NET_NodeMCU.ino delete mode 100644 RGB.NET.Devices.WS281X/Sketches/RGB.NET_udp.ino diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUUpdateMode.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUUpdateMode.cs new file mode 100644 index 0000000..f20bd8e --- /dev/null +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUUpdateMode.cs @@ -0,0 +1,21 @@ +namespace RGB.NET.Devices.WS281X.NodeMCU +{ + /// + /// Contaisn a list of possible update-modes for NodeMCU-devices. + /// + // ReSharper disable once InconsistentNaming + public enum NodeMCUUpdateMode + { + /// + /// Updates through the HTTP-REST-API. + /// Slow, but reliable. + /// + Http, + + /// + /// Updates through a UDP-connection. + /// Fast, but might skip updates if the network connection is bad. + /// + Udp + } +} diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs index cb4424e..f5feffe 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBUpdateQueue.cs @@ -1,7 +1,10 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; -using System.Net; +using System.Net.Http; using System.Net.Sockets; +using System.Text; +using System.Text.RegularExpressions; using RGB.NET.Core; namespace RGB.NET.Devices.WS281X.NodeMCU @@ -13,94 +16,169 @@ namespace RGB.NET.Devices.WS281X.NodeMCU /// public class NodeMCUWS2812USBUpdateQueue : UpdateQueue { - #region Constants - - private static readonly byte UPDATE_COMMAND = 0x02; - - #endregion - #region Properties & Fields private readonly string _hostname; - private readonly UdpClient _udpClient; + private HttpClient _httpClient = new HttpClient(); + private UdpClient _udpClient; + private readonly Dictionary _dataBuffer = new Dictionary(); private readonly Dictionary _sequenceNumbers = new Dictionary(); + private readonly Action _sendDataAction; + #endregion #region Constructors /// /// Initializes a new instance of the class. + /// If this constructor is used UDP updates are disabled. /// /// The update trigger used by this queue. /// The hostname to connect to. - /// The port used by the web-connection. - public NodeMCUWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, string hostname, int port) + public NodeMCUWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, string hostname) : base(updateTrigger) { this._hostname = hostname; - _udpClient = new UdpClient(_hostname, port); - _udpClient.Connect(_hostname, port); + _sendDataAction = SendHttp; + } + + /// + /// Initializes a new instance of the class. + /// If this constructor is used UDP updates are enabled. + /// + /// The update trigger used by this queue. + /// The hostname to connect to. + /// The port used by the UDP-connection. + public NodeMCUWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, string hostname, int udpPort) + : base(updateTrigger) + { + this._hostname = hostname; + + _udpClient = new UdpClient(); + EnableUdp(udpPort); + + _sendDataAction = SendUdp; } #endregion #region Methods + /// + protected override void OnStartup(object sender, CustomUpdateData customData) + { + base.OnStartup(sender, customData); + + ResetDevice(); + } + /// protected override void Update(Dictionary dataSet) { foreach (IGrouping channelData in dataSet.Select(x => (((int channel, int key))x.Key, x.Value)) .GroupBy(x => x.Item1.channel)) { - int channel = channelData.Key; - byte[] buffer = _dataBuffer[channel]; - - buffer[0] = GetSequenceNumber(channel); - buffer[1] = (byte)((channel << 4) | UPDATE_COMMAND); - int i = 2; - foreach ((byte _, byte r, byte g, byte b) in channelData.OrderBy(x => x.Item1.key) - .Select(x => x.Value.GetRGBBytes())) - { - buffer[i++] = r; - buffer[i++] = g; - buffer[i++] = b; - } - - Send(buffer); + byte[] buffer = GetBuffer(channelData); + _sendDataAction(buffer); } } + private void SendHttp(byte[] buffer) + { + string data = Convert.ToBase64String(buffer); + lock (_httpClient) _httpClient?.PostAsync(GetUrl("update"), new StringContent(data, Encoding.ASCII)).Wait(); + } + + private void SendUdp(byte[] buffer) + { + _udpClient?.Send(buffer, buffer.Length); + } + + private byte[] GetBuffer(IGrouping data) + { + int channel = data.Key; + byte[] buffer = _dataBuffer[channel]; + + buffer[0] = GetSequenceNumber(channel); + buffer[1] = (byte)channel; + int i = 2; + foreach ((byte _, byte r, byte g, byte b) in data.OrderBy(x => x.Item1.key) + .Select(x => x.Value.GetRGBBytes())) + { + buffer[i++] = r; + buffer[i++] = g; + buffer[i++] = b; + } + + return buffer; + } + internal IEnumerable<(int channel, int ledCount)> GetChannels() { - WebClient webClient = new WebClient(); - webClient.DownloadString($"http://{_hostname}/reset"); + string configString; + lock (_httpClient) configString = _httpClient.GetStringAsync(GetUrl("config")).Result; - int channelCount = int.Parse(webClient.DownloadString($"http://{_hostname}/channels")); - for (int channel = 1; channel <= channelCount; channel++) + configString = configString.Replace(" ", "") + .Replace("\r", "") + .Replace("\n", ""); + + //HACK DarthAffe 13.07.2020: Adding a JSON-Parser dependency just for this is not really worth it right now ... + MatchCollection channelMatches = Regex.Matches(configString, "\\{\"channel\":(?\\d+),\"leds\":(?\\d+)\\}"); + foreach (Match channelMatch in channelMatches) { - int ledCount = int.Parse(webClient.DownloadString($"http://{_hostname}/channel/{channel}")); - if (ledCount > 0) + int channel = int.Parse(channelMatch.Groups["channel"].Value); + int leds = int.Parse(channelMatch.Groups["leds"].Value); + if (leds > 0) { - _dataBuffer[channel] = new byte[(ledCount * 3) + 2]; + _dataBuffer[channel] = new byte[(leds * 3) + 2]; _sequenceNumbers[channel] = 0; - yield return (channel, ledCount); + yield return (channel, leds); } } } - private void Send(byte[] data) => _udpClient.Send(data, data.Length); + internal void ResetDevice() + { + lock (_httpClient) _httpClient.GetStringAsync(GetUrl("reset")).Wait(); + } + + private void EnableUdp(int port) + { + _httpClient.PostAsync(GetUrl("enableUDP"), new StringContent(port.ToString(), Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Wait(); + _udpClient.Connect(_hostname, port); + } private byte GetSequenceNumber(int channel) { - byte sequenceNumber = (byte)((_sequenceNumbers[channel] + 1) % byte.MaxValue); + byte sequenceNumber = (byte)Math.Max(1, (_sequenceNumbers[channel] + 1) % byte.MaxValue); _sequenceNumbers[channel] = sequenceNumber; return sequenceNumber; } + /// + public override void Dispose() + { + lock (_httpClient) + { + base.Dispose(); + +#if NETSTANDARD + _udpClient?.Dispose(); +#endif + _udpClient = null; + + ResetDevice(); + _httpClient.Dispose(); + _httpClient = null; + } + } + + private string GetUrl(string path) => $"http://{_hostname}/{path}"; + #endregion } } diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs index 14d5a05..f573eab 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS281XDeviceDefinition.cs @@ -2,6 +2,7 @@ // ReSharper disable UnusedMember.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global +using System; using System.Collections.Generic; using RGB.NET.Core; @@ -22,9 +23,14 @@ namespace RGB.NET.Devices.WS281X.NodeMCU public string Hostname { get; } /// - /// Gets the port of the UDP connection. + /// Gets or sets the port of the UDP connection. /// - public int Port { get; } + public int Port { get; set; } = 1872; + + /// + /// Gets or sets the update-mode of the device. + /// + public NodeMCUUpdateMode UpdateMode { get; set; } /// /// Gets or sets the name used by this device. @@ -40,11 +46,11 @@ namespace RGB.NET.Devices.WS281X.NodeMCU /// Initializes a new instance of the class. /// /// The hostname to connect to. - /// The port of the UDP connection. - public NodeMCUWS281XDeviceDefinition(string hostname, int port = 1872) + /// The update mode of the device. + public NodeMCUWS281XDeviceDefinition(string hostname, NodeMCUUpdateMode updateMode = NodeMCUUpdateMode.Udp) { this.Hostname = hostname; - this.Port = port; + this.UpdateMode = updateMode; } #endregion @@ -54,7 +60,13 @@ namespace RGB.NET.Devices.WS281X.NodeMCU /// public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger) { - NodeMCUWS2812USBUpdateQueue queue = new NodeMCUWS2812USBUpdateQueue(updateTrigger, Hostname, Port); + NodeMCUWS2812USBUpdateQueue queue = UpdateMode switch + { + NodeMCUUpdateMode.Http => new NodeMCUWS2812USBUpdateQueue(updateTrigger, Hostname), + NodeMCUUpdateMode.Udp => new NodeMCUWS2812USBUpdateQueue(updateTrigger, Hostname, Port), + _ => throw new ArgumentOutOfRangeException() + }; + IEnumerable<(int channel, int ledCount)> channels = queue.GetChannels(); int counter = 0; foreach ((int channel, int ledCount) in channels) diff --git a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj index d2ce907..c8a987d 100644 --- a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj +++ b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj @@ -64,6 +64,7 @@ + diff --git a/RGB.NET.Devices.WS281X/Sketches/RGB.NET_NodeMCU.ino b/RGB.NET.Devices.WS281X/Sketches/RGB.NET_NodeMCU.ino new file mode 100644 index 0000000..dc28c66 --- /dev/null +++ b/RGB.NET.Devices.WS281X/Sketches/RGB.NET_NodeMCU.ino @@ -0,0 +1,295 @@ +#define FASTLED_ESP8266_RAW_PIN_ORDER + +#include "FastLED.h" +#include +#include +#include +#include "base64.hpp" + +//#### CONFIGURATION #### + +// WLAN settings +const char* ssid = ""; // WLAN-network-name +const char* password = ""; // WLAN-password + +#define CHANNELS 4 // change this only if you add or remove channels in the implementation-part. To disable channels set them to 0 leds. + +// should not exceed 168 leds, since that results in the maximum paket size that is safe to transmit. Everything above could potentially be dropped. +// no more than 255 leds per channel (hard limit) +#define LEDS_CHANNEL_1 3 +#define LEDS_CHANNEL_2 0 +#define LEDS_CHANNEL_3 0 +#define LEDS_CHANNEL_4 0 + +#define PIN_CHANNEL_1 15 // D8 +#define PIN_CHANNEL_2 13 // D7 +#define PIN_CHANNEL_3 12 // D6 +#define PIN_CHANNEL_4 14 // D5 + +#define WEBSERVER_PORT 80 + +//####################### + +CRGB leds_channel_1[LEDS_CHANNEL_1]; +CRGB leds_channel_2[LEDS_CHANNEL_2]; +CRGB leds_channel_3[LEDS_CHANNEL_3]; +CRGB leds_channel_4[LEDS_CHANNEL_4]; + +ESP8266WebServer server(80); +WiFiUDP Udp; + +bool isUDPEnabled; +int udpPort; +byte incomingPacket[767]; // 255 (max leds) * 3 + 2 (header) +byte lastSequenceNumbers[CHANNELS]; + +bool checkSequenceNumber(int channel, byte currentSequenceNumber) +{ + bool isValid = (currentSequenceNumber > lastSequenceNumbers[channel]) || ((lastSequenceNumbers[channel] > 200) && (currentSequenceNumber < 50)); + if(isValid) + { + lastSequenceNumbers[channel] = currentSequenceNumber; + } + return isValid; +} + +void processUDP() +{ + int packetSize = Udp.parsePacket(); + if (packetSize) + { + // receive incoming UDP packets + byte sequenceNumber = Udp.read(); + byte channel = Udp.read(); + if(checkSequenceNumber(channel, sequenceNumber)) + { + switch(channel) + { + case 1: // set leds of channel 1 + Udp.read((uint8_t*)leds_channel_1, (LEDS_CHANNEL_1 * 3)); + FastLED.show(); + break; + + // ### channel 2 ### + case 2: // set leds of channel 2 + Udp.read((uint8_t*)leds_channel_2, (LEDS_CHANNEL_2 * 3)); + FastLED.show(); + break; + + // ### channel 3 ### + case 3: // set leds of channel 3 + Udp.read((uint8_t*)leds_channel_3, (LEDS_CHANNEL_3 * 3)); + FastLED.show(); + break; + + // ### channel 4 ### + case 4: // set leds of channel 4 + Udp.read((uint8_t*)leds_channel_4, (LEDS_CHANNEL_4 * 3)); + FastLED.show(); + break; + + // ### default ### + default: + break; + } + } + } +} + +void handleRoot() +{ + String infoSite = (String)"\ + \ + RGB.NET\ + \ + \ +

RGB.NET

\ + This device is currently running the NodeMCU WS281X RGB.NET-Sketch.
\ +
\ + Check https://github.com/DarthAffe/RGB.NET for more info and the latest version of this sketch.
\ +
\ +

Configuration:

\ + UDP:\ " + (isUDPEnabled ? ((String)"enabled (" + udpPort + ")") : "disabled") + "
\ +
\ + Channel 1
\ + Leds: " + LEDS_CHANNEL_1 + "
\ + Pin: " + PIN_CHANNEL_1 + "
\ +
\ + Channel 2
\ + Leds: " + LEDS_CHANNEL_2 + "
\ + Pin: " + PIN_CHANNEL_2 + "
\ +
\ + Channel 4
\ + Leds: " + LEDS_CHANNEL_3 + "
\ + Pin: " + PIN_CHANNEL_3 + "
\ +
\ + Channel 4
\ + Leds: " + LEDS_CHANNEL_4 + "
\ + Pin: " + PIN_CHANNEL_4 + "
\ +
\ + \ +"; + + server.send(200, "text/html", infoSite); +} + +void handleConfig() +{ + String config = (String)"{\ + \"channels\": [\ + {\ + \"channel\": 1,\ + \"leds\": " + LEDS_CHANNEL_1 + "\ + },\ + {\ + \"channel\": 2,\ + \"leds\": " + LEDS_CHANNEL_2 + "\ + },\ + {\ + \"channel\": 3,\ + \"leds\": " + LEDS_CHANNEL_3 + "\ + },\ + {\ + \"channel\": 4,\ + \"leds\": " + LEDS_CHANNEL_4 + "\ + }\ + ]\ +}"; + + server.send(200, "application/json", config); +} + +void handleEnableUDP() +{ + if(isUDPEnabled) + { + Udp.stop(); + } + + udpPort = server.arg(0).toInt(); + + Udp.begin(udpPort); + isUDPEnabled = true; + + server.send(200, "text/html", ""); +} + +void handleDisableUDP() +{ + if(isUDPEnabled) + { + Udp.stop(); + isUDPEnabled = false; + } + + server.send(200, "text/html", ""); +} + +void handleReset() +{ + for(int i = 0; i < CHANNELS; i++) + { + lastSequenceNumbers[i] = 0; + } + + for(int i = 0; i < LEDS_CHANNEL_1; i++) + { + leds_channel_1[i] = CRGB::Black; + } + + for(int i = 0; i < LEDS_CHANNEL_2; i++) + { + leds_channel_2[i] = CRGB::Black; + } + + for(int i = 0; i < LEDS_CHANNEL_3; i++) + { + leds_channel_3[i] = CRGB::Black; + } + + for(int i = 0; i < LEDS_CHANNEL_4; i++) + { + leds_channel_4[i] = CRGB::Black; + } + + FastLED.show(); + + server.send(200, "text/html", ""); +} + +void handleUpdate() +{ + unsigned int dataLength = decode_base64((unsigned char*)server.arg(0).c_str(), incomingPacket); + + byte channel = (byte)incomingPacket[1]; + switch(channel) + { + case 1: // set leds of channel 1 + memcpy((uint8_t*)leds_channel_1, &incomingPacket[2], (LEDS_CHANNEL_1 * 3)); + FastLED.show(); + break; + + // ### channel 2 ### + case 2: // set leds of channel 2 + memcpy((uint8_t*)leds_channel_2, &incomingPacket[2], (LEDS_CHANNEL_2 * 3)); + FastLED.show(); + break; + + // ### channel 3 ### + case 3: // set leds of channel 3 + memcpy((uint8_t*)leds_channel_3, &incomingPacket[2], (LEDS_CHANNEL_3 * 3)); + FastLED.show(); + break; + + // ### channel 4 ### + case 4: // set leds of channel 4 + memcpy((uint8_t*)leds_channel_4, &incomingPacket[2], (LEDS_CHANNEL_4 * 3)); + FastLED.show(); + break; + + // ### default ### + default: + break; + } + + server.send(200, "text/html", ""); +} + +void setup() +{ + if(LEDS_CHANNEL_1 > 0) { FastLED.addLeds(leds_channel_1, LEDS_CHANNEL_1); } + if(LEDS_CHANNEL_2 > 0) { FastLED.addLeds(leds_channel_2, LEDS_CHANNEL_2); } + if(LEDS_CHANNEL_3 > 0) { FastLED.addLeds(leds_channel_3, LEDS_CHANNEL_3); } + if(LEDS_CHANNEL_4 > 0) { FastLED.addLeds(leds_channel_4, LEDS_CHANNEL_4); } + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) + { + delay(500); + } + + delay(100); + + server.on("/", handleRoot); + server.on("/config", handleConfig); + server.on("/enableUDP", handleEnableUDP); + server.on("/disableUDP", handleDisableUDP); + server.on("/reset", handleReset); + server.on("/update", handleUpdate); + server.onNotFound(handleRoot); + + server.begin(); + + handleReset(); +} + +void loop() +{ + server.handleClient(); + + if(isUDPEnabled) + { + processUDP(); + } +} + \ No newline at end of file diff --git a/RGB.NET.Devices.WS281X/Sketches/RGB.NET_udp.ino b/RGB.NET.Devices.WS281X/Sketches/RGB.NET_udp.ino deleted file mode 100644 index 91f03d2..0000000 --- a/RGB.NET.Devices.WS281X/Sketches/RGB.NET_udp.ino +++ /dev/null @@ -1,210 +0,0 @@ -#define FASTLED_ESP8266_RAW_PIN_ORDER - -#include "FastLED.h" -#include -#include - -//#### CONFIGURATION #### - -// WLAN settings -const char* ssid = ""; // WLAN-network-name -const char* password = ""; // WLAN-password - -#define CHANNELS 4 // change this only if you add or remove channels in the implementation-part. To disable channels set them to 0 leds. - -// should not exceed 168 leds, since that results in the maximum paket size that is safe to transmit. Everything above could potentially be dropped. -// no more than 255 leds per channel (hard limit) -#define LEDS_CHANNEL_1 3 -#define LEDS_CHANNEL_2 0 -#define LEDS_CHANNEL_3 0 -#define LEDS_CHANNEL_4 0 - -#define PIN_CHANNEL_1 15 // D8 -#define PIN_CHANNEL_2 13 // D7 -#define PIN_CHANNEL_3 12 // D6 -#define PIN_CHANNEL_4 14 // D5 - -#define PORT 1872 // if changed needs to be configured in RGB.NET (default: 1872) - -#define WEBSERVER_PORT 80 - -//####################### - -CRGB leds_channel_1[LEDS_CHANNEL_1]; -CRGB leds_channel_2[LEDS_CHANNEL_2]; -CRGB leds_channel_3[LEDS_CHANNEL_3]; -CRGB leds_channel_4[LEDS_CHANNEL_4]; - -WiFiServer server(WEBSERVER_PORT); -WiFiUDP Udp; - -byte incomingPacket[767]; // 255 (max leds) * 3 + 2 (header) -byte lastSequenceNumbers[CHANNELS]; - -String header; - -void setup() { - if(LEDS_CHANNEL_1 > 0) { FastLED.addLeds(leds_channel_1, LEDS_CHANNEL_1); } - if(LEDS_CHANNEL_2 > 0) { FastLED.addLeds(leds_channel_2, LEDS_CHANNEL_2); } - if(LEDS_CHANNEL_3 > 0) { FastLED.addLeds(leds_channel_3, LEDS_CHANNEL_3); } - if(LEDS_CHANNEL_4 > 0) { FastLED.addLeds(leds_channel_4, LEDS_CHANNEL_4); } - - for(int i = 0; i < CHANNELS; i++) - { - lastSequenceNumbers[i] = 255; - } - - WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED) - { - delay(500); - } - delay(100); - - Udp.begin(PORT); - server.begin(); -} - -bool checkSequenceNumber(int channel, byte currentSequenceNumber) -{ - bool isValid = (currentSequenceNumber > lastSequenceNumbers[channel]) || ((lastSequenceNumbers[channel] > 200) && (currentSequenceNumber < 50)); - if(isValid) - { - lastSequenceNumbers[channel] = currentSequenceNumber; - } - return isValid; -} - -void loop() { - // Web client - WiFiClient client = server.available(); - if (client) - { - String currentLine = ""; - while (client.connected()) - { - if (client.available()) - { - char c = client.read(); - header += c; - if (c == '\n') { - if (currentLine.length() == 0) { - client.println("HTTP/1.1 200 OK"); - client.println("Content-type:text/html"); - client.println("Connection: close"); - client.println(); - - if (header.indexOf("GET /reset") >= 0) - { - for(int i = 0; i < CHANNELS; i++) - { - lastSequenceNumbers[i] = 255; - } - for(int i = 0; i < LEDS_CHANNEL_1; i++) - { - leds_channel_1[i] = CRGB::Black; - } - for(int i = 0; i < LEDS_CHANNEL_2; i++) - { - leds_channel_2[i] = CRGB::Black; - } - for(int i = 0; i < LEDS_CHANNEL_3; i++) - { - leds_channel_3[i] = CRGB::Black; - } - for(int i = 0; i < LEDS_CHANNEL_4; i++) - { - leds_channel_4[i] = CRGB::Black; - } - FastLED.show(); - } - else if (header.indexOf("GET /channels") >= 0) - { - client.println(CHANNELS); - } - else if (header.indexOf("GET /channel/1") >= 0) - { - client.println(LEDS_CHANNEL_1); - } - else if (header.indexOf("GET /channel/2") >= 0) - { - client.println(LEDS_CHANNEL_2); - } - else if (header.indexOf("GET /channel/3") >= 0) - { - client.println(LEDS_CHANNEL_3); - } - else if (header.indexOf("GET /channel/4") >= 0) - { - client.println(LEDS_CHANNEL_4); - } - client.println(); - - break; - } - else - { - currentLine = ""; - } - } - else if (c != '\r') - { - currentLine += c; - } - } - } - header = ""; - client.stop(); - } - - // Color update - int packetSize = Udp.parsePacket(); - if (packetSize) - { - // receive incoming UDP packets - byte sequenceNumber = Udp.read(); - byte command = Udp.read(); - switch(command) - { - // ### channel 1 ### - case 0x12: // set leds of channel 1 - if(checkSequenceNumber(0, sequenceNumber)) - { - Udp.read(((uint8_t*)leds_channel_1), (LEDS_CHANNEL_1 * 3)); - FastLED.show(); - } - break; - - // ### channel 2 ### - case 0x22: // set leds of channel 2 - if(checkSequenceNumber(1, sequenceNumber)) - { - Udp.read(((uint8_t*)leds_channel_2), (LEDS_CHANNEL_2 * 3)); - FastLED.show(); - } - break; - - // ### channel 3 ### - case 0x32: // set leds of channel 3 - if(checkSequenceNumber(2, sequenceNumber)) - { - Udp.read(((uint8_t*)leds_channel_3), (LEDS_CHANNEL_3 * 3)); - FastLED.show(); - } - break; - - // ### channel 4 ### - case 0x42: // set leds of channel 4 - if(checkSequenceNumber(3, sequenceNumber)) - { - Udp.read(((uint8_t*)leds_channel_4), (LEDS_CHANNEL_4 * 3)); - FastLED.show(); - } - break; - - // ### default ### - default: - break; - } - } -} diff --git a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs index 89ad1cc..3875cf4 100644 --- a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs +++ b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using RGB.NET.Core; +using RGB.NET.Devices.WS281X.NodeMCU; namespace RGB.NET.Devices.WS281X { @@ -105,7 +106,11 @@ namespace RGB.NET.Devices.WS281X /// public void ResetDevices() - { } + { + foreach (IRGBDevice device in Devices) + if (device is NodeMCUWS2812USBDevice nodemcuDevice) + nodemcuDevice.UpdateQueue.ResetDevice(); + } /// public void Dispose() From 1e8c6596c55b1d5327245dcaabad8863dcbd7ec9 Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Tue, 14 Jul 2020 14:28:20 +0200 Subject: [PATCH 40/51] Used port-constant for web-server creation in NodeMCU-sketch Co-authored-by: Leon Kiefer --- RGB.NET.Devices.WS281X/Sketches/RGB.NET_NodeMCU.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Devices.WS281X/Sketches/RGB.NET_NodeMCU.ino b/RGB.NET.Devices.WS281X/Sketches/RGB.NET_NodeMCU.ino index dc28c66..02feab3 100644 --- a/RGB.NET.Devices.WS281X/Sketches/RGB.NET_NodeMCU.ino +++ b/RGB.NET.Devices.WS281X/Sketches/RGB.NET_NodeMCU.ino @@ -35,7 +35,7 @@ CRGB leds_channel_2[LEDS_CHANNEL_2]; CRGB leds_channel_3[LEDS_CHANNEL_3]; CRGB leds_channel_4[LEDS_CHANNEL_4]; -ESP8266WebServer server(80); +ESP8266WebServer server(WEBSERVER_PORT); WiFiUDP Udp; bool isUDPEnabled; @@ -292,4 +292,4 @@ void loop() processUDP(); } } - \ No newline at end of file + From 924fa40232d5fbf225f8c510537570c054e44870 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 16 Jul 2020 00:43:51 +0200 Subject: [PATCH 41/51] Replaced magic numbers with enum values --- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 33 +++++++++------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index cf19d8c..8547b14 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -90,52 +90,45 @@ namespace RGB.NET.Devices.Asus { try { - IAsusRGBDevice rgbDevice = null; - switch (device.Type) + IAsusRGBDevice rgbDevice; + switch ((AsusDeviceType)device.Type) { - case 0x00010000: //Motherboard + case AsusDeviceType.MB_RGB: rgbDevice = new AsusMainboardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mainboard, device, WMIHelper.GetMainboardInfo()?.model ?? device.Name)); break; - case 0x00011000: //Motherboard LED Strip + case AsusDeviceType.MB_ADDRESABLE: rgbDevice = new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.LedStripe, device), LedId.LedStripe1); break; - case 0x00020000: //VGA + case AsusDeviceType.VGA_RGB: rgbDevice = new AsusGraphicsCardRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.GraphicsCard, device)); break; - case 0x00040000: //Headset + case AsusDeviceType.HEADSET_RGB: rgbDevice = new AsusHeadsetRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Headset, device)); break; - case 0x00070000: //DRAM + case AsusDeviceType.DRAM_RGB: rgbDevice = new AsusDramRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.DRAM, device)); break; - case 0x00080000: //Keyboard - case 0x00081000: //Notebook Keyboard - case 0x00081001: //Notebook Keyboard(4 - zone type) + case AsusDeviceType.KEYBOARD_RGB: + case AsusDeviceType.NB_KB_RGB: + case AsusDeviceType.NB_KB_4ZONE_RGB: rgbDevice = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device, CultureInfo.CurrentCulture)); break; - case 0x00090000: //Mouse + case AsusDeviceType.MOUSE_RGB: rgbDevice = new AsusMouseRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Mouse, device)); break; - case 0x00000000: //All - case 0x00012000: //All - In - One PC - case 0x00030000: //Display - case 0x00050000: //Microphone - case 0x00060000: //External HDD - case 0x00061000: //External BD Drive - case 0x000B0000: //Chassis - case 0x000C0000: //Projector + default: rgbDevice = new AsusUnspecifiedRGBDevice(new AsusRGBDeviceInfo(RGBDeviceType.Unknown, device), LedId.Custom1); break; } - if ((rgbDevice != null) && loadFilter.HasFlag(rgbDevice.DeviceInfo.DeviceType)) + if (loadFilter.HasFlag(rgbDevice.DeviceInfo.DeviceType)) { rgbDevice.Initialize(UpdateTrigger); devices.Add(rgbDevice); From b885116e830a11170b018606071b688f66432037 Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Thu, 16 Jul 2020 00:54:41 +0200 Subject: [PATCH 42/51] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 45ae0db..7d7098d 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ This is the easiest and therefore preferred way to include RGB.NET in your proje Since there aren't any release-packages right now you'll have to use the CI-feed from [http://nuget.arge.be](http://nuget.arge.be). You can include it either by adding ```http://nuget.arge.be/v3/index.json``` to your Visual Studio package sources or by adding this [NuGet.Config](https://github.com/DarthAffe/RGB.NET/tree/master/Documentation/NuGet.Config) to your project (at the same level as your solution). +### .NET 4.5 Support ### +At the end of the year with the release of .NET 5 the support for old .NET-Framwork versions will be droppped! +It's not recommended to use RGB.NET in projects targeting .NET 4.x that aren't planned to be moved to Core/.NET 5 in the future. + ### Device-Layouts To be able to have devices with correct LED-locations and sizes they need to be layouted. Pre-created layouts can be found at https://github.com/DarthAffe/RGB.NET-Resources. From 37426ef413e788a3219cf79ef11322348e62d126 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sat, 1 Aug 2020 18:57:24 +0200 Subject: [PATCH 43/51] Include Layout path in Debug RGB device --- RGB.NET.Devices.Debug/DebugRGBDevice.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/RGB.NET.Devices.Debug/DebugRGBDevice.cs b/RGB.NET.Devices.Debug/DebugRGBDevice.cs index 2ed6700..c63e3e8 100644 --- a/RGB.NET.Devices.Debug/DebugRGBDevice.cs +++ b/RGB.NET.Devices.Debug/DebugRGBDevice.cs @@ -16,6 +16,11 @@ namespace RGB.NET.Devices.Debug /// public override DebugRGBDeviceInfo DeviceInfo { get; } + /// + /// Gets the path used to mock this + /// + public string LayoutPath { get; } + private Func> _syncBackFunc; private Action> _updateLedsAction; @@ -32,6 +37,7 @@ namespace RGB.NET.Devices.Debug DeviceLayout layout = DeviceLayout.Load(layoutPath); DeviceInfo = new DebugRGBDeviceInfo(layout.Type, layout.Vendor, layout.Model, layout.Lighting, syncBackFunc != null); + LayoutPath = layoutPath; } #endregion From 0c5d0fe7354eb2bd94f840cbe04c165a8f4e2e52 Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Mon, 3 Aug 2020 00:05:31 +0200 Subject: [PATCH 44/51] Small coding style adjustment --- RGB.NET.Devices.Debug/DebugRGBDevice.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Devices.Debug/DebugRGBDevice.cs b/RGB.NET.Devices.Debug/DebugRGBDevice.cs index c63e3e8..174e7fd 100644 --- a/RGB.NET.Devices.Debug/DebugRGBDevice.cs +++ b/RGB.NET.Devices.Debug/DebugRGBDevice.cs @@ -17,7 +17,7 @@ namespace RGB.NET.Devices.Debug public override DebugRGBDeviceInfo DeviceInfo { get; } /// - /// Gets the path used to mock this + /// Gets the path of the layout used to mock this /// public string LayoutPath { get; } @@ -32,12 +32,12 @@ namespace RGB.NET.Devices.Debug ///
internal DebugRGBDevice(string layoutPath, Func> syncBackFunc = null, Action> updateLedsAction = null) { + this.LayoutPath = layoutPath; this._syncBackFunc = syncBackFunc; this._updateLedsAction = updateLedsAction; DeviceLayout layout = DeviceLayout.Load(layoutPath); DeviceInfo = new DebugRGBDeviceInfo(layout.Type, layout.Vendor, layout.Model, layout.Lighting, syncBackFunc != null); - LayoutPath = layoutPath; } #endregion From 2d833fb8006d84e33d6dd62366995779293838c1 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Thu, 13 Aug 2020 00:40:46 +0200 Subject: [PATCH 45/51] CoolerMaster - Fix slow device updates --- .../Generic/CoolerMasterUpdateQueue.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs index ecc4cd6..eb94e3a 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs @@ -13,6 +13,7 @@ namespace RGB.NET.Devices.CoolerMaster #region Properties & Fields private CoolerMasterDevicesIndexes _deviceIndex; + private _CoolerMasterColorMatrix _deviceMatrix; #endregion @@ -27,6 +28,9 @@ namespace RGB.NET.Devices.CoolerMaster : base(updateTrigger) { this._deviceIndex = deviceIndex; + this._deviceMatrix = new _CoolerMasterColorMatrix(); + + _deviceMatrix.KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS]; } #endregion @@ -39,10 +43,10 @@ namespace RGB.NET.Devices.CoolerMaster foreach (KeyValuePair data in dataSet) { (int row, int column) = ((int, int))data.Key; - _CoolerMasterSDK.SetLedColor(row, column, data.Value.GetR(), data.Value.GetG(), data.Value.GetB(), _deviceIndex); + _deviceMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(data.Value.GetR(), data.Value.GetG(), data.Value.GetB()); } - _CoolerMasterSDK.RefreshLed(false, _deviceIndex); + _CoolerMasterSDK.SetAllLedColor(_deviceMatrix, _deviceIndex); } #endregion From a3f9b430d1860c55c2ce7a6d2d9e7916e74565ad Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Thu, 13 Aug 2020 10:30:25 +0200 Subject: [PATCH 46/51] Small formatting changes --- .../Generic/CoolerMasterUpdateQueue.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs index eb94e3a..21b26ce 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs @@ -13,7 +13,7 @@ namespace RGB.NET.Devices.CoolerMaster #region Properties & Fields private CoolerMasterDevicesIndexes _deviceIndex; - private _CoolerMasterColorMatrix _deviceMatrix; + private readonly _CoolerMasterColorMatrix _deviceMatrix; #endregion @@ -28,8 +28,8 @@ namespace RGB.NET.Devices.CoolerMaster : base(updateTrigger) { this._deviceIndex = deviceIndex; - this._deviceMatrix = new _CoolerMasterColorMatrix(); - + + _deviceMatrix = new _CoolerMasterColorMatrix(); _deviceMatrix.KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS]; } From fd2e9a004968f622d8219d3768c631ca008ef2e9 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 5 Sep 2020 23:47:05 +0200 Subject: [PATCH 47/51] Added color-extension to calculate the distance between two colors --- RGB.NET.Core/Extensions/ColorExtensions.cs | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 RGB.NET.Core/Extensions/ColorExtensions.cs diff --git a/RGB.NET.Core/Extensions/ColorExtensions.cs b/RGB.NET.Core/Extensions/ColorExtensions.cs new file mode 100644 index 0000000..15d0c80 --- /dev/null +++ b/RGB.NET.Core/Extensions/ColorExtensions.cs @@ -0,0 +1,30 @@ +using System; + +namespace RGB.NET.Core +{ + public static class ColorExtensions + { + #region Methods + + /// + /// Calculates the distance between the two given colors using the redmean algorithm. + /// For more infos check https://www.compuphase.com/cmetric.htm + /// + /// The start color of the distance calculation. + /// The end color fot the distance calculation. + /// + public static double DistanceTo(this Color color1, Color color2) + { + (_, byte r1, byte g1, byte b1) = color1.GetRGBBytes(); + (_, byte r2, byte g2, byte b2) = color2.GetRGBBytes(); + + long rmean = (r1 + r2) / 2; + long r = r1 - r2; + long g = g1 - g2; + long b = b1 - b2; + return Math.Sqrt((((512 + rmean) * r * r) >> 8) + (4 * g * g) + (((767 - rmean) * b * b) >> 8)); + } + + #endregion + } +} From f91d5e50605cebcad5c095b5f5092696f76160a5 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 5 Sep 2020 23:48:46 +0200 Subject: [PATCH 48/51] Added support for novation launchpad mk2 --- .../Attributes/LedIdMappingAttribute.cs | 35 +++ .../Enum/NovationDevices.cs | 10 +- .../Enum/NovationLedId.cs | 107 -------- .../Generic/LimitedColorUpdateQueue.cs | 4 +- .../Generic/MidiUpdateQueue.cs | 14 +- .../Generic/NovationRGBDevice.cs | 10 +- .../Generic/RGBColorUpdateQueue.cs | 195 ++++++++++++++ .../Helper/DictionaryExtension.cs | 10 - .../Helper/EnumExtension.cs | 7 + .../Helper/NovationLedIdExtension.cs | 47 ---- .../Launchpad/LaunchpadIdMapping.cs | 252 ++++++++++++------ .../Launchpad/LedIdMappings.cs | 8 + .../Launchpad/NovationLaunchpadRGBDevice.cs | 27 +- .../NovationLaunchpadRGBDeviceInfo.cs | 13 +- .../NovationDeviceProvider.cs | 7 +- 15 files changed, 474 insertions(+), 272 deletions(-) create mode 100644 RGB.NET.Devices.Novation/Attributes/LedIdMappingAttribute.cs delete mode 100644 RGB.NET.Devices.Novation/Enum/NovationLedId.cs create mode 100644 RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs delete mode 100644 RGB.NET.Devices.Novation/Helper/DictionaryExtension.cs delete mode 100644 RGB.NET.Devices.Novation/Helper/NovationLedIdExtension.cs create mode 100644 RGB.NET.Devices.Novation/Launchpad/LedIdMappings.cs diff --git a/RGB.NET.Devices.Novation/Attributes/LedIdMappingAttribute.cs b/RGB.NET.Devices.Novation/Attributes/LedIdMappingAttribute.cs new file mode 100644 index 0000000..3cda1aa --- /dev/null +++ b/RGB.NET.Devices.Novation/Attributes/LedIdMappingAttribute.cs @@ -0,0 +1,35 @@ +using System; + +namespace RGB.NET.Devices.Novation.Attributes +{ + /// + /// + /// Specifies the led id mapping of a field. + /// + [AttributeUsage(AttributeTargets.Field)] + internal class LedIdMappingAttribute : Attribute + { + #region Properties & Fields + + /// + /// Gets the led id mapping. + /// + internal LedIdMappings LedIdMapping { get; } + + #endregion + + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + /// The led id mapping. + internal LedIdMappingAttribute(LedIdMappings ledIdMapping) + { + this.LedIdMapping = ledIdMapping; + } + + #endregion + } +} diff --git a/RGB.NET.Devices.Novation/Enum/NovationDevices.cs b/RGB.NET.Devices.Novation/Enum/NovationDevices.cs index c9cf763..f1afa2c 100644 --- a/RGB.NET.Devices.Novation/Enum/NovationDevices.cs +++ b/RGB.NET.Devices.Novation/Enum/NovationDevices.cs @@ -13,9 +13,17 @@ namespace RGB.NET.Devices.Novation { [DeviceId("Launchpad S")] [ColorCapability(NovationColorCapabilities.LimitedRG)] + [LedIdMapping(LedIdMappings.Legacy)] LaunchpadS, + [DeviceId("Launchpad Mini")] [ColorCapability(NovationColorCapabilities.LimitedRG)] - LaunchpadMini + [LedIdMapping(LedIdMappings.Legacy)] + LaunchpadMini, + + [DeviceId("Launchpad MK2")] + [ColorCapability(NovationColorCapabilities.RGB)] + [LedIdMapping(LedIdMappings.Current)] + LaunchpadMK2 } } diff --git a/RGB.NET.Devices.Novation/Enum/NovationLedId.cs b/RGB.NET.Devices.Novation/Enum/NovationLedId.cs deleted file mode 100644 index 22f44c3..0000000 --- a/RGB.NET.Devices.Novation/Enum/NovationLedId.cs +++ /dev/null @@ -1,107 +0,0 @@ -// ReSharper disable InconsistentNaming -// ReSharper disable UnusedMember.Global - -#pragma warning disable 1591 // Missing XML comment for publicly visible type or member - -namespace RGB.NET.Devices.Novation -{ - /// - /// Contains list of all LEDs available for all Novation devices. - /// They are represented as Hex 0x[00][11] where [00] is the status flag, [1] the id of the led. - /// - //TODO DarthAffe 15.08.2017: Check if this is really correct for all devices - public enum NovationLedId - { - Invalid = -1, - - Grid1 = 0x9000, - Grid2 = 0x9001, - Grid3 = 0x9002, - Grid4 = 0x9003, - Grid5 = 0x9004, - Grid6 = 0x9005, - Grid7 = 0x9006, - Grid8 = 0x9007, - - Grid9 = 0x9010, - Grid10 = 0x9011, - Grid11 = 0x9012, - Grid12 = 0x9013, - Grid13 = 0x9014, - Grid14 = 0x9015, - Grid15 = 0x9016, - Grid16 = 0x9017, - - Grid17 = 0x9020, - Grid18 = 0x9021, - Grid19 = 0x9022, - Grid20 = 0x9023, - Grid21 = 0x9024, - Grid22 = 0x9025, - Grid23 = 0x9026, - Grid24 = 0x9027, - - Grid25 = 0x9030, - Grid26 = 0x9031, - Grid27 = 0x9032, - Grid28 = 0x9033, - Grid29 = 0x9034, - Grid30 = 0x9035, - Grid31 = 0x9036, - Grid32 = 0x9037, - - Grid33 = 0x9040, - Grid34 = 0x9041, - Grid35 = 0x9042, - Grid36 = 0x9043, - Grid37 = 0x9044, - Grid38 = 0x9045, - Grid39 = 0x9046, - Grid40 = 0x9047, - - Grid41 = 0x9050, - Grid42 = 0x9051, - Grid43 = 0x9052, - Grid44 = 0x9053, - Grid45 = 0x9054, - Grid46 = 0x9055, - Grid47 = 0x9056, - Grid48 = 0x9057, - - Grid49 = 0x9060, - Grid50 = 0x9061, - Grid51 = 0x9062, - Grid52 = 0x9063, - Grid53 = 0x9064, - Grid54 = 0x9065, - Grid55 = 0x9066, - Grid56 = 0x9067, - - Grid57 = 0x9070, - Grid58 = 0x9071, - Grid59 = 0x9072, - Grid60 = 0x9073, - Grid61 = 0x9074, - Grid62 = 0x9075, - Grid63 = 0x9076, - Grid64 = 0x9077, - - Up = 0xB068, - Down = 0xB069, - Left = 0xB06A, - Right = 0xB06B, - Session = 0xB06C, - User1 = 0xB06D, - User2 = 0xB06E, - Mix = 0xB06F, - - Scene1 = 0x9009, - Scene2 = 0x9019, - Scene3 = 0x9029, - Scene4 = 0x9039, - Scene5 = 0x9049, - Scene6 = 0x9059, - Scene7 = 0x9069, - Scene8 = 0x9079 - } -} diff --git a/RGB.NET.Devices.Novation/Generic/LimitedColorUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/LimitedColorUpdateQueue.cs index a3570c9..588e359 100644 --- a/RGB.NET.Devices.Novation/Generic/LimitedColorUpdateQueue.cs +++ b/RGB.NET.Devices.Novation/Generic/LimitedColorUpdateQueue.cs @@ -28,8 +28,8 @@ namespace RGB.NET.Devices.Novation /// protected override ShortMessage CreateMessage(KeyValuePair data) { - NovationLedId ledId = (NovationLedId)data.Key; - return new ShortMessage(Convert.ToByte(ledId.GetStatus()), Convert.ToByte(ledId.GetId()), Convert.ToByte(ConvertColor(data.Value))); + (byte mode, byte id) = ((byte, byte))data.Key; + return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(data.Value))); } /// diff --git a/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs index 4dfafc9..6e34359 100644 --- a/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs +++ b/RGB.NET.Devices.Novation/Generic/MidiUpdateQueue.cs @@ -47,7 +47,12 @@ namespace RGB.NET.Devices.Novation /// Sends the specified message to the device this queue is performing updates for. /// /// The message to send. - protected virtual void SendMessage(ShortMessage message) => _outputDevice.SendShort(message.Message); + protected virtual void SendMessage(ShortMessage message) + { + if (message != null) + _outputDevice.SendShort(message.Message); + } + /// /// Creates a update-message out of a given data set. @@ -57,7 +62,12 @@ namespace RGB.NET.Devices.Novation protected abstract ShortMessage CreateMessage(KeyValuePair data); /// - public void Dispose() => _outputDevice.Dispose(); + public override void Dispose() + { + base.Dispose(); + + _outputDevice.Dispose(); + } #endregion } diff --git a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs index a66fb03..d1f7679 100644 --- a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs +++ b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs @@ -57,8 +57,12 @@ namespace RGB.NET.Devices.Novation Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y); } - if (DeviceInfo.ColorCapabilities == NovationColorCapabilities.LimitedRG) - UpdateQueue = new LimitedColorUpdateQueue(updateTrigger, DeviceInfo.DeviceId); + UpdateQueue = DeviceInfo.ColorCapabilities switch + { + NovationColorCapabilities.LimitedRG => new LimitedColorUpdateQueue(updateTrigger, DeviceInfo.DeviceId), + NovationColorCapabilities.RGB => new RGBColorUpdateQueue(updateTrigger, DeviceInfo.DeviceId), + _ => throw new ArgumentOutOfRangeException() + }; } /// @@ -82,7 +86,7 @@ namespace RGB.NET.Devices.Novation try { UpdateQueue?.Dispose(); } catch { /* at least we tried */ } - + base.Dispose(); } diff --git a/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs b/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs new file mode 100644 index 0000000..5dd9d54 --- /dev/null +++ b/RGB.NET.Devices.Novation/Generic/RGBColorUpdateQueue.cs @@ -0,0 +1,195 @@ +using System; +using System.Collections.Generic; +using RGB.NET.Core; +using Sanford.Multimedia.Midi; + +namespace RGB.NET.Devices.Novation +{ + /// + /// Represents the update-queue performing updates for a RGB-color novation device. + /// + public class RGBColorUpdateQueue : MidiUpdateQueue + { + #region Properties & Fields + + private static readonly (Color, int)[] COLOR_PALETTE = + { + (new Color(0, 0, 0), 0), + (new Color(28, 28, 28), 1), + (new Color(124, 124, 124), 2), + (new Color(252, 252, 252), 3), + (new Color(255, 77, 71), 4), + (new Color(255, 10, 0), 5), + (new Color(90, 1, 0), 6), + (new Color(25, 0, 0), 7), + (new Color(255, 189, 98), 8), + (new Color(255, 86, 0), 9), + (new Color(90, 29, 0), 10), + (new Color(36, 24, 0), 11), + (new Color(253, 253, 33), 12), + (new Color(253, 253, 0), 13), + (new Color(88, 88, 0), 14), + (new Color(24, 24, 0), 15), + (new Color(128, 253, 42), 16), + (new Color(64, 253, 0), 17), + (new Color(22, 88, 0), 18), + (new Color(19, 40, 0), 19), + (new Color(52, 253, 43), 20), + (new Color(0, 253, 0), 21), + (new Color(0, 88, 0), 22), + (new Color(0, 24, 0), 23), + (new Color(51, 253, 70), 24), + (new Color(50, 253, 126), 28), + (new Color(0, 253, 58), 29), + (new Color(0, 88, 20), 30), + (new Color(0, 28, 15), 31), + (new Color(47, 252, 176), 32), + (new Color(0, 252, 145), 33), + (new Color(0, 88, 49), 34), + (new Color(0, 24, 15), 35), + (new Color(57, 191, 255), 36), + (new Color(0, 167, 255), 37), + (new Color(0, 64, 81), 38), + (new Color(0, 16, 24), 39), + (new Color(65, 134, 255), 40), + (new Color(0, 80, 255), 41), + (new Color(0, 26, 90), 42), + (new Color(0, 7, 25), 43), + (new Color(70, 71, 255), 44), + (new Color(0, 0, 255), 45), + (new Color(0, 0, 91), 46), + (new Color(0, 0, 25), 47), + (new Color(131, 71, 255), 48), + (new Color(80, 0, 255), 49), + (new Color(22, 0, 103), 50), + (new Color(11, 0, 50), 51), + (new Color(255, 73, 255), 52), + (new Color(255, 0, 255), 53), + (new Color(90, 0, 90), 54), + (new Color(25, 0, 25), 55), + (new Color(255, 77, 132), 56), + (new Color(255, 7, 82), 57), + (new Color(90, 1, 27), 58), + (new Color(33, 0, 16), 59), + (new Color(255, 25, 0), 60), + (new Color(155, 53, 0), 61), + (new Color(122, 81, 0), 62), + (new Color(62, 100, 0), 63), + (new Color(0, 56, 0), 64), + (new Color(0, 84, 50), 65), + (new Color(0, 83, 126), 66), + (new Color(0, 68, 77), 68), + (new Color(27, 0, 210), 69), + (new Color(32, 32, 32), 71), + (new Color(186, 253, 0), 73), + (new Color(170, 237, 0), 74), + (new Color(86, 253, 0), 75), + (new Color(0, 136, 0), 76), + (new Color(0, 252, 122), 77), + (new Color(0, 27, 255), 79), + (new Color(53, 0, 255), 80), + (new Color(119, 0, 255), 81), + (new Color(180, 23, 126), 82), + (new Color(65, 32, 0), 83), + (new Color(255, 74, 0), 84), + (new Color(131, 225, 0), 85), + (new Color(101, 253, 0), 86), + (new Color(69, 253, 97), 89), + (new Color(0, 252, 202), 90), + (new Color(80, 134, 255), 91), + (new Color(39, 77, 201), 92), + (new Color(130, 122, 237), 93), + (new Color(211, 12, 255), 94), + (new Color(255, 6, 90), 95), + (new Color(255, 125, 0), 96), + (new Color(185, 177, 0), 97), + (new Color(138, 253, 0), 98), + (new Color(130, 93, 0), 99), + (new Color(57, 40, 0), 100), + (new Color(13, 76, 5), 101), + (new Color(0, 80, 55), 102), + (new Color(19, 19, 41), 103), + (new Color(16, 31, 90), 104), + (new Color(106, 60, 23), 105), + (new Color(172, 4, 0), 106), + (new Color(225, 81, 53), 107), + (new Color(220, 105, 0), 108), + (new Color(255, 255, 0), 109), + (new Color(153, 225, 0), 110), + (new Color(95, 181, 0), 111), + (new Color(27, 27, 49), 112), + (new Color(220, 253, 84), 113), + (new Color(118, 252, 184), 114), + (new Color(150, 151, 255), 115), + (new Color(139, 97, 255), 116), + (new Color(64, 64, 64), 117), + (new Color(116, 116, 116), 118), + (new Color(222, 252, 252), 119), + (new Color(164, 4, 0), 120), + (new Color(53, 0, 0), 121), + (new Color(0, 209, 0), 122), + (new Color(0, 64, 0), 123), + (new Color(61, 48, 0), 125), + (new Color(180, 93, 0), 126), + (new Color(74, 20, 0), 127), + }; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The update trigger used by this queue. + /// The device-id of the device this queue is performing updates for. + public RGBColorUpdateQueue(IDeviceUpdateTrigger updateTrigger, int deviceId) + : base(updateTrigger, deviceId) + { } + + #endregion + + #region Methods + + /// + protected override ShortMessage CreateMessage(KeyValuePair data) + { + (byte mode, byte id) = ((byte, byte))data.Key; + if (mode == 0x00) return null; + + return new ShortMessage(mode, id, Convert.ToByte(ConvertColor(data.Value))); + } + + /// + /// Convert a to its novation-representation depending on the of the . + /// Source: http://www.launchpadfun.com/downloads_de/velocity-colors/ + /// + /// The to convert. + /// The novation-representation of the . + protected virtual int ConvertColor(Color color) + { + int bestVelocity = 0; + double bestMatchDistance = double.MaxValue; + foreach ((Color c, int velocity) in COLOR_PALETTE) + { + double distance = c.DistanceTo(color); + if (distance < bestMatchDistance) + { + bestVelocity = velocity; + bestMatchDistance = distance; + } + } + + return bestVelocity; + } + + /// + public override void Reset() + { + base.Reset(); + SendMessage(new ShortMessage(Convert.ToByte(0xB0), Convert.ToByte(0), Convert.ToByte(0))); + } + + #endregion + } +} diff --git a/RGB.NET.Devices.Novation/Helper/DictionaryExtension.cs b/RGB.NET.Devices.Novation/Helper/DictionaryExtension.cs deleted file mode 100644 index 607ad97..0000000 --- a/RGB.NET.Devices.Novation/Helper/DictionaryExtension.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace RGB.NET.Devices.Novation -{ - internal static class DictionaryExtension - { - public static Dictionary SwapKeyValue(this Dictionary dictionary) => dictionary.ToDictionary(x => x.Value, x => x.Key); - } -} diff --git a/RGB.NET.Devices.Novation/Helper/EnumExtension.cs b/RGB.NET.Devices.Novation/Helper/EnumExtension.cs index 9be8305..a3f432a 100644 --- a/RGB.NET.Devices.Novation/Helper/EnumExtension.cs +++ b/RGB.NET.Devices.Novation/Helper/EnumExtension.cs @@ -23,6 +23,13 @@ namespace RGB.NET.Devices.Novation /// The value of the of the source. internal static NovationColorCapabilities GetColorCapability(this Enum source) => source.GetAttribute()?.Capability ?? NovationColorCapabilities.None; + /// + /// Gets the value of the . + /// + /// The enum value to get the description from. + /// The value of the of the source. + internal static LedIdMappings GetLedIdMapping(this Enum source) => source.GetAttribute()?.LedIdMapping ?? LedIdMappings.Current; + /// /// Gets the attribute of type T. /// diff --git a/RGB.NET.Devices.Novation/Helper/NovationLedIdExtension.cs b/RGB.NET.Devices.Novation/Helper/NovationLedIdExtension.cs deleted file mode 100644 index 7d8556c..0000000 --- a/RGB.NET.Devices.Novation/Helper/NovationLedIdExtension.cs +++ /dev/null @@ -1,47 +0,0 @@ -namespace RGB.NET.Devices.Novation -{ - /// - /// Offers some extensions and helper-methods for NovationLedId related things. - /// - public static class NovationLedIdExtension - { - #region Methods - - /// - /// Gets the status-flag associated with the id. - /// - /// The whose status-flag should be determinated. - /// The status-flag of the . - public static int GetStatus(this NovationLedId ledId) => ((int)ledId & 0xFF00) >> 8; - - /// - /// Gets the id associated with the id. - /// - /// The whose idshould be determinated. - /// The id of the . - public static int GetId(this NovationLedId ledId) => (int)ledId & 0x00FF; - - /// - /// Tests if the given is a grid-button. - /// - /// the to test. - /// true if is a grid-button; otherwise, false. - public static bool IsGrid(this NovationLedId ledId) => (ledId.GetStatus() == 0x90) && ((ledId.GetId() / 0x10) < 0x08) && ((ledId.GetId() % 0x10) < 0x08); - - /// - /// Tests if the given is a scene-button. - /// - /// the to test. - /// true if is a scene-button; otherwise, false. - public static bool IsScene(this NovationLedId ledId) => (ledId.GetStatus() == 0x90) && ((ledId.GetId() / 0x10) < 0x08) && ((ledId.GetId() % 0x10) == 0x09); - - /// - /// Tests if the given is custom-button. - /// - /// the to test. - /// true if is a custom-button; otherwise, false. - public static bool IsCustom(this NovationLedId ledId) => (ledId.GetStatus() == 0xB0) && ((ledId.GetId() / 0x10) == 0x06) && ((ledId.GetId() % 0x10) > 0x07); - - #endregion - } -} diff --git a/RGB.NET.Devices.Novation/Launchpad/LaunchpadIdMapping.cs b/RGB.NET.Devices.Novation/Launchpad/LaunchpadIdMapping.cs index 8d90205..39aa29f 100644 --- a/RGB.NET.Devices.Novation/Launchpad/LaunchpadIdMapping.cs +++ b/RGB.NET.Devices.Novation/Launchpad/LaunchpadIdMapping.cs @@ -5,92 +5,180 @@ namespace RGB.NET.Devices.Novation { internal static class LaunchpadIdMapping { - internal static readonly Dictionary DEFAULT = new Dictionary + internal static readonly Dictionary LEGACY = new Dictionary { - { LedId.Invalid, NovationLedId.Invalid }, + { LedId.Invalid, (0x00, 0xFF, 8, 0) }, - { LedId.LedMatrix1, NovationLedId.Grid1 }, - { LedId.LedMatrix2, NovationLedId.Grid2 }, - { LedId.LedMatrix3, NovationLedId.Grid3 }, - { LedId.LedMatrix4, NovationLedId.Grid4 }, - { LedId.LedMatrix5, NovationLedId.Grid5 }, - { LedId.LedMatrix6, NovationLedId.Grid6 }, - { LedId.LedMatrix7, NovationLedId.Grid7 }, - { LedId.LedMatrix8, NovationLedId.Grid8 }, - { LedId.LedMatrix9, NovationLedId.Grid9 }, - { LedId.LedMatrix10, NovationLedId.Grid10 }, - { LedId.LedMatrix11, NovationLedId.Grid11 }, - { LedId.LedMatrix12, NovationLedId.Grid12 }, - { LedId.LedMatrix13, NovationLedId.Grid13 }, - { LedId.LedMatrix14, NovationLedId.Grid14 }, - { LedId.LedMatrix15, NovationLedId.Grid15 }, - { LedId.LedMatrix16, NovationLedId.Grid16 }, - { LedId.LedMatrix17, NovationLedId.Grid17 }, - { LedId.LedMatrix18, NovationLedId.Grid18 }, - { LedId.LedMatrix19, NovationLedId.Grid19 }, - { LedId.LedMatrix20, NovationLedId.Grid20 }, - { LedId.LedMatrix21, NovationLedId.Grid21 }, - { LedId.LedMatrix22, NovationLedId.Grid22 }, - { LedId.LedMatrix23, NovationLedId.Grid23 }, - { LedId.LedMatrix24, NovationLedId.Grid24 }, - { LedId.LedMatrix25, NovationLedId.Grid25 }, - { LedId.LedMatrix26, NovationLedId.Grid26 }, - { LedId.LedMatrix27, NovationLedId.Grid27 }, - { LedId.LedMatrix28, NovationLedId.Grid28 }, - { LedId.LedMatrix29, NovationLedId.Grid29 }, - { LedId.LedMatrix30, NovationLedId.Grid30 }, - { LedId.LedMatrix31, NovationLedId.Grid31 }, - { LedId.LedMatrix32, NovationLedId.Grid32 }, - { LedId.LedMatrix33, NovationLedId.Grid33 }, - { LedId.LedMatrix34, NovationLedId.Grid34 }, - { LedId.LedMatrix35, NovationLedId.Grid35 }, - { LedId.LedMatrix36, NovationLedId.Grid36 }, - { LedId.LedMatrix37, NovationLedId.Grid37 }, - { LedId.LedMatrix38, NovationLedId.Grid38 }, - { LedId.LedMatrix39, NovationLedId.Grid39 }, - { LedId.LedMatrix40, NovationLedId.Grid40 }, - { LedId.LedMatrix41, NovationLedId.Grid41 }, - { LedId.LedMatrix42, NovationLedId.Grid42 }, - { LedId.LedMatrix43, NovationLedId.Grid43 }, - { LedId.LedMatrix44, NovationLedId.Grid44 }, - { LedId.LedMatrix45, NovationLedId.Grid45 }, - { LedId.LedMatrix46, NovationLedId.Grid46 }, - { LedId.LedMatrix47, NovationLedId.Grid47 }, - { LedId.LedMatrix48, NovationLedId.Grid48 }, - { LedId.LedMatrix49, NovationLedId.Grid49 }, - { LedId.LedMatrix50, NovationLedId.Grid50 }, - { LedId.LedMatrix51, NovationLedId.Grid51 }, - { LedId.LedMatrix52, NovationLedId.Grid52 }, - { LedId.LedMatrix53, NovationLedId.Grid53 }, - { LedId.LedMatrix54, NovationLedId.Grid54 }, - { LedId.LedMatrix55, NovationLedId.Grid55 }, - { LedId.LedMatrix56, NovationLedId.Grid56 }, - { LedId.LedMatrix57, NovationLedId.Grid57 }, - { LedId.LedMatrix58, NovationLedId.Grid58 }, - { LedId.LedMatrix59, NovationLedId.Grid59 }, - { LedId.LedMatrix60, NovationLedId.Grid60 }, - { LedId.LedMatrix61, NovationLedId.Grid61 }, - { LedId.LedMatrix62, NovationLedId.Grid62 }, - { LedId.LedMatrix63, NovationLedId.Grid63 }, - { LedId.LedMatrix64, NovationLedId.Grid64 }, + { LedId.LedMatrix1, (0x90, 0x00, 0, 1) }, + { LedId.LedMatrix2, (0x90, 0x01, 1, 1) }, + { LedId.LedMatrix3, (0x90, 0x02, 2, 1) }, + { LedId.LedMatrix4, (0x90, 0x03, 3, 1) }, + { LedId.LedMatrix5, (0x90, 0x04, 4, 1) }, + { LedId.LedMatrix6, (0x90, 0x05, 5, 1) }, + { LedId.LedMatrix7, (0x90, 0x06, 6, 1) }, + { LedId.LedMatrix8, (0x90, 0x07, 7, 1) }, + { LedId.LedMatrix9, (0x90, 0x10, 0, 2) }, + { LedId.LedMatrix10, (0x90, 0x11, 1, 2) }, + { LedId.LedMatrix11, (0x90, 0x12, 2, 2) }, + { LedId.LedMatrix12, (0x90, 0x13, 3, 2) }, + { LedId.LedMatrix13, (0x90, 0x14, 4, 2) }, + { LedId.LedMatrix14, (0x90, 0x15, 5, 2) }, + { LedId.LedMatrix15, (0x90, 0x16, 6, 2) }, + { LedId.LedMatrix16, (0x90, 0x17, 7, 2) }, + { LedId.LedMatrix17, (0x90, 0x20, 0, 3) }, + { LedId.LedMatrix18, (0x90, 0x21, 1, 3) }, + { LedId.LedMatrix19, (0x90, 0x22, 2, 3) }, + { LedId.LedMatrix20, (0x90, 0x23, 3, 3) }, + { LedId.LedMatrix21, (0x90, 0x24, 4, 3) }, + { LedId.LedMatrix22, (0x90, 0x25, 5, 3) }, + { LedId.LedMatrix23, (0x90, 0x26, 6, 3) }, + { LedId.LedMatrix24, (0x90, 0x27, 7, 3) }, + { LedId.LedMatrix25, (0x90, 0x30, 0, 4) }, + { LedId.LedMatrix26, (0x90, 0x31, 1, 4) }, + { LedId.LedMatrix27, (0x90, 0x32, 2, 4) }, + { LedId.LedMatrix28, (0x90, 0x33, 3, 4) }, + { LedId.LedMatrix29, (0x90, 0x34, 4, 4) }, + { LedId.LedMatrix30, (0x90, 0x35, 5, 4) }, + { LedId.LedMatrix31, (0x90, 0x36, 6, 4) }, + { LedId.LedMatrix32, (0x90, 0x37, 7, 4) }, + { LedId.LedMatrix33, (0x90, 0x40, 0, 5) }, + { LedId.LedMatrix34, (0x90, 0x41, 1, 5) }, + { LedId.LedMatrix35, (0x90, 0x42, 2, 5) }, + { LedId.LedMatrix36, (0x90, 0x43, 3, 5) }, + { LedId.LedMatrix37, (0x90, 0x44, 4, 5) }, + { LedId.LedMatrix38, (0x90, 0x45, 5, 5) }, + { LedId.LedMatrix39, (0x90, 0x46, 6, 5) }, + { LedId.LedMatrix40, (0x90, 0x47, 7, 5) }, + { LedId.LedMatrix41, (0x90, 0x50, 0, 6) }, + { LedId.LedMatrix42, (0x90, 0x51, 1, 6) }, + { LedId.LedMatrix43, (0x90, 0x52, 2, 6) }, + { LedId.LedMatrix44, (0x90, 0x53, 3, 6) }, + { LedId.LedMatrix45, (0x90, 0x54, 4, 6) }, + { LedId.LedMatrix46, (0x90, 0x55, 5, 6) }, + { LedId.LedMatrix47, (0x90, 0x56, 6, 6) }, + { LedId.LedMatrix48, (0x90, 0x57, 7, 6) }, + { LedId.LedMatrix49, (0x90, 0x60, 0, 7) }, + { LedId.LedMatrix50, (0x90, 0x61, 1, 7) }, + { LedId.LedMatrix51, (0x90, 0x62, 2, 7) }, + { LedId.LedMatrix52, (0x90, 0x63, 3, 7) }, + { LedId.LedMatrix53, (0x90, 0x64, 4, 7) }, + { LedId.LedMatrix54, (0x90, 0x65, 5, 7) }, + { LedId.LedMatrix55, (0x90, 0x66, 6, 7) }, + { LedId.LedMatrix56, (0x90, 0x67, 7, 7) }, + { LedId.LedMatrix57, (0x90, 0x70, 0, 8) }, + { LedId.LedMatrix58, (0x90, 0x71, 1, 8) }, + { LedId.LedMatrix59, (0x90, 0x72, 2, 8) }, + { LedId.LedMatrix60, (0x90, 0x73, 3, 8) }, + { LedId.LedMatrix61, (0x90, 0x74, 4, 8) }, + { LedId.LedMatrix62, (0x90, 0x75, 5, 8) }, + { LedId.LedMatrix63, (0x90, 0x76, 6, 8) }, + { LedId.LedMatrix64, (0x90, 0x77, 7, 8) }, - { LedId.Custom1, NovationLedId.Up }, - { LedId.Custom2, NovationLedId.Down }, - { LedId.Custom3, NovationLedId.Left }, - { LedId.Custom4, NovationLedId.Right }, - { LedId.Custom5, NovationLedId.Session }, - { LedId.Custom6, NovationLedId.User1 }, - { LedId.Custom7, NovationLedId.User2 }, - { LedId.Custom8, NovationLedId.Mix }, + { LedId.Custom1, (0xB0, 0x68, 0, 0) }, // Up + { LedId.Custom2, (0xB0, 0x69, 1, 0) }, // Down + { LedId.Custom3, (0xB0, 0x6A, 2, 0) }, // Left + { LedId.Custom4, (0xB0, 0x6B, 3, 0) }, // Right + { LedId.Custom5, (0xB0, 0x6C, 4, 0) }, // Session + { LedId.Custom6, (0xB0, 0x6D, 5, 0) }, // User 1 + { LedId.Custom7, (0xB0, 0x6E, 6, 0) }, // User 2 + { LedId.Custom8, (0xB0, 0x6F, 7, 0) }, // Mix - { LedId.Custom9, NovationLedId.Scene1 }, - { LedId.Custom10, NovationLedId.Scene2 }, - { LedId.Custom11, NovationLedId.Scene3 }, - { LedId.Custom12, NovationLedId.Scene4 }, - { LedId.Custom13, NovationLedId.Scene5 }, - { LedId.Custom14, NovationLedId.Scene6 }, - { LedId.Custom15, NovationLedId.Scene7 }, - { LedId.Custom16, NovationLedId.Scene8 }, + { LedId.Custom9, (0x90, 0x08, 8, 1) }, //Scene1 + { LedId.Custom10, (0x90, 0x18, 8, 2) }, //Scene2 + { LedId.Custom11, (0x90, 0x28, 8, 3) }, //Scene3 + { LedId.Custom12, (0x90, 0x38, 8, 4) }, //Scene4 + { LedId.Custom13, (0x90, 0x48, 8, 5) }, //Scene5 + { LedId.Custom14, (0x90, 0x58, 8, 6) }, //Scene6 + { LedId.Custom15, (0x90, 0x68, 8, 7) }, //Scene7 + { LedId.Custom16, (0x90, 0x78, 8, 8) }, //Scene8 + }; + + internal static readonly Dictionary CURRENT = new Dictionary + { + { LedId.Invalid, (0x00, 0xFF, 8, 0) }, + + { LedId.LedMatrix1, (0x90, 81, 0, 1) }, + { LedId.LedMatrix2, (0x90, 82, 1, 1) }, + { LedId.LedMatrix3, (0x90, 83, 2, 1) }, + { LedId.LedMatrix4, (0x90, 84, 3, 1) }, + { LedId.LedMatrix5, (0x90, 85, 4, 1) }, + { LedId.LedMatrix6, (0x90, 86, 5, 1) }, + { LedId.LedMatrix7, (0x90, 87, 6, 1) }, + { LedId.LedMatrix8, (0x90, 88, 7, 1) }, + { LedId.LedMatrix9, (0x90, 71, 0, 2) }, + { LedId.LedMatrix10, (0x90, 72, 1, 2) }, + { LedId.LedMatrix11, (0x90, 73, 2, 2) }, + { LedId.LedMatrix12, (0x90, 74, 3, 2) }, + { LedId.LedMatrix13, (0x90, 75, 4, 2) }, + { LedId.LedMatrix14, (0x90, 76, 5, 2) }, + { LedId.LedMatrix15, (0x90, 77, 6, 2) }, + { LedId.LedMatrix16, (0x90, 78, 7, 2) }, + { LedId.LedMatrix17, (0x90, 61, 0, 3) }, + { LedId.LedMatrix18, (0x90, 62, 1, 3) }, + { LedId.LedMatrix19, (0x90, 63, 2, 3) }, + { LedId.LedMatrix20, (0x90, 64, 3, 3) }, + { LedId.LedMatrix21, (0x90, 65, 4, 3) }, + { LedId.LedMatrix22, (0x90, 66, 5, 3) }, + { LedId.LedMatrix23, (0x90, 67, 6, 3) }, + { LedId.LedMatrix24, (0x90, 68, 7, 3) }, + { LedId.LedMatrix25, (0x90, 51, 0, 4) }, + { LedId.LedMatrix26, (0x90, 52, 1, 4) }, + { LedId.LedMatrix27, (0x90, 53, 2, 4) }, + { LedId.LedMatrix28, (0x90, 54, 3, 4) }, + { LedId.LedMatrix29, (0x90, 55, 4, 4) }, + { LedId.LedMatrix30, (0x90, 56, 5, 4) }, + { LedId.LedMatrix31, (0x90, 57, 6, 4) }, + { LedId.LedMatrix32, (0x90, 58, 7, 4) }, + { LedId.LedMatrix33, (0x90, 41, 0, 5) }, + { LedId.LedMatrix34, (0x90, 42, 1, 5) }, + { LedId.LedMatrix35, (0x90, 43, 2, 5) }, + { LedId.LedMatrix36, (0x90, 44, 3, 5) }, + { LedId.LedMatrix37, (0x90, 45, 4, 5) }, + { LedId.LedMatrix38, (0x90, 46, 5, 5) }, + { LedId.LedMatrix39, (0x90, 47, 6, 5) }, + { LedId.LedMatrix40, (0x90, 48, 7, 5) }, + { LedId.LedMatrix41, (0x90, 31, 0, 6) }, + { LedId.LedMatrix42, (0x90, 32, 1, 6) }, + { LedId.LedMatrix43, (0x90, 33, 2, 6) }, + { LedId.LedMatrix44, (0x90, 34, 3, 6) }, + { LedId.LedMatrix45, (0x90, 35, 4, 6) }, + { LedId.LedMatrix46, (0x90, 36, 5, 6) }, + { LedId.LedMatrix47, (0x90, 37, 6, 6) }, + { LedId.LedMatrix48, (0x90, 38, 7, 6) }, + { LedId.LedMatrix49, (0x90, 21, 0, 7) }, + { LedId.LedMatrix50, (0x90, 22, 1, 7) }, + { LedId.LedMatrix51, (0x90, 23, 2, 7) }, + { LedId.LedMatrix52, (0x90, 24, 3, 7) }, + { LedId.LedMatrix53, (0x90, 25, 4, 7) }, + { LedId.LedMatrix54, (0x90, 26, 5, 7) }, + { LedId.LedMatrix55, (0x90, 27, 6, 7) }, + { LedId.LedMatrix56, (0x90, 28, 7, 7) }, + { LedId.LedMatrix57, (0x90, 11, 0, 8) }, + { LedId.LedMatrix58, (0x90, 12, 1, 8) }, + { LedId.LedMatrix59, (0x90, 13, 2, 8) }, + { LedId.LedMatrix60, (0x90, 14, 3, 8) }, + { LedId.LedMatrix61, (0x90, 15, 4, 8) }, + { LedId.LedMatrix62, (0x90, 16, 5, 8) }, + { LedId.LedMatrix63, (0x90, 17, 6, 8) }, + { LedId.LedMatrix64, (0x90, 18, 7, 8) }, + + { LedId.Custom1, (0xB0, 104, 0, 0) }, // Up + { LedId.Custom2, (0xB0, 105, 1, 0) }, // Down + { LedId.Custom3, (0xB0, 106, 2, 0) }, // Left + { LedId.Custom4, (0xB0, 107, 3, 0) }, // Right + { LedId.Custom5, (0xB0, 108, 4, 0) }, // Session + { LedId.Custom6, (0xB0, 109, 5, 0) }, // User 1 + { LedId.Custom7, (0xB0, 110, 6, 0) }, // User 2 + { LedId.Custom8, (0xB0, 111, 7, 0) }, // Mix + + { LedId.Custom9, (0x90, 89, 8, 1) }, //Scene1 + { LedId.Custom10, (0x90, 79, 8, 2) }, //Scene2 + { LedId.Custom11, (0x90, 69, 8, 3) }, //Scene3 + { LedId.Custom12, (0x90, 59, 8, 4) }, //Scene4 + { LedId.Custom13, (0x90, 49, 8, 5) }, //Scene5 + { LedId.Custom14, (0x90, 39, 8, 6) }, //Scene6 + { LedId.Custom15, (0x90, 29, 8, 7) }, //Scene7 + { LedId.Custom16, (0x90, 19, 8, 8) }, //Scene8 }; } } diff --git a/RGB.NET.Devices.Novation/Launchpad/LedIdMappings.cs b/RGB.NET.Devices.Novation/Launchpad/LedIdMappings.cs new file mode 100644 index 0000000..e264f1a --- /dev/null +++ b/RGB.NET.Devices.Novation/Launchpad/LedIdMappings.cs @@ -0,0 +1,8 @@ +namespace RGB.NET.Devices.Novation +{ + internal enum LedIdMappings + { + Current, + Legacy + } +} diff --git a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs index 3eabdf5..e00f114 100644 --- a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs +++ b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDevice.cs @@ -28,22 +28,13 @@ namespace RGB.NET.Devices.Novation /// protected override void InitializeLayout() { - Dictionary mapping = LaunchpadIdMapping.DEFAULT.SwapKeyValue(); + Dictionary mapping = GetDeviceMapping(); - //TODO DarthAffe 15.08.2017: Check if all launchpads are using the same basic layout const int BUTTON_SIZE = 20; - foreach (NovationLedId ledId in Enum.GetValues(typeof(NovationLedId))) + foreach (LedId ledId in mapping.Keys) { - Rectangle rectangle; - if (ledId.IsCustom()) - rectangle = new Rectangle(BUTTON_SIZE * (ledId.GetId() - 0x68), 0, BUTTON_SIZE, BUTTON_SIZE); - else if (ledId.IsScene()) - rectangle = new Rectangle(8 * BUTTON_SIZE, BUTTON_SIZE * (((int)ledId.GetId() / 0x10) + 1), BUTTON_SIZE, BUTTON_SIZE); - else if (ledId.IsGrid()) - rectangle = new Rectangle(BUTTON_SIZE * ((int)ledId.GetId() % 0x10), BUTTON_SIZE * (((int)ledId.GetId() / 0x10) + 1), BUTTON_SIZE, BUTTON_SIZE); - else continue; - - InitializeLed(mapping[ledId], rectangle); + (_, _, int x, int y) = mapping[ledId]; + InitializeLed(ledId, new Point(BUTTON_SIZE * x, BUTTON_SIZE * y), new Size(BUTTON_SIZE)); } string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); @@ -51,7 +42,15 @@ namespace RGB.NET.Devices.Novation } /// - protected override object CreateLedCustomData(LedId ledId) => LaunchpadIdMapping.DEFAULT.TryGetValue(ledId, out NovationLedId novationLedId) ? novationLedId : NovationLedId.Invalid; + protected override object CreateLedCustomData(LedId ledId) => GetDeviceMapping().TryGetValue(ledId, out (byte mode, byte id, int _, int __) data) ? (data.mode, data.id) : ((byte)0x00, (byte)0x00); + + protected virtual Dictionary GetDeviceMapping() + => DeviceInfo.LedIdMapping switch + { + LedIdMappings.Current => LaunchpadIdMapping.CURRENT, + LedIdMappings.Legacy => LaunchpadIdMapping.LEGACY, + _ => throw new ArgumentOutOfRangeException() + }; #endregion } diff --git a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDeviceInfo.cs b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDeviceInfo.cs index b854c26..ce86e05 100644 --- a/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Novation/Launchpad/NovationLaunchpadRGBDeviceInfo.cs @@ -8,6 +8,12 @@ namespace RGB.NET.Devices.Novation /// public class NovationLaunchpadRGBDeviceInfo : NovationRGBDeviceInfo { + #region Properties & Fields + + internal LedIdMappings LedIdMapping { get; } + + #endregion + #region Constructors /// @@ -17,9 +23,12 @@ namespace RGB.NET.Devices.Novation /// The represented device model. /// /// The of the . - internal NovationLaunchpadRGBDeviceInfo(string model, int deviceId, NovationColorCapabilities colorCapabilities) + internal NovationLaunchpadRGBDeviceInfo(string model, int deviceId, NovationColorCapabilities colorCapabilities, + LedIdMappings ledIdMapping) : base(RGBDeviceType.LedMatrix, model, deviceId, colorCapabilities) - { } + { + this.LedIdMapping = ledIdMapping; + } #endregion } diff --git a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs index b7890e8..4e031fe 100644 --- a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs +++ b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs @@ -85,11 +85,14 @@ namespace RGB.NET.Devices.Novation NovationDevices? deviceId = (NovationDevices?)Enum.GetValues(typeof(NovationDevices)) .Cast() - .FirstOrDefault(x => string.Equals(x.GetDeviceId(), outCaps.name, StringComparison.OrdinalIgnoreCase)); + .FirstOrDefault(x => x.GetDeviceId().ToUpperInvariant().Contains(outCaps.name.ToUpperInvariant())); if (deviceId == null) continue; - INovationRGBDevice device = new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo(outCaps.name, index, deviceId.GetColorCapability())); + NovationColorCapabilities colorCapability = deviceId.GetColorCapability(); + if (colorCapability == NovationColorCapabilities.None) continue; + + INovationRGBDevice device = new NovationLaunchpadRGBDevice(new NovationLaunchpadRGBDeviceInfo(outCaps.name, index, colorCapability, deviceId.GetLedIdMapping())); device.Initialize(UpdateTrigger); devices.Add(device); } From cb83135c6269efdabd19a6d912c783377e7668bf Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Mon, 7 Sep 2020 00:18:52 +0200 Subject: [PATCH 49/51] Allowed to use custom serial-connection implementations for WS281X-devices. --- .../Arduino/ArduinoWS2812USBUpdateQueue.cs | 24 +++---- .../Arduino/ArduinoWS281XDeviceDefinition.cs | 27 ++++++-- .../BitwizardWS2812USBUpdateQueue.cs | 6 +- .../BitwizardWS281XDeviceDefinition.cs | 27 ++++++-- .../Generic/ISerialConnection.cs | 62 ++++++++++++++++++ .../Generic/SerialPortConnection.cs | 63 +++++++++++++++++++ .../Generic/SerialPortUpdateQueue.cs | 22 +++---- 7 files changed, 193 insertions(+), 38 deletions(-) create mode 100644 RGB.NET.Devices.WS281X/Generic/ISerialConnection.cs create mode 100644 RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs index e9fea46..6b2c1cb 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Devices.WS281X.Arduino /// /// Represents the update-queue performing updates for arduino WS2812 devices. /// - public class ArduinoWS2812USBUpdateQueue : SerialPortUpdateQueue + public class ArduinoWS2812USBUpdateQueue : SerialConnectionUpdateQueue { #region Constants @@ -33,8 +33,8 @@ namespace RGB.NET.Devices.WS281X.Arduino /// The update trigger used by this queue. /// The name of the serial-port to connect to. /// The baud-rate used by the serial-connection. - public ArduinoWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, string portName, int baudRate = 115200) - : base(updateTrigger, portName, baudRate) + public ArduinoWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, ISerialConnection serialConnection) + : base(updateTrigger, serialConnection) { } #endregion @@ -45,7 +45,7 @@ namespace RGB.NET.Devices.WS281X.Arduino protected override void OnStartup(object sender, CustomUpdateData customData) { base.OnStartup(sender, customData); - + SendCommand(ASK_PROMPT_COMMAND); // Get initial prompt } @@ -75,26 +75,26 @@ namespace RGB.NET.Devices.WS281X.Arduino } /// - protected override void SendCommand(byte[] command) => SerialPort.Write(command, 0, command.Length); + protected override void SendCommand(byte[] command) => SerialConnection.Write(command, 0, command.Length); internal IEnumerable<(int channel, int ledCount)> GetChannels() { - if (!SerialPort.IsOpen) - SerialPort.Open(); + if (!SerialConnection.IsOpen) + SerialConnection.Open(); - SerialPort.DiscardInBuffer(); + SerialConnection.DiscardInBuffer(); SendCommand(ASK_PROMPT_COMMAND); - SerialPort.ReadTo(Prompt); + SerialConnection.ReadTo(Prompt); SendCommand(COUNT_COMMAND); - int channelCount = SerialPort.ReadByte(); + int channelCount = SerialConnection.ReadByte(); for (int i = 1; i <= channelCount; i++) { - SerialPort.ReadTo(Prompt); + SerialConnection.ReadTo(Prompt); byte[] channelLedCountCommand = { (byte)((i << 4) | COUNT_COMMAND[0]) }; SendCommand(channelLedCountCommand); - int ledCount = SerialPort.ReadByte(); + int ledCount = SerialConnection.ReadByte(); if (ledCount > 0) yield return (i, ledCount); } diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs index 0690926..ff1b88f 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs @@ -16,15 +16,20 @@ namespace RGB.NET.Devices.WS281X.Arduino { #region Properties & Fields + /// + /// Gets the serial-connection used for the device. + /// + public ISerialConnection SerialConnection { get; } + /// /// Gets the name of the serial-port to connect to. /// - public string Port { get; } + public string Port => SerialConnection?.Port; /// /// Gets the baud-rate used by the serial-connection. /// - public int BaudRate { get; set; } = 115200; + public int BaudRate => SerialConnection?.BaudRate ?? 0; /// /// Gets or sets the name used by this device. @@ -39,10 +44,20 @@ namespace RGB.NET.Devices.WS281X.Arduino /// /// Initializes a new instance of the class. /// - /// The name of the serial-port to connect to. - public ArduinoWS281XDeviceDefinition(string port) + /// The serial connection used for the device. + public ArduinoWS281XDeviceDefinition(ISerialConnection serialConnection) { - this.Port = port; + this.SerialConnection = serialConnection; + } + + /// + /// Initializes a new instance of the class. + /// + /// The name of the serial-port to connect to. + /// The baud-rate of the serial-connection. + public ArduinoWS281XDeviceDefinition(string port, int baudRate = 115200) + { + SerialConnection = new SerialPortConnection(port, baudRate); } #endregion @@ -52,7 +67,7 @@ namespace RGB.NET.Devices.WS281X.Arduino /// public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger) { - ArduinoWS2812USBUpdateQueue queue = new ArduinoWS2812USBUpdateQueue(updateTrigger, Port, BaudRate); + ArduinoWS2812USBUpdateQueue queue = new ArduinoWS2812USBUpdateQueue(updateTrigger, SerialConnection); IEnumerable<(int channel, int ledCount)> channels = queue.GetChannels(); int counter = 0; foreach ((int channel, int ledCount) in channels) diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs index 5b70008..dd6acc0 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBUpdateQueue.cs @@ -8,7 +8,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard /// /// Represents the update-queue performing updates for a bitwizard WS2812 device. /// - public class BitwizardWS2812USBUpdateQueue : SerialPortUpdateQueue + public class BitwizardWS2812USBUpdateQueue : SerialConnectionUpdateQueue { #region Constructors @@ -19,8 +19,8 @@ namespace RGB.NET.Devices.WS281X.Bitwizard /// The update trigger used by this queue. /// The name of the serial-port to connect to. /// The baud-rate used by the serial-connection. - public BitwizardWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, string portName, int baudRate = 115200) - : base(updateTrigger, portName, baudRate) + public BitwizardWS2812USBUpdateQueue(IDeviceUpdateTrigger updateTrigger, ISerialConnection serialConnection) + : base(updateTrigger, serialConnection) { } #endregion diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs index b769519..b7f61b3 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS281XDeviceDefinition.cs @@ -16,15 +16,20 @@ namespace RGB.NET.Devices.WS281X.Bitwizard { #region Properties & Fields + /// + /// Gets the serial-connection used for the device. + /// + public ISerialConnection SerialConnection { get; } + /// /// Gets the name of the serial-port to connect to. /// - public string Port { get; } + public string Port => SerialConnection?.Port; /// /// Gets the baud-rate used by the serial-connection. /// - public int BaudRate { get; set; } = 115200; + public int BaudRate => SerialConnection?.BaudRate ?? 0; /// /// Gets or sets the name used by this device. @@ -43,10 +48,20 @@ namespace RGB.NET.Devices.WS281X.Bitwizard /// /// Initializes a new instance of the class. /// - /// The name of the serial-port to connect to. - public BitwizardWS281XDeviceDefinition(string port) + /// The serial connection used for the device. + public BitwizardWS281XDeviceDefinition(ISerialConnection serialConnection) { - this.Port = port; + this.SerialConnection = serialConnection; + } + + /// + /// Initializes a new instance of the class. + /// + /// The name of the serial-port to connect to. + /// The baud-rate of the serial-connection. + public BitwizardWS281XDeviceDefinition(string port, int baudRate = 115200) + { + SerialConnection = new SerialPortConnection(port, baudRate); } #endregion @@ -56,7 +71,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard /// public IEnumerable CreateDevices(IDeviceUpdateTrigger updateTrigger) { - BitwizardWS2812USBUpdateQueue queue = new BitwizardWS2812USBUpdateQueue(updateTrigger, Port, BaudRate); + BitwizardWS2812USBUpdateQueue queue = new BitwizardWS2812USBUpdateQueue(updateTrigger, SerialConnection); string name = Name ?? $"Bitwizard WS2812 USB ({Port})"; BitwizardWS2812USBDevice device = new BitwizardWS2812USBDevice(new BitwizardWS2812USBDeviceInfo(name), queue); device.Initialize(StripLength); diff --git a/RGB.NET.Devices.WS281X/Generic/ISerialConnection.cs b/RGB.NET.Devices.WS281X/Generic/ISerialConnection.cs new file mode 100644 index 0000000..5851e7a --- /dev/null +++ b/RGB.NET.Devices.WS281X/Generic/ISerialConnection.cs @@ -0,0 +1,62 @@ +using System; + +namespace RGB.NET.Devices.WS281X +{ + /// + /// Represents a generic serial connection. + /// + public interface ISerialConnection : IDisposable + { + /// + /// Gets the COM-port used by the serial connection. + /// + string Port { get; } + + /// + /// Gets the baud-rate used by the serial connection. + /// + int BaudRate { get; } + + /// + /// Gets the connection-status of the serial connection. + /// true if connected; otherwise false. + /// + bool IsOpen { get; } + + /// + /// Opens the serial connection. + /// + void Open(); + + /// + /// Discards the in-buffer of the serial connection. + /// + void DiscardInBuffer(); + + /// + /// Reads a single byte from the serial connection + /// + /// The byte read. + byte ReadByte(); + + /// + /// Blocks till the provided char is received from the serial connection. + /// + /// The target-character to read to. + void ReadTo(char target); + + /// + /// Writes the provided data to the serial connection. + /// + /// The buffer containing the data to write. + /// The offset of the data in the buffer. + /// The amount of data to write. + void Write(byte[] buffer, int offset, int length); + + /// + /// Write the provided text to the serial connection followed by a line break. + /// + /// The text to write. + void WriteLine(string line); + } +} diff --git a/RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs b/RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs new file mode 100644 index 0000000..fded9dc --- /dev/null +++ b/RGB.NET.Devices.WS281X/Generic/SerialPortConnection.cs @@ -0,0 +1,63 @@ +using System.IO.Ports; + +namespace RGB.NET.Devices.WS281X +{ + /// + /// + /// Represents a serial-connection using the default microsoft serial-port implementation. + /// + public class SerialPortConnection : ISerialConnection + { + #region Properties & Fields + + /// + /// The used for the connection. + /// + public SerialPort SerialPort { get; } + + /// + public string Port => SerialPort.PortName; + + /// + public int BaudRate => SerialPort.BaudRate; + + /// + public bool IsOpen => SerialPort.IsOpen; + + #endregion + + #region Constructors + + public SerialPortConnection(string port, int baudRate) + { + SerialPort = new SerialPort(port, baudRate); + } + + #endregion + + #region Methods + + /// + public void Open() => SerialPort.Open(); + + /// + public void DiscardInBuffer() => SerialPort.DiscardInBuffer(); + + /// + public byte ReadByte() => (byte)SerialPort.ReadByte(); + + /// + public void ReadTo(char target) => SerialPort.ReadTo(target.ToString()); + + /// + public void Write(byte[] buffer, int offset, int length) => SerialPort.Write(buffer, offset, length); + + /// + public void WriteLine(string line) => SerialPort.WriteLine(line); + + /// + public void Dispose() => SerialPort.Dispose(); + + #endregion + } +} diff --git a/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs b/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs index 21504cf..0f343da 100644 --- a/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Generic/SerialPortUpdateQueue.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Devices.WS281X /// Represents a update queue for serial devices. /// /// The type of data sent through the serial connection. - public abstract class SerialPortUpdateQueue : UpdateQueue + public abstract class SerialConnectionUpdateQueue : UpdateQueue { #region Properties & Fields @@ -17,12 +17,12 @@ namespace RGB.NET.Devices.WS281X /// Gets or sets the prompt to wait for between sending commands. /// // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global - protected string Prompt { get; set; } = ">"; + protected char Prompt { get; set; } = '>'; /// /// Gets the serial port used by this queue. /// - protected SerialPort SerialPort { get; } + protected ISerialConnection SerialConnection { get; } #endregion @@ -30,15 +30,15 @@ namespace RGB.NET.Devices.WS281X /// /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The update trigger used by this queue. /// The name of the serial-port to connect to. /// The baud-rate used by the serial-connection. - internal SerialPortUpdateQueue(IDeviceUpdateTrigger updateTrigger, string portName, int baudRate = 115200) + internal SerialConnectionUpdateQueue(IDeviceUpdateTrigger updateTrigger, ISerialConnection serialConnection) : base(updateTrigger) { - SerialPort = new SerialPort(portName, baudRate); + SerialConnection = serialConnection; } #endregion @@ -50,10 +50,10 @@ namespace RGB.NET.Devices.WS281X { base.OnStartup(sender, customData); - if (!SerialPort.IsOpen) - SerialPort.Open(); + if (!SerialConnection.IsOpen) + SerialConnection.Open(); - SerialPort.DiscardInBuffer(); + SerialConnection.DiscardInBuffer(); } /// @@ -61,7 +61,7 @@ namespace RGB.NET.Devices.WS281X { foreach (TData command in GetCommands(dataSet)) { - SerialPort.ReadTo(Prompt); + SerialConnection.ReadTo(Prompt); SendCommand(command); } } @@ -78,7 +78,7 @@ namespace RGB.NET.Devices.WS281X /// This most likely needs to be overwritten if the data-type isn't string. /// /// The command to be sent. - protected virtual void SendCommand(TData command) => SerialPort.WriteLine((command as string) ?? string.Empty); + protected virtual void SendCommand(TData command) => SerialConnection.WriteLine((command as string) ?? string.Empty); #endregion } From 9acf8fc37f46a82a93247f7ca5b5e116869ed6e7 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Tue, 8 Sep 2020 21:47:39 +0100 Subject: [PATCH 50/51] Fixed Wooting One Mode key mapping --- .../Keyboard/WootingKeyboardLedMappings.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs index 2f032f6..dc9fa15 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs +++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardLedMappings.cs @@ -32,7 +32,7 @@ namespace RGB.NET.Devices.Wooting.Keyboard { LedId.Keyboard_F12, (0,13) }, { LedId.Keyboard_PrintScreen, (0,14) }, { LedId.Keyboard_PauseBreak, (0,15) }, - { LedId.Keyboard_Custom1, (0,20) }, + { LedId.Keyboard_Custom1, (0,16) }, { LedId.Keyboard_GraveAccentAndTilde, (1,0) }, { LedId.Keyboard_1, (1,1) }, @@ -128,7 +128,7 @@ namespace RGB.NET.Devices.Wooting.Keyboard { LedId.Keyboard_F12, (0,13) }, { LedId.Keyboard_PrintScreen, (0,14) }, { LedId.Keyboard_PauseBreak, (0,15) }, - { LedId.Keyboard_Custom1, (0,20) }, + { LedId.Keyboard_Custom1, (0,16) }, { LedId.Keyboard_GraveAccentAndTilde, (1,0) }, { LedId.Keyboard_1, (1,1) }, From 2e6ff339e0fa27f1cbb50247e33e9c30e514b9ad Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Thu, 10 Sep 2020 16:25:35 +0100 Subject: [PATCH 51/51] Updated wooting SDK functions to v1.2.0 https://github.com/WootingKb/wooting-rgb-sdk/releases/tag/v1.2.0 --- RGB.NET.Devices.Wooting/Native/_WootingSDK.cs | 8 +++++++- RGB.NET.Devices.Wooting/WootingDeviceProvider.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs index a9dee8e..1bb7dd9 100644 --- a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs +++ b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs @@ -46,7 +46,8 @@ namespace RGB.NET.Devices.Wooting.Native _getDeviceInfoPointer = (GetDeviceInfoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_device_info"), typeof(GetDeviceInfoPointer)); _keyboardConnectedPointer = (KeyboardConnectedPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_kbd_connected"), typeof(KeyboardConnectedPointer)); - _resetPointer = (ResetPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_reset"), typeof(ResetPointer)); + _resetPointer = (ResetPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_reset_rgb"), typeof(ResetPointer)); + _closePointer = (ClosePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_close"), typeof(ClosePointer)); _arrayUpdateKeyboardPointer = (ArrayUpdateKeyboardPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_array_update_keyboard"), typeof(ArrayUpdateKeyboardPointer)); _arraySetSinglePointer = (ArraySetSinglePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_array_set_single"), typeof(ArraySetSinglePointer)); } @@ -81,6 +82,7 @@ namespace RGB.NET.Devices.Wooting.Native private static GetDeviceInfoPointer _getDeviceInfoPointer; private static KeyboardConnectedPointer _keyboardConnectedPointer; private static ResetPointer _resetPointer; + private static ClosePointer _closePointer; private static ArrayUpdateKeyboardPointer _arrayUpdateKeyboardPointer; private static ArraySetSinglePointer _arraySetSinglePointer; @@ -97,6 +99,9 @@ namespace RGB.NET.Devices.Wooting.Native [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate bool ResetPointer(); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate bool ClosePointer(); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate bool ArrayUpdateKeyboardPointer(); @@ -108,6 +113,7 @@ namespace RGB.NET.Devices.Wooting.Native internal static IntPtr GetDeviceInfo() => _getDeviceInfoPointer(); internal static bool KeyboardConnected() => _keyboardConnectedPointer(); internal static bool Reset() => _resetPointer(); + internal static bool Close() => _closePointer(); internal static bool ArrayUpdateKeyboard() => _arrayUpdateKeyboardPointer(); internal static bool ArraySetSingle(byte row, byte column, byte red, byte green, byte blue) => _arraySetSinglePointer(row, column, red, green, blue); diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 638949a..9b83452 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -146,7 +146,7 @@ namespace RGB.NET.Devices.Wooting try { UpdateTrigger?.Dispose(); } catch { /* at least we tried */ } - try { _WootingSDK.Reset(); } + try { _WootingSDK.Close(); } catch { /* Unlucky.. */ } try { _WootingSDK.UnloadWootingSDK(); }