diff --git a/data/conf.csv b/data/conf.csv
new file mode 100644
index 00000000..40b35ae1
--- /dev/null
+++ b/data/conf.csv
@@ -0,0 +1 @@
+Удалить;Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета
\ No newline at end of file
diff --git a/data/items/button-in.txt b/data/items/button-in.txt
new file mode 100644
index 00000000..d01c6f0b
--- /dev/null
+++ b/data/items/button-in.txt
@@ -0,0 +1 @@
+0;button-in;switch1;toggle;Кнопки;Свет;1;pin[2];db[20]
\ No newline at end of file
diff --git a/data/items/button-out-i.txt b/data/items/button-out-i.txt
new file mode 100644
index 00000000..3db63e7f
--- /dev/null
+++ b/data/items/button-out-i.txt
@@ -0,0 +1 @@
+0;button-out;light1;toggle;Кнопки;Свет;1;pin[12];inv[1];st[1]
\ No newline at end of file
diff --git a/data/items/button-out.txt b/data/items/button-out.txt
new file mode 100644
index 00000000..3c6ba8c0
--- /dev/null
+++ b/data/items/button-out.txt
@@ -0,0 +1 @@
+0;button-out;light1;toggle;Кнопки;Свет;1;pin[12];st[0]
\ No newline at end of file
diff --git a/data/items/pwm-out.txt b/data/items/pwm-out.txt
new file mode 100644
index 00000000..41eec52d
--- /dev/null
+++ b/data/items/pwm-out.txt
@@ -0,0 +1 @@
+0;pwm-out;volume;range;Кнопки;Свет;1;pin[12];st[500]
\ No newline at end of file
diff --git a/data/set.device.json b/data/set.device.json
index f890fa5e..340d21b7 100644
--- a/data/set.device.json
+++ b/data/set.device.json
@@ -91,6 +91,7 @@
"action": "/set?devinit",
"class": "btn btn-block btn-default"
},
+
{
"type": "h2",
"title": "Сценарии"
diff --git a/data/setn.device.json b/data/setn.device.json
new file mode 100644
index 00000000..b6e813be
--- /dev/null
+++ b/data/setn.device.json
@@ -0,0 +1,65 @@
+{
+ "configs": [
+ "/config.setup.json",
+ "/config.option.json",
+ "/config.live.json",
+ "/lang/lang.ru.json"
+ ],
+ "class": "col-sm-offset-1 col-sm-10",
+ "content": [
+ {
+ "type": "h5",
+ "title": "{{name}}",
+ "class": "alert-default"
+ },
+ {
+ "type": "link",
+ "title": "{{ButMainPage}}",
+ "action": "/",
+ "class": "btn btn-block btn-default"
+ },
+ {
+ "type": "hr"
+ },
+ {
+ "type": "dropdown",
+ "name": "help-url",
+ "class": "btn btn-default",
+ "style": "display:inline",
+ "title": {
+ "#": "Выберите элемент из списка",
+ "/set?element=button-out": "1.Кнопка управляющая пином",
+ "/set?element=button-out-i": "2.Кнопка управляющая пином с инверсией",
+ "/set?element=pwm-out": "3.Широтно импульсная подуляция",
+ "/set?element=button-in": "4.Физическая кнопка"
+ }
+ },
+ {
+ "type": "hr"
+ },
+ {
+ "type": "csv",
+ "title": [
+ "checkbox",
+ "html",
+ "text",
+ "text",
+ "text",
+ "text",
+ "text"
+ ],
+ "state": "conf.csv",
+ "style": "width:100%;",
+ "class": "btn btn-block btn-default"
+ },
+ {
+ "type": "hr"
+ },
+ {
+ "type": "link",
+ "title": "Удалить все",
+ "action": "/set?cleanconf",
+ "class": "btn btn-block btn-default"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/include/Class/LineParsing.h b/include/Class/LineParsing.h
index 884510b9..53481c9f 100644
--- a/include/Class/LineParsing.h
+++ b/include/Class/LineParsing.h
@@ -135,7 +135,7 @@ class LineParsing {
#ifdef LAYOUT_IN_RAM
all_widgets += widget + "\r\n";
#else
- addFile("layout.txt", buf);
+ addFileLn("layout.txt", buf);
#endif
}
diff --git a/include/Utils/FileUtils.h b/include/Utils/FileUtils.h
index af4dadc9..da2688ac 100644
--- a/include/Utils/FileUtils.h
+++ b/include/Utils/FileUtils.h
@@ -35,6 +35,11 @@ File seekFile(const String& filename, size_t position = 0);
*/
const String readFileString(const String& filename, const String& to_find);
+/*
+* Добовление строки в файл
+*/
+const String addFileLn(const String& filename, const String& str);
+
/*
* Добовление строки в файл
*/
diff --git a/src/Logging.cpp b/src/Logging.cpp
index 0abe9fb5..ab44bba6 100644
--- a/src/Logging.cpp
+++ b/src/Logging.cpp
@@ -94,7 +94,7 @@ void deleteOldDate(const String filename, size_t max_lines_cnt, String payload)
}
} else {
if (timeNow->hasTimeSynced()) {
- addFile(filename, timeNow->getTimeUnix() + " " + payload);
+ addFileLn(filename, timeNow->getTimeUnix() + " " + payload);
}
}
}
diff --git a/src/Utils/FileUtils.cpp b/src/Utils/FileUtils.cpp
index be3c4e5a..0ec732c3 100644
--- a/src/Utils/FileUtils.cpp
+++ b/src/Utils/FileUtils.cpp
@@ -51,7 +51,7 @@ const String readFileString(const String& filename, const String& to_find) {
return res;
}
-const String addFile(const String& filename, const String& str) {
+const String addFileLn(const String& filename, const String& str) {
String path = filepath(filename);
auto file = LittleFS.open(path, "a");
if (!file) {
@@ -62,6 +62,17 @@ const String addFile(const String& filename, const String& str) {
return "sucсess";
}
+const String addFile(const String& filename, const String& str) {
+ String path = filepath(filename);
+ auto file = LittleFS.open(path, "a");
+ if (!file) {
+ return "failed";
+ }
+ file.print(str);
+ file.close();
+ return "sucсess";
+}
+
bool copyFile(const String& src, const String& dst, bool overwrite) {
String srcPath = filepath(src);
String dstPath = filepath(dst);
diff --git a/src/Web.cpp b/src/Web.cpp
index f3813638..69f322fd 100644
--- a/src/Web.cpp
+++ b/src/Web.cpp
@@ -37,6 +37,16 @@ void web_init() {
request->redirect("/?set.device");
}
+ //--------------------------------------------------------------------------------
+ if (request->hasArg("element")) {
+ String name = request->getParam("element")->value();
+ String item = readFile("items/" + name + ".txt", 1024);
+ item.replace("\r\n", "");
+ item.replace("\r", "");
+ item.replace("\n", "");
+ addFile("conf.csv", "\n" + item);
+ request->redirect("/?setn.device");
+ }
//--------------------------------------------------------------------------------
if (request->hasArg("devinit")) {
Device_init();
@@ -73,7 +83,7 @@ void web_init() {
//--------------------------------------------------------------------------------
if (request->hasArg("updatelist")) {
removeFile("/dev.csv");
- addFile("dev.csv", "device id;device name;ip address");
+ addFileLn("dev.csv", "device id;device name;ip address");
request->redirect("/?set.udp");
}
//--------------------------------------------------------------------------------
diff --git a/src/Widgets.cpp b/src/Widgets.cpp
index e05bafbb..1f8b07ca 100644
--- a/src/Widgets.cpp
+++ b/src/Widgets.cpp
@@ -29,7 +29,7 @@ void createWidget(String descr, String page, String order, String filename, Stri
#ifdef LAYOUT_IN_RAM
all_widgets += widget + "\r\n";
#else
- addFile("layout.txt", buf);
+ addFileLn("layout.txt", buf);
#endif
}
@@ -56,7 +56,7 @@ void createWidgetParam(String widget, String page, String pageNumber, String fil
#ifdef LAYOUT_IN_RAM
all_widgets += widget + "\r\n";
#else
- addFile("layout.txt", buf);
+ addFileLn("layout.txt", buf);
#endif
}
@@ -80,7 +80,7 @@ void createChart(String widget, String page, String pageNumber, String filename,
#ifdef LAYOUT_IN_RAM
all_widgets += widget + "\r\n";
#else
- addFile("layout.txt", buf);
+ addFileLn("layout.txt", buf);
#endif
}
diff --git a/src/udp.cpp b/src/udp.cpp
index 5b9dc977..2f7ba644 100644
--- a/src/udp.cpp
+++ b/src/udp.cpp
@@ -24,7 +24,7 @@ void add_dev_in_list(String fileName, String id, String dev_name, String ip);
#ifdef UDP_ENABLED
void udp_init() {
removeFile("dev.csv");
- addFile("dev.csv", "device id;device name;ip address");
+ addFileLn("dev.csv", "device id;device name;ip address");
#ifdef ESP8266
udp.begin(udp_port);
@@ -130,7 +130,7 @@ void do_udp_data_parse() {
void add_dev_in_list(String filename, String id, String dev_name, String ip) {
auto file = seekFile("/" + filename);
if (!file.find(id.c_str())) {
- addFile(filename, id + ";" + dev_name + "; " + ip + "");
+ addFileLn(filename, id + ";" + dev_name + "; " + ip + "");
}
}