Merge pull request #114 from biveraxe/ver3

Поддержка LCD 2004 и 1602
This commit is contained in:
Dmitry Borisenko
2022-01-12 13:11:06 +01:00
committed by GitHub
11 changed files with 239 additions and 31 deletions

View File

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

Binary file not shown.

View File

@@ -127,6 +127,7 @@ class LineParsing {
} }
if (_pin != "") { if (_pin != "") {
/*
if (_pin.indexOf(",") == -1) { if (_pin.indexOf(",") == -1) {
if (!isPinExist(_pin.toInt()) || !isDigitStr(_pin)) { if (!isPinExist(_pin.toInt()) || !isDigitStr(_pin)) {
pinErrors++; pinErrors++;
@@ -139,6 +140,17 @@ class LineParsing {
pinErrors++; pinErrors++;
_pin = ""; _pin = "";
} }
}*/
String tmpstr;
for (int i=0; i<15; i++) {
tmpstr = selectFromMarkerToMarker(_pin, ",", i);
if(tmpstr == "not found") break;
if(!isDigitStr(tmpstr) || !isPinExist(tmpstr.toInt())){
pinErrors++;
_pin = "";
break;
}
} }
} }

View File

@@ -53,7 +53,7 @@
#define NUM_BUTTONS 8 #define NUM_BUTTONS 8
#endif #endif
#define MQTT_RECONNECT_INTERVAL 20000 #define MQTT_RECONNECT_INTERVAL 60000
#define CHANGE_BROKER_AFTER 5 #define CHANGE_BROKER_AFTER 5
#define TELEMETRY_UPDATE_INTERVAL_MIN 60 #define TELEMETRY_UPDATE_INTERVAL_MIN 60
#define DEVICE_CONFIG_FILE "s.conf.csv" #define DEVICE_CONFIG_FILE "s.conf.csv"
@@ -87,6 +87,7 @@
#define EnableSensorAny #define EnableSensorAny
#define EnableTelegram #define EnableTelegram
#define EnableUart #define EnableUart
#define EnableSensorLCD2004
#endif #endif
#ifdef GATE_MODE #ifdef GATE_MODE

View File

@@ -0,0 +1,40 @@
#ifdef EnableSensorLCD2004
#pragma once
#include <Arduino.h>
#include <OneWire.h>
#include "Global.h"
#include "LiquidCrystal_I2C.h"
class SensorLCD2004;
typedef std::vector<SensorLCD2004> MySensorLCD2004Vector;
class SensorLCD2004 {
public:
SensorLCD2004(String key, unsigned long interval, unsigned int x, unsigned int y, String val, String descr);
~SensorLCD2004();
void loop();
void writeLCD2004();
void execute(String command);
String _key;
void printBlankStr(int strSize);
private:
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long difference;
unsigned long _interval;
unsigned int _x;
unsigned int _y;
String _val;
String _descr;
int _prevStrSize;
};
extern MySensorLCD2004Vector* mySensorLCD20042;
extern void lcd2004();
#endif

View File

@@ -43,8 +43,8 @@ lib_deps =
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080 ClosedCube HDC1080
Adafruit AHTX0 Adafruit AHTX0
LiquidCrystal_I2C
BH1750 BH1750
marcoschwartz/LiquidCrystal_I2C@^1.1.4
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -71,8 +71,8 @@ lib_deps =
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080 ClosedCube HDC1080
Adafruit AHTX0 Adafruit AHTX0
LiquidCrystal_I2C
BH1750 BH1750
marcoschwartz/LiquidCrystal_I2C@^1.1.4
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -90,6 +90,7 @@ lib_deps =
ESPAsyncUDP ESPAsyncUDP
CTBot @2.1.6 CTBot @2.1.6
MySensors @2.3.2 MySensors @2.3.2
marcoschwartz/LiquidCrystal_I2C@^1.1.4
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -117,8 +118,8 @@ lib_deps =
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
ClosedCube HDC1080 ClosedCube HDC1080
Adafruit AHTX0 Adafruit AHTX0
LiquidCrystal_I2C
BH1750 BH1750
marcoschwartz/LiquidCrystal_I2C@^1.1.4
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -138,6 +139,8 @@ lib_deps =
ESP32 AnalogWrite ESP32 AnalogWrite
ESP32Servo ESP32Servo
MySensors @2.3.2 MySensors @2.3.2
fmalpartida/LiquidCrystal@^1.5.0
marcoschwartz/LiquidCrystal_I2C@^1.1.4
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200

View File

@@ -16,6 +16,7 @@
#include "items/vSensorBmp280.h" #include "items/vSensorBmp280.h"
#include "items/vSensorCcs811.h" #include "items/vSensorCcs811.h"
#include "items/vSensorDallas.h" #include "items/vSensorDallas.h"
#include "items/vSensorLCD2004.h"
#include "items/vSensorDht.h" #include "items/vSensorDht.h"
#include "items/vSensorNode.h" #include "items/vSensorNode.h"
#include "items/vSensorPzem.h" #include "items/vSensorPzem.h"
@@ -105,6 +106,10 @@ void csvCmdExecute(String& cmdStr) {
} else if (order == F("dallas-temp")) { } else if (order == F("dallas-temp")) {
#ifdef EnableSensorDallas #ifdef EnableSensorDallas
sCmd.addCommand(order.c_str(), dallas); sCmd.addCommand(order.c_str(), dallas);
#endif
} else if (order == F("LCD2004")) {
#ifdef EnableSensorLCD2004
sCmd.addCommand(order.c_str(), lcd2004);
#endif #endif
} else if (order == F("dht")) { } else if (order == F("dht")) {
#ifdef EnableSensorDht #ifdef EnableSensorDht

View File

@@ -16,6 +16,7 @@
#include "items/vSensorBmp280.h" #include "items/vSensorBmp280.h"
#include "items/vSensorCcs811.h" #include "items/vSensorCcs811.h"
#include "items/vSensorDallas.h" #include "items/vSensorDallas.h"
#include "items/vSensorLCD2004.h"
#include "items/vSensorDht.h" #include "items/vSensorDht.h"
#include "items/vSensorNode.h" #include "items/vSensorNode.h"
#include "items/vSensorPzem.h" #include "items/vSensorPzem.h"
@@ -23,6 +24,10 @@
#include "items/vSensorUltrasonic.h" #include "items/vSensorUltrasonic.h"
#include "items/vSensorUptime.h" #include "items/vSensorUptime.h"
#ifdef EnableSensorLCD2004
extern LiquidCrystal_I2C *LCDI2C;
#endif
void loadConfig() { void loadConfig() {
configSetupJson = readFile("config.json", 4096); configSetupJson = readFile("config.json", 4096);
configSetupJson.replace("\r\n", ""); configSetupJson.replace("\r\n", "");
@@ -169,6 +174,13 @@ void clearVectors() {
mySensorDallas2->clear(); mySensorDallas2->clear();
} }
#endif #endif
#ifdef EnableSensorLCD2004
if (mySensorLCD20042 != nullptr) {
if(LCDI2C != nullptr) LCDI2C->clear();
mySensorLCD20042->clear();
}
#endif
#ifdef EnableSensorUltrasonic #ifdef EnableSensorUltrasonic
if (mySensorUltrasonic != nullptr) { if (mySensorUltrasonic != nullptr) {
mySensorUltrasonic->clear(); mySensorUltrasonic->clear();

View File

@@ -9,7 +9,7 @@
#include "Adafruit_AHTX0.h" #include "Adafruit_AHTX0.h"
#include "BH1750.h" #include "BH1750.h"
#include "ClosedCube_HDC1080.h" #include "ClosedCube_HDC1080.h"
#include "LiquidCrystal_I2C.h" //#include "LiquidCrystal_I2C.h"
//создаем объект HDC1080 //создаем объект HDC1080
ClosedCube_HDC1080 hdc1080; ClosedCube_HDC1080 hdc1080;
@@ -20,7 +20,7 @@ Adafruit_Sensor *aht_humidity, *aht_temp;
sensors_event_t tmpEvent_t; sensors_event_t tmpEvent_t;
//создаем объект LCD //создаем объект LCD
LiquidCrystal_I2C LCD(0x27, 16, 2); //LiquidCrystal_I2C LCD(0x27, 16, 2);
//создаем объект BH1750 //создаем объект BH1750
BH1750 lightMeter; BH1750 lightMeter;
@@ -29,7 +29,7 @@ BH1750 lightMeter;
// Adafruit_ADS1015 ads; // Adafruit_ADS1015 ads;
// co2 sensor // co2 sensor
SoftwareSerial K_30_Serial(13, 15); //Программный порт //SoftwareSerial K_30_Serial(13, 15); //Программный порт
byte readCO2[] = {0xFE, 0X44, 0X00, 0X08, 0X02, 0X9F, 0X25}; //Команды для запроса показаний с датчика byte readCO2[] = {0xFE, 0X44, 0X00, 0X08, 0X02, 0X9F, 0X25}; //Команды для запроса показаний с датчика
byte response[] = {0, 0, 0, 0, 0, 0, 0}; //массив для ответа от датчика byte response[] = {0, 0, 0, 0, 0, 0, 0}; //массив для ответа от датчика
unsigned long getValue(byte packet[]) { unsigned long getValue(byte packet[]) {
@@ -39,10 +39,10 @@ unsigned long getValue(byte packet[]) {
return val_1; return val_1;
} }
void sendRequest(byte packet[]) { void sendRequest(byte packet[]) {
while (!K_30_Serial.available()) { //while (!K_30_Serial.available()) {
K_30_Serial.write(readCO2, 7); // K_30_Serial.write(readCO2, 7);
delay(50); // delay(50);
} //}
} }
float yourSensorReading(String type, String paramsAny) { float yourSensorReading(String type, String paramsAny) {
@@ -68,12 +68,12 @@ float yourSensorReading(String type, String paramsAny) {
value = tmpEvent_t.relative_humidity; value = tmpEvent_t.relative_humidity;
} }
//==========================================================LCD================================================================= //==========================================================LCD=================================================================
if (type == "LCD") { //if (type == "LCD") {
LCD_init(); //LCD_init();
LCD.setCursor(jsonReadInt(paramsAny, "c"), jsonReadInt(paramsAny, "k")); // LCD.setCursor(jsonReadInt(paramsAny, "c"), jsonReadInt(paramsAny, "k"));
String toPrint = jsonReadStr(paramsAny, "descr") + " " + jsonReadStr(configLiveJson, jsonReadStr(paramsAny, "val")); // String toPrint = jsonReadStr(paramsAny, "descr") + " " + jsonReadStr(configLiveJson, jsonReadStr(paramsAny, "val"));
LCD.print(toPrint); // LCD.print(toPrint);
} //}
//==========================================================BH1750================================================================= //==========================================================BH1750=================================================================
if (type == "BH1750_lux") { if (type == "BH1750_lux") {
BH1750_init(); BH1750_init();
@@ -81,10 +81,10 @@ float yourSensorReading(String type, String paramsAny) {
} }
//==========================================================co2================================================================= //==========================================================co2=================================================================
if (type == "valCO2") { if (type == "valCO2") {
K_30_Serial.begin(9600); //K_30_Serial.begin(9600);
sendRequest(readCO2); //sendRequest(readCO2);
int valCO2 = getValue(response); //int valCO2 = getValue(response);
value = valCO2; //value = valCO2;
// Serial.println(valCO2); // Serial.println(valCO2);
} }
//==========================================================timer================================================================= //==========================================================timer=================================================================
@@ -119,14 +119,14 @@ void AHTX0_init() {
} }
} }
void LCD_init() { //void LCD_init() {
static bool LCD_flag = true; //static bool LCD_flag = true;
if (LCD_flag) { //if (LCD_flag) {
LCD.init(); //инициализация дисплея //LCD.init(); //инициализация дисплея
LCD.backlight(); //включаем подсветку //LCD.backlight(); //включаем подсветку
} //}
LCD_flag = false; //LCD_flag = false;
} //}
void BH1750_init() { void BH1750_init() {
static bool BH1750_flag = true; static bool BH1750_flag = true;

View File

@@ -0,0 +1,128 @@
#include "Consts.h"
#ifdef EnableSensorLCD2004
#include "items/vSensorLCD2004.h"
#include "BufferExecute.h"
#include "Class/LineParsing.h"
#include "Global.h"
#include "Utils/StringUtils.h"
#include <map>
#include <Arduino.h>
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;
_prevStrSize = 0;
}
SensorLCD2004::~SensorLCD2004() {}
//печать пустой строки нужной длинны для затирания предыдущего значения на экране
void SensorLCD2004::printBlankStr(int strSize){
String tmpStr = "";
for(int i=0; i<strSize; i++) tmpStr += " ";
LCDI2C->setCursor(_x, _y);
LCDI2C->print(tmpStr);
}
void SensorLCD2004::execute(String command) {
if (command == "noBacklight") LCDI2C->noBacklight();
else if (command == "backlight") LCDI2C->backlight();
else if (command == "noDisplay") LCDI2C->noDisplay();
else if (command == "display") LCDI2C->display();
else if (command == "x") {
printBlankStr(_prevStrSize);
String par = sCmd.next();
_x = par.toInt();
}
else if (command == "y") {
printBlankStr(_prevStrSize);
String par = sCmd.next();
_y = par.toInt();
}
else if (command == "descr") {
printBlankStr(_prevStrSize);
String par = sCmd.next();
_descr = par;
}
else { //не команда, значит данные
_val = command;
}
writeLCD2004();
}
void SensorLCD2004::loop() {
currentMillis = millis();
difference = currentMillis - prevMillis;
if (difference >= _interval) {
prevMillis = millis();
writeLCD2004();
}
}
void SensorLCD2004::writeLCD2004() {
if (LCDI2C != nullptr) {
printBlankStr(_prevStrSize);
String tmpStr = getValue(_val);
if (tmpStr == "no value") tmpStr = _val;
if (_descr != "none") tmpStr = _descr + " " + tmpStr;
LCDI2C->setCursor(_x, _y);
LCDI2C->print(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 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, ",", 0).toInt(); //количество столбцов
int h = selectFromMarkerToMarker(k, ",", 1).toInt(); //количество строк
if (LCDI2C == nullptr) { //инициализации экрана еще не было
LCDI2C = new LiquidCrystal_I2C(hexStringToUint8(addr), w, h);//hexStringToUint8(addr), w, h);
if(LCDI2C != nullptr) {
LCDI2C->init();
LCDI2C->backlight();
}
}
static bool firstTime = true;
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

View File

@@ -29,6 +29,7 @@
#include "items/vSensorBmp280.h" #include "items/vSensorBmp280.h"
#include "items/vSensorCcs811.h" #include "items/vSensorCcs811.h"
#include "items/vSensorDallas.h" #include "items/vSensorDallas.h"
#include "items/vSensorLCD2004.h"
#include "items/vSensorDht.h" #include "items/vSensorDht.h"
#include "items/vSensorNode.h" #include "items/vSensorNode.h"
#include "items/vSensorPzem.h" #include "items/vSensorPzem.h"
@@ -153,6 +154,13 @@ void loop() {
} }
} }
#endif #endif
#ifdef EnableSensorLCD2004
if (mySensorLCD20042 != nullptr) {
for (unsigned int i = 0; i < mySensorLCD20042->size(); i++) {
mySensorLCD20042->at(i).loop();
}
}
#endif
#ifdef EnableSensorUltrasonic #ifdef EnableSensorUltrasonic
if (mySensorUltrasonic != nullptr) { if (mySensorUltrasonic != nullptr) {
for (unsigned int i = 0; i < mySensorUltrasonic->size(); i++) { for (unsigned int i = 0; i < mySensorUltrasonic->size(); i++) {