Fix Corsair K100 initialization

This commit is contained in:
Qwex
2021-12-05 01:23:46 +00:00
committed by Adam Honse
parent fe59f75b5b
commit de91237de8
4 changed files with 91 additions and 9 deletions

View File

@@ -14,7 +14,7 @@ static unsigned int keys_k100[] = {0x25, 0x31, 0x27, 0x35, 0x66, 0x65, 0x41, 0x2
0x3C, 0x20, 0x14, 0x09, 0x0D, 0x6B, 0x2C, 0x69, 0x50, 0x55, 0x3D, 0x21, 0x08, 0x0A, 0x0C, 0x76,
0x2D, 0x4E, 0x51, 0x56, 0x3E, 0x22, 0x0E, 0x0B, 0x32, 0x61, 0x4C, 0x52, 0x57, 0x3F, 0x23, 0x0F,
0x2F, 0x33, 0x24, 0x4D, 0x53, 0x5E, 0x40, 0x29, 0x2B, 0x30, 0x34, /*Brightness,*/
0x4B, 0x54, 0x5F, 114 , 99, 0x7C, //114 and 99 is not conformed it just a guess
0x4B, 0x54, 0x5F, 0x60, 0x2E, 0x7C,
0x7F, 0x80, 0x81, 0x82, 0x83, 0x84,//Macro
0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1, 0xA0, 0x9F, 0x9E, 0x9D, 0x9C, 0x86, 0x87, 0x88, 0x89, 0x8A,
0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A,
@@ -80,22 +80,59 @@ void CorsairK100Controller::LightingControl()
{
unsigned char usb_buf[65];
memset(usb_buf, 0x00, sizeof(usb_buf));
//This is requered
usb_buf[0x01] = 0x08;
usb_buf[0x02] = 0x01;
usb_buf[0x03] = 0x03;
usb_buf[0x05] = 0x02;
hid_write(dev, (unsigned char *)usb_buf, 65);
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[0x01] = 0x08;
usb_buf[0x02] = 0x01;
usb_buf[0x03] = 0x4A;
usb_buf[0x05] = 0x01;
hid_write(dev, (unsigned char *)usb_buf, 65);
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[0x01] = 0x08;
usb_buf[0x02] = 0x01;
usb_buf[0x03] = 0x45;
usb_buf[0x05] = 0x00;
hid_write(dev, (unsigned char *)usb_buf, 65);
memset(usb_buf, 0x00, sizeof(usb_buf));
//This is requered
usb_buf[0x01] = 0x08;
usb_buf[0x02] = 0x0D;
usb_buf[0x03] = 0x01;
usb_buf[0x04] = 0x22;
hid_write(dev, (unsigned char *)usb_buf, 65);
/*memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[0x01] = 0x08;
usb_buf[0x02] = 0x05;
usb_buf[0x03] = 0x01;
hid_write(dev, (unsigned char *)usb_buf, 5);
hid_write(dev, (unsigned char *)usb_buf, 65);
memset(usb_buf, 0x00, sizeof(usb_buf));
int res = hid_read_timeout(dev, usb_buf, 50, 1000);
if (res == 0 || usb_buf[1] != 0x05)
if (res == 0 || usb_buf[1] != 0x01)
{
LOG_INFO("[Corsair-K100] This device did not allow to take control over it.");
LOG_INFO("[Corsair-K100] This device did not allow to take control over it. recieved response: %02X", usb_buf[1]);
keyboard_type = CORSAIR_TYPE_UNKNOWN;
}
}*/
}
void CorsairK100Controller::SetLEDs(std::vector<RGBColor>colors)
@@ -116,7 +153,6 @@ void CorsairK100Controller::SetLEDsKeyboardFull(std::vector<RGBColor> colors)
unsigned char usb_buf[600];
memset(usb_buf, 0x00, sizeof(usb_buf));
usb_buf[0x00] = 0x00;
usb_buf[0x01] = 0x08;
usb_buf[0x02] = 0x06;
usb_buf[0x03] = 0x01;

View File

@@ -7,6 +7,8 @@
#include "RGBController_CorsairK100.h"
#include "LogManager.h"
using namespace std::chrono_literals;
#define NA 0xFFFFFFFF
static unsigned int matrix_map_k100[7][24] =
@@ -238,10 +240,25 @@ RGBController_CorsairK100::RGBController_CorsairK100(CorsairK100Controller* cors
modes.push_back(Direct);
SetupZones();
/*-----------------------------------------------------*\
| The Corsair K100 requires a packet within |
| 1 minutes of sending the lighting change in order |
| to not revert back into rainbow mode. Start a thread |
| to continuously send a keepalive packet every 50 sec |
\*-----------------------------------------------------*/
keepalive_thread_run = true;
keepalive_thread = new std::thread(&RGBController_CorsairK100::KeepaliveThread, this);
}
RGBController_CorsairK100::~RGBController_CorsairK100()
{
/*-----------------------------------------------------*\
| Close keepalive thread |
\*-----------------------------------------------------*/
keepalive_thread_run = false;
keepalive_thread->join();
delete keepalive_thread;
/*---------------------------------------------------------*\
| Delete the matrix map |
\*---------------------------------------------------------*/
@@ -314,6 +331,8 @@ void RGBController_CorsairK100::ResizeZone(int /*zone*/, int /*new_size*/)
void RGBController_CorsairK100::DeviceUpdateLEDs()
{
last_update_time = std::chrono::steady_clock::now();
corsair->SetLEDs(colors);
}
@@ -336,3 +355,18 @@ void RGBController_CorsairK100::DeviceUpdateMode()
{
}
void RGBController_CorsairK100::KeepaliveThread()
{
while(keepalive_thread_run.load())
{
if(active_mode == 0)
{
if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(50000))
{
DeviceUpdateLEDs();
}
}
std::this_thread::sleep_for(3000ms);
}
}

View File

@@ -25,10 +25,16 @@ public:
void DeviceUpdateMode();
void SetCustomMode();
void KeepaliveThread();
private:
CorsairK100Controller* corsair;
CorsairKeyboardType logical_layout;
CorsairK100Controller* corsair;
CorsairKeyboardType logical_layout;
std::thread* keepalive_thread;
std::atomic<bool> keepalive_thread_run;
std::chrono::time_point<std::chrono::steady_clock> last_update_time;
};
#endif // RGBCONTROLLER_CORSAIRK100_H

View File

@@ -206,12 +206,18 @@ RGBController_CorsairWireless::RGBController_CorsairWireless(CorsairWirelessCont
| to not revert back into rainbow mode. Start a thread |
| to continuously send a keepalive packet every 5s |
\*-----------------------------------------------------*/
keepalive_thread_run = 1;
keepalive_thread_run = true;
keepalive_thread = new std::thread(&RGBController_CorsairWireless::KeepaliveThread, this);
}
RGBController_CorsairWireless::~RGBController_CorsairWireless()
{
/*-----------------------------------------------------*\
| Close keepalive thread |
\*-----------------------------------------------------*/
keepalive_thread_run = false;
keepalive_thread->join();
delete keepalive_thread;
/*---------------------------------------------------------*\
| Delete the matrix map |
\*---------------------------------------------------------*/