Store name in WushiController to avoid setting it in detector

This commit is contained in:
Adam Honse 2025-08-14 22:59:05 -05:00
parent d069947252
commit 84c24e70c0
3 changed files with 30 additions and 30 deletions

View file

@ -11,11 +11,12 @@
#include "StringUtils.h" #include "StringUtils.h"
#include "WushiL50USBController.h" #include "WushiL50USBController.h"
WushiL50USBController::WushiL50USBController(hidapi_wrapper hid_wrapper, hid_device* dev_handle, const char* path) WushiL50USBController::WushiL50USBController(hidapi_wrapper hid_wrapper, hid_device* dev_handle, const char* path, std::string dev_name)
{ {
wrapper = hid_wrapper; wrapper = hid_wrapper;
dev = dev_handle; dev = dev_handle;
location = path; location = path;
name = dev_name;
} }
WushiL50USBController::~WushiL50USBController() WushiL50USBController::~WushiL50USBController()
@ -23,6 +24,29 @@ WushiL50USBController::~WushiL50USBController()
wrapper.hid_close(dev); wrapper.hid_close(dev);
} }
std::string WushiL50USBController::getName()
{
return name;
}
std::string WushiL50USBController::getLocation()
{
return location;
}
std::string WushiL50USBController::GetSerialString()
{
wchar_t serial_string[128];
int ret = wrapper.hid_get_serial_number_string(dev, serial_string, 128);
if(ret != 0)
{
return("");
}
return(StringUtils::wstring_to_string(serial_string));
}
void WushiL50USBController::setMode(WushiL50State * in_mode) void WushiL50USBController::setMode(WushiL50State * in_mode)
{ {
unsigned char usb_buf[WUSHI_L50_HID_PACKET_SIZE]; unsigned char usb_buf[WUSHI_L50_HID_PACKET_SIZE];
@ -62,26 +86,3 @@ void WushiL50USBController::setMode(WushiL50State * in_mode)
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
wrapper.hid_send_feature_report(dev, usb_buf, WUSHI_L50_HID_PACKET_SIZE); wrapper.hid_send_feature_report(dev, usb_buf, WUSHI_L50_HID_PACKET_SIZE);
} }
std::string WushiL50USBController::getName()
{
return name;
}
std::string WushiL50USBController::getLocation()
{
return location;
}
std::string WushiL50USBController::GetSerialString()
{
wchar_t serial_string[128];
int ret = wrapper.hid_get_serial_number_string(dev, serial_string, 128);
if(ret != 0)
{
return("");
}
return(StringUtils::wstring_to_string(serial_string));
}

View file

@ -95,18 +95,18 @@ public:
class WushiL50USBController class WushiL50USBController
{ {
public: public:
WushiL50USBController(hidapi_wrapper hid_wrapper, hid_device* dev_handle, const char* path); WushiL50USBController(hidapi_wrapper hid_wrapper, hid_device* dev_handle, const char* path, std::string dev_name);
~WushiL50USBController(); ~WushiL50USBController();
void setMode(WushiL50State * in_mode);
std::string getName(); std::string getName();
std::string getLocation(); std::string getLocation();
std::string GetSerialString(); std::string GetSerialString();
void setMode(WushiL50State * in_mode);
private: private:
std::string name;
hidapi_wrapper wrapper; hidapi_wrapper wrapper;
hid_device * dev; hid_device * dev;
std::string location; std::string location;
std::string name;
}; };

View file

@ -28,9 +28,8 @@ void DetectWushiL50USBControllers(hidapi_wrapper wrapper, hid_device_info* info,
if(dev) if(dev)
{ {
WushiL50USBController* controller = new WushiL50USBController(wrapper, dev, info->path); WushiL50USBController* controller = new WushiL50USBController(wrapper, dev, info->path, name);
RGBController_WushiL50USB* rgb_controller = new RGBController_WushiL50USB(controller); RGBController_WushiL50USB* rgb_controller = new RGBController_WushiL50USB(controller);
rgb_controller->name = name;
ResourceManager::get()->RegisterRGBController(rgb_controller); ResourceManager::get()->RegisterRGBController(rgb_controller);
} }