From 66051080526df52c90f243d2e50812d216b3be64 Mon Sep 17 00:00:00 2001 From: Ilya Belyakov Date: Wed, 1 May 2024 10:06:10 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A3=D1=82=D0=BE=D1=87=D0=BD=D1=8F=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=BF=D0=B5=D1=80=D0=B8=D0=BE=D0=B4=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D1=8B=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20nowInTimePeriod=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=20=D0=B2=20IoTItem.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/classes/IoTItem.h | 1 + src/modules/virtual/Math/Math.cpp | 9 ++- .../virtual/Math/SimpleTimePeriod.json | 57 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/modules/virtual/Math/SimpleTimePeriod.json diff --git a/include/classes/IoTItem.h b/include/classes/IoTItem.h index cfdb33e2..5ff1e0fe 100644 --- a/include/classes/IoTItem.h +++ b/include/classes/IoTItem.h @@ -1,4 +1,5 @@ #pragma once +#include #include "classes/IoTGpio.h" //#include "classes/IoTBench.h" diff --git a/src/modules/virtual/Math/Math.cpp b/src/modules/virtual/Math/Math.cpp index d726d2dc..979031f6 100644 --- a/src/modules/virtual/Math/Math.cpp +++ b/src/modules/virtual/Math/Math.cpp @@ -37,9 +37,16 @@ private: int h2 = selectToMarker(endTime, ":").toInt(); int min2 = selectToMarkerLast(endTime, ":").toInt(); + int sumMin1 = h1 * 60 + min1; + int sumMin2 = h2 * 60 + min2; + int nowMinutes = _time_local.hour * 60 + _time_local.minute; - return nowMinutes >= h1 * 60 + min1 && nowMinutes <= h2 * 60 + min2; + if (sumMin1 <= sumMin2) { + return nowMinutes >= sumMin1 && nowMinutes <= sumMin2; + } else { + return nowMinutes >= sumMin1 && nowMinutes <= 24 * 60 || nowMinutes >= 0 && nowMinutes <= sumMin2; + } } diff --git a/src/modules/virtual/Math/SimpleTimePeriod.json b/src/modules/virtual/Math/SimpleTimePeriod.json new file mode 100644 index 00000000..1b402876 --- /dev/null +++ b/src/modules/virtual/Math/SimpleTimePeriod.json @@ -0,0 +1,57 @@ +{ + "mark": "iotm", + "config": [ + { + "global": 0, + "type": "Reading", + "subtype": "IoTMath", + "id": "math", + "widget": "anydataValue", + "page": "Ввод", + "descr": "" + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "start", + "needSave": 0, + "widget": "inputTm", + "page": "Ввод", + "descr": "Введите время", + "int": "0", + "val": "02:00" + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "stop", + "needSave": 0, + "widget": "inputTm", + "page": "Ввод", + "descr": "Введите время", + "int": "0", + "val": "02:00" + }, + { + "global": 0, + "type": "Writing", + "subtype": "ButtonOut", + "needSave": 0, + "id": "led", + "widget": "toggle", + "page": "Ввод", + "descr": "Освещение", + "int": 0, + "inv": 0, + "pin": 2 + } + ] +} + +scenario=>if start | stop then { +if math.nowInTimePeriod(start, stop) then { +led = 1 +} else led = 0 +} \ No newline at end of file From ed7037f280fa0e9069f61d70203692a50e5414df Mon Sep 17 00:00:00 2001 From: Ilya Belyakov Date: Tue, 13 Aug 2024 18:28:37 +0500 Subject: [PATCH 2/3] =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=88=D0=B8=D1=80=D0=B8?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=20=D0=BF=D0=BE=D1=80=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=20Tca9555=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=20=D0=9D=D0=BE=20=D1=82=D1=80=D0=B5=D0=B1=D1=83=D0=B5=D1=82?= =?UTF-8?q?=D1=81=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/exec/Tca9555/Tca9555.cpp | 98 +++++++++++++++++++++++++++ src/modules/exec/Tca9555/modinfo.json | 47 +++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 src/modules/exec/Tca9555/Tca9555.cpp create mode 100644 src/modules/exec/Tca9555/modinfo.json diff --git a/src/modules/exec/Tca9555/Tca9555.cpp b/src/modules/exec/Tca9555/Tca9555.cpp new file mode 100644 index 00000000..58007543 --- /dev/null +++ b/src/modules/exec/Tca9555/Tca9555.cpp @@ -0,0 +1,98 @@ +#include "Global.h" +#include "classes/IoTItem.h" +#include "classes/IoTGpio.h" +#include "Wire.h" +#include "TCA9555.h" + + +class Tca9555Driver : public IoTGpio { + private: + TCA9555* _tca; + + public: + Tca9555Driver(int index, TCA9555* tca) : IoTGpio(index) { + _tca = tca; + } + + void pinMode(int pin, uint8_t mode) { + _tca->pinMode1(pin, mode); + } + + void digitalWrite(int pin, uint8_t val) { + _tca->write1(pin, val); + } + + int digitalRead(int pin) { + return _tca->read1(pin); + } + + void digitalInvert(int pin) { + _tca->write1(pin, 1 - _tca->read1(pin)); + } + + ~Tca9555Driver() {}; +}; + + +class Tca9555 : public IoTItem { + private: + String _addr; + Tca9555Driver* _driver; + + public: + Tca9555(String parameters) : IoTItem(parameters) { + _driver = nullptr; + Wire.begin(); + + jsonRead(parameters, "addr", _addr); + if (_addr == "") { + scanI2C(); + return; + } + + int index; + jsonRead(parameters, "index", index); + if (index > 4) { + Serial.println(F("TCA9555 wrong index. Must be 0 - 4")); + return; + } + + int mktype; + TCA9555* tca; + jsonRead(parameters, "mktype", mktype); + if (mktype == 35) { + tca = new TCA9535(hexStringToUint8(_addr)); + } else if (mktype == 55) { + tca = new TCA9555(hexStringToUint8(_addr)); + } else { + Serial.println(F("TCA9555 wrong type. Must be 35 or 55")); + return; + } + + _driver = new Tca9555Driver(index, tca); + } + + void doByInterval() { + if (_addr == "") { + scanI2C(); + return; + } + } + + //возвращает ссылку на экземпляр класса Tca9555Driver + IoTGpio* getGpioDriver() { + return _driver; + } + + ~Tca9555() { + delete _driver; + }; +}; + +void* getAPI_Tca9555(String subtype, String param) { + if (subtype == F("Tca9555")) { + return new Tca9555(param); + } else { + return nullptr; + } +} diff --git a/src/modules/exec/Tca9555/modinfo.json b/src/modules/exec/Tca9555/modinfo.json new file mode 100644 index 00000000..2a4c8b34 --- /dev/null +++ b/src/modules/exec/Tca9555/modinfo.json @@ -0,0 +1,47 @@ +{ + "menuSection": "executive_devices", + "configItem": [ + { + "global": 0, + "name": "Расширитель портов Tca9555", + "type": "Reading", + "subtype": "Tca9555", + "id": "Tca", + "widget": "", + "page": "", + "descr": "", + + "mktype": 55, + "addr": "0x20", + "index": 1 + } + ], + "about": { + "authorName": "Ilya Belyakov", + "authorContact": "https://t.me/Biveraxe", + "authorGit": "https://github.com/biveraxe", + "specialThanks": "", + "moduleName": "Tca9555", + "moduleVersion": "1.0", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "Расширитель портов Tca9555", + "moduleDesc": "Добавляет в систему дополнительные GPIO для элементов, которые поддерживают такую функцию.", + "propInfo": { + "mktype": "Тип устройства: 55 - TCA9555, 35 - TCA9535", + "addr": "Адрес устройства на шине, обычно 0x20", + "index": "Значения от 1 до 4, где при выборе 1 будет нумерация pin 100-115, при выборе 2 200-215 и т.д." + } + }, + "defActive": false, + "usedLibs": { + "esp32*": [ + "https://github.com/RobTillaart/TCA9555" + ], + "esp82*": [ + "https://github.com/RobTillaart/TCA9555" + ] + } +} \ No newline at end of file From 0f8fa70a566b7b3646773f95aecc9522f396805d Mon Sep 17 00:00:00 2001 From: Mit4el Date: Tue, 7 Jan 2025 13:33:48 +0300 Subject: [PATCH 3/3] =?UTF-8?q?fix=20=D0=B4=D0=B0=D1=82=D1=8B=20=D0=B2=20?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=BA=D0=B0=D1=85,=20fix=20?= =?UTF-8?q?=D1=81=D1=80=D0=B5=D0=B4=D0=BD=D0=B5=D0=B5=20AnalogAdc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/NTP.cpp | 47 ++++++++++----------- src/modules/sensors/AnalogAdc/AnalogAdc.cpp | 5 ++- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/NTP.cpp b/src/NTP.cpp index f43654ce..ba0cbe37 100644 --- a/src/NTP.cpp +++ b/src/NTP.cpp @@ -156,33 +156,30 @@ const String getTodayDateDotFormated() { // format 22.02.2022 unsigned long strDateToUnix(String date) { - int day = selectToMarker(date, ".").toInt(); - date = deleteBeforeDelimiter(date, "."); - int month = selectToMarker(date, ".").toInt(); - date = deleteBeforeDelimiter(date, "."); - int year = selectToMarker(date, ".").toInt(); - int secsInOneDay = 86400; - int daysInOneYear = 365; - int daysInLeepYear = 366; - int numberOfLeepYears = 12; - int totalNormalYears = year - 1970 - numberOfLeepYears; + int day, month, year; unsigned int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - if (year % 4 == 0) { - if (year % 100 != 0 || year % 400 == 0) { - daysInMonth[1] = 29; - } else { - daysInMonth[1] = 28; - } - } else { - daysInMonth[1] = 28; - } - int numberOfDaysInPastMonths = 0; - for (int i = 0; i <= 11; i++) { - if (i <= month - 2) { - numberOfDaysInPastMonths = numberOfDaysInPastMonths + daysInMonth[i]; - } + + day = date.substring(0, date.indexOf(".")).toInt(); + date = date.substring(date.indexOf(".") + 1); + month = date.substring(0, date.indexOf(".")).toInt(); + date = date.substring(date.indexOf(".") + 1); + year = date.toInt(); + + unsigned long unixTime = (year - 1970) * 365 * 86400; + int numberOfLeepYears = (year - 1968) / 4 - (year - 1900) / 100 + (year - 1600) / 400; + unixTime += numberOfLeepYears * 86400; + + if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) { + daysInMonth[1] = 29; } - return (day * secsInOneDay) + (numberOfDaysInPastMonths * secsInOneDay) + (totalNormalYears * daysInOneYear * secsInOneDay) + (numberOfLeepYears * daysInLeepYear * secsInOneDay); + + for (int i = 0; i < month - 1; i++) { + unixTime += daysInMonth[i] * 86400; + } + + unixTime += (day - 1) * 86400; + + return unixTime; } const String getDateTimeDotFormatedFromUnix(unsigned long unixTime) { diff --git a/src/modules/sensors/AnalogAdc/AnalogAdc.cpp b/src/modules/sensors/AnalogAdc/AnalogAdc.cpp index 510d5723..4ee91d51 100644 --- a/src/modules/sensors/AnalogAdc/AnalogAdc.cpp +++ b/src/modules/sensors/AnalogAdc/AnalogAdc.cpp @@ -17,6 +17,7 @@ class AnalogAdc : public IoTItem { unsigned int _pin; unsigned int _avgSteps, _avgCount; unsigned long _avgSumm; + float adCresult; public: //======================================================================================================= @@ -45,6 +46,7 @@ class AnalogAdc : public IoTItem { // и выполнить за несколько тактов void doByInterval() { if (_avgSteps <= 1) value.valD = IoTgpio.analogRead(_pin); + value.valD = adCresult;/// regEvent(value.valD, "AnalogAdc"); //обязательный вызов хотяб один } @@ -56,7 +58,8 @@ class AnalogAdc : public IoTItem { void loop() { if (_avgSteps > 1) { if (_avgCount > _avgSteps) { - value.valD = _avgSumm / _avgSteps; + // value.valD = _avgSumm / (_avgSteps + 1); + adCresult = _avgSumm / (_avgSteps + 1); _avgSumm = 0; _avgCount = 0; }