diff --git a/Project-Aurora/Project-Aurora/Devices/Durgod/DurgodDevice.cs b/Project-Aurora/Project-Aurora/Devices/Durgod/DurgodDevice.cs new file mode 100644 index 000000000..62f0f521f --- /dev/null +++ b/Project-Aurora/Project-Aurora/Devices/Durgod/DurgodDevice.cs @@ -0,0 +1,122 @@ +using Aurora.Settings; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Linq; +using HidSharp; + +namespace Aurora.Devices.Durgod +{ + class DurgodDevice : DefaultDevice + { + public override string DeviceName => "Durgod"; + + HidDevice durgodKeyboard; + HidStream packetStream; + + public byte[] colorCodeBytes = new byte[378]; + public byte[] prevColorCodeBytes = new byte[378]; + private int currentKeyOffset; + + + public override bool Initialize() + { + + foreach (int keyboardID in DurgodRGBMappings.KeyboardIDs) + { + durgodKeyboard = GetDurgodKeyboard(DurgodRGBMappings.DurgodID, keyboardID); + if (durgodKeyboard != null) + { + try + { + IsInitialized = durgodKeyboard.TryOpen(out packetStream); + packetStream.Write(DurgodRGBMappings.RgbOff); + for (int c = 0; c < colorCodeBytes.Length; c++) colorCodeBytes[c] = 0xff; + } + catch + { + IsInitialized = false; + } + break; + } + else + { + IsInitialized = false; + } + } + + return IsInitialized; + } + + public override void Shutdown() + { + if (!IsInitialized) + return; + try + { + packetStream.Write(DurgodRGBMappings.RgbOn); + } + catch { } + + packetStream?.Dispose(); + packetStream?.Close(); + IsInitialized = false; + } + + + public override bool UpdateDevice(Dictionary keyColors, DoWorkEventArgs e, bool forced = false) + { + + int ROW_LENGTH = 42; + int ROW_COUNT = 9; + foreach (KeyValuePair kc in keyColors) + { + + if (!DurgodRGBMappings.DurgodColourOffsetMap.TryGetValue(kc.Key, out currentKeyOffset)) + { + continue; + } + colorCodeBytes[currentKeyOffset * 3] = (byte)kc.Value.R; + colorCodeBytes[currentKeyOffset * 3 + 1] = (byte)kc.Value.G; + colorCodeBytes[currentKeyOffset * 3 + 2] = (byte)kc.Value.B; + } + + if (!prevColorCodeBytes.SequenceEqual(colorCodeBytes)) + { + //Firstly we must send message about starting color changing + packetStream.Write(DurgodRGBMappings.RgbColormapStartMessage); + //Durgod requires 9 separated message for each key block + for (int row = 0; row < ROW_COUNT; row++) + { + int start = row * ROW_LENGTH; + int end = (row + 1) * ROW_LENGTH; + + byte[] segment = new byte[end - start]; + + + byte[] colourHeader = { 0x00, 0x03, 0x18, 0x08, (byte)row }; + byte[] header = new byte[47]; + + //Let's compose your message for keyboard + //Firstly we need magic bytes for color change + Array.Copy(colourHeader, 0, header, 0, colourHeader.Length); + //Secondly we need a slice which will appropriate to row + Array.Copy(colorCodeBytes, start, segment, 0, segment.Length); + //Finally we copy this slice to final message + Array.Copy(segment, 0, header, 5, segment.Length); + packetStream.Write(header); + + } + + colorCodeBytes.CopyTo(prevColorCodeBytes, 0); + + packetStream.Write(DurgodRGBMappings.RgbColormapEndMessage); + } + + return true; + } + + private HidDevice GetDurgodKeyboard(int VID, int PID) => DeviceList.Local.GetHidDevices(VID, PID).FirstOrDefault(HidDevice => HidDevice.GetMaxInputReportLength() == 65); + } +} diff --git a/Project-Aurora/Project-Aurora/Devices/Durgod/DurgodRGBMappings.cs b/Project-Aurora/Project-Aurora/Devices/Durgod/DurgodRGBMappings.cs new file mode 100644 index 000000000..0042906aa --- /dev/null +++ b/Project-Aurora/Project-Aurora/Devices/Durgod/DurgodRGBMappings.cs @@ -0,0 +1,130 @@ +using System.Collections.Generic; + +namespace Aurora.Devices.Durgod +{ + static class DurgodRGBMappings + { + public const int DurgodID = 0x2f68; + public static int[] KeyboardIDs = new int[] + { + 0x0082, // Durgod K310 + 0x0081 // Durgod K320 + }; + + public static byte[] RgbOff => new byte[] { 0x00, 0x03, 0x06, 0x86, 0x01 }; + public static byte[] RgbOn => new byte[] { 0x00, 0x03, 0x06, 0x86, 0x00 }; + public static byte[] RgbColormapStartMessage => new byte[] { 0x00, 0x03, 0x19, 0x66 }; + public static byte[] RgbColormapRowMessage => new byte[] { 0x00, 0x03, 0x18, 0x08 }; + public static byte[] RgbColormapEndMessage => new byte[] { 0x00, 0x03, 0x19, 0x88 }; + + //Keyboard represents as matrix of keys + public static int HEIGHT = 16; + public static int WIDTH = 8; + + public static Dictionary DurgodColourOffsetMap => new Dictionary + { + {DeviceKeys.ESC, 0 * WIDTH + 0 }, + + {DeviceKeys.F1, 0 * WIDTH + 2 }, + {DeviceKeys.F2, 0 * WIDTH + 3 }, + {DeviceKeys.F3, 0 * WIDTH + 4 }, + {DeviceKeys.F4, 0 * WIDTH + 5 }, + {DeviceKeys.F5, 0 * WIDTH + 6 }, + {DeviceKeys.F6, 0 * WIDTH + 7 }, + {DeviceKeys.F7, 1 * WIDTH + 0 }, + {DeviceKeys.F8, 1 * WIDTH + 1 }, + {DeviceKeys.F9, 1 * WIDTH + 2 }, + {DeviceKeys.F10, 1 * WIDTH + 3 }, + {DeviceKeys.F11, 1 * WIDTH + 4 }, + {DeviceKeys.F12, 1 * WIDTH + 5 }, + {DeviceKeys.PRINT_SCREEN, 1 * WIDTH + 6 }, + {DeviceKeys.SCROLL_LOCK, 1 * WIDTH + 7 }, + {DeviceKeys.PAUSE_BREAK, 2 * WIDTH + 0}, + + {DeviceKeys.TILDE, 2 * WIDTH + 5 }, + {DeviceKeys.ONE, 2 * WIDTH + 6 }, + {DeviceKeys.TWO, 2 * WIDTH + 7 }, + {DeviceKeys.THREE, 3 * WIDTH + 0 }, + {DeviceKeys.FOUR, 3 * WIDTH + 1 }, + {DeviceKeys.FIVE, 3 * WIDTH + 2 }, + {DeviceKeys.SIX, 3 * WIDTH + 3 }, + {DeviceKeys.SEVEN, 3 * WIDTH + 4 }, + {DeviceKeys.EIGHT, 3 * WIDTH + 5 }, + {DeviceKeys.NINE, 3 * WIDTH + 6 }, + {DeviceKeys.ZERO, 3 * WIDTH + 7 }, + {DeviceKeys.MINUS, 4 * WIDTH + 0 }, + {DeviceKeys.EQUALS, 4 * WIDTH + 1 }, + {DeviceKeys.BACKSPACE, 4 * WIDTH + 2 }, + {DeviceKeys.INSERT, 4 * WIDTH + 3 }, + {DeviceKeys.HOME, 4 * WIDTH + 4 }, + {DeviceKeys.PAGE_UP, 4 * WIDTH + 5 }, + + {DeviceKeys.TAB, 5 * WIDTH + 2 }, + {DeviceKeys.Q, 5 * WIDTH + 3}, + {DeviceKeys.W, 5 * WIDTH + 4}, + {DeviceKeys.E, 5 * WIDTH + 5}, + {DeviceKeys.R, 5 * WIDTH + 6}, + {DeviceKeys.T, 5 * WIDTH + 7}, + {DeviceKeys.Y, 6 * WIDTH + 0}, + {DeviceKeys.U, 6 * WIDTH + 1}, + {DeviceKeys.I, 6 * WIDTH + 2}, + {DeviceKeys.O, 6 * WIDTH + 3}, + {DeviceKeys.P, 6 * WIDTH + 4}, + {DeviceKeys.OPEN_BRACKET, 6 * WIDTH + 5 }, + {DeviceKeys.CLOSE_BRACKET, 6 * WIDTH + 6 }, + {DeviceKeys.BACKSLASH, 6 * WIDTH + 7 }, + {DeviceKeys.BACKSLASH_UK, 6 * WIDTH + 7 }, + + + {DeviceKeys.CAPS_LOCK, 7 * WIDTH + 7 }, + {DeviceKeys.A, 8 * WIDTH + 0}, + {DeviceKeys.S, 8 * WIDTH + 1}, + {DeviceKeys.D, 8 * WIDTH + 2}, + {DeviceKeys.F, 8 * WIDTH + 3}, + {DeviceKeys.G, 8 * WIDTH + 4}, + {DeviceKeys.H, 8 * WIDTH + 5}, + {DeviceKeys.J, 8 * WIDTH + 6}, + {DeviceKeys.K, 8 * WIDTH + 7}, + {DeviceKeys.L, 9 * WIDTH + 0}, + {DeviceKeys.SEMICOLON, 9 * WIDTH + 1}, + {DeviceKeys.APOSTROPHE, 9 * WIDTH + 2}, + {DeviceKeys.HASHTAG, 9 * WIDTH + 3}, + {DeviceKeys.ENTER, 9 * WIDTH + 4}, + {DeviceKeys.DELETE, 7 * WIDTH + 0 }, + {DeviceKeys.END, 7 * WIDTH + 1 }, + {DeviceKeys.PAGE_DOWN, 7 * WIDTH + 2 }, + + + {DeviceKeys.LEFT_SHIFT, 10 * WIDTH + 4 }, + {DeviceKeys.Z, 10 * WIDTH + 6}, + {DeviceKeys.X, 10 * WIDTH + 7}, + {DeviceKeys.C, 11 * WIDTH + 0}, + {DeviceKeys.V, 11 * WIDTH + 1}, + {DeviceKeys.B, 11 * WIDTH + 2}, + {DeviceKeys.N, 11 * WIDTH + 3}, + {DeviceKeys.M, 11 * WIDTH + 4}, + {DeviceKeys.COMMA, 11 * WIDTH + 5}, + {DeviceKeys.PERIOD, 11 * WIDTH + 6 }, + {DeviceKeys.FORWARD_SLASH, 11 * WIDTH + 7 }, + {DeviceKeys.RIGHT_SHIFT, 12 * WIDTH + 1 }, + + {DeviceKeys.LEFT_CONTROL, 13 * WIDTH + 1 }, + {DeviceKeys.LEFT_WINDOWS, 13 * WIDTH + 2 }, + {DeviceKeys.LEFT_ALT, 13 * WIDTH + 3 }, + {DeviceKeys.SPACE, 13 * WIDTH + 7 }, + {DeviceKeys.RIGHT_ALT, 14 * WIDTH + 3 }, + {DeviceKeys.FN_Key, 14 * WIDTH + 4 }, + {DeviceKeys.RIGHT_WINDOWS, 14 * WIDTH + 5 }, //Context menu (???) + {DeviceKeys.APPLICATION_SELECT, 14 * WIDTH + 5 }, //Context menu (???) + {DeviceKeys.RIGHT_CONTROL, 14 * WIDTH + 6 }, + + {DeviceKeys.ARROW_UP, 12 * WIDTH + 3 }, + {DeviceKeys.ARROW_DOWN, 15 * WIDTH + 0 }, + {DeviceKeys.ARROW_LEFT, 14 * WIDTH + 7 }, + {DeviceKeys.ARROW_RIGHT, 15 * WIDTH + 1 }, + + }; + + + } +} \ No newline at end of file diff --git a/Project-Aurora/Project-Aurora/Settings/Configuration.cs b/Project-Aurora/Project-Aurora/Settings/Configuration.cs index 9c87116e2..cf004b0a2 100755 --- a/Project-Aurora/Project-Aurora/Settings/Configuration.cs +++ b/Project-Aurora/Project-Aurora/Settings/Configuration.cs @@ -307,7 +307,10 @@ public enum PreferredKeyboard //HyperX range is 1400-1499 [Description("HyperX Alloy Elite RGB")] HyperX_Alloy_Elite_RGB = 1400, - + + //Durgod range is 1500-1599 + [Description("Durgod K320 Nebula RGB")] + Durgod_K320_RGB = 1500, } public enum PreferredKeyboardLocalization diff --git a/Project-Aurora/Project-Aurora/Settings/KeyboardLayoutManager.cs b/Project-Aurora/Project-Aurora/Settings/KeyboardLayoutManager.cs index 80a9357d8..ed8fbd79b 100755 --- a/Project-Aurora/Project-Aurora/Settings/KeyboardLayoutManager.cs +++ b/Project-Aurora/Project-Aurora/Settings/KeyboardLayoutManager.cs @@ -796,6 +796,8 @@ public void LoadBrand(PreferredKeyboard keyboard_preference = PreferredKeyboard. layoutConfigPath = Path.Combine(layoutsPath, "omen_four_zone.json"); else if (keyboard_preference == PreferredKeyboard.HyperX_Alloy_Elite_RGB) layoutConfigPath = Path.Combine(layoutsPath, "hyperx_alloy_elite_rgb.json"); + else if (keyboard_preference == PreferredKeyboard.Durgod_K320_RGB) + layoutConfigPath = Path.Combine(layoutsPath, "durgod_k320_nebula_rgb.json"); else { diff --git a/Project-Aurora/Project-Aurora/kb_layouts/Extra Features/durgod_k320_nebula_rgb_features.json b/Project-Aurora/Project-Aurora/kb_layouts/Extra Features/durgod_k320_nebula_rgb_features.json new file mode 100644 index 000000000..c6194f966 --- /dev/null +++ b/Project-Aurora/Project-Aurora/kb_layouts/Extra Features/durgod_k320_nebula_rgb_features.json @@ -0,0 +1,24 @@ +{ + "group_tag": "keyboard", + "origin_region": 1, + "grouped_keys": [ + { + "visualName": "\\", + "tag": 51, + "margin_left": 500, + "margin_top": 74, + "width": 47.0, + "height": 30.0, + "font_size": 9.0, + "width_bits": 5, + "height_bits": 3, + "margin_left_bits": 0, + "margin_top_bits": 6, + "enabled": true, + "absolute_location": true + } + ], + "key_conversion": { + 77: 51 + } +} \ No newline at end of file diff --git a/Project-Aurora/Project-Aurora/kb_layouts/durgod_k320_nebula_rgb.json b/Project-Aurora/Project-Aurora/kb_layouts/durgod_k320_nebula_rgb.json new file mode 100644 index 000000000..d0523f92d --- /dev/null +++ b/Project-Aurora/Project-Aurora/kb_layouts/durgod_k320_nebula_rgb.json @@ -0,0 +1,185 @@ +{ + "keys_to_remove": [ + 34, + 35, + 36, + 37, + 55, + 56, + 57, + 58, + 73, + 74, + 75, + 90, + 91, + 92, + 93, + 105, + 106, + 71 + + ], + "keys_to_set_as_new_line": [ + 16, + 33, + 54, + 89, + 104 + ], + "key_modifications": { + "16": { + "visualName": null, + "tag": 16, + "line_break": true, + "margin_left": null, + "margin_top": null, + "width": null, + "height": null, + "font_size": null, + "width_bits": null, + "height_bits": null, + "margin_left_bits": null, + "margin_top_bits": null, + "enabled": null + }, + "33": { + "visualName": null, + "tag": 33, + "line_break": true, + "margin_left": null, + "margin_top": null, + "width": null, + "height": null, + "font_size": null, + "width_bits": null, + "height_bits": null, + "margin_left_bits": null, + "margin_top_bits": null, + "enabled": null + }, + "50": { + "visualName": null, + "tag": 50, + "line_break": false, + "margin_left": null, + "margin_top": null, + "width": 30, + "height": null, + "font_size": null, + "width_bits": null, + "height_bits": null, + "margin_left_bits": null, + "margin_top_bits": null, + "enabled": null + }, + "52": { + "visualName": null, + "tag": 52, + "line_break": false, + "margin_left": 68, + "margin_top": null, + "width": null, + "height": null, + "font_size": null, + "width_bits": null, + "height_bits": null, + "margin_left_bits": null, + "margin_top_bits": null, + "enabled": null + }, + "54": { + "visualName": null, + "tag": 54, + "line_break": true, + "margin_left": null, + "margin_top": null, + "width": null, + "height": null, + "font_size": null, + "width_bits": null, + "height_bits": null, + "margin_left_bits": null, + "margin_top_bits": null, + "enabled": null + }, + "72": { + "visualName": "ENTER", + "tag": 72, + "line_break": true, + "margin_left": 7.0, + "margin_top": 0.0, + "width": 74.0, + "height": 30.0, + "font_size": 12.0, + "width_bits": 7, + "height_bits": 3, + "margin_left_bits": 0, + "margin_top_bits": 0, + "enabled": null + }, + "89": { + "visualName": null, + "tag": 89, + "line_break": true, + "margin_left": null, + "margin_top": null, + "width": null, + "height": null, + "font_size": null, + "width_bits": null, + "height_bits": null, + "margin_left_bits": null, + "margin_top_bits": null, + "enabled": null + }, + "99": { + "visualName": "FN", + "tag": 107, + "line_break": null, + "margin_left": null, + "margin_top": null, + "width": null, + "height": null, + "font_size": null, + "width_bits": null, + "height_bits": null, + "margin_left_bits": null, + "margin_top_bits": null, + "enabled": null + }, + "100": { + "visualName": "APP", + "tag": 100, + "line_break": null, + "margin_left": null, + "margin_top": null, + "width": null, + "height": null, + "font_size": null, + "width_bits": null, + "height_bits": null, + "margin_left_bits": null, + "margin_top_bits": null, + "enabled": null + }, + "104": { + "visualName": null, + "tag": 104, + "line_break": true, + "margin_left": null, + "margin_top": null, + "width": null, + "height": null, + "font_size": null, + "width_bits": null, + "height_bits": null, + "margin_left_bits": null, + "margin_top_bits": null, + "enabled": null + } + }, + "included_features": [ + "durgod_k320_nebula_rgb_features.json" + ] +} \ No newline at end of file