mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
web interface constructor
This commit is contained in:
@@ -463,14 +463,17 @@ void fileExecute(const String &filename) {
|
||||
stringExecute(cmdStr);
|
||||
}
|
||||
|
||||
void stringExecute(String &cmdStr) {
|
||||
void stringExecute(String &cmdStr) {
|
||||
cmdStr.replace("x;","");
|
||||
cmdStr.replace(";"," ");
|
||||
cmdStr += "\r\n";
|
||||
cmdStr.replace("\r\n", "\n");
|
||||
cmdStr.replace("\r", "\n");
|
||||
|
||||
int count = 0;
|
||||
while (cmdStr.length()) {
|
||||
String buf = selectToMarker(cmdStr, "\n");
|
||||
sCmd.readStr(buf);
|
||||
count++;
|
||||
if (count > 1)sCmd.readStr(buf);
|
||||
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
#include "DeviceList.h"
|
||||
|
||||
static const char* firstLine PROGMEM = "Удалить;Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета";
|
||||
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")));
|
||||
|
||||
item.replace("\r\n", "");
|
||||
item.replace("\r", "");
|
||||
item.replace("\n", "");
|
||||
@@ -13,29 +17,52 @@ void addElement(String name) {
|
||||
void delAllElement() {
|
||||
removeFile("conf.csv");
|
||||
addFile("conf.csv", String(firstLine));
|
||||
removeFile("id.txt");
|
||||
removeFile("order.txt");
|
||||
}
|
||||
|
||||
|
||||
int getNewElementNumber(String file) {
|
||||
int number = readFile(file, 100).toInt();
|
||||
number++;
|
||||
removeFile(file);
|
||||
addFile(file, String(number));
|
||||
return number;
|
||||
}
|
||||
|
||||
void do_delElement() {
|
||||
if (delElementFlag) {
|
||||
delElementFlag = false;
|
||||
delElement();
|
||||
delElement(itemsFile, itemsLine);
|
||||
}
|
||||
}
|
||||
|
||||
void delElement() {
|
||||
File configFile = LittleFS.open("/conf.csv", "r");
|
||||
void delElement(String _itemsFile, String _itemsLine) {
|
||||
File configFile = LittleFS.open("/" + _itemsFile, "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
configFile.seek(0, SeekSet); //поставим курсор в начало файла
|
||||
configFile.seek(0, SeekSet);
|
||||
String finalConf;
|
||||
int count = -1;
|
||||
while (configFile.position() != configFile.size()) {
|
||||
count++;
|
||||
String item = configFile.readStringUntil('\n');
|
||||
if (selectToMarker(item, ";") == "0") {
|
||||
finalConf += "\n" + item;
|
||||
Serial.print(_itemsLine);
|
||||
Serial.print(" ");
|
||||
Serial.println(count);
|
||||
if (count != _itemsLine.toInt()) {
|
||||
if (count == 0) {
|
||||
finalConf += item;
|
||||
} else {
|
||||
finalConf += "\n" + item;
|
||||
}
|
||||
}
|
||||
}
|
||||
removeFile("conf.csv");
|
||||
addFile("conf.csv", String(firstLine) + "\n" + finalConf);
|
||||
removeFile(_itemsFile);
|
||||
addFile(_itemsFile, finalConf);
|
||||
Serial.println(finalConf);
|
||||
itemsFile = "";
|
||||
itemsLine = "";
|
||||
configFile.close();
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,9 @@ String all_widgets = "";
|
||||
String scenario = "";
|
||||
String order_loop = "";
|
||||
|
||||
String itemsFile = "";
|
||||
String itemsLine = "";
|
||||
|
||||
// Sensors
|
||||
String analog_value_names_list;
|
||||
int enter_to_analog_counter;
|
||||
|
||||
@@ -62,6 +62,7 @@ void Device_init() {
|
||||
removeFile(String("layout.txt"));
|
||||
#endif
|
||||
|
||||
|
||||
fileExecute(String(DEVICE_CONFIG_FILE));
|
||||
//outcoming_date();
|
||||
}
|
||||
|
||||
21
src/Web.cpp
21
src/Web.cpp
@@ -38,20 +38,22 @@ void web_init() {
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
//==============================list of items=====================================================
|
||||
if (request->hasArg("element")) {
|
||||
String name = request->getParam("element")->value();
|
||||
addElement(name);
|
||||
Device_init();
|
||||
request->redirect("/?setn.device");
|
||||
}
|
||||
|
||||
if (request->hasArg("cleanconf")) {
|
||||
delAllElement();
|
||||
Device_init();
|
||||
request->redirect("/?setn.device");
|
||||
}
|
||||
|
||||
if (request->hasArg("delete")) {
|
||||
delElementFlag = true;
|
||||
if (request->hasArg("save")) {
|
||||
Device_init();
|
||||
request->redirect("/?setn.device");
|
||||
}
|
||||
|
||||
@@ -235,6 +237,19 @@ void web_init() {
|
||||
}
|
||||
});
|
||||
|
||||
//==============================list of items=====================================================
|
||||
//server.on("/del", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
// if (request->hasArg("file")) {
|
||||
// itemsFile = request->getParam("file")->value();
|
||||
// }
|
||||
// if (request->hasArg("line")) {
|
||||
// itemsLine = request->getParam("line")->value();
|
||||
// }
|
||||
// delElementFlag = true;
|
||||
// Device_init();
|
||||
// request->redirect("/?setn.device");
|
||||
//});
|
||||
|
||||
/*
|
||||
* Check
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user