Skip to content

Commit

Permalink
Added preset to l500
Browse files Browse the repository at this point in the history
# Conflicts:
#	include/librealsense2/h/rs_types.h
  • Loading branch information
aangerma committed Feb 4, 2020
1 parent 84e40c0 commit c8d4acf
Show file tree
Hide file tree
Showing 28 changed files with 759 additions and 101 deletions.
94 changes: 58 additions & 36 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
using namespace rs400;
using namespace nlohmann;

const int XGA = 0;
const int VGA = 1;

ImVec4 flip(const ImVec4& c)
{
return{ c.y, c.x, c.z, c.w };
Expand Down Expand Up @@ -736,7 +739,7 @@ namespace rs2
ImGui::PopStyleColor();

if (ImGui::IsItemHovered())
ImGui::SetTooltip("Select custom region of interest for the auto-exposure algorithm\nClick the button, then draw a rect on the frame");
ImGui::SetTooltip("Selectcustom region of interest for the auto-exposure algorithm\nClick the button, then draw a rect on the frame");
}
}

Expand Down Expand Up @@ -992,7 +995,6 @@ namespace rs2
ss << "##" << dev.get_info(RS2_CAMERA_INFO_NAME)
<< "/" << s->get_info(RS2_CAMERA_INFO_NAME)
<< "/" << (long long)this;
populate_options(options_metadata, ss.str().c_str(), this, s, &_options_invalidated, error_message);

if (dev.supports(RS2_CAMERA_INFO_PHYSICAL_PORT) && dev.supports(RS2_CAMERA_INFO_PRODUCT_LINE))
{
Expand Down Expand Up @@ -1119,13 +1121,18 @@ namespace rs2
get_default_selection_index(res_values, resolution_constrain, &selection_index);
ui.selected_res_id = selection_index;

if (s->supports(RS2_OPTION_CAMERA_MODE))
s->set_option(RS2_OPTION_CAMERA_MODE, res_values[ui.selected_res_id].first == 640 || res_values[ui.selected_res_id].second == 640 ? VGA : XGA);

while (ui.selected_res_id >= 0 && !is_selected_combination_supported()) ui.selected_res_id--;
last_valid_ui = ui;
}
catch (const error& e)
{
error_message = error_to_string(e);
}
populate_options(options_metadata, ss.str().c_str(), this, s, &_options_invalidated, error_message);

}

subdevice_model::~subdevice_model()
Expand Down Expand Up @@ -1212,6 +1219,20 @@ namespace rs2
static_cast<int>(res_chars.size())))
{
res = true;
_options_invalidated = true;

if (s->supports(RS2_OPTION_CAMERA_MODE))
{
const int XGA = 0;
const int VGA = 1;

auto width = res_values[ui.selected_res_id].first;
auto height = res_values[ui.selected_res_id].second;
if (width == 640 || height == 640)
s->set_option(RS2_OPTION_CAMERA_MODE, VGA);
else
s->set_option(RS2_OPTION_CAMERA_MODE, XGA);
}
}
ImGui::PopStyleColor();
ImGui::PopItemWidth();
Expand Down Expand Up @@ -1848,7 +1869,8 @@ namespace rs2

for (auto&& pbm : post_processing) pbm->save_to_config_file();
}
if (next_option < s->get_supported_options().size())
auto option = 0;
if (option++ < s->get_supported_options().size())
{
if (options_metadata.find(static_cast<rs2_option>(next_option)) != options_metadata.end())
{
Expand Down Expand Up @@ -4949,7 +4971,7 @@ namespace rs2
throw std::runtime_error(to_string() << "Failed to read configuration file:\n\"" << f << "\"\nRemoving it from presets.");
}
std::string str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
if (auto advanced = dev.as<advanced_mode>())
if (auto advanced = dev.as<serializable_device>())
{
advanced.load_json(str);
for (auto&& sub : subdevices)
Expand All @@ -4976,11 +4998,11 @@ namespace rs2

const auto save_to_json = [&](std::string full_filename)
{
auto advanced = dev.as<advanced_mode>();
auto advanced = dev.as<serializable_device>();
if (!ends_with(to_lower(full_filename), ".json")) full_filename += ".json";
std::ofstream outfile(full_filename);
json saved_configuraion;
if (auto advanced = dev.as<advanced_mode>())
if (auto advanced = dev.as<serializable_device>())
{
saved_configuraion = json::parse(advanced.serialize_json());
}
Expand Down Expand Up @@ -5057,38 +5079,35 @@ namespace rs2
if (ImGui::Combo(opt_model.id.c_str(), &selected, labels.data(),
static_cast<int>(labels.size())))
{
*opt_model.invalidate_flag = true;

auto advanced = dev.as<advanced_mode>();
if (advanced)
{
if (advanced.is_enabled())
if (!advanced.is_enabled())
keep_showing_popup = true;

if(!keep_showing_popup)
if (selected < static_cast<int>(labels.size() - files_labels.size()))
{
if (selected < static_cast<int>(labels.size() - files_labels.size()))
{
//Known preset was chosen
auto new_val = opt_model.range.min + opt_model.range.step * selected;
model.add_log(to_string() << "Setting " << opt_model.opt << " to "
<< opt_model.value << " (" << labels[selected] << ")");
//Known preset was chosen
auto new_val = opt_model.range.min + opt_model.range.step * selected;
model.add_log(to_string() << "Setting " << opt_model.opt << " to "
<< opt_model.value << " (" << labels[selected] << ")");

opt_model.endpoint->set_option(opt_model.opt, new_val);
opt_model.endpoint->set_option(opt_model.opt, new_val);

// Only apply preset to GUI if set_option was succesful
selected_file_preset = "";
opt_model.value = new_val;
is_clicked = true;
}
else
{
//File was chosen
auto f = full_files_names[selected - static_cast<int>(labels.size() - files_labels.size())];
error_message = safe_call([&]() { load_json(f); });
selected_file_preset = f;
}
// Only apply preset to GUI if set_option was succesful
selected_file_preset = "";
opt_model.value = new_val;
is_clicked = true;
}
else
{
keep_showing_popup = true;
//File was chosen
auto f = full_files_names[selected - static_cast<int>(labels.size() - files_labels.size())];
error_message = safe_call([&]() { load_json(f); });
selected_file_preset = f;
}
}
}
if (keep_showing_popup)
{
Expand Down Expand Up @@ -5116,14 +5135,17 @@ namespace rs2
const ImVec2 icons_size{ 20, 20 };
//TODO: Change this once we have support for loading jsons with more data than only advanced controls
bool is_streaming = std::any_of(subdevices.begin(), subdevices.end(), [](const std::shared_ptr<subdevice_model>& sm) { return sm->streaming; });
const int buttons_flags = dev.is<advanced_mode>() ? 0 : ImGuiButtonFlags_Disabled;
const int buttons_flags = dev.is<serializable_device>() ? 0 : ImGuiButtonFlags_Disabled;
static bool require_advanced_mode_enable_prompt = false;
auto advanced_dev = dev.as<advanced_mode>();
bool is_advanced_mode_enabled = false;
bool is_advanced_mode_enabled = true;
if (advanced_dev)
{
is_advanced_mode_enabled = advanced_dev.is_enabled();
}

auto serializable_dev = dev.is<serializable_device>();

ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 3);

////////////////////////////////////////
Expand All @@ -5135,7 +5157,7 @@ namespace rs2

if (ImGui::ButtonEx(upload_button_name.c_str(), icons_size, (is_streaming && !load_json_if_streaming) ? ImGuiButtonFlags_Disabled : buttons_flags))
{
if (is_advanced_mode_enabled)
if (serializable_dev && is_advanced_mode_enabled)
{
json_loading([&]()
{
Expand Down Expand Up @@ -5167,7 +5189,7 @@ namespace rs2
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 1); //Align the two icons to buttom
if (ImGui::ButtonEx(save_button_name.c_str(), icons_size, buttons_flags))
{
if (is_advanced_mode_enabled)
if (serializable_dev && is_advanced_mode_enabled)
{
auto ret = file_dialog_open(save_file, "JavaScript Object Notation (JSON)\0*.json\0", NULL, NULL);
if (ret)
Expand Down Expand Up @@ -5390,7 +5412,7 @@ namespace rs2
////////////////////////////////////////
// draw advanced mode panel
////////////////////////////////////////
if (dev.is<advanced_mode>())
if (dev.is<serializable_device>())
{
pos = ImGui::GetCursorPos();
const float vertical_space_before_advanced_mode_control = 10.0f;
Expand Down Expand Up @@ -5652,7 +5674,7 @@ namespace rs2
if (show_stream_selection)
sub->draw_stream_selection();

static const std::vector<rs2_option> drawing_order = dev.is<advanced_mode>() ?
static const std::vector<rs2_option> drawing_order = dev.is<serializable_device>() ?
std::vector<rs2_option>{ RS2_OPTION_EMITTER_ENABLED, RS2_OPTION_ENABLE_AUTO_EXPOSURE }
: std::vector<rs2_option>{ RS2_OPTION_VISUAL_PRESET, RS2_OPTION_EMITTER_ENABLED, RS2_OPTION_ENABLE_AUTO_EXPOSURE };

Expand All @@ -5676,7 +5698,7 @@ namespace rs2
if (skip_option(opt)) continue;
if (std::find(drawing_order.begin(), drawing_order.end(), opt) == drawing_order.end())
{
if (dev.is<advanced_mode>() && opt == RS2_OPTION_VISUAL_PRESET)
if (dev.is<serializable_device>() && opt == RS2_OPTION_VISUAL_PRESET)
continue;
if (sub->draw_option(opt, dev.is<playback>() || update_read_only_options, error_message, viewer.not_model))
{
Expand Down
3 changes: 2 additions & 1 deletion common/model-views.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ namespace rs2
if (opt == RS2_OPTION_STREAM_FILTER ||
opt == RS2_OPTION_STREAM_FORMAT_FILTER ||
opt == RS2_OPTION_STREAM_INDEX_FILTER ||
opt == RS2_OPTION_FRAMES_QUEUE_SIZE)
opt == RS2_OPTION_FRAMES_QUEUE_SIZE ||
opt == RS2_OPTION_CAMERA_MODE)
return true;
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions common/on-chip-calib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ namespace rs2
{
std::stringstream ss;
ss << "{\n \"speed\":" << speed <<
",\n \"average_step_count\":" << average_step_count <<
",\n \"step_count\":" << step_count <<
",\n \"average step count\":" << average_step_count <<
",\n \"step count\":" << step_count <<
",\n \"accuracy\":" << accuracy <<"}";

std::string json = ss.str();
Expand Down
7 changes: 7 additions & 0 deletions include/librealsense2/h/rs_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ extern "C" {
RS2_OPTION_LED_POWER, /**< Power of the LED (light emitting diode), with 0 meaning LED off*/
RS2_OPTION_ZERO_ORDER_ENABLED, /**< Toggle Zero-Order mode */
RS2_OPTION_ENABLE_MAP_PRESERVATION, /**< Preserve previous map when starting */
RS2_OPTION_AVALANCHE_PHOTO_DIODE, /**< Changes the Avalanche Photo Diode in the reciever */
RS2_OPTION_POST_PROCESSING_SHARPENING, /**< Changes the amount of sharpening in the post-processed image */
RS2_OPTION_PRE_PROCESSING_SHARPENING, /**< Changes the amount of sharpening in the pre-processed image */
RS2_OPTION_NOISE_FILTERING, /**< Control edges and background noise */
RS2_OPTION_INVALIDATION_BYPASS, /**< Enable\disable pixel invalidation */
RS2_OPTION_SENSETIVITY, /**< Canges the depth sensetivity to ambient: 1 for no ambient and 2 for low ambient*/
RS2_OPTION_CAMERA_MODE, /**< Device specific for L515: 0 for XGA and 1 for VGA */
RS2_OPTION_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */
} rs2_option;

Expand Down
1 change: 1 addition & 0 deletions include/librealsense2/h/rs_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ typedef enum rs2_extension
RS2_EXTENSION_MOTION_SENSOR,
RS2_EXTENSION_FISHEYE_SENSOR,
RS2_EXTENSION_DEPTH_HUFFMAN_DECODER,
RS2_EXTENSION_SERIALIZABLE_DEVICE,
RS2_EXTENSION_COUNT
} rs2_extension;
const char* rs2_extension_type_to_string(rs2_extension type);
Expand Down
81 changes: 48 additions & 33 deletions include/librealsense2/rs_advanced_mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,57 @@

namespace rs400
{
class advanced_mode : public rs2::device
class serializable_device : public rs2::device
{
public:
serializable_device(rs2::device d)
: rs2::device(d.get())
{
rs2_error* e = nullptr;
if (rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_SERIALIZABLE_DEVICE, &e) == 0 && !e)
{
_dev = nullptr;
}
rs2::error::handle(e);
}

std::string serialize_json() const
{
std::string results;

rs2_error* e = nullptr;
std::shared_ptr<rs2_raw_data_buffer> json_data(
rs2_serialize_json(_dev.get(), &e),
rs2_delete_raw_data);
rs2::error::handle(e);

auto size = rs2_get_raw_data_size(json_data.get(), &e);
rs2::error::handle(e);

auto start = rs2_get_raw_data(json_data.get(), &e);
rs2::error::handle(e);

results.insert(results.begin(), start, start + size);

return results;
}

void load_json(const std::string& json_content)
{
rs2_error* e = nullptr;
rs2_load_json(_dev.get(),
json_content.data(),
(unsigned int)json_content.size(),
&e);
rs2::error::handle(e);
}
};

class advanced_mode : public serializable_device
{
public:
advanced_mode(rs2::device d)
: rs2::device(d.get())
: serializable_device(d)
{
rs2_error* e = nullptr;
if(rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_ADVANCED_MODE, &e) == 0 && !e)
Expand Down Expand Up @@ -261,37 +307,6 @@ namespace rs400

return group;
}

std::string serialize_json() const
{
std::string results;

rs2_error* e = nullptr;
std::shared_ptr<rs2_raw_data_buffer> json_data(
rs2_serialize_json(_dev.get(), &e),
rs2_delete_raw_data);
rs2::error::handle(e);

auto size = rs2_get_raw_data_size(json_data.get(), &e);
rs2::error::handle(e);

auto start = rs2_get_raw_data(json_data.get(), &e);
rs2::error::handle(e);

results.insert(results.begin(), start, start + size);

return results;
}

void load_json(const std::string& json_content)
{
rs2_error* e = nullptr;
rs2_load_json(_dev.get(),
json_content.data(),
(unsigned int)json_content.size(),
&e);
rs2::error::handle(e);
}
};
}

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@ target_sources(${LRS_TARGET}
"${CMAKE_CURRENT_LIST_DIR}/command_transfer.h"
"${CMAKE_CURRENT_LIST_DIR}/frame-validator.h"
"${CMAKE_CURRENT_LIST_DIR}/auto-calibrated-device.h"
"${CMAKE_CURRENT_LIST_DIR}/serializable.h"
)
7 changes: 3 additions & 4 deletions src/core/advanced_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#define RS400_ADVANCED_MODE_HPP
#include "ds5/advanced_mode/presets.h"
#include "../../include/librealsense2/h/rs_advanced_mode_command.h"
#include "serializable.h"

#undef RS400_ADVANCED_MODE_HPP


Expand Down Expand Up @@ -55,7 +57,7 @@ namespace librealsense
MAP_ADVANCED_MODE(STAFactor, etAFactor);


class ds5_advanced_mode_interface : public recordable<ds5_advanced_mode_interface>
class ds5_advanced_mode_interface : public serializable_interface, public recordable<ds5_advanced_mode_interface>
{
public:
virtual bool is_enabled() const = 0;
Expand Down Expand Up @@ -94,9 +96,6 @@ namespace librealsense
virtual void set_census_radius(const STCensusRadius& val) = 0;
virtual void set_amp_factor(const STAFactor& val) = 0;

virtual std::vector<uint8_t> serialize_json() const = 0;
virtual void load_json(const std::string& json_content) = 0;

virtual ~ds5_advanced_mode_interface() = default;
};

Expand Down
Loading

0 comments on commit c8d4acf

Please sign in to comment.