mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2026-01-21 21:47:54 -05:00
Move HID detector calls to RunHIDDetector/RunHIDWrappedDetector functions and return controller list from detector functions
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
| SPDX-License-Identifier: GPL-2.0-or-later |
|
||||
\*---------------------------------------------------------*/
|
||||
|
||||
#include "DetectionManager.h"
|
||||
#include "AMBXController.h"
|
||||
#include "DetectionManager.h"
|
||||
#include "RGBController.h"
|
||||
#include "RGBController_AMBX.h"
|
||||
|
||||
@@ -18,66 +18,60 @@
|
||||
#include <libusb.h>
|
||||
#endif
|
||||
|
||||
/******************************************************************************************\
|
||||
* *
|
||||
* DetectAMBXControllers *
|
||||
* *
|
||||
* Detect Philips amBX Gaming devices *
|
||||
* *
|
||||
\******************************************************************************************/
|
||||
|
||||
void DetectAMBXControllers()
|
||||
DetectedControllers DetectAMBXControllers()
|
||||
{
|
||||
libusb_context* ctx = NULL;
|
||||
DetectedControllers detected_controllers;
|
||||
libusb_context* ctx = NULL;
|
||||
|
||||
if(libusb_init(&ctx) < 0)
|
||||
if(libusb_init(&ctx) >= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
libusb_device** devs;
|
||||
ssize_t num_devs = libusb_get_device_list(ctx, &devs);
|
||||
|
||||
libusb_device** devs;
|
||||
ssize_t num_devs = libusb_get_device_list(ctx, &devs);
|
||||
|
||||
if(num_devs <= 0)
|
||||
{
|
||||
libusb_exit(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
for(ssize_t i = 0; i < num_devs; i++)
|
||||
{
|
||||
libusb_device* dev = devs[i];
|
||||
libusb_device_descriptor desc;
|
||||
|
||||
if(libusb_get_device_descriptor(dev, &desc) != 0)
|
||||
if(num_devs > 0)
|
||||
{
|
||||
continue;
|
||||
for(ssize_t i = 0; i < num_devs; i++)
|
||||
{
|
||||
libusb_device* dev = devs[i];
|
||||
libusb_device_descriptor desc;
|
||||
|
||||
if(libusb_get_device_descriptor(dev, &desc) != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(desc.idVendor == AMBX_VID && desc.idProduct == AMBX_PID)
|
||||
{
|
||||
uint8_t bus = libusb_get_bus_number(dev);
|
||||
uint8_t address = libusb_get_device_address(dev);
|
||||
char device_path[32];
|
||||
snprintf(device_path, sizeof(device_path), "%d-%d", bus, address);
|
||||
|
||||
// Use the AMBXController to handle opening and initializing
|
||||
AMBXController* controller = new AMBXController(device_path);
|
||||
|
||||
if(controller->IsInitialized())
|
||||
{
|
||||
RGBController_AMBX* rgb_controller = new RGBController_AMBX(controller);
|
||||
detected_controllers.push_back(rgb_controller);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
libusb_free_device_list(devs, 1);
|
||||
libusb_exit(ctx);
|
||||
}
|
||||
|
||||
if(desc.idVendor == AMBX_VID && desc.idProduct == AMBX_PID)
|
||||
else
|
||||
{
|
||||
uint8_t bus = libusb_get_bus_number(dev);
|
||||
uint8_t address = libusb_get_device_address(dev);
|
||||
char device_path[32];
|
||||
snprintf(device_path, sizeof(device_path), "%d-%d", bus, address);
|
||||
|
||||
// Use the AMBXController to handle opening and initializing
|
||||
AMBXController* controller = new AMBXController(device_path);
|
||||
|
||||
if(controller->IsInitialized())
|
||||
{
|
||||
RGBController_AMBX* rgb_controller = new RGBController_AMBX(controller);
|
||||
DetectionManager::get()->RegisterRGBController(rgb_controller);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete controller;
|
||||
}
|
||||
libusb_exit(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
libusb_free_device_list(devs, 1);
|
||||
libusb_exit(ctx);
|
||||
return(detected_controllers);
|
||||
}
|
||||
|
||||
REGISTER_DETECTOR("Philips amBX", DetectAMBXControllers);
|
||||
|
||||
Reference in New Issue
Block a user