mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
#include "Global.h"
|
|
#include "Classes/IoTItem.h"
|
|
|
|
#include "Wire.h"
|
|
#include "SHT2x.h"
|
|
|
|
|
|
SHT2x* sht = nullptr;
|
|
|
|
class Sht20t : public IoTItem {
|
|
public:
|
|
Sht20t(String parameters): IoTItem(parameters) { }
|
|
|
|
void doByInterval() {
|
|
sht->read();
|
|
float value = sht->getTemperature();
|
|
if (value > -46.85F) regEvent(value, "Sht20t");
|
|
else SerialPrint("E", "Sensor Sht20t", "Error");
|
|
}
|
|
|
|
~Sht20t();
|
|
};
|
|
|
|
class Sht20h : public IoTItem {
|
|
public:
|
|
Sht20h(String parameters): IoTItem(parameters) { }
|
|
|
|
void doByInterval() {
|
|
sht->read();
|
|
float value = sht->getHumidity();
|
|
if (value != -6) regEvent(value, "Sht20h");
|
|
else SerialPrint("E", "Sensor Sht20h", "Error");
|
|
}
|
|
|
|
~Sht20h();
|
|
};
|
|
|
|
|
|
void* getAPI_Sht20(String subtype, String param) {
|
|
if (!sht) {
|
|
sht = new SHT2x;
|
|
if (sht) sht->begin();
|
|
}
|
|
|
|
if (subtype == F("Sht20t")) {
|
|
return new Sht20t(param);
|
|
} else if (subtype == F("Sht20h")) {
|
|
return new Sht20h(param);
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|