option.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 #include "option.h"
4 #include "sensor.h"
5 
7 {
8  if (!std::isnormal(_opt_range.step) && _opt_range.step != 0)
9  throw invalid_value_exception(to_string() << "is_valid(...) failed! step is not properly defined. (" << _opt_range.step << ")");
10 
11  if ((value < _opt_range.min) || (value > _opt_range.max))
12  return false;
13 
14  if (_opt_range.step == 0)
15  return true;
16 
17  auto n = (value - _opt_range.min) / _opt_range.step;
18  return (fabs(fmod(n, 1)) < std::numeric_limits<float>::min());
19 }
20 
22 {
23  return _opt_range;
24 }
25 void librealsense::option_base::enable_recording(std::function<void(const option&)> recording_action)
26 {
27  _recording_function = recording_action;
28 }
29 
30 void librealsense::option::create_snapshot(std::shared_ptr<option>& snapshot) const
31 {
32  snapshot = std::make_shared<const_value_option>(get_description(), query());
33 }
34 
36 {
37  if (!is_valid(value))
38  throw invalid_value_exception(to_string() << "set(...) failed! " << value << " is not a valid value");
39  _value = value;
40 }
41 
43 {
44  _ep.invoke_powered(
45  [this, value](platform::uvc_device& dev)
46  {
47  if (!dev.set_pu(_id, static_cast<int32_t>(value)))
48  throw invalid_value_exception(to_string() << "set_pu(id=" << std::to_string(_id) << ") failed!" << " Last Error: " << strerror(errno));
49  _record(*this);
50  });
51 }
52 
54 {
55  return static_cast<float>(_ep.invoke_powered(
56  [this](platform::uvc_device& dev)
57  {
58  int32_t value = 0;
59  if (!dev.get_pu(_id, value))
60  throw invalid_value_exception(to_string() << "get_pu(id=" << std::to_string(_id) << ") failed!" << " Last Error: " << strerror(errno));
61 
62  return static_cast<float>(value);
63  }));
64 }
65 
67 {
68  auto uvc_range = _ep.invoke_powered(
69  [this](platform::uvc_device& dev)
70  {
71  return dev.get_pu_range(_id);
72  });
73 
74  if (uvc_range.min.size() < sizeof(int32_t)) return option_range{0,0,1,0};
75 
76  auto min = *(reinterpret_cast<int32_t*>(uvc_range.min.data()));
77  auto max = *(reinterpret_cast<int32_t*>(uvc_range.max.data()));
78  auto step = *(reinterpret_cast<int32_t*>(uvc_range.step.data()));
79  auto def = *(reinterpret_cast<int32_t*>(uvc_range.def.data()));
80  return option_range{static_cast<float>(min),
81  static_cast<float>(max),
82  static_cast<float>(step),
83  static_cast<float>(def)};
84 }
85 
87 {
88  switch(_id)
89  {
90  case RS2_OPTION_BACKLIGHT_COMPENSATION: return "Enable / disable backlight compensation";
91  case RS2_OPTION_BRIGHTNESS: return "UVC image brightness";
92  case RS2_OPTION_CONTRAST: return "UVC image contrast";
93  case RS2_OPTION_EXPOSURE: return "Controls exposure time of color camera. Setting any value will disable auto exposure";
94  case RS2_OPTION_GAIN: return "UVC image gain";
95  case RS2_OPTION_GAMMA: return "UVC image gamma setting";
96  case RS2_OPTION_HUE: return "UVC image hue";
97  case RS2_OPTION_SATURATION: return "UVC image saturation setting";
98  case RS2_OPTION_SHARPNESS: return "UVC image sharpness setting";
99  case RS2_OPTION_WHITE_BALANCE: return "Controls white balance of color image. Setting any value will disable auto white balance";
100  case RS2_OPTION_ENABLE_AUTO_EXPOSURE: return "Enable / disable auto-exposure";
101  case RS2_OPTION_ENABLE_AUTO_WHITE_BALANCE: return "Enable / disable auto-white-balance";
102  case RS2_OPTION_POWER_LINE_FREQUENCY: return "Power Line Frequency";
103  case RS2_OPTION_AUTO_EXPOSURE_PRIORITY: return "Restrict Auto-Exposure to enforce constant FPS rate. Turn ON to remove the restrictions (may result in FPS drop)";
104  default: return _ep.get_option_name(_id);
105  }
106 }
107 
108 std::vector<uint8_t> librealsense::command_transfer_over_xu::send_receive(const std::vector<uint8_t>& data, int, bool require_response)
109 {
110  return _uvc.invoke_powered([this, &data, require_response]
112  {
113  std::vector<uint8_t> result;
114  std::lock_guard<platform::uvc_device> lock(dev);
115 
116  if (data.size() > HW_MONITOR_BUFFER_SIZE)
117  {
118  LOG_ERROR("XU command size is invalid");
119  throw invalid_value_exception(to_string() << "Requested XU command size " <<
120  std::dec << data.size() << " exceeds permitted limit " << HW_MONITOR_BUFFER_SIZE);
121  }
122 
123  std::vector<uint8_t> transmit_buf(HW_MONITOR_BUFFER_SIZE, 0);
124  std::copy(data.begin(), data.end(), transmit_buf.begin());
125 
126  if (!dev.set_xu(_xu, _ctrl, transmit_buf.data(), static_cast<int>(transmit_buf.size())))
127  throw invalid_value_exception(to_string() << "set_xu(ctrl=" << unsigned(_ctrl) << ") failed!" << " Last Error: " << strerror(errno));
128 
129  if (require_response)
130  {
131  result.resize(HW_MONITOR_BUFFER_SIZE);
132  if (!dev.get_xu(_xu, _ctrl, result.data(), static_cast<int>(result.size())))
133  throw invalid_value_exception(to_string() << "get_xu(ctrl=" << unsigned(_ctrl) << ") failed!" << " Last Error: " << strerror(errno));
134 
135  // Returned data size located in the last 4 bytes
136  auto data_size = *(reinterpret_cast<uint32_t*>(result.data() + HW_MONITOR_DATA_SIZE_OFFSET)) + SIZE_OF_HW_MONITOR_HEADER;
137  result.resize(data_size);
138  }
139  return result;
140  });
141 }
142 
144 {
145  if (auto handler = _polling_error_handler.lock())
146  handler->stop();
147 }
148 
150 {
151  if( value < 0 )
152  throw invalid_value_exception("invalid polling errors value " + std::to_string(value));
153 
154  if( auto handler = _polling_error_handler.lock() )
155  {
156  _value = value;
157  if( value <= std::numeric_limits< float >::epsilon() )
158  handler->stop();
159  else
160  handler->start(( unsigned int )( value * 1000.f ));
161  }
162  _recording_function(*this);
163 }
164 
166 {
167  return _value;
168 }
169 
171 {
172  return option_range{0, 1, 1, 0};
173 }
174 
176 {
177  return true;
178 }
179 
181 {
182  return "Enable / disable polling of camera internal errors";
183 }
184 
186 {
187  if (value == 0)
188  {
189  return "Disable error polling";
190  }
191  else
192  {
193  return "Enable error polling";
194  }
195 }
196 
198 {
199  std::vector<rs2_option> options;
200  for (auto option : _options)
201  options.push_back(option.first);
202 
203  return options;
204 }
bool is_enabled() const override
Definition: option.cpp:175
static const textual_icon lock
Definition: model-views.h:218
const option_range _opt_range
Definition: option.h:99
virtual const char * get_description() const =0
void set(float value) override
Definition: option.cpp:35
option_range get_range() const override
Definition: option.cpp:21
const uint16_t HW_MONITOR_DATA_SIZE_OFFSET
Definition: hw-monitor.h:42
float query() const override
Definition: option.cpp:53
option_range get_range() const override
Definition: option.cpp:170
float query() const override
Definition: option.cpp:165
virtual control_range get_pu_range(rs2_option opt) const =0
GLfloat value
virtual void create_snapshot(std::shared_ptr< option > &snapshot) const
Definition: option.cpp:30
void set(float value) override
Definition: option.cpp:42
GLdouble n
Definition: glext.h:1966
virtual void enable_recording(std::function< void(const option &)> recording_action) override
Definition: option.cpp:25
virtual float query() const =0
virtual bool set_pu(rs2_option opt, int32_t value)=0
std::vector< rs2_option > get_supported_options() const override
Definition: option.cpp:197
virtual bool get_xu(const extension_unit &xu, uint8_t ctrl, uint8_t *data, int len) const =0
void set(float value) override
Definition: option.cpp:149
const char * get_description() const override
Definition: option.cpp:86
GLdouble f
option_range get_range() const override
Definition: option.cpp:66
unsigned int uint32_t
Definition: stdint.h:80
virtual bool get_pu(rs2_option opt, int32_t &value) const =0
#define LOG_ERROR(...)
Definition: src/types.h:242
std::function< void(const option &)> _recording_function
Definition: option.h:100
const char * get_value_description(float value) const override
Definition: option.cpp:185
std::vector< uint8_t > send_receive(const std::vector< uint8_t > &data, int, bool require_response) override
Definition: option.cpp:108
int min(int a, int b)
Definition: lz4s.c:73
virtual bool set_xu(const extension_unit &xu, uint8_t ctrl, const uint8_t *data, int len)=0
const uint16_t SIZE_OF_HW_MONITOR_HEADER
Definition: hw-monitor.h:43
signed int int32_t
Definition: stdint.h:77
const uint16_t HW_MONITOR_BUFFER_SIZE
Definition: hw-monitor.h:41
bool is_valid(float value) const
Definition: option.cpp:6
GLuint64EXT * result
Definition: glext.h:10921
const char * get_description() const override
Definition: option.cpp:180
Definition: parser.hpp:150
void copy(void *dst, void const *src, size_t size)
Definition: types.cpp:836
std::string to_string(T value)


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