Skip to content

Commit

Permalink
Merge pull request #7542 from remibettan/get_option_handler-fix
Browse files Browse the repository at this point in the history
returning nullptr instead of throwing exception
  • Loading branch information
ev-mp authored Oct 13, 2020
2 parents 7d95aba + 68c1cb8 commit 2ef61da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
8 changes: 1 addition & 7 deletions src/core/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,7 @@ namespace librealsense
std::shared_ptr<option> get_option_handler(rs2_option id) const
{
auto it = _options.find(id);
if (it == _options.end())
{
throw invalid_value_exception(to_string()
<< "Device does not support option "
<< get_option_name(id) << "!");
}
return it->second;
return (it == _options.end() ? std::shared_ptr<option>(nullptr) : it->second);
}

void register_option(rs2_option id, std::shared_ptr<option> option)
Expand Down
25 changes: 9 additions & 16 deletions src/ds5/ds5-active.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,8 @@ namespace librealsense
auto&& depth_ep = get_depth_sensor();
auto&& raw_depth_ep = get_raw_depth_sensor();

auto emitter_enabled = std::make_shared<emitter_option>(raw_depth_ep);
std::shared_ptr<option> hdr_enabled_option(depth_ep.get_option_handler(RS2_OPTION_HDR_ENABLED));

//EMITTER ENABLED OPTION
if (hdr_enabled_option)
{
depth_ep.register_option(RS2_OPTION_EMITTER_ENABLED,
std::make_shared<gated_option>(
emitter_enabled,
hdr_enabled_option,
"Emitter status cannot be set while HDR is enabled"));
}
else
{
depth_ep.register_option(RS2_OPTION_EMITTER_ENABLED, emitter_enabled);
}
auto emitter_enabled = std::make_shared<emitter_option>(raw_depth_ep);

//LASER POWER OPTION
auto laser_power = std::make_shared<uvc_xu_option<uint16_t>>(raw_depth_ep,
Expand All @@ -60,8 +46,14 @@ namespace librealsense
emitter_enabled,
std::vector<float>{0.f, 2.f}, 1.f);

if (hdr_enabled_option)
if (auto hdr_enabled_option = depth_ep.get_option_handler(RS2_OPTION_HDR_ENABLED))
{
depth_ep.register_option(RS2_OPTION_EMITTER_ENABLED,
std::make_shared<gated_option>(
emitter_enabled,
hdr_enabled_option,
"Emitter status cannot be set while HDR is enabled"));

depth_ep.register_option(RS2_OPTION_LASER_POWER,
std::make_shared<gated_option>(
laser_power_auto_disabling,
Expand All @@ -70,6 +62,7 @@ namespace librealsense
}
else
{
depth_ep.register_option(RS2_OPTION_EMITTER_ENABLED, emitter_enabled);
depth_ep.register_option(RS2_OPTION_LASER_POWER, laser_power_auto_disabling);
}

Expand Down

0 comments on commit 2ef61da

Please sign in to comment.