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

@@ -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) {