From 473331dd3a96c76a63157838ad8f82d239a05fca Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Thu, 25 Jun 2026 01:27:15 -0500 Subject: [PATCH] Add option to skip reads for most packets as even short reads slow K57 effects --- .../CorsairPeripheralV2Controller.cpp | 47 +++++++++++++------ .../CorsairPeripheralV2Controller.h | 1 + 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp index 3a2f1ad7d..3a2af8513 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.cpp @@ -39,6 +39,7 @@ CorsairPeripheralV2Controller::CorsairPeripheralV2Controller(hid_device* dev_han case CORSAIR_K57_RGB_WIRED_PID: write_cmd = 0x80; light_ctrl = CORSAIR_V2_LIGHT_CTRL1; + skip_reads = true; break; } @@ -179,7 +180,11 @@ void CorsairPeripheralV2Controller::SetRenderMode(corsair_v2_device_mode mode) buffer[5] = mode; hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); + + if(!skip_reads) + { + hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); + } } void CorsairPeripheralV2Controller::LightingControl(uint8_t opt1) @@ -199,7 +204,11 @@ void CorsairPeripheralV2Controller::LightingControl(uint8_t opt1) buffer[5] = 0x00; hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); + + if(!skip_reads) + { + hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); + } } unsigned int CorsairPeripheralV2Controller::GetKeyboardLayout() @@ -249,19 +258,10 @@ unsigned char CorsairPeripheralV2Controller::StartTransaction(uint8_t opt1) hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - /*-----------------------------------------------------*\ - | The return value is only used to check if switching | - | from CTRL2 to CTRL1 is needed, if it is already at | - | CTRL1 use a short wait to avoid delaying direct mode. | - \*-----------------------------------------------------*/ - if(light_ctrl == CORSAIR_V2_LIGHT_CTRL2) + if(!skip_reads) { hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); } - else - { - hid_read_timeout(dev, buffer, pkt_sze, CORSAIR_V2_TIMEOUT_SHORT); - } return buffer[2]; } @@ -278,11 +278,20 @@ void CorsairPeripheralV2Controller::StopTransaction(uint8_t opt1) buffer[4] = opt1; hid_write(dev, buffer, CORSAIR_V2_WRITE_SIZE); - hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); + + if(!skip_reads) + { + hid_read_timeout(dev, buffer, CORSAIR_V2_WRITE_SIZE, CORSAIR_V2_TIMEOUT); + } } void CorsairPeripheralV2Controller::ClearPacketBuffer() { + if(skip_reads) + { + return; + } + uint8_t result = 0; uint8_t buffer[CORSAIR_V2_PACKET_SIZE]; @@ -325,7 +334,11 @@ void CorsairPeripheralV2Controller::SetLEDs(uint8_t *data, uint16_t data_size) memcpy(&buffer[offset1], &data[0], copy_bytes); hid_write(dev, buffer, pkt_sze); - hid_read_timeout(dev, buffer, pkt_sze, CORSAIR_V2_TIMEOUT_SHORT); + + if(!skip_reads) + { + hid_read_timeout(dev, buffer, pkt_sze, CORSAIR_V2_TIMEOUT_SHORT); + } remaining -= copy_bytes; buffer[2] = CORSAIR_V2_CMD_BLK_WN; @@ -346,7 +359,11 @@ void CorsairPeripheralV2Controller::SetLEDs(uint8_t *data, uint16_t data_size) memcpy(&buffer[offset2], &data[index], copy_bytes); hid_write(dev, buffer, pkt_sze); - hid_read_timeout(dev, buffer, pkt_sze, CORSAIR_V2_TIMEOUT_SHORT); + + if(!skip_reads) + { + 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 c2cf91cf2..40b41f53e 100644 --- a/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.h +++ b/Controllers/CorsairPeripheralV2Controller/CorsairPeripheralV2Controller.h @@ -109,6 +109,7 @@ private: uint8_t write_cmd = CORSAIR_V2_WRITE_WIRED_ID; uint16_t pkt_sze = CORSAIR_V2_WRITE_SIZE; + bool skip_reads = false; std::string firmware_version; std::string location; };