diff --git a/inc/Services/Parameter.hpp b/inc/Services/Parameter.hpp index 5e90a72b6e88997947b773416a57a6fd2d07e369..9cf9a01583ad83c23816fb5785c7a58eece8dfc6 100644 --- a/inc/Services/Parameter.hpp +++ b/inc/Services/Parameter.hpp @@ -59,29 +59,57 @@ typedef etl::bitset<NUM_OF_FLAGS> Flags; */ class ParameterBase { - protected: - uint8_t ptc; - uint8_t pfc; - uint8_t sizeInBytes; - void* valuePtr; - Flags flags; - public: - uint8_t getPTC(); - void setFlags(const char* flags); - uint8_t getPFC(); - virtual String<MAX_STRING_LENGTH> getValueAsString() = 0; - template <typename ValueType> void setCurrentValue(ValueType newVal); +protected: + uint8_t ptc; + uint8_t pfc; + uint8_t sizeInBytes; + void* valuePtr; + Flags flags; +public: + uint8_t getPTC(); + + void setFlags(const char* flags); + + uint8_t getPFC(); + + virtual String<MAX_STRING_LENGTH> getValueAsString() = 0; + + template <typename ValueType> + void setCurrentValue(ValueType newVal) { + // set the value only if the parameter can be updated manually + if (flags[1]) { + *reinterpret_cast<ValueType*>(valuePtr) = newVal; + } + } }; template <typename ValueType> class Parameter : public ParameterBase { - void(*ptr)(ValueType*); + void (* ptr)(ValueType*); + ValueType currentValue; - public: - Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue = 0, void(*newPtr) - (ValueType*) = nullptr); - String<MAX_STRING_LENGTH> getValueAsString() override; +public: + Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue = 0, void(* newPtr)(ValueType*) = nullptr) { + ptc = newPtc; + pfc = newPfc; + ptr = newPtr; + sizeInBytes = sizeof(initialValue); + valuePtr = static_cast<void*>(¤tValue); + // see Parameter.hpp for explanation on flags + // by default: no update priority, manual and automatic update available + + if (ptr != nullptr) { + (*ptr)(¤tValue); // call the update function for the initial value + } else { + currentValue = initialValue; + } + } + + String<MAX_STRING_LENGTH> getValueAsString() override { + String<MAX_STRING_LENGTH> contents(reinterpret_cast<uint8_t*>(¤tValue), sizeInBytes); + return contents; + } }; diff --git a/src/Services/Parameter.cpp b/src/Services/Parameter.cpp index 8bf1603f3b7654e19d4475fe68810bb4d331b697..f1410d910314931e536b24b49945d3cf9dc2c9fe 100644 --- a/src/Services/Parameter.cpp +++ b/src/Services/Parameter.cpp @@ -1,37 +1,5 @@ #include "Services/Parameter.hpp" -template <typename ValueType> -Parameter<ValueType>::Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue, void (* -newPtr)(ValueType*)) { - ptc = newPtc; - pfc = newPfc; - ptr = newPtr; - sizeInBytes = sizeof(initialValue); - valuePtr = static_cast<void *>(¤tValue); - // see Parameter.hpp for explanation on flags - // by default: no update priority, manual and automatic update available - - if (ptr != nullptr) { - (*ptr)(¤tValue); // call the update function for the initial value - } else { - currentValue = initialValue; - } -} - -template <typename ValueType> -void ParameterBase::setCurrentValue(ValueType newVal) { - // set the value only if the parameter can be updated manually - if (flags[1]) { - *reinterpret_cast<ValueType>(valuePtr) = newVal; - } -} - -template <typename ValueType> -String<MAX_STRING_LENGTH> Parameter<ValueType>::getValueAsString() { - String<MAX_STRING_LENGTH> contents(reinterpret_cast<uint8_t*>(¤tValue), sizeInBytes); - return contents; -} - uint8_t ParameterBase::getPTC() { return ptc; }