From afeb741dfef7df53fda0f284bc24aa1ca80ab7a0 Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 1 Mar 2022 21:07:17 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D1=83?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B8=D0=B5=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=20=D0=B4=D1=8F=D0=BB=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/IoTItem.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 322bc42c..2a3e43a8 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -11,9 +11,9 @@ IoTItem::IoTItem(String parameters) { _interval = _interval * 1000; jsonRead(parameters, F("subtype"), _subtype); jsonRead(parameters, F("id"), _id); - jsonRead(parameters, F("multiply"), _multiply, false); - jsonRead(parameters, F("plus"), _plus, false); - jsonRead(parameters, F("round"), _round, false); + 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; String valAsStr; if (jsonRead(parameters, F("val"), valAsStr, false)) // значение переменной или датчика при инициализации если есть в конфигурации From 1ac32e671120d3b9db9e077ad4a2ac931ae3122f Mon Sep 17 00:00:00 2001 From: biver Date: Thu, 3 Mar 2022 22:58:39 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B2=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20IF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/IoTScenario.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/classes/IoTScenario.cpp b/src/classes/IoTScenario.cpp index 970f07c5..a69bbe7e 100644 --- a/src/classes/IoTScenario.cpp +++ b/src/classes/IoTScenario.cpp @@ -260,8 +260,14 @@ class IfExprAST : public ExprAST { String _IDNames; public: - IfExprAST(ExprAST *cond, ExprAST *then, ExprAST *_else, String IDNames) - : Cond(cond), Then(then), Else(_else), _IDNames(IDNames) {} + IfExprAST(ExprAST *cond, ExprAST *then, ExprAST *_else, String *IDNames) + : Cond(cond), Then(then), Else(_else) { + if (IDNames) { + _IDNames = *IDNames; + //Serial.printf("eeeeeeeeeeeeee %s\n", _IDNames.c_str()); + } else _IDNames = ""; + Serial.printf("eeeeeeeeeeeeee\n"); + } bool hasEventIdName(String eventIdName) { Serial.printf("Call from BinaryExprAST _IDNames:%s\n", _IDNames.c_str()); @@ -579,7 +585,7 @@ public: getNextToken(); // Получаем then ExprAST *Then = ParseExpression(nullptr); - if (Then == 0) return 0; + if (!Then) return 0; //if (CurTok != tok_else) // return Error("expected else"); @@ -589,7 +595,7 @@ public: Else = ParseExpression(nullptr); } - return new IfExprAST(Cond, Then, Else, *IDNames); + return new IfExprAST(Cond, Then, Else, IDNames); } /// primary @@ -646,7 +652,7 @@ public: LHS = new BinaryExprAST(BinOp, LHS, RHS); } } - + /// expression /// ::= primary binoprhs @@ -682,7 +688,8 @@ public: //case ';': getNextToken(); break; // игнорируем верхнеуровневые точки с запятой. case tok_if: { String IDNames = ""; // накопитель встречающихся идентификаторов в условии - ScenarioElements.push_back(ParseExpression(&IDNames)); + ScenarioElements.push_back(ParseIfExpr(&IDNames)); + Serial.printf("vvvvvvvvvvvvvvvv %s", IDNames.c_str()); break; } default: getNextToken(); break; From 42c1cd3e57ed4771ec26389491cafc8ebd730348 Mon Sep 17 00:00:00 2001 From: biver Date: Thu, 3 Mar 2022 23:15:11 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BA=D1=80=D1=8B=D0=B2=D0=B0=D1=8E=D1=89=D0=B5?= =?UTF-8?q?=D0=B9=20=D1=84=D0=B8=D0=B3=D0=BA=D1=80=D0=BD=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=81=D0=BA=D0=BE=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/classes/IoTScenario.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/classes/IoTScenario.cpp b/src/classes/IoTScenario.cpp index a69bbe7e..f446d6ef 100644 --- a/src/classes/IoTScenario.cpp +++ b/src/classes/IoTScenario.cpp @@ -264,9 +264,7 @@ public: : Cond(cond), Then(then), Else(_else) { if (IDNames) { _IDNames = *IDNames; - //Serial.printf("eeeeeeeeeeeeee %s\n", _IDNames.c_str()); } else _IDNames = ""; - Serial.printf("eeeeeeeeeeeeee\n"); } bool hasEventIdName(String eventIdName) { @@ -553,10 +551,13 @@ public: bracketsList.push_back(Expr); if (CurTok != ';') - return Error("Expected '}' or ';' in operation list"); - getNextToken(); - + return Error("Expected ';' in operation list"); + int ttok = getNextToken(); + if (!ttok) { Error("Expected '}'"); break; } + if (CurTok == '}') break; + + } } @@ -689,7 +690,7 @@ public: case tok_if: { String IDNames = ""; // накопитель встречающихся идентификаторов в условии ScenarioElements.push_back(ParseIfExpr(&IDNames)); - Serial.printf("vvvvvvvvvvvvvvvv %s", IDNames.c_str()); + //Serial.printf("vvvvvvvvvvvvvvvv %s", IDNames.c_str()); break; } default: getNextToken(); break; From 0ae8fd1e38fa622a971f47763f38b1d859704b8e Mon Sep 17 00:00:00 2001 From: biver Date: Thu, 3 Mar 2022 23:28:27 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=B2=20=D1=81=D1=86=D0=B5=D0=BD=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=B8=20digitalWrite(pin),=20digitalRead(pin),=20digital?= =?UTF-8?q?Invert(pin)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/classes/IoTGpio.h | 1 + src/classes/IoTGpio.cpp | 6 ++++++ src/modules/Mcp23017.cpp | 4 ++++ src/modules/SysExt.cpp | 19 ++++++++++++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/classes/IoTGpio.h b/include/classes/IoTGpio.h index a77341ea..a83a63c5 100644 --- a/include/classes/IoTGpio.h +++ b/include/classes/IoTGpio.h @@ -11,6 +11,7 @@ class IoTGpio { virtual int digitalRead(uint8_t pin); virtual int analogRead(uint8_t pin); virtual void analogWrite(uint8_t pin, int val); + virtual void digitalInvert(uint8_t pin); int index; void regDriver(IoTGpio* newDriver); diff --git a/src/classes/IoTGpio.cpp b/src/classes/IoTGpio.cpp index 161a6348..29e164e8 100644 --- a/src/classes/IoTGpio.cpp +++ b/src/classes/IoTGpio.cpp @@ -48,6 +48,12 @@ void IoTGpio::analogWrite(uint8_t pin, int val) { } } +void IoTGpio::digitalInvert(uint8_t pin) { + int pinH = pin/100; + if (_drivers[pinH]) _drivers[pinH]->digitalInvert(pin - pinH*100); + else ::digitalWrite(pin, 1 - ::digitalRead(pin)); +} + void IoTGpio::regDriver(IoTGpio* newDriver) { _drivers[newDriver->index] = newDriver; diff --git a/src/modules/Mcp23017.cpp b/src/modules/Mcp23017.cpp index cf6b748d..a360230f 100644 --- a/src/modules/Mcp23017.cpp +++ b/src/modules/Mcp23017.cpp @@ -36,6 +36,10 @@ class Mcp23017 : public IoTItem, IoTGpio { return mcp.digitalRead(pin); } + void digitalInvert(uint8_t pin) { + mcp.digitalWrite(pin, 1 - mcp.digitalRead(pin)); + } + ~Mcp23017() {}; }; diff --git a/src/modules/SysExt.cpp b/src/modules/SysExt.cpp index e8272f04..6686ebaa 100644 --- a/src/modules/SysExt.cpp +++ b/src/modules/SysExt.cpp @@ -31,8 +31,25 @@ class SysExt : public IoTItem { if (command == "reboot") { // выполняем код при вызове спец команды из сценария: ID.reboot(); ESP.restart(); + } else if (command == "digitalRead") { + if (param.size()) { + IoTgpio.pinMode(param[0].valD, INPUT); + value.valD = IoTgpio.digitalRead(param[0].valD); + return value; + } + } else if (command == "digitalWrite") { + if (param.size() == 2) { + IoTgpio.pinMode(param[0].valD, OUTPUT); + IoTgpio.digitalWrite(param[0].valD, param[1].valD); + return {}; + } + } else if (command == "digitalInvert") { + if (param.size()) { + IoTgpio.pinMode(param[0].valD, OUTPUT); + IoTgpio.digitalInvert(param[0].valD); + return {}; + } } - return {}; // команда поддерживает возвращаемое значения. Т.е. по итогу выполнения команды или общения с внешней системой, можно вернуть значение в сценарий для дальнейшей обработки } From 2bca458f0cb73ec938a1fcd3fc9dbca23bde9c80 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 4 Mar 2022 00:11:13 +0300 Subject: [PATCH 5/6] =?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?=D1=87=D1=82=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B7=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20Item=20=D0=B2=20Lcd2004?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/Lcd2004.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/modules/Lcd2004.cpp b/src/modules/Lcd2004.cpp index 8f023b4f..c7396a61 100644 --- a/src/modules/Lcd2004.cpp +++ b/src/modules/Lcd2004.cpp @@ -42,11 +42,10 @@ class Lcd2004 : public IoTItem { void doByInterval() { if (LCDI2C != nullptr) { printBlankStr(_prevStrSize); - - String tmpStr; - // to do - // jsonRead(paramsHeapJson, _id2show, tmpStr); - if (_descr != "none") tmpStr = _descr + " " + tmpStr; + + String tmpStr = ""; + if (_descr != "none") tmpStr = _descr + " " + getItemValue(_id2show); + else tmpStr = getItemValue(_id2show); LCDI2C->setCursor(_x, _y); LCDI2C->print(tmpStr); From 4f57e965cba0d92931dbf76a2ab0a1b42b5de1b3 Mon Sep 17 00:00:00 2001 From: biver Date: Fri, 4 Mar 2022 01:01:13 +0300 Subject: [PATCH 6/6] =?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() {}