diff --git a/src/ds/d500/d500-device.cpp b/src/ds/d500/d500-device.cpp index 1a69a91a42..c9b57b4091 100644 --- a/src/ds/d500/d500-device.cpp +++ b/src/ds/d500/d500-device.cpp @@ -527,17 +527,20 @@ namespace librealsense rsutils::lazy< float >( [default_depth_units]() { return default_depth_units; } ) ) ); } - depth_sensor.register_option(RS2_OPTION_SOC_PVT_TEMPERATURE, - std::make_shared(_hw_monitor, - temperature_option::temperature_component::HKR_PVT, "Temperature reading for SOC PVT")); + // defining the temperature options + auto pvt_temperature = std::make_shared< temperature_xu_option >(raw_depth_sensor, + depth_xu, + DS5_HKR_PVT_TEMPERATURE, + "PVT Temperature"); - depth_sensor.register_option(RS2_OPTION_OHM_TEMPERATURE, - std::make_shared(_hw_monitor, - temperature_option::temperature_component::LEFT_IR, "Temperature reading for Left Infrared Sensor")); + auto ohm_temperature = std::make_shared< temperature_xu_option >(raw_depth_sensor, + depth_xu, + DS5_HKR_OHM_TEMPERATURE, + "OHM Temperature"); - depth_sensor.register_option(RS2_OPTION_PROJECTOR_TEMPERATURE, - std::make_shared(_hw_monitor, - temperature_option::temperature_component::LEFT_PROJ, "Temperature reading for Left Projector")); + // registering the temperature options + depth_sensor.register_option(RS2_OPTION_SOC_PVT_TEMPERATURE, pvt_temperature); + depth_sensor.register_option(RS2_OPTION_OHM_TEMPERATURE, ohm_temperature); auto error_control = std::make_shared< uvc_xu_option< uint8_t > >( raw_depth_sensor, depth_xu, diff --git a/src/ds/d500/d500-options.cpp b/src/ds/d500/d500-options.cpp index c4765c8a38..aca1c50a62 100644 --- a/src/ds/d500/d500-options.cpp +++ b/src/ds/d500/d500-options.cpp @@ -50,6 +50,24 @@ namespace librealsense return temperature; } + temperature_xu_option::temperature_xu_option(const std::weak_ptr& ep, + platform::extension_unit xu, uint8_t id, + std::string description) + : uvc_xu_option(ep, xu, id, description, false, + // defining the parsing modifier, to be used on the calls for query and get_range methods + [](const int16_t read_value) { + return static_cast(read_value) / 10.f; + }) {} + + float temperature_xu_option::query() const + { + return uvc_xu_option::query(); + } + + void temperature_xu_option::set(float value) + { + readonly_option::set(value); + } power_line_freq_option::power_line_freq_option(const std::weak_ptr< uvc_sensor >& ep, rs2_option id, const std::map< float, std::string >& description_per_value) : diff --git a/src/ds/d500/d500-options.h b/src/ds/d500/d500-options.h index 4196974412..68a2d46411 100644 --- a/src/ds/d500/d500-options.h +++ b/src/ds/d500/d500-options.h @@ -3,10 +3,10 @@ #pragma once +#include #include "ds/ds-private.h" #include "core/options-container.h" #include "option.h" -#include "platform/uvc-option.h" #include @@ -76,6 +76,23 @@ namespace librealsense const char* _description; }; + class temperature_xu_option : public uvc_xu_option, + public readonly_option + { + public: + + explicit temperature_xu_option(const std::weak_ptr< uvc_sensor >& ep, + platform::extension_unit xu, + uint8_t id, + std::string description); + + virtual float query() const override; + virtual void set(float value) override; + inline bool is_enabled() const override { return true; } + virtual void enable_recording(std::function record_action) override + { uvc_xu_option::enable_recording(record_action); } + }; + class power_line_freq_option : public uvc_pu_option { public: diff --git a/src/ds/d500/d500-private.h b/src/ds/d500/d500-private.h index 59e6ed24a4..d38a8e784b 100644 --- a/src/ds/d500/d500-private.h +++ b/src/ds/d500/d500-private.h @@ -17,9 +17,10 @@ namespace librealsense const uint16_t D555E_PID = 0x0B56; const uint16_t D555E_RECOVERY_PID = 0x0ADE; - namespace xu_id - { - } + // DS500 depth XU identifiers + const uint8_t DS5_HKR_PVT_TEMPERATURE = 0x15; + const uint8_t DS5_HKR_PROJECTOR_TEMPERATURE = 0x16; + const uint8_t DS5_HKR_OHM_TEMPERATURE = 0x17; // d500 Devices supported by the current version static const std::set rs500_sku_pid = { diff --git a/src/option.h b/src/option.h index ec782704f7..dda3e78e2b 100644 --- a/src/option.h +++ b/src/option.h @@ -37,7 +37,7 @@ namespace librealsense std::vector> _callbacks; }; - class readonly_option : public option + class readonly_option : virtual public option { public: bool is_read_only() const override { return true; } diff --git a/src/platform/uvc-option.h b/src/platform/uvc-option.h index 67075c0ac0..d279bba2fb 100644 --- a/src/platform/uvc-option.h +++ b/src/platform/uvc-option.h @@ -49,7 +49,7 @@ class uvc_pu_option : public option // XU control with exclusing access to setter/getters template< typename T > -class uvc_xu_option : public option +class uvc_xu_option : virtual public option { public: void set( float value ) override @@ -87,6 +87,8 @@ class uvc_xu_option : public option throw invalid_value_exception( rsutils::string::from() << "get_xu(id=" << std::to_string( _id ) << ") failed!" << " Last Error: " << strerror( errno ) ); + if (_parsing_modifier) + return _parsing_modifier(t); return static_cast< float >( t ); } ) ); @@ -101,13 +103,21 @@ class uvc_xu_option : public option uvc_range = ep->invoke_powered( [this]( platform::uvc_device & dev ) { return dev.get_xu_range( _xu, _id, sizeof( T ) ); } ); - if( uvc_range.min.size() < sizeof( int32_t ) ) + if( uvc_range.min.size() < sizeof( T ) ) return option_range{ 0, 0, 1, 0 }; - auto min = *( reinterpret_cast< int32_t * >( uvc_range.min.data() ) ); - auto max = *( reinterpret_cast< int32_t * >( uvc_range.max.data() ) ); - auto step = *( reinterpret_cast< int32_t * >( uvc_range.step.data() ) ); - auto def = *( reinterpret_cast< int32_t * >( uvc_range.def.data() ) ); + auto min = *( reinterpret_cast< T* >( uvc_range.min.data() ) ); + auto max = *( reinterpret_cast< T* >( uvc_range.max.data() ) ); + auto step = *( reinterpret_cast< T* >( uvc_range.step.data() ) ); + auto def = *( reinterpret_cast< T* >( uvc_range.def.data() ) ); + + if (_parsing_modifier) + { + return option_range{ _parsing_modifier( min ), + _parsing_modifier( max ), + _parsing_modifier( step ), + _parsing_modifier( def ) }; + } return option_range{ static_cast< float >( min ), static_cast< float >( max ), static_cast< float >( step ), @@ -116,16 +126,20 @@ class uvc_xu_option : public option bool is_enabled() const override { return true; } + typedef std::function< float(const T param) > parsing_modifier; + uvc_xu_option( const std::weak_ptr< uvc_sensor > & ep, platform::extension_unit xu, uint8_t id, std::string description, - bool allow_set_while_streaming = true ) + bool allow_set_while_streaming = true, + parsing_modifier modifier = nullptr) : _ep( ep ) , _xu( xu ) , _id( id ) , _desciption( std::move( description ) ) , _allow_set_while_streaming( allow_set_while_streaming ) + , _parsing_modifier(modifier) { } @@ -134,13 +148,15 @@ class uvc_xu_option : public option uint8_t id, std::string description, const std::map< float, std::string > & description_per_value, - bool allow_set_while_streaming = true ) + bool allow_set_while_streaming = true, + parsing_modifier modifier = nullptr) : _ep( ep ) , _xu( xu ) , _id( id ) , _desciption( std::move( description ) ) , _description_per_value( description_per_value ) , _allow_set_while_streaming( allow_set_while_streaming ) + , _parsing_modifier(modifier) { } @@ -165,6 +181,7 @@ class uvc_xu_option : public option }; const std::map< float, std::string > _description_per_value; bool _allow_set_while_streaming; + parsing_modifier _parsing_modifier = nullptr; };