From 818824c3780ad11b43f4ec5cd3533ebc574315d9 Mon Sep 17 00:00:00 2001 From: biver Date: Wed, 14 Sep 2022 20:36:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BF=D0=B8=D0=BB=D1=8F=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B0=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B5=20=D1=8F?= =?UTF-8?q?=D0=B4=D1=80=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/sensors/Bme280/Bme280.cpp | 36 +++++++++---------- src/modules/sensors/Bmp280/Bmp280.cpp | 32 ++++++++--------- src/modules/sensors/Dht1122/Dht1122.cpp | 46 ++++++++++++------------- src/modules/sensors/GY21/GY21.cpp | 26 +++++++------- src/modules/sensors/Sht20/Sht20.cpp | 26 +++++++------- 5 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/modules/sensors/Bme280/Bme280.cpp b/src/modules/sensors/Bme280/Bme280.cpp index 5d4d11ad..6ef5d160 100644 --- a/src/modules/sensors/Bme280/Bme280.cpp +++ b/src/modules/sensors/Bme280/Bme280.cpp @@ -74,23 +74,23 @@ class Bme280p : public IoTItem { }; 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 { + 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); + } + } + return nullptr; - //} } diff --git a/src/modules/sensors/Bmp280/Bmp280.cpp b/src/modules/sensors/Bmp280/Bmp280.cpp index e6ff58f4..454f1c3b 100644 --- a/src/modules/sensors/Bmp280/Bmp280.cpp +++ b/src/modules/sensors/Bmp280/Bmp280.cpp @@ -54,21 +54,21 @@ class Bmp280p : public IoTItem { }; void* getAPI_Bmp280(String subtype, String param) { - // 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 (subtype == F("Bmp280t")) { - // return new Bmp280t(bmps[addr], param); - // } else if (subtype == F("Bmp280p")) { - // return new Bmp280p(bmps[addr], param); - // } - //} else { + 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 (subtype == F("Bmp280t")) { + return new Bmp280t(bmps[addr], param); + } else if (subtype == F("Bmp280p")) { + return new Bmp280p(bmps[addr], param); + } + } + return nullptr; - //} } diff --git a/src/modules/sensors/Dht1122/Dht1122.cpp b/src/modules/sensors/Dht1122/Dht1122.cpp index 33aed240..a9c00ef4 100644 --- a/src/modules/sensors/Dht1122/Dht1122.cpp +++ b/src/modules/sensors/Dht1122/Dht1122.cpp @@ -53,28 +53,28 @@ class Dht1122h : public IoTItem { }; void* getAPI_Dht1122(String subtype, String param) { - // 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 (subtype == F("Dht1122t")) { - // return new Dht1122t(dhts[pin], param); - // } else if (subtype == F("Dht1122h")) { - // return new Dht1122h(dhts[pin], param); - // } - //} else { + 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 (subtype == F("Dht1122t")) { + return new Dht1122t(dhts[pin], param); + } else if (subtype == F("Dht1122h")) { + return new Dht1122h(dhts[pin], param); + } + } + return nullptr; - //} } diff --git a/src/modules/sensors/GY21/GY21.cpp b/src/modules/sensors/GY21/GY21.cpp index ba663972..4c89722e 100644 --- a/src/modules/sensors/GY21/GY21.cpp +++ b/src/modules/sensors/GY21/GY21.cpp @@ -46,18 +46,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); - // } - // - // if (subtype == F("GY21t")) { - // return new GY21t(param); - // } else if (subtype == F("GY21h")) { - // return new GY21h(param); - // } - //} else { + if (subtype == F("GY21t") || subtype == F("GY21h")) { + if (!sensor) { + 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); + } + } + return nullptr; - //} } \ No newline at end of file diff --git a/src/modules/sensors/Sht20/Sht20.cpp b/src/modules/sensors/Sht20/Sht20.cpp index aa781a2e..a9100974 100644 --- a/src/modules/sensors/Sht20/Sht20.cpp +++ b/src/modules/sensors/Sht20/Sht20.cpp @@ -39,18 +39,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(); - // } - // - // if (subtype == F("Sht20t")) { - // return new Sht20t(param); - // } else if (subtype == F("Sht20h")) { - // return new Sht20h(param); - // } - //} else { + if (subtype == F("Sht20t") || subtype == F("Sht20h")) { + 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); + } + } + return nullptr; - //} }