Changing Wooting KB detection to PU
* Simplified detection * Adding more useful data to `info page` * Adding DEBUG logging
This commit is contained in:
parent
62906e7f10
commit
ad6d605c88
4 changed files with 74 additions and 89 deletions
|
|
@ -149,9 +149,12 @@ RGBController_WootingKeyboard::RGBController_WootingKeyboard(WootingKeyboardCont
|
|||
{
|
||||
wooting = wooting_ptr;
|
||||
|
||||
name = "Wooting keyboard Device";
|
||||
name = wooting_ptr->GetName();
|
||||
vendor = wooting_ptr->GetVendor();
|
||||
type = DEVICE_TYPE_KEYBOARD;
|
||||
description = "Wooting Keyboard Device";
|
||||
description = wooting_ptr->GetDescription();
|
||||
location = wooting_ptr->GetLocation();
|
||||
serial = wooting_ptr->GetSerial();
|
||||
|
||||
mode Direct;
|
||||
Direct.name = "Direct";
|
||||
|
|
|
|||
|
|
@ -58,9 +58,25 @@ static uint16_t getCrc16ccitt(const uint8_t* buffer, uint16_t size)
|
|||
return crc;
|
||||
}
|
||||
|
||||
WootingKeyboardController::WootingKeyboardController(hid_device* dev_handle)
|
||||
WootingKeyboardController::WootingKeyboardController(hid_device* dev_handle, const char *path)
|
||||
{
|
||||
const int szTemp = 256;
|
||||
wchar_t tmpName[szTemp];
|
||||
|
||||
dev = dev_handle;
|
||||
location = path;
|
||||
|
||||
hid_get_manufacturer_string(dev, tmpName, szTemp);
|
||||
std::wstring wName = std::wstring(tmpName);
|
||||
vendor = std::string(wName.begin(), wName.end());
|
||||
|
||||
hid_get_product_string(dev, tmpName, szTemp);
|
||||
wName = std::wstring(tmpName);
|
||||
description = std::string(wName.begin(), wName.end());
|
||||
|
||||
hid_get_serial_number_string(dev, tmpName, szTemp);
|
||||
wName = std::wstring(tmpName);
|
||||
serial = std::string(wName.begin(), wName.end());
|
||||
|
||||
SendInitialize();
|
||||
}
|
||||
|
|
@ -70,6 +86,31 @@ WootingKeyboardController::~WootingKeyboardController()
|
|||
|
||||
}
|
||||
|
||||
std::string WootingKeyboardController::GetName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string WootingKeyboardController::GetVendor()
|
||||
{
|
||||
return vendor;
|
||||
}
|
||||
|
||||
std::string WootingKeyboardController::GetLocation()
|
||||
{
|
||||
return("HID: " + location);
|
||||
}
|
||||
|
||||
std::string WootingKeyboardController::GetDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
std::string WootingKeyboardController::GetSerial()
|
||||
{
|
||||
return serial;
|
||||
}
|
||||
|
||||
void WootingKeyboardController::SendDirect(RGBColor* colors, unsigned int num_colors)
|
||||
{
|
||||
const uint8_t pwm_mem_map[48] =
|
||||
|
|
|
|||
|
|
@ -26,13 +26,22 @@ enum RGB_PARTS
|
|||
class WootingKeyboardController
|
||||
{
|
||||
public:
|
||||
WootingKeyboardController(hid_device* dev_handle);
|
||||
WootingKeyboardController(hid_device* dev_handle, const char *path);
|
||||
~WootingKeyboardController();
|
||||
|
||||
void SendDirect(RGBColor* colors, unsigned int num_colors);
|
||||
|
||||
void SendDirect(RGBColor* colors, unsigned int num_colors);
|
||||
std::string GetName();
|
||||
std::string GetVendor();
|
||||
std::string GetDescription();
|
||||
std::string GetLocation();
|
||||
std::string GetSerial();
|
||||
private:
|
||||
hid_device* dev;
|
||||
std::string name;
|
||||
std::string vendor;
|
||||
std::string description;
|
||||
std::string location;
|
||||
std::string serial;
|
||||
|
||||
void SendInitialize();
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "WootingKeyboardController.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_WootingKeyboard.h"
|
||||
#include "LogManager.h"
|
||||
#include <vector>
|
||||
#include <hidapi/hidapi.h>
|
||||
|
||||
|
|
@ -19,91 +20,22 @@
|
|||
#define WOOTING_TWO_LE_PID 0x1210
|
||||
#define WOOTING_TWO_HE_PID 0x1220
|
||||
|
||||
typedef struct
|
||||
void DetectWootingKeyboardControllers(hid_device_info* info, const std::string& name)
|
||||
{
|
||||
unsigned short usb_vid;
|
||||
unsigned short usb_pid;
|
||||
const char * name;
|
||||
} wooting_device;
|
||||
LOG_DEBUG("[Wooting KB] Interface %i\tPage %04X\tUsage %i\tPath %s", info->interface_number, info->usage_page, info->usage, info->path);
|
||||
|
||||
#define WOOTING_NUM_DEVICES (sizeof(device_list) / sizeof(device_list[0]))
|
||||
|
||||
static const wooting_device device_list[] =
|
||||
{
|
||||
/*-----------------------------------------------------------------------*\
|
||||
| Keyboards |
|
||||
\*-----------------------------------------------------------------------*/
|
||||
{ WOOTING_OLD_VID, WOOTING_ONE_PID, "Wooting One" },
|
||||
{ WOOTING_OLD_VID, WOOTING_TWO_PID, "Wooting Two" },
|
||||
{ WOOTING_NEW_VID, WOOTING_TWO_LE_PID, "Wooting Two LE" },
|
||||
{ WOOTING_NEW_VID, WOOTING_TWO_HE_PID, "Wooting Two HE" },
|
||||
};
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectWootingKeyboardControllers *
|
||||
* *
|
||||
* Tests the USB address to see if a Wooting RGB Keyboard controller exists there. *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectWootingKeyboardControllers(std::vector<RGBController*>& rgb_controllers)
|
||||
{
|
||||
hid_device_info* info;
|
||||
hid_device* dev;
|
||||
|
||||
hid_init();
|
||||
|
||||
for(std::size_t device_idx = 0; device_idx < WOOTING_NUM_DEVICES; device_idx++)
|
||||
hid_device* dev = hid_open_path(info->path);
|
||||
|
||||
if(dev)
|
||||
{
|
||||
dev = NULL;
|
||||
|
||||
info = hid_enumerate(device_list[device_idx].usb_vid, device_list[device_idx].usb_pid);
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
| The amount of interfaces is variable, so we need to look for |
|
||||
| the configuration interface. In the Wooting one keyboard the |
|
||||
| configuration interface is always 4 lower than the highest |
|
||||
| number |
|
||||
\*-------------------------------------------------------------*/
|
||||
hid_device_info* hid_info_walker = info;
|
||||
|
||||
unsigned char highestInterfaceNr = 0;
|
||||
while(hid_info_walker)
|
||||
{
|
||||
if(hid_info_walker->interface_number > highestInterfaceNr)
|
||||
{
|
||||
highestInterfaceNr = hid_info_walker->interface_number;
|
||||
}
|
||||
|
||||
hid_info_walker = hid_info_walker->next;
|
||||
}
|
||||
|
||||
unsigned char interfaceNr = highestInterfaceNr - 4;
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
| Look for Wooting keyboard |
|
||||
\*-------------------------------------------------------------*/
|
||||
while(info)
|
||||
{
|
||||
if(info->interface_number == interfaceNr)
|
||||
{
|
||||
dev = hid_open_path(info->path);
|
||||
|
||||
if(dev)
|
||||
{
|
||||
WootingKeyboardController* controller = new WootingKeyboardController(dev);
|
||||
|
||||
RGBController_WootingKeyboard* rgb_controller = new RGBController_WootingKeyboard(controller);
|
||||
|
||||
rgb_controller->name = device_list[device_idx].name;
|
||||
|
||||
rgb_controllers.push_back(rgb_controller);
|
||||
}
|
||||
}
|
||||
info = info->next;
|
||||
}
|
||||
WootingKeyboardController* controller = new WootingKeyboardController(dev, info->path);
|
||||
RGBController_WootingKeyboard* rgb_controller = new RGBController_WootingKeyboard(controller);
|
||||
rgb_controller->name = name;
|
||||
ResourceManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
} /* DetectWootingKeyboardControllers() */
|
||||
} /* DetectWootingKeyboardControllers */
|
||||
|
||||
REGISTER_DETECTOR("Wooting Keyboard", DetectWootingKeyboardControllers);
|
||||
REGISTER_HID_DETECTOR_PU("Wooting ONE Keyboard", DetectWootingKeyboardControllers, WOOTING_OLD_VID, WOOTING_ONE_PID, 0x1337, 1);
|
||||
REGISTER_HID_DETECTOR_PU("Wooting TWO Keyboard", DetectWootingKeyboardControllers, WOOTING_OLD_VID, WOOTING_TWO_PID, 0x1337, 1);
|
||||
REGISTER_HID_DETECTOR_PU("Wooting TWO Keyboard LE", DetectWootingKeyboardControllers, WOOTING_NEW_VID, WOOTING_TWO_LE_PID, 0x1337, 1);
|
||||
REGISTER_HID_DETECTOR_PU("Wooting TWO Keyboard HE", DetectWootingKeyboardControllers, WOOTING_NEW_VID, WOOTING_TWO_HE_PID, 0x1337, 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue