mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 14:42:18 +03:00
Скопом добавляем несколько сенсоров
This commit is contained in:
@@ -8,6 +8,10 @@ void* getAPI_Sht20(String subtype, String params);
|
||||
void* getAPI_Dht1122(String subtype, String params);
|
||||
void* getAPI_Bmp280(String subtype, String params);
|
||||
void* getAPI_Bme280(String subtype, String params);
|
||||
void* getAPI_Aht20(String subtype, String params);
|
||||
void* getAPI_Hdc1080(String subtype, String params);
|
||||
void* getAPI_GY21(String subtype, String params);
|
||||
void* getAPI_Lcd2004(String subtype, String params);
|
||||
//============================================================================================
|
||||
|
||||
void* getAPI(String subtype, String params) {
|
||||
@@ -20,6 +24,10 @@ void* getAPI(String subtype, String params) {
|
||||
if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_GY21(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
|
||||
//================================================================================================================
|
||||
|
||||
return nullptr;
|
||||
|
||||
60
src/modules/Aht20.cpp
Normal file
60
src/modules/Aht20.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/******************************************************************
|
||||
Used Adafruit AHT20 Driver (temperature and humidity sensor)
|
||||
Support for AHT20
|
||||
https://github.com/adafruit/Adafruit_AHTX0
|
||||
|
||||
adapted for version 4 @Serghei63
|
||||
******************************************************************/
|
||||
|
||||
|
||||
#include "Global.h"
|
||||
#include "Classes/IoTItem.h"
|
||||
|
||||
#include "Adafruit_AHTX0.h"
|
||||
#include <map>
|
||||
|
||||
Adafruit_AHTX0 aht;
|
||||
sensors_event_t temp, humidity;
|
||||
|
||||
class Aht20t : public IoTItem {
|
||||
public:
|
||||
Aht20t(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = temp.temperature;
|
||||
if (String(value.valD) != "nan") regEvent(value.valD, "Aht20t");
|
||||
else SerialPrint("E", "Sensor AHTt", "Error");
|
||||
}
|
||||
|
||||
~Aht20t();
|
||||
};
|
||||
|
||||
|
||||
class Aht20h : public IoTItem {
|
||||
public:
|
||||
Aht20h(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = humidity.relative_humidity;
|
||||
if (String(value.valD) != "nan") regEvent(value.valD, "Aht20t");
|
||||
else SerialPrint("E", "Sensor AHTt", "Error");
|
||||
}
|
||||
|
||||
~Aht20h();
|
||||
};
|
||||
|
||||
|
||||
void* getAPI_Aht20(String subtype, String param) {
|
||||
if (subtype == F("Aht20t")) {
|
||||
aht.begin();
|
||||
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
|
||||
return new Aht20t(param);
|
||||
} else if (subtype == F("Aht20h")) {
|
||||
aht.begin();
|
||||
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
|
||||
return new Aht20h(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
57
src/modules/GY-21.cpp
Normal file
57
src/modules/GY-21.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/******************************************************************
|
||||
Used GY21 Driver (temperature and humidity sensor)
|
||||
Support for HTY21 , SHT21 , Si7021
|
||||
https://github.com/adafruit/Adafruit_AHTX0
|
||||
|
||||
adapted for version 4 Alecs Alecs
|
||||
******************************************************************/
|
||||
#include "Global.h"
|
||||
#include "Classes/IoTItem.h"
|
||||
|
||||
#include "Wire.h"
|
||||
#include "GY21.h"
|
||||
|
||||
GY21* sensor = nullptr;
|
||||
|
||||
class GY21t : public IoTItem {
|
||||
public:
|
||||
GY21t(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
//wire->read();
|
||||
value.valD = sensor->GY21_Temperature();
|
||||
if (value.valD > -46.85F) regEvent(value.valD, "GY21");
|
||||
else SerialPrint("E", "Sensor GY21t", "Error");
|
||||
}
|
||||
|
||||
~GY21t();
|
||||
};
|
||||
|
||||
class GY21h : public IoTItem {
|
||||
public:
|
||||
GY21h(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
//sht->read();
|
||||
value.valD = sensor->GY21_Humidity();
|
||||
if (value.valD != -6) regEvent(value.valD, "GY21h");
|
||||
else SerialPrint("E", "Sensor GY21h", "Error");
|
||||
}
|
||||
|
||||
~GY21h();
|
||||
};
|
||||
|
||||
void* getAPI_GY21(String subtype, String param) {
|
||||
if (!sensor) {
|
||||
sensor = new GY21;
|
||||
if (sensor) Wire.begin(SDA, SCL);
|
||||
}
|
||||
|
||||
if (subtype == F("GY21t")) {
|
||||
return new GY21t(param);
|
||||
} else if (subtype == F("GY21h")) {
|
||||
return new GY21h(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
54
src/modules/Hdc1080.cpp
Normal file
54
src/modules/Hdc1080.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/******************************************************************
|
||||
Used ClosedCube HDC1080 Driver (temperature and humidity sensor)
|
||||
Support for HDC1080
|
||||
https://github.com/closedcube/ClosedCube_HDC1080_Arduino
|
||||
|
||||
adapted for version 4 @Serghei63
|
||||
******************************************************************/
|
||||
#include "Global.h"
|
||||
#include "Classes/IoTItem.h"
|
||||
|
||||
#include "Wire.h"
|
||||
#include "ClosedCube_HDC1080.h"
|
||||
#include <map>
|
||||
|
||||
//создаем объект HDC1080
|
||||
ClosedCube_HDC1080 hdc1080;
|
||||
|
||||
class Hdc1080t : public IoTItem {
|
||||
public:
|
||||
Hdc1080t(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = hdc1080.readTemperature();
|
||||
if (value.valD > -46.85F) regEvent(value.valD, "Hdc1080t");
|
||||
else SerialPrint("E", "Sensor Hdc1080t", "Error");
|
||||
}
|
||||
|
||||
~Hdc1080t();
|
||||
};
|
||||
|
||||
class Hdc1080h : public IoTItem {
|
||||
public:
|
||||
Hdc1080h(String parameters): IoTItem(parameters) { }
|
||||
|
||||
void doByInterval() {
|
||||
value.valD = hdc1080.readHumidity();
|
||||
if (value.valD > -46.85F) regEvent(value.valD, "Hdc1080h");
|
||||
else SerialPrint("E", "Sensor Hdc1080h", "Error");
|
||||
}
|
||||
|
||||
~Hdc1080h();
|
||||
};
|
||||
|
||||
void* getAPI_Hdc1080(String subtype, String param) {
|
||||
if (subtype == F("Hdc1080t")) {
|
||||
hdc1080.begin(0x40);
|
||||
return new Hdc1080t(param);
|
||||
} else if (subtype == F("Hdc1080h")) {
|
||||
hdc1080.begin(0x40);
|
||||
return new Hdc1080h(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
97
src/modules/Lcd2004.cpp
Normal file
97
src/modules/Lcd2004.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
|
||||
#include "LiquidCrystal_I2C.h"
|
||||
#include <map>
|
||||
|
||||
LiquidCrystal_I2C *LCDI2C;
|
||||
|
||||
class Lcd2004 : public IoTItem {
|
||||
private:
|
||||
unsigned int _x;
|
||||
unsigned int _y;
|
||||
String _id2show;
|
||||
String _descr;
|
||||
int _prevStrSize;
|
||||
|
||||
public:
|
||||
Lcd2004(String parameters): IoTItem(parameters) {
|
||||
String addr, size, xy;
|
||||
_prevStrSize = 0;
|
||||
|
||||
jsonRead(parameters, "addr", addr);
|
||||
jsonRead(parameters, "size", size);
|
||||
int w = selectFromMarkerToMarker(size, ",", 0).toInt(); //количество столбцов
|
||||
int h = selectFromMarkerToMarker(size, ",", 1).toInt(); //количество строк
|
||||
if (LCDI2C == nullptr) { //инициализации экрана еще не было
|
||||
LCDI2C = new LiquidCrystal_I2C(hexStringToUint8(addr), w, h);
|
||||
if(LCDI2C != nullptr) {
|
||||
LCDI2C->init();
|
||||
LCDI2C->backlight();
|
||||
}
|
||||
}
|
||||
|
||||
jsonRead(parameters, "coord", xy);
|
||||
_x = selectFromMarkerToMarker(xy, ",", 0).toInt();
|
||||
_y = selectFromMarkerToMarker(xy, ",", 1).toInt();
|
||||
|
||||
jsonRead(parameters, "descr", _descr);
|
||||
jsonRead(parameters, "id2show", _id2show);
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
if (LCDI2C != nullptr) {
|
||||
printBlankStr(_prevStrSize);
|
||||
|
||||
String tmpStr;
|
||||
jsonRead(paramsHeapJson, _id2show, tmpStr);
|
||||
if (_descr != "none") tmpStr = _descr + " " + tmpStr;
|
||||
LCDI2C->setCursor(_x, _y);
|
||||
LCDI2C->print(tmpStr);
|
||||
|
||||
// LCDI2C->print("Helloy,Manager 404 !");
|
||||
|
||||
_prevStrSize = tmpStr.length();
|
||||
}
|
||||
}
|
||||
|
||||
IoTValue execute(String command, std::vector<IoTValue> ¶m) { // будет возможным использовать, когда сценарии запустятся
|
||||
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") {
|
||||
_x = param[0].valD;
|
||||
}
|
||||
else if (command == "y") {
|
||||
_y = param[0].valD;
|
||||
}
|
||||
else if (command == "descr") {
|
||||
_descr = param[0].valS;
|
||||
}
|
||||
else if (command == "id2show") {
|
||||
_id2show = param[0].valS;
|
||||
}
|
||||
|
||||
doByInterval();
|
||||
return {};
|
||||
}
|
||||
|
||||
//печать пустой строки нужной длинны для затирания предыдущего значения на экране
|
||||
void printBlankStr(int strSize){
|
||||
String tmpStr = "";
|
||||
for(int i=0; i<strSize; i++) tmpStr += " ";
|
||||
LCDI2C->setCursor(_x, _y);
|
||||
LCDI2C->print(tmpStr);
|
||||
}
|
||||
|
||||
~Lcd2004(){};
|
||||
};
|
||||
|
||||
void* getAPI_Lcd2004(String subtype, String param) {
|
||||
if (subtype == F("Lcd2004")) {
|
||||
return new Lcd2004(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user