-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenRGB-K551-Direct.patch
More file actions
569 lines (524 loc) · 22.8 KB
/
Copy pathOpenRGB-K551-Direct.patch
File metadata and controls
569 lines (524 loc) · 22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
diff --git a/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardController.cpp b/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardController.cpp
index cf5f25c..d6e39fe 100644
--- a/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardController.cpp
+++ b/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardController.cpp
@@ -14,11 +14,12 @@
#include "EVisionKeyboardController.h"
#include "StringUtils.h"
-EVisionKeyboardController::EVisionKeyboardController(hid_device* dev_handle, const char* path, std::string dev_name)
+EVisionKeyboardController::EVisionKeyboardController(hid_device* dev_handle, const char* path, std::string dev_name, bool direct_supported)
{
- dev = dev_handle;
- location = path;
- name = dev_name;
+ dev = dev_handle;
+ location = path;
+ name = dev_name;
+ this->direct_supported = direct_supported;
}
EVisionKeyboardController::~EVisionKeyboardController()
@@ -49,11 +50,55 @@ std::string EVisionKeyboardController::GetSerialString()
return(StringUtils::wstring_to_string(serial_string));
}
+bool EVisionKeyboardController::SupportsDirect()
+{
+ return(direct_supported);
+}
+
void EVisionKeyboardController::SetKeyboardColors
(
unsigned char * color_data,
unsigned int size
)
+{
+ unsigned short data_offset = direct_supported ? 0x0200 : 0x0000;
+
+ SetKeyboardColorsEx
+ (
+ EVISION_KB_COMMAND_WRITE_CUSTOM_COLOR_DATA,
+ data_offset,
+ color_data,
+ size
+ );
+}
+
+void EVisionKeyboardController::SetKeyboardColorsDirect
+ (
+ unsigned char * color_data,
+ unsigned int size
+ )
+{
+ if(!direct_supported)
+ {
+ return;
+ }
+
+ SetKeyboardColorsEx
+ (
+ EVISION_KB_COMMAND_SEND_DYNAMIC_COLOR_DATA,
+ 0x0000,
+ color_data,
+ size
+ );
+}
+
+void EVisionKeyboardController::SetKeyboardColorsEx
+ (
+ unsigned char command,
+ unsigned short data_offset,
+ unsigned char * color_data,
+ unsigned int size
+ )
{
unsigned int packet_size = 0;
unsigned int packet_offset = 0;
@@ -71,9 +116,10 @@ void EVisionKeyboardController::SetKeyboardColors
SendKeyboardData
(
+ command,
&color_data[packet_offset],
packet_size,
- packet_offset
+ data_offset + packet_offset
);
size -= packet_size;
@@ -81,6 +127,24 @@ void EVisionKeyboardController::SetKeyboardColors
}
}
+void EVisionKeyboardController::SendKeyboardDirectEnd()
+{
+ if(!direct_supported)
+ {
+ return;
+ }
+
+ char usb_buf[64];
+ memset(usb_buf, 0x00, sizeof(usb_buf));
+
+ usb_buf[0x00] = 0x04;
+ usb_buf[0x03] = EVISION_KB_COMMAND_END_DYNAMIC_COLOR_DATA;
+ ComputeChecksum(usb_buf);
+
+ hid_write(dev, (unsigned char *)usb_buf, 64);
+ hid_read(dev, (unsigned char *)usb_buf, 64);
+}
+
void EVisionKeyboardController::SendKeyboardMode
(
unsigned char mode
@@ -189,6 +253,7 @@ void EVisionKeyboardController::SendKeyboardEnd()
void EVisionKeyboardController::SendKeyboardData
(
+ unsigned char command,
unsigned char * data,
unsigned char data_size,
unsigned short data_offset
@@ -202,10 +267,10 @@ void EVisionKeyboardController::SendKeyboardData
memset(usb_buf, 0x00, sizeof(usb_buf));
/*-----------------------------------------------------*\
- | Set up Keyboard Color Data (0x11) packet |
+ | Set up Keyboard Color Data packet |
\*-----------------------------------------------------*/
usb_buf[0x00] = 0x04;
- usb_buf[0x03] = 0x11;
+ usb_buf[0x03] = command;
usb_buf[0x04] = data_size;
usb_buf[0x05] = data_offset & 0x00FF;
diff --git a/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardController.h b/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardController.h
index d8f5d1c..ffc0d46 100644
--- a/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardController.h
+++ b/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardController.h
@@ -25,6 +25,8 @@ enum
EVISION_KB_COMMAND_SET_PARAMETER = 0x06, /* Set parameter command */
EVISION_KB_COMMAND_READ_CUSTOM_COLOR_DATA = 0x10, /* Read custom color data */
EVISION_KB_COMMAND_WRITE_CUSTOM_COLOR_DATA = 0x11, /* Write custom color data */
+ EVISION_KB_COMMAND_SEND_DYNAMIC_COLOR_DATA = 0x12, /* Write live color data */
+ EVISION_KB_COMMAND_END_DYNAMIC_COLOR_DATA = 0x13, /* End live color mode */
};
enum
@@ -60,6 +62,7 @@ enum
EVISION_KB_MODE_SURMOUNT = 0x11, /* "Surmount" */
EVISION_KB_MODE_RAINBOW_WAVE_CIRCLE = 0x12, /* "Fast and the Furious" */
EVISION_KB_MODE_CUSTOM = 0x14, /* "Coastal" */
+ EVISION_KB_MODE_DIRECT = 0xFF, /* Software controlled mode */
};
enum
@@ -94,19 +97,29 @@ enum
class EVisionKeyboardController
{
public:
- EVisionKeyboardController(hid_device* dev_handle, const char* path, std::string dev_name);
+ EVisionKeyboardController(hid_device* dev_handle, const char* path, std::string dev_name, bool direct_supported);
~EVisionKeyboardController();
std::string GetDeviceLocation();
std::string GetNameString();
std::string GetSerialString();
+ bool SupportsDirect();
+
void SetKeyboardColors
(
unsigned char * color_data,
unsigned int size
);
+ void SetKeyboardColorsDirect
+ (
+ unsigned char * color_data,
+ unsigned int size
+ );
+
+ void SendKeyboardDirectEnd();
+
void SendKeyboardBegin();
void SendKeyboardMode
@@ -128,6 +141,7 @@ public:
void SendKeyboardData
(
+ unsigned char command,
unsigned char * data,
unsigned char data_size,
unsigned short data_offset
@@ -139,6 +153,15 @@ private:
hid_device* dev;
std::string location;
std::string name;
+ bool direct_supported;
+
+ void SetKeyboardColorsEx
+ (
+ unsigned char command,
+ unsigned short data_offset,
+ unsigned char * color_data,
+ unsigned int size
+ );
void ComputeChecksum
(
diff --git a/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardControllerDetect.cpp b/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardControllerDetect.cpp
index ac14801..d285acc 100644
--- a/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardControllerDetect.cpp
+++ b/Controllers/EVisionKeyboardController/EVisionKeyboardController/EVisionKeyboardControllerDetect.cpp
@@ -45,6 +45,11 @@
#define EVISION_5078_PID 0x5078
#define EVISION_5084_PID 0x5084
+/*---------------------------------------------------------*\
+| Firmware revision with RAM-only dynamic color command |
+\*---------------------------------------------------------*/
+#define EVISION_5000_DIRECT_RELEASE 0x0103
+
DetectedControllers DetectEVisionKeyboards(hid_device_info* info, const std::string& name)
{
DetectedControllers detected_controllers;
@@ -54,7 +59,12 @@ DetectedControllers DetectEVisionKeyboards(hid_device_info* info, const std::str
if(dev)
{
- EVisionKeyboardController* controller = new EVisionKeyboardController(dev, info->path, name);
+ bool direct_supported =
+ info->vendor_id == EVISION_VID
+ && info->product_id == EVISION_5000_PID
+ && info->release_number == EVISION_5000_DIRECT_RELEASE;
+
+ EVisionKeyboardController* controller = new EVisionKeyboardController(dev, info->path, name, direct_supported);
RGBController_EVisionKeyboard* rgb_controller = new RGBController_EVisionKeyboard(controller);
detected_controllers.push_back(rgb_controller);
diff --git a/Controllers/EVisionKeyboardController/EVisionV2KeyboardController/RGBController_EVisionKeyboard.cpp b/Controllers/EVisionKeyboardController/EVisionV2KeyboardController/RGBController_EVisionKeyboard.cpp
index 12d4b55..ee71df1 100644
--- a/Controllers/EVisionKeyboardController/EVisionV2KeyboardController/RGBController_EVisionKeyboard.cpp
+++ b/Controllers/EVisionKeyboardController/EVisionV2KeyboardController/RGBController_EVisionKeyboard.cpp
@@ -12,6 +12,8 @@
#include "RGBController_EVisionKeyboard.h"
+using namespace std::chrono_literals;
+
//0xFFFFFFFF indicates an unused entry in matrix
#define NA 0xFFFFFFFF
@@ -23,6 +25,62 @@ static unsigned int matrix_map[6][23] =
{ 84, NA, 86, 87, 88, 89, NA, 90, NA, 91, 92, 93, 94, 95, 97, NA, NA, 99, NA, 101, 102, 103, 104 },
{ 105, 106, 107, NA, NA, NA, NA, 108, NA, NA, NA, NA, 109, 110, 111, 113, 119, 120, 121, 123, NA, 124, NA } };
+/*---------------------------------------------------------*\
+| K551RGB-1 V2 firmware 0105 has 128 four-byte LED records |
+| in XRAM at 0x066B..0x086A. HID command 0x12 accepts a |
+| packed RGB stream and expands each triplet into a record. |
+| Therefore the exact safe limit is 128 RGB triplets. |
+| |
+| The firmware table at code address 0x30A7 maps these raw |
+| records to the persistent/layout indices used below. Its |
+| three otherwise unrepresented positions are the second |
+| emitters for Enter and both Shift keys. Raw slot 126 is |
+| NumPad Enter. Raw slot 127 has no physical LED. |
+| |
+| Sending 133 triplets in the old probe overflowed past |
+| 0x086A into runtime state and caused stuck/repeated keys. |
+| The eighth HID packet is safe when it contains only the |
+| final six bytes for slots 126 and 127. |
+\*---------------------------------------------------------*/
+static unsigned int k551_matrix_map[6][23] =
+ { { 0, NA, 1, 2, 3, 4, NA, 5, 6, 7, 8, NA, 9, 10, 11, 12, 13, 14, 15, NA, NA, NA, NA },
+ { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, NA, 27, 28, 29, NA, 30, 31, 32, 33, 34, 35, 36 },
+ { 37, NA, 38, 39, 40, 41, NA, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 },
+ { 58, NA, 59, 60, 61, 62, NA, 63, 64, 65, 66, 67, 68, 69, 70, NA, NA, NA, NA, 71, 72, 73, NA },
+ { 74, NA, 75, 76, 77, 78, NA, 79, NA, 80, 81, 82, 83, 84, 85, NA, NA, 86, NA, 87, 88, 89, 90 },
+ { 91, 92, 93, NA, NA, NA, NA, 94, NA, NA, NA, NA, 95, 96, 97, 98, 99, 100, 101, 102, NA, 103, NA } };
+
+static const unsigned int k551_logical_led_count = 104;
+static const unsigned int k551_framebuffer_led_count = 128;
+static const unsigned char k551_unmapped_led = 0xFF;
+
+/*---------------------------------------------------------*\
+| Raw 0x12 framebuffer slot -> OpenRGB logical LED. |
+| Repeated logical indices intentionally drive the two LED |
+| emitters under Enter, Left Shift, and Right Shift. |
+\*---------------------------------------------------------*/
+static const unsigned char k551_raw_to_logical_led[k551_framebuffer_led_count] =
+ {
+ 0, 16, 37, 58, 74, 91, 33, k551_unmapped_led, 1, 17, 38, 59, 74, 92, 34, k551_unmapped_led,
+ 2, 18, 39, 60, 75, 93, 35, k551_unmapped_led, 3, 19, 40, 61, 76, k551_unmapped_led, 36, k551_unmapped_led,
+ 4, 20, 41, 62, 77, k551_unmapped_led, 54, k551_unmapped_led, 5, 21, 42, 63, 78, 94, 55, k551_unmapped_led,
+ 6, 22, 43, 64, 79, k551_unmapped_led, 56, k551_unmapped_led, 7, 23, 44, 65, 80, k551_unmapped_led, 71, k551_unmapped_led,
+ 8, 24, 45, 66, 81, k551_unmapped_led, 72, k551_unmapped_led, 9, 25, 46, 67, 82, 95, 73, k551_unmapped_led,
+ 10, 26, 47, 68, 83, 96, 57, k551_unmapped_led, 11, 27, 48, 69, 84, 97, 88, k551_unmapped_led,
+ 12, 28, 49, 70, 85, 98, 89, k551_unmapped_led, 13, 29, 50, 70, 85, 99, 102, k551_unmapped_led,
+ 14, 30, 51, 32, 86, 100, 103, k551_unmapped_led, 15, 31, 52, 53, 87, 101, 90, k551_unmapped_led
+ };
+
+static const char* k551_led_names[k551_logical_led_count] =
+ {
+ "Esc", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "Print Screen", "Scroll Lock", "Pause",
+ "`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "Backspace", "Insert", "Home", "Page Up", "Num Lock", "Num /", "Num *", "Num -",
+ "Tab", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "\\", "Delete", "End", "Page Down", "Num 7", "Num 8", "Num 9", "Num +",
+ "Caps Lock", "A", "S", "D", "F", "G", "H", "J", "K", "L", ";", "'", "Enter", "Num 4", "Num 5", "Num 6",
+ "Left Shift", "Z", "X", "C", "V", "B", "N", "M", ",", ".", "/", "Right Shift", "Up", "Num 1", "Num 2", "Num 3", "Num Enter",
+ "Left Ctrl", "Left Win", "Left Alt", "Space", "Right Alt", "Fn", "Menu", "Right Ctrl", "Left", "Down", "Right", "Num 0", "Num ."
+ };
+
/**------------------------------------------------------------------*\
@name EVision Keyboard
@category Keyboard
@@ -37,6 +95,10 @@ static unsigned int matrix_map[6][23] =
RGBController_EVisionKeyboard::RGBController_EVisionKeyboard(EVisionKeyboardController* controller_ptr)
{
controller = controller_ptr;
+ direct_active = false;
+ keepalive_thread_run = false;
+ keepalive_thread = nullptr;
+ last_update_time = std::chrono::steady_clock::now();
name = controller->GetNameString();
vendor = "EVision";
@@ -45,6 +107,32 @@ RGBController_EVisionKeyboard::RGBController_EVisionKeyboard(EVisionKeyboardCont
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
+ if(controller->SupportsDirect())
+ {
+ name = "Redragon K551RGB-1 V2";
+ vendor = "Redragon";
+ description = "Redragon K551RGB-1 V2 Keyboard";
+
+ mode Direct;
+ Direct.name = "Direct";
+ Direct.value = EVISION_KB_MODE_DIRECT;
+ Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR;
+ Direct.color_mode = MODE_COLORS_PER_LED;
+ modes.push_back(Direct);
+
+ /*-------------------------------------------------*
+ | This firmware revision uses the RAM-only 0x12 |
+ | framebuffer for software effects. The legacy |
+ | EVision hardware-mode commands target a different |
+ | keyboard protocol and are deliberately not shown. |
+ \*-------------------------------------------------*/
+ SetupZones();
+
+ keepalive_thread_run = true;
+ keepalive_thread = new std::thread(&RGBController_EVisionKeyboard::KeepaliveThreadFunction, this);
+ return;
+ }
+
mode Custom;
Custom.name = "Custom";
Custom.value = EVISION_KB_MODE_CUSTOM;
@@ -298,12 +386,25 @@ RGBController_EVisionKeyboard::RGBController_EVisionKeyboard(EVisionKeyboardCont
modes.push_back(ReactiveLine);
SetupZones();
+
}
RGBController_EVisionKeyboard::~RGBController_EVisionKeyboard()
{
Shutdown();
+ if(keepalive_thread != nullptr)
+ {
+ keepalive_thread_run = false;
+ keepalive_thread->join();
+ delete keepalive_thread;
+ }
+
+ if(direct_active.exchange(false))
+ {
+ controller->SendKeyboardDirectEnd();
+ }
+
delete controller;
}
@@ -313,19 +414,26 @@ void RGBController_EVisionKeyboard::SetupZones()
new_zone.name = "Keyboard";
new_zone.type = ZONE_TYPE_MATRIX;
- new_zone.leds_min = 126;
- new_zone.leds_max = 126;
- new_zone.leds_count = 126;
- new_zone.matrix_map.Set(6, 23, (unsigned int *)&matrix_map);
+ new_zone.leds_min = controller->SupportsDirect() ? k551_logical_led_count : 126;
+ new_zone.leds_max = controller->SupportsDirect() ? k551_logical_led_count : 126;
+ new_zone.leds_count = controller->SupportsDirect() ? k551_logical_led_count : 126;
+ new_zone.matrix_map.Set(6, 23, controller->SupportsDirect() ? (unsigned int *)&k551_matrix_map : (unsigned int *)&matrix_map);
zones.push_back(new_zone);
- for(int led_idx = 0; led_idx < 126; led_idx++)
+ for(unsigned int led_idx = 0; led_idx < new_zone.leds_count; led_idx++)
{
led new_led;
- new_led.name = "Keyboard LED ";
- new_led.name.append(std::to_string(led_idx));
+ if(controller->SupportsDirect())
+ {
+ new_led.name = k551_led_names[led_idx];
+ }
+ else
+ {
+ new_led.name = "Keyboard LED ";
+ new_led.name.append(std::to_string(led_idx));
+ }
leds.push_back(new_led);
}
@@ -335,20 +443,64 @@ void RGBController_EVisionKeyboard::SetupZones()
void RGBController_EVisionKeyboard::DeviceUpdateLEDs()
{
- unsigned char color_data[7*0x36];
+ std::lock_guard<std::mutex> update_lock(direct_update_mutex);
+
+ unsigned char color_data[k551_framebuffer_led_count * 3] = { 0 };
+ unsigned int color_data_size = 126 * 3;
+
+ last_update_time = std::chrono::steady_clock::now();
- for(int led_idx = 0; led_idx < 126; led_idx++)
+ if(controller->SupportsDirect())
+ {
+ color_data_size = sizeof(color_data);
+
+ /*-------------------------------------------------*
+ | Scatter the 104 OpenRGB keys through the exact |
+ | firmware mapping. This also mirrors the colors |
+ | onto the secondary Enter/Shift emitters and maps |
+ | NumPad Enter to raw slot 126. |
+ \*-------------------------------------------------*/
+ for(unsigned int framebuffer_slot = 0; framebuffer_slot < k551_framebuffer_led_count; framebuffer_slot++)
+ {
+ unsigned int led_idx = k551_raw_to_logical_led[framebuffer_slot];
+
+ if(led_idx >= k551_logical_led_count)
+ {
+ continue;
+ }
+
+ color_data[(3 * framebuffer_slot) + 0] = RGBGetRValue(colors[led_idx]);
+ color_data[(3 * framebuffer_slot) + 1] = RGBGetGValue(colors[led_idx]);
+ color_data[(3 * framebuffer_slot) + 2] = RGBGetBValue(colors[led_idx]);
+ }
+ }
+ else
{
- color_data[(3 * led_idx) + 0] = RGBGetRValue(colors[led_idx]);
- color_data[(3 * led_idx) + 1] = RGBGetGValue(colors[led_idx]);
- color_data[(3 * led_idx) + 2] = RGBGetBValue(colors[led_idx]);
+ for(int led_idx = 0; led_idx < 126; led_idx++)
+ {
+ color_data[(3 * led_idx) + 0] = RGBGetRValue(colors[led_idx]);
+ color_data[(3 * led_idx) + 1] = RGBGetGValue(colors[led_idx]);
+ color_data[(3 * led_idx) + 2] = RGBGetBValue(colors[led_idx]);
+ }
}
- controller->SetKeyboardColors
- (
- color_data,
- 0x36 * 7
- );
+ if(modes[active_mode].value == EVISION_KB_MODE_DIRECT)
+ {
+ controller->SetKeyboardColorsDirect
+ (
+ color_data,
+ color_data_size
+ );
+ direct_active.store(true);
+ }
+ else
+ {
+ controller->SetKeyboardColors
+ (
+ color_data,
+ color_data_size
+ );
+ }
}
void RGBController_EVisionKeyboard::DeviceUpdateZoneLEDs(int /*zone*/)
@@ -363,6 +515,16 @@ void RGBController_EVisionKeyboard::DeviceUpdateSingleLED(int /*led*/)
void RGBController_EVisionKeyboard::DeviceUpdateMode()
{
+ if(modes[active_mode].value == EVISION_KB_MODE_DIRECT)
+ {
+ return;
+ }
+
+ if(direct_active.exchange(false))
+ {
+ controller->SendKeyboardDirectEnd();
+ }
+
unsigned char red = 0x00;
unsigned char grn = 0x00;
unsigned char blu = 0x00;
@@ -387,3 +549,26 @@ void RGBController_EVisionKeyboard::DeviceUpdateMode()
blu
);
}
+
+void RGBController_EVisionKeyboard::KeepaliveThreadFunction()
+{
+ while(keepalive_thread_run.load())
+ {
+ if(direct_active.load())
+ {
+ bool update_required = false;
+
+ {
+ std::lock_guard<std::mutex> update_lock(direct_update_mutex);
+ update_required = (std::chrono::steady_clock::now() - last_update_time) > 100ms;
+ }
+
+ if(update_required)
+ {
+ UpdateLEDsInternal();
+ }
+ }
+
+ std::this_thread::sleep_for(5ms);
+ }
+}
diff --git a/Controllers/EVisionKeyboardController/EVisionV2KeyboardController/RGBController_EVisionKeyboard.h b/Controllers/EVisionKeyboardController/EVisionV2KeyboardController/RGBController_EVisionKeyboard.h
index 80c7c66..7464451 100644
--- a/Controllers/EVisionKeyboardController/EVisionV2KeyboardController/RGBController_EVisionKeyboard.h
+++ b/Controllers/EVisionKeyboardController/EVisionV2KeyboardController/RGBController_EVisionKeyboard.h
@@ -12,6 +12,10 @@
#pragma once
+#include <atomic>
+#include <chrono>
+#include <mutex>
+#include <thread>
#include "RGBController.h"
#include "EVisionKeyboardController.h"
@@ -29,6 +33,13 @@ public:
void DeviceUpdateMode();
+ void KeepaliveThreadFunction();
+
private:
EVisionKeyboardController* controller;
+ std::atomic<bool> direct_active;
+ std::atomic<bool> keepalive_thread_run;
+ std::thread* keepalive_thread;
+ std::mutex direct_update_mutex;
+ std::chrono::time_point<std::chrono::steady_clock> last_update_time;
};