Skip to content
Snippets Groups Projects
Commit b620da8f authored by Daniel Agar's avatar Daniel Agar Committed by Lorenz Meier
Browse files

BlockParam update() and commit() add returns

parent 633102e7
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@
****************************************************************************/
/**
* @file Blockparam.cpp
* @file BlockParam.cpp
*
* Controller library code
*/
......
......@@ -32,17 +32,18 @@
****************************************************************************/
/**
* @file BlockParam.h
* @file BlockParam.hpp
*
* Controller library code
*/
#pragma once
#include <systemlib/param/param.h>
#include "Block.hpp"
#include <containers/List.hpp>
#include <px4_defines.h>
#include <systemlib/param/param.h>
namespace control
{
......@@ -59,9 +60,9 @@ public:
* @param parent_prefix Set to true to include the parent name in the parameter name
*/
BlockParamBase(Block *parent, const char *name, bool parent_prefix = true);
virtual ~BlockParamBase() {};
virtual ~BlockParamBase() = default;
virtual void update() = 0;
virtual bool update() = 0;
const char *getName() { return param_name(_handle); }
protected:
......@@ -70,13 +71,13 @@ protected:
// Parameters that are tied to blocks for updating and naming.
template <class T>
class __EXPORT BlockParam : public BlockParamBase
class __EXPORT BlockParam final : public BlockParamBase
{
public:
BlockParam(Block *block, const char *name, bool parent_prefix = true);
BlockParam(Block *block, const char *name, bool parent_prefix, T &extern_val);
~BlockParam() = default;
~BlockParam() override = default;
// no copy, assignment, move, move assignment
BlockParam(const BlockParam &) = delete;
......@@ -87,13 +88,14 @@ public:
T get() const { return _val; }
// Store the parameter value to the parameter storage (@see param_set())
void commit() { param_set(_handle, &_val); };
bool commit() { return (param_set(_handle, &_val) == PX4_OK); }
// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification())
void commit_no_notification() { param_set_no_notification(_handle, &_val); };
bool commit_no_notification() { return (param_set_no_notification(_handle, &_val) == PX4_OK); }
void set(T val) { _val = val; }
void set(T val) { _val = val; };
void update() override { param_get(_handle, &_val); };
bool update() override { return (param_get(_handle, &_val) == PX4_OK); }
protected:
T _val;
......@@ -104,9 +106,4 @@ typedef BlockParam<int32_t> BlockParamInt;
typedef BlockParam<float &> BlockParamExtFloat;
typedef BlockParam<int32_t &> BlockParamExtInt;
template class __EXPORT BlockParam<float>;
template class __EXPORT BlockParam<int32_t>;
template class __EXPORT BlockParam<float &>;
template class __EXPORT BlockParam<int32_t &>;
} // namespace control
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment