From 4fbcf883fe570812e19fe31a6f1a3c2946d52e27 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 7 Aug 2023 23:11:50 +1000 Subject: [PATCH] Initial commit for the Corsair Dark Core Pro SE mouse * Reworked wireless Corsair Slipstream detection to be generic for all devices * Adding key layout and metadata to CorsairPeripheralV2Devices.cpp * Adding new detector --- .../CorsairPeripheralV2Controller.cpp | 145 +++++++++++++----- .../CorsairPeripheralV2Controller.h | 16 +- .../CorsairPeripheralV2ControllerDetect.cpp | 30 ++-- .../CorsairPeripheralV2Devices.cpp | 143 +++++++++++------ .../CorsairPeripheralV2Devices.h | 7 +- .../CorsairPeripheralV2HardwareController.cpp | 33 ++-- .../CorsairPeripheralV2HardwareController.h | 2 +- .../CorsairPeripheralV2SoftwareController.cpp | 4 +- .../CorsairPeripheralV2SoftwareController.h | 2 +- .../RGBController_CorsairV2Hardware.cpp | 10 +- .../RGBController_CorsairV2Software.cpp | 38 ++--- 11 files changed, 273 insertions(+), 157 deletions(-) diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp index b9fc32d1..7715fc6c 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp @@ -11,7 +11,7 @@ using namespace std::chrono_literals; -CorsairPeripheralV2Controller::CorsairPeripheralV2Controller(hid_device* dev_handle, const char* path, std::string /*name*/, uint16_t pid) +CorsairPeripheralV2Controller::CorsairPeripheralV2Controller(hid_device* dev_handle, const char* path, std::string /*name*/) { const uint8_t sz = HID_MAX_STR; wchar_t tmp[sz]; @@ -27,37 +27,83 @@ CorsairPeripheralV2Controller::CorsairPeripheralV2Controller(hid_device* dev_han wName = std::wstring(tmp); device_name.append(" ").append(std::string(wName.begin(), wName.end())); - for(size_t i = 0; i < CORSAIR_V2_DEVICE_COUNT; i++) + /*---------------------------------------------------------*\ + | Get PID | + | If the PID is in the know wireless receivers list | + | switch the write_cmd to talk to the device and retry | + \*---------------------------------------------------------*/ + unsigned int pid = GetAddress(0x12); + + switch(pid) + { + case CORSAIR_SLIPSTREAM_WIRELESS_PID: + write_cmd = CORSAIR_V2_WRITE_WIRELESS_ID; + pid = GetAddress(0x12); + break; + } + + /*---------------------------------------------------------*\ + | If the hid_pid passed in from the detector does not match | + | the pid reported by the device then it is likey | + | behind a wireless receiver. | + \*---------------------------------------------------------*/ + LOG_DEBUG("[%s] Setting write CMD to %02X for %s mode for PID %04X", device_name.c_str(), + write_cmd, (write_cmd == CORSAIR_V2_WRITE_WIRELESS_ID) ? "wireless" : "wired", pid); + + /*---------------------------------------------------------*\ + | Get VID | + | NB: this can be achieved with GetAddress(0x11) but we | + | also need to set the packet length capabilities for | + | the device being set up. | + \*---------------------------------------------------------*/ + uint8_t buffer[CORSAIR_V2_PACKET_SIZE]; + buffer[1] = write_cmd; + buffer[2] = CORSAIR_V2_CMD_GET; + buffer[3] = 0x11; + hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); + uint16_t result = hid_read_timeout(dev, buffer, CORSAIR_V2_PACKET_SIZE, CORSAIR_V2_TIMEOUT); + result++; + pkt_sze = result; + LOG_DEBUG("[%s] Packet length set to %d", device_name.c_str(), pkt_sze); + + /*---------------------------------------------------------*\ + | NB: If the device is not found in the device list | + | then wireless mode may not work reliably | + \*---------------------------------------------------------*/ + bool not_found = true; + + for(uint16_t i = 0; i < CORSAIR_V2_DEVICE_COUNT; i++) { if(corsair_v2_device_list[i]->pid == pid) { /*---------------------------------------------------------*\ | Set device ID | \*---------------------------------------------------------*/ + not_found = false; device_index = i; + break; } } - /*---------------------------------------------------------*\ - | NB: If the device is not found in the device list | - | then wireless mode may not work reliably | - \*---------------------------------------------------------*/ - bool wireless = corsair_v2_device_list[device_index]->wireless; - if(wireless) + if(not_found) { - write_cmd = CORSAIR_V2_WRITE_WIRELESS_ID; + LOG_ERROR("[%s] device capabilities not found. Please creata a new device request.", + device_name.c_str()); } - LOG_DEBUG("[%s] Setting write CMD to %02X for %s mode", device_name.c_str(), - write_cmd, (wireless) ? "wireless" : "wired" ); /*---------------------------------------------------------*\ - | Get VID | + | Check lighting control endpoints | + | If lighting control endpoint 2 is unavailable | + | then use endpoint 1. | \*---------------------------------------------------------*/ - GetAddress(0x11); - /*---------------------------------------------------------*\ - | Get PID | - \*---------------------------------------------------------*/ - GetAddress(0x12); + result = StartTransaction(0); + if(result > 0) + { + light_ctrl = CORSAIR_V2_LIGHT_CTRL1; + StartTransaction(0); + } + StopTransaction(0); + LOG_DEBUG("[%s] Lighting Endpoint set to %02X", device_name.c_str(), light_ctrl); } CorsairPeripheralV2Controller::~CorsairPeripheralV2Controller() @@ -75,6 +121,21 @@ std::string CorsairPeripheralV2Controller::GetDeviceLocation() return("HID: " + location); } +std::string CorsairPeripheralV2Controller::GetErrorString(uint8_t err) +{ + switch(err) + { + case 1: + return "Invalid Value"; + case 3: + return "Failed"; + case 5: + return "Unsupported"; + default: + return "Protocol Error (Unknown)"; + } +} + std::string CorsairPeripheralV2Controller::GetFirmwareString() { return ""; @@ -122,7 +183,7 @@ void CorsairPeripheralV2Controller::SetRenderMode(corsair_v2_device_mode mode) hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); } -void CorsairPeripheralV2Controller::LightingControl(uint8_t opt1, uint8_t opt2) +void CorsairPeripheralV2Controller::LightingControl(uint8_t opt1) { uint8_t buffer[CORSAIR_V2_WRITE_SIZE]; @@ -140,17 +201,6 @@ void CorsairPeripheralV2Controller::LightingControl(uint8_t opt1, uint8_t opt2) hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); - - /*---------------------------------------------------------*\ - | Open a RGB lighting handle | - \*---------------------------------------------------------*/ - buffer[2] = 0x0D; - buffer[3] = 0x00; - buffer[4] = 0x01; - buffer[5] = opt2; - - hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); } unsigned int CorsairPeripheralV2Controller::GetKeyboardLayout() @@ -181,13 +231,13 @@ unsigned int CorsairPeripheralV2Controller::GetAddress(uint8_t address) if(result > 0) { LOG_DEBUG("[%s] An error occurred! Get Address %02X failed - %d %s", device_name.c_str(), - address, result, (result == 5) ? "unsupported" : ""); + address, result, GetErrorString(result).c_str()); return -1; } return temp; } -void CorsairPeripheralV2Controller::StartTransaction(uint8_t opt1) +unsigned char CorsairPeripheralV2Controller::StartTransaction(uint8_t opt1) { uint8_t buffer[CORSAIR_V2_WRITE_SIZE]; @@ -196,10 +246,12 @@ void CorsairPeripheralV2Controller::StartTransaction(uint8_t opt1) buffer[1] = write_cmd; buffer[2] = CORSAIR_V2_CMD_START_TX; buffer[3] = opt1; - buffer[4] = 0x01; + buffer[4] = light_ctrl; hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); + + return buffer[2]; } void CorsairPeripheralV2Controller::StopTransaction(uint8_t opt1) @@ -217,15 +269,28 @@ void CorsairPeripheralV2Controller::StopTransaction(uint8_t opt1) hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); } +void CorsairPeripheralV2Controller::ClearPacketBuffer() +{ + uint8_t result = 0; + uint8_t buffer[CORSAIR_V2_PACKET_SIZE]; + + do + { + result = hid_read_timeout(dev, buffer, pkt_sze, CORSAIR_V2_TIMEOUT_SHORT); + } + while(result > 0); +} + void CorsairPeripheralV2Controller::SetLEDs(uint8_t *data, uint16_t data_size) { const uint8_t offset1 = 8; const uint8_t offset2 = 4; uint16_t remaining = data_size; - uint8_t buffer[CORSAIR_V2_WRITE_SIZE]; - memset(buffer, 0, CORSAIR_V2_WRITE_SIZE); + uint8_t buffer[CORSAIR_V2_PACKET_SIZE]; + memset(buffer, 0, CORSAIR_V2_PACKET_SIZE); + ClearPacketBuffer(); StartTransaction(0); /*---------------------------------------------------------*\ | Set the data header in packet 1 with the data length | @@ -239,7 +304,7 @@ void CorsairPeripheralV2Controller::SetLEDs(uint8_t *data, uint16_t data_size) /*---------------------------------------------------------*\ | Check if the data needs more than 1 packet | \*---------------------------------------------------------*/ - uint16_t copy_bytes = CORSAIR_V2_WRITE_SIZE - offset1; + uint16_t copy_bytes = pkt_sze - offset1; if(remaining < copy_bytes) { copy_bytes = remaining; @@ -247,12 +312,12 @@ 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); - hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT_SHORT); + hid_write(dev, buffer, pkt_sze); + hid_read_timeout(dev, buffer, pkt_sze, CORSAIR_V2_TIMEOUT_SHORT); remaining -= copy_bytes; buffer[2] = CORSAIR_V2_CMD_BLK_WN; - copy_bytes = CORSAIR_V2_WRITE_SIZE - offset2; + copy_bytes = pkt_sze - offset2; /*---------------------------------------------------------*\ | Send the remaining packets | @@ -268,8 +333,8 @@ 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); - hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT_SHORT); + hid_write(dev, buffer, pkt_sze); + hid_read_timeout(dev, buffer, pkt_sze, CORSAIR_V2_TIMEOUT_SHORT); remaining -= copy_bytes; } diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.h b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.h index 4a686741..6001588e 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.h +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.h @@ -25,6 +25,12 @@ #define CORSAIR_V2_WRITE_WIRED_ID 8 #define CORSAIR_V2_WRITE_WIRELESS_ID 9 #define CORSAIR_V2_WRITE_SIZE 65 +#define CORSAIR_V2_PACKET_SIZE 1024 + +#define CORSAIR_V2_LIGHT_CTRL1 1 +#define CORSAIR_V2_LIGHT_CTRL2 34 /* 0x22 */ +#define CORSAIR_V2_UPDATE_PERIOD 30000 +#define CORSAIR_V2_SLEEP_PERIOD 12500ms #define CORSAIR_V2_BRIGHTNESS_MIN 0 #define CORSAIR_V2_BRIGHTNESS_MAX 0xFF @@ -67,10 +73,11 @@ enum corsair_v2_color class CorsairPeripheralV2Controller { public: - CorsairPeripheralV2Controller(hid_device* dev_handle, const char* path, std::string name, uint16_t pid); + CorsairPeripheralV2Controller(hid_device* dev_handle, const char* path, std::string name); virtual ~CorsairPeripheralV2Controller(); std::string GetDeviceLocation(); + std::string GetErrorString(uint8_t err); std::string GetFirmwareString(); std::string GetName(); std::string GetSerialString(); @@ -78,7 +85,7 @@ public: unsigned int GetKeyboardLayout(); void SetRenderMode(corsair_v2_device_mode mode); - void LightingControl(uint8_t opt1, uint8_t opt2); + void LightingControl(uint8_t opt1); void SetLEDs(uint8_t *data, uint16_t data_size); void UpdateHWMode(uint16_t mode, corsair_v2_color color_mode, uint8_t speed, uint8_t direction, uint8_t brightness, std::vector colors); @@ -88,15 +95,18 @@ public: protected: uint16_t device_index; std::string device_name; + uint8_t light_ctrl = CORSAIR_V2_LIGHT_CTRL2; private: + void ClearPacketBuffer(); unsigned int GetAddress(uint8_t address); - void StartTransaction(uint8_t opt1); + unsigned char StartTransaction(uint8_t opt1); void StopTransaction(uint8_t opt1); hid_device* dev; uint8_t write_cmd = CORSAIR_V2_WRITE_WIRED_ID; + uint16_t pkt_sze = CORSAIR_V2_WRITE_SIZE; std::string firmware_version; std::string location; }; diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2ControllerDetect.cpp b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2ControllerDetect.cpp index 767e73a1..222cfb86 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2ControllerDetect.cpp +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2ControllerDetect.cpp @@ -26,12 +26,19 @@ void DetectCorsairV2HardwareControllers(hid_device_info* info, const std::string if(dev) { - CorsairPeripheralV2HWController* controller = new CorsairPeripheralV2HWController(dev, info->path, name, info->product_id); + CorsairPeripheralV2HWController* controller = new CorsairPeripheralV2HWController(dev, info->path, name); RGBController_CorsairV2HW* rgb_controller = new RGBController_CorsairV2HW(controller); - rgb_controller->name = name; + if(info->product_id == CORSAIR_SLIPSTREAM_WIRELESS_PID) + { + rgb_controller->name = controller->GetName(); + } + else + { + rgb_controller->name = name; + } ResourceManager::get()->RegisterRGBController(rgb_controller); } -} /* DetectCorsairV2SoftwareControllers() */ +} /* DetectCorsairV2HardwareControllers() */ void DetectCorsairV2SoftwareControllers(hid_device_info* info, const std::string& name) { @@ -39,7 +46,7 @@ void DetectCorsairV2SoftwareControllers(hid_device_info* info, const std::string if(dev) { - CorsairPeripheralV2SWController* controller = new CorsairPeripheralV2SWController(dev, info->path, name, info->product_id); + CorsairPeripheralV2SWController* controller = new CorsairPeripheralV2SWController(dev, info->path, name); RGBController_CorsairV2SW* rgb_controller = new RGBController_CorsairV2SW(controller); rgb_controller->name = name; ResourceManager::get()->RegisterRGBController(rgb_controller); @@ -50,18 +57,19 @@ void DetectCorsairV2SoftwareControllers(hid_device_info* info, const std::string /*-----------------------------------------------------------------------------------------------------*\ | Keyboards | \*-----------------------------------------------------------------------------------------------------*/ -REGISTER_HID_DETECTOR_IP("Corsair K55 RGB PRO", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_K55_RGB_PRO_PID, 1, 0xFF42); -REGISTER_HID_DETECTOR_IP("Corsair K60 RGB PRO", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_K60_RGB_PRO_PID, 1, 0xFF42); -REGISTER_HID_DETECTOR_IP("Corsair K60 RGB PRO Low Profile", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_K60_RGB_PRO_LP_PID, 1, 0xFF42); +REGISTER_HID_DETECTOR_IP("Corsair K55 RGB PRO", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_K55_RGB_PRO_PID, 1, 0xFF42); +REGISTER_HID_DETECTOR_IP("Corsair K60 RGB PRO", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_K60_RGB_PRO_PID, 1, 0xFF42); +REGISTER_HID_DETECTOR_IP("Corsair K60 RGB PRO Low Profile", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_K60_RGB_PRO_LP_PID, 1, 0xFF42); /*-----------------------------------------------------------------------------------------------------*\ | Mice | \*-----------------------------------------------------------------------------------------------------*/ -REGISTER_HID_DETECTOR_IP("Corsair Ironclaw Wireless", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_IRONCLAW_WIRELESS_PID, 1, 0xFF42); -REGISTER_HID_DETECTOR_IP("Corsair Ironclaw Wireless (Wired)", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_IRONCLAW_WIRELESS_WIRED_PID, 1, 0xFF42); -REGISTER_HID_DETECTOR_IP("Corsair M55 RGB PRO", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_M55_RGB_PRO_PID, 1, 0xFF42); +REGISTER_HID_DETECTOR_IP("Corsair Ironclaw Wireless (Wired)", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_IRONCLAW_WIRELESS_PID, 1, 0xFF42); +REGISTER_HID_DETECTOR_IP("Corsair M55 RGB PRO", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_M55_RGB_PRO_PID, 1, 0xFF42); +REGISTER_HID_DETECTOR_IP("Corsair Dark Core RGB Pro SE (Wired)", DetectCorsairV2HardwareControllers, CORSAIR_VID, CORSAIR_DARK_CORE_RGB_PRO_PID, 1, 0xFF42); +REGISTER_HID_DETECTOR_IP("Corsair Slipstream Wireless Receiver", DetectCorsairV2HardwareControllers, CORSAIR_VID, CORSAIR_SLIPSTREAM_WIRELESS_PID, 1, 0xFF42); /*-----------------------------------------------------------------------------------------------------*\ | Mousemat | \*-----------------------------------------------------------------------------------------------------*/ -REGISTER_HID_DETECTOR_IP("Corsair MM700", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_MM700_PID, 1, 0xFF42); +REGISTER_HID_DETECTOR_IP("Corsair MM700", DetectCorsairV2SoftwareControllers, CORSAIR_VID, CORSAIR_MM700_PID, 1, 0xFF42); diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.cpp b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.cpp index 100dd43b..7581fb23 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.cpp +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.cpp @@ -12,10 +12,10 @@ std::vector corsair_full_size_values = 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, + /* 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, 50, 40, 92, 93, 94, + /* LSFT ISO\ Z X C V B N M , . / RSFT ARWU NM1 NM2 NM3 NMER */ + 106, 100, 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, }; @@ -29,17 +29,6 @@ keyboard_keymap_overlay_values corsair_K60_layout { 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 */ } }, @@ -56,8 +45,95 @@ keyboard_keymap_overlay_values corsair_K60_layout \*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------*\ -| Corsair Ironclaw Wireless 1B1C:1B66 | -| Corsair Ironclaw Wireless (Wired) 1B1C:1B4C | +| Corsair Dark Core Pro SE 1B1C:1B7E | +| | +| Zone "Scroll Wheel" | +| Single | +| | +| Zone "Side Buttons" | +| Linear | +| 1 Row, 4 Columns | +| | +| Zone "Rear Left" | +| Single | +| | +| Zone "Logo" | +| Single | +| | +| Zone "Rear Right" | +| Single | +| | +| Zone "DPI & Indicator" | +| Linear | +| 1 Row, 4 Columns | +\*-------------------------------------------------------------*/ +static const corsair_v2_zone dark_core_pro_se_scroll_zone = +{ + "Scroll Wheel", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const corsair_v2_zone dark_core_pro_se_button_zone = +{ + "Side Buttons", + ZONE_TYPE_LINEAR, + 1, + 4 +}; + +static const corsair_v2_zone dark_core_pro_se_left_zone = +{ + "Rear Left", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const corsair_v2_zone dark_core_pro_se_logo_zone = +{ + "Logo", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const corsair_v2_zone dark_core_pro_se_right_zone = +{ + "Rear Right", + ZONE_TYPE_SINGLE, + 1, + 1 +}; + +static const corsair_v2_zone dark_core_pro_se_dpi_zone = +{ + "DPI & Indicator Zone", + ZONE_TYPE_LINEAR, + 1, + 4 +}; + +static const corsair_v2_device dark_core_pro_se_device = +{ + CORSAIR_DARK_CORE_RGB_PRO_PID, + DEVICE_TYPE_MOUSE, + 1, + 12, + { + &dark_core_pro_se_scroll_zone, + &dark_core_pro_se_button_zone, + &dark_core_pro_se_left_zone, + &dark_core_pro_se_logo_zone, + &dark_core_pro_se_right_zone, + &dark_core_pro_se_dpi_zone + }, + nullptr +}; + +/*-------------------------------------------------------------*\ +| Corsair Ironclaw Wireless 1B1C:1B4C | | | | Zone "Logo" | | Single | @@ -104,31 +180,10 @@ static const corsair_v2_zone ironclaw_side_zone = 3 }; -static const corsair_v2_device ironclaw_wired_device = -{ - CORSAIR_IRONCLAW_WIRELESS_WIRED_PID, - false, - DEVICE_TYPE_MOUSE, - CORSAIR_V2_TYPE_SW_COLOUR_BLOCK, - 1, - 6, - { - &ironclaw_logo_zone, - &ironclaw_scroll_zone, - &ironclaw_button_zone, - &ironclaw_side_zone, - nullptr, - nullptr - }, - nullptr -}; - static const corsair_v2_device ironclaw_wireless_device = { CORSAIR_IRONCLAW_WIRELESS_PID, - true, DEVICE_TYPE_MOUSE, - CORSAIR_V2_TYPE_SW_COLOUR_BLOCK, 1, 6, { @@ -160,9 +215,7 @@ static const corsair_v2_zone k55_rgb_pro_zone = static const corsair_v2_device k55_rgb_pro_device = { CORSAIR_K55_RGB_PRO_PID, - false, DEVICE_TYPE_KEYBOARD, - CORSAIR_V2_TYPE_SW_COLOUR_BLOCK, 1, 6, { @@ -194,9 +247,7 @@ static const corsair_v2_zone k60_rgb_pro_zone = static const corsair_v2_device k60_rgb_pro_device = { CORSAIR_K60_RGB_PRO_PID, - false, DEVICE_TYPE_KEYBOARD, - CORSAIR_V2_TYPE_SW_COLOUR_BLOCK, 6, 21, { @@ -228,9 +279,7 @@ static const corsair_v2_zone k60_rgb_pro_lp_zone = static const corsair_v2_device k60_rgb_pro_lp_device = { CORSAIR_K60_RGB_PRO_LP_PID, - false, DEVICE_TYPE_KEYBOARD, - CORSAIR_V2_TYPE_SW_COLOUR_BLOCK, 6, 21, { @@ -273,9 +322,7 @@ static const corsair_v2_zone m55_logo_zone = static const corsair_v2_device m55_device = { CORSAIR_M55_RGB_PRO_PID, - false, DEVICE_TYPE_MOUSE, - CORSAIR_V2_TYPE_SW_COLOUR_BLOCK, 1, 2, { @@ -326,9 +373,7 @@ static const corsair_v2_zone mm700_left_zone = static const corsair_v2_device mm700_device = { CORSAIR_MM700_PID, - false, DEVICE_TYPE_MOUSEMAT, - CORSAIR_V2_TYPE_SW_COLOUR_BLOCK, 1, 3, { @@ -357,7 +402,7 @@ const corsair_v2_device* corsair_v2_device_list_data[] = /*-----------------------------------------------------------------*\ | MICE | \*-----------------------------------------------------------------*/ - &ironclaw_wired_device, + &dark_core_pro_se_device, &ironclaw_wireless_device, &m55_device, diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.h b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.h index 9c7a1d7d..884619fa 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.h +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Devices.h @@ -49,9 +49,7 @@ typedef struct 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]; @@ -68,9 +66,10 @@ typedef struct /*-----------------------------------------------------*\ | Corsair V2 Protocol Mice | \*-----------------------------------------------------*/ -#define CORSAIR_IRONCLAW_WIRELESS_PID 0x1BA6 -#define CORSAIR_IRONCLAW_WIRELESS_WIRED_PID 0x1B4C +#define CORSAIR_DARK_CORE_RGB_PRO_PID 0x1B7E +#define CORSAIR_IRONCLAW_WIRELESS_PID 0x1B4C #define CORSAIR_M55_RGB_PRO_PID 0x1B70 +#define CORSAIR_SLIPSTREAM_WIRELESS_PID 0x1BA6 /*-----------------------------------------------------*\ | Corsair V2 Protocol Mousemats | diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2HardwareController.cpp b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2HardwareController.cpp index c13db697..95105942 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2HardwareController.cpp +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2HardwareController.cpp @@ -10,10 +10,10 @@ #include "LogManager.h" #include "CorsairPeripheralV2HardwareController.h" -CorsairPeripheralV2HWController::CorsairPeripheralV2HWController(hid_device* dev_handle, const char* path, std::string name, uint16_t pid) : CorsairPeripheralV2Controller(dev_handle, path, name, pid) +CorsairPeripheralV2HWController::CorsairPeripheralV2HWController(hid_device* dev_handle, const char* path, std::string name) : CorsairPeripheralV2Controller(dev_handle, path, name) { SetRenderMode(CORSAIR_V2_MODE_SW); - LightingControl(0x5F, 0x00); + LightingControl(0x5F); } CorsairPeripheralV2HWController::~CorsairPeripheralV2HWController() @@ -23,17 +23,17 @@ CorsairPeripheralV2HWController::~CorsairPeripheralV2HWController() void CorsairPeripheralV2HWController::SetLedsDirect(std::vectorcolors) { - switch(corsair_v2_device_list[device_index]->protocol) + switch(light_ctrl) { - case CORSAIR_V2_TYPE_HW_TRIPLETS: - SetLedsDirectTriplets(colors); - break; - case CORSAIR_V2_TYPE_HW_COLOUR_BLOCK: + case CORSAIR_V2_LIGHT_CTRL1: SetLedsDirectColourBlocks(colors); break; + case CORSAIR_V2_LIGHT_CTRL2: + SetLedsDirectTriplets(colors); + break; default: - LOG_ERROR("[%s] Error setting Direct mode: Device supportes returned %i", device_name.c_str(), - corsair_v2_device_list[device_index]->protocol); + LOG_ERROR("[%s] Error setting Direct mode: Device supportes returned %i", + device_name.c_str(), light_ctrl); break; } } @@ -41,23 +41,20 @@ void CorsairPeripheralV2HWController::SetLedsDirect(std::vectorcolor void CorsairPeripheralV2HWController::SetLedsDirectColourBlocks(std::vectorcolors) { uint16_t count = colors.size(); - uint16_t green = count + CORSAIR_V2HW_DATA_OFFSET; - uint16_t blue = (count * 2) + CORSAIR_V2HW_DATA_OFFSET; - uint16_t length = (count * 3) + CORSAIR_V2HW_DATA_OFFSET; + uint16_t green = count; + uint16_t blue = (count * 2); + uint16_t length = (count * 3); uint8_t* buffer = new uint8_t[length]; memset(buffer, 0, length); - buffer[0] = CORSAIR_V2_MODE_DIRECT & 0xFF; - buffer[1] = CORSAIR_V2_MODE_DIRECT >> 8; for(std::size_t i = 0; i < count; i++) { RGBColor color = *colors[i]; - std::size_t idx = i + CORSAIR_V2HW_DATA_OFFSET; - buffer[idx] = RGBGetRValue(color); - buffer[idx + green] = RGBGetGValue(color); - buffer[idx + blue] = RGBGetBValue(color); + buffer[i] = RGBGetRValue(color); + buffer[i + green] = RGBGetGValue(color); + buffer[i + blue] = RGBGetBValue(color); } SetLEDs(buffer, length); diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2HardwareController.h b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2HardwareController.h index d8011698..78db7f7f 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2HardwareController.h +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2HardwareController.h @@ -21,7 +21,7 @@ class CorsairPeripheralV2HWController : public CorsairPeripheralV2Controller { public: - CorsairPeripheralV2HWController(hid_device* dev_handle, const char* path, std::string name, uint16_t pid); + CorsairPeripheralV2HWController(hid_device* dev_handle, const char* path, std::string name); ~CorsairPeripheralV2HWController(); void SetLedsDirect(std::vector colors); diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2SoftwareController.cpp b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2SoftwareController.cpp index 03280608..d1b01c1e 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2SoftwareController.cpp +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2SoftwareController.cpp @@ -10,10 +10,10 @@ #include "LogManager.h" #include "CorsairPeripheralV2SoftwareController.h" -CorsairPeripheralV2SWController::CorsairPeripheralV2SWController(hid_device* dev_handle, const char* path, std::string name, uint16_t pid) : CorsairPeripheralV2Controller(dev_handle, path, name, pid) +CorsairPeripheralV2SWController::CorsairPeripheralV2SWController(hid_device* dev_handle, const char* path, std::string name) : CorsairPeripheralV2Controller(dev_handle, path, name) { SetRenderMode(CORSAIR_V2_MODE_SW); - LightingControl(0x5F, 0x00); + LightingControl(0x5F); } CorsairPeripheralV2SWController::~CorsairPeripheralV2SWController() diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2SoftwareController.h b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2SoftwareController.h index ddb79f09..1b247a16 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2SoftwareController.h +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2SoftwareController.h @@ -17,7 +17,7 @@ class CorsairPeripheralV2SWController : public CorsairPeripheralV2Controller { public: - CorsairPeripheralV2SWController(hid_device* dev_handle, const char* path, std::string name, uint16_t pid); + CorsairPeripheralV2SWController(hid_device* dev_handle, const char* path, std::string name); ~CorsairPeripheralV2SWController(); void SetLedsDirect(std::vector colors); diff --git a/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Hardware.cpp b/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Hardware.cpp index 30f5a809..ea7b3782 100644 --- a/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Hardware.cpp +++ b/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Hardware.cpp @@ -197,7 +197,10 @@ void RGBController_CorsairV2HW::SetupZones() max_led_value = std::max(max_led_value, (unsigned int)leds.size()); } - LOG_DEBUG("[%s] Creating a %s zone: %s with %d LEDs", name.c_str(), + /*---------------------------------------------------------*\ + | name is not set yet so description is used instead | + \*---------------------------------------------------------*/ + LOG_DEBUG("[%s] Creating a %s zone: %s with %d LEDs", description.c_str(), ((new_zone.type == ZONE_TYPE_MATRIX) ? "matrix": "linear"), new_zone.name.c_str(), new_zone.leds_count); new_zone.leds_min = new_zone.leds_count; @@ -258,11 +261,12 @@ void RGBController_CorsairV2HW::KeepaliveThread() { if(active_mode == 0) { - if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(50000)) + if((std::chrono::steady_clock::now() - last_update_time) > + std::chrono::milliseconds(CORSAIR_V2_UPDATE_PERIOD)) { DeviceUpdateLEDs(); } } - std::this_thread::sleep_for(30000ms); + std::this_thread::sleep_for(CORSAIR_V2_SLEEP_PERIOD); } } diff --git a/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Software.cpp b/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Software.cpp index 43002e87..18ee62bb 100644 --- a/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Software.cpp +++ b/Controllers/CorsairPeripheralV2Controller/RGBController_CorsairV2Software.cpp @@ -35,28 +35,12 @@ RGBController_CorsairV2SW::RGBController_CorsairV2SW(CorsairPeripheralV2Controll location = controller->GetDeviceLocation(); serial = controller->GetSerialString(); - if(corsair->protocol & CORSAIR_V2_TYPE_SW_COLOUR_BLOCK) - { - mode Direct; - Direct.name = "Direct"; - Direct.value = CORSAIR_V2_MODE_DIRECT; - Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; - Direct.color_mode = MODE_COLORS_PER_LED; - modes.push_back(Direct); - - mode Static; - Static.name = "Static"; - Static.value = CORSAIR_V2_MODE_STATIC; - Static.flags = MODE_FLAG_HAS_MODE_SPECIFIC_COLOR | MODE_FLAG_HAS_BRIGHTNESS; - Static.colors_min = 1; - Static.colors_max = 1; - Static.colors.resize(Static.colors_max); - Static.brightness_min = CORSAIR_V2_BRIGHTNESS_MIN; - Static.brightness_max = CORSAIR_V2_BRIGHTNESS_MAX; - Static.brightness = CORSAIR_V2_BRIGHTNESS_MAX; - Static.color_mode = MODE_COLORS_MODE_SPECIFIC; - modes.push_back(Static); - } + mode Direct; + Direct.name = "Direct"; + Direct.value = CORSAIR_V2_MODE_DIRECT; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Direct); SetupZones(); /*-----------------------------------------------------*\ @@ -201,7 +185,10 @@ void RGBController_CorsairV2SW::SetupZones() max_led_value = std::max(max_led_value, (unsigned int)leds.size()); } - LOG_DEBUG("[%s] Creating a %s zone: %s with %d LEDs", name.c_str(), + /*---------------------------------------------------------*\ + | name is not set yet so description is used instead | + \*---------------------------------------------------------*/ + LOG_DEBUG("[%s] Creating a %s zone: %s with %d LEDs", description.c_str(), ((new_zone.type == ZONE_TYPE_MATRIX) ? "matrix": "linear"), new_zone.name.c_str(), new_zone.leds_count); new_zone.leds_min = new_zone.leds_count; @@ -262,11 +249,12 @@ void RGBController_CorsairV2SW::KeepaliveThread() { if(active_mode == 0) { - if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(50000)) + if((std::chrono::steady_clock::now() - last_update_time) > + std::chrono::milliseconds(CORSAIR_V2_UPDATE_PERIOD)) { DeviceUpdateLEDs(); } } - std::this_thread::sleep_for(30000ms); + std::this_thread::sleep_for(CORSAIR_V2_SLEEP_PERIOD); } }