Исправляем ошибку получения значения IoTItem при прямом обращении

приводило к искажению значения
This commit is contained in:
2022-10-07 22:18:05 +03:00
parent 111486c7c3
commit 9e4ebd2a5e
2 changed files with 21 additions and 15 deletions

View File

@@ -44,6 +44,7 @@ class IoTItem {
virtual IoTGpio* getGpioDriver();
virtual void setValue(IoTValue Value);
virtual void setValue(String valStr);
String getRoundValue();
//методы для графиков
virtual void publishValue();

View File

@@ -52,20 +52,7 @@ void IoTItem::loop() {
//получить
String IoTItem::getValue() {
if (value.isDecimal) {
if (_multiply) value.valD = value.valD * _multiply;
if (_plus) value.valD = value.valD + _plus;
if (_round >= 0 && _round <= 6) {
int sot = _round ? pow(10, (int)_round) : 1;
value.valD = round(value.valD * sot) / sot;
}
if (_map1 != _map2) value.valD = map(value.valD, _map1, _map2, _map3, _map4);
if (_round >= 0 && _round <= 6) {
char buf[15];
sprintf(buf, ("%1." + (String)_round + "f").c_str(), value.valD);
return value.valS = buf;
} else
return (String)value.valD;
return getRoundValue();
} else
return value.valS;
}
@@ -114,9 +101,27 @@ void IoTItem::regEvent(String value, String consoleInfo = "") {
//========================================================================
}
String IoTItem::getRoundValue() {
if (_round >= 0 && _round <= 6) {
int sot = _round ? pow(10, (int)_round) : 1;
value.valD = round(value.valD * sot) / sot;
char buf[15];
sprintf(buf, ("%1." + (String)_round + "f").c_str(), value.valD);
return (String)buf;
} else {
return (String)value.valD;
}
}
void IoTItem::regEvent(float regvalue, String consoleInfo = "") {
value.valD = regvalue;
regEvent(getValue(), consoleInfo);
if (_multiply) value.valD = value.valD * _multiply;
if (_plus) value.valD = value.valD + _plus;
if (_map1 != _map2) value.valD = map(value.valD, _map1, _map2, _map3, _map4);
regEvent(getRoundValue(), consoleInfo);
}
void IoTItem::doByInterval() {}