Skip to content

Commit ad6d605

Browse files
Chr1sNoCalcProgrammer1
authored andcommitted
Changing Wooting KB detection to PU
* Simplified detection * Adding more useful data to `info page` * Adding DEBUG logging
1 parent 62906e7 commit ad6d605

File tree

4 files changed

+74
-89
lines changed

4 files changed

+74
-89
lines changed

Controllers/WootingKeyboardController/RGBController_WootingKeyboard.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ RGBController_WootingKeyboard::RGBController_WootingKeyboard(WootingKeyboardCont
149149
{
150150
wooting = wooting_ptr;
151151

152-
name = "Wooting keyboard Device";
152+
name = wooting_ptr->GetName();
153+
vendor = wooting_ptr->GetVendor();
153154
type = DEVICE_TYPE_KEYBOARD;
154-
description = "Wooting Keyboard Device";
155+
description = wooting_ptr->GetDescription();
156+
location = wooting_ptr->GetLocation();
157+
serial = wooting_ptr->GetSerial();
155158

156159
mode Direct;
157160
Direct.name = "Direct";

Controllers/WootingKeyboardController/WootingKeyboardController.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,25 @@ static uint16_t getCrc16ccitt(const uint8_t* buffer, uint16_t size)
5858
return crc;
5959
}
6060

61-
WootingKeyboardController::WootingKeyboardController(hid_device* dev_handle)
61+
WootingKeyboardController::WootingKeyboardController(hid_device* dev_handle, const char *path)
6262
{
63+
const int szTemp = 256;
64+
wchar_t tmpName[szTemp];
65+
6366
dev = dev_handle;
67+
location = path;
68+
69+
hid_get_manufacturer_string(dev, tmpName, szTemp);
70+
std::wstring wName = std::wstring(tmpName);
71+
vendor = std::string(wName.begin(), wName.end());
72+
73+
hid_get_product_string(dev, tmpName, szTemp);
74+
wName = std::wstring(tmpName);
75+
description = std::string(wName.begin(), wName.end());
76+
77+
hid_get_serial_number_string(dev, tmpName, szTemp);
78+
wName = std::wstring(tmpName);
79+
serial = std::string(wName.begin(), wName.end());
6480

6581
SendInitialize();
6682
}
@@ -70,6 +86,31 @@ WootingKeyboardController::~WootingKeyboardController()
7086

7187
}
7288

89+
std::string WootingKeyboardController::GetName()
90+
{
91+
return name;
92+
}
93+
94+
std::string WootingKeyboardController::GetVendor()
95+
{
96+
return vendor;
97+
}
98+
99+
std::string WootingKeyboardController::GetLocation()
100+
{
101+
return("HID: " + location);
102+
}
103+
104+
std::string WootingKeyboardController::GetDescription()
105+
{
106+
return description;
107+
}
108+
109+
std::string WootingKeyboardController::GetSerial()
110+
{
111+
return serial;
112+
}
113+
73114
void WootingKeyboardController::SendDirect(RGBColor* colors, unsigned int num_colors)
74115
{
75116
const uint8_t pwm_mem_map[48] =

Controllers/WootingKeyboardController/WootingKeyboardController.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,22 @@ enum RGB_PARTS
2626
class WootingKeyboardController
2727
{
2828
public:
29-
WootingKeyboardController(hid_device* dev_handle);
29+
WootingKeyboardController(hid_device* dev_handle, const char *path);
3030
~WootingKeyboardController();
3131

32-
void SendDirect(RGBColor* colors, unsigned int num_colors);
33-
32+
void SendDirect(RGBColor* colors, unsigned int num_colors);
33+
std::string GetName();
34+
std::string GetVendor();
35+
std::string GetDescription();
36+
std::string GetLocation();
37+
std::string GetSerial();
3438
private:
3539
hid_device* dev;
40+
std::string name;
41+
std::string vendor;
42+
std::string description;
43+
std::string location;
44+
std::string serial;
3645

3746
void SendInitialize();
3847

Controllers/WootingKeyboardController/WootingKeyboardControllerDetect.cpp

Lines changed: 15 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "WootingKeyboardController.h"
33
#include "RGBController.h"
44
#include "RGBController_WootingKeyboard.h"
5+
#include "LogManager.h"
56
#include <vector>
67
#include <hidapi/hidapi.h>
78

@@ -19,91 +20,22 @@
1920
#define WOOTING_TWO_LE_PID 0x1210
2021
#define WOOTING_TWO_HE_PID 0x1220
2122

22-
typedef struct
23+
void DetectWootingKeyboardControllers(hid_device_info* info, const std::string& name)
2324
{
24-
unsigned short usb_vid;
25-
unsigned short usb_pid;
26-
const char * name;
27-
} wooting_device;
25+
LOG_DEBUG("[Wooting KB] Interface %i\tPage %04X\tUsage %i\tPath %s", info->interface_number, info->usage_page, info->usage, info->path);
2826

29-
#define WOOTING_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[0]))
30-
31-
static const wooting_device device_list[] =
32-
{
33-
/*-----------------------------------------------------------------------*\
34-
| Keyboards |
35-
\*-----------------------------------------------------------------------*/
36-
{ WOOTING_OLD_VID, WOOTING_ONE_PID, "Wooting One" },
37-
{ WOOTING_OLD_VID, WOOTING_TWO_PID, "Wooting Two" },
38-
{ WOOTING_NEW_VID, WOOTING_TWO_LE_PID, "Wooting Two LE" },
39-
{ WOOTING_NEW_VID, WOOTING_TWO_HE_PID, "Wooting Two HE" },
40-
};
41-
42-
/******************************************************************************************\
43-
* *
44-
* DetectWootingKeyboardControllers *
45-
* *
46-
* Tests the USB address to see if a Wooting RGB Keyboard controller exists there. *
47-
* *
48-
\******************************************************************************************/
49-
50-
void DetectWootingKeyboardControllers(std::vector<RGBController*>& rgb_controllers)
51-
{
52-
hid_device_info* info;
53-
hid_device* dev;
54-
55-
hid_init();
56-
57-
for(std::size_t device_idx = 0; device_idx < WOOTING_NUM_DEVICES; device_idx++)
27+
hid_device* dev = hid_open_path(info->path);
28+
29+
if(dev)
5830
{
59-
dev = NULL;
60-
61-
info = hid_enumerate(device_list[device_idx].usb_vid, device_list[device_idx].usb_pid);
62-
63-
/*-------------------------------------------------------------*\
64-
| The amount of interfaces is variable, so we need to look for |
65-
| the configuration interface. In the Wooting one keyboard the |
66-
| configuration interface is always 4 lower than the highest |
67-
| number |
68-
\*-------------------------------------------------------------*/
69-
hid_device_info* hid_info_walker = info;
70-
71-
unsigned char highestInterfaceNr = 0;
72-
while(hid_info_walker)
73-
{
74-
if(hid_info_walker->interface_number > highestInterfaceNr)
75-
{
76-
highestInterfaceNr = hid_info_walker->interface_number;
77-
}
78-
79-
hid_info_walker = hid_info_walker->next;
80-
}
81-
82-
unsigned char interfaceNr = highestInterfaceNr - 4;
83-
84-
/*-------------------------------------------------------------*\
85-
| Look for Wooting keyboard |
86-
\*-------------------------------------------------------------*/
87-
while(info)
88-
{
89-
if(info->interface_number == interfaceNr)
90-
{
91-
dev = hid_open_path(info->path);
92-
93-
if(dev)
94-
{
95-
WootingKeyboardController* controller = new WootingKeyboardController(dev);
96-
97-
RGBController_WootingKeyboard* rgb_controller = new RGBController_WootingKeyboard(controller);
98-
99-
rgb_controller->name = device_list[device_idx].name;
100-
101-
rgb_controllers.push_back(rgb_controller);
102-
}
103-
}
104-
info = info->next;
105-
}
31+
WootingKeyboardController* controller = new WootingKeyboardController(dev, info->path);
32+
RGBController_WootingKeyboard* rgb_controller = new RGBController_WootingKeyboard(controller);
33+
rgb_controller->name = name;
34+
ResourceManager::get()->RegisterRGBController(rgb_controller);
10635
}
107-
} /* DetectWootingKeyboardControllers() */
36+
} /* DetectWootingKeyboardControllers */
10837

109-
REGISTER_DETECTOR("Wooting Keyboard", DetectWootingKeyboardControllers);
38+
REGISTER_HID_DETECTOR_PU("Wooting ONE Keyboard", DetectWootingKeyboardControllers, WOOTING_OLD_VID, WOOTING_ONE_PID, 0x1337, 1);
39+
REGISTER_HID_DETECTOR_PU("Wooting TWO Keyboard", DetectWootingKeyboardControllers, WOOTING_OLD_VID, WOOTING_TWO_PID, 0x1337, 1);
40+
REGISTER_HID_DETECTOR_PU("Wooting TWO Keyboard LE", DetectWootingKeyboardControllers, WOOTING_NEW_VID, WOOTING_TWO_LE_PID, 0x1337, 1);
41+
REGISTER_HID_DETECTOR_PU("Wooting TWO Keyboard HE", DetectWootingKeyboardControllers, WOOTING_NEW_VID, WOOTING_TWO_HE_PID, 0x1337, 1);

0 commit comments

Comments
 (0)