From bd4753f2c9f2e24a4c747b4de108126c73274998 Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 22 Feb 2022 21:21:48 +0300 Subject: [PATCH 1/5] Merge branch 'ver4dev' --- src/modules/Aht20.cpp | 4 ++-- src/modules/Bme280.cpp | 29 ++++++++++++++++------------- src/modules/Bmp280.cpp | 22 ++++++++++++---------- src/modules/Dht1122.cpp | 34 ++++++++++++++++++---------------- src/modules/GY-21.cpp | 14 ++++++++------ src/modules/Mcp23017.cpp | 1 - src/modules/Sht20.cpp | 10 ++++++---- 7 files changed, 62 insertions(+), 52 deletions(-) diff --git a/src/modules/Aht20.cpp b/src/modules/Aht20.cpp index e59bdf35..d37034e9 100644 --- a/src/modules/Aht20.cpp +++ b/src/modules/Aht20.cpp @@ -22,7 +22,7 @@ class Aht20t : public IoTItem { void doByInterval() { value.valD = temp.temperature; - if (value.valD != -200) regEvent(value.valD, "Aht20t"); // todo: найти способ понимания ошибки получения данных + if (value.valD != -200) regEvent(value.valD, "Aht20t"); // TODO: найти способ понимания ошибки получения данных else SerialPrint("E", "Sensor AHTt", "Error"); } @@ -36,7 +36,7 @@ class Aht20h : public IoTItem { void doByInterval() { value.valD = humidity.relative_humidity; - if (value.valD != -200) regEvent(value.valD, "Aht20h"); // todo: найти способ понимания ошибки получения данных + if (value.valD != -200) regEvent(value.valD, "Aht20h"); // TODO: найти способ понимания ошибки получения данных else SerialPrint("E", "Sensor AHTt", "Error"); } diff --git a/src/modules/Bme280.cpp b/src/modules/Bme280.cpp index b32f4499..ca3589a0 100644 --- a/src/modules/Bme280.cpp +++ b/src/modules/Bme280.cpp @@ -73,21 +73,24 @@ class Bme280p : public IoTItem { ~Bme280p(); }; -void* getAPI_Bme280(String subtype, String param) { - String addr; - jsonRead(param, "addr", addr); - if (bmes.find(addr) == bmes.end()) { - bmes[addr] = new Adafruit_BME280(); - bmes[addr]->begin(hexStringToUint8(addr)); - } +void* getAPI_Bme280(String subtype, String param) { + if (subtype == F("Bme280t") || subtype == F("Bme280h") || subtype == F("Bme280p")) { + String addr; + jsonRead(param, "addr", addr); - if (subtype == F("Bme280t")) { - return new Bme280t(bmes[addr], param); - } else if (subtype == F("Bme280h")) { - return new Bme280h(bmes[addr], param); - } else if (subtype == F("Bme280p")) { - return new Bme280p(bmes[addr], param); + if (bmes.find(addr) == bmes.end()) { + bmes[addr] = new Adafruit_BME280(); + bmes[addr]->begin(hexStringToUint8(addr)); + } + + if (subtype == F("Bme280t")) { + return new Bme280t(bmes[addr], param); + } else if (subtype == F("Bme280h")) { + return new Bme280h(bmes[addr], param); + } else if (subtype == F("Bme280p")) { + return new Bme280p(bmes[addr], param); + } } else { return nullptr; } diff --git a/src/modules/Bmp280.cpp b/src/modules/Bmp280.cpp index 35686689..368c9bf7 100644 --- a/src/modules/Bmp280.cpp +++ b/src/modules/Bmp280.cpp @@ -55,18 +55,20 @@ class Bmp280p : public IoTItem { void* getAPI_Bmp280(String subtype, String param) { - String addr; - jsonRead(param, "addr", addr); + if (subtype == F("Bmp280t") || subtype == F("Bmp280p")) { + String addr; + jsonRead(param, "addr", addr); - if (bmps.find(addr) == bmps.end()) { - bmps[addr] = new Adafruit_BMP280(); - bmps[addr]->begin(hexStringToUint8(addr)); - } + if (bmps.find(addr) == bmps.end()) { + bmps[addr] = new Adafruit_BMP280(); + bmps[addr]->begin(hexStringToUint8(addr)); + } - if (subtype == F("Bmp280t")) { - return new Bmp280t(bmps[addr], param); - } else if (subtype == F("Bmp280p")) { - return new Bmp280p(bmps[addr], param); + if (subtype == F("Bmp280t")) { + return new Bmp280t(bmps[addr], param); + } else if (subtype == F("Bmp280p")) { + return new Bmp280p(bmps[addr], param); + } } else { return nullptr; } diff --git a/src/modules/Dht1122.cpp b/src/modules/Dht1122.cpp index 54e8495f..98ada9be 100644 --- a/src/modules/Dht1122.cpp +++ b/src/modules/Dht1122.cpp @@ -53,25 +53,27 @@ class Dht1122h : public IoTItem { void* getAPI_Dht1122(String subtype, String param) { - int pin; - String senstype; - jsonRead(param, "pin", pin); - jsonRead(param, "senstype", senstype); + if (subtype == F("Dht1122t") || subtype == F("Dht1122h")) { + int pin; + String senstype; + jsonRead(param, "pin", pin); + jsonRead(param, "senstype", senstype); - if (dhts.find(pin) == dhts.end()) { - dhts[pin] = new DHTesp(); - - if (senstype == "dht11") { - dhts[pin]->setup(pin, DHTesp::DHT11); - } else if (senstype == "dht22") { - dhts[pin]->setup(pin, DHTesp::DHT22); + if (dhts.find(pin) == dhts.end()) { + dhts[pin] = new DHTesp(); + + if (senstype == "dht11") { + dhts[pin]->setup(pin, DHTesp::DHT11); + } else if (senstype == "dht22") { + dhts[pin]->setup(pin, DHTesp::DHT22); + } } - } - if (subtype == F("Dht1122t")) { - return new Dht1122t(dhts[pin], param); - } else if (subtype == F("Dht1122h")) { - return new Dht1122h(dhts[pin], param); + if (subtype == F("Dht1122t")) { + return new Dht1122t(dhts[pin], param); + } else if (subtype == F("Dht1122h")) { + return new Dht1122h(dhts[pin], param); + } } else { return nullptr; } diff --git a/src/modules/GY-21.cpp b/src/modules/GY-21.cpp index b341fa2e..e430afde 100644 --- a/src/modules/GY-21.cpp +++ b/src/modules/GY-21.cpp @@ -20,7 +20,7 @@ class GY21t : public IoTItem { void doByInterval() { //wire->read(); value.valD = sensor->GY21_Temperature(); - if (value.valD < 300) regEvent(value.valD, "GY21"); // todo: найти способ понимания ошибки получения данных + if (value.valD < 300) regEvent(value.valD, "GY21"); // TODO: найти способ понимания ошибки получения данных else SerialPrint("E", "Sensor GY21t", "Error"); } @@ -34,7 +34,7 @@ class GY21h : public IoTItem { void doByInterval() { //sht->read(); value.valD = sensor->GY21_Humidity(); - if (value.valD != 0) regEvent(value.valD, "GY21h"); // todo: найти способ понимания ошибки получения данных + if (value.valD != 0) regEvent(value.valD, "GY21h"); // TODO: найти способ понимания ошибки получения данных else SerialPrint("E", "Sensor GY21h", "Error"); } @@ -42,16 +42,18 @@ class GY21h : public IoTItem { }; void* getAPI_GY21(String subtype, String param) { + if (subtype == F("GY21t") || subtype == F("GY21h")) { if (!sensor) { - sensor = new GY21; - if (sensor) Wire.begin(SDA, SCL); + sensor = new GY21; + if (sensor) Wire.begin(SDA, SCL); } if (subtype == F("GY21t")) { return new GY21t(param); } else if (subtype == F("GY21h")) { return new GY21h(param); - } else { - return nullptr; } + } else { + return nullptr; + } } \ No newline at end of file diff --git a/src/modules/Mcp23017.cpp b/src/modules/Mcp23017.cpp index 2c64d5a1..552ece0f 100644 --- a/src/modules/Mcp23017.cpp +++ b/src/modules/Mcp23017.cpp @@ -43,7 +43,6 @@ class Mcp23017 : public IoTItem, IoTGpio { void* getAPI_Mcp23017(String subtype, String param) { if (subtype == F("Mcp23017")) { String addr; - uint8_t deviceAddress[1]; jsonRead(param, "addr", addr); Serial.printf("deviceAddress %s = %02x \n", addr.c_str(), hexStringToUint8(addr)); diff --git a/src/modules/Sht20.cpp b/src/modules/Sht20.cpp index 82d8d2ca..af677033 100644 --- a/src/modules/Sht20.cpp +++ b/src/modules/Sht20.cpp @@ -37,16 +37,18 @@ class Sht20h : public IoTItem { void* getAPI_Sht20(String subtype, String param) { + if (subtype == F("Sht20t") || subtype == F("Sht20h")) { if (!sht) { - sht = new SHT2x; - if (sht) sht->begin(); + sht = new SHT2x; + if (sht) sht->begin(); } if (subtype == F("Sht20t")) { return new Sht20t(param); } else if (subtype == F("Sht20h")) { return new Sht20h(param); - } else { - return nullptr; } + } else { + return nullptr; + } } From df6d328cc49e9790db2e5b993273f1cbc6e4a854 Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 22 Feb 2022 21:35:50 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=A3=D1=81=D1=82=D1=80=D0=B0=D0=BD=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=BD=D0=B5=D1=82=D0=BE=D1=87=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8=20=D0=B2=20=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 1 + src/classes/IoTGpio.cpp | 2 +- src/classes/IoTItem.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/data_svelte/items.json b/data_svelte/items.json index 3a275f6b..e4f24006 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -304,6 +304,7 @@ "page": "", "descr": "", + "int": "0", "addr": "0x20", "index": 1 } diff --git a/src/classes/IoTGpio.cpp b/src/classes/IoTGpio.cpp index 18ea2f6d..161a6348 100644 --- a/src/classes/IoTGpio.cpp +++ b/src/classes/IoTGpio.cpp @@ -40,7 +40,7 @@ void IoTGpio::analogWrite(uint8_t pin, int val) { if (_drivers[pinH]) _drivers[pinH]->analogWrite(pin - pinH*100, val); else { #ifdef ESP32 - // todo: написать для esp32 аналог функции analogWrite + // TODO: написать для esp32 аналог функции analogWrite #endif #ifdef ESP8266 ::analogWrite(pin, val); diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 59d6c643..64ff1422 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -63,7 +63,7 @@ void IoTItem::regEvent(float value, String consoleInfo = "") { value = value / _round; } - // value = (float)value / (_round ? pow(10, (int)_round) : 1); // todo: решить как указывать округление, количество знаков после запятой или десятые сотые ... + // value = (float)value / (_round ? pow(10, (int)_round) : 1); // TODO: решить как указывать округление, количество знаков после запятой или десятые сотые ... } if (_map1 != _map2) value = map(value, _map1, _map2, _map3, _map4); From 3a9775df5d896668e8e4188f194988a71937a4dc Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 22 Feb 2022 22:47:21 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20ButtonOut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 17 ++++++++++++ src/modules/API.cpp | 2 ++ src/modules/ButtonOut.cpp | 58 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/modules/ButtonOut.cpp diff --git a/data_svelte/items.json b/data_svelte/items.json index e4f24006..d712b55c 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -307,5 +307,22 @@ "int": "0", "addr": "0x20", "index": 1 + }, + { + "header": "Исполнительные устройства" + }, + { + "name": "23. Доп. функции системы", + "num": 23, + "type": "Writing", + "subtype": "ButtonOut", + "id": "btn", + "widget": "", + "page": "", + "descr": "", + "int": 0, + + "inv": 0, + "pin": 2 } ] \ No newline at end of file diff --git a/src/modules/API.cpp b/src/modules/API.cpp index e15fad73..3ee9b279 100644 --- a/src/modules/API.cpp +++ b/src/modules/API.cpp @@ -15,6 +15,7 @@ void* getAPI_Lcd2004(String subtype, String params); void* getAPI_SysExt(String subtype, String params); void* getAPI_Ads1115(String subtype, String params); void* getAPI_Mcp23017(String subtype, String params); +void* getAPI_ButtonOut(String subtype, String params); //============================================================================================ void* getAPI(String subtype, String params) { @@ -34,6 +35,7 @@ void* getAPI(String subtype, String params) { if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Ads1115(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI; + if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI; //================================================================================================================ return nullptr; diff --git a/src/modules/ButtonOut.cpp b/src/modules/ButtonOut.cpp new file mode 100644 index 00000000..d76e563a --- /dev/null +++ b/src/modules/ButtonOut.cpp @@ -0,0 +1,58 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +extern IoTGpio IoTgpio; + + +class ButtonOut : public IoTItem { + private: + int _pin, _inv; + + public: + ButtonOut(String parameters): IoTItem(parameters) { + jsonRead(parameters, "pin", _pin); + jsonRead(parameters, "inv", _inv); + + IoTgpio.pinMode(_pin, OUTPUT); + //TODO: прочитать состояние из памяти + IoTgpio.digitalWrite(_pin, LOW); // пока нет памяти, устанавливаем значение в ноль + value.valD = 0; + } + + void doByInterval() { + //value.valD = IoTgpio.analogRead(_pin); + + //regEvent(value.valD, "ButtonOut"); //обязательный вызов хотяб один + } + + IoTValue execute(String command, std::vector ¶m) { + // реакция на вызов команды модуля из сценария + // String command - имя команды после ID. (ID.Команда()) + // param - вектор ("массив") значений параметров переданных вместе с командой: ID.Команда("пар1", 22, 33) -> param[0].ValS = "пар1", param[1].ValD = 22 + + if (command == "change") { // выполняем код при вызове спец команды из сценария: ID.reboot(); + value.valD = !IoTgpio.digitalRead(_pin); + IoTgpio.digitalWrite(_pin, value.valD); + } + + return {}; // команда поддерживает возвращаемое значения. Т.е. по итогу выполнения команды или общения с внешней системой, можно вернуть значение в сценарий для дальнейшей обработки + } + + void setValue(IoTValue Value) { + value = Value; + IoTgpio.digitalWrite(_pin, value.valD); + if (value.isDecimal) regEvent(value.valD, "ButtonOut"); + else regEvent(value.valS, "ButtonOut"); + } + //======================================================================================================= + + ~ButtonOut(); +}; + +void* getAPI_ButtonOut(String subtype, String param) { + if (subtype == F("ButtonOut")) { + return new ButtonOut(param); + } else { + return nullptr; + } +} From a69e048da96f9c172995775ea48b95467830d040 Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 22 Feb 2022 22:48:35 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=A1=D1=82=D0=B0=D0=BD=D0=B4=D0=B0=D1=80?= =?UTF-8?q?=D1=82=D0=B8=D0=B7=D0=B8=D1=80=D1=83=D0=B5=D0=BC=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=20=D0=BF=D1=80=D0=B8=20=D0=B2=D1=8B=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=BF=D1=80=D0=B8=D1=81=D0=B2=D0=B0=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=B7=20=D1=81=D1=86=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=D1=80=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 | 6 ++++++ src/classes/IoTScenario.cpp | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/classes/IoTItem.h b/include/classes/IoTItem.h index 7d012b7d..e15c48e5 100644 --- a/include/classes/IoTItem.h +++ b/include/classes/IoTItem.h @@ -29,6 +29,7 @@ class IoTItem { IoTValue value; // хранение основного значения, котрое обновляется из сценария, execute(), loop() или doByInterval() virtual IoTGpio* getGpioDriver(); + virtual void setValue(IoTValue Value); protected: String _subtype; diff --git a/src/classes/IoTItem.cpp b/src/classes/IoTItem.cpp index 850cbae5..f3d9ac12 100644 --- a/src/classes/IoTItem.cpp +++ b/src/classes/IoTItem.cpp @@ -90,4 +90,10 @@ IoTItem* myIoTItem; IoTGpio* IoTItem::getGpioDriver() { return nullptr; +} + +void IoTItem::setValue(IoTValue Value) { + value = Value; + if (value.isDecimal) regEvent(value.valD, ""); + else regEvent(value.valS, ""); } \ No newline at end of file diff --git a/src/classes/IoTScenario.cpp b/src/classes/IoTScenario.cpp index 255d26ad..22b5b73d 100644 --- a/src/classes/IoTScenario.cpp +++ b/src/classes/IoTScenario.cpp @@ -64,7 +64,10 @@ public: VariableExprAST(const String &name, IoTItem* item) : Name(name), Item(item) {} int setValue(IoTValue *val) { - Item->value = *val; // устанавливаем значение в связанном Item модуля напрямую + if (Item) { + //Item->value = *val; // устанавливаем значение в связанном Item модуля напрямую + Item->setValue(*val); + } return 1; } From 729c126405cd2cee185958efdf1bd04d50cd6db4 Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 22 Feb 2022 23:01:01 +0300 Subject: [PATCH 5/5] =?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=D0=B8=20?= =?UTF-8?q?=D0=B2=20=D0=BD=D0=B0=D1=89=D0=B2=D0=B0=D0=BD=D0=B8=D0=B8=20?= =?UTF-8?q?=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=20ButtonOut=20?= =?UTF-8?q?=D0=B2=20=D0=B2=D0=B5=D0=B1=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_svelte/items.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data_svelte/items.json b/data_svelte/items.json index d712b55c..61a235e0 100644 --- a/data_svelte/items.json +++ b/data_svelte/items.json @@ -312,13 +312,13 @@ "header": "Исполнительные устройства" }, { - "name": "23. Доп. функции системы", + "name": "23. Кнопка управляющая пином (Реле с кнопкой)", "num": 23, "type": "Writing", "subtype": "ButtonOut", "id": "btn", - "widget": "", - "page": "", + "widget": "button", + "page": "Кнопки", "descr": "", "int": 0,