Get vendor and device names from HID descriptors

This commit is contained in:
Adam Honse
2026-01-31 23:37:35 -06:00
parent 7a8941f3cb
commit 6c4e2bf251
4 changed files with 31 additions and 11 deletions

View File

@@ -15,11 +15,10 @@
#include "HIDLampArrayController.h"
#include "StringUtils.h"
HIDLampArrayController::HIDLampArrayController(hid_device *dev_handle, const char *path, std::string dev_name)
HIDLampArrayController::HIDLampArrayController(hid_device *dev_handle, const char *path)
{
dev = dev_handle;
location = path;
name = dev_name;
/*-----------------------------------------------------*\
| Parse report IDs from descriptor |
@@ -128,10 +127,18 @@ std::string HIDLampArrayController::GetDeviceLocation()
std::string HIDLampArrayController::GetDeviceName()
{
return(name);
wchar_t name_string[128];
int ret = hid_get_product_string(dev, name_string, 128);
if(ret != 0)
{
return("");
}
return(StringUtils::wstring_to_string(name_string));
}
std::string HIDLampArrayController::GetSerialString()
std::string HIDLampArrayController::GetDeviceSerial()
{
wchar_t serial_string[128];
int ret = hid_get_serial_number_string(dev, serial_string, 128);
@@ -144,6 +151,19 @@ std::string HIDLampArrayController::GetSerialString()
return(StringUtils::wstring_to_string(serial_string));
}
std::string HIDLampArrayController::GetDeviceVendor()
{
wchar_t vendor_string[128];
int ret = hid_get_manufacturer_string(dev, vendor_string, 128);
if(ret != 0)
{
return("");
}
return(StringUtils::wstring_to_string(vendor_string));
}
unsigned int HIDLampArrayController::GetLampArrayKind()
{
return(LampArray.LampArrayKind);

View File

@@ -109,12 +109,13 @@ enum
class HIDLampArrayController
{
public:
HIDLampArrayController(hid_device *dev_handle, const char *path, std::string dev_name);
HIDLampArrayController(hid_device *dev_handle, const char *path);
~HIDLampArrayController();
std::string GetDeviceLocation();
std::string GetDeviceName();
std::string GetSerialString();
std::string GetDeviceSerial();
std::string GetDeviceVendor();
unsigned int GetLampArrayKind();
unsigned int GetLampCount();
@@ -126,7 +127,6 @@ private:
hid_device * dev;
HIDLampArrayReportIDs ids;
std::string location;
std::string name;
/*-----------------------------------------------------*\
| Vector to store lamp attributes for each lamp |

View File

@@ -16,7 +16,7 @@
#include <vector>
#include <hidapi.h>
DetectedControllers DetectHIDLampArrayControllers(hid_device_info* info, const std::string& name)
DetectedControllers DetectHIDLampArrayControllers(hid_device_info* info, const std::string& /*name*/)
{
DetectedControllers detected_controllers;
hid_device* dev;
@@ -25,7 +25,7 @@ DetectedControllers DetectHIDLampArrayControllers(hid_device_info* info, const s
if(dev)
{
HIDLampArrayController* controller = new HIDLampArrayController(dev, info->path, name);
HIDLampArrayController* controller = new HIDLampArrayController(dev, info->path);
RGBController_HIDLampArray* rgb_controller = new RGBController_HIDLampArray(controller);
detected_controllers.push_back(rgb_controller);

View File

@@ -26,10 +26,10 @@ RGBController_HIDLampArray::RGBController_HIDLampArray(HIDLampArrayController* c
controller = controller_ptr;
name = controller->GetDeviceName();
vendor = "Generic";
description = "HID LampArray Device";
location = controller->GetDeviceLocation();
serial = controller->GetSerialString();
serial = controller->GetDeviceSerial();
vendor = controller->GetDeviceVendor();
/*-----------------------------------------------------*\
| Determine device type from LampArray kind |