Skip to content

Commit de91237

Browse files
xQwexxCalcProgrammer1
authored andcommitted
Fix Corsair K100 initialization
1 parent fe59f75 commit de91237

File tree

4 files changed

+91
-9
lines changed

4 files changed

+91
-9
lines changed

Controllers/CorsairPeripheralController/CorsairK100Controller.cpp

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static unsigned int keys_k100[] = {0x25, 0x31, 0x27, 0x35, 0x66, 0x65, 0x41, 0x2
1414
0x3C, 0x20, 0x14, 0x09, 0x0D, 0x6B, 0x2C, 0x69, 0x50, 0x55, 0x3D, 0x21, 0x08, 0x0A, 0x0C, 0x76,
1515
0x2D, 0x4E, 0x51, 0x56, 0x3E, 0x22, 0x0E, 0x0B, 0x32, 0x61, 0x4C, 0x52, 0x57, 0x3F, 0x23, 0x0F,
1616
0x2F, 0x33, 0x24, 0x4D, 0x53, 0x5E, 0x40, 0x29, 0x2B, 0x30, 0x34, /*Brightness,*/
17-
0x4B, 0x54, 0x5F, 114 , 99, 0x7C, //114 and 99 is not conformed it just a guess
17+
0x4B, 0x54, 0x5F, 0x60, 0x2E, 0x7C,
1818
0x7F, 0x80, 0x81, 0x82, 0x83, 0x84,//Macro
1919
0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1, 0xA0, 0x9F, 0x9E, 0x9D, 0x9C, 0x86, 0x87, 0x88, 0x89, 0x8A,
2020
0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A,
@@ -79,23 +79,60 @@ std::string CorsairK100Controller::GetSerialString()
7979
void CorsairK100Controller::LightingControl()
8080
{
8181
unsigned char usb_buf[65];
82+
memset(usb_buf, 0x00, sizeof(usb_buf));
83+
//This is requered
84+
usb_buf[0x01] = 0x08;
85+
usb_buf[0x02] = 0x01;
86+
usb_buf[0x03] = 0x03;
87+
usb_buf[0x05] = 0x02;
88+
89+
hid_write(dev, (unsigned char *)usb_buf, 65);
90+
8291
memset(usb_buf, 0x00, sizeof(usb_buf));
8392

93+
usb_buf[0x01] = 0x08;
94+
usb_buf[0x02] = 0x01;
95+
usb_buf[0x03] = 0x4A;
96+
usb_buf[0x05] = 0x01;
97+
98+
hid_write(dev, (unsigned char *)usb_buf, 65);
99+
100+
memset(usb_buf, 0x00, sizeof(usb_buf));
101+
102+
usb_buf[0x01] = 0x08;
103+
usb_buf[0x02] = 0x01;
104+
usb_buf[0x03] = 0x45;
105+
usb_buf[0x05] = 0x00;
106+
107+
hid_write(dev, (unsigned char *)usb_buf, 65);
108+
109+
memset(usb_buf, 0x00, sizeof(usb_buf));
110+
//This is requered
111+
usb_buf[0x01] = 0x08;
112+
usb_buf[0x02] = 0x0D;
113+
usb_buf[0x03] = 0x01;
114+
usb_buf[0x04] = 0x22;
115+
116+
hid_write(dev, (unsigned char *)usb_buf, 65);
117+
118+
/*memset(usb_buf, 0x00, sizeof(usb_buf));
119+
84120
usb_buf[0x01] = 0x08;
85121
usb_buf[0x02] = 0x05;
86122
usb_buf[0x03] = 0x01;
87123
88-
hid_write(dev, (unsigned char *)usb_buf, 5);
124+
hid_write(dev, (unsigned char *)usb_buf, 65);
89125
90126
memset(usb_buf, 0x00, sizeof(usb_buf));
91127
92128
int res = hid_read_timeout(dev, usb_buf, 50, 1000);
93129
94-
if (res == 0 || usb_buf[1] != 0x05)
130+
if (res == 0 || usb_buf[1] != 0x01)
95131
{
96-
LOG_INFO("[Corsair-K100] This device did not allow to take control over it.");
132+
LOG_INFO("[Corsair-K100] This device did not allow to take control over it. recieved response: %02X", usb_buf[1]);
97133
keyboard_type = CORSAIR_TYPE_UNKNOWN;
98-
}
134+
}*/
135+
99136
}
100137

101138
void CorsairK100Controller::SetLEDs(std::vector<RGBColor>colors)
@@ -116,7 +153,6 @@ void CorsairK100Controller::SetLEDsKeyboardFull(std::vector<RGBColor> colors)
116153
unsigned char usb_buf[600];
117154
memset(usb_buf, 0x00, sizeof(usb_buf));
118155

119-
usb_buf[0x00] = 0x00;
120156
usb_buf[0x01] = 0x08;
121157
usb_buf[0x02] = 0x06;
122158
usb_buf[0x03] = 0x01;

Controllers/CorsairPeripheralController/RGBController_CorsairK100.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "RGBController_CorsairK100.h"
88
#include "LogManager.h"
99

10+
using namespace std::chrono_literals;
11+
1012
#define NA 0xFFFFFFFF
1113

1214
static unsigned int matrix_map_k100[7][24] =
@@ -238,10 +240,25 @@ RGBController_CorsairK100::RGBController_CorsairK100(CorsairK100Controller* cors
238240
modes.push_back(Direct);
239241

240242
SetupZones();
243+
/*-----------------------------------------------------*\
244+
| The Corsair K100 requires a packet within |
245+
| 1 minutes of sending the lighting change in order |
246+
| to not revert back into rainbow mode. Start a thread |
247+
| to continuously send a keepalive packet every 50 sec |
248+
\*-----------------------------------------------------*/
249+
keepalive_thread_run = true;
250+
keepalive_thread = new std::thread(&RGBController_CorsairK100::KeepaliveThread, this);
241251
}
242252

243253
RGBController_CorsairK100::~RGBController_CorsairK100()
244254
{
255+
/*-----------------------------------------------------*\
256+
| Close keepalive thread |
257+
\*-----------------------------------------------------*/
258+
keepalive_thread_run = false;
259+
keepalive_thread->join();
260+
delete keepalive_thread;
261+
245262
/*---------------------------------------------------------*\
246263
| Delete the matrix map |
247264
\*---------------------------------------------------------*/
@@ -314,6 +331,8 @@ void RGBController_CorsairK100::ResizeZone(int /*zone*/, int /*new_size*/)
314331

315332
void RGBController_CorsairK100::DeviceUpdateLEDs()
316333
{
334+
last_update_time = std::chrono::steady_clock::now();
335+
317336
corsair->SetLEDs(colors);
318337
}
319338

@@ -336,3 +355,18 @@ void RGBController_CorsairK100::DeviceUpdateMode()
336355
{
337356

338357
}
358+
359+
void RGBController_CorsairK100::KeepaliveThread()
360+
{
361+
while(keepalive_thread_run.load())
362+
{
363+
if(active_mode == 0)
364+
{
365+
if((std::chrono::steady_clock::now() - last_update_time) > std::chrono::milliseconds(50000))
366+
{
367+
DeviceUpdateLEDs();
368+
}
369+
}
370+
std::this_thread::sleep_for(3000ms);
371+
}
372+
}

Controllers/CorsairPeripheralController/RGBController_CorsairK100.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ class RGBController_CorsairK100 : public RGBController
2525

2626
void DeviceUpdateMode();
2727
void SetCustomMode();
28+
void KeepaliveThread();
2829

2930
private:
30-
CorsairK100Controller* corsair;
31-
CorsairKeyboardType logical_layout;
31+
CorsairK100Controller* corsair;
32+
CorsairKeyboardType logical_layout;
33+
34+
std::thread* keepalive_thread;
35+
std::atomic<bool> keepalive_thread_run;
36+
std::chrono::time_point<std::chrono::steady_clock> last_update_time;
37+
3238
};
3339

3440
#endif // RGBCONTROLLER_CORSAIRK100_H

Controllers/CorsairWirelessController/RGBController_CorsairWireless.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,18 @@ RGBController_CorsairWireless::RGBController_CorsairWireless(CorsairWirelessCont
206206
| to not revert back into rainbow mode. Start a thread |
207207
| to continuously send a keepalive packet every 5s |
208208
\*-----------------------------------------------------*/
209-
keepalive_thread_run = 1;
209+
keepalive_thread_run = true;
210210
keepalive_thread = new std::thread(&RGBController_CorsairWireless::KeepaliveThread, this);
211211
}
212212

213213
RGBController_CorsairWireless::~RGBController_CorsairWireless()
214214
{
215+
/*-----------------------------------------------------*\
216+
| Close keepalive thread |
217+
\*-----------------------------------------------------*/
218+
keepalive_thread_run = false;
219+
keepalive_thread->join();
220+
delete keepalive_thread;
215221
/*---------------------------------------------------------*\
216222
| Delete the matrix map |
217223
\*---------------------------------------------------------*/

0 commit comments

Comments
 (0)