This commit is contained in:
Dmitry Borisenko
2021-01-04 00:39:35 +01:00
parent bf9855aa60
commit 5eb3c6d3a3
339 changed files with 21164 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
#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;

253
include/Class/LineParsing.h Normal file
View File

@@ -0,0 +1,253 @@
#pragma once
#include <Arduino.h>
#include "Global.h"
#include "ItemsList.h"
#include "Utils/JsonUtils.h"
class LineParsing {
protected:
String _key;
String _file;
String _page;
String _descr;
String _order;
String _addr;
String _reg;
String _pin;
String _map;
String _c;
String _inv;
String _state;
String _db;
String _type;
String _int;
String _cnt;
String _val;
String _index;
int pinErrors;
public:
LineParsing() :
_key{""},
_file{""},
_page{""},
_descr{""},
_order{""},
_addr{""},
_reg{""},
_pin{""},
_map{""},
_c{""},
_inv{""},
_state{""},
_db{""},
_type{""},
_int{""},
_cnt{""},
_val{""},
_index{""},
pinErrors{0}
{};
void update() {
//String order = sCmd.order();
//SerialPrint("I","module","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);
}
if (arg.indexOf("type[") != -1) {
_type = extractInner(arg);
}
if (arg.indexOf("addr[") != -1) {
_addr = extractInner(arg);
}
if (arg.indexOf("reg[") != -1) {
_reg = extractInner(arg);
}
if (arg.indexOf("int[") != -1) {
_int = extractInner(arg);
}
if (arg.indexOf("cnt[") != -1) {
_cnt = extractInner(arg);
}
if (arg.indexOf("val[") != -1) {
_val = extractInner(arg);
}
if (arg.indexOf("index[") != -1) {
_index = extractInner(arg);
}
}
}
if (_pin != "") {
if (!isPinExist(_pin.toInt()) || !isDigitStr(_pin)) {
pinErrors++;
Serial.println("'" + _pin + "'");
_pin = "";
}
}
_page.replace("#", " ");
_descr.replace("#", " ");
_descr.replace("%ver%", String(FIRMWARE_VERSION));
_descr.replace("%name%", jsonReadStr(configSetupJson, F("name")));
createWidget(_descr, _page, _order, _file, _key);
}
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;
}
String gtype() {
return _type;
}
String gaddr() {
return _addr;
}
String gregaddr() {
return _reg;
}
String gint() {
return _int;
}
String gcnt() {
return _cnt;
}
String gval() {
return _val;
}
String gindex() {
return _index;
}
int getPinErrors() {
return pinErrors;
}
void clearErrors() {
pinErrors = 0;
}
void clear() {
_key = "";
_file = "";
_page = "";
_descr = "";
_order = "";
_addr = "";
_reg = "";
_pin = "";
_map = "";
_c = "";
_inv = "";
_state = "";
_db = "";
_type = "";
_int = "";
_cnt = "";
_val = "";
_index = "";
}
String extractInnerDigit(String str) {
int p1 = str.indexOf("[");
int p2 = str.indexOf("]");
return str.substring(p1 + 1, p2);
}
void createWidget(String descr, String page, String order, String filename, String topic) {
if (filename != "na") {
String buf = "{}";
if (!loadWidget(filename, buf)) {
return;
}
if (filename.indexOf("chart") != -1) jsonWriteStr(buf, "maxCount", _cnt);
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 loadWidget(const String& filename, String& buf) {
buf = readFile(getWidgetFile(filename), 2048);
bool res = !(buf == "Failed" || buf == "Large");
if (!res) {
//SerialPrint("[E]","module","on load" + filename);
}
return res;
}
const String getWidgetFile(const String& name) {
return "/widgets/" + name + ".json";
}
};
extern LineParsing myLineParsing;

32
include/Class/NotAsync.h Normal file
View File

@@ -0,0 +1,32 @@
#pragma once
#include <Arduino.h>
#include <stdint.h>
#include <functional>
typedef std::function<void(void*)> NotAsyncCb;
struct NotAsyncItem {
bool test;
NotAsyncCb cb;
void* cb_arg;
volatile bool is_used = false;
};
class NotAsync {
private:
uint8_t size;
uint8_t task = 0;
NotAsyncItem* items = NULL;
void handle(NotAsyncCb f, void* arg);
public:
NotAsync(uint8_t size);
~NotAsync();
void add(uint8_t i, NotAsyncCb, void* arg);
void make(uint8_t task);
void loop();
};
extern NotAsync* myNotAsyncActions;

View File

@@ -0,0 +1,85 @@
#pragma once
#include <Arduino.h>
#include "Cmd.h"
#include "Global.h"
class Scenario {
public:
void loop() {
if (!jsonReadBool(configSetupJson, "scen")) {
return;
}
String allBlocks = scenario;
allBlocks.replace("\r\n", "\n");
allBlocks.replace("\r", "\n");
allBlocks += "\n";
String incommingEvent = selectToMarker(eventBuf, ",");
String incommingEventKey = selectToMarker(incommingEvent, " ");
String incommingEventValue = selectToMarkerLast(incommingEvent, " ");
while (allBlocks.length() > 1) {
String oneBlock = selectToMarker(allBlocks, "end\n");
String condition = selectToMarker(oneBlock, "\n");
String setEventKey = selectFromMarkerToMarker(condition, " ", 0);
if (incommingEventKey == setEventKey) {
String setEventSign = selectFromMarkerToMarker(condition, " ", 1);
String setEventValue = selectFromMarkerToMarker(condition, " ", 2);
if (!isDigitDotCommaStr(setEventValue)) {
if (setEventValue.indexOf("+-") != -1) {
String setEventValueName = selectToMarker(setEventValue, "+-");
String gisteresisValue = selectToMarkerLast(setEventValue, "+-");
gisteresisValue.replace("+-", "");
String value = getValue(setEventValueName);
String upValue = String(value.toFloat() + gisteresisValue.toFloat());
String lowValue = String(value.toFloat() - gisteresisValue.toFloat());
if (setEventSign == ">") {
setEventValue = upValue;
} else if (setEventSign == "<") {
setEventValue = lowValue;
}
} else {
setEventValue = getValue(setEventValue);
}
}
boolean flag = false;
if (setEventSign == "=") {
flag = incommingEventValue == setEventValue;
} else if (setEventSign == "!=") {
flag = incommingEventValue != setEventValue;
} else if (setEventSign == "<") {
flag = incommingEventValue.toFloat() < setEventValue.toFloat();
} else if (setEventSign == ">") {
flag = incommingEventValue.toFloat() > setEventValue.toFloat();
} else if (setEventSign == ">=") {
flag = incommingEventValue.toFloat() >= setEventValue.toFloat();
} else if (setEventSign == "<=") {
flag = incommingEventValue.toFloat() <= setEventValue.toFloat();
}
if (flag) {
//SerialPrint("I", "Scenario", "incomming Event Value: " + incommingEventValue);
//SerialPrint("I", "Scenario", "set Event Value: " + setEventValue);
oneBlock = deleteBeforeDelimiter(oneBlock, "\n");
oneBlock.replace("end", "");
SerialPrint("I", "Scenario", condition + " \n" + oneBlock);
spaceCmdExecute(oneBlock);
}
}
allBlocks = deleteBeforeDelimiter(allBlocks, "end\n");
}
eventBuf = deleteBeforeDelimiter(eventBuf, ",");
}
};
extern Scenario* myScenario;
extern void streamEventUDP(String event);