Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aangerma committed Feb 4, 2020
1 parent a05bb6e commit b5d8e69
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 66 deletions.
26 changes: 13 additions & 13 deletions common/model-views.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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<serializable>();
auto serializable = dev.as<serializable_device>();

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())
{
Expand All @@ -4978,9 +4978,9 @@ namespace rs2
}
std::string str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());

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
Expand All @@ -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);
Expand Down Expand Up @@ -5111,7 +5111,7 @@ namespace rs2
{
//File was chosen
auto file = selected - static_cast<int>(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); });
Expand Down Expand Up @@ -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<subdevice_model>& 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<advanced_mode>();
auto is_advanced_device = false;
Expand All @@ -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([&]()
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -5421,7 +5421,7 @@ namespace rs2
////////////////////////////////////////
// draw advanced mode panel
////////////////////////////////////////
auto serialize = dev.is<serializable>();
auto serialize = dev.is<serializable_device>();
if (serialize)
{
pos = ImGui::GetCursorPos();
Expand Down
20 changes: 14 additions & 6 deletions include/librealsense2/h/rs_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions include/librealsense2/hpp/rs_serializable_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions include/librealsense2/rs_advanced_mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/l500/l500-depth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())<<")");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/l500/l500-factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<matcher> create_matcher(const frame_holder& frame) const override;
Expand Down
20 changes: 10 additions & 10 deletions src/l500/l500-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -65,8 +65,8 @@ namespace librealsense
depth_sensor.register_option
(RS2_OPTION_VISUAL_PRESET, std::make_shared<uvc_xu_option<int >>(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<float, std::string>{ { no_ambient, "No Ambient"},
{ low_ambient, "Low Ambient" }}));
std::map<float, std::string>{ { RS2_AMBIENT_LIGHT_NO_AMBIENT, "No Ambient"},
{ RS2_AMBIENT_LIGHT_LOW_AMBIENT, "Low Ambient" }}));
}
else
{
Expand All @@ -86,8 +86,8 @@ namespace librealsense
_ambient_light = register_option<uvc_xu_option<int>, uvc_sensor&, platform::extension_unit, uint8_t, std::string, const std::map<float, std::string>& >
(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<float, std::string>{ { no_ambient, "No Ambient"},
{ low_ambient, "Low Ambient" }});
std::map<float, std::string>{ { RS2_AMBIENT_LIGHT_NO_AMBIENT, "No Ambient"},
{ RS2_AMBIENT_LIGHT_LOW_AMBIENT, "Low Ambient" }});


_preset = register_option <float_option_with_description<rs2_l500_visual_preset>, option_range>
Expand Down Expand Up @@ -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;
};
Expand Down
6 changes: 0 additions & 6 deletions src/l500/l500-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions src/l500/l500-serializable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace librealsense
using json = nlohmann::json;

l500_serializable_base::l500_serializable_base(std::shared_ptr<hw_monitor> hw_monitor, synthetic_sensor & depth_sensor)
:_hw_monitor(hw_monitor),
:_hw_monitor_ptr(hw_monitor),
_depth_sensor(depth_sensor)
{
}
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/l500/l500-serializable.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace librealsense
void load_json(const std::string& json_content) override;

private:
std::shared_ptr<hw_monitor> _hw_monitor;
std::shared_ptr<hw_monitor> _hw_monitor_ptr;
synthetic_sensor& _depth_sensor;
};
} // namespace librealsense
18 changes: 11 additions & 7 deletions src/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,20 @@ namespace librealsense
};

template<class T>
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
{
Expand Down Expand Up @@ -215,13 +219,13 @@ namespace librealsense
};

template<class T>
class float_option_with_description : public float_option, public option_with_description<T>
class float_option_with_description : public float_option, public option_description, public enum_option<T>
{
public:
float_option_with_description(option_range range, std::string description)
:float_option(range), option_with_description<T>(description) {}
:float_option(range), option_description(description) {}

const char* get_description() const override { return option_with_description<T>::get_description(); }
const char* get_description() const override { return option_description::get_description(); }
};

class LRS_EXTENSION_API bool_option : public float_option
Expand Down
3 changes: 2 additions & 1 deletion src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/serializable-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once
#include "types.h"
#include "core/streaming.h"
#include "core/extension.h"

namespace librealsense
{
Expand Down
13 changes: 12 additions & 1 deletion src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit b5d8e69

Please sign in to comment.