Skip to content

Commit

Permalink
PR #12741 from remibettan: D500 temperatures as xu
Browse files Browse the repository at this point in the history
  • Loading branch information
Nir-Az authored Apr 4, 2024
2 parents 997d079 + a728a38 commit 3053e9f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 22 deletions.
21 changes: 12 additions & 9 deletions src/ds/d500/d500-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<temperature_option>(_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<temperature_option>(_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<temperature_option>(_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,
Expand Down
18 changes: 18 additions & 0 deletions src/ds/d500/d500-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ namespace librealsense

return temperature;
}
temperature_xu_option::temperature_xu_option(const std::weak_ptr<uvc_sensor>& ep,
platform::extension_unit xu, uint8_t id,
std::string description)
: uvc_xu_option<int16_t>(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<float>(read_value) / 10.f;
}) {}

float temperature_xu_option::query() const
{
return uvc_xu_option<int16_t>::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) :
Expand Down
19 changes: 18 additions & 1 deletion src/ds/d500/d500-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#pragma once

#include <src/platform/uvc-option.h>
#include "ds/ds-private.h"
#include "core/options-container.h"
#include "option.h"
#include "platform/uvc-option.h"

#include <rsutils/lazy.h>

Expand Down Expand Up @@ -76,6 +76,23 @@ namespace librealsense
const char* _description;
};

class temperature_xu_option : public uvc_xu_option<int16_t>,
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<void(const option&)> record_action) override
{ uvc_xu_option<int16_t>::enable_recording(record_action); }
};

class power_line_freq_option : public uvc_pu_option
{
public:
Expand Down
7 changes: 4 additions & 3 deletions src/ds/d500/d500-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint16_t> rs500_sku_pid = {
Expand Down
2 changes: 1 addition & 1 deletion src/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace librealsense
std::vector<std::function<void(float)>> _callbacks;
};

class readonly_option : public option
class readonly_option : virtual public option
{
public:
bool is_read_only() const override { return true; }
Expand Down
33 changes: 25 additions & 8 deletions src/platform/uvc-option.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
} ) );
Expand All @@ -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 ),
Expand All @@ -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)
{
}

Expand All @@ -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)
{
}

Expand All @@ -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;
};


Expand Down

0 comments on commit 3053e9f

Please sign in to comment.