Skip to content

Commit 6d5ca0b

Browse files
CooperCoronaCalcProgrammer1
authored andcommitted
Track used paths in DetectRazerARGBController to support multiple Razer ARGB controllers at once.
1 parent b877787 commit 6d5ca0b

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

Controllers/RazerController/RazerControllerDetect.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "RGBController_RazerKraken.h"
1111
#include <hidapi/hidapi.h>
1212

13+
#include <unordered_set>
14+
1315
static bool openrazer_checked = false;
1416
static bool openrazer_enabled = false;
1517

@@ -88,6 +90,21 @@ void DetectRazerControllers(hid_device_info* info, const std::string& name)
8890
* *
8991
\******************************************************************************************/
9092

93+
94+
/*---------------------------------------------------------------------*\
95+
| Tracks the paths used in DetectRazerARGBControllers so multiple Razer |
96+
| devices can be detected without all controlling the same device. |
97+
\*---------------------------------------------------------------------*/
98+
static std::unordered_set<std::string> used_paths;
99+
100+
/*--------------------------------------------------------------------------------*\
101+
| Removes all entries in used_paths so device discovery does not skip any of them. |
102+
\*--------------------------------------------------------------------------------*/
103+
void ResetRazerARGBControllersPaths()
104+
{
105+
used_paths.clear();
106+
}
107+
91108
void DetectRazerARGBControllers(hid_device_info* info, const std::string& name)
92109
{
93110
/*-------------------------------------------------------------------------------------------------*\
@@ -102,19 +119,31 @@ void DetectRazerARGBControllers(hid_device_info* info, const std::string& name)
102119
hid_device* dev_interface_1 = nullptr;
103120
hid_device_info* info_full = hid_enumerate(RAZER_VID, RAZER_CHROMA_ADDRESSABLE_RGB_CONTROLLER_PID);
104121
hid_device_info* info_temp = info_full;
122+
/*--------------------------------------------------------------------------------------------*\
123+
| Keep track of paths so they can be added to used_paths only if both interfaces can be found. |
124+
\*--------------------------------------------------------------------------------------------*/
125+
std::string dev_interface_0_path;
126+
std::string dev_interface_1_path;
105127

106128
while(info_temp)
107129
{
108-
if(info_temp->vendor_id == info->vendor_id
109-
&& info_temp->product_id == info->product_id )
130+
/*----------------------------------------------------------------------------*\
131+
| Check for paths used on an already registered Razer ARGB controller to avoid |
132+
| registering multiple controllers that refer to the same physical hardware. |
133+
\*----------------------------------------------------------------------------*/
134+
if(info_temp->vendor_id == info->vendor_id
135+
&& info_temp->product_id == info->product_id
136+
&& used_paths.find(info_temp->path) == used_paths.end() )
110137
{
111138
if(info_temp->interface_number == 0)
112139
{
113-
dev_interface_0 = hid_open_path(info_temp->path);
140+
dev_interface_0 = hid_open_path(info_temp->path);
141+
dev_interface_0_path = info_temp->path;
114142
}
115143
else if(info_temp->interface_number == 1)
116144
{
117145
dev_interface_1 = hid_open_path(info_temp->path);
146+
dev_interface_1_path = info_temp->path;
118147
}
119148
}
120149
if(dev_interface_0 && dev_interface_1)
@@ -131,6 +160,8 @@ void DetectRazerARGBControllers(hid_device_info* info, const std::string& name)
131160
RazerController* controller = new RazerController(dev_interface_0, dev_interface_1, info->path, info->product_id, name);
132161
RGBController_RazerAddressable* rgb_controller = new RGBController_RazerAddressable(controller);
133162
ResourceManager::get()->RegisterRGBController(rgb_controller);
163+
used_paths.insert(dev_interface_0_path);
164+
used_paths.insert(dev_interface_1_path);
134165
}
135166
else
136167
{
@@ -348,6 +379,7 @@ REGISTER_HID_DETECTOR_IPU("Razer Base Station Chroma", Det
348379
REGISTER_HID_DETECTOR_IPU("Razer Base Station V2 Chroma", DetectRazerControllers, RAZER_VID, RAZER_BASE_STATION_V2_CHROMA_PID, 0x00, 0x01, 0x02);
349380
REGISTER_HID_DETECTOR_IPU("Razer Charging Pad Chroma", DetectRazerControllers, RAZER_VID, RAZER_CHARGING_PAD_CHROMA_PID, 0x00, 0x0C, 0x01);
350381
REGISTER_HID_DETECTOR_I ("Razer Chroma Addressable RGB Controller", DetectRazerARGBControllers, RAZER_VID, RAZER_CHROMA_ADDRESSABLE_RGB_CONTROLLER_PID, 0x00 );
382+
REGISTER_DYNAMIC_DETECTOR("Razer Chrome Addressable RGB Controller Setup", ResetRazerARGBControllersPaths );
351383
REGISTER_HID_DETECTOR_IPU("Razer Chroma HDK", DetectRazerControllers, RAZER_VID, RAZER_CHROMA_HDK_PID, 0x02, 0x01, 0x02);
352384
REGISTER_HID_DETECTOR_IPU("Razer Chroma Mug Holder", DetectRazerControllers, RAZER_VID, RAZER_CHROMA_MUG_PID, 0x00, 0x01, 0x02);
353385
REGISTER_HID_DETECTOR_IPU("Razer Chroma PC Case Lighting Kit", DetectRazerControllers, RAZER_VID, RAZER_CHROMA_PC_CASE_LIGHTING_KIT_PID, 0x02, 0x01, 0x02);

0 commit comments

Comments
 (0)