mirror of
https://github.com/CalcProgrammer1/OpenRGB.git
synced 2025-12-23 23:37:48 -05:00
Add pre detection hooks to resource manager. Closes #2184
This commit is contained in:
@@ -385,7 +385,6 @@ REGISTER_HID_DETECTOR_IPU("Razer Base Station Chroma", Det
|
||||
REGISTER_HID_DETECTOR_IPU("Razer Base Station V2 Chroma", DetectRazerControllers, RAZER_VID, RAZER_BASE_STATION_V2_CHROMA_PID, 0x00, 0x01, 0x02);
|
||||
REGISTER_HID_DETECTOR_IPU("Razer Charging Pad Chroma", DetectRazerControllers, RAZER_VID, RAZER_CHARGING_PAD_CHROMA_PID, 0x00, 0x0C, 0x01);
|
||||
REGISTER_HID_DETECTOR_I ("Razer Chroma Addressable RGB Controller", DetectRazerARGBControllers, RAZER_VID, RAZER_CHROMA_ADDRESSABLE_RGB_CONTROLLER_PID, 0x00 );
|
||||
REGISTER_DYNAMIC_DETECTOR("Razer Chrome Addressable RGB Controller Setup", ResetRazerARGBControllersPaths );
|
||||
REGISTER_HID_DETECTOR_IPU("Razer Chroma HDK", DetectRazerControllers, RAZER_VID, RAZER_CHROMA_HDK_PID, 0x02, 0x01, 0x02);
|
||||
REGISTER_HID_DETECTOR_IPU("Razer Chroma Mug Holder", DetectRazerControllers, RAZER_VID, RAZER_CHROMA_MUG_PID, 0x00, 0x01, 0x02);
|
||||
REGISTER_HID_DETECTOR_IPU("Razer Chroma PC Case Lighting Kit", DetectRazerControllers, RAZER_VID, RAZER_CHROMA_PC_CASE_LIGHTING_KIT_PID, 0x02, 0x01, 0x02);
|
||||
@@ -409,3 +408,7 @@ REGISTER_HID_DETECTOR_IPU("Razer Nommo Chroma", Det
|
||||
REGISTER_HID_DETECTOR_IPU("Razer Nommo Pro", DetectRazerControllers, RAZER_VID, RAZER_NOMMO_PRO_PID, 0x00, 0x01, 0x00);
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------------------------------------------------*\
|
||||
| Need to clean up some stuff before we scan/rescan |
|
||||
\*-----------------------------------------------------------------------------------------------------*/
|
||||
REGISTER_PRE_DETECTION_HOOK(ResetRazerARGBControllersPaths);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#define REGISTER_HID_DETECTOR_P(name, func, vid, pid, page) static HIDDeviceDetector device_detector_obj_##vid##pid##__##page(name, func, vid, pid, HID_INTERFACE_ANY, page, HID_USAGE_ANY)
|
||||
#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_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)
|
||||
|
||||
#define REGISTER_DYNAMIC_I2C_DETECTOR(name, func) I2CDeviceDetector device_detector_obj_##func(name, func)
|
||||
#define REGISTER_DYNAMIC_I2C_BUS_DETECTOR(func) I2CBusDetector device_detector_obj_##func(func)
|
||||
@@ -20,4 +21,4 @@
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_IP(name, func, vid, pid, interface, page) HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page(name, func, vid, pid, interface, page, HID_USAGE_ANY)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_IPU(name, func, vid, pid, interface, page, usage) HIDDeviceDetector device_detector_obj_##vid##pid##_##interface##_##page##_##usage(name, func, vid, pid, interface, page, usage)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_P(name, func, vid, pid, page) HIDDeviceDetector device_detector_obj_##vid##pid##__##page(name, func, vid, pid, HID_INTERFACE_ANY, page, HID_USAGE_ANY)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_PU(name, func, vid, pid, page, usage) HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
|
||||
#define REGISTER_DYNAMIC_HID_DETECTOR_PU(name, func, vid, pid, page, usage) HIDDeviceDetector device_detector_obj_##vid##pid##__##page##_##usage(name, func, vid, pid, HID_INTERFACE_ANY, page, usage)
|
||||
|
||||
@@ -49,4 +49,13 @@ public:
|
||||
{
|
||||
ResourceManager::get()->RegisterDynamicDetector(name, detector);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
class PreDetectionHook
|
||||
{
|
||||
public:
|
||||
PreDetectionHook(PreDetectionHookFunction hook)
|
||||
{
|
||||
ResourceManager::get()->RegisterPreDetectionHook(hook);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -228,6 +228,11 @@ void ResourceManager::RegisterDynamicDetector(std::string name, DynamicDetectorF
|
||||
dynamic_detectors.push_back(detector);
|
||||
}
|
||||
|
||||
void ResourceManager::RegisterPreDetectionHook(PreDetectionHookFunction hook)
|
||||
{
|
||||
pre_detection_hooks.push_back(hook);
|
||||
}
|
||||
|
||||
void ResourceManager::RegisterDeviceListChangeCallback(DeviceListChangeCallback new_callback, void * new_callback_arg)
|
||||
{
|
||||
DeviceListChangeCallbacks.push_back(new_callback);
|
||||
@@ -618,6 +623,14 @@ void ResourceManager::Cleanup()
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceManager::ProcessPreDetectionHooks()
|
||||
{
|
||||
for(unsigned int hook_idx = 0; hook_idx < pre_detection_hooks.size(); hook_idx++)
|
||||
{
|
||||
pre_detection_hooks[hook_idx]();
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceManager::ProcessDynamicDetectors()
|
||||
{
|
||||
for(unsigned int detector_idx = 0; detector_idx < dynamic_detectors.size(); detector_idx++)
|
||||
@@ -630,6 +643,11 @@ void ResourceManager::ProcessDynamicDetectors()
|
||||
|
||||
void ResourceManager::DetectDevices()
|
||||
{
|
||||
/*-----------------------------------------------------*\
|
||||
| Process pre-detection hooks |
|
||||
\*-----------------------------------------------------*/
|
||||
ProcessPreDetectionHooks();
|
||||
|
||||
/*-----------------------------------------------------*\
|
||||
| Process Dynamic Detectors |
|
||||
\*-----------------------------------------------------*/
|
||||
|
||||
@@ -37,6 +37,8 @@ typedef std::function<void(std::vector<RGBController*>&)> DeviceDetect
|
||||
typedef std::function<void(std::vector<i2c_smbus_interface*>&)> I2CDeviceDetectorFunction;
|
||||
typedef std::function<void(hid_device_info*, const std::string&)> HIDDeviceDetectorFunction;
|
||||
typedef std::function<void()> DynamicDetectorFunction;
|
||||
typedef std::function<void()> PreDetectionHookFunction;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::string name;
|
||||
@@ -119,6 +121,7 @@ public:
|
||||
int usage_page = HID_USAGE_PAGE_ANY,
|
||||
int usage = HID_USAGE_ANY);
|
||||
void RegisterDynamicDetector (std::string name, DynamicDetectorFunction detector);
|
||||
void RegisterPreDetectionHook (PreDetectionHookFunction hook);
|
||||
|
||||
void RegisterDeviceListChangeCallback(DeviceListChangeCallback new_callback, void * new_callback_arg);
|
||||
void RegisterDetectionProgressCallback(DetectionProgressCallback new_callback, void * new_callback_arg);
|
||||
@@ -149,6 +152,7 @@ public:
|
||||
|
||||
void SetConfigurationDirectory(std::string directory);
|
||||
|
||||
void ProcessPreDetectionHooks();
|
||||
void ProcessDynamicDetectors();
|
||||
void UpdateDeviceList();
|
||||
void DeviceListChanged();
|
||||
@@ -224,6 +228,7 @@ private:
|
||||
std::vector<std::string> hid_device_detector_strings;
|
||||
std::vector<DynamicDetectorFunction> dynamic_detectors;
|
||||
std::vector<std::string> dynamic_detector_strings;
|
||||
std::vector<PreDetectionHookFunction> pre_detection_hooks;
|
||||
|
||||
bool dynamic_detectors_processed;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user