From d442588ac4df298a9f9adf6d6e1a802e833ecb12 Mon Sep 17 00:00:00 2001 From: Ilya Belyakov Date: Fri, 5 Jan 2024 22:00:28 +0500 Subject: [PATCH 1/4] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20AnalogBtn=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D1=80=D0=B0=D1=81=D0=BF=D0=BE=D0=B7=D0=BD=D0=B0=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B0=D0=BD=D0=B0=D0=BB=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D1=85=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BE=D0=BA=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=83=D1=80=D0=BE=D0=B2=D0=BD=D1=8E=20=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D0=BE=D0=B3=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=81=D0=B8=D0=B3=D0=BD=D0=B0=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/exec/AnalogBtn/AnalogBtn.cpp | 54 ++++++++++++++++++++++++ src/modules/exec/AnalogBtn/modinfo.json | 43 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/modules/exec/AnalogBtn/AnalogBtn.cpp create mode 100644 src/modules/exec/AnalogBtn/modinfo.json diff --git a/src/modules/exec/AnalogBtn/AnalogBtn.cpp b/src/modules/exec/AnalogBtn/AnalogBtn.cpp new file mode 100644 index 00000000..3630f9f5 --- /dev/null +++ b/src/modules/exec/AnalogBtn/AnalogBtn.cpp @@ -0,0 +1,54 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +extern IoTGpio IoTgpio; + + +class AnalogBtn : public IoTItem { + private: + int _pin, _aValue, _delta; + int _oldVal, _newVal; + + public: + AnalogBtn(String parameters) : IoTItem(parameters) { + _pin = 0; + _aValue = 0; + _delta = 50; + jsonRead(parameters, "pin", _pin); + jsonRead(parameters, "aValue", _aValue); + jsonRead(parameters, "delta", _delta); + _round = 0; + setInterval(-100); + } + + void doByInterval() { + _newVal = IoTgpio.analogRead(_pin); + if (_aValue == -1 && _oldVal != _newVal) { + _oldVal = _newVal; + SerialPrint("i", "AnalogBtn", (String)_newVal); + return; + } + + if ((_newVal > _aValue - _delta) && (_newVal < _aValue + _delta)) { + if (value.valD == 0) { + value.valD = 1; + regEvent(value.valD, "AnalogBtn"); + } + } else { + if (value.valD == 1) { + value.valD = 0; + regEvent(value.valD, "AnalogBtn"); + } + } + } + + ~AnalogBtn() {}; +}; + +void* getAPI_AnalogBtn(String subtype, String param) { + if (subtype == F("AnalogBtn")) { + return new AnalogBtn(param); + } else { + return nullptr; + } +} diff --git a/src/modules/exec/AnalogBtn/modinfo.json b/src/modules/exec/AnalogBtn/modinfo.json new file mode 100644 index 00000000..ca3d11d2 --- /dev/null +++ b/src/modules/exec/AnalogBtn/modinfo.json @@ -0,0 +1,43 @@ +{ + "menuSection": "executive_devices", + "configItem": [ + { + "global": 0, + "name": "Аналоговая кнопка", + "type": "Reading", + "subtype": "AnalogBtn", + "id": "abtn", + "widget": "toggle", + "page": "Кнопки", + "descr": "Освещение", + "pin": 34, + "aValue": -1, + "delta": 50 + } + ], + "about": { + "authorName": "Ilya Belyakov", + "authorContact": "https://t.me/Biveraxe", + "authorGit": "https://github.com/biveraxe", + "exampleURL": "https://iotmanager.org/wiki", + "specialThanks": "", + "moduleName": "AnalogBtn", + "moduleVersion": "1.0", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "Аналоговая кнопка", + "moduleDesc": "Позволяет получить состояние кнопки на аналоговом пине.", + "propInfo": { + "pin": "Аналоговый GPIO номер, к которому подключена кнопка.", + "aValue": "Значение кнопки в диапазоне от 0 до 1023 (8266) или от 0 до 4095 (esp32). Если =-1 то включается режим отладки и в консоль отправляются значения нажимаемой кнопки.", + "delta": "Погрешность срабатывания кнопки в диапазоне +-delta." + } + }, + "defActive": true, + "usedLibs": { + "esp32*": [], + "esp82*": [] + } +} \ No newline at end of file From 9da0260a94e8c6d6dd77763e3f248d31ac599f15 Mon Sep 17 00:00:00 2001 From: Ilya Belyakov Date: Sat, 6 Jan 2024 11:24:49 +0500 Subject: [PATCH 2/4] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B6=D0=B0?= =?UTF-8?q?=D0=B5=D0=BC=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BD=D0=B0=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=B5=D0=BA=20=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B8=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3?= =?UTF-8?q?=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BD=D0=B5=20=D1=81?= =?UTF-8?q?=D0=B1=D1=80=D0=B0=D1=81=D1=8B=D0=B2=D0=B0=D1=8E=D1=82=D1=81?= =?UT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=D0=B8=D0=BC=D0=BE?= =?UTF-8?q?=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20values.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WsServer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/WsServer.cpp b/src/WsServer.cpp index 0965338d..98123e75 100644 --- a/src/WsServer.cpp +++ b/src/WsServer.cpp @@ -117,6 +117,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t* payload, size_t length) if (headerStr == "/oiranecs|") { writeFileUint8tByFrames("scenario.txt", payload, length, headerLenth, 256); clearConfigure(); + globalVarsSync(); // в том числе подгружаем сохраненные значения элементов с флешки configure("/config.json"); iotScen.loadScenario("/scenario.txt"); // создаем событие завершения конфигурирования для возможности From e0ec19c5f79438d6424c363988918484e96570a6 Mon Sep 17 00:00:00 2001 From: Ilya Belyakov Date: Sat, 6 Jan 2024 17:30:23 +0500 Subject: [PATCH 3/4] =?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=D0=BC=D0=B0=D1=82=D0=B5=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D0=BA=D1=83=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D1=8E=20=D0=B2=D1=85=D0=BE=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=82=D0=B5=D0=BA=D1=83=D1=89=D0=B5=D0=B3=D0=BE=20=D0=B2?= =?UTF-8?q?=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=B2=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B8=D0=BE=D0=B4=20=D0=92=20=D0=BF=D0=B0=D0=BF=D0=BA?= =?UTF-8?q?=D0=B5=20=D1=81=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D0=B5=D0=BC=20?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D1=8C=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=80?= =?UTF-8?q?=20=D1=82=D0=B0=D0=B9=D0=BC=D0=B5=D1=80=D0=B0=20=D1=81=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=D0=BC=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D1=84?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/virtual/Math/Math.cpp | 22 +- src/modules/virtual/Math/TimerRelay.json | 258 +++++++++++++++++++++++ src/modules/virtual/Math/modinfo.json | 10 +- 3 files changed, 286 insertions(+), 4 deletions(-) create mode 100644 src/modules/virtual/Math/TimerRelay.json diff --git a/src/modules/virtual/Math/Math.cpp b/src/modules/virtual/Math/Math.cpp index 7b14c396..d726d2dc 100644 --- a/src/modules/virtual/Math/Math.cpp +++ b/src/modules/virtual/Math/Math.cpp @@ -31,6 +31,18 @@ private: return mktime(&t); } + bool nowInTimePeriod(String startTime, String endTime) { + int h1 = selectToMarker(startTime, ":").toInt(); + int min1 = selectToMarkerLast(startTime, ":").toInt(); + int h2 = selectToMarker(endTime, ":").toInt(); + int min2 = selectToMarkerLast(endTime, ":").toInt(); + + int nowMinutes = _time_local.hour * 60 + _time_local.minute; + + return nowMinutes >= h1 * 60 + min1 && nowMinutes <= h2 * 60 + min2; + } + + public: IoTMath(String parameters) : IoTItem(parameters) {} @@ -42,7 +54,7 @@ public: //SerialPrint("i", F("IoTMath"), F("Mapping value done.")); return valTmp; } else if(command == "convertTime" && param.size() == 5) { - time_t unixTime = convertTime(param[0].valD, param[1].valD, param[2].valD, param[3].valD, param[4].valD); + uint32_t unixTime = convertTime(param[0].valD, param[1].valD, param[2].valD, param[3].valD, param[4].valD); if (unixTime == -1) { SerialPrint("E", F("IoTMath"), F("Failed to convert time.")); @@ -51,8 +63,12 @@ public: IoTValue valTmp; valTmp.isDecimal = true; - valTmp.valD = unixTime; - //SerialPrint("i", F("IoTMath"), F("Time conversion done.")); + valTmp.valD = static_cast< float > (unixTime); + return valTmp; + } else if(command == "nowInTimePeriod" && param.size() == 2) { + IoTValue valTmp; + valTmp.isDecimal = true; + valTmp.valD = nowInTimePeriod(param[0].valS, param[1].valS); return valTmp; } diff --git a/src/modules/virtual/Math/TimerRelay.json b/src/modules/virtual/Math/TimerRelay.json new file mode 100644 index 00000000..7a74884a --- /dev/null +++ b/src/modules/virtual/Math/TimerRelay.json @@ -0,0 +1,258 @@ +{ + "mark": "iotm", + "config": [ + { + "global": 0, + "type": "Writing", + "subtype": "ButtonOut", + "needSave": "1", + "id": "rel1", + "widget": "toggle", + "page": "Свет 1", + "descr": " Реле 1", + "int": 0, + "inv": "1", + "pin": "32" + }, + { + "global": 0, + "type": "Writing", + "subtype": "ButtonOut", + "needSave": "1", + "id": "rel2", + "widget": "toggle", + "page": "Свет 2", + "descr": " Реле 2", + "int": 0, + "inv": "1", + "pin": "33" + }, + { + "global": 0, + "type": "Reading", + "subtype": "RTC", + "id": "rtc", + "widget": "anydataDef", + "page": "Система", + "descr": "Время", + "chipCode": "3", + "timeFormat": "d-m-Y H:i:s", + "RST": -1, + "CLK": -1, + "DAT": -1, + "ticker": 0, + "int": 5, + "btn-setUTime": "0", + "btn-setSysTime": "nil" + }, + { + "global": 0, + "type": "Reading", + "subtype": "AnalogBtn", + "id": "btn1", + "widget": "nil", + "page": "Свет 1", + "descr": "Кнопка 1", + "pin": "34", + "aValue": 0, + "delta": 50 + }, + { + "global": 0, + "type": "Reading", + "subtype": "AnalogBtn", + "id": "btn2", + "widget": "nil", + "page": "Свет 2", + "descr": "Кнопка 2", + "pin": "34", + "aValue": "1910", + "delta": 50 + }, + { + "global": 0, + "type": "Reading", + "subtype": "IoTMath", + "id": "math", + "widget": "anydataValue", + "page": "Математика", + "descr": "" + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "start11", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 1", + "descr": " Старт 1", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "stop11", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 1", + "descr": " Стоп 1", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "start12", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 1", + "descr": "Старт 2", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "stop12", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 1", + "descr": "Стоп 2", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "start21", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 2", + "descr": " Старт 1", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "stop21", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 2", + "descr": " Стоп 1", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "start22", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 2", + "descr": "Старт 2", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "stop22", + "needSave": "1", + "widget": "inputTm", + "page": "Свет 2", + "descr": "Стоп 2", + "int": "0", + "val": "0.0", + "map": "1024,1024,1,100", + "plus": 0, + "multiply": 1, + "round": 0 + }, + { + "global": 0, + "type": "Writing", + "subtype": "Cron", + "id": "timer", + "widget": "anydataRed", + "page": "Система", + "descr": "Будильник", + "int": 1, + "val": "0 * * * * *", + "formatNextAlarm": "%H:%M:%S", + "needSave": 0 + }, + { + "global": 0, + "type": "Reading", + "subtype": "VButton", + "id": "rel1on", + "needSave": "1", + "widget": "toggle", + "page": "Свет 1", + "descr": " Работать", + "int": "0", + "val": "0" + }, + { + "global": 0, + "type": "Reading", + "subtype": "VButton", + "id": "rel2on", + "needSave": "1", + "widget": "toggle", + "page": "Свет 2", + "descr": " Работать", + "int": "0", + "val": "0" + } + ] +} + +scenario=>if btn1>0 then rel1 = 1- rel1 +if btn2>0 then rel2 = 1- rel2 + +if timer == 0 | start11 | stop11 | start12 | stop12 | start21 | stop21 | start22 | stop22 then { +if rel1on then +if math.nowInTimePeriod(start11, stop11) | math.nowInTimePeriod(start12, stop12) then rel1=1 else rel1=0 + +if rel2on then +if math.nowInTimePeriod(start21, stop21) | math.nowInTimePeriod(start22, stop22) then rel2=1 else rel2=0 +} \ No newline at end of file diff --git a/src/modules/virtual/Math/modinfo.json b/src/modules/virtual/Math/modinfo.json index 6265e85b..27080b3c 100644 --- a/src/modules/virtual/Math/modinfo.json +++ b/src/modules/virtual/Math/modinfo.json @@ -38,10 +38,18 @@ }, { "name": "convertTime", - "descr": "Перевести время из формата d-m-Y H:i:s например, 13-08-2023 16:24:00 в юникс-время ", + "descr": "Перевести время из формата d-m-Y H:i:s например, 13-08-2023 16:24:00 в юникс-время", "params": [ "tm.convertTime(13, 08, 2023, 16, 24); - передаем пять целых чисел. секунды подставятся в ноль" ] + }, + { + "name": "nowInTimePeriod", + "descr": "Проверяет входит ли текущее время в указанный период. Возвращает 1 если входит, 0 если нет.", + "params": [ + "Начало периода в формате HH:MM", + "Конец периода в формате HH:MM" + ] } ] }, From 02cf1547a8a03af856cd4c2d5be8937f85a421f8 Mon Sep 17 00:00:00 2001 From: Ilya Belyakov Date: Sat, 6 Jan 2024 18:01:51 +0500 Subject: [PATCH 4/4] =?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=D1=82=D1=80=D0=B5=D0=B1=D1=83=D0=B5=D0=BC=D1=8B?= =?UTF-8?q?=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20TM16XX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/display/TM16XX/modinfo.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/display/TM16XX/modinfo.json b/src/modules/display/TM16XX/modinfo.json index bbbed517..1aaf3857 100644 --- a/src/modules/display/TM16XX/modinfo.json +++ b/src/modules/display/TM16XX/modinfo.json @@ -78,10 +78,14 @@ "defActive": false, "usedLibs": { "esp32*": [ - "https://github.com/maxint-rd/TM16xx" + "https://github.com/maxint-rd/TM16xx", + "https://github.com/adafruit/Adafruit-GFX-Library", + "adafruit/Adafruit BusIO @ ^1.13.2" ], "esp82*": [ - "https://github.com/maxint-rd/TM16xx" + "https://github.com/maxint-rd/TM16xx", + "https://github.com/adafruit/Adafruit-GFX-Library", + "adafruit/Adafruit BusIO @ ^1.13.2" ] } } \ No newline at end of file