add getStep() method

This commit is contained in:
John
2023-01-30 22:06:06 +01:00
parent af614ae1e1
commit fd47929f8e
3 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -1098,7 +1098,7 @@ void MqttHandler::run() {
values.set("max", ostr.str());
ostr.str("");
}
if (dt->readFromRawValue(1, g_publishFormat, &ostr) != RESULT_OK) {
if (dt->getStep(g_publishFormat, &ostr) != RESULT_OK) {
// fallback method, when smallest number didn't work
int divisor = dt->getDivisor();
float step = 1.0f;
+4
View File
@@ -735,6 +735,10 @@ result_t NumberDataType::getMinMax(bool getMax, const OutputFormat outputFormat,
return readFromRawValue(getMax ? m_maxValue : m_minValue, outputFormat, output);
}
result_t NumberDataType::getStep(const OutputFormat outputFormat, ostream* output) const {
return readFromRawValue(hasFlag(EXP) ? floatToUint(1.0f) : 1, outputFormat, output);
}
result_t NumberDataType::readRawValue(size_t offset, size_t length, const SymbolString& input,
unsigned int* value) const {
size_t start = 0, count = length;
+8
View File
@@ -517,6 +517,14 @@ class NumberDataType : public DataType {
*/
result_t getMinMax(bool getMax, const OutputFormat outputFormat, ostream* output) const;
/**
* Get the smallest step value for increment/decrement.
* @param outputFormat the @a OutputFormat options to use.
* @param output the ostream to append the formatted value to.
* @return @a RESULT_OK on success, or an error code.
*/
result_t getStep(const OutputFormat outputFormat, ostream* output) const;
/**
* @return the divisor (negative for reciprocal).
*/