Skip to content

Commit

Permalink
PR #12897 from OhadMeir: Power on UVC sensors after creation to speed…
Browse files Browse the repository at this point in the history
… initialization
  • Loading branch information
Nir-Az committed May 9, 2024
2 parents 88285da + 6008047 commit cac91e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ds/d400/d400-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@ namespace librealsense

auto depth_ep = std::make_shared<d400_depth_sensor>(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);
Expand Down
3 changes: 3 additions & 0 deletions src/ds/d500/d500-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ namespace librealsense

auto depth_ep = std::make_shared<d500_depth_sensor>(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);
Expand Down
14 changes: 14 additions & 0 deletions src/uvc-sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cac91e2

Please sign in to comment.