mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
добавил LCD
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
#include "YourSensor.h"
|
||||
|
||||
#include "Global.h"
|
||||
#include "Utils/JsonUtils.h"
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
//подключаем необходимые файлы библиотеки
|
||||
#include <Adafruit_AHTX0.h>
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
|
||||
#include "ClosedCube_HDC1080.h"
|
||||
|
||||
@@ -15,14 +18,17 @@ Adafruit_AHTX0 aht;
|
||||
Adafruit_Sensor *aht_humidity, *aht_temp;
|
||||
sensors_event_t tmpEvent_t;
|
||||
|
||||
float yourSensorReading(String type, String addr) {
|
||||
//создаем объект LCD
|
||||
LiquidCrystal_I2C LCD(0x27, 16, 2);
|
||||
|
||||
float yourSensorReading(String type, String paramsAny) {
|
||||
float value;
|
||||
//========================================================HDC1080================================================================
|
||||
if (type == "HDC1080_temp") {
|
||||
HDC1080_init(addr);
|
||||
HDC1080_init(jsonReadStr(paramsAny, "addr"));
|
||||
value = hdc1080.readTemperature();
|
||||
} else if (type == "HDC1080_hum") {
|
||||
HDC1080_init(addr);
|
||||
HDC1080_init(jsonReadStr(paramsAny, "addr"));
|
||||
value = hdc1080.readHumidity();
|
||||
}
|
||||
//==========================================================AHTX0=================================================================
|
||||
@@ -30,15 +36,21 @@ float yourSensorReading(String type, String addr) {
|
||||
AHTX0_init();
|
||||
aht_temp->getEvent(&tmpEvent_t);
|
||||
value = tmpEvent_t.temperature;
|
||||
} else if (type == "typeAHTX0_hum") {
|
||||
} else if (type == "AHTX0_hum") {
|
||||
AHTX0_init();
|
||||
aht_humidity->getEvent(&tmpEvent_t);
|
||||
value = tmpEvent_t.relative_humidity;
|
||||
}
|
||||
//==========================================================LCD=================================================================
|
||||
if (type == "LCD") {
|
||||
LCD_init();
|
||||
LCD.setCursor(jsonReadInt(paramsAny, "с"), jsonReadInt(paramsAny, "k"));
|
||||
LCD.print(jsonReadFloat(configLiveJson, jsonReadStr(paramsAny, "val")));
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void HDC1080_init(String &addr) {
|
||||
void HDC1080_init(String addr) {
|
||||
static bool HDC1080_flag = true;
|
||||
if (HDC1080_flag) {
|
||||
hdc1080.begin(hexStringToUint8(addr));
|
||||
@@ -61,3 +73,11 @@ void AHTX0_init() {
|
||||
AHTX0_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
void LCD_init() {
|
||||
static bool LCD_flag = true;
|
||||
if (LCD_flag) {
|
||||
LCD.init(); //инициализация дисплея
|
||||
LCD.backlight(); //включаем подсветку
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,11 @@ SensorAny::SensorAny(const String& paramsAny) {
|
||||
|
||||
_interval = jsonReadInt(_paramsAny, "int");
|
||||
_c = jsonReadFloat(_paramsAny, "c");
|
||||
_k = jsonReadFloat(_paramsAny, "k");
|
||||
_key = jsonReadStr(_paramsAny, "key");
|
||||
_addr = jsonReadStr(_paramsAny, "addr");
|
||||
_type = jsonReadStr(_paramsAny, "type");
|
||||
_val = jsonReadStr(_paramsAny, "val");
|
||||
}
|
||||
|
||||
SensorAny::~SensorAny() {}
|
||||
@@ -29,7 +31,7 @@ void SensorAny::loop() {
|
||||
}
|
||||
|
||||
void SensorAny::read() {
|
||||
float value = yourSensorReading(_type, _addr);
|
||||
float value = yourSensorReading(_type, _paramsAny);
|
||||
|
||||
value = value * _c;
|
||||
|
||||
@@ -54,6 +56,8 @@ void AnySensor() {
|
||||
jsonWriteStr(params, "addr", myLineParsing.gaddr());
|
||||
jsonWriteStr(params, "int", myLineParsing.gint());
|
||||
jsonWriteStr(params, "c", myLineParsing.gc());
|
||||
jsonWriteStr(params, "k", myLineParsing.gk());
|
||||
jsonWriteStr(params, "val", myLineParsing.gval());
|
||||
jsonWriteStr(params, "type", myLineParsing.gtype());
|
||||
myLineParsing.clear();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user