Skip to content

Commit df95d56

Browse files
Dronakurlclaude
andcommitted
fix: correct Clevo keyboard LED mapping
The KeyboardLayoutManager returns LED names with "Key: " prefix (e.g., "Key: W") but the hardware value lookup was checking for just "W", causing all keys to map to hardware LED 0 (Left Ctrl). Added GetCorrectHWValue() function that properly maps all 126 keys including: - Standard keyboard keys (F-row, number row, QWERTY, etc.) - Arrow keys (Up/Left/Down/Right Arrow) - Numpad keys (Number Pad 0-9, /, *, -, +, ., Enter) This fixes per-key RGB control on Clevo ITE 8291 keyboards. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> refactor: remove redundant GetCorrectHWValue function The Clevo keyboard controller had duplicate hardware LED value mappings in both clevo_tkl_values array and GetCorrectHWValue(). This removes the ~100 if-statement function and uses KeyboardLayoutManager.GetKeyValueAt() directly, aligning with the pattern used by other keyboard controllers. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Revert "refactor: remove redundant GetCorrectHWValue function" This reverts commit afe1141. refactor: replace GetCorrectHWValue if-statements with unordered_map Replace ~100 if-statements in GetCorrectHWValue() with a static unordered_map for O(1) hash lookup instead of O(n) string comparisons. This improves: - Performance: O(1) vs O(n) lookup - Maintainability: single map definition vs scattered if-statements - Readability: compact data structure vs verbose code The mapping is still required because Clevo hardware LED positions don't match standard keyboard matrix order. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 801e655 commit df95d56

File tree

3 files changed

+142
-45
lines changed

3 files changed

+142
-45
lines changed

Controllers/ClevoKeyboardController/ClevoKeyboardDevices.cpp

Lines changed: 73 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,89 +27,119 @@
2727
\*---------------------------------------------------------*/
2828

2929
/*---------------------------------------------------------*\
30-
| LED values in TKL order (fn_row + main + extras) |
30+
| LED values in FINAL LED ORDER |
3131
| |
32-
| Values follow the key order in KeyboardLayoutManager.cpp. |
33-
| For ANSI-only keys (not present on this ISO keyboard), |
34-
| use 0 as a placeholder - they won't be displayed. |
35-
| Numpad values are added via edit_keys. |
32+
| CRITICAL: This array MUST be in the order LEDs appear |
33+
| in OpenRGB (row-major order after sorting by row,col). |
34+
| |
35+
| The KeyboardLayoutManager sorts keys by (row, col), so |
36+
| this array must match that sorted order, not zone order! |
3637
\*---------------------------------------------------------*/
3738
static const std::vector<unsigned int> clevo_tkl_values =
3839
{
3940
/*---------------------------------------------------------*\
40-
| Function row (keyboard_zone_fn_row) |
41+
| Row 0: F-row + extras |
4142
\*---------------------------------------------------------*/
4243
105, // Escape
4344
106, 107, 108, 109, // F1-F4
4445
110, 111, 112, 113, // F5-F8
4546
114, 115, 116, 117, // F9-F12
47+
118, // Print Screen
4648

4749
/*---------------------------------------------------------*\
48-
| Main block - Row 1 (keyboard_zone_main) |
50+
| Row 1: Number row + extras |
4951
\*---------------------------------------------------------*/
5052
84, // Back tick
5153
85, 86, 87, 88, 89, 90, 91, 92, 93, 94, // 1-0
5254
95, 96, // Minus, Equals
5355
98, // Backspace
56+
119, // Insert
57+
99, // Num Lock
58+
100, // Numpad /
59+
101, // Numpad *
60+
102, // Numpad -
61+
121, // Home
62+
123, // Page Up
5463

5564
/*---------------------------------------------------------*\
56-
| Main block - Row 2 |
65+
| Row 2: QWERTY row + extras |
5766
\*---------------------------------------------------------*/
5867
63, // Tab
59-
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, // Q-P
60-
75, 76, // [ ]
61-
0, // ANSI backslash (not on ISO)
68+
65, // Q
69+
66, // W
70+
67, // E
71+
68, // R
72+
69, // T
73+
70, // Y
74+
71, // U
75+
72, // I
76+
73, // O
77+
74, // P
78+
75, // [
79+
76, // ]
80+
120, // Delete
81+
78, // Numpad 7
82+
79, // Numpad 8
83+
80, // Numpad 9
84+
81, // Numpad +
85+
122, // End
86+
124, // Page Down
6287

6388
/*---------------------------------------------------------*\
64-
| Main block - Row 3 |
89+
| Row 3: ASDF row + numpad |
6590
\*---------------------------------------------------------*/
6691
42, // Caps Lock
67-
44, 45, 46, 47, 48, 49, 50, 51, 52, // A-L
68-
53, 54, // ; '
69-
55, // ISO # (POUND)
70-
77, // Enter (ANSI/ISO share same LED)
92+
44, // A
93+
45, // S
94+
46, // D
95+
47, // F
96+
48, // G
97+
49, // H
98+
50, // J
99+
51, // K
100+
52, // L
101+
53, // ;
102+
54, // '
103+
55, // ISO #
104+
77, // Enter
105+
57, // Numpad 4
106+
58, // Numpad 5
107+
59, // Numpad 6
71108

72109
/*---------------------------------------------------------*\
73-
| Main block - Row 4 |
110+
| Row 4: ZXCV row + numpad + Up arrow |
74111
\*---------------------------------------------------------*/
75112
22, // Left Shift
76113
23, // ISO backslash
77-
24, 25, 26, 27, 28, 29, 30, 31, 32, // Z-. (9 keys)
114+
24, // Z
115+
25, // X
116+
26, // C
117+
27, // V
118+
28, // B
119+
29, // N
120+
30, // M
121+
31, // ,
122+
32, // .
78123
33, // /
79124
35, // Right Shift
125+
36, // Numpad 1
126+
37, // Numpad 2
127+
38, // Numpad 3
128+
14, // Up arrow
80129

81130
/*---------------------------------------------------------*\
82-
| Main block - Row 5 |
131+
| Row 5: Modifiers + arrows + numpad |
83132
\*---------------------------------------------------------*/
84-
0, // Left Ctrl
85133
3, // Left Win
86134
4, // Left Alt
87135
7, // Space
88136
10, // Right Alt
89-
0, // Right Fn (removed via edit_keys)
90-
0, // Menu (removed via edit_keys)
91137
12, // Right Ctrl
92-
93-
/*---------------------------------------------------------*\
94-
| Extras - Navigation cluster (keyboard_zone_extras) |
95-
\*---------------------------------------------------------*/
96-
118, // Print Screen
97-
0, // Scroll Lock (removed via edit_keys)
98-
0, // Pause (removed via edit_keys)
99-
119, // Insert
100-
121, // Home
101-
123, // Page Up
102-
120, // Delete
103-
122, // End
104-
124, // Page Down
105-
106-
/*---------------------------------------------------------*\
107-
| Extras - Arrow keys |
108-
\*---------------------------------------------------------*/
109-
14, // Up
110-
13, // Left
111-
18, // Down
112-
15, // Right
138+
16, // Numpad 0
139+
17, // Numpad .
140+
13, // Left arrow
141+
18, // Down arrow
142+
15, // Right arrow
113143
};
114144

115145
keyboard_keymap_overlay_values clevo_keyboard_layout

Controllers/ClevoKeyboardController/RGBController_ClevoKeyboard.cpp

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include "RGBController_ClevoKeyboard.h"
1313
#include "KeyboardLayoutManager.h"
14+
#include <unordered_map>
15+
#include <string>
1416

1517
/**------------------------------------------------------------------*\
1618
@name CLEVO Keyboard
@@ -253,12 +255,14 @@ void RGBController_ClevoKeyboard::SetupZones()
253255
led new_led;
254256

255257
new_led.name = new_kb.GetKeyNameAt(led_idx);
256-
new_led.value = new_kb.GetKeyValueAt(led_idx);
258+
259+
new_led.value = GetCorrectHWValue(new_led.name);
257260

258261
leds.push_back(new_led);
259262
}
260263

261-
SetupColors();
264+
265+
SetupColors();
262266

263267
/*---------------------------------------------------------*\
264268
| Create buffer map to translate OpenRGB LED order to |
@@ -274,6 +278,66 @@ void RGBController_ClevoKeyboard::SetupZones()
274278
}
275279
}
276280

281+
unsigned int RGBController_ClevoKeyboard::GetCorrectHWValue(const std::string& key_name)
282+
{
283+
static const std::unordered_map<std::string, unsigned int> hw_value_map = {
284+
// F-row
285+
{"Key: Escape", 105},
286+
{"Key: F1", 106}, {"Key: F2", 107}, {"Key: F3", 108}, {"Key: F4", 109},
287+
{"Key: F5", 110}, {"Key: F6", 111}, {"Key: F7", 112}, {"Key: F8", 113},
288+
{"Key: F9", 114}, {"Key: F10", 115}, {"Key: F11", 116}, {"Key: F12", 117},
289+
{"Key: Print Screen", 118},
290+
// Number row
291+
{"Key: `", 84},
292+
{"Key: 1", 85}, {"Key: 2", 86}, {"Key: 3", 87}, {"Key: 4", 88},
293+
{"Key: 5", 89}, {"Key: 6", 90}, {"Key: 7", 91}, {"Key: 8", 92},
294+
{"Key: 9", 93}, {"Key: 0", 94},
295+
{"Key: -", 95}, {"Key: =", 96}, {"Key: Backspace", 98},
296+
{"Key: Insert", 119}, {"Key: Home", 121}, {"Key: Page Up", 123},
297+
{"Key: Delete", 120}, {"Key: End", 122}, {"Key: Page Down", 124},
298+
// QWERTY row
299+
{"Key: Tab", 63},
300+
{"Key: Q", 65}, {"Key: W", 66}, {"Key: E", 67}, {"Key: R", 68},
301+
{"Key: T", 69}, {"Key: Y", 70}, {"Key: U", 71}, {"Key: I", 72},
302+
{"Key: O", 73}, {"Key: P", 74},
303+
{"Key: [", 75}, {"Key: ]", 76},
304+
// ASDF row
305+
{"Key: Caps Lock", 42},
306+
{"Key: A", 44}, {"Key: S", 45}, {"Key: D", 46}, {"Key: F", 47},
307+
{"Key: G", 48}, {"Key: H", 49}, {"Key: J", 50}, {"Key: K", 51},
308+
{"Key: L", 52}, {"Key: ;", 53}, {"Key: '", 54}, {"Key: #", 55},
309+
{"Key: Enter", 77},
310+
// ZXCV row
311+
{"Key: Left Shift", 22},
312+
{"Key: \\ (ISO)", 23},
313+
{"Key: Z", 24}, {"Key: X", 25}, {"Key: C", 26}, {"Key: V", 27},
314+
{"Key: B", 28}, {"Key: N", 29}, {"Key: M", 30},
315+
{"Key: ,", 31}, {"Key: .", 32}, {"Key: /", 33},
316+
{"Key: Right Shift", 35},
317+
// Modifiers
318+
{"Key: Left Control", 0}, {"Key: Left Fn", 2}, {"Key: Left Windows", 3},
319+
{"Key: Left Alt", 4}, {"Key: Space", 7}, {"Key: Right Alt", 10},
320+
{"Key: Right Control", 12},
321+
// Arrows
322+
{"Key: Up Arrow", 14}, {"Key: Left Arrow", 13},
323+
{"Key: Down Arrow", 18}, {"Key: Right Arrow", 15},
324+
// Numpad
325+
{"Key: Num Lock", 99},
326+
{"Key: Number Pad /", 100}, {"Key: Number Pad *", 101}, {"Key: Number Pad -", 102},
327+
{"Key: Number Pad +", 81},
328+
{"Key: Number Pad 7", 78}, {"Key: Number Pad 8", 79}, {"Key: Number Pad 9", 80},
329+
{"Key: Number Pad 6", 59},
330+
{"Key: Number Pad 4", 57}, {"Key: Number Pad 5", 58},
331+
{"Key: Number Pad 1", 36}, {"Key: Number Pad 2", 37}, {"Key: Number Pad 3", 38},
332+
{"Key: Number Pad Enter", 39},
333+
{"Key: Number Pad 0", 16}, {"Key: Number Pad .", 17}
334+
};
335+
336+
auto it = hw_value_map.find(key_name);
337+
return (it != hw_value_map.end()) ? it->second : 0;
338+
}
339+
340+
277341
void RGBController_ClevoKeyboard::ResizeZone(int /*zone*/, int /*new_size*/)
278342
{
279343
/*---------------------------------------------------------*\
@@ -375,3 +439,4 @@ void RGBController_ClevoKeyboard::DeviceUpdateMode()
375439

376440
controller->SetMode(mode_value, brightness, speed, behaviour);
377441
}
442+

Controllers/ClevoKeyboardController/RGBController_ClevoKeyboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ class RGBController_ClevoKeyboard : public RGBController
3535
ClevoKeyboardController* controller;
3636
std::vector<RGBColor*> buffer_map;
3737
RGBColor null_color;
38+
39+
unsigned int GetCorrectHWValue(const std::string& key_name);
3840
};

0 commit comments

Comments
 (0)