Skip to content

Commit

Permalink
Merge pull request #7673 from remibettan/hdr-correct-fps-bug
Browse files Browse the repository at this point in the history
avoid enabling hdr if is it already enabled
  • Loading branch information
ev-mp committed Nov 3, 2020
2 parents 9b0ff86 + 4d96039 commit 20d16c4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
66 changes: 39 additions & 27 deletions src/hdr-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,10 @@ namespace librealsense
_hdr_sequence_params.resize(DEFAULT_HDR_SEQUENCE_SIZE);

// restoring current HDR configuration if such subpreset is active
command cmd(ds::GETSUBPRESET);
bool existing_subpreset_restored = false;
try {
auto res = _hwm.send(cmd);
if (res.size() && is_current_subpreset_hdr(res))
{
existing_subpreset_restored = configure_hdr_as_in_fw(res);
}
}
catch (std::exception ex) {
LOG_WARNING("In hdr_config::hdr_config() - hw command failed: " << ex.what());
}
std::vector<byte> res;
if (is_hdr_enabled_in_device(res))
existing_subpreset_restored = configure_hdr_as_in_fw(res);

if (!existing_subpreset_restored)
{
Expand All @@ -55,6 +47,20 @@ namespace librealsense
}
}

bool hdr_config::is_hdr_enabled_in_device(std::vector<byte>& result) const
{
command cmd(ds::GETSUBPRESET);
bool hdr_enabled_in_device = false;
try {
result = _hwm.send(cmd);
hdr_enabled_in_device = (result.size() && is_current_subpreset_hdr(result));
}
catch (std::exception ex) {
LOG_WARNING("In hdr_config::hdr_config() - hw command failed: " << ex.what());
}
return hdr_enabled_in_device;
}

bool hdr_config::is_current_subpreset_hdr(const std::vector<byte>& current_subpreset) const
{
bool result = false;
Expand Down Expand Up @@ -242,25 +248,30 @@ namespace librealsense
{
if (validate_config())
{
// saving status of options that are not compatible with hdr,
// so that they could be reenabled after hdr disable
set_options_to_be_restored_after_disable();

if (_use_workaround)
std::vector<byte> res;
_is_enabled = is_hdr_enabled_in_device(res);
if (!_is_enabled)
{
try {
// the following statement is needed in order to get/set the UVC exposure
// instead of one of the hdr's configuration exposure
set_sequence_index(0.f);
_pre_hdr_exposure = _sensor->get_option(RS2_OPTION_EXPOSURE).query();
_sensor->get_option(RS2_OPTION_EXPOSURE).set(PRE_ENABLE_HDR_EXPOSURE);
} catch (...) {
LOG_WARNING("HDR: enforced exposure failed");
// saving status of options that are not compatible with hdr,
// so that they could be reenabled after hdr disable
set_options_to_be_restored_after_disable();

if (_use_workaround)
{
try {
// the following statement is needed in order to get/set the UVC exposure
// instead of one of the hdr's configuration exposure
set_sequence_index(0.f);
_pre_hdr_exposure = _sensor->get_option(RS2_OPTION_EXPOSURE).query();
_sensor->get_option(RS2_OPTION_EXPOSURE).set(PRE_ENABLE_HDR_EXPOSURE);
} catch (...) {
LOG_WARNING("HDR: enforced exposure failed");
}
}
}

_is_enabled = send_sub_preset_to_fw();
_has_config_changed = false;
_is_enabled = send_sub_preset_to_fw();
_has_config_changed = false;
}
}
else
// msg to user to be improved later on
Expand All @@ -275,6 +286,7 @@ namespace librealsense
{
// this sleep is needed to let the fw restore the manual exposure
std::this_thread::sleep_for(std::chrono::milliseconds(70));

if (_pre_hdr_exposure >= _exposure_range.min && _pre_hdr_exposure <= _exposure_range.max)
{
try {
Expand Down
1 change: 1 addition & 0 deletions src/hdr-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace librealsense

private:
bool is_hdr_id(int id) const;
bool is_hdr_enabled_in_device(std::vector<byte>& result) const;
bool is_current_subpreset_hdr(const std::vector<byte>& current_subpreset) const;
bool configure_hdr_as_in_fw(const std::vector<byte>& current_subpreset);
command prepare_hdr_sub_preset_command() const;
Expand Down

0 comments on commit 20d16c4

Please sign in to comment.