mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
начал писать систему формирования виджетов
This commit is contained in:
47
src/CreateWidget.cpp
Normal file
47
src/CreateWidget.cpp
Normal 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";
|
||||
}
|
||||
@@ -20,6 +20,7 @@ void configure(String path) {
|
||||
myIoTSensor = (IoTSensor*)getAPI_AnalogAdc(jsonArrayElement);
|
||||
if (myIoTSensor) {
|
||||
iotSensors.push_back(myIoTSensor);
|
||||
createWidget(jsonArrayElement);
|
||||
}
|
||||
//================================================================================================================
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
Reference in New Issue
Block a user