Скопом добавляем несколько сенсоров

This commit is contained in:
2022-02-17 18:25:50 +03:00
parent 52db75b8d5
commit c728d7b90c
8 changed files with 425 additions and 15 deletions

60
src/modules/Aht20.cpp Normal file
View 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;
}
}