Skip to content
Snippets Groups Projects
Unverified Commit 8ef686cb authored by Grigoris Pavlakis's avatar Grigoris Pavlakis
Browse files

Convert Parameter class to template

parent 807648b6
No related branches found
No related tags found
No related merge requests found
......@@ -23,8 +23,7 @@
* @typedef Flags: container for the binary flags
*/
typedef uint16_t ParamId;
typedef uint32_t ValueType;
typedef void(*UpdatePtr)(ValueType*);
//typedef etl::variant<bool, uint8_t, int32_t, float> ValueType;
typedef etl::bitset<NUM_OF_FLAGS> Flags;
/**
......@@ -55,17 +54,17 @@ typedef etl::bitset<NUM_OF_FLAGS> Flags;
* @public getCurrentValue(): Gets the current value of the parameter
* @public getPTC(), getPFC(): Returns the PFC and PTC of the parameter
*/
class Parameter {
template <typename ValueType> class Parameter {
uint8_t ptc;
uint8_t pfc;
UpdatePtr ptr;
void(*ptr)(ValueType*);
Flags flags;
ValueType currentValue = 0;
public:
Parameter(uint8_t newPtc, uint8_t newPfc, uint32_t initialValue = 0, UpdatePtr newPtr = nullptr);
Parameter<ValueType>(uint8_t newPtc, uint8_t newPfc, const ValueType& initialValue, void(*newPtr)(ValueType*));
void setCurrentValue(ValueType newVal);
void setCurrentValue(const ValueType& newVal);
void setFlags(const char* flags);
ValueType getCurrentValue();
......
#include "Services/Parameter.hpp"
Parameter::Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue, UpdatePtr newPtr) {
template <typename ValueType>
Parameter<ValueType>::Parameter(uint8_t newPtc, uint8_t newPfc, const ValueType& initialValue, void(*newPtr)(ValueType*)) {
ptc = newPtc;
pfc = newPfc;
ptr = newPtr;
......@@ -15,25 +16,30 @@ Parameter::Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue, Upd
}
}
void Parameter::setCurrentValue(ValueType newVal) {
template <typename ValueType>
void Parameter<ValueType>::setCurrentValue(const ValueType& newVal) {
// set the value only if the parameter can be updated manually
if (flags[1]) {
currentValue = newVal;
}
}
ValueType Parameter::getCurrentValue() {
template <typename ValueType>
ValueType Parameter<ValueType>::getCurrentValue() {
return currentValue;
}
uint8_t Parameter::getPTC() {
template <typename ValueType>
uint8_t Parameter<ValueType>::getPTC() {
return ptc;
}
uint8_t Parameter::getPFC() {
template <typename ValueType>
uint8_t Parameter<ValueType>::getPFC() {
return pfc;
}
void Parameter::setFlags(const char* flags) {
template <typename ValueType>
void Parameter<ValueType>::setFlags(const char* flags) {
this->flags = Flags(flags);
}
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