l500-options.cpp
Go to the documentation of this file.
1 
4 #include "l500-options.h"
5 #include "l500-private.h"
6 #include "l500-depth.h"
7 
8 const std::string MIN_CONTROLS_FW_VERSION("1.3.9.0");
9 const std::string MIN_GET_DEFAULT_FW_VERSION( "1.5.4.0" );
10 
11 namespace librealsense
12 {
13  using namespace ivcam2;
14 
16  {
17  return ( rs2_sensor_mode )(int)resolution.query();
18  }
19 
20  float l500_hw_options::query() const
21  {
22  return query_current( query_sensor_mode(*_resolution) );
23  }
24 
26  {
27  // Block activating alternate IR when IR reflectivity is on [RS5-8358]
28  auto &ds = _l500_dev->get_depth_sensor();
29  if( ( alternate_ir == _type ) && ( 1.0f == value ) )
30  {
31  if( ds.supports_option( RS2_OPTION_ENABLE_IR_REFLECTIVITY )
32  && ds.get_option( RS2_OPTION_ENABLE_IR_REFLECTIVITY ).query() == 1.0f )
34  "Alternate IR cannot be enabled with IR Reflectivity" );
35  }
36 
37  _hw_monitor->send(command{ AMCSET, _type, (int)value });
38  }
39 
41  {
42  return _range;
43  }
44 
46  {
47  success = true;
48  if(_fw_version >= firmware_version( MIN_GET_DEFAULT_FW_VERSION ) )
49  {
50  return query_new_fw_default( success );
51  }
52  else
53  {
54  return query_old_fw_default();
55  }
56  }
57 
62  const std::string & description,
63  firmware_version fw_version,
64  std::shared_ptr< digital_gain_option > digital_gain )
65  : _l500_dev( l500_dev )
66  , _hw_monitor( hw_monitor )
67  , _type( type )
68  , _resolution( resolution )
69  , _description( description )
70  , _fw_version( fw_version )
71  , _digital_gain( digital_gain )
72  , _is_read_only(false)
73  , _was_set_manually( false )
74  {
75  // Keep the USB power on while triggering multiple calls on it.
77  auto min = _hw_monitor->send( command{ AMCGET, _type, get_min } );
78  auto max = _hw_monitor->send( command{ AMCGET, _type, get_max } );
79  auto step = _hw_monitor->send( command{ AMCGET, _type, get_step } );
80 
81  if( min.size() < sizeof( int32_t ) || max.size() < sizeof( int32_t )
82  || step.size() < sizeof( int32_t ) )
83  {
84  std::stringstream s;
85  s << "Size of data returned is not valid min size = " << min.size()
86  << ", max size = " << max.size() << ", step size = " << step.size();
87  throw std::runtime_error( s.str() );
88  }
89 
90  auto max_value = float( *( reinterpret_cast< int32_t * >( max.data() ) ) );
91  auto min_value = float( *( reinterpret_cast< int32_t * >( min.data() ) ) );
92 
93  bool success;
94  auto res = query_default( success );
95 
96  if( ! success )
97  {
98  _is_read_only = true;
99  res = -1;
100  }
101 
102  _range = option_range{ min_value,
103  max_value,
104  float( *( reinterpret_cast< int32_t * >( step.data() ) ) ),
105  res };
106  } );
107  }
108 
110  {
111  _range.def = def;
112  }
113 
114  void l500_hw_options::set_read_only( bool read_only )
115  {
116  _is_read_only = read_only;
117  }
118 
120  {
121  _was_set_manually = set;
122  }
123 
124  void l500_hw_options::enable_recording(std::function<void(const option&)> recording_action)
125  {}
126 
127  // this method can throw an exception if un-expected error occurred
128  // or return error by output parameter 'success' if default value not applicable
129  // on this state return value is undefined
131  {
132  success = true;
133  hwmon_response response;
134  auto res = _hw_monitor->send( command{ AMCGET,
135  _type,
137  (int)query_sensor_mode( *_resolution ) },
138  &response );
139 
140  // Some controls that are automatically set by the FW (e.g., APD when digital gain is AUTO) are read-only
141  // and have no defaults: the FW will return hwm_IllegalHwState for these. Some can still be modified (e.g.,
142  // laser power & min distance), and for these we expect hwm_Success.
143  if( response == hwm_IllegalHwState )
144  {
145  success = false;
146  return -1;
147  }
148  else if( response != hwm_Success )
149  {
150  std::stringstream s;
151  s << "hw_monitor AMCGET of " << _type << " return error " << response;
152  throw std::runtime_error( s.str() );
153  }
154  else if (res.size() < sizeof(int32_t))
155  {
156  std::stringstream s;
157  s << "Size of data returned from query(get_default) of " << _type << " is "
158  << res.size() << " while min size = " << sizeof( int32_t );
159  throw std::runtime_error( s.str() );
160  }
161 
162  auto val = *( reinterpret_cast< uint32_t * >( res.data() ) );
163  return float( val );
164  }
165 
167  {
168  // For older FW without support for get_default, we have to:
169  // 1. Save the current value
170  // 2. Change to -1
171  // 3. Wait for the next frame (if streaming)
172  // 4. Read the current value
173  // 5. Restore the current value
174  auto current = query_current( query_sensor_mode( *_resolution ) );
175  _hw_monitor->send( command{ AMCSET, _type, -1 } );
176 
177  // if the sensor is streaming the value of control will update only when the next frame
178  // arrive
180  std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) );
181 
182  auto def = query_current( query_sensor_mode( *_resolution ) );
183 
184  if( current != def )
185  _hw_monitor->send( command{ AMCSET, _type, (int)current } );
186 
187  return def;
188  }
189 
191  {
192  auto res = _hw_monitor->send( command{ AMCGET, _type, get_current, mode } );
193 
194  if( res.size() < sizeof( int32_t ) )
195  {
196  std::stringstream s;
197  s << "Size of data returned from query(get_current) of " << _type << " is " << res.size()
198  << " while min size = " << sizeof( int32_t );
199  throw std::runtime_error( s.str() );
200  }
201  auto val = *( reinterpret_cast< uint32_t * >( res.data() ) );
202  return float( val );
203  }
204 
206  device(ctx, group),
207  l500_device(ctx, group)
208  {
209  auto& raw_depth_sensor = get_raw_depth_sensor();
210  auto& depth_sensor = get_depth_sensor();
211 
212  // Keep the USB power on while triggering multiple HW monitor commands on it.
215  {
216  depth_sensor.register_option(
218  std::make_shared< uvc_xu_option< int > >(
219  raw_depth_sensor,
222  "Change the depth digital gain to: 1 for high gain and 2 for low gain",
223  std::map< float, std::string >{
224  { float( RS2_DIGITAL_GAIN_HIGH ), "High Gain" },
225  { float( RS2_DIGITAL_GAIN_LOW ), "Low Gain" } } ) );
226  }
227  else
228  {
229  // On USB2 we have only QVGA sensor mode
230  bool usb3mode
232 
233  auto default_sensor_mode
234  = static_cast< float >( usb3mode ? RS2_SENSOR_MODE_VGA : RS2_SENSOR_MODE_QVGA );
235 
236  auto resolution_option = std::make_shared< sensor_mode_option >(
237  this,
240  1,
241  default_sensor_mode },
242  "Notify the sensor about the intended streaming mode. Required for preset " );
243 
244  // changing the resolution affects the defaults
245  resolution_option->add_observer( [&]( float ) {
246  update_defaults();
247 
248  auto curr_preset = ( rs2_l500_visual_preset )(int)_preset->query();
249  if( curr_preset != RS2_L500_VISUAL_PRESET_AUTOMATIC
250  && curr_preset != RS2_L500_VISUAL_PRESET_CUSTOM )
251  {
252  change_preset( curr_preset );
253  }
254  } );
255 
256 
257  depth_sensor.register_option( RS2_OPTION_SENSOR_MODE, resolution_option );
258 
259  _digital_gain = std::make_shared< digital_gain_option >(
260  raw_depth_sensor,
263  "Change the depth digital gain to: 1 for high gain and 2 for low gain",
264  std::map< float, std::string >{ /*{ RS2_DIGITAL_GAIN_AUTO, "Auto Gain" },*/
265  { (float)(RS2_DIGITAL_GAIN_HIGH), "High Gain" },
266  { (float)(RS2_DIGITAL_GAIN_LOW), "Low Gain" } },
267  _fw_version,
268  this );
269 
271 
272  if( _fw_version >= firmware_version( "1.5.2.0" ) )
273  {
274  _alt_ir = std::make_shared< l500_hw_options >( this,
275  _hw_monitor.get(),
276  alternate_ir,
277  resolution_option.get(),
278  "Enable/Disable alternate IR",
279  _fw_version,
280  _digital_gain );
281 
282  depth_sensor.register_option( RS2_OPTION_ALTERNATE_IR, _alt_ir );
283  }
284 
287  l500_device *,
288  hw_monitor *,
289  l500_control,
290  option *,
291  std::string >(
293  this,
294  _hw_monitor.get(),
296  resolution_option.get(),
297  "Changes the amount of sharpening in the post-processed image",
298  _fw_version,
299  _digital_gain );
300 
302  = register_option< l500_hw_options,
303  l500_device *,
304  hw_monitor *,
305  l500_control,
306  option *,
307  std::string >(
309  this,
310  _hw_monitor.get(),
312  resolution_option.get(),
313  "Changes the amount of sharpening in the pre-processed image",
314  _fw_version,
315  _digital_gain );
316 
317  _hw_options[RS2_OPTION_NOISE_FILTERING]
318  = register_option< l500_hw_options,
319  l500_device *,
320  hw_monitor *,
321  l500_control,
322  option *,
324  this,
325  _hw_monitor.get(),
327  resolution_option.get(),
328  "Control edges and background noise",
329  _fw_version,
330  _digital_gain );
331 
332  _hw_options[RS2_OPTION_AVALANCHE_PHOTO_DIODE] = register_option< l500_hw_options,
333  l500_device *,
334  hw_monitor *,
335  l500_control,
336  option *,
337  std::string >(
339  this,
340  _hw_monitor.get(),
341  apd,
342  resolution_option.get(),
343  "Changes the exposure time of Avalanche Photo Diode in the receiver",
344  _fw_version,
345  _digital_gain );
346 
347  _hw_options[RS2_OPTION_CONFIDENCE_THRESHOLD] = register_option< l500_hw_options,
348  l500_device *,
349  hw_monitor *,
350  l500_control,
351  option *,
352  std::string >(
354  this,
355  _hw_monitor.get(),
356  confidence,
357  resolution_option.get(),
358  "The confidence level threshold to use to mark a "
359  "pixel as valid by the depth algorithm",
360  _fw_version,
361  _digital_gain );
362 
363  _hw_options[RS2_OPTION_LASER_POWER] = register_option< l500_hw_options,
364  l500_device *,
365  hw_monitor *,
366  l500_control,
367  option *,
368  std::string >(
370  this,
371  _hw_monitor.get(),
372  laser_gain,
373  resolution_option.get(),
374  "Power of the laser emitter, with 0 meaning projector off",
375  _fw_version,
376  _digital_gain );
377 
378  _hw_options[RS2_OPTION_MIN_DISTANCE]
379  = register_option< l500_hw_options,
380  l500_device *,
381  hw_monitor *,
382  l500_control,
383  option *,
385  this,
386  _hw_monitor.get(),
387  min_distance,
388  resolution_option.get(),
389  "Minimal distance to the target (in mm)",
390  _fw_version,
391  _digital_gain );
392 
393  _hw_options[RS2_OPTION_INVALIDATION_BYPASS]
394  = register_option< l500_hw_options,
395  l500_device *,
396  hw_monitor *,
397  l500_control,
398  option *,
400  this,
401  _hw_monitor.get(),
403  resolution_option.get(),
404  "Enable/disable pixel invalidation",
405  _fw_version,
406  _digital_gain );
407 
409 
410  _preset = std::make_shared< l500_preset_option >(
413  1,
415  "Preset to calibrate the camera to environment ambient, no ambient or low "
416  "ambient.",
417  this );
418 
419  _preset->set_value( (float)preset );
420 
421  depth_sensor.register_option( RS2_OPTION_VISUAL_PRESET, _preset );
422 
424  }
425  } );
426  }
427 
428  std::vector<rs2_option> l500_options::get_advanced_controls()
429  {
430  std::vector<rs2_option> res;
431 
432  res.push_back(RS2_OPTION_DIGITAL_GAIN);
433  for (auto&& o : _hw_options)
434  res.push_back(o.first);
435 
436  return res;
437  }
438 
440  {
441  try
442  {
443  // compare default values to current values except for laser power,
444  // if we are on preset, we expect that all control's currents values will
445  // be aqual to control's default values according to current digital gain value,
446  // only laser power can have diffrant value according to preset
447  // laser power value will be check later
448  for( auto control : _hw_options )
449  {
450  if( control.first != RS2_OPTION_LASER_POWER && !control.second->is_read_only() )
451  {
452  auto curr = control.second->query();
453  auto def = control.second->get_range().def;
454  if( def != curr )
456  }
457  }
458 
459  // all the hw_options values are equal to their default values
460  // now what is left to check if the gain and laser power correspond to one of the
461  // presets
462 
463  auto laser = _hw_options.find(RS2_OPTION_LASER_POWER);
464  if (laser == _hw_options.end())
465  {
466  LOG_ERROR("RS2_OPTION_LASER_POWER didnt found on hw_options list ");
468  }
469  auto max_laser = laser->second->get_range().max;
470  auto def_laser = laser->second->get_range().def;
471 
472  std::map< std::pair< rs2_digital_gain, float >, rs2_l500_visual_preset >
473  gain_and_laser_to_preset = {
478  };
479 
480  auto gain = ( rs2_digital_gain )(int)_digital_gain->query();
481  auto laser_val = laser->second->query();
482 
483  auto it = gain_and_laser_to_preset.find( { gain, laser_val } );
484 
485  if( it != gain_and_laser_to_preset.end() )
486  {
487  return it->second;
488  }
489 
491  }
492  catch( ... )
493  {
494  LOG_ERROR( "Exception caught in calc_preset_from_controls" );
495  }
497  }
498 
501  _owner( owner )
502  {}
503 
505  {
506  if( static_cast< rs2_l500_visual_preset >( int( value ) )
509  << "RS2_L500_VISUAL_PRESET_DEFAULT was deprecated!" );
510 
512  _owner->change_preset( static_cast< rs2_l500_visual_preset >( int( value ) ) );
513 
515  }
516 
518  {
520  }
521 
523  {
524  // Block changing visual preset while Max Usable Range is on [RS5-8358]
527  == 1.0f ) )
528  {
529  if( ( RS2_OPTION_VISUAL_PRESET == opt )
530  && ( value == RS2_L500_VISUAL_PRESET_MAX_RANGE ) )
531  return;
532 
534  to_string()
535  << "Visual Preset cannot be changed while Max Usable Range is enabled" );
536  }
537  }
538 
540  {
541  auto advanced_controls = get_advanced_controls();
542  if( std::find( advanced_controls.begin(), advanced_controls.end(), opt )
543  != advanced_controls.end() )
544  {
545  // when we moved to auto preset we set all controls to -1
546  // so we have to set preset controls to defaults values now
547  /*auto curr_preset = ( rs2_l500_visual_preset )(int)_preset->query();
548  if( curr_preset == RS2_L500_VISUAL_PRESET_AUTOMATIC )
549  set_preset_controls_to_defaults();*/
550 
551  move_to_custom();
552  _hw_options[opt]->set_manually( true );
553  }
554  else
556  to_string() << "on_set_option support advanced controls only " << opt
557  << " injected" );
558  }
559 
561  {
562  switch( preset )
563  {
566  _digital_gain->set_by_preset( RS2_DIGITAL_GAIN_HIGH );
567  break;
570  _digital_gain->set_by_preset( RS2_DIGITAL_GAIN_LOW );
571  break;
573  _digital_gain->set_by_preset( RS2_DIGITAL_GAIN_AUTO );
574  break;
575  };
576  }
577 
579  {
580  auto curr_preset = ( rs2_l500_visual_preset )(int)_preset->query();
581 
582  if( preset == RS2_L500_VISUAL_PRESET_AUTOMATIC )
583  _alt_ir->set( 1 );
584  else if( curr_preset == RS2_L500_VISUAL_PRESET_AUTOMATIC
585  && preset != RS2_L500_VISUAL_PRESET_CUSTOM )
586  _alt_ir->set( 0 );
587  }
588 
590  {
592  || preset == RS2_L500_VISUAL_PRESET_MAX_RANGE )
593  set_max_laser();
594  }
595 
597  {
598  // Keep the USB power on while triggering multiple calls on it.
599  ivcam2::group_multiple_fw_calls( get_depth_sensor(), [&]() {
600  // we need to reset the controls before change gain because after moving to auto gain
601  // APD is read only. This will tell the FW that the control values are defaults and
602  // therefore can be overridden automatically according to gain
603  if( preset == RS2_L500_VISUAL_PRESET_AUTOMATIC )
604  {
605  auto curr_preset = ( rs2_l500_visual_preset )(int)_preset->query();
606  if( curr_preset == RS2_L500_VISUAL_PRESET_AUTOMATIC )
607  return;
609  }
610 
611  // if the user set preset custom we should not change the controls default or current
612  // values the values should stay the same
613  if( preset == RS2_L500_VISUAL_PRESET_CUSTOM )
614  {
615  move_to_custom();
616  return;
617  }
618 
619  // digital gain must be the first option that is set because it
620  // impacts the default values of some of the hw controls
621  change_gain( preset );
622  change_alt_ir( preset );
623 
624  if( preset != RS2_L500_VISUAL_PRESET_AUTOMATIC )
625  set_preset_controls_to_defaults();
626 
627  change_laser_power( preset );
628  } );
629  }
630 
632  {
633  _preset->set_value( (float)preset );
634  }
635 
637  {
638  for( auto & o : _hw_options )
639  {
640  if( ! o.second->is_read_only() )
641  {
642  auto val = o.second->get_range().def;
643  o.second->set_with_no_signal( val );
644  o.second->set_manually( false );
645  }
646  }
647  }
648 
650  {
651  _preset->set_value( RS2_L500_VISUAL_PRESET_CUSTOM );
652  }
653 
655  {
656  // Keep the USB power on while triggering multiple calls on it.
657  ivcam2::group_multiple_fw_calls( get_depth_sensor(), [&]() {
658  for (auto& o : _hw_options)
659  if (!o.second->is_read_only())
660  {
661  o.second->set_with_no_signal(-1);
662  }
663  });
664  }
665 
667  {
668  auto range = _hw_options[RS2_OPTION_LASER_POWER]->get_range();
669  _hw_options[RS2_OPTION_LASER_POWER]->set_with_no_signal(range.max);
670  }
671 
672  // this method not uses l500_hw_options::query_default() because
673  // we want to save the 50ms sleep on streaming and do it once to all the controlls
675  {
676  // Keep the USB power on while triggering multiple calls on it.
677  ivcam2::group_multiple_fw_calls( get_depth_sensor(), [&]() {
678 
679  auto& resolution = get_depth_sensor().get_option(RS2_OPTION_SENSOR_MODE);
680 
681  std::map< rs2_option, float > defaults;
682  if (_fw_version >= firmware_version(MIN_GET_DEFAULT_FW_VERSION))
683  {
684  for (auto opt : _hw_options)
685  {
686  bool success;
687  defaults[opt.first] = opt.second->query_new_fw_default(success);
688 
689  if (!success)
690  {
691  defaults[opt.first] = -1;
692  opt.second->set_read_only(true);
693  }
694  else
695  opt.second->set_read_only(false);
696  }
697  }
698  else
699  {
700  // For older FW without support for get_default, we have to:
701  // 1. Save the current value
702  // 2. Wait for the next frame (if streaming)
703  // 3. Change to -1
704  // 4. Read the current value and store as default value
705  // 5. Restore the current value
706  std::map< rs2_option, float > currents;
707  for (auto opt : _hw_options)
708  currents[opt.first] = opt.second->query_current(query_sensor_mode(resolution));
709 
710  // if the sensor is streaming the value of control will update only when the next frame
711  // arrive
712  if (get_depth_sensor().is_streaming())
713  std::this_thread::sleep_for(std::chrono::milliseconds(50));
714 
715  for (auto opt : _hw_options)
716  {
717  opt.second->set_with_no_signal(-1);
718  defaults[opt.first] = opt.second->query_current(query_sensor_mode(resolution));
719  }
720 
721  for (auto opt : currents)
722  {
723  _hw_options[opt.first]->set_with_no_signal(opt.second);
724  }
725  }
726 
727  for (auto opt : _hw_options)
728  {
729  opt.second->set_default(defaults[opt.first]);
730  }
731  });
732  }
733 
735  {
736  // Restrictions for Max Usable Range option as required on [RS5-8358]
737  auto& ds = _l500_depth_dev->get_depth_sensor();
738  if (value == 1.0f)
739  {
740  auto &sensor_mode_option = ds.get_option(RS2_OPTION_SENSOR_MODE);
741  auto sensor_mode = sensor_mode_option.query();
742  bool sensor_mode_is_vga = (sensor_mode == rs2_sensor_mode::RS2_SENSOR_MODE_VGA);
743 
744  bool visual_preset_is_max_range = ds.is_max_range_preset();
745 
746  if (ds.is_streaming())
747  {
748  if (!sensor_mode_is_vga || !visual_preset_is_max_range)
749  throw wrong_api_call_sequence_exception("Please set 'VGA' resolution and 'Max Range' preset before enabling Max Usable Range");
750  }
751  else
752  {
753  if (!visual_preset_is_max_range)
754  {
755  auto &visual_preset_option = ds.get_option(RS2_OPTION_VISUAL_PRESET);
757  LOG_INFO("Visual Preset was changed to: " << visual_preset_option.get_value_description(rs2_l500_visual_preset::RS2_L500_VISUAL_PRESET_MAX_RANGE));
758  }
759 
760  if (!sensor_mode_is_vga)
761  {
764  }
765  }
766  }
767  else
768  {
769  if (ds.supports_option(RS2_OPTION_ENABLE_IR_REFLECTIVITY) && ds.get_option(RS2_OPTION_ENABLE_IR_REFLECTIVITY).query() == 1.0f)
770  {
771  ds.get_option(RS2_OPTION_ENABLE_IR_REFLECTIVITY).set(0.0f);
772  LOG_INFO("IR Reflectivity was on - turning it off");
773  }
774  }
775 
776  bool_option::set(value);
777  }
778 
780  {
781  if (_value == value) return;
782 
783  // Restrictions for sensor mode option as required on [RS5-8358]
784  auto &ds = _l500_depth_dev->get_depth_sensor();
785 
786  if( ds.supports_option( RS2_OPTION_ENABLE_IR_REFLECTIVITY )
787  && ds.get_option( RS2_OPTION_ENABLE_IR_REFLECTIVITY ).query() == 1.0f
788  && ( value != rs2_sensor_mode::RS2_SENSOR_MODE_VGA ) )
789  {
790  ds.get_option( RS2_OPTION_ENABLE_IR_REFLECTIVITY ).set( 0.0f );
791  LOG_INFO( "IR Reflectivity was on - turning it off" );
792  }
793 
794  if( ds.supports_option( RS2_OPTION_ENABLE_MAX_USABLE_RANGE )
795  && ( ds.get_option( RS2_OPTION_ENABLE_MAX_USABLE_RANGE ).query() == 1.0f )
796  && ( value != rs2_sensor_mode::RS2_SENSOR_MODE_VGA ) )
797  {
798  ds.get_option( RS2_OPTION_ENABLE_MAX_USABLE_RANGE ).set( 0.0f );
799  LOG_INFO( "Max Usable Range was on - turning it off" );
800  }
801 
803 
804  // Keep the USB power on while triggering multiple calls on it.
805  ivcam2::group_multiple_fw_calls( ds, [&]() { notify( value ); } );
806  }
807 
809  {
810 
811  return "Max Usable Range calculates the maximum range of the camera given the amount of "
812  "ambient light in the scene.\n"
813  "For example, if Max Usable Range returns 5m, this means that the ambient light in "
814  "the scene is reducing the maximum range from 9m down to 5m.\n"
815  "Values are between 1.5 and 9 meters, in 1.5m increments. "
816  "Max range refers to the center 10% of the frame.";
817  }
818 
820  {
821  // Restrictions for IR Reflectivity option as required on [RS5-8358]
822  auto &ds = _l500_depth_dev->get_depth_sensor();
823  if (value == 1.0f)
824  {
825  // Verify option Alternate IR is off
826  if( ds.supports_option( RS2_OPTION_ALTERNATE_IR )
827  && ds.get_option( RS2_OPTION_ALTERNATE_IR ).query() == 1.0f )
828  {
829  throw wrong_api_call_sequence_exception("Cannot enable IR Reflectivity when Alternate IR option is on");
830  }
831 
832  auto &sensor_mode_option = ds.get_option(RS2_OPTION_SENSOR_MODE);
833  auto sensor_mode = sensor_mode_option.query();
834  bool sensor_mode_is_vga = (sensor_mode == rs2_sensor_mode::RS2_SENSOR_MODE_VGA);
835 
836  bool visual_preset_is_max_range = ds.is_max_range_preset();
837 
838  if( ds.is_streaming() )
839  {
840  // While streaming we use active stream resolution and not sensor mode due as a
841  // patch for the DQT sensor mode wrong handling.
842  // This should be changed for using sensor mode after DQT fix
843  auto active_streams = ds.get_active_streams();
844  auto dp = std::find_if( active_streams.begin(),
845  active_streams.end(),
846  []( std::shared_ptr< stream_profile_interface > sp ) {
847  return sp->get_stream_type() == RS2_STREAM_DEPTH;
848  } );
849 
850  bool vga_sensor_mode = false;
851  if( dp != active_streams.end() )
852  {
853  auto vs = dynamic_cast< video_stream_profile * >( ( *dp ).get() );
854  vga_sensor_mode
855  = ( get_resolution_from_width_height( vs->get_width(), vs->get_height() )
856  == RS2_SENSOR_MODE_VGA );
857  }
858 
859  if( ( ! vga_sensor_mode ) || ! visual_preset_is_max_range )
861  "Please set 'VGA' resolution, 'Max Range' preset and 20% ROI before enabling IR Reflectivity" );
862  }
863  else
864  {
865  if (!visual_preset_is_max_range)
866  {
867  auto &visual_preset_option = ds.get_option(RS2_OPTION_VISUAL_PRESET);
869  LOG_INFO("Visual Preset was changed to: " << visual_preset_option.get_value_description(rs2_l500_visual_preset::RS2_L500_VISUAL_PRESET_MAX_RANGE));
870  }
871 
872  if (!sensor_mode_is_vga)
873  {
876  }
877  }
878 
880  if (max_usable_range_option.query() != 1.0f)
881  {
882  max_usable_range_option.set(1.0f);
883  _max_usable_range_forced_on = true;
884  LOG_INFO("Max Usable Range was off - turning it on");
885  }
886  }
887  else
888  {
889  if (_max_usable_range_forced_on)
890  {
891  _max_usable_range_forced_on = false;
892  bool_option::set( value ); // We set the value here to prevent a loop between Max Usable Range &
893  // Reflectivity options trying to turn off each other
894 
895  ds.get_option(RS2_OPTION_ENABLE_MAX_USABLE_RANGE).set(0.0f);
896  LOG_INFO("Max Usable Range was on - turning it off");
897  return;
898  }
899  }
900 
901  bool_option::set(value);
902  }
903 
905  {
906 
907  return "IR Reflectivity Tool calculates the percentage of IR light reflected by the "
908  "object and returns to the camera for processing.\nFor example, a value of 60% means "
909  "that 60% of the IR light projected by the camera is reflected by the object and returns "
910  "to the camera.\n\n"
911  "Note: only active on 2D view, Visual Preset:Max Range, Resolution:VGA, ROI:20%";
912  }
913 
915  {
916  super::set( value );
918 
919  // when we moved to auto preset we set all controls to -1
920  // so we have to set preset controls to defaults values now
921  /*auto curr_preset = ( rs2_l500_visual_preset )(int)_preset->query();
922  if( curr_preset == RS2_L500_VISUAL_PRESET_AUTOMATIC )
923  set_preset_controls_to_defaults();*/
924 
926  }
927 
928  // set gain as result of change preset
930  {
931  work_around_for_old_fw();
932 
933  super::set( value );
935  }
936 
937  // FW expose 'auto gain' with value 0 as one of the values of gain option in addition
938  // to 'low gain' and 'high gain'
939  // for now we don't want to expose it to user so the range starts from 1
940  // once we want to expose it we will remove this override method
942  {
944  range.min = 1;
945  return range;
946  }
947 
949  {
950  // On old FW versions the way to get the default values of the hw commands is to
951  // reset hw commands current values -1 and than get the current values
952  // on some of the old FW versions there is a bug that we must reset hw commands
953  // before setting the digital gain, otherwise its not updates the current with default
954  // values in digital_gain_option class we override the set_with_no_signal that called when
955  // changing preset and reset hw commands before setting the digital gain as WA to this bug
956  // we still have a limit on the scenario that user change digital gain manually (not from
957  // preset) we won't get the correct default values
958  if( _fw_version < firmware_version( MIN_GET_DEFAULT_FW_VERSION ) )
959  _owner->reset_hw_controls(); // should be before gain changing as WA for old FW versions
960  }
961 } // namespace librealsense
rs2_sensor_mode get_resolution_from_width_height(int width, int height)
std::shared_ptr< hw_monitor > _hw_monitor
Definition: l500-device.h:91
void set(float value) override
const char * get_value_description(float val) const override
Definition: option.h:107
const std::string MIN_GET_DEFAULT_FW_VERSION("1.5.4.0")
void set(float value) override
Definition: option.cpp:35
rs2_option
Defines general configuration controls. These can generally be mapped to camera UVC controls...
Definition: rs_option.h:22
GLdouble s
option_range get_range() const override
Definition: option.h:357
rs2_l500_visual_preset calc_preset_from_controls() const
float query_current(rs2_sensor_mode mode) const
l500_options(std::shared_ptr< context > ctx, const platform::backend_device_group &group)
l500_hw_options(l500_device *l500_dev, hw_monitor *hw_monitor, l500_control type, option *resolution, const std::string &description, firmware_version fw_version, std::shared_ptr< digital_gain_option > digital_gain)
void set(float value) override
option_range get_range() const override
void change_gain(rs2_l500_visual_preset preset)
GLfloat value
void set_preset_value(rs2_l500_visual_preset preset)
const uint8_t L500_DIGITAL_GAIN
Definition: l500-private.h:31
void change_preset(rs2_l500_visual_preset preset)
l500_preset_option(option_range range, std::string description, l500_options *owner)
void change_alt_ir(rs2_l500_visual_preset preset)
std::vector< rs2_option > _advanced_options
Definition: l500-device.h:111
bool supports_option(rs2_option id) const override
Definition: options.h:51
GLsizei const GLchar *const * string
platform::usb_spec _usb_mode
Definition: l500-device.h:114
option & get_option(rs2_option id) override
Definition: options.h:58
virtual float query() const =0
GLuint GLfloat * val
std::vector< rs2_option > get_advanced_controls()
void set(float value) override
Definition: option.h:332
GLdouble f
firmware_version _fw_version
Definition: l500-device.h:97
GLenum mode
void set(float value) override
void set(float value) override
const std::string MIN_CONTROLS_FW_VERSION("1.3.9.0")
void verify_max_usable_range_restrictions(rs2_option opt, float value)
std::vector< uint8_t > send(std::vector< uint8_t > const &data) const
Definition: hw-monitor.cpp:115
unsigned int uint32_t
Definition: stdint.h:80
float query() const override
GLboolean GLuint group
Definition: glext.h:5688
void set(float value) override
rs2_sensor_mode query_sensor_mode(option &resolution)
l500_depth_sensor & get_depth_sensor()
float query_new_fw_default(bool &success) const
std::shared_ptr< cascade_option< T > > register_option(rs2_option opt, Args...args)
Definition: l500-options.h:198
def find(dir, mask)
Definition: file.py:25
float query_default(bool &success) const
uvc_sensor & get_raw_depth_sensor()
Definition: l500-device.h:46
#define LOG_ERROR(...)
Definition: src/types.h:242
float query() const override
Definition: option.h:238
void reset_hw_controls(rs2::device &dev)
bool is_streaming() const override
Definition: sensor.cpp:1619
void set_read_only(bool read_only)
rs2_sensor_mode
For setting the camera_mode option.
Definition: rs_option.h:165
std::shared_ptr< l500_hw_options > _alt_ir
Definition: l500-options.h:194
LOG_INFO("Log message using LOG_INFO()")
std::shared_ptr< digital_gain_option > _digital_gain
Definition: l500-options.h:193
void set(float value) override
void on_set_option(rs2_option opt, float value)
static auto it
GLenum type
int min(int a, int b)
Definition: lz4s.c:73
std::map< rs2_option, std::shared_ptr< cascade_option< l500_hw_options > > > _hw_options
Definition: l500-options.h:192
rs2_digital_gain
digital gain for RS2_OPTION_DIGITAL_GAIN option.
Definition: rs_option.h:183
const char * get_description() const override
GLsizei range
auto group_multiple_fw_calls(synthetic_sensor &s, T action) -> decltype(action())
Definition: l500-private.h:615
GLuint res
Definition: glext.h:8856
const char * get_description() const override
void enable_recording(std::function< void(const option &)> recording_action) override
const platform::extension_unit depth_xu
Definition: l500-private.h:43
signed int int32_t
Definition: stdint.h:77
std::shared_ptr< l500_preset_option > _preset
Definition: l500-options.h:195
option_range get_range() const override
void change_laser_power(rs2_l500_visual_preset preset)
std::string to_string(T value)
rs2_l500_visual_preset
For L500 devices: provides optimized settings (presets) for specific types of usage.
Definition: rs_option.h:151


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