mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
252 added delete function in items list
This commit is contained in:
@@ -18,6 +18,7 @@ void fileCmdExecute(const String &filename) {
|
||||
}
|
||||
|
||||
void csvCmdExecute(String &cmdStr) {
|
||||
|
||||
cmdStr.replace(";", " ");
|
||||
cmdStr += "\r\n";
|
||||
cmdStr.replace("\r\n", "\n");
|
||||
@@ -25,6 +26,7 @@ void csvCmdExecute(String &cmdStr) {
|
||||
int count = 0;
|
||||
while (cmdStr.length()) {
|
||||
String buf = selectToMarker(cmdStr, "\n");
|
||||
buf = deleteBeforeDelimiter(buf, " "); //отсечка чекбокса
|
||||
count++;
|
||||
if (count > 1) sCmd.readStr(buf);
|
||||
cmdStr = deleteBeforeDelimiter(cmdStr, "\n");
|
||||
|
||||
@@ -1,23 +1,51 @@
|
||||
#include "ItemsList.h"
|
||||
|
||||
#include "Class\NotAsinc.h"
|
||||
#include "Init.h"
|
||||
#include "Utils\StringUtils.h"
|
||||
|
||||
static const char* firstLine PROGMEM = "Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета";
|
||||
static const char* firstLine PROGMEM = "Удалить;Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета";
|
||||
|
||||
void itemsListInit() {
|
||||
myNotAsincActions->add(
|
||||
do_deviceInit, [&](void*) {
|
||||
Device_init();
|
||||
},
|
||||
nullptr);
|
||||
|
||||
myNotAsincActions->add(
|
||||
do_delChoosingItems, [&](void*) {
|
||||
delChoosingItems();
|
||||
Device_init();
|
||||
},
|
||||
nullptr);
|
||||
}
|
||||
|
||||
void addItem(String name) {
|
||||
String item = readFile("items/" + name + ".txt", 1024);
|
||||
name = deleteToMarkerLast(name, "-");
|
||||
|
||||
name = deleteToMarkerLast(name, ".");
|
||||
|
||||
item.replace("id", name + "-" + String(getNewElementNumber("id.txt")));
|
||||
item.replace("order", String(getNewElementNumber("order.txt")));
|
||||
|
||||
if (item.indexOf("pin") != -1) { //all cases (random pins from available)
|
||||
item.replace("pin", "pin[" + String(getFreePinAll()) + "]");
|
||||
} else if (item.indexOf("gol") != -1) { //analog
|
||||
} else
|
||||
|
||||
if (item.indexOf("gol") != -1) { //analog
|
||||
item.replace("gol", "pin[" + String(getFreePinAnalog()) + "]");
|
||||
} else if (item.indexOf("cin") != -1) { //ultrasonic
|
||||
} else
|
||||
|
||||
if (item.indexOf("cin") != -1) { //ultrasonic
|
||||
item.replace("cin", "pin[" + String(getFreePinAll()) + "," + String(getFreePinAll()) + "]");
|
||||
} else if (item.indexOf("sal") != -1) { //dallas
|
||||
} else
|
||||
|
||||
if (item.indexOf("sal") != -1) { //dallas
|
||||
item.replace("sal", "pin[2]");
|
||||
} else if (item.indexOf("thd") != -1) { //dht11/22
|
||||
} else
|
||||
|
||||
if (item.indexOf("thd") != -1) { //dht11/22
|
||||
item.replace("thd", "pin[2]");
|
||||
}
|
||||
|
||||
@@ -65,71 +93,28 @@ uint8_t getFreePinAnalog() {
|
||||
#endif
|
||||
}
|
||||
|
||||
//void do_getJsonListFromCsv() {
|
||||
// if (getJsonListFromCsvFlag) {
|
||||
// getJsonListFromCsvFlag = false;
|
||||
// removeFile("items/items.json");
|
||||
// addFile("items/items.json", getJsonListFromCsv(DEVICE_CONFIG_FILE, 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 delChoosingItems() {
|
||||
File configFile = LittleFS.open("/" + String(DEVICE_CONFIG_FILE), "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
configFile.seek(0, SeekSet);
|
||||
String finalConf;
|
||||
bool firstLine = true;
|
||||
while (configFile.position() != configFile.size()) {
|
||||
String item = configFile.readStringUntil('\n');
|
||||
if (firstLine) {
|
||||
finalConf += item;
|
||||
} else {
|
||||
int checkbox = selectToMarker(item, ";").toInt();
|
||||
if (checkbox == 0) {
|
||||
finalConf += "\n" + item;
|
||||
}
|
||||
}
|
||||
firstLine = false;
|
||||
}
|
||||
removeFile(String(DEVICE_CONFIG_FILE));
|
||||
addFile(String(DEVICE_CONFIG_FILE), finalConf);
|
||||
Serial.println(finalConf);
|
||||
configFile.close();
|
||||
}
|
||||
21
src/Web.cpp
21
src/Web.cpp
@@ -14,30 +14,34 @@ bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) {
|
||||
}
|
||||
|
||||
void web_init() {
|
||||
|
||||
server.on("/set", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
//==============================set.device.json====================================================================================================
|
||||
if (request->hasArg("addItem")) {
|
||||
String name = request->getParam("addItem")->value();
|
||||
addItem(name);
|
||||
//Device_init();
|
||||
myNotAsincActions->make(do_deviceInit);
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
if (request->hasArg("delChoosingItems")) {
|
||||
myNotAsincActions->make(do_delChoosingItems);
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("delAllItems")) {
|
||||
delAllItems();
|
||||
Device_init();
|
||||
myNotAsincActions->make(do_deviceInit);
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
if (request->hasArg("saveItems")) {
|
||||
Device_init();
|
||||
myNotAsincActions->make(do_deviceInit);
|
||||
request->redirect("/?set.device");
|
||||
}
|
||||
|
||||
//==============================init====================================================================================================
|
||||
if (request->hasArg("devinit")) {
|
||||
Device_init();
|
||||
myNotAsincActions->make(do_deviceInit);
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
@@ -134,6 +138,13 @@ void web_init() {
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
if (request->hasArg("test")) {
|
||||
if (request->getParam("test")->value() == "ok") {
|
||||
Serial.println("test pass");
|
||||
}
|
||||
request->send(200);
|
||||
}
|
||||
|
||||
//==============================mqtt settings=============================================
|
||||
|
||||
if (request->hasArg("mqttServer")) {
|
||||
|
||||
41
src/main.cpp
41
src/main.cpp
@@ -5,11 +5,11 @@
|
||||
#include "Class/CallBackTest.h"
|
||||
#include "Class/NotAsinc.h"
|
||||
#include "Class/ScenarioClass.h"
|
||||
#include "Utils/StatUtils.h"
|
||||
#include "Cmd.h"
|
||||
#include "Global.h"
|
||||
#include "Init.h"
|
||||
#include "ItemsList.h"
|
||||
#include "Utils/StatUtils.h"
|
||||
#include "Utils/Timings.h"
|
||||
#include "Utils\WebUtils.h"
|
||||
#include "items/ButtonInClass.h"
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
void not_async_actions();
|
||||
|
||||
|
||||
Timings metric;
|
||||
boolean initialized = false;
|
||||
|
||||
@@ -36,62 +35,64 @@ void setup() {
|
||||
myNotAsincActions = new NotAsinc(do_LAST);
|
||||
myScenario = new Scenario();
|
||||
|
||||
SerialPrint("I","FS","FS Init");
|
||||
SerialPrint("I", "FS", "FS Init");
|
||||
fileSystemInit();
|
||||
|
||||
SerialPrint("I","Conf","Config Init");
|
||||
SerialPrint("I", "Conf", "Config Init");
|
||||
loadConfig();
|
||||
|
||||
SerialPrint("I","Time","Clock Init");
|
||||
SerialPrint("I", "Time", "Clock Init");
|
||||
clock_init();
|
||||
|
||||
SerialPrint("I","CMD","Commands Init");
|
||||
SerialPrint("I", "CMD", "Commands Init");
|
||||
cmd_init();
|
||||
|
||||
SerialPrint("I","Sensors","Sensors Init");
|
||||
SerialPrint("I", "Sensors", "Sensors Init");
|
||||
sensorsInit();
|
||||
|
||||
SerialPrint("I","Init","Init Init");
|
||||
SerialPrint("I", "Items", "Items Init");
|
||||
itemsListInit();
|
||||
|
||||
SerialPrint("I", "Init", "Init Init");
|
||||
all_init();
|
||||
|
||||
SerialPrint("I","WIFI","Network Init");
|
||||
SerialPrint("I", "WIFI", "Network Init");
|
||||
routerConnect();
|
||||
|
||||
SerialPrint("I","Uptime","Uptime Init");
|
||||
SerialPrint("I", "Uptime", "Uptime Init");
|
||||
uptime_init();
|
||||
|
||||
SerialPrint("I","Update","Updater Init");
|
||||
SerialPrint("I", "Update", "Updater Init");
|
||||
upgradeInit();
|
||||
|
||||
SerialPrint("I","HTTP","HttpServer Init");
|
||||
SerialPrint("I", "HTTP", "HttpServer Init");
|
||||
HttpServer::init();
|
||||
|
||||
SerialPrint("I","Web","WebAdmin Init");
|
||||
SerialPrint("I", "Web", "WebAdmin Init");
|
||||
web_init();
|
||||
|
||||
SerialPrint("I","Stat","Stat Init");
|
||||
SerialPrint("I", "Stat", "Stat Init");
|
||||
initSt();
|
||||
|
||||
//SerialPrint("I","UDP","Udp Init");
|
||||
//asyncUdpInit();
|
||||
|
||||
SerialPrint("I","Bus","Bus Init");
|
||||
SerialPrint("I", "Bus", "Bus Init");
|
||||
busInit();
|
||||
|
||||
|
||||
#ifdef SSDP_EN
|
||||
SerialPrint("I","SSDP","Ssdp Init");
|
||||
SerialPrint("I", "SSDP", "Ssdp Init");
|
||||
SsdpInit();
|
||||
#endif
|
||||
|
||||
ts.add(
|
||||
TEST, 1000 * 60, [&](void*) {
|
||||
SerialPrint("I","System",printMemoryStatus());
|
||||
|
||||
SerialPrint("I", "System", printMemoryStatus());
|
||||
},
|
||||
nullptr, true);
|
||||
|
||||
just_load = false;
|
||||
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
|
||||
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Reference in New Issue
Block a user