This commit is contained in:
Dmitry Borisenko
2020-08-24 13:56:12 +03:00
parent 82b1fb6846
commit e44d2dc793
12 changed files with 187 additions and 44 deletions

View File

@@ -0,0 +1,13 @@
#include "Class/AsyncActions.h"
AsyncActions::AsyncActions(){};
void AsyncActions::loop() {
count++;
if (count > 5000) {
if(_cb) _cb; //что означает эта запись? это и есть вызов callback?
count = 0;
}
}
AsyncActions* async;

View File

@@ -4,7 +4,7 @@ static const char* firstLine PROGMEM = "Тип элемента;Id;Виджет;
void addElement(String name) {
String item = readFile("items/" + name + ".txt", 1024);
item.replace("id", "id" + String(getNewElementNumber("id.txt")));
item.replace("order", String(getNewElementNumber("order.txt")));
@@ -21,7 +21,6 @@ void delAllElement() {
removeFile("order.txt");
}
int getNewElementNumber(String file) {
int number = readFile(file, 100).toInt();
number++;
@@ -30,7 +29,37 @@ int getNewElementNumber(String file) {
return number;
}
void do_getJsonListFromCsv() {
if (getJsonListFromCsvFlag) {
getJsonListFromCsvFlag = false;
removeFile("items/elements.json");
addFile("items/elements.json", getJsonListFromCsv("conf.csv", 1));
}
}
String getJsonListFromCsv(String csvFile, int colum) {
File configFile = LittleFS.open("/" + csvFile, "r");
if (!configFile) {
return "error";
}
configFile.seek(0, SeekSet);
String outJson = "{}";
int count = -1;
while (configFile.position() != configFile.size()) {
count++;
String item = configFile.readStringUntil('\n');
if (count > 0) {
String line = selectFromMarkerToMarker(item, ";", colum);
jsonWriteStr(outJson, line, line);
}
}
configFile.close();
csvFile = "";
return outJson;
}
void do_delElement() {
if (delElementFlag) {

View File

@@ -85,4 +85,8 @@ boolean mqtt_send_settings_to_udp = false;
BusScanner_t busToScan;
boolean busScanFlag = false;
boolean fsCheckFlag = false;
boolean delElementFlag = false;
boolean delElementFlag = false;
boolean getJsonListFromCsvFlag = false;
String csvFile = "";
int colum;

View File

@@ -42,21 +42,27 @@ void web_init() {
if (request->hasArg("element")) {
String name = request->getParam("element")->value();
addElement(name);
getJsonListFromCsvFlag = true;
Device_init();
request->redirect("/?setn.device");
}
if (request->hasArg("cleanconf")) {
delAllElement();
removeFile("items/elements.json");
Device_init();
request->redirect("/?setn.device");
}
if (request->hasArg("save")) {
Device_init();
getJsonListFromCsvFlag = true;
request->redirect("/?setn.device");
}
//--------------------------------------------------------------------------------
if (request->hasArg("devinit")) {
Device_init();

View File

@@ -1,11 +1,12 @@
#include "Global.h"
#include "Init.h"
#include "Cmd.h"
#include "HttpServer.h"
#include "Bus/BusScannerFactory.h"
#include "Utils/Timings.h"
#include "Class/Switch.h"
#include "Cmd.h"
#include "DeviceList.h"
#include "Global.h"
#include "HttpServer.h"
#include "Init.h"
#include "Utils/Timings.h"
#include "Class/AsyncActions.h"
void not_async_actions();
@@ -67,49 +68,54 @@ void setup() {
pm.info("Broadcast UDP");
udp_init();
#endif
ts.add(
TEST, 1000 * 60, [&](void*) {
pm.info(printMemoryStatus());
},
nullptr, true);
ts.add(TEST, 1000 * 60, [&](void*) { pm.info(printMemoryStatus()); }, nullptr, true);
just_load = false;
initialized = true;
async = new AsyncActions();
//async->setCallback([&](void*) {
//
//
//});
async->setCallback(myCallback); //
}
void loop() {
if (!initialized) {
return;
}
timeNow->loop();
#ifdef OTA_UPDATES_ENABLED
ArduinoOTA.handle();
#endif
#ifdef WS_enable
ws.cleanupClients();
#endif
not_async_actions();
MqttClient::loop();
loopCmd();
mySwitch->loop();
loopScenario();
#ifdef UDP_ENABLED
loopUdp();
#endif
timeNow->loop();
async->loop();
not_async_actions();
MqttClient::loop();
loopCmd();
mySwitch->loop();
loopScenario();
loopSerial();
ts.update();
}
void not_async_actions() {
#ifdef UDP_ENABLED
do_udp_data_parse();
do_mqtt_send_settings_to_udp();
#endif
if (mqttParamsChanged) {
MqttClient::reconnect();
mqttParamsChanged = false;
@@ -118,15 +124,9 @@ void not_async_actions() {
getLastVersion();
do_update();
#ifdef UDP_ENABLED
do_udp_data_parse();
do_mqtt_send_settings_to_udp();
#endif
do_scan_bus();
do_delElement();
do_getJsonListFromCsv();
}
String getURL(const String& urls) {