From 4f57e965cba0d92931dbf76a2ab0a1b42b5de1b3 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 4 Mar 2022 01:01:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=B0=D0=B8?= =?UTF-8?q?=D0=B2=D0=B0=D0=B5=D0=BC=20=D0=B5=D0=B4=D0=B8=D0=BD=D1=8B=D0=B9?= =?UTF-8?q?=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20=D0=B2=D1=8B=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20Item?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/IoTItem.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 93c8041d..7813a956 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -11,7 +11,7 @@ IoTItem::IoTItem(String parameters) { _interval = _interval * 1000; jsonRead(parameters, F("subtype"), _subtype); jsonRead(parameters, F("id"), _id); - if (jsonRead(parameters, F("multiply"), _multiply, false)) _multiply = 1; + if (!jsonRead(parameters, F("multiply"), _multiply, false)) _multiply = 1; if (!jsonRead(parameters, F("plus"), _plus, false)) _plus = 0; if (!jsonRead(parameters, F("round"), _round, false)) _round = -1; @@ -44,7 +44,11 @@ String IoTItem::getID() { String IoTItem::getValue() { if (value.isDecimal) - return (String)value.valD; + if (_round >= 0) { + char buf[8]; + sprintf(buf, ("%1." + (String)_round + "f").c_str(), value.valD); + return (String)buf; + } else return (String)value.valD; else return value.valS; } @@ -78,7 +82,7 @@ void IoTItem::regEvent(String value, String consoleInfo = "") { void IoTItem::regEvent(float regvalue, String consoleInfo = "") { if (_multiply) regvalue = regvalue * _multiply; if (_plus) regvalue = regvalue + _multiply; - if (_round >= 0 && _round < 6) { + if (_round >= 0 && _round <= 6) { int sot = _round ? pow(10, (int)_round) : 1; regvalue = round(regvalue * sot) / sot; } @@ -86,12 +90,7 @@ void IoTItem::regEvent(float regvalue, String consoleInfo = "") { value.valD = regvalue; - // убираем лишние нули - // char buf[20]; - // sprintf(buf, "%g", regvalue); - // regEvent((String)buf, consoleInfo); - - regEvent((String)regvalue, consoleInfo); + regEvent(getValue(), consoleInfo); } void IoTItem::doByInterval() {}