From d78907d854d48b30a411d7ae0320b453779a08de Mon Sep 17 00:00:00 2001 From: biver Date: Wed, 5 Jan 2022 17:49:33 +0300 Subject: [PATCH] =?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=BD=D0=B5=D0=BE=D0=B1=D1=85=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D0=BC=D1=8B=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D0=B5=20=D0=B7=D0=B0=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B8=20=D0=B2=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D0=B2?= =?UTF-8?q?=D0=B5=D0=B9=D1=81=20=D0=B4=D0=BB=D1=8F=20=D1=8D=D0=BA=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=20LCD2004?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_esp/items/items.txt | 3 +- include/Consts.h | 1 + include/items/vSensorLCD2004.h | 35 ++++++++++++++++++ src/items/vSensorLCD2004.cpp | 66 ++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 include/items/vSensorLCD2004.h create mode 100644 src/items/vSensorLCD2004.cpp diff --git a/data_esp/items/items.txt b/data_esp/items/items.txt index 5e43e747..ece28a84 100644 --- a/data_esp/items/items.txt +++ b/data_esp/items/items.txt @@ -38,6 +38,5 @@ 0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[HDC1080_hum];addr[0x76]* 0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[AHTX0_temp];addr[0x76] 0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[AHTX0_hum];addr[0x76]* -0;sensor;anyid;anydata;Page;Tmp;1;c[0];k[0];int[10];type[LCD];val[any] -0;sensor;anyid;anydata;Page;Hum;1;c[8];k[1];int[10];type[LCD];val[any]* +0;LCD2004;lcdid;anydata;Вывод;Пример;1;addr[0х27];pin[16,2];int[10];c[0,0];val[ip]* 0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[type1];addr[0x76]* \ No newline at end of file diff --git a/include/Consts.h b/include/Consts.h index e0d1740a..1738cd18 100644 --- a/include/Consts.h +++ b/include/Consts.h @@ -87,6 +87,7 @@ #define EnableSensorAny #define EnableTelegram #define EnableUart +#define EnableSensorLCD2004 #endif #ifdef GATE_MODE diff --git a/include/items/vSensorLCD2004.h b/include/items/vSensorLCD2004.h new file mode 100644 index 00000000..39555cd6 --- /dev/null +++ b/include/items/vSensorLCD2004.h @@ -0,0 +1,35 @@ +#ifdef EnableSensorLCD2004 +#pragma once +#include +#include +#include "Global.h" + +//ИНТЕГРИРУЮ: следим за наименованиями далее +class SensorLCD2004; + +typedef std::vector MySensorLCD2004Vector; + +class SensorLCD2004 { + public: + //ИНТЕГРИРУЮ: обращаем внимание на параметры, берутся из таблицы настроек + SensorLCD2004(unsigned long interval, unsigned int pin, unsigned int index, String addr, String key); + ~SensorLCD2004(); + + void loop(); + void readLCD2004(); + + private: + unsigned long currentMillis; + unsigned long prevMillis; + unsigned long difference; + unsigned long _interval; + String _key; + String _addr; + unsigned int _pin; + unsigned int _index; +}; + +extern MySensorLCD2004Vector* mySensorLCD20042; + +extern void LCD2004(); +#endif diff --git a/src/items/vSensorLCD2004.cpp b/src/items/vSensorLCD2004.cpp new file mode 100644 index 00000000..e37f6e9f --- /dev/null +++ b/src/items/vSensorLCD2004.cpp @@ -0,0 +1,66 @@ +#include "Consts.h" +#ifdef EnableSensorLCD2004 +#include "items/vSensorLCD2004.h" +#include "BufferExecute.h" +#include "Class/LineParsing.h" +#include "Global.h" +#include "Utils/StringUtils.h" +#include + +#include + +SensorLCD2004::SensorLCD2004(unsigned long interval, unsigned int pin, unsigned int index, String addr, String key) { + _interval = interval * 1000; + _key = key; + _pin = pin; + _index = index; + _addr = addr; + + +} + +SensorLCD2004::~SensorLCD2004() {} + +void SensorLCD2004::loop() { + currentMillis = millis(); + difference = currentMillis - prevMillis; + if (difference >= _interval) { + prevMillis = millis(); + readLCD2004(); + } +} + +void SensorLCD2004::readLCD2004() { + //if (_addr == "") { + // sensors->getAddress(deviceAddress, _index); + //} else { + // string2hex(_addr.c_str(), deviceAddress); + //} + + + + //eventGen2(_key, String(value)); + //jsonWriteStr(configLiveJson, _key, String(value)); + //publishStatus(_key, String(value)); + //char addrStr[20] = ""; + //hex2string(deviceAddress, 8, addrStr); + //SerialPrint("I", "Sensor", "'" + _key + "' data: " + String(value) + "' addr: " + String(addrStr)); +} + +MySensorLCD2004Vector* mySensorLCD20042 = nullptr; + +void LCD2004() { + myLineParsing.update(); + String interval = myLineParsing.gint(); + String pin = myLineParsing.gpin(); + String index = myLineParsing.gindex(); + String key = myLineParsing.gkey(); + String addr = myLineParsing.gaddr(); + myLineParsing.clear(); + + static bool firstTime = true; + if (firstTime) mySensorLCD20042 = new MySensorLCD2004Vector(); + firstTime = false; + mySensorLCD20042->push_back(SensorLCD2004(interval.toInt(), pin.toInt(), index.toInt(), addr, key)); +} +#endif