mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 14:42:18 +03:00
process to asinc
This commit is contained in:
30
src/Class/NotAsinc.cpp
Normal file
30
src/Class/NotAsinc.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "Class/NotAsinc.h"
|
||||
|
||||
NotAsinc::NotAsinc(uint8_t size) {
|
||||
this->items = new NotAsincItem[size];
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
NotAsinc::~NotAsinc() {}
|
||||
|
||||
void NotAsinc::add(uint8_t i, NotAsincCb f, void* arg) {
|
||||
this->items[i].cb = f;
|
||||
this->items[i].cb_arg = arg;
|
||||
this->items[i].is_used = true;
|
||||
}
|
||||
|
||||
void NotAsinc::loop() {
|
||||
if (this->items[task].is_used) {
|
||||
handle(this->items[task].cb, this->items[task].cb_arg);
|
||||
task = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void NotAsinc::make(uint8_t task) {
|
||||
this->task = task;
|
||||
}
|
||||
|
||||
void NotAsinc::handle(NotAsincCb f, void* arg) {
|
||||
f(arg);
|
||||
}
|
||||
NotAsinc* myNotAsincActions;
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "Class/Pwm.h"
|
||||
#include "Class/Switch.h"
|
||||
//-----------------------------
|
||||
#include "Class/NotAsinc.h"
|
||||
#include "Global.h"
|
||||
#include "Module/Terminal.h"
|
||||
#include "Servo/Servos.h"
|
||||
@@ -439,7 +440,7 @@ void httpOrderSend() {
|
||||
}
|
||||
|
||||
void firmwareUpdate() {
|
||||
updateFlag = true;
|
||||
myNotAsincActions->make(do_UPGRADE);
|
||||
}
|
||||
|
||||
void firmwareVersion() {
|
||||
|
||||
@@ -2,19 +2,17 @@
|
||||
|
||||
static const char* firstLine PROGMEM = "Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета";
|
||||
|
||||
void addElement(String name) {
|
||||
void addItem(String name) {
|
||||
String item = readFile("items/" + name + ".txt", 1024);
|
||||
|
||||
item.replace("id", "id" + String(getNewElementNumber("id.txt")));
|
||||
item.replace("order", String(getNewElementNumber("order.txt")));
|
||||
|
||||
item.replace("\r\n", "");
|
||||
item.replace("\r", "");
|
||||
item.replace("\n", "");
|
||||
addFile("conf.csv", "\n" + item);
|
||||
}
|
||||
|
||||
void delAllElement() {
|
||||
void delAllItems() {
|
||||
removeFile("conf.csv");
|
||||
addFile("conf.csv", String(firstLine));
|
||||
removeFile("id.txt");
|
||||
@@ -29,71 +27,73 @@ 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) {
|
||||
delElementFlag = false;
|
||||
delElement(itemsFile, itemsLine);
|
||||
}
|
||||
}
|
||||
|
||||
void delElement(String _itemsFile, String _itemsLine) {
|
||||
File configFile = LittleFS.open("/" + _itemsFile, "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
configFile.seek(0, SeekSet);
|
||||
String finalConf;
|
||||
int count = -1;
|
||||
while (configFile.position() != configFile.size()) {
|
||||
count++;
|
||||
String item = configFile.readStringUntil('\n');
|
||||
Serial.print(_itemsLine);
|
||||
Serial.print(" ");
|
||||
Serial.println(count);
|
||||
if (count != _itemsLine.toInt()) {
|
||||
if (count == 0) {
|
||||
finalConf += item;
|
||||
} else {
|
||||
finalConf += "\n" + item;
|
||||
}
|
||||
}
|
||||
}
|
||||
removeFile(_itemsFile);
|
||||
addFile(_itemsFile, finalConf);
|
||||
Serial.println(finalConf);
|
||||
itemsFile = "";
|
||||
itemsLine = "";
|
||||
configFile.close();
|
||||
}
|
||||
//void do_getJsonListFromCsv() {
|
||||
// if (getJsonListFromCsvFlag) {
|
||||
// getJsonListFromCsvFlag = false;
|
||||
// removeFile("items/items.json");
|
||||
// addFile("items/items.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) {
|
||||
// delElementFlag = false;
|
||||
// delElement(itemsFile, itemsLine);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void delElement(String _itemsFile, String _itemsLine) {
|
||||
// File configFile = LittleFS.open("/" + _itemsFile, "r");
|
||||
// if (!configFile) {
|
||||
// return;
|
||||
// }
|
||||
// configFile.seek(0, SeekSet);
|
||||
// String finalConf;
|
||||
// int count = -1;
|
||||
// while (configFile.position() != configFile.size()) {
|
||||
// count++;
|
||||
// String item = configFile.readStringUntil('\n');
|
||||
// Serial.print(_itemsLine);
|
||||
// Serial.print(" ");
|
||||
// Serial.println(count);
|
||||
// if (count != _itemsLine.toInt()) {
|
||||
// if (count == 0) {
|
||||
// finalConf += item;
|
||||
// } else {
|
||||
// finalConf += "\n" + item;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// removeFile(_itemsFile);
|
||||
// addFile(_itemsFile, finalConf);
|
||||
// Serial.println(finalConf);
|
||||
// itemsFile = "";
|
||||
// itemsLine = "";
|
||||
// configFile.close();
|
||||
//}
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Global.h"
|
||||
#include "Init.h"
|
||||
#include <LittleFS.h>
|
||||
#include "Class/NotAsinc.h"
|
||||
|
||||
static const char* MODULE = "Mqtt";
|
||||
|
||||
@@ -151,7 +152,7 @@ void handleSubscribedUpdates(char* topic, uint8_t* payload, size_t length) {
|
||||
} else if (topicStr.indexOf("update")) {
|
||||
|
||||
if (payloadStr == "1") {
|
||||
updateFlag = true;
|
||||
myNotAsincActions->make(do_UPGRADE);
|
||||
}
|
||||
|
||||
} else if (topicStr.indexOf("devc")) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "Upgrade.h"
|
||||
|
||||
#include "Class/NotAsinc.h"
|
||||
#include "Global.h"
|
||||
#include "ESP8266.h"
|
||||
|
||||
@@ -27,7 +27,14 @@ void getLastVersion() {
|
||||
}
|
||||
}
|
||||
|
||||
void initUpdater() {
|
||||
void upgradeInit() {
|
||||
|
||||
myNotAsincActions->add(
|
||||
do_UPGRADE, [&](void*) {
|
||||
upgrade_firmware();
|
||||
},
|
||||
nullptr);
|
||||
|
||||
if (isNetworkActive()) {
|
||||
getLastVersion();
|
||||
if (lastVersion.length()) {
|
||||
@@ -78,10 +85,3 @@ void upgrade_firmware() {
|
||||
pm.error("on firmware");
|
||||
}
|
||||
}
|
||||
|
||||
void do_update() {
|
||||
if (updateFlag) {
|
||||
updateFlag = false;
|
||||
upgrade_firmware();
|
||||
}
|
||||
}
|
||||
32
src/Web.cpp
32
src/Web.cpp
@@ -1,6 +1,7 @@
|
||||
#include "DeviceList.h"
|
||||
#include "Global.h"
|
||||
#include "Init.h"
|
||||
#include "Class/NotAsinc.h"
|
||||
|
||||
static const char* MODULE = "Web";
|
||||
|
||||
@@ -26,6 +27,8 @@ void web_init() {
|
||||
});
|
||||
|
||||
server.on("/set", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
|
||||
//==============================presets===========================================================================================================
|
||||
uint8_t preset;
|
||||
if (parseRequestForPreset(request, preset)) {
|
||||
pm.info("activate #" + String(preset, DEC));
|
||||
@@ -38,37 +41,30 @@ void web_init() {
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
//==============================list of items=====================================================
|
||||
if (request->hasArg("element")) {
|
||||
String name = request->getParam("element")->value();
|
||||
addElement(name);
|
||||
getJsonListFromCsvFlag = true;
|
||||
//==============================list of items====================================================================================================
|
||||
if (request->hasArg("addItem")) {
|
||||
String name = request->getParam("addItem")->value();
|
||||
addItem(name);
|
||||
Device_init();
|
||||
request->redirect("/?setn.device");
|
||||
}
|
||||
|
||||
if (request->hasArg("cleanconf")) {
|
||||
delAllElement();
|
||||
removeFile("items/elements.json");
|
||||
if (request->hasArg("delAllItems")) {
|
||||
delAllItems();
|
||||
Device_init();
|
||||
request->redirect("/?setn.device");
|
||||
}
|
||||
|
||||
if (request->hasArg("save")) {
|
||||
if (request->hasArg("saveItems")) {
|
||||
Device_init();
|
||||
getJsonListFromCsvFlag = true;
|
||||
request->redirect("/?setn.device");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
if (request->hasArg("devinit")) {
|
||||
Device_init();
|
||||
request->send(200);
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
if (request->hasArg("scen")) {
|
||||
bool value = request->getParam("scen")->value().toInt();
|
||||
jsonWriteBool(configSetupJson, "scen", value);
|
||||
@@ -76,12 +72,12 @@ void web_init() {
|
||||
loadScenario();
|
||||
request->send(200);
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
if (request->hasArg("sceninit")) {
|
||||
loadScenario();
|
||||
request->send(200);
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
#ifdef LOGGING_ENABLED
|
||||
if (request->hasArg("cleanlog")) {
|
||||
clean_log_date();
|
||||
@@ -295,7 +291,7 @@ void web_init() {
|
||||
* Upgrade
|
||||
*/
|
||||
server.on("/upgrade", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
updateFlag = true;
|
||||
myNotAsincActions->make(do_UPGRADE);;
|
||||
request->send(200, "text/html");
|
||||
});
|
||||
}
|
||||
28
src/main.cpp
28
src/main.cpp
@@ -1,5 +1,6 @@
|
||||
#include "Bus/BusScannerFactory.h"
|
||||
#include "Class/AsyncActions.h"
|
||||
#include "Class/CallBackTest.h"
|
||||
#include "Class/NotAsinc.h"
|
||||
#include "Class/Switch.h"
|
||||
#include "Cmd.h"
|
||||
#include "DeviceList.h"
|
||||
@@ -56,7 +57,7 @@ void setup() {
|
||||
telemetry_init();
|
||||
|
||||
pm.info("Updater");
|
||||
initUpdater();
|
||||
upgradeInit();
|
||||
|
||||
pm.info("HttpServer");
|
||||
HttpServer::init();
|
||||
@@ -70,22 +71,15 @@ void setup() {
|
||||
#endif
|
||||
|
||||
ts.add(
|
||||
TEST, 1000 * 60, [&](void*) { pm.info(printMemoryStatus()); }, nullptr, true);
|
||||
TEST, 1000 * 60, [&](void*) {
|
||||
pm.info(printMemoryStatus());
|
||||
},
|
||||
nullptr, true);
|
||||
|
||||
just_load = false;
|
||||
initialized = true;
|
||||
|
||||
CB = new CallBackTest();
|
||||
|
||||
CB->setCallback([]() {
|
||||
Serial.println("123");
|
||||
});
|
||||
|
||||
CB->setCallback([](const String str) {
|
||||
Serial.println(str);
|
||||
return true;
|
||||
});
|
||||
|
||||
myNotAsincActions = new NotAsinc(5);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -102,7 +96,7 @@ void loop() {
|
||||
loopUdp();
|
||||
#endif
|
||||
timeNow->loop();
|
||||
async->loop();
|
||||
myNotAsincActions->loop();
|
||||
not_async_actions();
|
||||
MqttClient::loop();
|
||||
loopCmd();
|
||||
@@ -124,10 +118,8 @@ void not_async_actions() {
|
||||
|
||||
getLastVersion();
|
||||
|
||||
do_update();
|
||||
|
||||
do_scan_bus();
|
||||
do_delElement();
|
||||
do_getJsonListFromCsv();
|
||||
}
|
||||
|
||||
String getURL(const String& urls) {
|
||||
|
||||
Reference in New Issue
Block a user