2020-09-02 22:34:49 +03:00
|
|
|
#include "ItemsList.h"
|
|
|
|
|
|
2020-10-18 09:52:17 +03:00
|
|
|
#include "Class/NotAsync.h"
|
2020-10-10 01:44:11 +03:00
|
|
|
#include "Init.h"
|
2020-10-18 09:52:17 +03:00
|
|
|
#include "Utils/StringUtils.h"
|
2020-09-02 22:34:49 +03:00
|
|
|
|
2020-10-10 01:44:11 +03:00
|
|
|
static const char* firstLine PROGMEM = "Удалить;Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета";
|
|
|
|
|
|
|
|
|
|
void itemsListInit() {
|
2020-10-18 09:52:17 +03:00
|
|
|
myNotAsyncActions->add(
|
2020-10-10 01:44:11 +03:00
|
|
|
do_deviceInit, [&](void*) {
|
2020-12-10 19:12:15 +03:00
|
|
|
deviceInit();
|
2020-10-10 01:44:11 +03:00
|
|
|
},
|
|
|
|
|
nullptr);
|
|
|
|
|
|
2020-10-18 09:52:17 +03:00
|
|
|
myNotAsyncActions->add(
|
2020-10-10 01:44:11 +03:00
|
|
|
do_delChoosingItems, [&](void*) {
|
|
|
|
|
delChoosingItems();
|
|
|
|
|
},
|
|
|
|
|
nullptr);
|
2020-12-17 01:29:30 +01:00
|
|
|
|
2020-12-09 04:08:36 +03:00
|
|
|
|
2020-12-10 19:12:15 +03:00
|
|
|
SerialPrint("I", F("Items"), F("Items Init"));
|
2020-10-10 01:44:11 +03:00
|
|
|
}
|
2020-09-02 22:34:49 +03:00
|
|
|
|
2020-12-17 01:29:30 +01:00
|
|
|
void addItem2(String param) {
|
|
|
|
|
int num = selectToMarker(param, "-").toInt();
|
|
|
|
|
File configFile = LittleFS.open("/items/items.txt", "r");
|
|
|
|
|
if (!configFile) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
configFile.seek(0, SeekSet);
|
|
|
|
|
String seachingLine;
|
|
|
|
|
|
|
|
|
|
while (configFile.position() != configFile.size()) {
|
|
|
|
|
String item = configFile.readStringUntil('\n');
|
|
|
|
|
int tmpNum = selectToMarker(item, ";").toInt();
|
|
|
|
|
if (tmpNum == num) {
|
|
|
|
|
seachingLine = item;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
configFile.close();
|
2020-12-16 13:59:01 +01:00
|
|
|
|
2020-12-17 01:29:30 +01:00
|
|
|
String name = deleteBeforeDelimiter(param, "-");
|
|
|
|
|
randomSeed(micros());
|
|
|
|
|
unsigned int rnd = random(0, 1000);
|
|
|
|
|
seachingLine.replace("id", name + String(rnd));
|
|
|
|
|
seachingLine.replace("order", String(getNewElementNumber("order.txt")));
|
2020-10-10 01:44:11 +03:00
|
|
|
|
2020-12-18 21:48:06 +01:00
|
|
|
if (seachingLine.indexOf("gpio") != -1) {
|
|
|
|
|
seachingLine.replace("gpio", "pin[" + String(getFreePinAll()) + "]");
|
2020-12-17 01:29:30 +01:00
|
|
|
}
|
2020-10-10 01:44:11 +03:00
|
|
|
|
2020-12-17 01:29:30 +01:00
|
|
|
seachingLine = deleteBeforeDelimiter(seachingLine, ";");
|
|
|
|
|
seachingLine.replace("\r\n", "");
|
|
|
|
|
seachingLine.replace("\r", "");
|
|
|
|
|
seachingLine.replace("\n", "");
|
|
|
|
|
addFile(DEVICE_CONFIG_FILE, "\n" + seachingLine);
|
|
|
|
|
Serial.println(seachingLine);
|
|
|
|
|
}
|
2020-12-02 05:05:16 +03:00
|
|
|
|
2020-10-10 01:44:11 +03:00
|
|
|
|
2020-12-17 01:29:30 +01:00
|
|
|
void addPreset2(int num) {
|
|
|
|
|
File configFile = LittleFS.open("/presets/presets.c.txt", "r");
|
|
|
|
|
if (!configFile) {
|
|
|
|
|
return;
|
2020-12-09 04:08:36 +03:00
|
|
|
}
|
2020-12-17 01:29:30 +01:00
|
|
|
configFile.seek(0, SeekSet);
|
|
|
|
|
String config;
|
|
|
|
|
int i1 = 0;
|
|
|
|
|
while (configFile.position() != configFile.size()) {
|
|
|
|
|
i1++;
|
|
|
|
|
String item = configFile.readStringUntil('*');
|
|
|
|
|
if (i1 == num) {
|
|
|
|
|
if (i1 == 1) {
|
|
|
|
|
config = "\n" + item;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
config = item;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-12-09 04:08:36 +03:00
|
|
|
}
|
2020-12-17 01:29:30 +01:00
|
|
|
configFile.close();
|
|
|
|
|
addFile(DEVICE_CONFIG_FILE, config);
|
|
|
|
|
|
|
|
|
|
File scenFile = LittleFS.open("/presets/presets.s.txt", "r");
|
|
|
|
|
if (!scenFile) {
|
|
|
|
|
return;
|
2020-12-09 04:08:36 +03:00
|
|
|
}
|
2020-12-17 01:29:30 +01:00
|
|
|
scenFile.seek(0, SeekSet);
|
|
|
|
|
String scen;
|
|
|
|
|
int i2 = 0;
|
|
|
|
|
while (scenFile.position() != scenFile.size()) {
|
|
|
|
|
i2++;
|
|
|
|
|
String item = scenFile.readStringUntil('*');
|
|
|
|
|
if (i2 == num) {
|
|
|
|
|
scen = item;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-12-09 04:08:36 +03:00
|
|
|
}
|
2020-12-17 01:29:30 +01:00
|
|
|
scenFile.close();
|
|
|
|
|
if (readFile(String(DEVICE_SCENARIO_FILE), 2048) == "//") {
|
|
|
|
|
removeFile(DEVICE_SCENARIO_FILE);
|
2020-09-02 22:34:49 +03:00
|
|
|
}
|
2020-12-17 01:29:30 +01:00
|
|
|
addFile(DEVICE_SCENARIO_FILE, scen);
|
2020-09-02 22:34:49 +03:00
|
|
|
}
|
|
|
|
|
|
2020-11-03 00:04:07 +03:00
|
|
|
|
2020-09-02 22:34:49 +03:00
|
|
|
void delAllItems() {
|
|
|
|
|
removeFile(DEVICE_CONFIG_FILE);
|
|
|
|
|
addFile(DEVICE_CONFIG_FILE, String(firstLine));
|
2020-11-15 02:46:27 +03:00
|
|
|
removeFile(DEVICE_SCENARIO_FILE);
|
|
|
|
|
addFile(DEVICE_SCENARIO_FILE, "//");
|
2020-09-02 22:34:49 +03:00
|
|
|
removeFile("id.txt");
|
|
|
|
|
removeFile("order.txt");
|
|
|
|
|
removeFile("pins.txt");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t getNewElementNumber(String file) {
|
|
|
|
|
uint8_t number = readFile(file, 100).toInt();
|
|
|
|
|
number++;
|
|
|
|
|
removeFile(file);
|
|
|
|
|
addFile(file, String(number));
|
|
|
|
|
return number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t getFreePinAll() {
|
|
|
|
|
#ifdef ESP8266
|
2020-12-09 04:08:36 +03:00
|
|
|
uint8_t pins[] = { 0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5 };
|
2020-09-02 22:34:49 +03:00
|
|
|
#endif
|
|
|
|
|
#ifdef ESP32
|
2020-12-09 04:08:36 +03:00
|
|
|
uint8_t pins[] = { 0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5 };
|
2020-09-02 22:34:49 +03:00
|
|
|
#endif
|
|
|
|
|
uint8_t array_sz = sizeof(pins) / sizeof(pins[0]);
|
|
|
|
|
uint8_t i = getNewElementNumber("pins.txt");
|
|
|
|
|
if (i < array_sz) {
|
|
|
|
|
return pins[i];
|
2020-12-09 04:08:36 +03:00
|
|
|
}
|
|
|
|
|
else {
|
2020-09-02 22:34:49 +03:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-18 23:20:42 +01:00
|
|
|
bool isPinExist(unsigned int num) {
|
|
|
|
|
bool ret = false;
|
|
|
|
|
unsigned int pins[] = { 0, 1, 2, 3, 4, 5, 9, 10, 12, 13, 14, 15, 16 };
|
|
|
|
|
uint8_t array_sz = sizeof(pins) / sizeof(pins[0]);
|
|
|
|
|
for (uint8_t i = 0; i < array_sz; i++) {
|
|
|
|
|
if (pins[i] == num) ret = true;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 22:34:49 +03:00
|
|
|
uint8_t getFreePinAnalog() {
|
|
|
|
|
#ifdef ESP8266
|
|
|
|
|
return 0;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 01:44:11 +03:00
|
|
|
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;
|
2020-12-09 04:08:36 +03:00
|
|
|
}
|
|
|
|
|
else {
|
2020-10-10 01:44:11 +03:00
|
|
|
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();
|
|
|
|
|
}
|