From 2ce0beec820879edbda1b37c048ef1933319023e Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Sun, 7 Dec 2025 15:32:01 -0600 Subject: [PATCH] Add a configurable settings option to delay detection after opening --- ResourceManager.cpp | 55 ++++++++++++++++++++++++++++++++------------- ResourceManager.h | 5 +++++ 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/ResourceManager.cpp b/ResourceManager.cpp index 871d7dce..5e97dff0 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -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 | diff --git a/ResourceManager.h b/ResourceManager.h index f3e255ad..b4abbed2 100644 --- a/ResourceManager.h +++ b/ResourceManager.h @@ -254,6 +254,11 @@ private: \*-----------------------------------------------------*/ std::atomic init_finished; + /*-----------------------------------------------------*\ + | Initial detection flag | + \*-----------------------------------------------------*/ + bool initial_detection; + /*-----------------------------------------------------*\ | Profile Manager | \*-----------------------------------------------------*/