advanced_mode.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 #pragma once
4 
5 #include "ds5/ds5-private.h"
6 #include "hw-monitor.h"
7 #include "streaming.h"
8 #include "option.h"
9 #define RS400_ADVANCED_MODE_HPP
11 #include "../../include/librealsense2/h/rs_advanced_mode_command.h"
12 #include "serializable-interface.h"
13 
14 #undef RS400_ADVANCED_MODE_HPP
15 
16 
17 typedef enum
18 {
20  etRsm = 1,
26  etHdad = 7,
31  etAFactor = 12,
32  etLastAdvancedModeGroup = 13, // Must be last
33 }
35 
36 namespace librealsense
37 {
38  class ds5_color_sensor;
39 
40  template<class T>
42 
43  #define MAP_ADVANCED_MODE(T, E) template<> struct advanced_mode_traits<T> { static const EtAdvancedModeRegGroup group = E; }
44 
58 
59 
60  class ds5_advanced_mode_interface : public serializable_interface, public recordable<ds5_advanced_mode_interface>
61  {
62  public:
63  virtual bool is_enabled() const = 0;
64 
65  virtual void toggle_advanced_mode(bool enable) = 0;
66 
67  virtual void apply_preset(const std::vector<platform::stream_profile>& configuration,
69  const firmware_version& fw_version) = 0;
70 
71  virtual void get_depth_control_group(STDepthControlGroup* ptr, int mode = 0) const = 0;
72  virtual void get_rsm(STRsm* ptr, int mode = 0) const = 0;
73  virtual void get_rau_support_vector_control(STRauSupportVectorControl* ptr, int mode = 0) const = 0;
74  virtual void get_color_control(STColorControl* ptr, int mode = 0) const = 0;
75  virtual void get_rau_color_thresholds_control(STRauColorThresholdsControl* ptr, int mode = 0) const = 0;
76  virtual void get_slo_color_thresholds_control(STSloColorThresholdsControl* ptr, int mode = 0) const = 0;
77  virtual void get_slo_penalty_control(STSloPenaltyControl* ptr, int mode = 0) const = 0;
78  virtual void get_hdad(STHdad* ptr, int mode = 0) const = 0;
79  virtual void get_color_correction(STColorCorrection* ptr, int mode = 0) const = 0;
80  virtual void get_depth_table_control(STDepthTableControl* ptr, int mode = 0) const = 0;
81  virtual void get_ae_control(STAEControl* ptr, int mode = 0) const = 0;
82  virtual void get_census_radius(STCensusRadius* ptr, int mode = 0) const = 0;
83  virtual void get_amp_factor(STAFactor* ptr, int mode = 0) const = 0;
84 
85  virtual void set_depth_control_group(const STDepthControlGroup& val) = 0;
86  virtual void set_rsm(const STRsm& val) = 0;
87  virtual void set_rau_support_vector_control(const STRauSupportVectorControl& val) = 0;
88  virtual void set_color_control(const STColorControl& val) = 0;
91  virtual void set_slo_penalty_control(const STSloPenaltyControl& val) = 0;
92  virtual void set_hdad(const STHdad& val) = 0;
93  virtual void set_color_correction(const STColorCorrection& val) = 0;
94  virtual void set_depth_table_control(const STDepthTableControl& val) = 0;
95  virtual void set_ae_control(const STAEControl& val) = 0;
96  virtual void set_census_radius(const STCensusRadius& val) = 0;
97  virtual void set_amp_factor(const STAFactor& val) = 0;
98 
99  virtual ~ds5_advanced_mode_interface() = default;
100  };
101 
103 
105 
107  {
108  public:
109  explicit ds5_advanced_mode_base(std::shared_ptr<hw_monitor> hwm,
111 
112  void create_snapshot(std::shared_ptr<ds5_advanced_mode_interface>& snapshot) const override {};
113  void enable_recording(std::function<void(const ds5_advanced_mode_interface&)> recording_function) override {};
114 
115  virtual ~ds5_advanced_mode_base() = default;
116 
117  bool is_enabled() const override;
118  void toggle_advanced_mode(bool enable) override;
119  void apply_preset(const std::vector<platform::stream_profile>& configuration,
121  const firmware_version& fw_version) override;
122 
123  void get_depth_control_group(STDepthControlGroup* ptr, int mode = 0) const override;
124  void get_rsm(STRsm* ptr, int mode = 0) const override;
125  void get_rau_support_vector_control(STRauSupportVectorControl* ptr, int mode = 0) const override;
126  void get_color_control(STColorControl* ptr, int mode = 0) const override;
127  void get_rau_color_thresholds_control(STRauColorThresholdsControl* ptr, int mode = 0) const override;
128  void get_slo_color_thresholds_control(STSloColorThresholdsControl* ptr, int mode = 0) const override;
129  void get_slo_penalty_control(STSloPenaltyControl* ptr, int mode = 0) const override;
130  void get_hdad(STHdad* ptr, int mode = 0) const override;
131  void get_color_correction(STColorCorrection* ptr, int mode = 0) const override;
132  void get_depth_table_control(STDepthTableControl* ptr, int mode = 0) const override;
133  void get_ae_control(STAEControl* ptr, int mode = 0) const override;
134  void get_census_radius(STCensusRadius* ptr, int mode = 0) const override;
135  void get_amp_factor(STAFactor* ptr, int mode = 0) const override;
136 
137  void set_depth_control_group(const STDepthControlGroup& val) override;
138  void set_rsm(const STRsm& val) override;
140  void set_color_control(const STColorControl& val) override;
143  void set_slo_penalty_control(const STSloPenaltyControl& val) override;
144  void set_hdad(const STHdad& val) override;
145  void set_color_correction(const STColorCorrection& val) override;
146  void set_depth_table_control(const STDepthTableControl& val) override;
147  void set_ae_control(const STAEControl& val) override;
148  void set_census_radius(const STCensusRadius& val) override;
149  void set_amp_factor(const STAFactor& val) override;
150 
151  std::vector<uint8_t> serialize_json() const override;
152  void load_json(const std::string& json_content) override;
153 
154  static const uint16_t HW_MONITOR_COMMAND_SIZE = 1000;
155  static const uint16_t HW_MONITOR_BUFFER_SIZE = 1024;
156 
157  private:
158  friend class auto_calibrated;
159  void set_exposure(synthetic_sensor& sensor, const exposure_control& val);
160  void set_auto_exposure(synthetic_sensor& sensor, const auto_exposure_control& val);
161  void get_exposure(synthetic_sensor& sensor, exposure_control* ptr) const;
162  void get_auto_exposure(synthetic_sensor& sensor, auto_exposure_control* ptr) const;
163 
164  void get_laser_power(laser_power_control* ptr) const;
165  void get_laser_state(laser_state_control* ptr) const;
166  void get_depth_exposure(exposure_control* ptr) const;
167  void get_depth_auto_exposure(auto_exposure_control* ptr) const;
168  void get_depth_gain(gain_control* ptr) const;
169  void get_depth_auto_white_balance(auto_white_balance_control* ptr) const;
170  void get_color_exposure(exposure_control* ptr) const;
171  void get_color_auto_exposure(auto_exposure_control* ptr) const;
172  void get_color_backlight_compensation(backlight_compensation_control* ptr) const;
173  void get_color_brightness(brightness_control* ptr) const;
174  void get_color_contrast(contrast_control* ptr) const;
175  void get_color_gain(gain_control* ptr) const;
176  void get_color_gamma(gamma_control* ptr) const;
177  void get_color_hue(hue_control* ptr) const;
178  void get_color_saturation(saturation_control* ptr) const;
179  void get_color_sharpness(sharpness_control* ptr) const;
180  void get_color_white_balance(white_balance_control* ptr) const;
181  void get_color_auto_white_balance(auto_white_balance_control* ptr) const;
182  void get_color_power_line_frequency(power_line_frequency_control* ptr) const;
183 
184  void set_laser_power(const laser_power_control& val);
185  void set_laser_state(const laser_state_control& val);
186  void set_depth_exposure(const exposure_control& val);
187  void set_depth_auto_exposure(const auto_exposure_control& val);
188  void set_depth_gain(const gain_control& val);
189  void set_depth_auto_white_balance(const auto_white_balance_control& val);
190  void set_color_exposure(const exposure_control& val);
191  void set_color_auto_exposure(const auto_exposure_control& val);
192  void set_color_backlight_compensation(const backlight_compensation_control& val);
193  void set_color_brightness(const brightness_control& val);
194  void set_color_contrast(const contrast_control& val);
195  void set_color_gain(const gain_control& val);
196  void set_color_gamma(const gamma_control& val);
197  void set_color_hue(const hue_control& val);
198  void set_color_saturation(const saturation_control& val);
199  void set_color_sharpness(const sharpness_control& val);
200  void set_color_white_balance(const white_balance_control& val);
201  void set_color_auto_white_balance(const auto_white_balance_control& val);
202  void set_color_power_line_frequency(const power_line_frequency_control& val);
203 
204  bool supports_option(const synthetic_sensor& sensor, rs2_option opt) const;
205 
206  std::shared_ptr<hw_monitor> _hw_monitor;
210  std::shared_ptr<advanced_mode_preset_option> _preset_opt;
213 
214  preset get_all() const;
215  void set_all(const preset& p);
216 
217  std::vector<uint8_t> send_receive(const std::vector<uint8_t>& input) const;
218 
219  template<class T>
220  void set(const T& strct, EtAdvancedModeRegGroup cmd) const
221  {
222  auto ptr = (uint8_t*)(&strct);
223  std::vector<uint8_t> data(ptr, ptr + sizeof(T));
224 
225  assert_no_error(ds::fw_cmd::SET_ADV,
226  send_receive(encode_command(ds::fw_cmd::SET_ADV, static_cast<uint32_t>(cmd), 0, 0, 0, data)));
227  std::this_thread::sleep_for(std::chrono::milliseconds(20));
228  }
229 
230  template<class T>
231  T get(EtAdvancedModeRegGroup cmd, T* ptr = static_cast<T*>(nullptr), int mode = 0) const
232  {
233  T res;
234  auto data = assert_no_error(ds::fw_cmd::GET_ADV,
235  send_receive(encode_command(ds::fw_cmd::GET_ADV,
236  static_cast<uint32_t>(cmd), mode)));
237  if (data.size() < sizeof(T))
238  {
239  throw std::runtime_error("The camera returned invalid sized result!");
240  }
241  res = *reinterpret_cast<T*>(data.data());
242  return res;
243  }
244 
245  static uint32_t pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3);
246 
247  static std::vector<uint8_t> assert_no_error(ds::fw_cmd opcode, const std::vector<uint8_t>& results);
248 
249  std::vector<uint8_t> encode_command(ds::fw_cmd opcode,
250  uint32_t p1 = 0,
251  uint32_t p2 = 0,
252  uint32_t p3 = 0,
253  uint32_t p4 = 0,
254  std::vector<uint8_t> data = std::vector<uint8_t>()) const;
255  };
256 
257 
259  {
260  public:
262  const option_range& opt_range);
263 
264  static rs2_rs400_visual_preset to_preset(float x);
265  void set(float value) override;
266  float query() const override;
267  bool is_enabled() const override;
268  const char* get_description() const override;
269  const char* get_value_description(float val) const override;
270 
271  private:
272  uint16_t get_device_pid(const uvc_sensor& sensor) const;
273  firmware_version get_firmware_version(const uvc_sensor& sensor) const;
274 
275  std::mutex _mtx;
279  };
280 }
virtual void get_hdad(STHdad *ptr, int mode=0) const =0
virtual void set_color_control(const STColorControl &val)=0
virtual void set_rau_support_vector_control(const STRauSupportVectorControl &val)=0
virtual void set_color_correction(const STColorCorrection &val)=0
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
virtual void set_depth_control_group(const STDepthControlGroup &val)=0
virtual void get_rau_support_vector_control(STRauSupportVectorControl *ptr, int mode=0) const =0
GLfloat GLfloat p
Definition: glext.h:12687
virtual void set_hdad(const STHdad &val)=0
GLfloat value
std::shared_ptr< hw_monitor > _hw_monitor
lazy< ds5_color_sensor * > _color_sensor
virtual void set_depth_table_control(const STDepthTableControl &val)=0
virtual void get_ae_control(STAEControl *ptr, int mode=0) const =0
std::vector< uint8_t > encode_command(command opcode, uint32_t p1=0, uint32_t p2=0, uint32_t p3=0, uint32_t p4=0, std::vector< uint8_t > data=std::vector< uint8_t >())
unsigned short uint16_t
Definition: stdint.h:79
MAP_ADVANCED_MODE(STDepthControlGroup, etDepthControl)
GLsizei const GLchar *const * string
virtual void set_slo_color_thresholds_control(const STSloColorThresholdsControl &val)=0
unsigned char uint8_t
Definition: stdint.h:78
std::shared_ptr< advanced_mode_preset_option > _preset_opt
virtual void load_json(const std::string &json_content)=0
GLuint GLfloat * val
virtual void apply_preset(const std::vector< platform::stream_profile > &configuration, rs2_rs400_visual_preset preset, uint16_t device_pid, const firmware_version &fw_version)=0
virtual void get_color_correction(STColorCorrection *ptr, int mode=0) const =0
GLenum mode
virtual void set_census_radius(const STCensusRadius &val)=0
virtual void get_rsm(STRsm *ptr, int mode=0) const =0
GLdouble x
unsigned int uint32_t
Definition: stdint.h:80
virtual void get_color_control(STColorControl *ptr, int mode=0) const =0
virtual std::vector< uint8_t > serialize_json() const =0
void enable_recording(std::function< void(const ds5_advanced_mode_interface &)> recording_function) override
virtual void get_depth_control_group(STDepthControlGroup *ptr, int mode=0) const =0
virtual void get_census_radius(STCensusRadius *ptr, int mode=0) const =0
virtual void get_slo_penalty_control(STSloPenaltyControl *ptr, int mode=0) const =0
virtual void get_depth_table_control(STDepthTableControl *ptr, int mode=0) const =0
virtual void set_ae_control(const STAEControl &val)=0
const uint16_t HW_MONITOR_COMMAND_SIZE
Definition: hw-monitor.h:40
GLboolean enable
Definition: glext.h:5688
GLenum query
GLenum GLenum GLenum input
Definition: glext.h:10805
virtual void set_rsm(const STRsm &val)=0
rs2_rs400_visual_preset
For RS400 devices: provides optimized settings (presets) for specific types of usage.
Definition: rs_option.h:137
virtual void toggle_advanced_mode(bool enable)=0
virtual void get_slo_color_thresholds_control(STSloColorThresholdsControl *ptr, int mode=0) const =0
GLuint res
Definition: glext.h:8856
virtual void set_slo_penalty_control(const STSloPenaltyControl &val)=0
virtual void set_amp_factor(const STAFactor &val)=0
GLboolean * data
const uint16_t HW_MONITOR_BUFFER_SIZE
Definition: hw-monitor.h:41
virtual void set_rau_color_thresholds_control(const STRauColorThresholdsControl &val)=0
virtual void get_amp_factor(STAFactor *ptr, int mode=0) const =0
uint32_t pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3)
Definition: src/types.h:1157
Definition: parser.hpp:150
MAP_EXTENSION(RS2_EXTENSION_POINTS, librealsense::points)
virtual void get_rau_color_thresholds_control(STRauColorThresholdsControl *ptr, int mode=0) const =0
void create_snapshot(std::shared_ptr< ds5_advanced_mode_interface > &snapshot) const override
EtAdvancedModeRegGroup
Definition: advanced_mode.h:17


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:45:06