mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
callback
This commit is contained in:
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"id1": "id1",
|
|
||||||
"id2": "id2",
|
|
||||||
"id3": "id3",
|
|
||||||
"id4": "id4"
|
|
||||||
}
|
|
||||||
5
data/items/signs.json
Normal file
5
data/items/signs.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"more":">",
|
||||||
|
"less":"<",
|
||||||
|
"eq":"="
|
||||||
|
}
|
||||||
@@ -58,12 +58,66 @@
|
|||||||
"action": "/set?cleanconf",
|
"action": "/set?cleanconf",
|
||||||
"class": "btn btn-block btn-default"
|
"class": "btn btn-block btn-default"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "hr"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "h4",
|
||||||
|
"title": "Если",
|
||||||
|
"style": "width:25%;float:left;"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "select",
|
"type": "select",
|
||||||
"name": "id-arg",
|
"name": "id-arg",
|
||||||
"action": "/set?id=[[id-arg]]",
|
"action": "/set?id=[[id-arg]]",
|
||||||
"state": "en",
|
"state": "en",
|
||||||
"title": "elements.json"
|
"title": "items/elements.json",
|
||||||
|
"style": "width:25%;float:left"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"name": "id-arg2",
|
||||||
|
"action": "/set?id=[[id-arg2]]",
|
||||||
|
"state": "en",
|
||||||
|
"title": "items/signs.json",
|
||||||
|
"style": "width:25%;float:left"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input",
|
||||||
|
"title": "",
|
||||||
|
"name": "fsi-arg",
|
||||||
|
"pattern": "",
|
||||||
|
"state": "{{fsi}}",
|
||||||
|
"style": "width:25%;float:left"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "hr"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "h4",
|
||||||
|
"title": "То",
|
||||||
|
"style": "width:25%;float:left;"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "select",
|
||||||
|
"name": "id-arg3",
|
||||||
|
"action": "/set?id=[[id-arg3]]",
|
||||||
|
"state": "en",
|
||||||
|
"title": "items/elements.json",
|
||||||
|
"style": "width:25%;float:left"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "h4",
|
||||||
|
"title": "=",
|
||||||
|
"style": "width:25%;float:left;"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input",
|
||||||
|
"title": "",
|
||||||
|
"name": "fsi-arg",
|
||||||
|
"pattern": "",
|
||||||
|
"state": "{{fsi}}",
|
||||||
|
"style": "width:25%;float:left"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
29
include/Class/AsyncActions.h
Normal file
29
include/Class/AsyncActions.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
// Декларируем тип - сигнатуру метода , который мы готовы принять в данном случае это
|
||||||
|
// должен быть метод без результата и без параметров.
|
||||||
|
// Новый тип мы называем AsynсActionCb - хотя можешь назвать вообще как нравиться а что значит callBack
|
||||||
|
|
||||||
|
//а как вызывать callback и когда их много? когда нужно вызывать например 10 разных из класса?
|
||||||
|
//
|
||||||
|
|
||||||
|
typedef std::function<void(void*)> AsyncActionCb; //метод без результата и параметров
|
||||||
|
|
||||||
|
class AsyncActions {
|
||||||
|
private:
|
||||||
|
long count;
|
||||||
|
AsyncActionCb _cb;
|
||||||
|
|
||||||
|
public:
|
||||||
|
AsyncActions();
|
||||||
|
void loop();
|
||||||
|
void setCallback(AsyncActionCb cb) { //передаем внутрь класса функцию любую void функцию без агрументов
|
||||||
|
_cb = cb;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern AsyncActions* async;
|
||||||
@@ -6,5 +6,7 @@
|
|||||||
extern void addElement(String name);
|
extern void addElement(String name);
|
||||||
extern void delAllElement();
|
extern void delAllElement();
|
||||||
extern int getNewElementNumber(String file);
|
extern int getNewElementNumber(String file);
|
||||||
extern void delElement(String itemsFile, String itemsLine);
|
extern void do_getJsonListFromCsv();
|
||||||
|
extern String getJsonListFromCsv(String csvFile,int colum);
|
||||||
extern void do_delElement();
|
extern void do_delElement();
|
||||||
|
extern void delElement(String itemsFile, String itemsLine);
|
||||||
@@ -115,6 +115,10 @@ extern boolean mqttParamsChanged;
|
|||||||
extern boolean udp_data_parse;
|
extern boolean udp_data_parse;
|
||||||
extern boolean mqtt_send_settings_to_udp;
|
extern boolean mqtt_send_settings_to_udp;
|
||||||
extern boolean delElementFlag;
|
extern boolean delElementFlag;
|
||||||
|
extern boolean getJsonListFromCsvFlag;
|
||||||
|
|
||||||
|
extern String csvFile;
|
||||||
|
extern int colum;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Запрос на скарнирование шины
|
* Запрос на скарнирование шины
|
||||||
|
|||||||
3
include/main.h
Normal file
3
include/main.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
//void myCallback;
|
||||||
13
src/Class/AsyncActions.cpp
Normal file
13
src/Class/AsyncActions.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include "Class/AsyncActions.h"
|
||||||
|
|
||||||
|
AsyncActions::AsyncActions(){};
|
||||||
|
|
||||||
|
void AsyncActions::loop() {
|
||||||
|
count++;
|
||||||
|
if (count > 5000) {
|
||||||
|
if(_cb) _cb; //что означает эта запись? это и есть вызов callback?
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncActions* async;
|
||||||
@@ -21,7 +21,6 @@ void delAllElement() {
|
|||||||
removeFile("order.txt");
|
removeFile("order.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int getNewElementNumber(String file) {
|
int getNewElementNumber(String file) {
|
||||||
int number = readFile(file, 100).toInt();
|
int number = readFile(file, 100).toInt();
|
||||||
number++;
|
number++;
|
||||||
@@ -30,7 +29,37 @@ int getNewElementNumber(String file) {
|
|||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void do_getJsonListFromCsv() {
|
||||||
|
if (getJsonListFromCsvFlag) {
|
||||||
|
getJsonListFromCsvFlag = false;
|
||||||
|
removeFile("items/elements.json");
|
||||||
|
addFile("items/elements.json", getJsonListFromCsv("conf.csv", 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String getJsonListFromCsv(String csvFile, int colum) {
|
||||||
|
File configFile = LittleFS.open("/" + csvFile, "r");
|
||||||
|
if (!configFile) {
|
||||||
|
return "error";
|
||||||
|
}
|
||||||
|
configFile.seek(0, SeekSet);
|
||||||
|
|
||||||
|
String outJson = "{}";
|
||||||
|
|
||||||
|
int count = -1;
|
||||||
|
|
||||||
|
while (configFile.position() != configFile.size()) {
|
||||||
|
count++;
|
||||||
|
String item = configFile.readStringUntil('\n');
|
||||||
|
if (count > 0) {
|
||||||
|
String line = selectFromMarkerToMarker(item, ";", colum);
|
||||||
|
jsonWriteStr(outJson, line, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
configFile.close();
|
||||||
|
csvFile = "";
|
||||||
|
return outJson;
|
||||||
|
}
|
||||||
|
|
||||||
void do_delElement() {
|
void do_delElement() {
|
||||||
if (delElementFlag) {
|
if (delElementFlag) {
|
||||||
|
|||||||
@@ -86,3 +86,7 @@ BusScanner_t busToScan;
|
|||||||
boolean busScanFlag = false;
|
boolean busScanFlag = false;
|
||||||
boolean fsCheckFlag = false;
|
boolean fsCheckFlag = false;
|
||||||
boolean delElementFlag = false;
|
boolean delElementFlag = false;
|
||||||
|
boolean getJsonListFromCsvFlag = false;
|
||||||
|
|
||||||
|
String csvFile = "";
|
||||||
|
int colum;
|
||||||
@@ -42,21 +42,27 @@ void web_init() {
|
|||||||
if (request->hasArg("element")) {
|
if (request->hasArg("element")) {
|
||||||
String name = request->getParam("element")->value();
|
String name = request->getParam("element")->value();
|
||||||
addElement(name);
|
addElement(name);
|
||||||
|
getJsonListFromCsvFlag = true;
|
||||||
Device_init();
|
Device_init();
|
||||||
request->redirect("/?setn.device");
|
request->redirect("/?setn.device");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasArg("cleanconf")) {
|
if (request->hasArg("cleanconf")) {
|
||||||
delAllElement();
|
delAllElement();
|
||||||
|
removeFile("items/elements.json");
|
||||||
Device_init();
|
Device_init();
|
||||||
request->redirect("/?setn.device");
|
request->redirect("/?setn.device");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->hasArg("save")) {
|
if (request->hasArg("save")) {
|
||||||
Device_init();
|
Device_init();
|
||||||
|
getJsonListFromCsvFlag = true;
|
||||||
request->redirect("/?setn.device");
|
request->redirect("/?setn.device");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
if (request->hasArg("devinit")) {
|
if (request->hasArg("devinit")) {
|
||||||
Device_init();
|
Device_init();
|
||||||
|
|||||||
64
src/main.cpp
64
src/main.cpp
@@ -1,11 +1,12 @@
|
|||||||
#include "Global.h"
|
|
||||||
#include "Init.h"
|
|
||||||
#include "Cmd.h"
|
|
||||||
#include "HttpServer.h"
|
|
||||||
#include "Bus/BusScannerFactory.h"
|
#include "Bus/BusScannerFactory.h"
|
||||||
#include "Utils/Timings.h"
|
|
||||||
#include "Class/Switch.h"
|
#include "Class/Switch.h"
|
||||||
|
#include "Cmd.h"
|
||||||
#include "DeviceList.h"
|
#include "DeviceList.h"
|
||||||
|
#include "Global.h"
|
||||||
|
#include "HttpServer.h"
|
||||||
|
#include "Init.h"
|
||||||
|
#include "Utils/Timings.h"
|
||||||
|
#include "Class/AsyncActions.h"
|
||||||
|
|
||||||
void not_async_actions();
|
void not_async_actions();
|
||||||
|
|
||||||
@@ -67,49 +68,54 @@ void setup() {
|
|||||||
pm.info("Broadcast UDP");
|
pm.info("Broadcast UDP");
|
||||||
udp_init();
|
udp_init();
|
||||||
#endif
|
#endif
|
||||||
ts.add(
|
|
||||||
TEST, 1000 * 60, [&](void*) {
|
ts.add(TEST, 1000 * 60, [&](void*) { pm.info(printMemoryStatus()); }, nullptr, true);
|
||||||
pm.info(printMemoryStatus());
|
|
||||||
},
|
|
||||||
nullptr, true);
|
|
||||||
|
|
||||||
just_load = false;
|
just_load = false;
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
|
async = new AsyncActions();
|
||||||
|
|
||||||
|
//async->setCallback([&](void*) {
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//});
|
||||||
|
|
||||||
|
async->setCallback(myCallback); //
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
timeNow->loop();
|
|
||||||
|
|
||||||
#ifdef OTA_UPDATES_ENABLED
|
#ifdef OTA_UPDATES_ENABLED
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
#endif
|
#endif
|
||||||
#ifdef WS_enable
|
#ifdef WS_enable
|
||||||
ws.cleanupClients();
|
ws.cleanupClients();
|
||||||
#endif
|
#endif
|
||||||
not_async_actions();
|
|
||||||
|
|
||||||
MqttClient::loop();
|
|
||||||
|
|
||||||
loopCmd();
|
|
||||||
|
|
||||||
mySwitch->loop();
|
|
||||||
|
|
||||||
loopScenario();
|
|
||||||
|
|
||||||
#ifdef UDP_ENABLED
|
#ifdef UDP_ENABLED
|
||||||
loopUdp();
|
loopUdp();
|
||||||
#endif
|
#endif
|
||||||
|
timeNow->loop();
|
||||||
|
async->loop();
|
||||||
|
not_async_actions();
|
||||||
|
MqttClient::loop();
|
||||||
|
loopCmd();
|
||||||
|
mySwitch->loop();
|
||||||
|
loopScenario();
|
||||||
loopSerial();
|
loopSerial();
|
||||||
|
|
||||||
ts.update();
|
ts.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void not_async_actions() {
|
void not_async_actions() {
|
||||||
|
#ifdef UDP_ENABLED
|
||||||
|
do_udp_data_parse();
|
||||||
|
do_mqtt_send_settings_to_udp();
|
||||||
|
#endif
|
||||||
if (mqttParamsChanged) {
|
if (mqttParamsChanged) {
|
||||||
MqttClient::reconnect();
|
MqttClient::reconnect();
|
||||||
mqttParamsChanged = false;
|
mqttParamsChanged = false;
|
||||||
@@ -118,15 +124,9 @@ void not_async_actions() {
|
|||||||
getLastVersion();
|
getLastVersion();
|
||||||
|
|
||||||
do_update();
|
do_update();
|
||||||
|
|
||||||
#ifdef UDP_ENABLED
|
|
||||||
do_udp_data_parse();
|
|
||||||
do_mqtt_send_settings_to_udp();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
do_scan_bus();
|
do_scan_bus();
|
||||||
|
|
||||||
do_delElement();
|
do_delElement();
|
||||||
|
do_getJsonListFromCsv();
|
||||||
}
|
}
|
||||||
|
|
||||||
String getURL(const String& urls) {
|
String getURL(const String& urls) {
|
||||||
|
|||||||
Reference in New Issue
Block a user