Add a configurable settings option to delay detection after opening

This commit is contained in:
Adam Honse
2025-12-07 15:32:01 -06:00
parent 74922bdf60
commit 2ce0beec82
2 changed files with 45 additions and 15 deletions

View File

@@ -124,6 +124,7 @@ ResourceManager::ResourceManager()
detection_is_required = false;
dynamic_detectors_processed = false;
init_finished = false;
initial_detection = true;
background_thread_running = true;
/*-----------------------------------------------------*\
@@ -1056,27 +1057,18 @@ void ResourceManager::DetectDevicesCoroutine()
DetectDeviceMutex.lock();
hid_device_info* current_hid_device;
float percent = 0.0f;
float percent_denominator = 0.0f;
float percent = 0.0f;
float percent_denominator = 0.0f;
json detector_settings;
unsigned int hid_device_count = 0;
hid_device_info* hid_devices = NULL;
bool hid_safe_mode = false;
unsigned int hid_device_count = 0;
hid_device_info* hid_devices = NULL;
bool hid_safe_mode = false;
unsigned int initial_detection_delay_ms = 0;
LOG_INFO("------------------------------------------------------");
LOG_INFO("| Start device detection |");
LOG_INFO("------------------------------------------------------");
/*-----------------------------------------------------*\
| Reset the size entry used flags vector |
\*-----------------------------------------------------*/
detection_size_entry_used.resize(rgb_controllers_sizes.size());
for(std::size_t size_idx = 0; size_idx < (unsigned int)detection_size_entry_used.size(); size_idx++)
{
detection_size_entry_used[size_idx] = false;
}
/*-----------------------------------------------------*\
| Open device disable list and read in disabled |
| device strings |
@@ -1091,6 +1083,39 @@ void ResourceManager::DetectDevicesCoroutine()
hid_safe_mode = detector_settings["hid_safe_mode"];
}
/*-----------------------------------------------------*\
| Check initial detection delay setting |
\*-----------------------------------------------------*/
if(detector_settings.contains("initial_detection_delay_ms"))
{
initial_detection_delay_ms = detector_settings["initial_detection_delay_ms"];
}
/*-----------------------------------------------------*\
| If configured, delay detection for the configured |
| time only on first detection |
\*-----------------------------------------------------*/
if(initial_detection)
{
if(initial_detection_delay_ms != 0)
{
LOG_INFO("[ResourceManager] Delaying detection for %d ms", initial_detection_delay_ms);
std::this_thread::sleep_for(initial_detection_delay_ms * 1ms);
}
initial_detection = false;
}
/*-----------------------------------------------------*\
| Reset the size entry used flags vector |
\*-----------------------------------------------------*/
detection_size_entry_used.resize(rgb_controllers_sizes.size());
for(std::size_t size_idx = 0; size_idx < (unsigned int)detection_size_entry_used.size(); size_idx++)
{
detection_size_entry_used[size_idx] = false;
}
/*-----------------------------------------------------*\
| Calculate the percentage denominator by adding the |
| number of I2C and miscellaneous detectors and the |

View File

@@ -254,6 +254,11 @@ private:
\*-----------------------------------------------------*/
std::atomic<bool> init_finished;
/*-----------------------------------------------------*\
| Initial detection flag |
\*-----------------------------------------------------*/
bool initial_detection;
/*-----------------------------------------------------*\
| Profile Manager |
\*-----------------------------------------------------*/