From 063e818c8711715cf6b2753f1c9d8864d0be1a60 Mon Sep 17 00:00:00 2001 From: Dmitry Borisenko <67171972+IoTManagerProject@users.noreply.github.com> Date: Fri, 14 Jan 2022 22:51:28 +0100 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D1=81=D0=B5=D0=BD=D1=81=D0=BE?= =?UTF-8?q?=D1=80=D0=B0=20=D0=B8=20=D0=BD=D0=B0=D1=81=D0=BB=D0=B5=D0=B4?= =?UTF-8?q?=D1=83=D1=8E=D1=89=D0=B8=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= =?UTF-8?q?=20=D0=B0=D0=BD=D0=B0=D0=BB=D0=BE=D0=B3=D0=BE=D0=B2=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D1=81=D0=B5=D0=BD=D1=81=D0=BE=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Config.h | 4 ---- include/Configuration.h | 7 +++++++ src/{Config.cpp => Configuration.cpp} | 14 ++++++------- src/modules/IoTSensorAnalog.cpp | 29 +++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 11 deletions(-) delete mode 100644 include/Config.h create mode 100644 include/Configuration.h rename src/{Config.cpp => Configuration.cpp} (60%) create mode 100644 src/modules/IoTSensorAnalog.cpp diff --git a/include/Config.h b/include/Config.h deleted file mode 100644 index 28e326b9..00000000 --- a/include/Config.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "Global.h" - -extern void configure(String& path); \ No newline at end of file diff --git a/include/Configuration.h b/include/Configuration.h new file mode 100644 index 00000000..c83b1872 --- /dev/null +++ b/include/Configuration.h @@ -0,0 +1,7 @@ +#pragma once +#include "Global.h" +#include "Classes/IoTSensor.h" + +extern std::vector iotSensors; // вектор ссылок базового класса IoTSensor - список всех запущенных сенсоров + +extern void configure(String& path); \ No newline at end of file diff --git a/src/Config.cpp b/src/Configuration.cpp similarity index 60% rename from src/Config.cpp rename to src/Configuration.cpp index 6b20f4b0..f004e4b0 100644 --- a/src/Config.cpp +++ b/src/Configuration.cpp @@ -1,17 +1,17 @@ -#include "Config.h" +#include "Configuration.h" void configure(String& path) { File file = seekFile(path); while (file.available()) { String jsonArrayElement = file.readStringUntil('}') + "}"; - String value; - if (jsonRead(jsonArrayElement, F("subtype"), value)) { - if (value == F("button-out")) { + String subtype; + if (jsonRead(jsonArrayElement, F("subtype"), subtype)) { + if (subtype == F("button-out")) { //============================= - } else if (value == F("pwm-out")) { - //============================= - } else if (value == F("analog-adc")) { + } else if (subtype == F("pwm-out")) { //============================= + } else if (subtype == F("analog-adc")) { + //iotSensors.push_back(IoTSensorAnalog(jsonArrayElement)); } else { SerialPrint(F("E"), F("Config"), F("config.json error, type not exist")); } diff --git a/src/modules/IoTSensorAnalog.cpp b/src/modules/IoTSensorAnalog.cpp new file mode 100644 index 00000000..b77362e8 --- /dev/null +++ b/src/modules/IoTSensorAnalog.cpp @@ -0,0 +1,29 @@ +#include "Utils/JsonUtils.h" +#include "Utils/SerialPrint.h" +#include "Utils/StringUtils.h" +#include "Classes/IoTSensor.h" + +class IoTSensorAnalog : public IoTSensor { + private: + //описание переменных экземпляра датчика - аналог глобальных переменных + //описание параметров передаваемых из настроек датчика из веба + unsigned int _pin; + + public: + //аналог setup() + IoTSensorAnalog(String parameters) { + //передаем часть базовых параметров в конструктор базового класса для обеспечения работы его методов + init(jsonReadStr(parameters, "key"), jsonReadStr(parameters, "id"), jsonReadInt(parameters, "int")); + + _pin = jsonReadInt(parameters, "pin"); + } + + //аналог loop() + void doByInterval() { + float value = analogRead(_pin); + + regEvent((String)value, "analog"); //обязательный вызов для отправки результата работы + } + + ~IoTSensorAnalog() {} +}; \ No newline at end of file