From 582afad5579138a735b4a4a6a8d6a5df8ea84697 Mon Sep 17 00:00:00 2001 From: denk_mal Date: Tue, 26 Jan 2021 09:29:33 +0100 Subject: [PATCH] Das Keyboard 4Q Fix-up Commits squashed and amended for code style by Adam Honse --- .../DasKeyboardController.cpp | 29 +++++++- .../DasKeyboardController.h | 2 + .../RGBController_DasKeyboard.cpp | 67 +++++++++++++------ .../RGBController_DasKeyboard.h | 9 +-- 4 files changed, 80 insertions(+), 27 deletions(-) diff --git a/Controllers/DasKeyboardController/DasKeyboardController.cpp b/Controllers/DasKeyboardController/DasKeyboardController.cpp index 31ebc01d..c7dec5d2 100644 --- a/Controllers/DasKeyboardController/DasKeyboardController.cpp +++ b/Controllers/DasKeyboardController/DasKeyboardController.cpp @@ -36,12 +36,39 @@ std::string DasKeyboardController::GetSerialString() std::wstring return_wstring = serial_string; std::string return_string(return_wstring.begin(), return_wstring.end()); + if(return_string.empty()) + { + return_string = version; + } + return return_string; } std::string DasKeyboardController::GetVersionString() { - return version; + std::string fw_version = "V"; + fw_version += version.substr(6, 2); + fw_version += "."; + fw_version += version.substr(15, 2); + fw_version += ".0"; + + return fw_version; +} + +std::string DasKeyboardController::GetLayoutString() +{ + /*-----------------------------------------------------*\ + | Experimental for now; should be '16' for US and '28' | + | for EU layout | + \*-----------------------------------------------------*/ + std::string layout_id = version.substr(3, 2); + + if (layout_id == "16") + { + return "US"; + } + + return "EU"; } void DasKeyboardController::SendColors(unsigned char key_id, unsigned char mode, diff --git a/Controllers/DasKeyboardController/DasKeyboardController.h b/Controllers/DasKeyboardController/DasKeyboardController.h index 1855b52e..56297aae 100644 --- a/Controllers/DasKeyboardController/DasKeyboardController.h +++ b/Controllers/DasKeyboardController/DasKeyboardController.h @@ -27,6 +27,8 @@ public: std::string GetVersionString(); + std::string GetLayoutString(); + void SendColors(unsigned char key_id, unsigned char mode, unsigned char red, unsigned char green, unsigned char blue); diff --git a/Controllers/DasKeyboardController/RGBController_DasKeyboard.cpp b/Controllers/DasKeyboardController/RGBController_DasKeyboard.cpp index 29ed0ad8..d91e83cd 100644 --- a/Controllers/DasKeyboardController/RGBController_DasKeyboard.cpp +++ b/Controllers/DasKeyboardController/RGBController_DasKeyboard.cpp @@ -14,13 +14,26 @@ using namespace std::chrono_literals; //0xFFFFFFFF indicates an unused entry in matrix #define NA 0xFFFFFFFF -static unsigned int matrix_map[7][21] = +// US Layout TODO: mus be checked/corrected +static unsigned int matrix_map_us[7][21] = { {NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 126, NA, NA, NA}, { 5, NA, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95, 101, 127, 128, 129, 130}, { 4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, 76, 82, 88, 94, 100, 106, 112, 118, 124}, - { 3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 80, 87, 93, 99, 105, 111, 117, 123}, - { 2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 81, NA, NA, NA, NA, 104, 110, 116, NA}, + { 3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, 7, 87, 93, 99, 105, 111, 117, 123}, + { 2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, NA, 80, NA, NA, NA, 104, 110, 116, NA}, + { 1, NA, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 79, NA, NA, 91, NA, 103, 109, 115, 122}, + { 0, 6, 12, NA, NA, NA, 36, NA, NA, NA, 60, 66, 72, 78, 84, 90, 96, 102, NA, 114, NA} + }; + +// EU Layout +static unsigned int matrix_map_eu[7][21] = + { + {NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 126, NA, NA, NA}, + { 5, NA, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95, 101, 127, 128, 129, 130}, + { 4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64, 70, 76, 82, 88, 94, 100, 106, 112, 118, 124}, + { 3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63, 69, 75, NA, 87, 93, 99, 105, 111, 117, 123}, + { 2, 8, 14, 20, 26, 32, 38, 44, 50, 56, 62, 68, 81, 80, NA, NA, NA, 104, 110, 116, NA}, { 1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 79, NA, NA, 91, NA, 103, 109, 115, 122}, { 0, 6, 12, NA, NA, NA, 36, NA, NA, NA, 60, 66, 72, 78, 84, 90, 96, 102, NA, 114, NA} }; @@ -40,22 +53,23 @@ static const unsigned int zone_sizes[] = 131 }; +// UK Layout static const char *led_names[] = { "Key: Left Control", "Key: Left Shift", "Key: Caps Lock", "Key: Tab", - "Key: ^", + "Key: `", "Key: Escape", "Key: Left Windows", - "Key: <", + "Key: \\ (ANSI)", "Key: A", "Key: Q", "Key: 1", "Undefined", "Key: Left Alt", - "Key: Y", + "Key: Z", "Key: S", "Key: W", "Key: 2", @@ -81,7 +95,7 @@ static const char *led_names[] = "Key: Space", "Key: B", "Key: H", - "Key: Z", + "Key: Y", "Key: 6", "Key: F5", "Undefined", @@ -104,21 +118,21 @@ static const char *led_names[] = "Key: F8", "Key: Right Alt", "Key: .", - "Key: O-Uml", + "Key: ;", "Key: P", "Key: 0", "Key: F9", "Key: Right Windows", + "Key: /", + "Key: '", + "Key: [", "Key: -", - "Key: A-Uml", - "Key: U-Uml", - "Key: SZ", "Key: F10", "Key: Menu", "Undefined", "Undefined", - "Key: +", - "Key: `", + "Key: ]", + "Key: =", "Key: F11", "Key: Right Control", "Key: Right Shift", @@ -187,7 +201,7 @@ RGBController_DasKeyboard::RGBController_DasKeyboard(DasKeyboardController *das_ updateDevice = true; name = "Das Keyboard Device"; - vendor = "Das Keyboard"; + vendor = "Metadot"; type = DEVICE_TYPE_KEYBOARD; description = "Das Keyboard Device"; location = das->GetDeviceLocation(); @@ -195,13 +209,13 @@ RGBController_DasKeyboard::RGBController_DasKeyboard(DasKeyboardController *das_ version = das->GetVersionString(); modes.resize(4); - modes[0].name = "Static"; - modes[0].value = DAS_KEYBOARD_MODE_STATIC; + modes[0].name = "Direct"; + modes[0].value = DAS_KEYBOARD_MODE_DIRECT; modes[0].flags = MODE_FLAG_HAS_PER_LED_COLOR; modes[0].color_mode = MODE_COLORS_PER_LED; - modes[1].name = "Blink"; - modes[1].value = DAS_KEYBOARD_MODE_BLINKING; + modes[1].name = "Flashing"; + modes[1].value = DAS_KEYBOARD_MODE_FLASHING; modes[1].flags = MODE_FLAG_HAS_PER_LED_COLOR; modes[1].color_mode = MODE_COLORS_PER_LED; @@ -210,8 +224,8 @@ RGBController_DasKeyboard::RGBController_DasKeyboard(DasKeyboardController *das_ modes[2].flags = MODE_FLAG_HAS_PER_LED_COLOR; modes[2].color_mode = MODE_COLORS_PER_LED; - modes[3].name = "Color Cycle"; - modes[3].value = DAS_KEYBOARD_MODE_COLOR_CYCLE; + modes[3].name = "Spectrum Cycle"; + modes[3].value = DAS_KEYBOARD_MODE_SPECTRUM_CYCLE; modes[3].flags = MODE_FLAG_HAS_PER_LED_COLOR; modes[3].color_mode = MODE_COLORS_PER_LED; @@ -249,7 +263,16 @@ void RGBController_DasKeyboard::SetupZones() new_zone.matrix_map = new matrix_map_type; new_zone.matrix_map->height = 7; new_zone.matrix_map->width = 21; - new_zone.matrix_map->map = (unsigned int *) &matrix_map; + + if(das->GetLayoutString() == "US") + { + new_zone.matrix_map->map = (unsigned int *) &matrix_map_us; + } + else + { + new_zone.matrix_map->map = (unsigned int *) &matrix_map_eu; + } + zones.push_back(new_zone); total_led_count += zone_sizes[zone_idx]; @@ -280,7 +303,7 @@ void RGBController_DasKeyboard::DeviceUpdateLEDs() void RGBController_DasKeyboard::UpdateZoneLEDs(int /*zone*/) { updateDevice = false; - + for(unsigned int led_idx = 0; led_idx < leds.size(); led_idx++) { UpdateSingleLED(static_cast(led_idx)); diff --git a/Controllers/DasKeyboardController/RGBController_DasKeyboard.h b/Controllers/DasKeyboardController/RGBController_DasKeyboard.h index c7e5c256..64f3b7da 100644 --- a/Controllers/DasKeyboardController/RGBController_DasKeyboard.h +++ b/Controllers/DasKeyboardController/RGBController_DasKeyboard.h @@ -14,10 +14,10 @@ enum { - DAS_KEYBOARD_MODE_STATIC = 0x01, - DAS_KEYBOARD_MODE_BLINKING = 0x1F, - DAS_KEYBOARD_MODE_BREATHING = 0x08, - DAS_KEYBOARD_MODE_COLOR_CYCLE = 0x14 + DAS_KEYBOARD_MODE_DIRECT = 0x01, + DAS_KEYBOARD_MODE_FLASHING = 0x1F, + DAS_KEYBOARD_MODE_BREATHING = 0x08, + DAS_KEYBOARD_MODE_SPECTRUM_CYCLE = 0x14 }; @@ -48,4 +48,5 @@ private: std::vector mode_index; std::vector double_buffer; bool updateDevice; + bool is_us_layout; };