Move HID detector calls to RunHIDDetector/RunHIDWrappedDetector functions and return controller list from detector functions

This commit is contained in:
Adam Honse
2026-01-12 19:05:21 -06:00
parent c46540339a
commit 8f29ad126e
191 changed files with 4362 additions and 4242 deletions

View File

@@ -16,36 +16,29 @@
#include "RGBController_E131.h"
#include "SettingsManager.h"
/******************************************************************************************\
* *
* DetectE131Controllers *
* *
* Detect devices supported by the E131 driver *
* *
\******************************************************************************************/
void DetectE131Controllers()
DetectedControllers DetectE131Controllers()
{
DetectedControllers detected_controllers;
json e131_settings;
std::vector<std::vector<E131Device>> device_lists;
E131Device dev;
/*-------------------------------------------------*\
| Get E1.31 settings from settings manager |
\*-------------------------------------------------*/
/*-----------------------------------------------------*\
| Get E1.31 settings from settings manager |
\*-----------------------------------------------------*/
e131_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("E131Devices");
/*-------------------------------------------------*\
| If the E1.31 settings contains devices, process |
\*-------------------------------------------------*/
/*-----------------------------------------------------*\
| If the E1.31 settings contains devices, process |
\*-----------------------------------------------------*/
if(e131_settings.contains("devices"))
{
for(unsigned int device_idx = 0; device_idx < e131_settings["devices"].size(); device_idx++)
{
/*-------------------------------------------------*\
| Clear E1.31 device data |
\*-------------------------------------------------*/
/*---------------------------------------------*\
| Clear E1.31 device data |
\*---------------------------------------------*/
dev.name = "";
dev.ip = "";
dev.type = ZONE_TYPE_SINGLE;
@@ -211,28 +204,32 @@ void DetectE131Controllers()
}
}
/*---------------------------------------------------------*\
| Determine whether to create a new list or add this device |
| to an existing list. A device is added to an existing |
| list if both devices share one or more universes for the |
| same output destination |
\*---------------------------------------------------------*/
/*---------------------------------------------*\
| Determine whether to create a new list or add |
| this device to an existing list. A device is |
| added to an existing list if both devices |
| share one or more universes for the same |
|output destination |
\*---------------------------------------------*/
bool device_added_to_existing_list = false;
/*---------------------------------------------------------*\
| Track grouping for all controllers. |
\*---------------------------------------------------------*/
/*---------------------------------------------*\
| Track grouping for all controllers. |
\*---------------------------------------------*/
for(unsigned int list_idx = 0; list_idx < device_lists.size(); list_idx++)
{
for(unsigned int device_idx = 0; device_idx < device_lists[list_idx].size(); device_idx++)
{
/*---------------------------------------------------------*\
| Determine if there is any overlap between this device and |
| any existing device list |
| Offset the end by two - one because the range is 1-512 |
| rather than 0-511, and one because the start channel is |
| included in the first set of 3 channels. |
\*---------------------------------------------------------*/
/*-------------------------------------*\
| Determine if there is any overlap |
| between this device and any existing |
| device list |
| Offset the end by two - one because |
| the range is 1-512 rather than 0-511, |
| and one because the start channel is |
| included in the first set of 3 |
| channels. |
\*-------------------------------------*/
unsigned int dev_start = dev.start_universe;
unsigned int list_start = device_lists[list_idx][device_idx].start_universe;
unsigned int dev_end = dev.start_universe + ((dev.start_channel + (3 * dev.num_leds) - 2) / 512);
@@ -242,11 +239,12 @@ void DetectE131Controllers()
bool overlap = dev_ip == list_ip && !(dev_end < list_start || list_end < dev_start);
/*---------------------------------------------------------*\
| Check if any universes used by this new device exist in |
| the existing device. If so, add the new device to the |
| existing list. |
\*---------------------------------------------------------*/
/*-------------------------------------*\
| Check if any universes used by this |
| new device exist in the existing |
| device. If so, add the new device to |
| the existing list. |
\*-------------------------------------*/
if(overlap)
{
device_lists[list_idx].push_back(dev);
@@ -261,10 +259,10 @@ void DetectE131Controllers()
}
}
/*---------------------------------------------------------*\
| If the device did not overlap with existing devices, |
| create a new list for it |
\*---------------------------------------------------------*/
/*---------------------------------------------*\
| If the device did not overlap with existing |
| devices, create a new list for it |
\*---------------------------------------------*/
if(!device_added_to_existing_list)
{
std::vector<E131Device> new_list;
@@ -279,10 +277,12 @@ void DetectE131Controllers()
{
RGBController_E131* rgb_controller;
rgb_controller = new RGBController_E131(device_lists[list_idx]);
DetectionManager::get()->RegisterRGBController(rgb_controller);
detected_controllers.push_back(rgb_controller);
}
}
} /* DetectE131Controllers() */
return(detected_controllers);
}
REGISTER_DETECTOR("E1.31", DetectE131Controllers);