From 1671eeed93b656cd06fde91e7bf2633618a52ad5 Mon Sep 17 00:00:00 2001 From: Dave Tong Date: Mon, 16 Dec 2019 11:14:32 -0800 Subject: [PATCH] Add the option to enable laser always on and fixed a minor performance prolem in rendering --- common/rendering.h | 3 ++- include/librealsense2/h/rs_option.h | 1 + src/ds5/ds5-device.cpp | 5 +++++ src/ds5/ds5-options.cpp | 35 +++++++++++++++++++++++++++++ src/ds5/ds5-options.h | 22 ++++++++++++++++++ src/ds5/ds5-private.h | 1 + src/types.cpp | 1 + 7 files changed, 67 insertions(+), 1 deletion(-) diff --git a/common/rendering.h b/common/rendering.h index b3aa06ffc2..72b8af62ad 100644 --- a/common/rendering.h +++ b/common/rendering.h @@ -131,7 +131,8 @@ namespace rs2 float3 normalize() const { - return (length() > 0)? float3{ x / length(), y / length(), z / length() }:*this; + float len = length(); + return (len > 0)? float3{ x / len, y / len, z / len }:*this; } }; diff --git a/include/librealsense2/h/rs_option.h b/include/librealsense2/h/rs_option.h index c33e98ec10..865c015dc4 100644 --- a/include/librealsense2/h/rs_option.h +++ b/include/librealsense2/h/rs_option.h @@ -84,6 +84,7 @@ 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_EMITTER_ALWAYS_ON, /**< Enable Laser On constantly (GS SKU Only) */ RS2_OPTION_COUNT /**< Number of enumeration values. Not a valid input: intended to be used in for-loops. */ } rs2_option; diff --git a/src/ds5/ds5-device.cpp b/src/ds5/ds5-device.cpp index d908509f4e..5489a92198 100644 --- a/src/ds5/ds5-device.cpp +++ b/src/ds5/ds5-device.cpp @@ -749,6 +749,11 @@ namespace librealsense depth_sensor.register_option(RS2_OPTION_EMITTER_ON_OFF, std::make_shared(*_hw_monitor, &raw_depth_sensor)); } + if ((_fw_version >= firmware_version("5.12.1.0")) && ((_device_capabilities & d400_caps::CAP_GLOBAL_SHUTTER) == d400_caps::CAP_GLOBAL_SHUTTER)) + { + depth_sensor.register_option(RS2_OPTION_EMITTER_ALWAYS_ON, std::make_shared(*_hw_monitor, &depth_sensor)); + } + if (_fw_version >= firmware_version("5.9.15.1")) { depth_sensor.register_option(RS2_OPTION_INTER_CAM_SYNC_MODE, diff --git a/src/ds5/ds5-options.cpp b/src/ds5/ds5-options.cpp index 06da500ae3..4df1c54ddb 100644 --- a/src/ds5/ds5-options.cpp +++ b/src/ds5/ds5-options.cpp @@ -474,4 +474,39 @@ namespace librealsense static std::vector alt_emitter_name(ds::alternating_emitter_pattern.begin()+2,ds::alternating_emitter_pattern.begin()+22); return (alt_emitter_name == res); } + + emitter_always_on_option::emitter_always_on_option(hw_monitor& hwm, sensor_base* ep) + : _hwm(hwm), _sensor(ep) + { + _range = [this]() + { + return option_range{ 0, 1, 1, 0 }; + }; + } + + void emitter_always_on_option::set(float value) + { + command cmd(ds::LASERONCONST); + cmd.param1 = static_cast(value); + + _hwm.send(cmd); + _record_action(*this); + } + + float emitter_always_on_option::query() const + { + command cmd(ds::LASERONCONST); + cmd.param1 = 2; + + auto res = _hwm.send(cmd); + if (res.empty()) + throw invalid_value_exception("emitter_always_on_option::query result is empty!"); + + return (res.front()); + } + + option_range emitter_always_on_option::get_range() const + { + return *_range; + } } diff --git a/src/ds5/ds5-options.h b/src/ds5/ds5-options.h index 38eac52491..9e48cb3c3b 100644 --- a/src/ds5/ds5-options.h +++ b/src/ds5/ds5-options.h @@ -275,4 +275,26 @@ namespace librealsense hw_monitor& _hwm; sensor_base* _sensor; }; + + class emitter_always_on_option : public option + { + public: + emitter_always_on_option(hw_monitor& hwm, sensor_base* depth_ep); + virtual ~emitter_always_on_option() = default; + virtual void set(float value) override; + virtual float query() const override; + virtual option_range get_range() const override; + virtual bool is_enabled() const override { return true; } + virtual const char* get_description() const override + { + return "Emitter always on mode: 0:disabled(default), 1:enabled."; + } + virtual void enable_recording(std::function record_action) override { _record_action = record_action; } + + private: + std::function _record_action = [](const option&) {}; + lazy _range; + hw_monitor& _hwm; + sensor_base* _sensor; + }; } diff --git a/src/ds5/ds5-private.h b/src/ds5/ds5-private.h index b64306199b..d18e229930 100644 --- a/src/ds5/ds5-private.h +++ b/src/ds5/ds5-private.h @@ -194,6 +194,7 @@ namespace librealsense GETSUBPRESET = 0x7C, // Upload the current sub-preset GETSUBPRESETNAME= 0x7D, // Retrieve sub-preset's name RECPARAMSGET = 0x7E, // Retrieve depth calibration table in new format (fw >= 5.11.12.100) + LASERONCONST = 0x7F, // Enable Laser On constantly (GS SKU Only) AUTO_CALIB = 0x80 // auto calibration commands }; diff --git a/src/types.cpp b/src/types.cpp index e27e60148d..5d4be88e89 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -290,6 +290,7 @@ namespace librealsense CASE(LED_POWER) CASE(ZERO_ORDER_ENABLED) CASE(ENABLE_MAP_PRESERVATION) + CASE(EMITTER_ALWAYS_ON) default: assert(!is_valid(value)); return UNKNOWN_VALUE; } #undef CASE