Исключаем поддержку параллельного подключения LCD2004 и наводим порядок с библиотеками.

This commit is contained in:
2022-01-12 10:00:19 +03:00
parent 3787959f52
commit 46a87ebe26
6 changed files with 54 additions and 58 deletions

View File

@@ -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;Вывод;IP;1;addr[0х27];k[16,2];int[10];c[0,0];val[ip]*
0;LCD2004;lcdid;anydata;Вывод;IP;1;addr[0x27];k[16,2];int[10];c[0,0];val[ip]*
0;sensor;anyid;anydata;Сенсоры;Параметр;1;c[1];int[10];type[type1];addr[0x76]*

Binary file not shown.

View File

@@ -4,7 +4,7 @@
#include <OneWire.h>
#include "Global.h"
#include "LiquidCrystal_I2C.h"
#include "LiquidCrystal.h"
class SensorLCD2004;
@@ -17,6 +17,8 @@ class SensorLCD2004 {
void loop();
void writeLCD2004();
void execute(String command);
String _key;
private:
unsigned long currentMillis;
@@ -27,8 +29,8 @@ class SensorLCD2004 {
unsigned int _x;
unsigned int _y;
String _val;
String _key;
String _descr;
int _prevStrSize;
};
extern MySensorLCD2004Vector* mySensorLCD20042;

View File

@@ -43,9 +43,8 @@ lib_deps =
robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080
Adafruit AHTX0
LiquidCrystal_I2C
BH1750
fmalpartida/LiquidCrystal@^1.5.0
marcoschwartz/LiquidCrystal_I2C@^1.1.4
monitor_filters = esp8266_exception_decoder
upload_speed = 921600
monitor_speed = 115200
@@ -72,9 +71,8 @@ lib_deps =
robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080
Adafruit AHTX0
LiquidCrystal_I2C
BH1750
fmalpartida/LiquidCrystal@^1.5.0
marcoschwartz/LiquidCrystal_I2C@^1.1.4
monitor_filters = esp8266_exception_decoder
upload_speed = 921600
monitor_speed = 115200
@@ -92,7 +90,7 @@ lib_deps =
ESPAsyncUDP
CTBot @2.1.6
MySensors @2.3.2
fmalpartida/LiquidCrystal@^1.5.0
marcoschwartz/LiquidCrystal_I2C@^1.1.4
monitor_filters = esp8266_exception_decoder
upload_speed = 921600
monitor_speed = 115200
@@ -120,9 +118,8 @@ lib_deps =
robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080
Adafruit AHTX0
LiquidCrystal_I2C
BH1750
fmalpartida/LiquidCrystal@^1.5.0
marcoschwartz/LiquidCrystal_I2C@^1.1.4
monitor_filters = esp32_exception_decoder
upload_speed = 921600
monitor_speed = 115200
@@ -143,6 +140,7 @@ lib_deps =
ESP32Servo
MySensors @2.3.2
fmalpartida/LiquidCrystal@^1.5.0
marcoschwartz/LiquidCrystal_I2C@^1.1.4
monitor_filters = esp32_exception_decoder
upload_speed = 921600
monitor_speed = 115200

View File

@@ -24,6 +24,10 @@
#include "items/vSensorUltrasonic.h"
#include "items/vSensorUptime.h"
#ifdef EnableSensorLCD2004
extern LiquidCrystal_I2C *LCDI2C;
#endif
void loadConfig() {
configSetupJson = readFile("config.json", 4096);
configSetupJson.replace("\r\n", "");
@@ -172,7 +176,9 @@ void clearVectors() {
#endif
#ifdef EnableSensorLCD2004
if (mySensorLCD20042 != nullptr) {
if(LCDI2C != nullptr) LCDI2C->clear();
mySensorLCD20042->clear();
}
#endif
#ifdef EnableSensorUltrasonic

View File

@@ -9,8 +9,6 @@
#include <Arduino.h>
LiquidCrystal *LCDLPT;
LiquidCrystal_I2C *LCDI2C;
SensorLCD2004::SensorLCD2004(String key, unsigned long interval, unsigned int x, unsigned int y, String val, String descr) {
@@ -20,11 +18,18 @@ SensorLCD2004::SensorLCD2004(String key, unsigned long interval, unsigned int x,
_y = y;
_val = val;
_descr = descr;
_prevStrSize = 0;
}
SensorLCD2004::~SensorLCD2004() {}
void SensorLCD2004::execute(String command) {
//if (command == "back")
String par = sCmd.next();
//SerialPrint("I", "execute", command + " " + par);
}
void SensorLCD2004::loop() {
currentMillis = millis();
difference = currentMillis - prevMillis;
@@ -35,34 +40,36 @@ void SensorLCD2004::loop() {
}
void SensorLCD2004::writeLCD2004() {
String tmpStr;
tmpStr = getValue(_val);
if (tmpStr == "no value") tmpStr = _val;
if (_descr != "none") tmpStr = _descr + " " + tmpStr;
if(LCDI2C != nullptr) {
if (LCDI2C != nullptr) {
String tmpStr = "";
for(int i=0; i<_prevStrSize; i++) tmpStr += " ";
LCDI2C->setCursor(_x, _y);
LCDI2C->print(tmpStr);
}
LCDI2C->print(tmpStr);
if(LCDLPT != nullptr) {
LCDLPT->setCursor(_x, _y);
LCDLPT->print(tmpStr);
}
tmpStr = getValue(_val);
if (tmpStr == "no value") tmpStr = _val;
if (_descr != "none") tmpStr = _descr + " " + tmpStr;
LCDI2C->setCursor(_x, _y);
LCDI2C->print(tmpStr);
//eventGen2(_key, String(_val));
//jsonWriteStr(configLiveJson, _key, String(_val));
//publishStatus(_key, String(_val));
SerialPrint("I", "Sensor", "'" + _key + "' data2: " + String(tmpStr));
_prevStrSize = tmpStr.length();
}
}
MySensorLCD2004Vector* mySensorLCD20042 = nullptr;
void lcd2004Execute() {
String key = sCmd.order();
String command = sCmd.next();
for (unsigned int i = 0; i < mySensorLCD20042->size(); i++) {
if (mySensorLCD20042->at(i)._key == key) mySensorLCD20042->at(i).execute(command);
}
}
void lcd2004() {
myLineParsing.update();
String key = myLineParsing.gkey();
String pin = myLineParsing.gpin();
String addr = myLineParsing.gaddr();
String interval = myLineParsing.gint();
String c = myLineParsing.gc();
@@ -73,35 +80,15 @@ void lcd2004() {
int x = selectFromMarkerToMarker(c, ",", 0).toInt();
int y = selectFromMarkerToMarker(c, ",", 1).toInt();
int w = selectFromMarkerToMarker(k, ",", 1).toInt(); //количество столбцов
int w = selectFromMarkerToMarker(k, ",", 0).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();
}
}
if (LCDI2C == nullptr) { //инициализации экрана еще не было
LCDI2C = new LiquidCrystal_I2C(hexStringToUint8(addr), w, h);//hexStringToUint8(addr), w, h);
if(LCDI2C != nullptr) {
LCDI2C->init();
LCDI2C->backlight();
}
}
@@ -109,5 +96,8 @@ void lcd2004() {
if (firstTime) mySensorLCD20042 = new MySensorLCD2004Vector();
firstTime = false;
mySensorLCD20042->push_back(SensorLCD2004(key, interval.toInt(), x, y, val, descr));
sCmd.addCommand(key.c_str(), lcd2004Execute);
}
#endif