Use wrapped HID detector for Wushi (JSAUX) controller

This commit is contained in:
Adam Honse 2023-06-10 00:40:13 -05:00
parent 0cef992ae6
commit 64c2243391
4 changed files with 14 additions and 32 deletions

View file

@ -6,33 +6,11 @@
#include "WushiL50USBController.h"
WushiL50USBController::WushiL50USBController(hid_device* dev_handle, const char* path)
WushiL50USBController::WushiL50USBController(hidapi_wrapper hid_wrapper, hid_device* dev_handle, const char* path)
{
const uint8_t sz = HID_MAX_STR;
wchar_t tmp[sz];
wchar_t serial_string[128];
dev = dev_handle;
location = path;
hid_get_manufacturer_string(dev, tmp, sz);
std::wstring w_tmp = std::wstring(tmp);
name = std::string(w_tmp.begin(), w_tmp.end());
hid_get_product_string(dev, tmp, sz);
w_tmp = std::wstring(tmp);
name.append(" ").append(std::string(w_tmp.begin(), w_tmp.end()));
int ret = hid_get_serial_number_string(dev, tmp, sz);
if(ret != 0)
{
serial_number = "";
}
else
{
std::wstring return_wstring = tmp;//serial_string;
serial_number = std::string(return_wstring.begin(), return_wstring.end());
}
wrapper = hid_wrapper;
dev = dev_handle;
location = path;
}
WushiL50USBController::~WushiL50USBController()
@ -42,7 +20,7 @@ WushiL50USBController::~WushiL50USBController()
void WushiL50USBController::setMode(WushiL50State * in_mode)
{
hid_send_feature_report(dev, (uint8_t *)in_mode, WUSHI_L50_HID_PACKET_SIZE);
wrapper.hid_send_feature_report(dev, (uint8_t *)in_mode, WUSHI_L50_HID_PACKET_SIZE);
}
std::string WushiL50USBController::getName()

View file

@ -11,6 +11,8 @@
#include <string>
#include <hidapi/hidapi.h>
#include "hidapi_wrapper.h"
#ifndef HID_MAX_STR
#define HID_MAX_STR 255
#endif
@ -103,7 +105,7 @@ public:
class WushiL50USBController
{
public:
WushiL50USBController(hid_device* dev_handle, const char* path);
WushiL50USBController(hidapi_wrapper hid_wrapper, hid_device* dev_handle, const char* path);
~WushiL50USBController();
void setMode(WushiL50State * in_mode);
@ -114,6 +116,7 @@ public:
private:
std::string name;
hidapi_wrapper wrapper;
hid_device * dev;
std::string location;
std::string serial_number;

View file

@ -24,13 +24,13 @@ enum
WUSHI_USAGE = 0x0C
};
void DetectWushiL50USBControllers(hid_device_info* info, const std::string& name)
void DetectWushiL50USBControllers(hidapi_wrapper wrapper, hid_device_info* info, const std::string& name)
{
hid_device* dev = hid_open_path(info->path);
hid_device* dev = wrapper.hid_open_path(info->path);
if(dev)
{
WushiL50USBController* controller = new WushiL50USBController(dev, info->path);
WushiL50USBController* controller = new WushiL50USBController(wrapper, dev, info->path);
RGBController_WushiL50USB* rgb_controller = new RGBController_WushiL50USB(controller);
rgb_controller->name = name;
@ -38,4 +38,4 @@ void DetectWushiL50USBControllers(hid_device_info* info, const std::string& name
}
}
REGISTER_HID_DETECTOR_PU("JSAUX RGB Docking Station", DetectWushiL50USBControllers, WUSHI_VID, WUSHI_PID, WUSHI_PAGE, WUSHI_USAGE);
REGISTER_HID_WRAPPED_DETECTOR_PU("JSAUX RGB Docking Station", DetectWushiL50USBControllers, WUSHI_VID, WUSHI_PID, WUSHI_PAGE, WUSHI_USAGE);

View file

@ -14,6 +14,7 @@
#define REGISTER_HID_DETECTOR_PU(name, func, vid, pid, page, usage) static HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
#define REGISTER_HID_WRAPPED_DETECTOR_I(name, func, vid, pid, interface) static HIDWrappedDeviceDetector device_detector_obj_##vid##pid##_##interface(name, func, vid, pid, interface, HID_USAGE_PAGE_ANY, HID_USAGE_ANY)
#define REGISTER_HID_WRAPPED_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) static HIDWrappedDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, func, vid, pid, interface, page, usage)
#define REGISTER_HID_WRAPPED_DETECTOR_PU(name, func, vid, pid, page, usage) static HIDWrappedDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
#define REGISTER_DYNAMIC_DETECTOR(name, func) static DynamicDetector device_detector_obj_##func(name, func)
#define REGISTER_PRE_DETECTION_HOOK(func) static PreDetectionHook device_detector_obj_##func(func)