Skip to content

Commit 5e4bc66

Browse files
stuartfCalcProgrammer1
authored andcommitted
Add Ducky TKL matrix map, select map based on USB PID
Commit amended for code style by Adam Honse <[email protected]>
1 parent 09fae4d commit 5e4bc66

File tree

4 files changed

+69
-27
lines changed

4 files changed

+69
-27
lines changed

Controllers/DuckyKeyboardController/DuckyKeyboardController.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
#include <cstring>
1111
#include "DuckyKeyboardController.h"
1212

13-
DuckyKeyboardController::DuckyKeyboardController(hid_device* dev_handle, const char* path)
13+
DuckyKeyboardController::DuckyKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid)
1414
{
1515
dev = dev_handle;
1616
location = path;
17+
usb_pid = pid;
1718

1819
SendInitialize();
1920
}
@@ -44,6 +45,11 @@ std::string DuckyKeyboardController::GetSerialString()
4445
return(return_string);
4546
}
4647

48+
unsigned short DuckyKeyboardController::GetUSBPID()
49+
{
50+
return(usb_pid);
51+
}
52+
4753
void DuckyKeyboardController::SendColors
4854
(
4955
unsigned char* color_data,

Controllers/DuckyKeyboardController/DuckyKeyboardController.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,27 @@
1414

1515
#pragma once
1616

17+
/*-----------------------------------------------------*\
18+
| Ducky vendor ID |
19+
\*-----------------------------------------------------*/
20+
#define DUCKY_VID 0x04D9
21+
22+
/*-----------------------------------------------------*\
23+
| Keyboard product IDs |
24+
\*-----------------------------------------------------*/
25+
#define DUCKY_SHINE_7_ONE_2_RGB_PID 0x0348
26+
#define DUCKY_ONE_2_RGB_TKL_PID 0x0356
27+
1728
class DuckyKeyboardController
1829
{
1930
public:
20-
DuckyKeyboardController(hid_device* dev_handle, const char* path);
31+
DuckyKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid);
2132
~DuckyKeyboardController();
2233

23-
std::string GetDeviceLocation();
24-
std::string GetSerialString();
25-
34+
std::string GetDeviceLocation();
35+
std::string GetSerialString();
36+
unsigned short GetUSBPID();
37+
2638
void SendColors
2739
(
2840
unsigned char* color_data,
@@ -32,6 +44,7 @@ class DuckyKeyboardController
3244
private:
3345
hid_device* dev;
3446
std::string location;
47+
unsigned short usb_pid;
3548

3649
void SendInitialize();
3750
void SendInitializeColorPacket();

Controllers/DuckyKeyboardController/DuckyKeyboardControllerDetect.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44
#include "RGBController_DuckyKeyboard.h"
55
#include <hidapi/hidapi.h>
66

7-
/*-----------------------------------------------------*\
8-
| Ducky vendor ID |
9-
\*-----------------------------------------------------*/
10-
#define DUCKY_VID 0x04D9
11-
12-
/*-----------------------------------------------------*\
13-
| Keyboard product IDs |
14-
\*-----------------------------------------------------*/
15-
#define DUCKY_SHINE_7_ONE_2_RGB_PID 0x0348
16-
#define DUCKY_ONE_2_RGB_TKL_PID 0x0356
17-
187
/******************************************************************************************\
198
* *
209
* DetectDuckyKeyboardControllers *
@@ -28,7 +17,8 @@ void DetectDuckyKeyboardControllers(hid_device_info* info, const std::string& na
2817
hid_device* dev = hid_open_path(info->path);
2918
if( dev )
3019
{
31-
DuckyKeyboardController* controller = new DuckyKeyboardController(dev, info->path);
20+
bool is_tkl = (info->product_id == DUCKY_ONE_2_RGB_TKL_PID);
21+
DuckyKeyboardController* controller = new DuckyKeyboardController(dev, info->path, is_tkl);
3222
RGBController_DuckyKeyboard* rgb_controller = new RGBController_DuckyKeyboard(controller);
3323
rgb_controller->name = name;
3424
ResourceManager::get()->RegisterRGBController(rgb_controller);

Controllers/DuckyKeyboardController/RGBController_DuckyKeyboard.cpp

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ static unsigned int matrix_map[6][23] =
2020
{ 4, 10, 16, 22, 28, 34, NA, 40, NA, 46, 52, 58, 64, 70, 82, NA, NA, 100, NA, 112, 118, 124, 131 },
2121
{ 5, 11, 17, NA, NA, NA, NA, 41, NA, NA, NA, NA, 65, 77, 83, 89, 95, 101, 107, 113, NA, 125, NA } };
2222

23+
static unsigned int matrix_map_tkl[6][19] =
24+
{ { 0, NA, 12, 18, 24, 30, NA, 42, 48, 54, 60, NA, 66, 72, 78, 84, 90, 96, 102 },
25+
{ 1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, NA, 67, 73, 85, NA, 91, 97, 103 },
26+
{ 2, NA, 8, 14, 20, 26, NA, 32, 38, 44, 50, 56, 62, 68, 74, 86, 92, 98, 104 },
27+
{ 3, NA, 9, 15, 21, 27, NA, 33, 39, 45, 51, 57, 63, 69, 75, 87, NA, NA, NA },
28+
{ 4, 10, 16, 22, 28, 34, NA, 40, NA, 46, 52, 58, 64, 70, 82, NA, NA, 100, NA },
29+
{ 5, 11, 17, NA, NA, NA, NA, 41, NA, NA, NA, NA, 65, 77, 83, 89, 95, 101, 107 } };
30+
31+
2332
static const char* zone_names[] =
2433
{
2534
"Keyboard"
@@ -35,6 +44,11 @@ static const unsigned int zone_sizes[] =
3544
132
3645
};
3746

47+
static const unsigned int zone_sizes_tkl[] =
48+
{
49+
108
50+
};
51+
3852
static const char *led_names[] =
3953
{
4054
"Key: Escape",
@@ -216,19 +230,38 @@ void RGBController_DuckyKeyboard::SetupZones()
216230
unsigned int total_led_count = 0;
217231
for(unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
218232
{
233+
unsigned int zone_size = 0;
234+
unsigned int matrix_width = 0;
235+
unsigned int* matrix_map_ptr = NULL;
236+
237+
switch(ducky->GetUSBPID())
238+
{
239+
case DUCKY_SHINE_7_ONE_2_RGB_PID:
240+
zone_size = zone_sizes[zone_idx];
241+
matrix_width = 23;
242+
matrix_map_ptr = (unsigned int *)&matrix_map;
243+
break;
244+
245+
case DUCKY_ONE_2_RGB_TKL_PID:
246+
zone_size = zone_sizes_tkl[zone_idx];
247+
matrix_width = 19;
248+
matrix_map_ptr = (unsigned int *)&matrix_map_tkl;
249+
break;
250+
}
251+
219252
zone new_zone;
220-
new_zone.name = zone_names[zone_idx];
221-
new_zone.type = zone_types[zone_idx];
222-
new_zone.leds_min = zone_sizes[zone_idx];
223-
new_zone.leds_max = zone_sizes[zone_idx];
224-
new_zone.leds_count = zone_sizes[zone_idx];
225-
new_zone.matrix_map = new matrix_map_type;
226-
new_zone.matrix_map->height = 6;
227-
new_zone.matrix_map->width = 23;
228-
new_zone.matrix_map->map = (unsigned int *)&matrix_map;
253+
new_zone.name = zone_names[zone_idx];
254+
new_zone.type = zone_types[zone_idx];
255+
new_zone.leds_min = zone_size;
256+
new_zone.leds_max = zone_size;
257+
new_zone.leds_count = zone_size;
258+
new_zone.matrix_map = new matrix_map_type;
259+
new_zone.matrix_map->height = 6;
260+
new_zone.matrix_map->width = matrix_width;
261+
new_zone.matrix_map->map = matrix_map_ptr;
229262
zones.push_back(new_zone);
230263

231-
total_led_count += zone_sizes[zone_idx];
264+
total_led_count += zone_size;
232265
}
233266

234267
for(unsigned int led_idx = 0; led_idx < total_led_count; led_idx++)

0 commit comments

Comments
 (0)