mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
not working version
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Switch : public LineParsing {
|
||||
class ButtonInClass : public LineParsing {
|
||||
protected:
|
||||
int numberEntering = 0;
|
||||
int state = _state.toInt();
|
||||
|
||||
public:
|
||||
Switch() : LineParsing(){};
|
||||
ButtonInClass() : LineParsing(){};
|
||||
|
||||
void init() {
|
||||
if (_pin != "") {
|
||||
@@ -53,4 +51,4 @@ class Switch : public LineParsing {
|
||||
}
|
||||
};
|
||||
|
||||
extern Switch* mySwitch;
|
||||
extern ButtonInClass* myButtonIn;
|
||||
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Button1 : public LineParsing {
|
||||
class ButtonOutClass : public LineParsing {
|
||||
public:
|
||||
Button1() : LineParsing(){};
|
||||
ButtonOutClass() : LineParsing(){};
|
||||
|
||||
void pinModeSet() {
|
||||
if (_pin != "") {
|
||||
@@ -40,4 +39,4 @@ class Button1 : public LineParsing {
|
||||
}
|
||||
};
|
||||
|
||||
extern Button1* myButton;
|
||||
extern ButtonOutClass* myButtonOut;
|
||||
@@ -1,13 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Input : public LineParsing {
|
||||
class InputClass : public LineParsing {
|
||||
public:
|
||||
Input() : LineParsing(){};
|
||||
InputClass() : LineParsing(){};
|
||||
|
||||
void inputSetDefaultFloat() {
|
||||
inputSetFloat(_key, _state);
|
||||
@@ -30,4 +28,4 @@ class Input : public LineParsing {
|
||||
}
|
||||
};
|
||||
|
||||
extern Input* myInput;
|
||||
extern InputClass* myInput;
|
||||
@@ -1,12 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class OutputModule : public LineParsing {
|
||||
class OutputTextClass : public LineParsing {
|
||||
public:
|
||||
OutputModule() : LineParsing(){};
|
||||
OutputTextClass() : LineParsing(){};
|
||||
|
||||
void OutputModuleStateSetDefault() {
|
||||
if (_state != "") {
|
||||
@@ -21,4 +20,4 @@ class OutputModule : public LineParsing {
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
extern OutputModule* myText;
|
||||
extern OutputTextClass* myOutputText;
|
||||
@@ -1,13 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Pwm : public LineParsing {
|
||||
class PwmOutClass : public LineParsing {
|
||||
public:
|
||||
Pwm() : LineParsing(){};
|
||||
PwmOutClass() : LineParsing(){};
|
||||
|
||||
void pwmModeSet() {
|
||||
if (_pin != "") {
|
||||
@@ -30,4 +28,4 @@ class Pwm : public LineParsing {
|
||||
}
|
||||
};
|
||||
|
||||
extern Pwm* myPwm;
|
||||
extern PwmOutClass* myPwmOut;
|
||||
@@ -1,35 +1,32 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Class/SensorConverting.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorAnalog : public SensorConverting {
|
||||
class SensorAnalogClass : public SensorConvertingClass {
|
||||
public:
|
||||
SensorAnalog() : SensorConverting(){};
|
||||
|
||||
void SensorAnalogInit(String key) {
|
||||
}
|
||||
SensorAnalogClass() : SensorConvertingClass(){};
|
||||
|
||||
int SensorAnalogRead(String key, String pin) {
|
||||
|
||||
int pinInt = pin.toInt();
|
||||
int value;
|
||||
|
||||
#ifdef ESP32
|
||||
value = analogRead(pinInt);
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
pinInt = pinInt;
|
||||
value = analogRead(A0);
|
||||
#endif
|
||||
|
||||
value = this->mapping(key, value);
|
||||
float valueFl = this->correction(key, value);
|
||||
|
||||
eventGen(key, "");
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
MqttClient::publishStatus(key, String(valueFl));
|
||||
|
||||
Serial.println("[I] sensor '" + key + "' data: " + String(valueFl));
|
||||
return value;
|
||||
}
|
||||
};
|
||||
extern SensorAnalog* mySensorAnalog;
|
||||
extern SensorAnalogClass* mySensorAnalog;
|
||||
@@ -5,9 +5,9 @@
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorConverting : public LineParsing {
|
||||
class SensorConvertingClass : public LineParsing {
|
||||
public:
|
||||
SensorConverting() : LineParsing(){};
|
||||
SensorConvertingClass() : LineParsing(){};
|
||||
|
||||
int mapping(String key, int input) {
|
||||
String map_ = jsonReadStr(configOptionJson, key + "_map");
|
||||
34
include/items/SensorUltrasonicClass.h
Normal file
34
include/items/SensorUltrasonicClass.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorUltrasonic : public SensorConvertingClass {
|
||||
public:
|
||||
SensorUltrasonic() : SensorConvertingClass(){};
|
||||
|
||||
int SensorUltrasonicRead(String key, String pin) {
|
||||
int trig = selectFromMarkerToMarker(pin, ",", 0).toInt();
|
||||
int echo = selectFromMarkerToMarker(pin, ",", 1).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 = this->mapping(key, value);
|
||||
float valueFl = this->correction(key, value);
|
||||
eventGen(key, "");
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
MqttClient::publishStatus(key, String(valueFl));
|
||||
Serial.println("[I] sensor '" + key + "' data: " + String(valueFl));
|
||||
return value;
|
||||
}
|
||||
};
|
||||
extern SensorUltrasonic* mySensorUltrasonic;
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "Class/Button.h"
|
||||
Button1* myButton;
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "Class/Input.h"
|
||||
Input* myInput;
|
||||
@@ -1 +0,0 @@
|
||||
#include "Class/LineParsing.h"
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "Class/OutputModule.h"
|
||||
OutputModule* myText;
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "Class/Pwm.h"
|
||||
Pwm* myPwm;
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "Class/SensorAnalog.h"
|
||||
SensorAnalog* mySensorAnalog;
|
||||
@@ -1,2 +0,0 @@
|
||||
#include "Class/Switch.h"
|
||||
Switch* mySwitch;
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "Class/SensorAnalog.h"
|
||||
#include "Cmd.h"
|
||||
#include "Global.h"
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
#include "items/itemsGlobal.h"
|
||||
#include "Class/Switch.h"
|
||||
#include "items/ButtonInClass.h"
|
||||
//==========================================Модуль физических кнопок========================================
|
||||
//button-in switch1 toggle Кнопки Свет 1 pin[2] db[20]
|
||||
//==========================================================================================================
|
||||
ButtonInClass* myButtonIn;
|
||||
void buttonIn() {
|
||||
mySwitch = new Switch();
|
||||
mySwitch->update();
|
||||
String key = mySwitch->gkey();
|
||||
String pin = mySwitch->gpin();
|
||||
myButtonIn = new ButtonInClass();
|
||||
myButtonIn->update();
|
||||
String key = myButtonIn->gkey();
|
||||
String pin = myButtonIn->gpin();
|
||||
sCmd.addCommand(key.c_str(), buttonInSet);
|
||||
mySwitch->init();
|
||||
mySwitch->switchStateSetDefault();
|
||||
mySwitch->clear();
|
||||
myButtonIn->init();
|
||||
myButtonIn->switchStateSetDefault();
|
||||
myButtonIn->clear();
|
||||
}
|
||||
|
||||
void buttonInSet() {
|
||||
String key = sCmd.order();
|
||||
String state = sCmd.next();
|
||||
mySwitch->switchChangeVirtual(key, state);
|
||||
myButtonIn->switchChangeVirtual(key, state);
|
||||
}
|
||||
@@ -1,21 +1,22 @@
|
||||
#include "items/itemsGlobal.h"
|
||||
#include "Class/Button.h"
|
||||
#include "items/ButtonOutClass.h"
|
||||
//==========================================Модуль кнопок===================================================
|
||||
//button-out light toggle Кнопки Свет 1 pin[12] inv[1] st[1]
|
||||
//==========================================================================================================
|
||||
ButtonOutClass* myButtonOut;
|
||||
void buttonOut() {
|
||||
myButton = new Button1();
|
||||
myButton->update();
|
||||
String key = myButton->gkey();
|
||||
String pin = myButton->gpin();
|
||||
String inv = myButton->ginv();
|
||||
myButtonOut = new ButtonOutClass();
|
||||
myButtonOut->update();
|
||||
String key = myButtonOut->gkey();
|
||||
String pin = myButtonOut->gpin();
|
||||
String inv = myButtonOut->ginv();
|
||||
sCmd.addCommand(key.c_str(), buttonOutSet);
|
||||
jsonWriteStr(configOptionJson, key + "_pin", pin);
|
||||
jsonWriteStr(configOptionJson, key + "_inv", inv);
|
||||
myButton->pinModeSet();
|
||||
myButton->pinStateSetDefault();
|
||||
myButton->pinStateSetInvDefault();
|
||||
myButton->clear();
|
||||
myButtonOut->pinModeSet();
|
||||
myButtonOut->pinStateSetDefault();
|
||||
myButtonOut->pinStateSetInvDefault();
|
||||
myButtonOut->clear();
|
||||
}
|
||||
|
||||
void buttonOutSet() {
|
||||
@@ -24,8 +25,8 @@ void buttonOutSet() {
|
||||
String pin = jsonReadStr(configOptionJson, key + "_pin");
|
||||
String inv = jsonReadStr(configOptionJson, key + "_inv");
|
||||
if (inv == "") {
|
||||
myButton->pinChange(key, pin, state, true);
|
||||
myButtonOut->pinChange(key, pin, state, true);
|
||||
} else {
|
||||
myButton->pinChange(key, pin, state, false);
|
||||
myButtonOut->pinChange(key, pin, state, false);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,20 @@
|
||||
#include "items/itemsGlobal.h"
|
||||
#include "Class/Input.h"
|
||||
#include "items/InputClass.h"
|
||||
//==========================================Модуль ввода цифровых значений==================================
|
||||
//input-digit digit1 inputDigit Ввод Введите.цифру 4 st[60]
|
||||
//==========================================================================================================
|
||||
InputClass* myInputDigit;
|
||||
void inputDigit() {
|
||||
myInput = new Input();
|
||||
myInput->update();
|
||||
String key = myInput->gkey();
|
||||
myInputDigit = new InputClass();
|
||||
myInputDigit->update();
|
||||
String key = myInputDigit->gkey();
|
||||
sCmd.addCommand(key.c_str(), inputDigitSet);
|
||||
myInput->inputSetDefaultFloat();
|
||||
myInput->clear();
|
||||
myInputDigit->inputSetDefaultFloat();
|
||||
myInputDigit->clear();
|
||||
}
|
||||
|
||||
void inputDigitSet() {
|
||||
String key = sCmd.order();
|
||||
String state = sCmd.next();
|
||||
myInput->inputSetFloat(key, state);
|
||||
myInputDigit->inputSetFloat(key, state);
|
||||
}
|
||||
@@ -1,21 +1,22 @@
|
||||
#include "items/itemsGlobal.h"
|
||||
#include "Class/Input.h"
|
||||
#include "items/InputClass.h"
|
||||
//==========================================Модуль ввода времени============================================
|
||||
//input-time time1 inputTime Ввод Введите.время 4 st[10-00-00]
|
||||
//==========================================================================================================
|
||||
InputClass* myInputTime;
|
||||
void inputTime() {
|
||||
myInput = new Input();
|
||||
myInput->update();
|
||||
String key = myInput->gkey();
|
||||
myInputTime = new InputClass();
|
||||
myInputTime->update();
|
||||
String key = myInputTime->gkey();
|
||||
sCmd.addCommand(key.c_str(), inputTimeSet);
|
||||
myInput->inputSetDefaultStr();
|
||||
myInput->clear();
|
||||
myInputTime->inputSetDefaultStr();
|
||||
myInputTime->clear();
|
||||
}
|
||||
|
||||
void inputTimeSet() {
|
||||
String key = sCmd.order();
|
||||
String state = sCmd.next();
|
||||
myInput->inputSetStr(key, state);
|
||||
myInputTime->inputSetStr(key, state);
|
||||
}
|
||||
|
||||
void handle_time_init() {
|
||||
@@ -1,19 +1,20 @@
|
||||
#include "items/itemsGlobal.h"
|
||||
#include "Class/OutputModule.h"
|
||||
#include "items/OutputTextClass.h"
|
||||
//===============================================Модуль вывода текста============================================
|
||||
//output-text;id;anydata;Вывод;Сигнализация;order;st[Обнаружено.движение]
|
||||
//===============================================================================================================
|
||||
OutputTextClass* myOutputText;
|
||||
void textOut() {
|
||||
myText = new OutputModule();
|
||||
myText->update();
|
||||
String key = myText->gkey();
|
||||
myOutputText = new OutputTextClass();
|
||||
myOutputText->update();
|
||||
String key = myOutputText->gkey();
|
||||
sCmd.addCommand(key.c_str(), textOutSet);
|
||||
myText->OutputModuleStateSetDefault();
|
||||
myText->clear();
|
||||
myOutputText->OutputModuleStateSetDefault();
|
||||
myOutputText->clear();
|
||||
}
|
||||
|
||||
void textOutSet() {
|
||||
String key = sCmd.order();
|
||||
String state = sCmd.next();
|
||||
myText->OutputModuleChange(key, state);
|
||||
myOutputText->OutputModuleChange(key, state);
|
||||
}
|
||||
@@ -1,24 +1,25 @@
|
||||
#include "items/itemsGlobal.h"
|
||||
#include "Class/Pwm.h"
|
||||
#include "items/PwmOutClass.h"
|
||||
//==========================================Модуль управления ШИМ===================================================
|
||||
//pwm-out volume range Кнопки Свет 1 pin[12] st[500]
|
||||
//==================================================================================================================
|
||||
PwmOutClass* myPwmOut;
|
||||
void pwmOut() {
|
||||
myPwm = new Pwm();
|
||||
myPwm->update();
|
||||
String key = myPwm->gkey();
|
||||
String pin = myPwm->gpin();
|
||||
String inv = myPwm->ginv();
|
||||
myPwmOut = new PwmOutClass();
|
||||
myPwmOut->update();
|
||||
String key = myPwmOut->gkey();
|
||||
String pin = myPwmOut->gpin();
|
||||
String inv = myPwmOut->ginv();
|
||||
sCmd.addCommand(key.c_str(), pwmOutSet);
|
||||
jsonWriteStr(configOptionJson, key + "_pin", pin);
|
||||
myPwm->pwmModeSet();
|
||||
myPwm->pwmStateSetDefault();
|
||||
myPwm->clear();
|
||||
myPwmOut->pwmModeSet();
|
||||
myPwmOut->pwmStateSetDefault();
|
||||
myPwmOut->clear();
|
||||
}
|
||||
|
||||
void pwmOutSet() {
|
||||
String key = sCmd.order();
|
||||
String state = sCmd.next();
|
||||
String pin = jsonReadStr(configOptionJson, key + "_pin");
|
||||
myPwm->pwmChange(key, pin, state);
|
||||
myPwmOut->pwmChange(key, pin, state);
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
#include "items/itemsGlobal.h"
|
||||
#include "Class/SensorAnalog.h"
|
||||
#include "items/SensorAnalogClass.h"
|
||||
#ifdef ANALOG_ENABLED
|
||||
//==============================================Модуль аналогового сенсора===========================================================================================
|
||||
//analog-adc;id;anydata;Сенсоры;Аналоговый;order;pin-adc;map[1,1024,1,100];c[1]
|
||||
//===================================================================================================================================================================
|
||||
SensorAnalogClass* mySensorAnalog;
|
||||
void analogAdc() {
|
||||
mySensorAnalog = new SensorAnalog();
|
||||
mySensorAnalog = new SensorAnalogClass();
|
||||
mySensorAnalog->update();
|
||||
String key = mySensorAnalog->gkey();
|
||||
String pin = mySensorAnalog->gpin();
|
||||
@@ -1,20 +1,35 @@
|
||||
#include "items/itemsGlobal.h"
|
||||
#include "Class/SensorAnalog.h"
|
||||
#ifdef LEVEL_ENABLED
|
||||
#include "items/SensorUltrasonicClass.h"
|
||||
//#ifdef LEVEL_ENABLED
|
||||
//=========================================Модуль ультрозвукового дальномера==================================================================
|
||||
//ultrasonic-cm;id;anydata;Сенсоры;Расстояние;order;pin;map[1,100,1,100];c[1]
|
||||
//ultrasonic-cm;id;anydata;Сенсоры;Расстояние;order;pin[12,13];map[1,100,1,100];c[1]
|
||||
//=========================================================================================================================================
|
||||
void ultrasonicCm() {
|
||||
|
||||
|
||||
mySensorUltrasonic = new SensorUltrasonic();
|
||||
mySensorUltrasonic->update();
|
||||
String key = mySensorUltrasonic->gkey();
|
||||
String pin = mySensorUltrasonic->gpin();
|
||||
String trig = selectFromMarkerToMarker(pin, ",", 0);
|
||||
String echo = selectFromMarkerToMarker(pin, ",", 1);
|
||||
sCmd.addCommand(key.c_str(), ultrasonicReading);
|
||||
sensorReadingMap += key + ",";
|
||||
jsonWriteStr(configOptionJson, key + "_trig", trig);
|
||||
jsonWriteStr(configOptionJson, key + "_echo", echo);
|
||||
jsonWriteStr(configOptionJson, key + "_map", mySensorUltrasonic->gmap());
|
||||
jsonWriteStr(configOptionJson, key + "_с", mySensorUltrasonic->gc());
|
||||
mySensorUltrasonic->clear();
|
||||
}
|
||||
|
||||
void ultrasonicReading() {
|
||||
|
||||
|
||||
String key = sCmd.order();
|
||||
String trig = jsonReadStr(configOptionJson, key + "_trig");
|
||||
String echo = jsonReadStr(configOptionJson, key + "_echo");
|
||||
String pin = trig + "," + echo;
|
||||
mySensorUltrasonic->SensorUltrasonicRead(key, pin);
|
||||
}
|
||||
//#endif
|
||||
|
||||
void levelPr() {
|
||||
//void levelPr() {
|
||||
// String value_name = sCmd.next();
|
||||
// String trig = sCmd.next();
|
||||
// String echo = sCmd.next();
|
||||
@@ -33,7 +48,7 @@ void levelPr() {
|
||||
// pinMode(echo.toInt(), INPUT);
|
||||
// createWidgetByType(widget_name, page_name, page_number, type, value_name);
|
||||
// sensors_reading_map[0] = 1;
|
||||
}
|
||||
//}
|
||||
////ultrasonicCm cm 14 12 Дистанция,#см Датчики fillgauge 1
|
||||
//void ultrasonicCm() {
|
||||
// String value_name = sCmd.next();
|
||||
@@ -54,20 +69,13 @@ void levelPr() {
|
||||
// sensors_reading_map[0] = 1;
|
||||
//}
|
||||
//
|
||||
void ultrasonic_reading() {
|
||||
//void ultrasonic_reading() {
|
||||
// long duration_;
|
||||
// int distance_cm;
|
||||
// int level;
|
||||
// static int counter;
|
||||
// int trig = jsonReadInt(configOptionJson, "trig");
|
||||
// int echo = jsonReadInt(configOptionJson, "echo");
|
||||
// digitalWrite(trig, LOW);
|
||||
// delayMicroseconds(2);
|
||||
// digitalWrite(trig, HIGH);
|
||||
// delayMicroseconds(10);
|
||||
// digitalWrite(trig, LOW);
|
||||
// duration_ = pulseIn(echo, HIGH, 30000); // 3000 µs = 50cm // 30000 µs = 5 m
|
||||
// distance_cm = duration_ / 29 / 2;
|
||||
// distance_cm = medianFilter.filtered(distance_cm); //отсечение промахов медианным фильтром
|
||||
// counter++;
|
||||
// if (counter > TANK_LEVEL_SAMPLES) {
|
||||
@@ -90,5 +98,5 @@ void ultrasonic_reading() {
|
||||
//
|
||||
// Serial.println("[I] sensor '" + ultrasonicCm_value_name + "' data: " + String(distance_cm));
|
||||
// }
|
||||
}
|
||||
#endif
|
||||
//}
|
||||
//
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Class/CallBackTest.h"
|
||||
#include "Class/NotAsinc.h"
|
||||
#include "Class/ScenarioClass.h"
|
||||
#include "Class/Switch.h"
|
||||
#include "items/ButtonInClass.h"
|
||||
#include "Cmd.h"
|
||||
#include "Global.h"
|
||||
#include "Init.h"
|
||||
@@ -101,7 +101,7 @@ void loop() {
|
||||
#endif
|
||||
timeNow->loop();
|
||||
MqttClient::loop();
|
||||
mySwitch->loop();
|
||||
myButtonIn->loop();
|
||||
myScenario->loop();
|
||||
//loopScenario();
|
||||
loopCmd();
|
||||
|
||||
Reference in New Issue
Block a user