Skip to content

Commit

Permalink
ignore extent
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrauch committed Oct 30, 2023
1 parent 3e3c981 commit 56c9e13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/CameraNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ CameraNode::declareParameters()
// clamp default ControlValue to min/max range and cast ParameterValue
rclcpp::ParameterValue value;
try {
value = cv_to_pv(clamp(info.def(), info.min(), info.max()), extent);
value = cv_to_pv(clamp(info.def(), info.min(), info.max()));
}
catch (const invalid_conversion &e) {
RCLCPP_ERROR_STREAM(get_logger(), "unsupported control '" << id->name() << "' (type: "
Expand Down
27 changes: 10 additions & 17 deletions src/cv_to_pv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#define CASE_CONVERT(T) \
case libcamera::ControlType##T: \
return cv_to_pv(extract_value<ControlTypeMap<libcamera::ControlType##T>::type>(value), extent);
return cv_to_pv(extract_value<ControlTypeMap<libcamera::ControlType##T>::type>(value));

#define CASE_NONE(T) \
case libcamera::ControlType##T: \
Expand Down Expand Up @@ -75,28 +75,21 @@ cv_to_pv_scalar(const libcamera::Size &size)

template<typename T>
rclcpp::ParameterValue
cv_to_pv(const std::vector<T> &values, const std::size_t &extent)
cv_to_pv(const std::vector<T> &values)
{
if ((values.size() > 1 && extent > 1) && (values.size() != extent))
throw invalid_conversion("type extent (" + std::to_string(extent) + ") and value size (" +
std::to_string(values.size()) +
") cannot be larger than 1 and differ");

if (values.size() > 1)
return cv_to_pv_array(values);
if (values.size() == 0)
// empty array
return rclcpp::ParameterValue();
else if (values.size() == 1)
if (!extent)
return cv_to_pv_scalar(values[0]);
else if (extent == libcamera::dynamic_extent)
return cv_to_pv_array(std::vector<T>());
else
return cv_to_pv_array(std::vector<T>(extent, values[0]));
// scalar
return cv_to_pv_scalar(values[0]);
else
return rclcpp::ParameterValue();
// dynamic array
return cv_to_pv_array(values);
}

rclcpp::ParameterValue
cv_to_pv(const libcamera::ControlValue &value, const std::size_t &extent)
cv_to_pv(const libcamera::ControlValue &value)
{
switch (value.type()) {
CASE_NONE(None)
Expand Down
2 changes: 1 addition & 1 deletion src/cv_to_pv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class invalid_conversion : public std::runtime_error


rclcpp::ParameterValue
cv_to_pv(const libcamera::ControlValue &value, const std::size_t &extent);
cv_to_pv(const libcamera::ControlValue &value);

rclcpp::ParameterType
cv_to_pv_type(const libcamera::ControlType &type, const bool is_array);

0 comments on commit 56c9e13

Please sign in to comment.