|
2 | 2 | #include "WootingKeyboardController.h" |
3 | 3 | #include "RGBController.h" |
4 | 4 | #include "RGBController_WootingKeyboard.h" |
| 5 | +#include "LogManager.h" |
5 | 6 | #include <vector> |
6 | 7 | #include <hidapi/hidapi.h> |
7 | 8 |
|
|
19 | 20 | #define WOOTING_TWO_LE_PID 0x1210 |
20 | 21 | #define WOOTING_TWO_HE_PID 0x1220 |
21 | 22 |
|
22 | | -typedef struct |
| 23 | +void DetectWootingKeyboardControllers(hid_device_info* info, const std::string& name) |
23 | 24 | { |
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); |
28 | 26 |
|
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) |
58 | 30 | { |
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); |
106 | 35 | } |
107 | | -} /* DetectWootingKeyboardControllers() */ |
| 36 | +} /* DetectWootingKeyboardControllers */ |
108 | 37 |
|
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