diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp index c82446f5d..b9fc32d1c 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp @@ -119,7 +119,6 @@ void CorsairPeripheralV2Controller::SetRenderMode(corsair_v2_device_mode mode) buffer[5] = mode; hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - std::this_thread::sleep_for(2ms); hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); } @@ -140,7 +139,6 @@ void CorsairPeripheralV2Controller::LightingControl(uint8_t opt1, uint8_t opt2) buffer[5] = 0x00; hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - std::this_thread::sleep_for(2ms); hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); /*---------------------------------------------------------*\ @@ -152,11 +150,15 @@ void CorsairPeripheralV2Controller::LightingControl(uint8_t opt1, uint8_t opt2) buffer[5] = opt2; hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - std::this_thread::sleep_for(2ms); hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); } -void CorsairPeripheralV2Controller::GetAddress(uint8_t address) +unsigned int CorsairPeripheralV2Controller::GetKeyboardLayout() +{ + return GetAddress(0x41); +} + +unsigned int CorsairPeripheralV2Controller::GetAddress(uint8_t address) { uint8_t buffer[CORSAIR_V2_WRITE_SIZE]; uint8_t read[CORSAIR_V2_WRITE_SIZE]; @@ -169,11 +171,20 @@ void CorsairPeripheralV2Controller::GetAddress(uint8_t address) buffer[3] = address; hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - std::this_thread::sleep_for(2ms); hid_read_timeout(dev, read, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); + unsigned int temp = (unsigned int)(read[6] << 24 | read[5] << 16 | read[4] << 8 | read[3]); LOG_DEBUG("[%s] GetAddress %02X - %02X %02X - %02X %02X %02X %02X %02X %02X %02X %02X", device_name.c_str(), address, read[0], read[1], read[2], read[3], read[4], read[5], read[6], read[7], read[8], read[9]); + + uint8_t result = read[2]; + if(result > 0) + { + LOG_DEBUG("[%s] An error occurred! Get Address %02X failed - %d %s", device_name.c_str(), + address, result, (result == 5) ? "unsupported" : ""); + return -1; + } + return temp; } void CorsairPeripheralV2Controller::StartTransaction(uint8_t opt1) @@ -188,7 +199,6 @@ void CorsairPeripheralV2Controller::StartTransaction(uint8_t opt1) buffer[4] = 0x01; hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - std::this_thread::sleep_for(2ms); hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); } @@ -204,7 +214,6 @@ void CorsairPeripheralV2Controller::StopTransaction(uint8_t opt1) buffer[4] = opt1; hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - std::this_thread::sleep_for(2ms); hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); } @@ -239,8 +248,7 @@ void CorsairPeripheralV2Controller::SetLEDs(uint8_t *data, uint16_t data_size) memcpy(&buffer[offset1], &data[0], copy_bytes); hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - std::this_thread::sleep_for(2ms); - hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); + hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT_SHORT); remaining -= copy_bytes; buffer[2] = CORSAIR_V2_CMD_BLK_WN; @@ -261,8 +269,7 @@ void CorsairPeripheralV2Controller::SetLEDs(uint8_t *data, uint16_t data_size) memcpy(&buffer[offset2], &data[index], copy_bytes); hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - std::this_thread::sleep_for(2ms); - hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); + hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT_SHORT); remaining -= copy_bytes; } diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.h b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.h index 81d423b4a..4a6867413 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.h +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.h @@ -19,7 +19,8 @@ #define NA 0xFFFFFFFF #define HID_MAX_STR 255 -#define CORSAIR_V2_TIMEOUT 100 +#define CORSAIR_V2_TIMEOUT 50 +#define CORSAIR_V2_TIMEOUT_SHORT 3 #define CORSAIR_V2_VALUE_MODE 3 #define CORSAIR_V2_WRITE_WIRED_ID 8 #define CORSAIR_V2_WRITE_WIRELESS_ID 9 @@ -74,6 +75,7 @@ public: std::string GetName(); std::string GetSerialString(); const corsair_v2_device* GetDeviceData(); + unsigned int GetKeyboardLayout(); void SetRenderMode(corsair_v2_device_mode mode); void LightingControl(uint8_t opt1, uint8_t opt2); @@ -88,7 +90,7 @@ protected: std::string device_name; private: - void GetAddress(uint8_t address); + unsigned int GetAddress(uint8_t address); void StartTransaction(uint8_t opt1); void StopTransaction(uint8_t opt1); diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.cpp b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.cpp index c127c08b2..100dd43b1 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.cpp +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.cpp @@ -1,121 +1,54 @@ #include "CorsairPeripheralV2Devices.h" +/*-------------------------------------------------------------------------*\ +| Corsair Key Values | +\*-------------------------------------------------------------------------*/ + +std::vector corsair_full_size_values = +{ + /* ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PRSC SCLK PSBK */ + 41, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, + /* BKTK 1 2 3 4 5 6 7 8 9 0 - = BSPC INS HOME PGUP NMLK NMDV NMTM NMMI */ + 53, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 45, 46, 42, 73, 74, 75, 83, 84, 85, 86, + /* TAB Q W E R T Y U I O P [ ] \ DEL END PGDN NM7 NM8 NM9 NMPL */ + 43, 20, 26, 8, 21, 23, 28, 24, 12, 18, 19, 47, 48, 49, 76, 77, 78, 95, 96, 97, 87, + /* CPLK A S D F G H J K L ; " ENTR NM4 NM5 NM6 */ + 57, 4, 22, 7, 9, 10, 11, 13, 14, 15, 51, 52, 40, 92, 93, 94, + /* LSFT Z X C V B N M , . / RSFT ARWU NM1 NM2 NM3 NMER */ + 106, 29, 27, 6, 25, 5, 17, 16, 54, 55, 56, 110, 82, 89, 90, 91, 88, + /* LCTL LWIN LALT SPC RALT RFNC RMNU RCTL ARWR ARWD ARWR NM0 NMPD */ + 105, 108, 107, 44, 111, 122, 101, 109, 80, 81, 79, 98, 99, +}; + /*-------------------------------------------------------------------------*\ | KEYMAPS | \*-------------------------------------------------------------------------*/ -#define K60_KEYMAP_SIZE (sizeof(K60_keymap) / sizeof(K60_keymap[0])) - -static const corsair_v2_led K60_keymap[] = +keyboard_keymap_overlay_values corsair_K60_layout { - /*---------------------------------------------------------------------*\ - | Zone, Row, Column, Index, Name | - \*---------------------------------------------------------------------*/ - { 0, 0, 0, 41, KEY_EN_ESCAPE }, - { 0, 0, 2, 58, KEY_EN_F1 }, - { 0, 0, 3, 59, KEY_EN_F2 }, - { 0, 0, 4, 60, KEY_EN_F3 }, - { 0, 0, 5, 61, KEY_EN_F4 }, - { 0, 0, 6, 62, KEY_EN_F5 }, - { 0, 0, 7, 63, KEY_EN_F6 }, - { 0, 0, 8, 64, KEY_EN_F7 }, - { 0, 0, 9, 65, KEY_EN_F8 }, - { 0, 0, 10, 66, KEY_EN_F9 }, - { 0, 0, 11, 67, KEY_EN_F10 }, - { 0, 0, 12, 68, KEY_EN_F11 }, - { 0, 0, 13, 69, KEY_EN_F12 }, - { 0, 0, 14, 70, KEY_EN_PRINT_SCREEN }, - { 0, 0, 15, 71, KEY_EN_SCROLL_LOCK }, - { 0, 0, 16, 72, KEY_EN_PAUSE_BREAK }, - { 0, 1, 0, 53, KEY_EN_BACK_TICK }, - { 0, 1, 1, 30, KEY_EN_1 }, - { 0, 1, 2, 31, KEY_EN_2 }, - { 0, 1, 3, 32, KEY_EN_3 }, - { 0, 1, 4, 33, KEY_EN_4 }, - { 0, 1, 5, 34, KEY_EN_5 }, - { 0, 1, 6, 35, KEY_EN_6 }, - { 0, 1, 7, 36, KEY_EN_7 }, - { 0, 1, 8, 37, KEY_EN_8 }, - { 0, 1, 9, 38, KEY_EN_9 }, - { 0, 1, 10, 39, KEY_EN_0 }, - { 0, 1, 11, 45, KEY_EN_MINUS }, - { 0, 1, 12, 46, KEY_EN_EQUALS }, - { 0, 1, 13, 42, KEY_EN_BACKSPACE }, - { 0, 1, 14, 73, KEY_EN_INSERT }, - { 0, 1, 15, 74, KEY_EN_HOME }, - { 0, 1, 16, 75, KEY_EN_PAGE_UP }, - { 0, 1, 17, 83, KEY_EN_NUMPAD_LOCK }, - { 0, 1, 18, 84, KEY_EN_NUMPAD_DIVIDE }, - { 0, 1, 19, 85, KEY_EN_NUMPAD_TIMES }, - { 0, 1, 20, 86, KEY_EN_NUMPAD_MINUS }, - { 0, 2, 0, 43, KEY_EN_TAB }, - { 0, 2, 1, 20, KEY_EN_Q }, - { 0, 2, 2, 26, KEY_EN_W }, - { 0, 2, 3, 8, KEY_EN_E }, - { 0, 2, 4, 21, KEY_EN_R }, - { 0, 2, 5, 23, KEY_EN_T }, - { 0, 2, 6, 28, KEY_EN_Y }, - { 0, 2, 7, 24, KEY_EN_U }, - { 0, 2, 8, 12, KEY_EN_I }, - { 0, 2, 9, 18, KEY_EN_O }, - { 0, 2, 10, 19, KEY_EN_P }, - { 0, 2, 11, 47, KEY_EN_LEFT_BRACKET }, - { 0, 2, 12, 48, KEY_EN_RIGHT_BRACKET }, - { 0, 2, 13, 49, KEY_EN_ANSI_BACK_SLASH }, - { 0, 2, 14, 76, KEY_EN_DELETE }, - { 0, 2, 15, 77, KEY_EN_END }, - { 0, 2, 16, 78, KEY_EN_PAGE_DOWN }, - { 0, 2, 17, 95, KEY_EN_NUMPAD_7 }, - { 0, 2, 18, 96, KEY_EN_NUMPAD_8 }, - { 0, 2, 19, 97, KEY_EN_NUMPAD_9 }, - { 0, 2, 20, 87, KEY_EN_NUMPAD_PLUS }, - { 0, 3, 0, 57, KEY_EN_CAPS_LOCK }, - { 0, 3, 1, 4, KEY_EN_A }, - { 0, 3, 2, 22, KEY_EN_S }, - { 0, 3, 3, 7, KEY_EN_D }, - { 0, 3, 4, 9, KEY_EN_F }, - { 0, 3, 5, 10, KEY_EN_G }, - { 0, 3, 6, 11, KEY_EN_H }, - { 0, 3, 7, 13, KEY_EN_J }, - { 0, 3, 8, 14, KEY_EN_K }, - { 0, 3, 9, 15, KEY_EN_L }, - { 0, 3, 10, 51, KEY_EN_SEMICOLON }, - { 0, 3, 11, 52, KEY_EN_QUOTE }, - { 0, 3, 12, 50, KEY_EN_POUND }, - { 0, 3, 13, 40, KEY_EN_ANSI_ENTER }, - { 0, 3, 17, 92, KEY_EN_NUMPAD_4 }, - { 0, 3, 18, 93, KEY_EN_NUMPAD_5 }, - { 0, 3, 19, 94, KEY_EN_NUMPAD_6 }, - { 0, 4, 0, 106, KEY_EN_LEFT_SHIFT }, - { 0, 4, 1, 100, KEY_EN_ISO_BACK_SLASH }, - { 0, 4, 2, 29, KEY_EN_Z }, - { 0, 4, 3, 27, KEY_EN_X }, - { 0, 4, 4, 6, KEY_EN_C }, - { 0, 4, 5, 25, KEY_EN_V }, - { 0, 4, 6, 5, KEY_EN_B }, - { 0, 4, 7, 17, KEY_EN_N }, - { 0, 4, 8, 16, KEY_EN_M }, - { 0, 4, 9, 54, KEY_EN_COMMA }, - { 0, 4, 10, 55, KEY_EN_PERIOD }, - { 0, 4, 11, 56, KEY_EN_FORWARD_SLASH }, - { 0, 4, 13, 110, KEY_EN_RIGHT_SHIFT }, - { 0, 4, 15, 82, KEY_EN_UP_ARROW }, - { 0, 4, 17, 89, KEY_EN_NUMPAD_1 }, - { 0, 4, 18, 90, KEY_EN_NUMPAD_2 }, - { 0, 4, 19, 91, KEY_EN_NUMPAD_3 }, - { 0, 4, 20, 88, KEY_EN_NUMPAD_ENTER }, - { 0, 5, 0, 105, KEY_EN_LEFT_CONTROL }, - { 0, 5, 1, 108, KEY_EN_LEFT_WINDOWS }, - { 0, 5, 2, 107, KEY_EN_LEFT_ALT }, - { 0, 5, 6, 44, KEY_EN_SPACE }, - { 0, 5, 10, 111, KEY_EN_RIGHT_ALT }, - { 0, 5, 11, 122, KEY_EN_RIGHT_FUNCTION }, - { 0, 5, 12, 101, KEY_EN_MENU }, - { 0, 5, 13, 109, KEY_EN_RIGHT_CONTROL }, - { 0, 5, 14, 80, KEY_EN_LEFT_ARROW }, - { 0, 5, 15, 81, KEY_EN_DOWN_ARROW }, - { 0, 5, 16, 79, KEY_EN_RIGHT_ARROW }, - { 0, 5, 18, 98, KEY_EN_NUMPAD_0 }, - { 0, 5, 19, 99, KEY_EN_NUMPAD_PERIOD }, + KEYBOARD_SIZE::KEYBOARD_SIZE_FULL, + { + corsair_full_size_values, + { + { + KEYBOARD_LAYOUT_ISO_QWERTY, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + { 0, 3, 12, 50, KEY_EN_POUND, KEYBOARD_OPCODE_SWAP_ONLY, }, + { 0, 4, 1, 100, KEY_EN_ISO_BACK_SLASH, KEYBOARD_OPCODE_SWAP_ONLY, }, + } + }, + /* Add more regional layout fixes here */ + } + }, + { + /*---------------------------------------------------------------------------------------------------------*\ + | Edit Keys | + | Zone, Row, Column, Value, Key, OpCode, | + \*---------------------------------------------------------------------------------------------------------*/ + } }; /*-------------------------------------------------------------------------*\ @@ -187,8 +120,7 @@ static const corsair_v2_device ironclaw_wired_device = nullptr, nullptr }, - nullptr, - 0 + nullptr }; static const corsair_v2_device ironclaw_wireless_device = @@ -207,8 +139,7 @@ static const corsair_v2_device ironclaw_wireless_device = nullptr, nullptr }, - nullptr, - 0 + nullptr }; /*-------------------------------------------------------------*\ @@ -242,8 +173,7 @@ static const corsair_v2_device k55_rgb_pro_device = nullptr, nullptr }, - nullptr, - 0 + nullptr }; /*-------------------------------------------------------------*\ @@ -277,8 +207,7 @@ static const corsair_v2_device k60_rgb_pro_device = nullptr, nullptr }, - K60_keymap, - K60_KEYMAP_SIZE + &corsair_K60_layout }; /*-------------------------------------------------------------*\ @@ -312,8 +241,7 @@ static const corsair_v2_device k60_rgb_pro_lp_device = nullptr, nullptr }, - K60_keymap, - K60_KEYMAP_SIZE + &corsair_K60_layout }; /*-------------------------------------------------------------*\ @@ -358,8 +286,7 @@ static const corsair_v2_device m55_device = nullptr, nullptr }, - nullptr, - 0 + nullptr }; /*-------------------------------------------------------------*\ @@ -412,8 +339,7 @@ static const corsair_v2_device mm700_device = nullptr, nullptr }, - nullptr, - 0 + nullptr }; /*-------------------------------------------------------------------------*\ diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.h b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.h index a76e060d3..9c7a1d7db 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.h +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.h @@ -3,51 +3,59 @@ #include #include "RGBController.h" #include "RGBControllerKeyNames.h" +#include "KeyboardLayoutManager.h" -#define CORSAIR_ZONES_MAX 6 +#define CORSAIR_ZONES_MAX 6 enum corsair_v2_device_mode { - CORSAIR_V2_MODE_HW = 0x01, /* Hardware RGB mode */ - CORSAIR_V2_MODE_SW = 0x02, /* Software RGB mode */ + CORSAIR_V2_MODE_HW = 0x01, /* Hardware RGB mode */ + CORSAIR_V2_MODE_SW = 0x02, /* Software RGB mode */ }; enum corsair_v2_supports { - CORSAIR_V2_TYPE_SW_COLOUR_BLOCK = 1, - CORSAIR_V2_TYPE_HW_COLOUR_BLOCK = 2, - CORSAIR_V2_TYPE_SW_TRIPLETS = 3, - CORSAIR_V2_TYPE_HW_TRIPLETS = 4, + CORSAIR_V2_TYPE_SW_COLOUR_BLOCK = 1, + CORSAIR_V2_TYPE_HW_COLOUR_BLOCK = 2, + CORSAIR_V2_TYPE_SW_TRIPLETS = 3, + CORSAIR_V2_TYPE_HW_TRIPLETS = 4, +}; + +enum corsair_v2_kb_layout +{ + CORSAIR_V2_KB_LAYOUT_ANSI = 0x01, /* US ANSI Layout */ + CORSAIR_V2_KB_LAYOUT_ISO = 0x02, /* EURO ISO Layout */ + CORSAIR_V2_KB_LAYOUT_ABNT = 0x03, /* Brazilian Layout */ + CORSAIR_V2_KB_LAYOUT_JIS = 0x04, /* Japanese Layout */ }; typedef struct { - std::string name; - zone_type type; - uint8_t rows; - uint8_t cols; + std::string name; + zone_type type; + uint8_t rows; + uint8_t cols; } corsair_v2_zone; typedef struct { - uint8_t zone; - uint8_t row; - uint8_t col; - uint8_t index; - const char* name; + uint8_t zone; + uint8_t row; + uint8_t col; + uint8_t index; + const char* name; } corsair_v2_led; typedef struct { - uint16_t pid; - bool wireless; - device_type type; - corsair_v2_supports protocol; - uint8_t rows; - uint8_t cols; - const corsair_v2_zone* zones[CORSAIR_ZONES_MAX]; - const corsair_v2_led* layout; - uint16_t layout_size; + uint16_t pid; + bool wireless; + device_type type; + corsair_v2_supports protocol; + uint8_t rows; + uint8_t cols; + const corsair_v2_zone* zones[CORSAIR_ZONES_MAX]; + keyboard_keymap_overlay_values* layout_new; } corsair_v2_device; /*-----------------------------------------------------*\ diff --git a/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Hardware.cpp b/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Hardware.cpp index dcba9e8a4..30f5a809e 100644 --- a/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Hardware.cpp +++ b/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Hardware.cpp @@ -90,8 +90,28 @@ RGBController_CorsairV2HW::~RGBController_CorsairV2HW() void RGBController_CorsairV2HW::SetupZones() { + std::string physical_size; + KEYBOARD_LAYOUT new_layout; unsigned int max_led_value = 0; const corsair_v2_device* corsair = controller->GetDeviceData(); + unsigned int layout = controller->GetKeyboardLayout(); + + switch(layout) + { + case CORSAIR_V2_KB_LAYOUT_ISO: + new_layout = KEYBOARD_LAYOUT_ISO_QWERTY; + break; + + case CORSAIR_V2_KB_LAYOUT_JIS: + new_layout = KEYBOARD_LAYOUT_JIS; + break; + + case CORSAIR_V2_KB_LAYOUT_ANSI: + case CORSAIR_V2_KB_LAYOUT_ABNT: + default: + new_layout = KEYBOARD_LAYOUT_ANSI_QWERTY; + break; + } /*---------------------------------------------------------*\ | Fill in zones from the device data | @@ -111,44 +131,45 @@ void RGBController_CorsairV2HW::SetupZones() if(new_zone.type == ZONE_TYPE_MATRIX) { - new_zone.leds_count = corsair->layout_size; + KeyboardLayoutManager new_kb(new_layout, corsair->layout_new->base_size, corsair->layout_new->key_values); + matrix_map_type * new_map = new matrix_map_type; new_zone.matrix_map = new_map; new_map->height = corsair->zones[i]->rows; new_map->width = corsair->zones[i]->cols; + new_map->map = new unsigned int[new_map->height * new_map->width]; - new_map->map = new unsigned int[new_map->height * new_map->width]; - - /*---------------------------------------------------------*\ - | Create an empty matrix | - \*---------------------------------------------------------*/ - for(unsigned int y = 0; y < new_map->height; y++) + if(corsair->layout_new->base_size != KEYBOARD_SIZE_EMPTY) { - for(unsigned int x = 0; x < new_map->width; x++) + /*---------------------------------------------------------*\ + | Minor adjustments to keyboard layout | + \*---------------------------------------------------------*/ + new_zone.leds_count = new_kb.GetKeyCount(); + keyboard_keymap_overlay_values* temp = corsair->layout_new; + new_kb.ChangeKeys(*temp); + + /*---------------------------------------------------------*\ + | Matrix map still uses declared zone rows and columns | + | as the packet structure depends on the matrix map | + \*---------------------------------------------------------*/ + new_kb.GetKeyMap(new_map->map, KEYBOARD_MAP_FILL_TYPE_COUNT, new_map->height, new_map->width); + + /*---------------------------------------------------------*\ + | Create LEDs for the Matrix zone | + | Place keys in the layout to populate the matrix | + \*---------------------------------------------------------*/ + for(size_t led_idx = 0; led_idx < new_zone.leds_count; led_idx++) { - new_map->map[(y * new_map->width) + x] = NA; + led new_led; + + new_led.name = new_kb.GetKeyNameAt(led_idx); + new_led.value = new_kb.GetKeyValueAt(led_idx); + max_led_value = std::max(max_led_value, new_led.value); + leds.push_back(new_led); } } - /*---------------------------------------------------------*\ - | Create LEDs for the Matrix zone | - | Place keys in the layout to populate the matrix | - \*---------------------------------------------------------*/ - for(size_t led_idx = 0; led_idx < new_zone.leds_count; led_idx++) - { - led new_led; - - new_led.name = corsair->layout[led_idx].name; - new_led.value = corsair->layout[led_idx].index; - max_led_value = std::max(max_led_value, new_led.value); - leds.push_back(new_led); - - uint8_t layout_index = (corsair->layout[led_idx].row * new_map->width) - + corsair->layout[led_idx].col; - new_map->map[layout_index] = led_idx; - } - /*---------------------------------------------------------*\ | Add 1 the max_led_value to account for the 0th index | \*---------------------------------------------------------*/ diff --git a/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Software.cpp b/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Software.cpp index 19807e17f..43002e878 100644 --- a/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Software.cpp +++ b/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Software.cpp @@ -94,8 +94,28 @@ RGBController_CorsairV2SW::~RGBController_CorsairV2SW() void RGBController_CorsairV2SW::SetupZones() { + std::string physical_size; + KEYBOARD_LAYOUT new_layout; unsigned int max_led_value = 0; const corsair_v2_device* corsair = controller->GetDeviceData(); + unsigned int layout = controller->GetKeyboardLayout(); + + switch(layout) + { + case CORSAIR_V2_KB_LAYOUT_ISO: + new_layout = KEYBOARD_LAYOUT_ISO_QWERTY; + break; + + case CORSAIR_V2_KB_LAYOUT_JIS: + new_layout = KEYBOARD_LAYOUT_JIS; + break; + + case CORSAIR_V2_KB_LAYOUT_ANSI: + case CORSAIR_V2_KB_LAYOUT_ABNT: + default: + new_layout = KEYBOARD_LAYOUT_ANSI_QWERTY; + break; + } /*---------------------------------------------------------*\ | Fill in zones from the device data | @@ -115,44 +135,45 @@ void RGBController_CorsairV2SW::SetupZones() if(new_zone.type == ZONE_TYPE_MATRIX) { - new_zone.leds_count = corsair->layout_size; + KeyboardLayoutManager new_kb(new_layout, corsair->layout_new->base_size, corsair->layout_new->key_values); + matrix_map_type * new_map = new matrix_map_type; new_zone.matrix_map = new_map; new_map->height = corsair->zones[i]->rows; new_map->width = corsair->zones[i]->cols; + new_map->map = new unsigned int[new_map->height * new_map->width]; - new_map->map = new unsigned int[new_map->height * new_map->width]; - - /*---------------------------------------------------------*\ - | Create an empty matrix | - \*---------------------------------------------------------*/ - for(unsigned int y = 0; y < new_map->height; y++) + if(corsair->layout_new->base_size != KEYBOARD_SIZE_EMPTY) { - for(unsigned int x = 0; x < new_map->width; x++) + /*---------------------------------------------------------*\ + | Minor adjustments to keyboard layout | + \*---------------------------------------------------------*/ + new_zone.leds_count = new_kb.GetKeyCount(); + keyboard_keymap_overlay_values* temp = corsair->layout_new; + new_kb.ChangeKeys(*temp); + + /*---------------------------------------------------------*\ + | Matrix map still uses declared zone rows and columns | + | as the packet structure depends on the matrix map | + \*---------------------------------------------------------*/ + new_kb.GetKeyMap(new_map->map, KEYBOARD_MAP_FILL_TYPE_COUNT, new_map->height, new_map->width); + + /*---------------------------------------------------------*\ + | Create LEDs for the Matrix zone | + | Place keys in the layout to populate the matrix | + \*---------------------------------------------------------*/ + for(size_t led_idx = 0; led_idx < new_zone.leds_count; led_idx++) { - new_map->map[(y * new_map->width) + x] = NA; + led new_led; + + new_led.name = new_kb.GetKeyNameAt(led_idx); + new_led.value = new_kb.GetKeyValueAt(led_idx); + max_led_value = std::max(max_led_value, new_led.value); + leds.push_back(new_led); } } - /*---------------------------------------------------------*\ - | Create LEDs for the Matrix zone | - | Place keys in the layout to populate the matrix | - \*---------------------------------------------------------*/ - for(size_t led_idx = 0; led_idx < new_zone.leds_count; led_idx++) - { - led new_led; - - new_led.name = corsair->layout[led_idx].name; - new_led.value = corsair->layout[led_idx].index; - max_led_value = std::max(max_led_value, new_led.value); - leds.push_back(new_led); - - uint8_t layout_index = (corsair->layout[led_idx].row * new_map->width) - + corsair->layout[led_idx].col; - new_map->map[layout_index] = led_idx; - } - /*---------------------------------------------------------*\ | Add 1 the max_led_value to account for the 0th index | \*---------------------------------------------------------*/