mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Continue making web interface
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
],
|
||||
"state": "conf.csv",
|
||||
"style": "width:100%;",
|
||||
"action": "/set?delete",
|
||||
"class": "btn btn-block btn-default"
|
||||
},
|
||||
{
|
||||
|
||||
9
include/DeviceList.h
Normal file
9
include/DeviceList.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Global.h"
|
||||
|
||||
extern void addElement(String name);
|
||||
extern void delAllElement();
|
||||
extern void delElement();
|
||||
extern void do_delElement();
|
||||
@@ -111,6 +111,7 @@ extern boolean updateFlag;
|
||||
extern boolean mqttParamsChanged;
|
||||
extern boolean udp_data_parse;
|
||||
extern boolean mqtt_send_settings_to_udp;
|
||||
extern boolean delElementFlag;
|
||||
|
||||
/*
|
||||
* Запрос на скарнирование шины
|
||||
|
||||
41
src/DeviceList.cpp
Normal file
41
src/DeviceList.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "DeviceList.h"
|
||||
|
||||
static const char* firstLine PROGMEM = "Удалить;Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета";
|
||||
|
||||
void addElement(String name) {
|
||||
String item = readFile("items/" + name + ".txt", 1024);
|
||||
item.replace("\r\n", "");
|
||||
item.replace("\r", "");
|
||||
item.replace("\n", "");
|
||||
addFile("conf.csv", "\n" + item);
|
||||
}
|
||||
|
||||
void delAllElement() {
|
||||
removeFile("conf.csv");
|
||||
addFile("conf.csv", String(firstLine));
|
||||
}
|
||||
|
||||
void do_delElement() {
|
||||
if (delElementFlag) {
|
||||
delElementFlag = false;
|
||||
delElement();
|
||||
}
|
||||
}
|
||||
|
||||
void delElement() {
|
||||
File configFile = LittleFS.open("/conf.csv", "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
}
|
||||
configFile.seek(0, SeekSet); //поставим курсор в начало файла
|
||||
String finalConf;
|
||||
while (configFile.position() != configFile.size()) {
|
||||
String item = configFile.readStringUntil('\n');
|
||||
if (selectToMarker(item, ";") == "0") {
|
||||
finalConf += "\n" + item;
|
||||
}
|
||||
}
|
||||
removeFile("conf.csv");
|
||||
addFile("conf.csv", String(firstLine) + "\n" + finalConf);
|
||||
configFile.close();
|
||||
}
|
||||
@@ -82,3 +82,4 @@ boolean mqtt_send_settings_to_udp = false;
|
||||
BusScanner_t busToScan;
|
||||
boolean busScanFlag = false;
|
||||
boolean fsCheckFlag = false;
|
||||
boolean delElementFlag = false;
|
||||
@@ -48,10 +48,10 @@ void timerStart_() {
|
||||
void addTimer(String number, String time) {
|
||||
String tmp = jsonReadStr(configOptionJson, "timers"); //1:60,2:120,
|
||||
String new_timer = number + ":" + time;
|
||||
int psn1 = tmp.indexOf(number + ":"); //0 ищем позицию таймера который надо заменить
|
||||
if (psn1 != -1) { //если он есть
|
||||
int psn2 = tmp.indexOf(",", psn1); //4 от этой позиции находим позицию запятой
|
||||
String timer = tmp.substring(psn1, psn2); //1:60 выделяем таймер который надо заменить
|
||||
int psn1 = tmp.indexOf(number + ":"); //0 ищем позицию таймера который надо заменить
|
||||
if (psn1 != -1) { //если он есть
|
||||
int psn2 = tmp.indexOf(",", psn1); //4 от этой позиции находим позицию запятой
|
||||
String timer = tmp.substring(psn1, psn2); //1:60 выделяем таймер который надо заменить
|
||||
///tmp.replace(timer, new_timer); //заменяем таймер на новый (во всей стороке)
|
||||
tmp.replace(timer + ",", "");
|
||||
tmp += new_timer + ",";
|
||||
|
||||
18
src/Web.cpp
18
src/Web.cpp
@@ -1,3 +1,4 @@
|
||||
#include "DeviceList.h"
|
||||
#include "Global.h"
|
||||
#include "Init.h"
|
||||
|
||||
@@ -40,13 +41,20 @@ void web_init() {
|
||||
//--------------------------------------------------------------------------------
|
||||
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);
|
||||
addElement(name);
|
||||
request->redirect("/?setn.device");
|
||||
}
|
||||
|
||||
if (request->hasArg("cleanconf")) {
|
||||
delAllElement();
|
||||
request->redirect("/?setn.device");
|
||||
}
|
||||
|
||||
if (request->hasArg("delete")) {
|
||||
delElementFlag = true;
|
||||
request->redirect("/?setn.device");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
if (request->hasArg("devinit")) {
|
||||
Device_init();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Bus/BusScannerFactory.h"
|
||||
#include "Utils/Timings.h"
|
||||
#include "Class/Switch.h"
|
||||
#include "DeviceList.h"
|
||||
|
||||
void not_async_actions();
|
||||
|
||||
@@ -124,6 +125,8 @@ void not_async_actions() {
|
||||
#endif
|
||||
|
||||
do_scan_bus();
|
||||
|
||||
do_delElement();
|
||||
}
|
||||
|
||||
String getURL(const String& urls) {
|
||||
|
||||
Reference in New Issue
Block a user