начал писать систему формирования виджетов

This commit is contained in:
Dmitry Borisenko
2022-01-15 23:29:52 +01:00
parent 7f5b78b695
commit f01fea9bac
39 changed files with 272 additions and 2 deletions

47
src/CreateWidget.cpp Normal file
View File

@@ -0,0 +1,47 @@
#include "CreateWidget.h"
void createWidget(String& parameters) {
String id = jsonReadStr(parameters, "id");
String widget = jsonReadStr(parameters, "widget");
String order = jsonReadStr(parameters, "order");
String page = jsonReadStr(parameters, "page");
String descr = jsonReadStr(parameters, "descr");
if (widget != "na") {
String buf = "{}";
if (!loadWidget(widget, buf)) {
return;
}
// if (_cnt != "") {
// if (widget.indexOf("chart") != -1) jsonWriteStr(buf, "maxCount", _cnt);
// }
#ifdef GATE_MODE
jsonWriteStr(buf, "info", " ");
#endif
jsonWriteStr(buf, "page", page);
jsonWriteStr(buf, "order", order);
jsonWriteStr(buf, "descr", descr);
jsonWriteStr(buf, "topic", prex + "/" + id);
#ifdef LAYOUT_IN_RAM
all_widgets += widget + "\r\n";
#else
addFileLn("layout.txt", buf);
#endif
}
}
bool loadWidget(const String& widget, String& buf) {
buf = readFile(getWidgetFile(widget), 2048);
bool res = !(buf == "Failed" || buf == "Large");
if (!res) {
SerialPrint("E", "module", "on load" + widget);
}
return res;
}
const String getWidgetFile(const String& name) {
return "/widgets/" + name + ".json";
}

View File

@@ -20,6 +20,7 @@ void configure(String path) {
myIoTSensor = (IoTSensor*)getAPI_AnalogAdc(jsonArrayElement);
if (myIoTSensor) {
iotSensors.push_back(myIoTSensor);
createWidget(jsonArrayElement);
}
//================================================================================================================
}

View File

@@ -63,4 +63,15 @@ bool cutFile(const String& src, const String& dst) {
dstFile.close();
FileFS.remove(srcPath);
return true;
}
const String addFileLn(const String& filename, const String& str) {
String path = filepath(filename);
auto file = FileFS.open(path, "a");
if (!file) {
return "failed";
}
file.println(str);
file.close();
return "sucсess";
}