From fd47929f8ecd735c0edb5cdf57e3d6cf5829129e Mon Sep 17 00:00:00 2001 From: John Date: Mon, 30 Jan 2023 21:59:40 +0100 Subject: [PATCH] add getStep() method --- src/ebusd/mqtthandler.cpp | 2 +- src/lib/ebus/datatype.cpp | 4 ++++ src/lib/ebus/datatype.h | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ebusd/mqtthandler.cpp b/src/ebusd/mqtthandler.cpp index cdd0baa8..b465dd4d 100755 --- a/src/ebusd/mqtthandler.cpp +++ b/src/ebusd/mqtthandler.cpp @@ -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; diff --git a/src/lib/ebus/datatype.cpp b/src/lib/ebus/datatype.cpp index 86146348..92f5e22b 100755 --- a/src/lib/ebus/datatype.cpp +++ b/src/lib/ebus/datatype.cpp @@ -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; diff --git a/src/lib/ebus/datatype.h b/src/lib/ebus/datatype.h index 388a4126..34ac913e 100755 --- a/src/lib/ebus/datatype.h +++ b/src/lib/ebus/datatype.h @@ -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). */