Skip to content

Commit e9eca70

Browse files
Chr1sNoCalcProgrammer1
authored andcommitted
Initial commit for the Dark Project KD3B Keyboard to resolve #2292
* Creating detector class and adding entry for the Dark Project KD3B VID & PID * Registered detectors * Creating DarkProjectKeyboardController class * Creating RGBController_DarkProjectKeyboard class * Added UDEV rule to 60-openrgb.rules
1 parent 42b9550 commit e9eca70

6 files changed

+464
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "Detector.h"
2+
#include "RGBController.h"
3+
4+
#include "RGBController_DarkProjectKeyboard.h"
5+
6+
/*---------------------------------------------------------*\
7+
| Dark Project vendor ID |
8+
\*---------------------------------------------------------*/
9+
#define DARKPROJECT_VID 0x195D
10+
11+
/*---------------------------------------------------------*\
12+
| Product IDs |
13+
\*---------------------------------------------------------*/
14+
#define KD3B_V2_PID 0x2061
15+
16+
void DetectDarkProjectKeyboardControllers(hid_device_info* info, const std::string& name)
17+
{
18+
hid_device* dev = hid_open_path(info->path);
19+
20+
if(dev)
21+
{
22+
DarkProjectKeyboardController* controller = new DarkProjectKeyboardController(dev, info->path);
23+
RGBController_DarkProjectKeyboard* rgb_controller = new RGBController_DarkProjectKeyboard(controller);
24+
rgb_controller->name = name;
25+
ResourceManager::get()->RegisterRGBController(rgb_controller);
26+
}
27+
}
28+
29+
REGISTER_HID_DETECTOR_IPU("Dark Project KD3B V2", DetectDarkProjectKeyboardControllers, DARKPROJECT_VID, KD3B_V2_PID, 2, 0xFFC2, 4);
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*-------------------------------------------------------------------*\
2+
| DarkProjectKeyboardController.cpp |
3+
| |
4+
| Driver for DarkProjectKeyboard USB Controller |
5+
| |
6+
| Chris M (DrNo) 8 Apr 2022 |
7+
| |
8+
\*-------------------------------------------------------------------*/
9+
10+
#include "LogManager.h"
11+
#include "DarkProjectKeyboardController.h"
12+
13+
static uint8_t packet_map[88] =
14+
{
15+
/*00 ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 */
16+
5, 11, 17, 23, 29, 35, 41, 47, 53, 59,
17+
18+
/*10 F10 F11 F12 PRT SLK PBK ` 1 2 3 */
19+
65, 71, 77, 83, 89, 95, 0, 6, 12, 18,
20+
21+
/*20 4 5 6 7 8 9 0 - = BSP */
22+
24, 30, 36, 42, 48, 54, 60, 66, 72, 78,
23+
24+
/*30 INS HME PUP TAB Q W E R T Y */
25+
84, 90, 96, 1, 7, 13, 19, 25, 31, 37,
26+
27+
/*40 U I O P [ ] \ DEL END PDN */
28+
43, 49, 55, 61, 67, 73, 79, 85, 91, 97,
29+
30+
/*50 CAP A S D F G H J K L */
31+
2, 8, 14, 20, 26, 32, 38, 44, 50, 56,
32+
33+
/*60 ; ' ENT LSH Z X C V B N */
34+
62, 68, 80, 3, 15, 21, 27, 33, 39, 45,
35+
36+
/*70 M , . / RSH UP LCTL LWIN LALT SPC */
37+
51, 57, 63, 69, 81, 93, 4, 10, 16, 34,
38+
39+
/*80 RALT RFNC MENU RCTL LFT DWN RGT */
40+
52, 58, 64, 76, 88, 94, 100
41+
42+
/* Missing Indexes 9, 22, 28, 40, 46, 70, 74, 75, 82, 86, 87, 92, 98, 99, 101 */
43+
};
44+
45+
DarkProjectKeyboardController::DarkProjectKeyboardController(hid_device* dev_handle, const char* path)
46+
{
47+
dev = dev_handle;
48+
location = path;
49+
}
50+
51+
DarkProjectKeyboardController::~DarkProjectKeyboardController()
52+
{
53+
hid_close(dev);
54+
}
55+
56+
std::string DarkProjectKeyboardController::GetDeviceName()
57+
{
58+
const int szTemp = HID_MAX_STR;
59+
wchar_t tmpName[szTemp];
60+
61+
hid_get_manufacturer_string(dev, tmpName, szTemp);
62+
std::wstring wName = std::wstring(tmpName);
63+
std::string name = std::string(wName.begin(), wName.end());
64+
65+
return name;
66+
}
67+
68+
std::string DarkProjectKeyboardController::GetSerial()
69+
{
70+
const int szTemp = HID_MAX_STR;
71+
wchar_t tmpName[szTemp];
72+
73+
hid_get_serial_number_string(dev, tmpName, szTemp);
74+
std::wstring wName = std::wstring(tmpName);
75+
std::string serial = std::string(wName.begin(), wName.end());
76+
77+
return serial;
78+
}
79+
80+
std::string DarkProjectKeyboardController::GetLocation()
81+
{
82+
return("HID: " + location);
83+
}
84+
85+
void DarkProjectKeyboardController::SetLedsDirect(std::vector<RGBColor> colors)
86+
{
87+
uint8_t RGbuffer[DARKPROJECTKEYBOARD_PACKET_SIZE] = { 0x08, 0x07, 0x00, 0x00, 0x00 };
88+
uint8_t BAbuffer[DARKPROJECTKEYBOARD_PACKET_SIZE] = { 0x08, 0x07, 0x00, 0x01, 0x00 };
89+
90+
/*-----------------------------------------------------------------*\
91+
| Set up Direct packet |
92+
| packet_map is the index of the Key from full_matrix_map and |
93+
| the value is the position in the direct packet buffer |
94+
\*-----------------------------------------------------------------*/
95+
for(size_t i = 0; i < colors.size(); i++)
96+
{
97+
RGBColor key = colors[i];
98+
uint16_t offset = packet_map[i];
99+
100+
RGbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetRValue(key);
101+
RGbuffer[DARKPROJECTKEYBOARD_GREEN_BYTE + offset] = RGBGetGValue(key);
102+
BAbuffer[DARKPROJECTKEYBOARD_RED_BLUE_BYTE + offset] = RGBGetBValue(key);
103+
}
104+
105+
hid_write(dev, RGbuffer, DARKPROJECTKEYBOARD_PACKET_SIZE);
106+
hid_write(dev, BAbuffer, DARKPROJECTKEYBOARD_PACKET_SIZE);
107+
}
108+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*-------------------------------------------------------------------*\
2+
| DarkProjectKeyboardController.h |
3+
| |
4+
| Driver for DarkProjectKeyboard USB Controller |
5+
| |
6+
| Chris M (DrNo) 8 Apr 2022 |
7+
| |
8+
\*-------------------------------------------------------------------*/
9+
10+
#include <string>
11+
#include <hidapi/hidapi.h>
12+
#include "RGBController.h"
13+
14+
#pragma once
15+
16+
#define NA 0xFFFFFFFF
17+
#define HID_MAX_STR 255
18+
19+
#define DARKPROJECTKEYBOARD_PACKET_SIZE 256
20+
#define DARKPROKECTKEYBOARD_TKL_KEYCOUNT 87
21+
22+
enum
23+
{
24+
DARKPROJECTKEYBOARD_MODE_DIRECT = 0x01, //Direct Led Control - Independently set LEDs in zone
25+
};
26+
27+
enum
28+
{
29+
DARKPROJECTKEYBOARD_REPORT_BYTE = 1,
30+
DARKPROJECTKEYBOARD_COMMAND_BYTE = 2,
31+
DARKPROJECTKEYBOARD_RED_BLUE_BYTE = 5,
32+
DARKPROJECTKEYBOARD_GREEN_BYTE = 107
33+
};
34+
35+
class DarkProjectKeyboardController
36+
{
37+
public:
38+
DarkProjectKeyboardController(hid_device* dev_handle, const char* path);
39+
~DarkProjectKeyboardController();
40+
41+
std::string GetDeviceName();
42+
std::string GetSerial();
43+
std::string GetLocation();
44+
45+
void SetLedsDirect(std::vector<RGBColor> colors);
46+
private:
47+
std::string location;
48+
hid_device* dev;
49+
};

0 commit comments

Comments
 (0)