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

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

View File

@@ -61,7 +61,7 @@
"type": "Reading", "type": "Reading",
"subtype": "InputValue", "subtype": "InputValue",
"id": "txt", "id": "txt",
"widget": "input", "widget": "inputDigit",
"page": "Лимиты", "page": "Лимиты",
"descr": "Порог" "descr": "Порог"
}, },

View File

@@ -0,0 +1,6 @@
{
"widget": "anydata",
"icon": "body",
"color": "red",
"descrColor": "red"
}

View File

@@ -0,0 +1,5 @@
{
"widget": "anydata",
"after": "",
"icon": ""
}

View File

@@ -0,0 +1,6 @@
{
"widget": "anydata",
"after": "",
"color":"red",
"icon": "walk"
}

View File

@@ -0,0 +1,5 @@
{
"widget": "anydata",
"after": "Amp",
"icon": "speedometer"
}

View File

@@ -0,0 +1,5 @@
{
"widget": "anydata",
"after": "Htz",
"icon": "speedometer"
}

View File

@@ -0,0 +1,6 @@
{
"widget": "anydata",
"after": "%",
"icon": "water",
"color": "#88AADF"
}

View File

@@ -0,0 +1,5 @@
{
"widget": "anydata",
"after": "ppb",
"icon": "body"
}

View File

@@ -0,0 +1,5 @@
{
"widget": "anydata",
"after": "ppm",
"icon": "body"
}

View File

@@ -0,0 +1,5 @@
{
"widget": "anydata",
"after": "mm",
"icon": "speedometer"
}

View File

@@ -0,0 +1,16 @@
{
"widget": "anydata",
"after": "°С",
"icon": "thermometer",
"font": "OCR A Std",
"color": [
{ "level": -20, "value": "#0000CC" },
{ "level": -10, "value": "#0000CC" },
{ "level": 0, "value": "#0000CC" },
{ "level": 12, "value": "#3366FF" },
{ "level": 16, "value": "#33CCFF" },
{ "level": 18, "value": "#009933" },
{ "level": 30, "value": "#FF9900" },
{ "level": 40, "value": "red" }
]
}

View File

@@ -0,0 +1,5 @@
{
"widget": "anydata",
"after": "",
"icon": "speedometer"
}

View File

@@ -0,0 +1,5 @@
{
"widget": "anydata",
"after": "Vlt",
"icon": "speedometer"
}

View File

@@ -0,0 +1,5 @@
{
"widget": "anydata",
"after": "Whr",
"icon": "speedometer"
}

View File

@@ -0,0 +1,5 @@
{
"widget": "anydata",
"after": "Wtt",
"icon": "speedometer"
}

View File

@@ -0,0 +1,6 @@
{
"widget": "btn",
"size": "large",
"color": "green",
"send": "test"
}

View File

@@ -0,0 +1,5 @@
{
"widget": "chart",
"dateFormat": "HH:mm",
"pointRadius": 0
}

View File

@@ -0,0 +1,4 @@
{
"widget": "chart",
"dateFormat": "HH:mm"
}

View File

@@ -0,0 +1,5 @@
{
"widget": "chart",
"dateFormat": "DD.MM.YYYY",
"type":"bar"
}

View File

@@ -0,0 +1,4 @@
{
"widget": "chart",
"dateFormat": "DD.MM.YYYY"
}

View File

@@ -0,0 +1,7 @@
{
"widget": "fillgauge",
"circleColor": "#00FFFF",
"textColor": "#FFFFFF",
"waveTextColor": "#000000",
"waveColor": "#00FFFF"
}

View File

@@ -0,0 +1,6 @@
{
"widget" : "input",
"size" : "small",
"color" : "orange",
"type" : "date"
}

View File

@@ -0,0 +1,5 @@
{
"widget" : "input",
"color" : "blue",
"type" : "number"
}

View File

@@ -0,0 +1,7 @@
{
"widget" : "input",
"color" : "green",
"type" : "number",
"size" : "small",
"icon": "thermometer"
}

View File

@@ -0,0 +1,6 @@
{
"widget" : "input",
"size" : "small",
"color" : "orange",
"type" : "text"
}

View File

@@ -0,0 +1,5 @@
{
"widget" : "input",
"color" : "blue",
"type" : "time"
}

View File

@@ -0,0 +1,7 @@
{
"widget" : "input",
"color" : "orange",
"type" : "time",
"size" : "small",
"icon": "alarm-outline"
}

View File

@@ -0,0 +1,12 @@
{
"widget": "progress-line",
"icon": "sunny",
"descrColor": "",
"color": "",
"max": "100",
"background": "",
"stroke": "10",
"disabled": "",
"before": "",
"after": ""
}

View File

@@ -0,0 +1,11 @@
{
"widget": "progress-round",
"descrColor": "",
"max": "100",
"stroke": "20",
"color": "#45ccce",
"background": "#777",
"before": "",
"semicircle": "1",
"after": ""
}

View File

@@ -0,0 +1,9 @@
{
"widget" : "range",
"descrColor": "red",
"after" : "%",
"k" : 0.0977,
"min" : 0,
"max" : 100,
"debounce": 500
}

View File

@@ -0,0 +1,8 @@
{
"widget": "select",
"options": [
"Выключен",
"Включен"
],
"status": 0
}

View File

@@ -0,0 +1,5 @@
{
"widget": "toggle",
"icon": "",
"iconOff": ""
}

View File

@@ -0,0 +1,5 @@
{
"widget": "toggle",
"icon": "sunny",
"iconOff": "moon"
}

8
include/CreateWidget.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
#include "Global.h"
extern void createWidget(String& parameters);
extern bool loadWidget(const String& filename, String& buf);
extern const String getWidgetFile(const String& name);

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "Global.h" #include "Global.h"
#include "Classes/IoTSensor.h" #include "Classes/IoTSensor.h"
#include "CreateWidget.h"
extern std::vector<IoTSensor*> iotSensors; // вектор ссылок базового класса IoTSensor - список всех запущенных сенсоров extern std::vector<IoTSensor*> iotSensors; // вектор ссылок базового класса IoTSensor - список всех запущенных сенсоров

View File

@@ -7,3 +7,4 @@ extern const String writeFile(const String& filename, const String& str);
extern const String readFile(const String& filename, size_t max_size); extern const String readFile(const String& filename, size_t max_size);
extern const String filepath(const String& filename); extern const String filepath(const String& filename);
extern bool cutFile(const String& src, const String& dst); extern bool cutFile(const String& src, const String& dst);
extern const String addFileLn(const String& filename, const String& str);

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); myIoTSensor = (IoTSensor*)getAPI_AnalogAdc(jsonArrayElement);
if (myIoTSensor) { if (myIoTSensor) {
iotSensors.push_back(myIoTSensor); iotSensors.push_back(myIoTSensor);
createWidget(jsonArrayElement);
} }
//================================================================================================================ //================================================================================================================
} }

View File

@@ -64,3 +64,14 @@ bool cutFile(const String& src, const String& dst) {
FileFS.remove(srcPath); FileFS.remove(srcPath);
return true; 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";
}