BlockParam: remove _extern_address and create a new class BlockParamExt for this

In most cases, _extern_address was unused, thus wasting cycles & RAM. This
adds a separate class BlockParamExt with the field and uses it in ekf2_main

Frees roughly 0.5KB of RAM on Pixracer
This commit is contained in:
Beat Küng
2016-10-23 15:25:20 +02:00
committed by Lorenz Meier
parent 09d8e4fd8c
commit 7c6d99d30f
3 changed files with 210 additions and 162 deletions
+27 -3
View File
@@ -77,21 +77,45 @@ class BlockParam : public BlockParamBase
{
public:
BlockParam(Block *block, const char *name,
bool parent_prefix = true, T *extern_address = NULL);
bool parent_prefix = true);
BlockParam(const BlockParam &) = delete;
BlockParam &operator=(const BlockParam &) = delete;
T get();
void commit();
void set(T val);
void update();
void update() override;
virtual ~BlockParam();
protected:
T _val;
T *_extern_address;
};
typedef BlockParam<float> BlockParamFloat;
typedef BlockParam<int> BlockParamInt;
/**
* Same as BlockParam, but in addition with a pointer to an external field that will be
* set to the value of the parameter.
* (BlockParam should be prefered over this)
*/
template <class T>
class BlockParamExt : public BlockParam<T>
{
public:
BlockParamExt(Block *block, const char *name,
bool parent_prefix, T &extern_val);
BlockParamExt(const BlockParamExt &) = delete;
BlockParamExt &operator=(const BlockParamExt &) = delete;
void set(T val);
void update() override;
virtual ~BlockParamExt();
protected:
T &_extern_val;
};
typedef BlockParamExt<float> BlockParamExtFloat;
typedef BlockParamExt<int> BlockParamExtInt;
} // namespace control