Структурируем модули как надо

This commit is contained in:
2022-08-11 17:40:42 +03:00
parent 1ddc3aab9c
commit 799aff3383
70 changed files with 281 additions and 281 deletions

View File

@@ -1,97 +0,0 @@
/******************************************************************
Used Adafruit BME280 Driver (Barometric Pressure Sensor)
Support for BME280
https://github.com/adafruit/Adafruit_BME280_Library
******************************************************************/
#include "Global.h"
#include "classes/IoTItem.h"
#include <Adafruit_BME280.h>
#include <map>
std::map<String, Adafruit_BME280*> bmes;
class Bme280t : public IoTItem {
private:
Adafruit_BME280* _bme;
public:
Bme280t(Adafruit_BME280* bme, String parameters) : IoTItem(parameters) {
_bme = bme;
}
void doByInterval() {
value.valD = _bme->readTemperature();
if (value.valD < 145)
regEvent(value.valD, "Bme280t");
else
SerialPrint("E", "Sensor Bme280t", "Error");
}
~Bme280t() {};
};
class Bme280h : public IoTItem {
private:
Adafruit_BME280* _bme;
public:
Bme280h(Adafruit_BME280* bme, String parameters) : IoTItem(parameters) {
_bme = bme;
}
void doByInterval() {
value.valD = _bme->readHumidity();
if (value.valD < 100)
regEvent(value.valD, "Bme280h");
else
SerialPrint("E", "Sensor Bme280h", "Error");
}
~Bme280h() {};
};
class Bme280p : public IoTItem {
private:
Adafruit_BME280* _bme;
public:
Bme280p(Adafruit_BME280* bme, String parameters) : IoTItem(parameters) {
_bme = bme;
}
void doByInterval() {
value.valD = _bme->readPressure();
if (value.valD > 0) {
value.valD = value.valD / 1.333224 / 100;
regEvent(value.valD, "Bme280p");
} else
SerialPrint("E", "Sensor Bme280p", "Error");
}
~Bme280p() {};
};
void* getAPI_Bme280(String subtype, String param) {
if (subtype == F("Bme280t") || subtype == F("Bme280h") || subtype == F("Bme280p")) {
String addr;
jsonRead(param, "addr", addr);
if (bmes.find(addr) == bmes.end()) {
bmes[addr] = new Adafruit_BME280();
bmes[addr]->begin(hexStringToUint8(addr));
}
if (subtype == F("Bme280t")) {
return new Bme280t(bmes[addr], param);
} else if (subtype == F("Bme280h")) {
return new Bme280h(bmes[addr], param);
} else if (subtype == F("Bme280p")) {
return new Bme280p(bmes[addr], param);
}
} else {
return nullptr;
}
}

View File

@@ -1,65 +0,0 @@
{
"menuSection": "Сенсоры",
"configItem": [{
"name": "Cенсор температуры Bme280",
"type": "Reading",
"subtype": "Bme280t",
"id": "tmp3",
"widget": "anydataTmp",
"page": "Сенсоры",
"descr": "Температура",
"int": 15,
"addr": "0x77",
"round": 1
},
{
"name": "Cенсор давления Bme280",
"type": "Reading",
"subtype": "Bme280p",
"id": "Press3",
"widget": "anydataMm",
"page": "Сенсоры",
"descr": "Давление",
"int": 15,
"addr": "0x77",
"round": 1
},
{
"name": "Cенсор влажности Bme280",
"type": "Reading",
"subtype": "Bme280h",
"id": "Hum3",
"widget": "anydataHum",
"page": "Сенсоры",
"descr": "Влажность",
"int": 15,
"addr": "0x77",
"round": 1
}],
"about": {
"authorName": "Ilya Belyakov",
"authorContact": "https://t.me/Biveraxe",
"authorGit": "https://github.com/biveraxe",
"specialThanks": "Serghei Crasnicov @Serghei63",
"moduleName": "Bme280",
"moduleVersion": "1.0",
"moduleDesc": "Позволяет получить значения температуры, давления и влажности с Bme280.",
"propInfo": {
"addr": "Адрес датчика на шине, обычно 0x77.",
"int": "Количество секунд между опросами датчика."
}
},
"defActive": true,
"devices": {
"esp32_4mb": [
"adafruit/Adafruit BME280 Library"
],
"esp8266_4mb": [
"adafruit/Adafruit BME280 Library"
]
}
}