Initial driver for Ducky One 2 keyboard
This commit is contained in:
parent
6492852627
commit
343c285321
7 changed files with 451 additions and 0 deletions
187
Controllers/DuckyKeyboardController/DuckyKeyboardController.cpp
Normal file
187
Controllers/DuckyKeyboardController/DuckyKeyboardController.cpp
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
/*-----------------------------------------*\
|
||||
| DuckyKeyboardController.cpp |
|
||||
| |
|
||||
| Driver for Ducky RGB keyboardlighting |
|
||||
| controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 7/4/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
#include "DuckyKeyboardController.h"
|
||||
|
||||
DuckyKeyboardController::DuckyKeyboardController(hid_device* dev_handle)
|
||||
{
|
||||
dev = dev_handle;
|
||||
|
||||
SendInitialize();
|
||||
}
|
||||
|
||||
DuckyKeyboardController::~DuckyKeyboardController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DuckyKeyboardController::SendColors
|
||||
(
|
||||
unsigned char* color_data,
|
||||
unsigned int color_data_size
|
||||
)
|
||||
{
|
||||
unsigned int bytes_sent;
|
||||
unsigned char* color_data_ptr = color_data;
|
||||
|
||||
SendInitializeColorPacket();
|
||||
|
||||
for(int i = 0; i < 8; i++)
|
||||
{
|
||||
bytes_sent = SendColorDataPacket(i, color_data_ptr, color_data_size);
|
||||
|
||||
color_data_ptr += bytes_sent;
|
||||
color_data_size -= bytes_sent;
|
||||
}
|
||||
|
||||
SendTerminateColorPacket();
|
||||
}
|
||||
|
||||
void DuckyKeyboardController::SendInitialize()
|
||||
{
|
||||
char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Initialize Direct Mode packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x00;
|
||||
usb_buf[0x01] = 0x41;
|
||||
usb_buf[0x02] = 0x01;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, (unsigned char *)usb_buf, 65);
|
||||
}
|
||||
|
||||
void DuckyKeyboardController::SendInitializeColorPacket()
|
||||
{
|
||||
char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Initialize Color packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x00;
|
||||
usb_buf[0x01] = 0x56;
|
||||
usb_buf[0x02] = 0x81;
|
||||
usb_buf[0x05] = 0x01;
|
||||
usb_buf[0x09] = 0x08;
|
||||
usb_buf[0x0D] = 0xAA;
|
||||
usb_buf[0x0E] = 0xAA;
|
||||
usb_buf[0x0F] = 0xAA;
|
||||
usb_buf[0x10] = 0xAA;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, (unsigned char *)usb_buf, 65);
|
||||
}
|
||||
|
||||
unsigned int DuckyKeyboardController::SendColorDataPacket
|
||||
(
|
||||
unsigned char packet_id,
|
||||
unsigned char* color_data,
|
||||
unsigned int color_size
|
||||
)
|
||||
{
|
||||
unsigned int bytes_sent;
|
||||
char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Color Data packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x00;
|
||||
usb_buf[0x01] = 0x56;
|
||||
usb_buf[0x02] = 0x83;
|
||||
usb_buf[0x03] = packet_id;
|
||||
|
||||
if(packet_id == 0x00)
|
||||
{
|
||||
usb_buf[0x05] = 0x01;
|
||||
usb_buf[0x09] = 0x80;
|
||||
usb_buf[0x0A] = 0x01;
|
||||
usb_buf[0x0C] = 0xC1;
|
||||
usb_buf[0x11] = 0xFF;
|
||||
usb_buf[0x12] = 0xFF;
|
||||
usb_buf[0x13] = 0xFF;
|
||||
usb_buf[0x14] = 0xFF;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Copy in color data |
|
||||
\*-----------------------------------------------------*/
|
||||
if(packet_id == 0x00)
|
||||
{
|
||||
bytes_sent = 65 - 0x19;
|
||||
|
||||
if(color_size < bytes_sent)
|
||||
{
|
||||
bytes_sent = color_size;
|
||||
}
|
||||
|
||||
memcpy(&usb_buf[0x19], color_data, bytes_sent);
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes_sent = 65 - 0x05;
|
||||
|
||||
if(color_size < bytes_sent)
|
||||
{
|
||||
bytes_sent = color_size;
|
||||
}
|
||||
|
||||
memcpy(&usb_buf[0x05], color_data, bytes_sent);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, (unsigned char *)usb_buf, 65);
|
||||
|
||||
return(bytes_sent);
|
||||
}
|
||||
|
||||
void DuckyKeyboardController::SendTerminateColorPacket()
|
||||
{
|
||||
char usb_buf[65];
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Zero out buffer |
|
||||
\*-----------------------------------------------------*/
|
||||
memset(usb_buf, 0x00, sizeof(usb_buf));
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Set up Terminate Color packet |
|
||||
\*-----------------------------------------------------*/
|
||||
usb_buf[0x00] = 0x00;
|
||||
usb_buf[0x01] = 0x51;
|
||||
usb_buf[0x02] = 0x28;
|
||||
usb_buf[0x05] = 0xFF;
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Send packet |
|
||||
\*-----------------------------------------------------*/
|
||||
hid_write(dev, (unsigned char *)usb_buf, 65);
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*-----------------------------------------*\
|
||||
| DuckyKeyboardController.h |
|
||||
| |
|
||||
| Definitions and types for Ducky RGB |
|
||||
| keyboard lighting controller |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 7/4/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController.h"
|
||||
|
||||
#include <string>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
class DuckyKeyboardController
|
||||
{
|
||||
public:
|
||||
DuckyKeyboardController(hid_device* dev_handle);
|
||||
~DuckyKeyboardController();
|
||||
|
||||
void SendColors
|
||||
(
|
||||
unsigned char* color_data,
|
||||
unsigned int color_data_size
|
||||
);
|
||||
|
||||
private:
|
||||
hid_device* dev;
|
||||
|
||||
void SendInitialize();
|
||||
void SendInitializeColorPacket();
|
||||
unsigned int SendColorDataPacket
|
||||
(
|
||||
unsigned char packet_id,
|
||||
unsigned char* color_data,
|
||||
unsigned int color_size
|
||||
);
|
||||
void SendTerminateColorPacket();
|
||||
};
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
#include "DuckyKeyboardController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_DuckyKeyboard.h"
|
||||
#include <vector>
|
||||
#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
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned short usb_vid;
|
||||
unsigned short usb_pid;
|
||||
unsigned char usb_interface;
|
||||
const char * name;
|
||||
} ducky_device;
|
||||
|
||||
#define DUCKY_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[ 0 ]))
|
||||
|
||||
static const ducky_device device_list[] =
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| Keyboards |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
{ DUCKY_VID, DUCKY_SHINE_7_ONE_2_RGB_PID, 1, "Ducky Shine 7/Ducky One 2 RGB" },
|
||||
{ DUCKY_VID, DUCKY_ONE_2_RGB_TKL_PID, 1, "Ducky One 2 RGB TKL" },
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectDuckyKeyboardControllers *
|
||||
* *
|
||||
* Tests the USB address to see if a Ducky RGB Keyboard controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectDuckyKeyboardControllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
hid_device_info* info;
|
||||
hid_device* dev;
|
||||
|
||||
hid_init();
|
||||
|
||||
for(std::size_t device_idx = 0; device_idx < DUCKY_NUM_DEVICES; device_idx++)
|
||||
{
|
||||
dev = NULL;
|
||||
|
||||
info = hid_enumerate(device_list[device_idx].usb_vid, device_list[device_idx].usb_pid);
|
||||
|
||||
//Look for Ducky RGB Peripheral
|
||||
while(info)
|
||||
{
|
||||
if((info->vendor_id == device_list[device_idx].usb_vid)
|
||||
&&(info->product_id == device_list[device_idx].usb_pid)
|
||||
&&(info->interface_number == device_list[device_idx].usb_interface))
|
||||
{
|
||||
dev = hid_open_path(info->path);
|
||||
|
||||
if( dev )
|
||||
{
|
||||
DuckyKeyboardController* controller = new DuckyKeyboardController(dev);
|
||||
|
||||
RGBController_DuckyKeyboard* rgb_controller = new RGBController_DuckyKeyboard(controller);
|
||||
|
||||
rgb_controller->name = device_list[device_idx].name;
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
info = info->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -351,6 +351,7 @@ void DetectLogitechControllers(std::vector<RGBController*>& rgb_controllers);
|
|||
void DetectNZXTKrakenControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectSteelSeriesControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectGloriousModelOControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
void DetectDuckyKeyboardControllers(std::vector<RGBController*>& rgb_controllers);
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
|
|
@ -402,6 +403,7 @@ void DetectRGBControllers(void)
|
|||
DetectNZXTKrakenControllers(rgb_controllers);
|
||||
DetectSteelSeriesControllers(rgb_controllers);
|
||||
DetectGloriousModelOControllers(rgb_controllers);
|
||||
DetectDuckyKeyboardControllers(rgb_controllers);
|
||||
|
||||
DetectE131Controllers(rgb_controllers);
|
||||
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ INCLUDEPATH += \
|
|||
Controllers/CorsairVengeanceController/ \
|
||||
Controllers/CorsairVengeanceProController/ \
|
||||
Controllers/CrucialController/ \
|
||||
Controllers/DuckyKeyboardController/ \
|
||||
Controllers/GloriousModelOController/ \
|
||||
Controllers/HuePlusController/ \
|
||||
Controllers/HyperXDRAMController/ \
|
||||
|
|
@ -118,6 +119,7 @@ HEADERS += \
|
|||
Controllers/CorsairVengeanceController/CorsairVengeanceController.h \
|
||||
Controllers/CorsairVengeanceProController/CorsairVengeanceProController.h \
|
||||
Controllers/CrucialController/CrucialController.h \
|
||||
Controllers/DuckyKeyboardController/DuckyKeyboardController.h \
|
||||
Controllers/GloriousModelOController/GloriousModelOController.h \
|
||||
Controllers/HuePlusController/HuePlusController.h \
|
||||
Controllers/HyperXDRAMController/HyperXDRAMController.h \
|
||||
|
|
@ -156,6 +158,7 @@ HEADERS += \
|
|||
RGBController/RGBController_CorsairVengeance.h \
|
||||
RGBController/RGBController_CorsairVengeancePro.h \
|
||||
RGBController/RGBController_Crucial.h \
|
||||
RGBController/RGBController_DuckyKeyboard.h \
|
||||
RGBController/RGBController_Dummy.h \
|
||||
RGBController/RGBController_E131.h \
|
||||
RGBController/RGBController_GloriousModelO.h \
|
||||
|
|
@ -235,6 +238,8 @@ SOURCES += \
|
|||
Controllers/CorsairVengeanceProController/CorsairVengeanceProControllerDetect.cpp \
|
||||
Controllers/CrucialController/CrucialController.cpp \
|
||||
Controllers/CrucialController/CrucialControllerDetect.cpp \
|
||||
Controllers/DuckyKeyboardController/DuckyKeyboardController.cpp \
|
||||
Controllers/DuckyKeyboardController/DuckyKeyboardControllerDetect.cpp \
|
||||
Controllers/GloriousModelOController/GloriousModelOController.cpp \
|
||||
Controllers/GloriousModelOController/GloriousModelOControllerDetect.cpp \
|
||||
Controllers/HuePlusController/HuePlusController.cpp \
|
||||
|
|
@ -296,6 +301,7 @@ SOURCES += \
|
|||
RGBController/RGBController_CorsairVengeance.cpp \
|
||||
RGBController/RGBController_CorsairVengeancePro.cpp \
|
||||
RGBController/RGBController_Crucial.cpp \
|
||||
RGBController/RGBController_DuckyKeyboard.cpp \
|
||||
RGBController/RGBController_Dummy.cpp \
|
||||
RGBController/RGBController_GloriousModelO.cpp \
|
||||
RGBController/RGBController_HuePlus.cpp \
|
||||
|
|
|
|||
101
RGBController/RGBController_DuckyKeyboard.cpp
Normal file
101
RGBController/RGBController_DuckyKeyboard.cpp
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/*-----------------------------------------*\
|
||||
| RGBController_DuckyKeyboard.cpp |
|
||||
| |
|
||||
| Generic RGB Interface for Ducky RGB |
|
||||
| keyboard devices |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 7/4/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#include "RGBController_DuckyKeyboard.h"
|
||||
|
||||
RGBController_DuckyKeyboard::RGBController_DuckyKeyboard(DuckyKeyboardController* ducky_ptr)
|
||||
{
|
||||
ducky = ducky_ptr;
|
||||
|
||||
name = "Ducky Keyboard Device";
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
description = "Ducky Keyboard Device";
|
||||
|
||||
mode Custom;
|
||||
Custom.name = "Custom";
|
||||
Custom.value = 0xFFFF;
|
||||
Custom.flags = MODE_FLAG_HAS_PER_LED_COLOR;
|
||||
Custom.color_mode = MODE_COLORS_PER_LED;
|
||||
modes.push_back(Custom);
|
||||
|
||||
SetupZones();
|
||||
}
|
||||
|
||||
RGBController_DuckyKeyboard::~RGBController_DuckyKeyboard()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_DuckyKeyboard::SetupZones()
|
||||
{
|
||||
zone new_zone;
|
||||
|
||||
new_zone.name = "Keyboard";
|
||||
new_zone.type = ZONE_TYPE_MATRIX;
|
||||
new_zone.leds_min = 155;
|
||||
new_zone.leds_max = 155;
|
||||
new_zone.leds_count = 155;
|
||||
new_zone.matrix_map = NULL;//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;
|
||||
|
||||
zones.push_back(new_zone);
|
||||
|
||||
for(int led_idx = 0; led_idx < 155; led_idx++)
|
||||
{
|
||||
led new_led;
|
||||
|
||||
new_led.name = "Keyboard LED ";
|
||||
new_led.name.append(std::to_string(led_idx));
|
||||
|
||||
leds.push_back(new_led);
|
||||
}
|
||||
|
||||
SetupColors();
|
||||
}
|
||||
|
||||
void RGBController_DuckyKeyboard::ResizeZone(int zone, int new_size)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_DuckyKeyboard::DeviceUpdateLEDs()
|
||||
{
|
||||
unsigned char colordata[155*3];
|
||||
|
||||
for(int color_idx = 0; color_idx < colors.size(); color_idx++)
|
||||
{
|
||||
colordata[(color_idx*3)+0] = RGBGetRValue(colors[color_idx]);
|
||||
colordata[(color_idx*3)+1] = RGBGetGValue(colors[color_idx]);
|
||||
colordata[(color_idx*3)+2] = RGBGetBValue(colors[color_idx]);
|
||||
}
|
||||
|
||||
ducky->SendColors(colordata, sizeof(colordata));
|
||||
}
|
||||
|
||||
void RGBController_DuckyKeyboard::UpdateZoneLEDs(int zone)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_DuckyKeyboard::UpdateSingleLED(int led)
|
||||
{
|
||||
DeviceUpdateLEDs();
|
||||
}
|
||||
|
||||
void RGBController_DuckyKeyboard::SetCustomMode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RGBController_DuckyKeyboard::UpdateMode()
|
||||
{
|
||||
|
||||
}
|
||||
33
RGBController/RGBController_DuckyKeyboard.h
Normal file
33
RGBController/RGBController_DuckyKeyboard.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*-----------------------------------------*\
|
||||
| RGBController_DuckyKeyboard.h |
|
||||
| |
|
||||
| Generic RGB Interface for Ducky RGB |
|
||||
| keyboard devices |
|
||||
| |
|
||||
| Adam Honse (CalcProgrammer1) 7/4/2020 |
|
||||
\*-----------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
#include "RGBController.h"
|
||||
#include "DuckyKeyboardController.h"
|
||||
|
||||
class RGBController_DuckyKeyboard : public RGBController
|
||||
{
|
||||
public:
|
||||
RGBController_DuckyKeyboard(DuckyKeyboardController* ducky_ptr);
|
||||
~RGBController_DuckyKeyboard();
|
||||
|
||||
void SetupZones();
|
||||
|
||||
void ResizeZone(int zone, int new_size);
|
||||
|
||||
void DeviceUpdateLEDs();
|
||||
void UpdateZoneLEDs(int zone);
|
||||
void UpdateSingleLED(int led);
|
||||
|
||||
void SetCustomMode();
|
||||
void UpdateMode();
|
||||
|
||||
private:
|
||||
DuckyKeyboardController* ducky;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue