mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-18 21:39:06 +08:00
BlockParam update() and commit() add returns
This commit is contained in:
parent
633102e7ca
commit
b620da8f01
@ -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 update() override { param_get(_handle, &_val); };
|
||||
void set(T val) { _val = 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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user