mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 22:52:19 +03:00
remoove all
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
|
||||
|
||||
class ButtonInClass : public LineParsing {
|
||||
protected:
|
||||
int numberEntering = 0;
|
||||
int state = _state.toInt();
|
||||
|
||||
public:
|
||||
ButtonInClass() : LineParsing(){};
|
||||
|
||||
void init() {
|
||||
if (_pin != "") {
|
||||
int number = numberEntering++;
|
||||
buttons[number].attach(_pin.toInt());
|
||||
buttons[number].interval(_db.toInt());
|
||||
but[number] = true;
|
||||
jsonWriteStr(configOptionJson, "switch_num_" + String(number), _key);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static uint8_t switch_number = 1;
|
||||
if (but[switch_number]) {
|
||||
buttons[switch_number].update();
|
||||
if (buttons[switch_number].fell()) {
|
||||
String key = jsonReadStr(configOptionJson, "switch_num_" + String(switch_number));
|
||||
state = 1;
|
||||
switchChangeVirtual(key, String(state));
|
||||
}
|
||||
if (buttons[switch_number].rose()) {
|
||||
String key = jsonReadStr(configOptionJson, "switch_num_" + String(switch_number));
|
||||
state = 0;
|
||||
switchChangeVirtual(key, String(state));
|
||||
}
|
||||
}
|
||||
switch_number++;
|
||||
if (switch_number == NUM_BUTTONS) {
|
||||
switch_number = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void switchStateSetDefault() {
|
||||
if (_state != "") {
|
||||
switchChangeVirtual(_key, _state);
|
||||
}
|
||||
}
|
||||
|
||||
void switchChangeVirtual(String key, String state) {
|
||||
eventGen2(key, state);
|
||||
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||
publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern ButtonInClass myButtonIn;
|
||||
@@ -1,41 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class ButtonOutClass : public LineParsing {
|
||||
public:
|
||||
ButtonOutClass() : LineParsing() {};
|
||||
|
||||
void init() {
|
||||
if (_pin != "") {
|
||||
pinMode(_pin.toInt(), OUTPUT);
|
||||
}
|
||||
jsonWriteStr(configOptionJson, _key + "_pin", _pin);
|
||||
jsonWriteStr(configOptionJson, _key + "_inv", _inv);
|
||||
}
|
||||
|
||||
void pinStateSetDefault() {
|
||||
pinChange(_key, _state);
|
||||
}
|
||||
|
||||
|
||||
void pinChange(String key, String state) {
|
||||
String pin = jsonReadStr(configOptionJson, key + "_pin");
|
||||
String inv = jsonReadStr(configOptionJson, key + "_inv");
|
||||
int pinInt = pin.toInt();
|
||||
|
||||
if (inv == "") {
|
||||
digitalWrite(pinInt, state.toInt());
|
||||
}
|
||||
else {
|
||||
digitalWrite(pinInt, !state.toInt());
|
||||
}
|
||||
eventGen2(key, state);
|
||||
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||
publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern ButtonOutClass myButtonOut;
|
||||
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Global.h"
|
||||
|
||||
class ImpulsOutClass;
|
||||
|
||||
typedef std::vector<ImpulsOutClass> MyImpulsOutVector;
|
||||
|
||||
class ImpulsOutClass {
|
||||
public:
|
||||
ImpulsOutClass(unsigned int impulsPin);
|
||||
~ImpulsOutClass();
|
||||
|
||||
void loop();
|
||||
void execute(unsigned long impulsPeriod, unsigned int impulsCount);
|
||||
|
||||
private:
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
|
||||
unsigned long _impulsPeriod = 0;
|
||||
unsigned int _impulsCount = 0;
|
||||
unsigned int _impulsCountBuf = 0;
|
||||
unsigned int _impulsPin = 0;
|
||||
|
||||
};
|
||||
|
||||
extern MyImpulsOutVector* myImpulsOut;
|
||||
|
||||
extern void impulsExecute();
|
||||
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class InputClass : public LineParsing {
|
||||
public:
|
||||
InputClass() : LineParsing(){};
|
||||
|
||||
void inputSetDefaultFloat() {
|
||||
inputSetFloat(_key, _state);
|
||||
}
|
||||
|
||||
void inputSetDefaultStr() {
|
||||
inputSetStr(_key, _state);
|
||||
}
|
||||
|
||||
void inputSetFloat(String key, String state) {
|
||||
eventGen2(key, state);
|
||||
jsonWriteFloat(configLiveJson, key, state.toFloat());
|
||||
publishStatus(key, state);
|
||||
}
|
||||
|
||||
void inputSetStr(String key, String state) {
|
||||
eventGen2(key, state);
|
||||
jsonWriteStr(configLiveJson, key, state);
|
||||
publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern InputClass myInput;
|
||||
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Global.h"
|
||||
|
||||
class LoggingClass;
|
||||
|
||||
typedef std::vector<LoggingClass> MyLoggingVector;
|
||||
|
||||
class LoggingClass {
|
||||
public:
|
||||
|
||||
LoggingClass(unsigned long period, unsigned int maxPoints, String loggingValueKey, String key);
|
||||
~LoggingClass();
|
||||
|
||||
void loop();
|
||||
|
||||
private:
|
||||
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
unsigned long _period;
|
||||
unsigned int _maxPoints;
|
||||
String _loggingValueKey;
|
||||
String _key;
|
||||
|
||||
void addNewDelOldData(const String filename, size_t maxPoints, String payload);
|
||||
};
|
||||
|
||||
extern MyLoggingVector* myLogging;
|
||||
|
||||
extern void choose_log_date_and_send();
|
||||
extern void sendLogData(String file, String topic);
|
||||
extern void clean_log_date();
|
||||
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class OutputTextClass : public LineParsing {
|
||||
public:
|
||||
OutputTextClass() : LineParsing(){};
|
||||
|
||||
void OutputModuleStateSetDefault() {
|
||||
if (_state != "") {
|
||||
OutputModuleChange(_key, _state);
|
||||
}
|
||||
}
|
||||
|
||||
void OutputModuleChange(String key, String state) {
|
||||
state.replace("#", " ");
|
||||
eventGen2(key, state);
|
||||
jsonWriteStr(configLiveJson, key, state);
|
||||
publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
extern OutputTextClass myOutputText;
|
||||
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class PwmOutClass : public LineParsing {
|
||||
public:
|
||||
PwmOutClass() : LineParsing(){};
|
||||
|
||||
void pwmModeSet() {
|
||||
if (_pin != "") {
|
||||
pinMode(_pin.toInt(), INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void pwmStateSetDefault() {
|
||||
if (_state != "") {
|
||||
pwmChange(_key, _pin, _state);
|
||||
}
|
||||
}
|
||||
|
||||
void pwmChange(String key, String pin, String state) {
|
||||
int pinInt = pin.toInt();
|
||||
analogWrite(pinInt, state.toInt());
|
||||
eventGen2(key, state);
|
||||
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||
publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern PwmOutClass myPwmOut;
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
|
||||
class SensorAnalogClass : public SensorConvertingClass {
|
||||
public:
|
||||
SensorAnalogClass() : SensorConvertingClass(){};
|
||||
|
||||
void SensorAnalogInit() {
|
||||
jsonWriteStr(configOptionJson, _key + "_pin", _pin);
|
||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
}
|
||||
|
||||
int SensorAnalogRead(String key, String pin) {
|
||||
int value;
|
||||
#ifdef ESP32
|
||||
int pinInt = pin.toInt();
|
||||
value = analogRead(pinInt);
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
value = analogRead(A0);
|
||||
#endif
|
||||
value = this->mapping(key, value);
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
return value;
|
||||
}
|
||||
};
|
||||
extern SensorAnalogClass mySensorAnalog;
|
||||
@@ -1,55 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
|
||||
Adafruit_BME280 bme;
|
||||
Adafruit_Sensor *bme_temp = bme.getTemperatureSensor();
|
||||
Adafruit_Sensor *bme_pressure = bme.getPressureSensor();
|
||||
Adafruit_Sensor *bme_humidity = bme.getHumiditySensor();
|
||||
|
||||
class SensorBme280Class : public SensorConvertingClass {
|
||||
public:
|
||||
SensorBme280Class() : SensorConvertingClass(){};
|
||||
|
||||
void SensorBme280Init() {
|
||||
bme.begin(hexStringToUint8(_addr));
|
||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
sensorReadingMap10sec += _key + ",";
|
||||
}
|
||||
|
||||
void SensorBme280ReadTmp(String key) {
|
||||
float value;
|
||||
value = bme.readTemperature();
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
}
|
||||
|
||||
void SensorBme280ReadHum(String key) {
|
||||
float value;
|
||||
value = bme.readHumidity();
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
}
|
||||
|
||||
void SensorBme280ReadPress(String key) {
|
||||
float value;
|
||||
value = bme.readPressure();
|
||||
value = value / 1.333224 / 100;
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
}
|
||||
};
|
||||
extern SensorBme280Class mySensorBme280;
|
||||
@@ -1,48 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
|
||||
Adafruit_BMP280 bmp;
|
||||
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
|
||||
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
|
||||
|
||||
class SensorBmp280Class : public SensorConvertingClass {
|
||||
public:
|
||||
SensorBmp280Class() : SensorConvertingClass(){};
|
||||
|
||||
void SensorBmp280Init() {
|
||||
bmp.begin(hexStringToUint8(_addr));
|
||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
sensorReadingMap10sec += _key + ",";
|
||||
}
|
||||
|
||||
void SensorBmp280ReadTmp(String key) {
|
||||
float value;
|
||||
sensors_event_t temp_event;
|
||||
bmp_temp->getEvent(&temp_event);
|
||||
value = temp_event.temperature;
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
}
|
||||
|
||||
void SensorBmp280ReadPress(String key) {
|
||||
float value;
|
||||
sensors_event_t pressure_event;
|
||||
bmp_pressure->getEvent(&pressure_event);
|
||||
value = pressure_event.pressure;
|
||||
value = value / 1.333224;
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
}
|
||||
};
|
||||
extern SensorBmp280Class mySensorBmp280;
|
||||
@@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorConvertingClass : public LineParsing {
|
||||
public:
|
||||
SensorConvertingClass() : LineParsing(){};
|
||||
|
||||
int mapping(String key, int input) {
|
||||
String map_ = jsonReadStr(configOptionJson, key + "_map");
|
||||
if (map_ != "") {
|
||||
input = map(input,
|
||||
selectFromMarkerToMarker(map_, ",", 0).toInt(),
|
||||
selectFromMarkerToMarker(map_, ",", 1).toInt(),
|
||||
selectFromMarkerToMarker(map_, ",", 2).toInt(),
|
||||
selectFromMarkerToMarker(map_, ",", 3).toInt());
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
float correction(String key, float input) {
|
||||
String corr = jsonReadStr(configOptionJson, key + "_с");
|
||||
if (corr != "") {
|
||||
float coef = corr.toFloat();
|
||||
input = input * coef;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
extern DallasTemperature sensors;
|
||||
extern OneWire* oneWire;
|
||||
|
||||
class SensorDallas;
|
||||
|
||||
typedef std::vector<SensorDallas> MySensorDallasVector;
|
||||
|
||||
class SensorDallas {
|
||||
public:
|
||||
|
||||
SensorDallas(unsigned long interval, unsigned int pin, unsigned int index, String key);
|
||||
~SensorDallas();
|
||||
|
||||
void loop();
|
||||
void readDallas();
|
||||
|
||||
private:
|
||||
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
unsigned long _interval;
|
||||
String _key;
|
||||
unsigned int _pin;
|
||||
unsigned int _index;
|
||||
|
||||
};
|
||||
|
||||
extern MySensorDallasVector* mySensorDallas2;
|
||||
|
||||
extern void dallas();
|
||||
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
|
||||
DHTesp dht;
|
||||
class SensorDhtClass : public SensorConvertingClass {
|
||||
public:
|
||||
SensorDhtClass() : SensorConvertingClass(){};
|
||||
|
||||
void SensorDhtInit() {
|
||||
if (_type == "dht11") {
|
||||
dht.setup(_pin.toInt(), DHTesp::DHT11);
|
||||
}
|
||||
if (_type == "dht22") {
|
||||
dht.setup(_pin.toInt(), DHTesp::DHT22);
|
||||
}
|
||||
sensorReadingMap10sec += _key + ",";
|
||||
|
||||
//to do если надо будет читать несколько dht
|
||||
//dhtEnterCounter++;
|
||||
//jsonWriteInt(configOptionJson, _key + "_num", dhtEnterCounter);
|
||||
|
||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
}
|
||||
|
||||
void SensorDhtReadTemp(String key) {
|
||||
//to do если надо будет читать несколько dht
|
||||
//int cnt = jsonReadInt(configOptionJson, key + "_num");
|
||||
float value;
|
||||
static int counter;
|
||||
if (dht.getStatus() != 0 && counter < 5) {
|
||||
counter++;
|
||||
//return;
|
||||
} else {
|
||||
counter = 0;
|
||||
value = dht.getTemperature();
|
||||
if (String(value) != "nan") {
|
||||
//value = this->mapping(key, value);
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
} else {
|
||||
Serial.println("[E] sensor '" + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SensorDhtReadHum(String key) {
|
||||
//to do если надо будет читать несколько dht
|
||||
//int cnt = jsonReadInt(configOptionJson, key + "_num");
|
||||
float value;
|
||||
static int counter;
|
||||
if (dht.getStatus() != 0 && counter < 5) {
|
||||
counter++;
|
||||
//return;
|
||||
} else {
|
||||
counter = 0;
|
||||
value = dht.getHumidity();
|
||||
if (String(value) != "nan") {
|
||||
//value = this->mapping(key, value);
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
} else {
|
||||
Serial.println("[E] sensor '" + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
extern SensorDhtClass mySensorDht;
|
||||
@@ -1,83 +0,0 @@
|
||||
//#pragma once
|
||||
//#include <Arduino.h>
|
||||
//#include <ModbusMaster.h>
|
||||
//#include <SoftwareSerial.h>
|
||||
//
|
||||
//#include "Class/LineParsing.h"
|
||||
//#include "Global.h"
|
||||
//#include "items/SensorConvertingClass.h"
|
||||
//
|
||||
//ModbusMaster modbus1;
|
||||
//SoftwareSerial uart(13, 12); // RX, TX
|
||||
//
|
||||
//class SensorModbusClass : public SensorConvertingClass {
|
||||
// public:
|
||||
// SensorModbusClass() : SensorConvertingClass(){};
|
||||
//
|
||||
// void SensorModbusInit() {
|
||||
// uart.begin(9600);
|
||||
// jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
// jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
// sensorReadingMap10sec += _key + " " + _addr + " " + _reg + ",";
|
||||
// Serial.println(sensorReadingMap10sec);
|
||||
// }
|
||||
//
|
||||
// void SensorModbusRead(String key, uint8_t slaveAddress, uint16_t regAddress) {
|
||||
// int value;
|
||||
//
|
||||
// modbus1.begin(slaveAddress, uart);
|
||||
// uint16_t reqisterValue = modbus1.readHoldingRegisters(regAddress, 1);
|
||||
// if (getResultMsg(&modbus1, reqisterValue)) {
|
||||
// reqisterValue = modbus1.getResponseBuffer(0);
|
||||
// value = reqisterValue;
|
||||
// } else {
|
||||
// value = NULL;
|
||||
// }
|
||||
//
|
||||
// int valueFl = this->correction(key, value);
|
||||
// eventGen2(key, String(valueFl));
|
||||
// jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
// publishStatus(key, String(valueFl));
|
||||
// SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl) + ", Slave dev addr: " + String(slaveAddress) + ", Register: " + String(regAddress));
|
||||
// }
|
||||
//
|
||||
// bool getResultMsg(ModbusMaster* modbus1, uint16_t result) {
|
||||
// String tmpstr;
|
||||
// switch (result) {
|
||||
// case modbus1->ku8MBSuccess:
|
||||
// return true;
|
||||
// tmpstr += "Ok";
|
||||
// break;
|
||||
// case modbus1->ku8MBIllegalFunction:
|
||||
// tmpstr += "Illegal Function";
|
||||
// break;
|
||||
// case modbus1->ku8MBIllegalDataAddress:
|
||||
// tmpstr += "Illegal Data Address";
|
||||
// break;
|
||||
// case modbus1->ku8MBIllegalDataValue:
|
||||
// tmpstr += "Illegal Data Value";
|
||||
// break;
|
||||
// case modbus1->ku8MBSlaveDeviceFailure:
|
||||
// tmpstr += "Slave Device Failure";
|
||||
// break;
|
||||
// case modbus1->ku8MBInvalidSlaveID:
|
||||
// tmpstr += "Invalid Slave ID";
|
||||
// break;
|
||||
// case modbus1->ku8MBInvalidFunction:
|
||||
// tmpstr += "Invalid Function";
|
||||
// break;
|
||||
// case modbus1->ku8MBResponseTimedOut:
|
||||
// tmpstr += "Response Timed Out";
|
||||
// break;
|
||||
// case modbus1->ku8MBInvalidCRC:
|
||||
// tmpstr += "Invalid CRC";
|
||||
// break;
|
||||
// default:
|
||||
// tmpstr += "Unknown error: " + String(result);
|
||||
// break;
|
||||
// }
|
||||
// SerialPrint("I", "Modbus", tmpstr);
|
||||
// return false;
|
||||
// }
|
||||
//};
|
||||
//extern SensorModbusClass mySensorModbus;
|
||||
@@ -1,49 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
#include "GyverFilters.h"
|
||||
|
||||
GMedian<6, int> testFilter;
|
||||
|
||||
class SensorUltrasonic : public SensorConvertingClass {
|
||||
public:
|
||||
SensorUltrasonic() : SensorConvertingClass(){};
|
||||
void init() {
|
||||
sensorReadingMap10sec += _key + ",";
|
||||
String trig = selectFromMarkerToMarker(_pin, ",", 0);
|
||||
String echo = selectFromMarkerToMarker(_pin, ",", 1);
|
||||
pinMode(trig.toInt(), OUTPUT);
|
||||
pinMode(echo.toInt(), INPUT);
|
||||
jsonWriteStr(configOptionJson, _key + "_trig", trig);
|
||||
jsonWriteStr(configOptionJson, _key + "_echo", echo);
|
||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
}
|
||||
|
||||
void SensorUltrasonicRead(String key) {
|
||||
int trig = jsonReadStr(configOptionJson, key + "_trig").toInt();
|
||||
int echo = jsonReadStr(configOptionJson, key + "_echo").toInt();
|
||||
int value;
|
||||
|
||||
digitalWrite(trig, LOW);
|
||||
delayMicroseconds(2);
|
||||
digitalWrite(trig, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(trig, LOW);
|
||||
long duration_ = pulseIn(echo, HIGH, 30000); // 3000 µs = 50cm // 30000 µs = 5 m
|
||||
value = duration_ / 29 / 2;
|
||||
|
||||
value = testFilter.filtered(value);
|
||||
|
||||
value = this->mapping(key, value);
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen2(key, String(valueFl));
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
publishStatus(key, String(valueFl));
|
||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
||||
}
|
||||
};
|
||||
extern SensorUltrasonic mySensorUltrasonic;
|
||||
Reference in New Issue
Block a user