From 6008047656fbfdcf775ca8c1afc7d8e248779099 Mon Sep 17 00:00:00 2001 From: ohadmeir Date: Sun, 5 May 2024 22:14:50 +0300 Subject: [PATCH] Power on UVC sensors after creation to speed initialization --- src/ds/d400/d400-device.cpp | 3 +++ src/ds/d500/d500-device.cpp | 3 +++ src/uvc-sensor.h | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/src/ds/d400/d400-device.cpp b/src/ds/d400/d400-device.cpp index 5a1fb757be..9020e66e20 100644 --- a/src/ds/d400/d400-device.cpp +++ b/src/ds/d400/d400-device.cpp @@ -493,6 +493,9 @@ namespace librealsense auto depth_ep = std::make_shared(this, raw_depth_ep); + // Many commands need power during initialization phase, no point turning it on and off again for each. + raw_depth_ep->power_for_duration( std::chrono::milliseconds( 1000 ) ); + depth_ep->register_info(RS2_CAMERA_INFO_PHYSICAL_PORT, filter_by_mi(all_device_infos, 0).front().device_path); depth_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option); diff --git a/src/ds/d500/d500-device.cpp b/src/ds/d500/d500-device.cpp index c9b57b4091..c8a2e07c58 100644 --- a/src/ds/d500/d500-device.cpp +++ b/src/ds/d500/d500-device.cpp @@ -345,6 +345,9 @@ namespace librealsense auto depth_ep = std::make_shared(this, raw_depth_ep); + // Many commands need power during initialization phase, no point turning it on and off again for each. + raw_depth_ep->power_for_duration( std::chrono::milliseconds( 1000 ) ); + depth_ep->register_info(RS2_CAMERA_INFO_PHYSICAL_PORT, filter_by_mi(all_device_infos, 0).front().device_path); depth_ep->register_option(RS2_OPTION_GLOBAL_TIME_ENABLED, enable_global_time_option); diff --git a/src/uvc-sensor.h b/src/uvc-sensor.h index c044595903..0b21a1d3fc 100644 --- a/src/uvc-sensor.h +++ b/src/uvc-sensor.h @@ -43,6 +43,20 @@ class uvc_sensor : public raw_sensor_base return action( *_device ); } + + void power_for_duration( std::chrono::steady_clock::duration timeout = std::chrono::milliseconds( 500 ) ) + { + acquire_power(); + std::weak_ptr< uvc_sensor > weak = std::dynamic_pointer_cast< uvc_sensor >( shared_from_this() ); + std::thread release_power_thread( [weak, timeout]() + { + std::this_thread::sleep_for( timeout ); + if( auto strong = weak.lock() ) + strong->release_power(); + } ); + release_power_thread.detach(); + } + protected: stream_profiles init_stream_profiles() override; void verify_supported_requests( const stream_profiles & requests ) const;