diff --git a/common/model-views.cpp b/common/model-views.cpp index 129367cb1d..dc0f7fba45 100644 --- a/common/model-views.cpp +++ b/common/model-views.cpp @@ -1234,7 +1234,7 @@ namespace rs2 auto width = res_values[ui.selected_res_id].first; auto height = res_values[ui.selected_res_id].second; auto res = resolution_from_width_height(width, height); - if (res >= RS2_SENSOR_MODE_XGA && res <= RS2_SENSOR_MODE_VGA) + if (res >= RS2_SENSOR_MODE_XGA && res < RS2_SENSOR_MODE_COUNT) s->set_option(RS2_OPTION_SENSOR_MODE, res); } } @@ -4965,9 +4965,9 @@ namespace rs2 ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, light_grey); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5, 5)); ImGui::PushFont(window.get_font()); - auto serializable_device = dev.as(); + auto serializable = dev.as(); - const auto load_json = [&, serializable_device](const std::string f) { + const auto load_json = [&, serializable](const std::string f) { std::ifstream file(f); if (!file.good()) { @@ -4978,9 +4978,9 @@ namespace rs2 } std::string str((std::istreambuf_iterator(file)), std::istreambuf_iterator()); - if (serializable_device) + if (serializable) { - serializable_device.load_json(str); + serializable.load_json(str); for (auto&& sub : subdevices) { //If json was loaded correctly, we want the presets combo box to show the name of the configuration file @@ -5003,14 +5003,14 @@ namespace rs2 viewer.not_model.add_log(to_string() << "Loaded settings from \"" << f << "\"..."); }; - const auto save_to_json = [&, serializable_device](std::string full_filename) + const auto save_to_json = [&, serializable](std::string full_filename) { if (!ends_with(to_lower(full_filename), ".json")) full_filename += ".json"; std::ofstream outfile(full_filename); json saved_configuraion; - if (serializable_device) + if (serializable) { - saved_configuraion = json::parse(serializable_device.serialize_json()); + saved_configuraion = json::parse(serializable.serialize_json()); } save_viewer_configurations(outfile, saved_configuraion); outfile << saved_configuraion.dump(4); @@ -5111,7 +5111,7 @@ namespace rs2 { //File was chosen auto file = selected - static_cast(labels.size() - files_labels.size()); - if(file < 0 || file > full_files_names.size()) + if(file < 0 || file >= full_files_names.size()) throw std::runtime_error("not a valid format"); auto f = full_files_names[file]; error_message = safe_call([&]() { load_json(f); }); @@ -5144,7 +5144,7 @@ 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& sm) { return sm->streaming; }); - const int buttons_flags = serializable_device ? 0 : ImGuiButtonFlags_Disabled; + const int buttons_flags = serializable ? 0 : ImGuiButtonFlags_Disabled; static bool require_advanced_mode_enable_prompt = false; auto advanced_dev = dev.as(); auto is_advanced_device = false; @@ -5166,7 +5166,7 @@ namespace rs2 if (ImGui::ButtonEx(upload_button_name.c_str(), icons_size, (is_streaming && !load_json_if_streaming) ? ImGuiButtonFlags_Disabled : buttons_flags)) { - if (serializable_device && (!is_advanced_device || is_advanced_mode_enabled)) + if (serializable && (!is_advanced_device || is_advanced_mode_enabled)) { json_loading([&]() { @@ -5198,7 +5198,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 (serializable_device && (!is_advanced_device || is_advanced_mode_enabled)) + if (serializable && (!is_advanced_device || is_advanced_mode_enabled)) { auto ret = file_dialog_open(save_file, "JavaScript Object Notation (JSON)\0*.json\0", NULL, NULL); if (ret) @@ -5421,7 +5421,7 @@ namespace rs2 //////////////////////////////////////// // draw advanced mode panel //////////////////////////////////////// - auto serialize = dev.is(); + auto serialize = dev.is(); if (serialize) { pos = ImGui::GetCursorPos(); diff --git a/include/librealsense2/h/rs_option.h b/include/librealsense2/h/rs_option.h index 33f37c595e..2b1bf7d5e7 100644 --- a/include/librealsense2/h/rs_option.h +++ b/include/librealsense2/h/rs_option.h @@ -84,13 +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 exposure time of Avalanche Photo Diode in the reciever */ + RS2_OPTION_AVALANCHE_PHOTO_DIODE, /**< Changes the exposure time of Avalanche Photo Diode in the receiver */ 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_AMBIENT_LIGHT, /**< Change the depth ambient light to ambient: 1 for no ambient and 2 for low ambient */ - RS2_OPTION_SENSOR_MODE, /**< Device specific for L515: 0 for XGA and 1 for VGA */ + RS2_OPTION_AMBIENT_LIGHT, /**< Change the depth ambient light see rs2_ambient_light for values */ + RS2_OPTION_SENSOR_MODE, /**< The resolution mode: see rs2_sensor_mode for values */ RS2_OPTION_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */ } rs2_option; @@ -125,7 +125,7 @@ extern "C" { RS2_RS400_VISUAL_PRESET_HIGH_DENSITY, RS2_RS400_VISUAL_PRESET_MEDIUM_DENSITY, RS2_RS400_VISUAL_PRESET_REMOVE_IR_PATTERN, - RS2_RS400_VISUAL_PRESET_COUNT + RS2_RS400_VISUAL_PRESET_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */ } rs2_rs400_visual_preset; const char* rs2_rs400_visual_preset_to_string(rs2_rs400_visual_preset preset); @@ -138,7 +138,7 @@ extern "C" { RS2_L500_VISUAL_PRESET_LOW_AMBIENT, RS2_L500_VISUAL_PRESET_MAX_RANGE, RS2_L500_VISUAL_PRESET_SHORT_RANGE, - RS2_L500_VISUAL_PRESET_COUNT + RS2_L500_VISUAL_PRESET_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */ } rs2_l500_visual_preset; const char* rs2_l500_visual_preset_to_string(rs2_l500_visual_preset preset); @@ -147,10 +147,18 @@ extern "C" { { RS2_SENSOR_MODE_XGA, RS2_SENSOR_MODE_VGA, - RS2_SENSOR_MODE_COUNT + RS2_SENSOR_MODE_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */ } rs2_sensor_mode; const char* rs2_sensor_mode_to_string(rs2_sensor_mode preset); + /** \brief ambient light for RS2_OPTION_AMBIENT_LIGHT option. */ + typedef enum rs2_ambient_light + { + RS2_AMBIENT_LIGHT_NO_AMBIENT = 1, + RS2_AMBIENT_LIGHT_LOW_AMBIENT = 2, + } rs2_ambient_light; + const char* rs2_ambient_light_to_string(rs2_ambient_light preset); + /** * check if an option is read-only * \param[in] options the options container diff --git a/include/librealsense2/hpp/rs_serializable_device.hpp b/include/librealsense2/hpp/rs_serializable_device.hpp index 7c0ef300ad..b221a167cd 100644 --- a/include/librealsense2/hpp/rs_serializable_device.hpp +++ b/include/librealsense2/hpp/rs_serializable_device.hpp @@ -9,10 +9,10 @@ namespace rs2 { - class serializable : public rs2::device + class serializable_device : public rs2::device { public: - serializable(rs2::device d) + serializable_device(rs2::device d) : rs2::device(d.get()) { rs2_error* e = nullptr; diff --git a/include/librealsense2/rs_advanced_mode.hpp b/include/librealsense2/rs_advanced_mode.hpp index 7517286d44..6bad55db3f 100644 --- a/include/librealsense2/rs_advanced_mode.hpp +++ b/include/librealsense2/rs_advanced_mode.hpp @@ -11,11 +11,11 @@ namespace rs400 { - class advanced_mode : public rs2::serializable + class advanced_mode : public rs2::serializable_device { public: advanced_mode(rs2::device d) - : rs2::serializable(d) + : rs2::serializable_device(d) { rs2_error* e = nullptr; if(_dev && rs2_is_device_extendable_to(_dev.get(), RS2_EXTENSION_ADVANCED_MODE, &e) == 0 && !e) diff --git a/src/l500/l500-depth.cpp b/src/l500/l500-depth.cpp index 68bc3898e4..650c04492f 100644 --- a/src/l500/l500-depth.cpp +++ b/src/l500/l500-depth.cpp @@ -337,7 +337,8 @@ namespace librealsense if (preset_option.query() == RS2_L500_VISUAL_PRESET_CUSTOM) { if(sensor_mode_option.query() != get_resolution_from_width_height(vs->get_width(), vs->get_height())) - throw std::runtime_error(to_string() << "sensor mode option is incompatible with requsted resolution"); + throw std::runtime_error(to_string() << "sensor mode option ("<< sensor_mode_option.query()<<") is incompatible with requsted resolution (" + << get_resolution_from_width_height(vs->get_width(), vs->get_height())<<")"); } } diff --git a/src/l500/l500-factory.cpp b/src/l500/l500-factory.cpp index 1ac2fbfe6e..3eb0d50605 100644 --- a/src/l500/l500-factory.cpp +++ b/src/l500/l500-factory.cpp @@ -39,7 +39,7 @@ namespace librealsense l500_options(ctx, group), l500_color(ctx, group), l500_motion(ctx, group), - l500_serializable_base(l500_device::_hw_monitor, get_depth_sensor()) + l500_serializable_base(_hw_monitor, get_depth_sensor()) {} std::shared_ptr create_matcher(const frame_holder& frame) const override; diff --git a/src/l500/l500-options.cpp b/src/l500/l500-options.cpp index b09f0dc01b..cebf94c2a7 100644 --- a/src/l500/l500-options.cpp +++ b/src/l500/l500-options.cpp @@ -5,7 +5,7 @@ #include "l500-private.h" #include "l500-depth.h" -const std::string MIN_CONTROLS_FW_VERSION("1.3.8.0"); +const std::string MIN_CONTROLS_FW_VERSION("1.3.9.0"); namespace librealsense { @@ -65,8 +65,8 @@ namespace librealsense depth_sensor.register_option (RS2_OPTION_VISUAL_PRESET, std::make_shared>(raw_depth_sensor, ivcam2::depth_xu, ivcam2::L500_AMBIENT, "Change the depth ambient light to ambient: 1 for no ambient and 2 for low ambient", - std::map{ { no_ambient, "No Ambient"}, - { low_ambient, "Low Ambient" }})); + std::map{ { RS2_AMBIENT_LIGHT_NO_AMBIENT, "No Ambient"}, + { RS2_AMBIENT_LIGHT_LOW_AMBIENT, "Low Ambient" }})); } else { @@ -86,8 +86,8 @@ namespace librealsense _ambient_light = register_option, uvc_sensor&, platform::extension_unit, uint8_t, std::string, const std::map& > (RS2_OPTION_AMBIENT_LIGHT, raw_depth_sensor, ivcam2::depth_xu, ivcam2::L500_AMBIENT, "Change the depth ambient light to ambient: 1 for no ambient and 2 for low ambient", - std::map{ { no_ambient, "No Ambient"}, - { low_ambient, "Low Ambient" }}); + std::map{ { RS2_AMBIENT_LIGHT_NO_AMBIENT, "No Ambient"}, + { RS2_AMBIENT_LIGHT_LOW_AMBIENT, "Low Ambient" }}); _preset = register_option , option_range> @@ -133,21 +133,21 @@ namespace librealsense switch (preset) { case RS2_L500_VISUAL_PRESET_NO_AMBIENT: - _ambient_light->set_with_no_signal(no_ambient); + _ambient_light->set_with_no_signal(RS2_AMBIENT_LIGHT_NO_AMBIENT); break; case RS2_L500_VISUAL_PRESET_LOW_AMBIENT: - _ambient_light->set_with_no_signal(low_ambient); + _ambient_light->set_with_no_signal(RS2_AMBIENT_LIGHT_LOW_AMBIENT); set_max_laser(); break; case RS2_L500_VISUAL_PRESET_MAX_RANGE: - _ambient_light->set_with_no_signal(no_ambient); + _ambient_light->set_with_no_signal(RS2_AMBIENT_LIGHT_NO_AMBIENT); set_max_laser(); break; case RS2_L500_VISUAL_PRESET_SHORT_RANGE: - _ambient_light->set_with_no_signal(low_ambient); + _ambient_light->set_with_no_signal(RS2_AMBIENT_LIGHT_LOW_AMBIENT); break; case RS2_L500_VISUAL_PRESET_CUSTOM: - move_to_custom (); + move_to_custom(); break; default: break; }; diff --git a/src/l500/l500-options.h b/src/l500/l500-options.h index 7d181985e0..3ba9af6e4f 100644 --- a/src/l500/l500-options.h +++ b/src/l500/l500-options.h @@ -27,12 +27,6 @@ namespace librealsense get_step = 3 }; - enum rs2_ambient_light - { - no_ambient = 1, - low_ambient = 2 - }; - class l500_hw_options : public option { public: diff --git a/src/l500/l500-serializable.cpp b/src/l500/l500-serializable.cpp index 3837bed91a..b88ee25e5a 100644 --- a/src/l500/l500-serializable.cpp +++ b/src/l500/l500-serializable.cpp @@ -9,7 +9,7 @@ namespace librealsense using json = nlohmann::json; l500_serializable_base::l500_serializable_base(std::shared_ptr hw_monitor, synthetic_sensor & depth_sensor) - :_hw_monitor(hw_monitor), + :_hw_monitor_ptr(hw_monitor), _depth_sensor(depth_sensor) { } @@ -23,8 +23,6 @@ namespace librealsense { auto&& opt = _depth_sensor.get_option(o); auto val = opt.query(); - std::stringstream ss; - ss << val; j[get_string(o)] = val; } diff --git a/src/l500/l500-serializable.h b/src/l500/l500-serializable.h index 5ac811159f..8d81d5ca1b 100644 --- a/src/l500/l500-serializable.h +++ b/src/l500/l500-serializable.h @@ -17,7 +17,7 @@ namespace librealsense void load_json(const std::string& json_content) override; private: - std::shared_ptr _hw_monitor; + std::shared_ptr _hw_monitor_ptr; synthetic_sensor& _depth_sensor; }; } // namespace librealsense diff --git a/src/option.h b/src/option.h index de4feaedd6..7dcd73b1e9 100644 --- a/src/option.h +++ b/src/option.h @@ -101,16 +101,20 @@ namespace librealsense }; template - class option_with_description : public virtual option + class enum_option : public virtual option { public: - option_with_description(std::string description) - :_description(description){} - const char* get_value_description(float val) const override { return get_string((T)((int)val)); } + }; + + class option_description : public virtual option + { + public: + option_description(std::string description) + :_description(description) {} const char* get_description() const override { @@ -215,13 +219,13 @@ namespace librealsense }; template - class float_option_with_description : public float_option, public option_with_description + class float_option_with_description : public float_option, public option_description, public enum_option { public: float_option_with_description(option_range range, std::string description) - :float_option(range), option_with_description(description) {} + :float_option(range), option_description(description) {} - const char* get_description() const override { return option_with_description::get_description(); } + const char* get_description() const override { return option_description::get_description(); } }; class LRS_EXTENSION_API bool_option : public float_option diff --git a/src/rs.cpp b/src/rs.cpp index d14565bc6f..2fced98214 100644 --- a/src/rs.cpp +++ b/src/rs.cpp @@ -1104,7 +1104,8 @@ const char* rs2_frame_metadata_to_string(rs2_frame_metadata_value metadata) const char* rs2_extension_to_string(rs2_extension type) { return rs2_extension_type_to_string(type); } const char* rs2_frame_metadata_value_to_string(rs2_frame_metadata_value metadata) { return rs2_frame_metadata_to_string(metadata); } const char* rs2_l500_visual_preset_to_string(rs2_l500_visual_preset preset) { return get_string(preset); } -const char* rs2_sensor_mode_to_string(rs2_sensor_mode mode) { return librealsense::get_string(mode); } +const char* rs2_sensor_mode_to_string(rs2_sensor_mode mode) { return get_string(mode); } +const char* rs2_ambient_light_to_string(rs2_ambient_light ambient) { return get_string(ambient); } void rs2_log_to_console(rs2_log_severity min_severity, rs2_error** error) BEGIN_API_CALL { diff --git a/src/serializable-interface.h b/src/serializable-interface.h index add632d834..1d805de4d3 100644 --- a/src/serializable-interface.h +++ b/src/serializable-interface.h @@ -3,7 +3,7 @@ #pragma once #include "types.h" -#include "core/streaming.h" +#include "core/extension.h" namespace librealsense { diff --git a/src/types.cpp b/src/types.cpp index 71a4b18029..e554ddf0ff 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -152,6 +152,18 @@ namespace librealsense #undef CASE } + const char* get_string(rs2_ambient_light value) + { +#define CASE(X) STRCASE(AMBIENT_LIGHT, X) + switch (value) + { + CASE(NO_AMBIENT) + CASE(LOW_AMBIENT) + default: assert(!is_valid(value)); return UNKNOWN_VALUE; + } +#undef CASE + } + const char* get_string(rs2_extension value) { #define CASE(X) STRCASE(EXTENSION, X) @@ -495,7 +507,6 @@ namespace librealsense CASE(LOW_AMBIENT) CASE(MAX_RANGE) CASE(SHORT_RANGE) - CASE(COUNT) default: assert(!is_valid(value)); return UNKNOWN_VALUE; } #undef CASE diff --git a/src/types.h b/src/types.h index 8abcca96fd..393ec5e18b 100644 --- a/src/types.h +++ b/src/types.h @@ -502,13 +502,14 @@ namespace librealsense // Enumerated type support // ///////////////////////////// +#define RS2_ENUM_HELPERS(TYPE, PREFIX) RS2_ENUM_HELPERS_CUSTOMIZED(TYPE, PREFIX, 0, RS2_##PREFIX##_COUNT) -#define RS2_ENUM_HELPERS(TYPE, PREFIX) LRS_EXTENSION_API const char* get_string(TYPE value); \ - inline bool is_valid(TYPE value) { return value >= 0 && value < RS2_##PREFIX##_COUNT; } \ +#define RS2_ENUM_HELPERS_CUSTOMIZED(TYPE, PREFIX, START, END) LRS_EXTENSION_API const char* get_string(TYPE value); \ + inline bool is_valid(TYPE value) { return value >= START && value (RS2_ ## PREFIX ## _COUNT); i++) { \ + for (int i = START; i < END; i++) { \ auto v = static_cast(i); \ if(str == get_string(v)) { res = v; return true; } \ } \ @@ -531,7 +532,7 @@ namespace librealsense RS2_ENUM_HELPERS(rs2_matchers, MATCHER) RS2_ENUM_HELPERS(rs2_sensor_mode, SENSOR_MODE) RS2_ENUM_HELPERS(rs2_l500_visual_preset, L500_VISUAL_PRESET) - + RS2_ENUM_HELPERS_CUSTOMIZED(rs2_ambient_light, AMBIENT_LIGHT, RS2_AMBIENT_LIGHT_NO_AMBIENT, RS2_AMBIENT_LIGHT_LOW_AMBIENT) //////////////////////////////////////////// // World's tiniest linear algebra library // diff --git a/unit-tests/unit-tests-live.cpp b/unit-tests/unit-tests-live.cpp index 1a2680c6af..a67956a3af 100644 --- a/unit-tests/unit-tests-live.cpp +++ b/unit-tests/unit-tests-live.cpp @@ -5841,7 +5841,7 @@ TEST_CASE("l500_presets_set_preset", "[live]") auto presets = ds.get_option_range(RS2_OPTION_VISUAL_PRESET); REQUIRE(presets.min == RS2_L500_VISUAL_PRESET_CUSTOM); - REQUIRE(presets.max == RS2_L500_VISUAL_PRESET_SHORT_RANGE); + REQUIRE(presets.max == RS2_L500_VISUAL_PRESET_COUNT - 1); REQUIRE(presets.step == 1); REQUIRE(presets.def == RS2_L500_VISUAL_PRESET_DEFAULT); @@ -5857,10 +5857,10 @@ TEST_CASE("l500_presets_set_preset", "[live]") std::map expected_ambient_per_preset = { - {RS2_L500_VISUAL_PRESET_NO_AMBIENT, 1}, - {RS2_L500_VISUAL_PRESET_LOW_AMBIENT, 2}, - {RS2_L500_VISUAL_PRESET_MAX_RANGE, 1}, - {RS2_L500_VISUAL_PRESET_SHORT_RANGE, 2} + {RS2_L500_VISUAL_PRESET_NO_AMBIENT, RS2_AMBIENT_LIGHT_NO_AMBIENT}, + {RS2_L500_VISUAL_PRESET_LOW_AMBIENT, RS2_AMBIENT_LIGHT_LOW_AMBIENT}, + {RS2_L500_VISUAL_PRESET_MAX_RANGE, RS2_AMBIENT_LIGHT_NO_AMBIENT}, + {RS2_L500_VISUAL_PRESET_SHORT_RANGE, RS2_AMBIENT_LIGHT_LOW_AMBIENT} }; std::map expected_laser_power_per_preset = @@ -5872,7 +5872,7 @@ TEST_CASE("l500_presets_set_preset", "[live]") std::map< float, float> apd_per_ambient; for (auto i : expected_ambient_per_preset) { - std::vector resolutions{ RS2_SENSOR_MODE_XGA, RS2_SENSOR_MODE_VGA }; //XGA, VGA + std::vector resolutions{ RS2_SENSOR_MODE_XGA, RS2_SENSOR_MODE_VGA }; for (auto res : resolutions) { ds.set_option(RS2_OPTION_SENSOR_MODE, res); @@ -5897,7 +5897,7 @@ TEST_CASE("l500_presets_set_preset", "[live]") { ds.set_option(opt.first, opt.second.min); CAPTURE(ds.get_option(RS2_OPTION_VISUAL_PRESET)); - REQUIRE(ds.get_option(RS2_OPTION_VISUAL_PRESET) == RS2_L500_VISUAL_PRESET_CUSTOM); //custom + REQUIRE(ds.get_option(RS2_OPTION_VISUAL_PRESET) == RS2_L500_VISUAL_PRESET_CUSTOM); ds.set_option(RS2_OPTION_VISUAL_PRESET, RS2_L500_VISUAL_PRESET_LOW_AMBIENT); }