From eb33145ac8066e73ef09b28528d8ebaf9f9f8288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Sat, 3 Mar 2018 14:45:43 +0100 Subject: [PATCH] px4_param.h: add ParamExtFloat & ParamExtInt (required by ekf2) --- src/platforms/px4_param.h | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/platforms/px4_param.h b/src/platforms/px4_param.h index ad8de90561..cf301ca5ba 100644 --- a/src/platforms/px4_param.h +++ b/src/platforms/px4_param.h @@ -139,6 +139,40 @@ private: float _val; }; +// external version +template +class Param +{ +public: + // static type-check + static_assert(px4::param_types_array[(int)p] == PARAM_TYPE_FLOAT, "parameter type must be float"); + + Param(float &external_val) + : _val(external_val) + { + param_set_used(handle()); + update(); + } + + float get() const { return _val; } + + const float &reference() const { return _val; } + + /// Store the parameter value to the parameter storage (@see param_set()) + bool commit() const { return param_set(handle(), &_val) == 0; } + + /// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification()) + bool commit_no_notification() const { return param_set_no_notification(handle(), &_val) == 0; } + + void set(float val) { _val = val; } + + bool update() { return param_get(handle(), &_val) == 0; } + + param_t handle() const { return param_handle(p); } +private: + float &_val; +}; + template class Param { @@ -171,6 +205,39 @@ private: int32_t _val; }; +//external version +template +class Param +{ +public: + // static type-check + static_assert(px4::param_types_array[(int)p] == PARAM_TYPE_INT32, "parameter type must be int32_t"); + + Param(int32_t &external_val) + : _val(external_val) + { + param_set_used(handle()); + update(); + } + + int32_t get() const { return _val; } + + const int32_t &reference() const { return _val; } + + /// Store the parameter value to the parameter storage (@see param_set()) + bool commit() const { return param_set(handle(), &_val) == 0; } + + /// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification()) + bool commit_no_notification() const { return param_set_no_notification(handle(), &_val) == 0; } + + void set(int32_t val) { _val = val; } + + bool update() { return param_get(handle(), &_val) == 0; } + + param_t handle() const { return param_handle(p); } +private: + int32_t &_val; +}; template class Param @@ -229,6 +296,12 @@ using ParamFloat = Param; template using ParamInt = Param; +template +using ParamExtFloat = Param; + +template +using ParamExtInt = Param; + template using ParamBool = Param;