Skip to content

Commit

Permalink
101?
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrauch committed May 25, 2024
1 parent 17f26ba commit 3b7cc6f
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 100
ColumnLimit: 101
CompactNamespaces: false
ContinuationIndentWidth: 2
IndentCaseLabels: false
Expand Down
3 changes: 1 addition & 2 deletions src/CameraNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,7 @@ CameraNode::declareParameters()
throw std::runtime_error("minimum and maximum parameter array sizes do not match");

// clamp default ControlValue to min/max range and cast ParameterValue
const rclcpp::ParameterValue value =
cv_to_pv(clamp(info.def(), info.min(), info.max()), extent);
const rclcpp::ParameterValue value = cv_to_pv(clamp(info.def(), info.min(), info.max()), extent);

// get smallest bounds for minimum and maximum set
rcl_interfaces::msg::IntegerRange range_int;
Expand Down
27 changes: 13 additions & 14 deletions src/clamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
#include <vector>


#define CASE_CLAMP(T) \
case libcamera::ControlType##T: \
#define CASE_CLAMP(T) \
case libcamera::ControlType##T: \
return clamp<ControlTypeMap<libcamera::ControlType##T>::type>(value, min, max);

#define CASE_NONE(T) \
case libcamera::ControlType##T: \
#define CASE_NONE(T) \
case libcamera::ControlType##T: \
return {};

#define MIN(T) \
template ControlTypeMap<libcamera::ControlType##T>::type min<libcamera::ControlType##T>( \
#define MIN(T) \
template ControlTypeMap<libcamera::ControlType##T>::type min<libcamera::ControlType##T>( \
const libcamera::ControlValue &);

#define MAX(T) \
template ControlTypeMap<libcamera::ControlType##T>::type max<libcamera::ControlType##T>( \
#define MAX(T) \
template ControlTypeMap<libcamera::ControlType##T>::type max<libcamera::ControlType##T>( \
const libcamera::ControlValue &);

template<enum libcamera::ControlType T>
Expand Down Expand Up @@ -109,8 +109,7 @@ clamp(const libcamera::ControlValue &value, const libcamera::ControlValue &min,
: std::clamp(value.get<T>(), min.get<T>(), max.get<T>());
}

template<typename T,
std::enable_if_t<std::is_same<std::remove_cv_t<T>, CTBool>::value, bool> = true>
template<typename T, std::enable_if_t<std::is_same<std::remove_cv_t<T>, CTBool>::value, bool> = true>
const libcamera::ControlValue &
clamp(const libcamera::ControlValue &value, const libcamera::ControlValue & /*min*/,
const libcamera::ControlValue & /*max*/)
Expand Down Expand Up @@ -218,12 +217,12 @@ greater(const libcamera::ControlValue &lhs, const libcamera::ControlValue &rhs)
}
}

#define CASE_LESS(T) \
case libcamera::ControlType##T: \
#define CASE_LESS(T) \
case libcamera::ControlType##T: \
return less<ControlTypeMap<libcamera::ControlType##T>::type>(lhs, rhs);

#define CASE_GREATER(T) \
case libcamera::ControlType##T: \
#define CASE_GREATER(T) \
case libcamera::ControlType##T: \
return greater<ControlTypeMap<libcamera::ControlType##T>::type>(lhs, rhs);

bool
Expand Down
23 changes: 11 additions & 12 deletions src/cv_to_pv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
#include <vector>


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

#define CASE_NONE(T) \
case libcamera::ControlType##T: \
#define CASE_NONE(T) \
case libcamera::ControlType##T: \
return {};


Expand All @@ -33,9 +33,9 @@ extract_value(const libcamera::ControlValue &value)
}
}

template<typename T,
std::enable_if_t<std::is_arithmetic<T>::value || std::is_same<std::string, T>::value,
bool> = true>
template<
typename T,
std::enable_if_t<std::is_arithmetic<T>::value || std::is_same<std::string, T>::value, bool> = true>
rclcpp::ParameterValue
cv_to_pv_array(const std::vector<T> &values)
{
Expand All @@ -51,9 +51,9 @@ cv_to_pv_array(const std::vector<T> & /*values*/)
throw std::runtime_error("ParameterValue only supported for arithmetic types");
}

template<typename T,
std::enable_if_t<std::is_arithmetic<T>::value || std::is_same<std::string, T>::value,
bool> = true>
template<
typename T,
std::enable_if_t<std::is_arithmetic<T>::value || std::is_same<std::string, T>::value, bool> = true>
rclcpp::ParameterValue
cv_to_pv_scalar(const T &value)
{
Expand All @@ -79,8 +79,7 @@ cv_to_pv(const std::vector<T> &values, const std::size_t &extent)
{
if ((values.size() > 1 && extent > 1) && (values.size() != extent))
throw std::runtime_error("type extent (" + std::to_string(extent) + ") and value size (" +
std::to_string(values.size()) +
") cannot be larger than 1 and differ");
std::to_string(values.size()) + ") cannot be larger than 1 and differ");

if (values.size() > 1)
return cv_to_pv_array(values);
Expand Down
4 changes: 2 additions & 2 deletions src/pv_to_cv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pv_to_cv(const rclcpp::Parameter &parameter, const libcamera::ControlType &type)
case rclcpp::ParameterType::PARAMETER_DOUBLE_ARRAY:
{
// convert to float vector
return {libcamera::Span<const CTFloat>(std::vector<CTFloat>(
parameter.as_double_array().begin(), parameter.as_double_array().end()))};
return {libcamera::Span<const CTFloat>(
std::vector<CTFloat>(parameter.as_double_array().begin(), parameter.as_double_array().end()))};
}
case rclcpp::ParameterType::PARAMETER_STRING_ARRAY:
return {libcamera::Span<const CTString>(parameter.as_string_array())};
Expand Down
12 changes: 6 additions & 6 deletions src/type_extent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include <type_traits>


#define LIBCAMERA_VER_GE(major, minor, patch) \
((major < LIBCAMERA_VERSION_MAJOR) || \
(major == LIBCAMERA_VERSION_MAJOR && minor < LIBCAMERA_VERSION_MINOR) || \
(major == LIBCAMERA_VERSION_MAJOR && minor == LIBCAMERA_VERSION_MINOR && \
#define LIBCAMERA_VER_GE(major, minor, patch) \
((major < LIBCAMERA_VERSION_MAJOR) || \
(major == LIBCAMERA_VERSION_MAJOR && minor < LIBCAMERA_VERSION_MINOR) || \
(major == LIBCAMERA_VERSION_MAJOR && minor == LIBCAMERA_VERSION_MINOR && \
patch <= LIBCAMERA_VERSION_PATCH))


Expand All @@ -29,8 +29,8 @@ get_extent(const libcamera::Control<T> &)
return libcamera::Control<T>::type::extent;
}

#define IF(T) \
if (id->id() == libcamera::controls::T.id()) \
#define IF(T) \
if (id->id() == libcamera::controls::T.id()) \
return get_extent(libcamera::controls::T);


Expand Down
4 changes: 2 additions & 2 deletions src/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <libcamera/controls.h>


#define CASE_TYPE(T) \
case libcamera::ControlType##T: \
#define CASE_TYPE(T) \
case libcamera::ControlType##T: \
return #T;

std::string
Expand Down
12 changes: 6 additions & 6 deletions src/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#include <libcamera/geometry.h>
#include <string>

#define MAP(T, N) \
template<> \
struct ControlTypeMap<libcamera::details::control_type<T>::value> \
{ \
using type = T; \
}; \
#define MAP(T, N) \
template<> \
struct ControlTypeMap<libcamera::details::control_type<T>::value> \
{ \
using type = T; \
}; \
typedef ControlTypeMap<libcamera::ControlType##N>::type CT##N;


Expand Down

0 comments on commit 3b7cc6f

Please sign in to comment.