diff --git a/data_esp/items/items.txt b/data_esp/items/items.txt index ece28a84..c7e7a660 100644 --- a/data_esp/items/items.txt +++ b/data_esp/items/items.txt @@ -38,5 +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;LCD2004;lcdid;anydata;Вывод;Пример;1;addr[0х27];pin[16,2];int[10];c[0,0];val[ip]* +0;LCD2004;lcdid;anydata;Вывод;IP;1;addr[0х27];k[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/data_esp/set.device.json.gz b/data_esp/set.device.json.gz index f484816e..bd42d625 100644 Binary files a/data_esp/set.device.json.gz and b/data_esp/set.device.json.gz differ diff --git a/include/items/vSensorLCD2004.h b/include/items/vSensorLCD2004.h index d9c7379f..1b677c89 100644 --- a/include/items/vSensorLCD2004.h +++ b/include/items/vSensorLCD2004.h @@ -3,6 +3,8 @@ #include #include #include "Global.h" +#include "LiquidCrystal_I2C.h" +#include "LiquidCrystal.h" class SensorLCD2004; @@ -10,7 +12,7 @@ typedef std::vector MySensorLCD2004Vector; class SensorLCD2004 { public: - SensorLCD2004(unsigned long interval, unsigned int pin, unsigned int index, String addr, String key); + SensorLCD2004(String key, unsigned long interval, unsigned int x, unsigned int y, String val, String descr); ~SensorLCD2004(); void loop(); @@ -20,11 +22,13 @@ class SensorLCD2004 { unsigned long currentMillis; unsigned long prevMillis; unsigned long difference; + unsigned long _interval; + unsigned int _x; + unsigned int _y; + String _val; String _key; - String _addr; - unsigned int _pin; - unsigned int _index; + String _descr; }; extern MySensorLCD2004Vector* mySensorLCD20042; diff --git a/platformio.ini b/platformio.ini index c7c184f2..da9411d9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -45,6 +45,7 @@ lib_deps = Adafruit AHTX0 LiquidCrystal_I2C BH1750 + fmalpartida/LiquidCrystal@^1.5.0 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -73,6 +74,7 @@ lib_deps = Adafruit AHTX0 LiquidCrystal_I2C BH1750 + fmalpartida/LiquidCrystal@^1.5.0 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -90,6 +92,7 @@ lib_deps = ESPAsyncUDP CTBot @2.1.6 MySensors @2.3.2 + fmalpartida/LiquidCrystal@^1.5.0 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -119,6 +122,7 @@ lib_deps = Adafruit AHTX0 LiquidCrystal_I2C BH1750 + fmalpartida/LiquidCrystal@^1.5.0 monitor_filters = esp32_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -138,6 +142,7 @@ lib_deps = ESP32 AnalogWrite ESP32Servo MySensors @2.3.2 + fmalpartida/LiquidCrystal@^1.5.0 monitor_filters = esp32_exception_decoder upload_speed = 921600 monitor_speed = 115200 diff --git a/src/items/vSensorLCD2004.cpp b/src/items/vSensorLCD2004.cpp index e859ee01..aca92d17 100644 --- a/src/items/vSensorLCD2004.cpp +++ b/src/items/vSensorLCD2004.cpp @@ -9,13 +9,17 @@ #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; +LiquidCrystal *LCDLPT; +LiquidCrystal_I2C *LCDI2C; + +SensorLCD2004::SensorLCD2004(String key, unsigned long interval, unsigned int x, unsigned int y, String val, String descr) { + _key = key; + _interval = interval * 1000; + _x = x; + _y = y; + _val = val; + _descr = descr; } @@ -31,36 +35,79 @@ void SensorLCD2004::loop() { } void SensorLCD2004::writeLCD2004() { - //if (_addr == "") { - // sensors->getAddress(deviceAddress, _index); - //} else { - // string2hex(_addr.c_str(), deviceAddress); - //} + String tmpStr; + tmpStr = getValue(_val); + if (tmpStr == "no value") tmpStr = _val; - + if (_descr != "none") tmpStr = _descr + " " + tmpStr; - //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)); + if(LCDI2C != nullptr) { + LCDI2C->setCursor(_x, _y); + LCDI2C->print(tmpStr); + } + + if(LCDLPT != nullptr) { + LCDLPT->setCursor(_x, _y); + LCDLPT->print(tmpStr); + } + + //eventGen2(_key, String(_val)); + //jsonWriteStr(configLiveJson, _key, String(_val)); + //publishStatus(_key, String(_val)); + SerialPrint("I", "Sensor", "'" + _key + "' data2: " + String(tmpStr)); } MySensorLCD2004Vector* mySensorLCD20042 = nullptr; void lcd2004() { myLineParsing.update(); - String interval = myLineParsing.gint(); - String pin = myLineParsing.gpin(); - String index = myLineParsing.gindex(); String key = myLineParsing.gkey(); + String pin = myLineParsing.gpin(); String addr = myLineParsing.gaddr(); + String interval = myLineParsing.gint(); + String c = myLineParsing.gc(); + String k = myLineParsing.gk(); + String val = myLineParsing.gval(); + String descr = myLineParsing.gdescr(); myLineParsing.clear(); + + int x = selectFromMarkerToMarker(c, ",", 0).toInt(); + int y = selectFromMarkerToMarker(c, ",", 1).toInt(); + int w = selectFromMarkerToMarker(k, ",", 1).toInt(); //количество столбцов + int h = selectFromMarkerToMarker(k, ",", 1).toInt(); //количество строк + + if (LCDI2C == nullptr && LCDLPT == nullptr) { //инициализации экрана еще не было + if (addr == "") { + int pin1 = selectFromMarkerToMarker(pin, ",", 0).toInt(); + int pin2 = selectFromMarkerToMarker(pin, ",", 1).toInt(); + int pin3 = selectFromMarkerToMarker(pin, ",", 2).toInt(); + int pin4 = selectFromMarkerToMarker(pin, ",", 3).toInt(); + int pin5 = selectFromMarkerToMarker(pin, ",", 4).toInt(); + int pin6 = selectFromMarkerToMarker(pin, ",", 5).toInt(); + int pin7 = selectFromMarkerToMarker(pin, ",", 6).toInt(); + int pin8 = selectFromMarkerToMarker(pin, ",", 7).toInt(); + int pin9 = selectFromMarkerToMarker(pin, ",", 8).toInt(); + int pin10 = selectFromMarkerToMarker(pin, ",", 9).toInt(); + if (pin7) { + LCDLPT = new LiquidCrystal(pin1, pin2, pin3, pin4, pin5, pin6, pin7, pin8, pin9, pin10); + } else { + LCDLPT = new LiquidCrystal(pin1, pin2, pin3, pin4, pin5, pin6); + } + if(LCDLPT != nullptr) LCDLPT->begin(w, h); + //val = (String)pin1 + " " + (String)pin2 + " " + (String)pin3 + " " + (String)pin4 + " " + (String)pin5 + " " + (String)pin6 + " " + (String)pin7 + " " + (String)pin8 + " " + (String)pin9 + " " + (String)pin10; + } else { + LCDI2C = new LiquidCrystal_I2C(hexStringToUint8(addr)); + if(LCDI2C != nullptr) { + LCDI2C->begin(w, h); + LCDI2C->backlight(); + } + } + } + static bool firstTime = true; if (firstTime) mySensorLCD20042 = new MySensorLCD2004Vector(); firstTime = false; - mySensorLCD20042->push_back(SensorLCD2004(interval.toInt(), pin.toInt(), index.toInt(), addr, key)); + mySensorLCD20042->push_back(SensorLCD2004(key, interval.toInt(), x, y, val, descr)); } #endif