Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh the _depth_units when its changed. #2655

Merged
merged 1 commit into from
Nov 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/ds5/ds5-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<depth_sensor>& snapshot) const
Expand All @@ -191,7 +193,7 @@ namespace librealsense
}
protected:
const ds5_device* _owner;
float _depth_units;
std::atomic<float> _depth_units;
float _stereo_baseline_mm;
};

Expand Down Expand Up @@ -476,7 +478,18 @@ namespace librealsense
lazy<float>([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<depth_scale_option>(*_hw_monitor));
{
auto depth_scale = std::make_shared<depth_scale_option>(*_hw_monitor);
auto depth_sensor = As<ds5_depth_sensor, uvc_sensor>(&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<const_value_option>("Number of meters represented by a single depth unit",
lazy<float>([]() { return 0.001f; })));
Expand Down
1 change: 1 addition & 0 deletions src/ds5/ds5-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ namespace librealsense

_hwm.send(cmd);
_record_action(*this);
notify(value);
}

float depth_scale_option::query() const
Expand Down
3 changes: 2 additions & 1 deletion src/ds5/ds5-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ namespace librealsense
std::shared_ptr<auto_exposure_mechanism> _auto_exposure;
};

class depth_scale_option : public option
class depth_scale_option : public option, public observable_option
{
public:
depth_scale_option(hw_monitor& hwm);
Expand All @@ -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<void(const option &)> _record_action = [](const option&) {};
Expand Down
20 changes: 20 additions & 0 deletions src/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@

namespace librealsense
{
class observable_option
{
public:
void add_observer(std::function<void(float)> callback)
{
_callbacks.push_back(callback);
}

void notify(float val)
{
for (auto callback : _callbacks)
{
callback(val);
}
}

private:
std::vector<std::function<void(float)>> _callbacks;
};

class readonly_option : public option
{
public:
Expand Down