Add Ducky TKL matrix map, select map based on USB PID

Commit amended for code style by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
D. Stuart Freeman 2021-10-04 13:23:19 -04:00 committed by Adam Honse
parent 09fae4d944
commit 5e4bc6651a
4 changed files with 69 additions and 27 deletions

View file

@ -10,10 +10,11 @@
#include <cstring>
#include "DuckyKeyboardController.h"
DuckyKeyboardController::DuckyKeyboardController(hid_device* dev_handle, const char* path)
DuckyKeyboardController::DuckyKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid)
{
dev = dev_handle;
location = path;
usb_pid = pid;
SendInitialize();
}
@ -44,6 +45,11 @@ std::string DuckyKeyboardController::GetSerialString()
return(return_string);
}
unsigned short DuckyKeyboardController::GetUSBPID()
{
return(usb_pid);
}
void DuckyKeyboardController::SendColors
(
unsigned char* color_data,

View file

@ -14,15 +14,27 @@
#pragma once
/*-----------------------------------------------------*\
| Ducky vendor ID |
\*-----------------------------------------------------*/
#define DUCKY_VID 0x04D9
/*-----------------------------------------------------*\
| Keyboard product IDs |
\*-----------------------------------------------------*/
#define DUCKY_SHINE_7_ONE_2_RGB_PID 0x0348
#define DUCKY_ONE_2_RGB_TKL_PID 0x0356
class DuckyKeyboardController
{
public:
DuckyKeyboardController(hid_device* dev_handle, const char* path);
DuckyKeyboardController(hid_device* dev_handle, const char* path, const unsigned short pid);
~DuckyKeyboardController();
std::string GetDeviceLocation();
std::string GetSerialString();
std::string GetDeviceLocation();
std::string GetSerialString();
unsigned short GetUSBPID();
void SendColors
(
unsigned char* color_data,
@ -32,6 +44,7 @@ public:
private:
hid_device* dev;
std::string location;
unsigned short usb_pid;
void SendInitialize();
void SendInitializeColorPacket();

View file

@ -4,17 +4,6 @@
#include "RGBController_DuckyKeyboard.h"
#include <hidapi/hidapi.h>
/*-----------------------------------------------------*\
| Ducky vendor ID |
\*-----------------------------------------------------*/
#define DUCKY_VID 0x04D9
/*-----------------------------------------------------*\
| Keyboard product IDs |
\*-----------------------------------------------------*/
#define DUCKY_SHINE_7_ONE_2_RGB_PID 0x0348
#define DUCKY_ONE_2_RGB_TKL_PID 0x0356
/******************************************************************************************\
* *
* DetectDuckyKeyboardControllers *
@ -28,7 +17,8 @@ void DetectDuckyKeyboardControllers(hid_device_info* info, const std::string& na
hid_device* dev = hid_open_path(info->path);
if( dev )
{
DuckyKeyboardController* controller = new DuckyKeyboardController(dev, info->path);
bool is_tkl = (info->product_id == DUCKY_ONE_2_RGB_TKL_PID);
DuckyKeyboardController* controller = new DuckyKeyboardController(dev, info->path, is_tkl);
RGBController_DuckyKeyboard* rgb_controller = new RGBController_DuckyKeyboard(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller);

View file

@ -20,6 +20,15 @@ static unsigned int matrix_map[6][23] =
{ 4, 10, 16, 22, 28, 34, NA, 40, NA, 46, 52, 58, 64, 70, 82, NA, NA, 100, NA, 112, 118, 124, 131 },
{ 5, 11, 17, NA, NA, NA, NA, 41, NA, NA, NA, NA, 65, 77, 83, 89, 95, 101, 107, 113, NA, 125, NA } };
static unsigned int matrix_map_tkl[6][19] =
{ { 0, NA, 12, 18, 24, 30, NA, 42, 48, 54, 60, NA, 66, 72, 78, 84, 90, 96, 102 },
{ 1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, NA, 67, 73, 85, NA, 91, 97, 103 },
{ 2, NA, 8, 14, 20, 26, NA, 32, 38, 44, 50, 56, 62, 68, 74, 86, 92, 98, 104 },
{ 3, NA, 9, 15, 21, 27, NA, 33, 39, 45, 51, 57, 63, 69, 75, 87, NA, NA, NA },
{ 4, 10, 16, 22, 28, 34, NA, 40, NA, 46, 52, 58, 64, 70, 82, NA, NA, 100, NA },
{ 5, 11, 17, NA, NA, NA, NA, 41, NA, NA, NA, NA, 65, 77, 83, 89, 95, 101, 107 } };
static const char* zone_names[] =
{
"Keyboard"
@ -35,6 +44,11 @@ static const unsigned int zone_sizes[] =
132
};
static const unsigned int zone_sizes_tkl[] =
{
108
};
static const char *led_names[] =
{
"Key: Escape",
@ -216,19 +230,38 @@ void RGBController_DuckyKeyboard::SetupZones()
unsigned int total_led_count = 0;
for(unsigned int zone_idx = 0; zone_idx < 1; zone_idx++)
{
unsigned int zone_size = 0;
unsigned int matrix_width = 0;
unsigned int* matrix_map_ptr = NULL;
switch(ducky->GetUSBPID())
{
case DUCKY_SHINE_7_ONE_2_RGB_PID:
zone_size = zone_sizes[zone_idx];
matrix_width = 23;
matrix_map_ptr = (unsigned int *)&matrix_map;
break;
case DUCKY_ONE_2_RGB_TKL_PID:
zone_size = zone_sizes_tkl[zone_idx];
matrix_width = 19;
matrix_map_ptr = (unsigned int *)&matrix_map_tkl;
break;
}
zone new_zone;
new_zone.name = zone_names[zone_idx];
new_zone.type = zone_types[zone_idx];
new_zone.leds_min = zone_sizes[zone_idx];
new_zone.leds_max = zone_sizes[zone_idx];
new_zone.leds_count = zone_sizes[zone_idx];
new_zone.matrix_map = new matrix_map_type;
new_zone.matrix_map->height = 6;
new_zone.matrix_map->width = 23;
new_zone.matrix_map->map = (unsigned int *)&matrix_map;
new_zone.name = zone_names[zone_idx];
new_zone.type = zone_types[zone_idx];
new_zone.leds_min = zone_size;
new_zone.leds_max = zone_size;
new_zone.leds_count = zone_size;
new_zone.matrix_map = new matrix_map_type;
new_zone.matrix_map->height = 6;
new_zone.matrix_map->width = matrix_width;
new_zone.matrix_map->map = matrix_map_ptr;
zones.push_back(new_zone);
total_led_count += zone_sizes[zone_idx];
total_led_count += zone_size;
}
for(unsigned int led_idx = 0; led_idx < total_led_count; led_idx++)