mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
добавил класс сенсора и наследующий класс аналогового сенсора
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "Global.h"
|
|
||||||
|
|
||||||
extern void configure(String& path);
|
|
||||||
7
include/Configuration.h
Normal file
7
include/Configuration.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Global.h"
|
||||||
|
#include "Classes/IoTSensor.h"
|
||||||
|
|
||||||
|
extern std::vector<IoTSensor*> iotSensors; // вектор ссылок базового класса IoTSensor - список всех запущенных сенсоров
|
||||||
|
|
||||||
|
extern void configure(String& path);
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
#include "Config.h"
|
#include "Configuration.h"
|
||||||
|
|
||||||
void configure(String& path) {
|
void configure(String& path) {
|
||||||
File file = seekFile(path);
|
File file = seekFile(path);
|
||||||
while (file.available()) {
|
while (file.available()) {
|
||||||
String jsonArrayElement = file.readStringUntil('}') + "}";
|
String jsonArrayElement = file.readStringUntil('}') + "}";
|
||||||
String value;
|
String subtype;
|
||||||
if (jsonRead(jsonArrayElement, F("subtype"), value)) {
|
if (jsonRead(jsonArrayElement, F("subtype"), subtype)) {
|
||||||
if (value == F("button-out")) {
|
if (subtype == F("button-out")) {
|
||||||
//=============================
|
//=============================
|
||||||
} else if (value == F("pwm-out")) {
|
} else if (subtype == F("pwm-out")) {
|
||||||
//=============================
|
|
||||||
} else if (value == F("analog-adc")) {
|
|
||||||
//=============================
|
//=============================
|
||||||
|
} else if (subtype == F("analog-adc")) {
|
||||||
|
//iotSensors.push_back(IoTSensorAnalog(jsonArrayElement));
|
||||||
} else {
|
} else {
|
||||||
SerialPrint(F("E"), F("Config"), F("config.json error, type not exist"));
|
SerialPrint(F("E"), F("Config"), F("config.json error, type not exist"));
|
||||||
}
|
}
|
||||||
29
src/modules/IoTSensorAnalog.cpp
Normal file
29
src/modules/IoTSensorAnalog.cpp
Normal file
@@ -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() {}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user