From 111486c7c3fd7f26e851a0d10de6f14a511166e3 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 7 Oct 2022 22:17:23 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A7=D1=83=D1=82=D1=8C=20=D0=BE=D0=BF?= =?UTF-8?q?=D1=82=D0=B8=D0=BC=D0=B8=D0=B7=D0=B8=D1=80=D1=83=D0=B5=D0=BC=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20LCD16XX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/display/Lcd2004/Lcd2004.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/modules/display/Lcd2004/Lcd2004.cpp b/src/modules/display/Lcd2004/Lcd2004.cpp index 3feee118..74f3080d 100644 --- a/src/modules/display/Lcd2004/Lcd2004.cpp +++ b/src/modules/display/Lcd2004/Lcd2004.cpp @@ -36,9 +36,11 @@ class Lcd2004 : public IoTItem { LCDI2C = new LiquidCrystal_I2C(hexStringToUint8(addr), w, h); if (LCDI2C != nullptr) { LCDI2C->init(); - LCDI2C->backlight(); } } + + LCDI2C->clear(); + LCDI2C->backlight(); jsonRead(parameters, "coord", xy); _x = selectFromMarkerToMarker(xy, ",", 0).toInt(); @@ -52,14 +54,13 @@ class Lcd2004 : public IoTItem { if (LCDI2C != nullptr) { printBlankStr(_prevStrSize); - String tmpStr = ""; - if (_descr != "none") tmpStr = _descr + " " + getItemValue(_id2show); - else tmpStr = getItemValue(_id2show); + String tmpStr = getItemValue(_id2show); + if (_descr != "none") tmpStr = _descr + " " + tmpStr; LCDI2C->setCursor(_x, _y); LCDI2C->print(tmpStr); //LCDI2C->print("Helloy,Manager 404 !"); - + //Serial.printf("ffff %s\n", _id2show); _prevStrSize = tmpStr.length(); } } @@ -113,7 +114,10 @@ class Lcd2004 : public IoTItem { LCDI2C->print(tmpStr); } - ~Lcd2004(){}; + ~Lcd2004(){ + if (LCDI2C) delete LCDI2C; + LCDI2C = nullptr; + }; }; void *getAPI_Lcd2004(String subtype, String param) { From 9e4ebd2a5ede0cf787ca0090835b35ad0543ed47 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 7 Oct 2022 22:18:05 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B7?= =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20IoTItem=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=BF=D1=80=D1=8F=D0=BC=D0=BE=D0=BC=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D1=89=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=D0=B2=D0=BE=D0=B4=D0=B8=D0=BB=D0=BE=20=D0=BA=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D1=8E=20=D0=B7=D0=BD?= =?UTF-8?q?=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/classes/IoTItem.h | 1 + src/classes/IoTItem.cpp | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/classes/IoTItem.h b/include/classes/IoTItem.h index e16e536e..555c3a35 100644 --- a/include/classes/IoTItem.h +++ b/include/classes/IoTItem.h @@ -44,6 +44,7 @@ class IoTItem { virtual IoTGpio* getGpioDriver(); virtual void setValue(IoTValue Value); virtual void setValue(String valStr); + String getRoundValue(); //методы для графиков virtual void publishValue(); diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 68f88c96..4f3cb1a4 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -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() {}