mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 15:43:34 +08:00
controllib add BlockParamBool (int32 wrapper)
This commit is contained in:
@@ -81,6 +81,30 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
BlockParam<bool>::BlockParam(Block *block, const char *name, bool parent_prefix) :
|
||||||
|
BlockParamBase(block, name, parent_prefix),
|
||||||
|
_val()
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
bool BlockParam<bool>::update()
|
||||||
|
{
|
||||||
|
int32_t tmp = 0;
|
||||||
|
int ret = param_get(_handle, &tmp);
|
||||||
|
|
||||||
|
if (tmp == 1) {
|
||||||
|
_val = true;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_val = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (ret == PX4_OK);
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
BlockParam<int32_t>::BlockParam(Block *block, const char *name, bool parent_prefix) :
|
BlockParam<int32_t>::BlockParam(Block *block, const char *name, bool parent_prefix) :
|
||||||
BlockParamBase(block, name, parent_prefix),
|
BlockParamBase(block, name, parent_prefix),
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public:
|
|||||||
virtual ~BlockParamBase() = default;
|
virtual ~BlockParamBase() = default;
|
||||||
|
|
||||||
virtual bool update() = 0;
|
virtual bool update() = 0;
|
||||||
const char *getName() { return param_name(_handle); }
|
const char *getName() const { return param_name(_handle); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
param_t _handle{PARAM_INVALID};
|
param_t _handle{PARAM_INVALID};
|
||||||
@@ -101,8 +101,12 @@ protected:
|
|||||||
T _val;
|
T _val;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
bool BlockParam<bool>::update();
|
||||||
|
|
||||||
typedef BlockParam<float> BlockParamFloat;
|
typedef BlockParam<float> BlockParamFloat;
|
||||||
typedef BlockParam<int32_t> BlockParamInt;
|
typedef BlockParam<int32_t> BlockParamInt;
|
||||||
|
typedef BlockParam<bool> BlockParamBool;
|
||||||
typedef BlockParam<float &> BlockParamExtFloat;
|
typedef BlockParam<float &> BlockParamExtFloat;
|
||||||
typedef BlockParam<int32_t &> BlockParamExtInt;
|
typedef BlockParam<int32_t &> BlockParamExtInt;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user