diff --git a/src/ds5/ds5-device.cpp b/src/ds5/ds5-device.cpp index 81114acddc..64d8060105 100644 --- a/src/ds5/ds5-device.cpp +++ b/src/ds5/ds5-device.cpp @@ -168,6 +168,8 @@ namespace librealsense float get_depth_scale() const override { return _depth_units; } + void set_depth_scale(float val){ _depth_units = val; } + float get_stereo_baseline_mm() const override { return _owner->get_stereo_baseline_mm(); } void create_snapshot(std::shared_ptr& snapshot) const @@ -191,7 +193,7 @@ namespace librealsense } protected: const ds5_device* _owner; - float _depth_units; + std::atomic _depth_units; float _stereo_baseline_mm; }; @@ -476,7 +478,18 @@ namespace librealsense lazy([this]() { return get_stereo_baseline_mm(); }))); if (advanced_mode && _fw_version >= firmware_version("5.6.3.0")) - depth_ep.register_option(RS2_OPTION_DEPTH_UNITS, std::make_shared(*_hw_monitor)); + { + auto depth_scale = std::make_shared(*_hw_monitor); + auto depth_sensor = As(&depth_ep); + assert(depth_sensor); + + depth_scale->add_observer([depth_sensor](float val) + { + depth_sensor->set_depth_scale(val); + }); + + depth_ep.register_option(RS2_OPTION_DEPTH_UNITS, depth_scale); + } else depth_ep.register_option(RS2_OPTION_DEPTH_UNITS, std::make_shared("Number of meters represented by a single depth unit", lazy([]() { return 0.001f; }))); diff --git a/src/ds5/ds5-options.cpp b/src/ds5/ds5-options.cpp index 06b3e60860..fee231a059 100644 --- a/src/ds5/ds5-options.cpp +++ b/src/ds5/ds5-options.cpp @@ -388,6 +388,7 @@ namespace librealsense _hwm.send(cmd); _record_action(*this); + notify(value); } float depth_scale_option::query() const diff --git a/src/ds5/ds5-options.h b/src/ds5/ds5-options.h index af4e16d756..e72010b99d 100644 --- a/src/ds5/ds5-options.h +++ b/src/ds5/ds5-options.h @@ -181,7 +181,7 @@ namespace librealsense std::shared_ptr _auto_exposure; }; - class depth_scale_option : public option + class depth_scale_option : public option, public observable_option { public: depth_scale_option(hw_monitor& hwm); @@ -199,6 +199,7 @@ namespace librealsense { _record_action = record_action; } + private: ds::depth_table_control get_depth_table(ds::advanced_query_mode mode) const; std::function _record_action = [](const option&) {}; diff --git a/src/option.h b/src/option.h index b9235f6a6e..17c8c0c92c 100644 --- a/src/option.h +++ b/src/option.h @@ -16,6 +16,26 @@ namespace librealsense { + class observable_option + { + public: + void add_observer(std::function callback) + { + _callbacks.push_back(callback); + } + + void notify(float val) + { + for (auto callback : _callbacks) + { + callback(val); + } + } + + private: + std::vector> _callbacks; + }; + class readonly_option : public option { public: