mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Fixed Ultrasonic, Start uart
This commit is contained in:
@@ -29,4 +29,4 @@ class SensorConvertingClass : public LineParsing {
|
||||
}
|
||||
return input;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
#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;
|
||||
//#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;
|
||||
47
include/items/vSensorUltrasonic.h
Normal file
47
include/items/vSensorUltrasonic.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#include <Arduino.h>
|
||||
#include "items/SensorConvertingClass.h"
|
||||
#include "GyverFilters.h"
|
||||
|
||||
class SensorUltrasonic;
|
||||
|
||||
typedef std::vector<SensorUltrasonic> MySensorUltrasonicVector;
|
||||
|
||||
|
||||
|
||||
class SensorUltrasonic : public SensorConvertingClass {
|
||||
public:
|
||||
|
||||
SensorUltrasonic(String key, unsigned long interval, unsigned int trig, unsigned int echo, int map1, int map2, int map3, int map4, float c);
|
||||
~SensorUltrasonic();
|
||||
|
||||
void loop();
|
||||
void readUltrasonic();
|
||||
|
||||
private:
|
||||
|
||||
unsigned long currentMillis;
|
||||
unsigned long prevMillis;
|
||||
unsigned long difference;
|
||||
|
||||
unsigned long _interval;
|
||||
|
||||
String _key;
|
||||
unsigned int _echo;
|
||||
unsigned int _trig;
|
||||
|
||||
int _map1;
|
||||
int _map2;
|
||||
int _map3;
|
||||
int _map4;
|
||||
|
||||
float _c;
|
||||
|
||||
};
|
||||
|
||||
extern MySensorUltrasonicVector* mySensorUltrasonic;
|
||||
|
||||
extern void ultrasonic();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user