From bd4753f2c9f2e24a4c747b4de108126c73274998 Mon Sep 17 00:00:00 2001 From: biver Date: Tue, 22 Feb 2022 21:21:48 +0300 Subject: [PATCH] Merge branch 'ver4dev' --- src/modules/Aht20.cpp | 4 ++-- src/modules/Bme280.cpp | 29 ++++++++++++++++------------- src/modules/Bmp280.cpp | 22 ++++++++++++---------- src/modules/Dht1122.cpp | 34 ++++++++++++++++++---------------- src/modules/GY-21.cpp | 14 ++++++++------ src/modules/Mcp23017.cpp | 1 - src/modules/Sht20.cpp | 10 ++++++---- 7 files changed, 62 insertions(+), 52 deletions(-) diff --git a/src/modules/Aht20.cpp b/src/modules/Aht20.cpp index e59bdf35..d37034e9 100644 --- a/src/modules/Aht20.cpp +++ b/src/modules/Aht20.cpp @@ -22,7 +22,7 @@ class Aht20t : public IoTItem { void doByInterval() { value.valD = temp.temperature; - if (value.valD != -200) regEvent(value.valD, "Aht20t"); // todo: найти способ понимания ошибки получения данных + if (value.valD != -200) regEvent(value.valD, "Aht20t"); // TODO: найти способ понимания ошибки получения данных else SerialPrint("E", "Sensor AHTt", "Error"); } @@ -36,7 +36,7 @@ class Aht20h : public IoTItem { void doByInterval() { value.valD = humidity.relative_humidity; - if (value.valD != -200) regEvent(value.valD, "Aht20h"); // todo: найти способ понимания ошибки получения данных + if (value.valD != -200) regEvent(value.valD, "Aht20h"); // TODO: найти способ понимания ошибки получения данных else SerialPrint("E", "Sensor AHTt", "Error"); } diff --git a/src/modules/Bme280.cpp b/src/modules/Bme280.cpp index b32f4499..ca3589a0 100644 --- a/src/modules/Bme280.cpp +++ b/src/modules/Bme280.cpp @@ -73,21 +73,24 @@ class Bme280p : public IoTItem { ~Bme280p(); }; -void* getAPI_Bme280(String subtype, String param) { - String addr; - jsonRead(param, "addr", addr); - if (bmes.find(addr) == bmes.end()) { - bmes[addr] = new Adafruit_BME280(); - bmes[addr]->begin(hexStringToUint8(addr)); - } +void* getAPI_Bme280(String subtype, String param) { + if (subtype == F("Bme280t") || subtype == F("Bme280h") || subtype == F("Bme280p")) { + String addr; + jsonRead(param, "addr", 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); + 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; } diff --git a/src/modules/Bmp280.cpp b/src/modules/Bmp280.cpp index 35686689..368c9bf7 100644 --- a/src/modules/Bmp280.cpp +++ b/src/modules/Bmp280.cpp @@ -55,18 +55,20 @@ class Bmp280p : public IoTItem { void* getAPI_Bmp280(String subtype, String param) { - String addr; - jsonRead(param, "addr", addr); + if (subtype == F("Bmp280t") || subtype == F("Bmp280p")) { + String addr; + jsonRead(param, "addr", addr); - if (bmps.find(addr) == bmps.end()) { - bmps[addr] = new Adafruit_BMP280(); - bmps[addr]->begin(hexStringToUint8(addr)); - } + if (bmps.find(addr) == bmps.end()) { + bmps[addr] = new Adafruit_BMP280(); + bmps[addr]->begin(hexStringToUint8(addr)); + } - if (subtype == F("Bmp280t")) { - return new Bmp280t(bmps[addr], param); - } else if (subtype == F("Bmp280p")) { - return new Bmp280p(bmps[addr], param); + if (subtype == F("Bmp280t")) { + return new Bmp280t(bmps[addr], param); + } else if (subtype == F("Bmp280p")) { + return new Bmp280p(bmps[addr], param); + } } else { return nullptr; } diff --git a/src/modules/Dht1122.cpp b/src/modules/Dht1122.cpp index 54e8495f..98ada9be 100644 --- a/src/modules/Dht1122.cpp +++ b/src/modules/Dht1122.cpp @@ -53,25 +53,27 @@ class Dht1122h : public IoTItem { void* getAPI_Dht1122(String subtype, String param) { - int pin; - String senstype; - jsonRead(param, "pin", pin); - jsonRead(param, "senstype", senstype); + if (subtype == F("Dht1122t") || subtype == F("Dht1122h")) { + int pin; + String senstype; + jsonRead(param, "pin", pin); + jsonRead(param, "senstype", senstype); - if (dhts.find(pin) == dhts.end()) { - dhts[pin] = new DHTesp(); - - if (senstype == "dht11") { - dhts[pin]->setup(pin, DHTesp::DHT11); - } else if (senstype == "dht22") { - dhts[pin]->setup(pin, DHTesp::DHT22); + if (dhts.find(pin) == dhts.end()) { + dhts[pin] = new DHTesp(); + + if (senstype == "dht11") { + dhts[pin]->setup(pin, DHTesp::DHT11); + } else if (senstype == "dht22") { + dhts[pin]->setup(pin, DHTesp::DHT22); + } } - } - if (subtype == F("Dht1122t")) { - return new Dht1122t(dhts[pin], param); - } else if (subtype == F("Dht1122h")) { - return new Dht1122h(dhts[pin], param); + if (subtype == F("Dht1122t")) { + return new Dht1122t(dhts[pin], param); + } else if (subtype == F("Dht1122h")) { + return new Dht1122h(dhts[pin], param); + } } else { return nullptr; } diff --git a/src/modules/GY-21.cpp b/src/modules/GY-21.cpp index b341fa2e..e430afde 100644 --- a/src/modules/GY-21.cpp +++ b/src/modules/GY-21.cpp @@ -20,7 +20,7 @@ class GY21t : public IoTItem { void doByInterval() { //wire->read(); value.valD = sensor->GY21_Temperature(); - if (value.valD < 300) regEvent(value.valD, "GY21"); // todo: найти способ понимания ошибки получения данных + if (value.valD < 300) regEvent(value.valD, "GY21"); // TODO: найти способ понимания ошибки получения данных else SerialPrint("E", "Sensor GY21t", "Error"); } @@ -34,7 +34,7 @@ class GY21h : public IoTItem { void doByInterval() { //sht->read(); value.valD = sensor->GY21_Humidity(); - if (value.valD != 0) regEvent(value.valD, "GY21h"); // todo: найти способ понимания ошибки получения данных + if (value.valD != 0) regEvent(value.valD, "GY21h"); // TODO: найти способ понимания ошибки получения данных else SerialPrint("E", "Sensor GY21h", "Error"); } @@ -42,16 +42,18 @@ class GY21h : public IoTItem { }; void* getAPI_GY21(String subtype, String param) { + if (subtype == F("GY21t") || subtype == F("GY21h")) { if (!sensor) { - sensor = new GY21; - if (sensor) Wire.begin(SDA, SCL); + 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; } + } else { + return nullptr; + } } \ No newline at end of file diff --git a/src/modules/Mcp23017.cpp b/src/modules/Mcp23017.cpp index 2c64d5a1..552ece0f 100644 --- a/src/modules/Mcp23017.cpp +++ b/src/modules/Mcp23017.cpp @@ -43,7 +43,6 @@ class Mcp23017 : public IoTItem, IoTGpio { void* getAPI_Mcp23017(String subtype, String param) { if (subtype == F("Mcp23017")) { String addr; - uint8_t deviceAddress[1]; jsonRead(param, "addr", addr); Serial.printf("deviceAddress %s = %02x \n", addr.c_str(), hexStringToUint8(addr)); diff --git a/src/modules/Sht20.cpp b/src/modules/Sht20.cpp index 82d8d2ca..af677033 100644 --- a/src/modules/Sht20.cpp +++ b/src/modules/Sht20.cpp @@ -37,16 +37,18 @@ class Sht20h : public IoTItem { void* getAPI_Sht20(String subtype, String param) { + if (subtype == F("Sht20t") || subtype == F("Sht20h")) { if (!sht) { - sht = new SHT2x; - if (sht) sht->begin(); + 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; } + } else { + return nullptr; + } }