Merge pull request #99 from DmitryBorisenko33/ver3

добавил AHTX0 HDC1080
This commit is contained in:
Dmitry Borisenko
2021-12-15 21:08:34 +01:00
committed by GitHub
4 changed files with 68 additions and 20 deletions

View File

@@ -1,23 +1,63 @@
#include "YourSensor.h"
float yourSensorReading(String type) {
#include "Utils/StringUtils.h"
//подключаем необходимые файлы библиотеки
#include <Adafruit_AHTX0.h>
#include "ClosedCube_HDC1080.h"
//создаем объект HDC1080
ClosedCube_HDC1080 hdc1080;
//создаем объект AHTX0
Adafruit_AHTX0 aht;
Adafruit_Sensor *aht_humidity, *aht_temp;
sensors_event_t tmpEvent_t;
float yourSensorReading(String type, String addr) {
float value;
if (type == "type1") { // type1 - замените на название вашего датчика, потом это же название указывайте в type[], в вебе
//сюда вставляем процедуру чтения одного датчика
static int a;
a++;
value = a;
} else if (type == "type2") {
//сюда вставляем процедуру чтения другого датчика
static int b;
b--;
value = b;
} else if (type == "type3") {
//сюда третьего и так далее, создавайте сколько угодно else if....
//если у одного датчика несколько параметров то под каждый из них делайте свой else if и свое имя type
static int c;
c++;
value = c * 10;
//========================================================HDC1080================================================================
if (type == "HDC1080_temp") {
HDC1080_init(addr);
value = hdc1080.readTemperature();
} else if (type == "HDC1080_hum") {
HDC1080_init(addr);
value = hdc1080.readHumidity();
}
//==========================================================AHTX0=================================================================
if (type == "AHTX0_temp") {
AHTX0_init();
aht_temp->getEvent(&tmpEvent_t);
value = tmpEvent_t.temperature;
} else if (type == "typeAHTX0_hum") {
AHTX0_init();
aht_humidity->getEvent(&tmpEvent_t);
value = tmpEvent_t.relative_humidity;
}
return value;
}
void HDC1080_init(String &addr) {
static bool HDC1080_flag = true;
if (HDC1080_flag) {
hdc1080.begin(hexStringToUint8(addr));
HDC1080_flag = false;
}
}
void AHTX0_init() {
static bool AHTX0_flag = true;
if (AHTX0_flag) {
if (!aht.begin()) {
Serial.println("Failed to find AHT10/AHT20 chip");
// return -127;
}
aht_temp = aht.getTemperatureSensor();
aht_temp->printSensorDetails();
aht_humidity = aht.getHumiditySensor();
aht_humidity->printSensorDetails();
AHTX0_flag = false;
}
}

View File

@@ -29,7 +29,7 @@ void SensorAny::loop() {
}
void SensorAny::read() {
float value = yourSensorReading(_type);
float value = yourSensorReading(_type, _addr);
value = value * _c;