mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
revert
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <stdint.h>
|
||||
#include <functional>
|
||||
|
||||
// Декларируем тип - сигнатуру метода , который мы готовы принять в данном случае это
|
||||
// должен быть метод без результата и без параметров.
|
||||
// Новый тип мы называем AsynсActionCb - хотя можешь назвать вообще как нравиться а что значит callBack
|
||||
|
||||
typedef std::function<void()> AsyncActionCb; //метод без результата и параметров
|
||||
typedef std::function<bool(const String)> AsyncParamActionCb; //метод без результата и параметров
|
||||
|
||||
class CallBackTest {
|
||||
private:
|
||||
long count;
|
||||
AsyncActionCb _cb;
|
||||
AsyncParamActionCb _pcb;
|
||||
|
||||
|
||||
public:
|
||||
CallBackTest();
|
||||
void loop();
|
||||
void setCallback(AsyncActionCb cb);
|
||||
void setCallback(AsyncParamActionCb pcb);
|
||||
};
|
||||
//extern CallBackTest* CB;
|
||||
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Input : public LineParsing {
|
||||
public:
|
||||
Input() : LineParsing(){};
|
||||
|
||||
void inputSetDefaultFloat() {
|
||||
inputSetFloat(_key, _state);
|
||||
}
|
||||
|
||||
void inputSetDefaultStr() {
|
||||
inputSetStr(_key, _state);
|
||||
}
|
||||
|
||||
void inputSetFloat(String key, String state) {
|
||||
eventGen(key, "");
|
||||
jsonWriteFloat(configLiveJson, key, state.toFloat());
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
|
||||
void inputSetStr(String key, String state) {
|
||||
eventGen(key, "");
|
||||
jsonWriteStr(configLiveJson, key, state);
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern Input* myInput;
|
||||
@@ -1,177 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Global.h"
|
||||
#include "Utils/JsonUtils.h"
|
||||
|
||||
class LineParsing {
|
||||
protected:
|
||||
String _key;
|
||||
String _file;
|
||||
String _page;
|
||||
String _descr;
|
||||
String _order;
|
||||
|
||||
String _addr;
|
||||
String _pin;
|
||||
String _map;
|
||||
String _c;
|
||||
String _inv;
|
||||
String _state;
|
||||
String _db;
|
||||
|
||||
public:
|
||||
LineParsing() :
|
||||
|
||||
_key{""},
|
||||
_file{""},
|
||||
_page{""},
|
||||
_descr{""},
|
||||
_order{""},
|
||||
_addr{""},
|
||||
_pin{""},
|
||||
_map{""},
|
||||
_c{""},
|
||||
_inv{""},
|
||||
_state{""},
|
||||
_db{""}
|
||||
|
||||
{};
|
||||
|
||||
void update() {
|
||||
//String order = sCmd.order();
|
||||
//pm.info("create '" + order + "'");
|
||||
for (int i = 1; i < 12; i++) {
|
||||
if (i == 1) _key = sCmd.next();
|
||||
if (i == 2) _file = sCmd.next();
|
||||
if (i == 3) _page = sCmd.next();
|
||||
if (i == 4) _descr = sCmd.next();
|
||||
if (i == 5) _order = sCmd.next();
|
||||
}
|
||||
|
||||
for (int i = 1; i < 10; i++) {
|
||||
String arg = sCmd.next();
|
||||
if (arg != "") {
|
||||
if (arg.indexOf("pin[") != -1) {
|
||||
_pin = extractInner(arg);
|
||||
}
|
||||
if (arg.indexOf("inv[") != -1) {
|
||||
_inv = extractInner(arg);
|
||||
}
|
||||
if (arg.indexOf("st[") != -1) {
|
||||
_state = extractInner(arg);
|
||||
}
|
||||
if (arg.indexOf("db[") != -1) {
|
||||
_db = extractInner(arg);
|
||||
}
|
||||
if (arg.indexOf("map[") != -1) {
|
||||
_map = extractInner(arg);
|
||||
}
|
||||
if (arg.indexOf("c[") != -1) {
|
||||
_c = extractInner(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_page.replace("#", " ");
|
||||
|
||||
_descr.replace("#", " ");
|
||||
|
||||
createWidgetClass(_descr, _page, _order, _file, _key);
|
||||
}
|
||||
|
||||
//jsonWriteStr(configOptionJson, _key + "_pin", _pin);
|
||||
|
||||
String gkey() {
|
||||
return _key;
|
||||
}
|
||||
String gfile() {
|
||||
return _file;
|
||||
}
|
||||
String gpage() {
|
||||
return _page;
|
||||
}
|
||||
String gdescr() {
|
||||
return _descr;
|
||||
}
|
||||
String gorder() {
|
||||
return _order;
|
||||
}
|
||||
String gpin() {
|
||||
return _pin; //
|
||||
}
|
||||
String ginv() {
|
||||
return _inv; //
|
||||
}
|
||||
String gstate() {
|
||||
return _state;
|
||||
}
|
||||
String gmap() {
|
||||
return _map;
|
||||
}
|
||||
String gc() {
|
||||
return _c;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_key = "";
|
||||
_file = "";
|
||||
_page = "";
|
||||
_descr = "";
|
||||
_order = "";
|
||||
_addr = "";
|
||||
_pin = "";
|
||||
_map = "";
|
||||
_c = "";
|
||||
_inv = "";
|
||||
_state = "";
|
||||
_db = "";
|
||||
}
|
||||
|
||||
String extractInnerDigit(String str) {
|
||||
int p1 = str.indexOf("[");
|
||||
int p2 = str.indexOf("]");
|
||||
return str.substring(p1 + 1, p2);
|
||||
}
|
||||
|
||||
void createWidgetClass(String descr, String page, String order, String filename, String topic) {
|
||||
String buf = "{}";
|
||||
if (!loadWidgetClass(filename, buf)) {
|
||||
return;
|
||||
}
|
||||
|
||||
jsonWriteStr(buf, "page", page);
|
||||
jsonWriteStr(buf, "order", order);
|
||||
jsonWriteStr(buf, "descr", descr);
|
||||
jsonWriteStr(buf, "topic", prex + "/" + topic);
|
||||
|
||||
#ifdef LAYOUT_IN_RAM
|
||||
all_widgets += widget + "\r\n";
|
||||
#else
|
||||
addFileLn("layout.txt", buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool loadWidgetClass(const String& filename, String& buf) {
|
||||
buf = readFile(getWidgetFileClass(filename), 2048);
|
||||
bool res = !(buf == "Failed" || buf == "Large");
|
||||
if (!res) {
|
||||
//pm.error("on load" + filename);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
const String getWidgetFileClass(const String& name) {
|
||||
return "/widgets/" + name + ".json";
|
||||
}
|
||||
|
||||
//String jsonWriteStr1(String& json, String name, String value) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// root[name] = value;
|
||||
// json = "";
|
||||
// root.printTo(json);
|
||||
// return json;
|
||||
//}
|
||||
};
|
||||
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
typedef std::function<void(void*)> NotAsincCb;
|
||||
|
||||
struct NotAsincItem {
|
||||
bool test;
|
||||
NotAsincCb cb;
|
||||
void * cb_arg;
|
||||
volatile bool is_used = false;
|
||||
};
|
||||
|
||||
class NotAsinc {
|
||||
private:
|
||||
uint8_t size;
|
||||
uint8_t task = 0;
|
||||
NotAsincItem* items = NULL;
|
||||
void handle(NotAsincCb f, void* arg);
|
||||
|
||||
public:
|
||||
NotAsinc(uint8_t size);
|
||||
~NotAsinc();
|
||||
|
||||
void add(uint8_t i, NotAsincCb, void* arg);
|
||||
void make(uint8_t task);
|
||||
void loop();
|
||||
};
|
||||
extern NotAsinc* myNotAsincActions;
|
||||
@@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class OutputModule : public LineParsing {
|
||||
public:
|
||||
OutputModule() : LineParsing(){};
|
||||
|
||||
void OutputModuleStateSetDefault() {
|
||||
if (_state != "") {
|
||||
OutputModuleChange(_key, _state);
|
||||
}
|
||||
}
|
||||
|
||||
void OutputModuleChange(String key, String state) {
|
||||
state.replace("#", " ");
|
||||
eventGen(key, "");
|
||||
jsonWriteStr(configLiveJson, key, state);
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
extern OutputModule* myText;
|
||||
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Pwm : public LineParsing {
|
||||
public:
|
||||
Pwm() : 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());
|
||||
eventGen(key, "");
|
||||
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern Pwm* myPwm;
|
||||
@@ -1,113 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Cmd.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Scenario {
|
||||
protected:
|
||||
String _scenarioTmp;
|
||||
String _condition;
|
||||
String _conditionParam;
|
||||
String _conditionSign;
|
||||
String _conditionValue;
|
||||
String _scenBlok;
|
||||
String _event;
|
||||
String _eventParam;
|
||||
String _eventValue;
|
||||
|
||||
public:
|
||||
Scenario() : _scenarioTmp{""},
|
||||
_condition{""},
|
||||
_conditionParam{""},
|
||||
_conditionSign{""},
|
||||
_conditionValue{""},
|
||||
_scenBlok{""},
|
||||
_event{""},
|
||||
_eventParam{""},
|
||||
_eventValue{""} {};
|
||||
|
||||
void load() {
|
||||
_scenarioTmp = scenario;
|
||||
}
|
||||
|
||||
void calculate1() {
|
||||
_scenBlok = selectToMarker(_scenarioTmp, "end\n");
|
||||
_condition = selectToMarker(_scenBlok, "\n");
|
||||
_eventParam = selectToMarker(eventBuf, ",");
|
||||
}
|
||||
|
||||
bool isIncommingEventInScenario() {
|
||||
bool ret = false;
|
||||
if (_condition.indexOf(_eventParam) != -1) {
|
||||
ret = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void calculate2() {
|
||||
_scenarioTmp += "\n";
|
||||
_scenarioTmp.replace("\r\n", "\n");
|
||||
_scenarioTmp.replace("\r", "\n");
|
||||
|
||||
_conditionParam = selectFromMarkerToMarker(_condition, " ", 0);
|
||||
_conditionSign = selectFromMarkerToMarker(_condition, " ", 1);
|
||||
_conditionValue = selectFromMarkerToMarker(_condition, " ", 2);
|
||||
if (!isDigitStr(_conditionValue)) _conditionValue = jsonReadStr(configLiveJson, _conditionValue);
|
||||
_eventValue = jsonReadStr(configLiveJson, _conditionParam);
|
||||
}
|
||||
|
||||
void delOneScenBlock() {
|
||||
_scenarioTmp = deleteBeforeDelimiter(_scenarioTmp, "end\n");
|
||||
}
|
||||
|
||||
void delOneEvent() {
|
||||
eventBuf = deleteBeforeDelimiter(eventBuf, ",");
|
||||
}
|
||||
|
||||
bool isConditionSatisfied() {
|
||||
boolean flag = false;
|
||||
|
||||
if (_conditionSign == "=") {
|
||||
flag = _eventValue == _conditionValue;
|
||||
} else if (_conditionSign == "!=") {
|
||||
flag = _eventValue != _conditionValue;
|
||||
} else if (_conditionSign == "<") {
|
||||
flag = _eventValue.toInt() < _conditionValue.toInt();
|
||||
} else if (_conditionSign == ">") {
|
||||
flag = _eventValue.toInt() > _conditionValue.toInt();
|
||||
} else if (_conditionSign == ">=") {
|
||||
flag = _eventValue.toInt() >= _conditionValue.toInt();
|
||||
} else if (_conditionSign == "<=") {
|
||||
flag = _eventValue.toInt() <= _conditionValue.toInt();
|
||||
}
|
||||
|
||||
if (flag) Serial.println("[I] Scenario event: " + _condition);
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (!this->isScenarioEnabled()) {
|
||||
return;
|
||||
}
|
||||
this->load(); //после этого мы получили все сценарии
|
||||
while (_scenarioTmp.length() > 1) {
|
||||
this->calculate1(); //расчет необходимый для ответа на следующий вопрос
|
||||
if (this->isIncommingEventInScenario()) { //если вошедшее событие есть в сценарии
|
||||
this->calculate2();
|
||||
if (this->isConditionSatisfied()) { //если вошедшее событие выполняет условие сценария
|
||||
_scenBlok = deleteBeforeDelimiter(_scenBlok, "\n");
|
||||
//Serial.println(" [>] Making: " + _scenBlok);
|
||||
spaceExecute(_scenBlok);
|
||||
}
|
||||
}
|
||||
this->delOneScenBlock(); //удалим использованный блок
|
||||
}
|
||||
this->delOneEvent();
|
||||
}
|
||||
|
||||
bool isScenarioEnabled() {
|
||||
return jsonReadBool(configSetupJson, "scen") && eventBuf != "";
|
||||
}
|
||||
};
|
||||
extern Scenario* myScenario;
|
||||
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Class/SensorConverting.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorAnalog : public SensorConverting {
|
||||
public:
|
||||
SensorAnalog() : SensorConverting(){};
|
||||
|
||||
void SensorAnalogInit(String key) {
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorConverting : public LineParsing {
|
||||
public:
|
||||
SensorConverting() : 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,56 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Switch : public LineParsing {
|
||||
protected:
|
||||
int numberEntering = 0;
|
||||
int state = _state.toInt();
|
||||
|
||||
public:
|
||||
Switch() : 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()) {
|
||||
}
|
||||
if (buttons[switch_number].rose()) {
|
||||
String key = jsonReadStr(configOptionJson, "switch_num_" + String(switch_number));
|
||||
state = !state;
|
||||
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) {
|
||||
eventGen(key, "");
|
||||
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern Switch* mySwitch;
|
||||
@@ -1,43 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Button1 : public LineParsing {
|
||||
public:
|
||||
Button1() : LineParsing(){};
|
||||
|
||||
void pinModeSet() {
|
||||
if (_pin != "") {
|
||||
pinMode(_pin.toInt(), OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void pinStateSetDefault() {
|
||||
if (_inv == "" && _state != "") {
|
||||
pinChange(_key, _pin, _state, true);
|
||||
}
|
||||
}
|
||||
|
||||
void pinStateSetInvDefault() {
|
||||
if (_inv != "" && _state != "") {
|
||||
pinChange(_key, _pin, _state, false);
|
||||
}
|
||||
}
|
||||
|
||||
void pinChange(String key, String pin, String state, bool rev) {
|
||||
int pinInt = pin.toInt();
|
||||
int stateInt;
|
||||
if (rev) {
|
||||
digitalWrite(pinInt, state.toInt());
|
||||
} else {
|
||||
digitalWrite(pinInt, !state.toInt());
|
||||
}
|
||||
eventGen(key, "");
|
||||
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern Button1* myButton;
|
||||
Reference in New Issue
Block a user