mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-29 07:32:18 +03:00
working example of callback with date passing inside and outside
This commit is contained in:
@@ -5,9 +5,28 @@ AsyncActions::AsyncActions(){};
|
||||
void AsyncActions::loop() {
|
||||
count++;
|
||||
if (count > 5000) {
|
||||
if(_cb) _cb; //что означает эта запись? это и есть вызов callback?
|
||||
// Проверяем что переменная содержит указатель - не пустая не null
|
||||
// и непосредственно вызываем то, на что это указывает
|
||||
// просто пишем имя - без () - это указатель на фунецию.
|
||||
// () - вызываем функцию - с пустым набором параметров
|
||||
|
||||
if (_cb != NULL) {
|
||||
_cb();
|
||||
}
|
||||
//или ровно тоже самое
|
||||
//if (_cb) _cb();
|
||||
|
||||
if (_pcb) {
|
||||
if (_pcb("SomeTextValue")) {
|
||||
Serial.print("Got true!");
|
||||
} else {
|
||||
Serial.print("Got false!");
|
||||
}
|
||||
}
|
||||
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AsyncActions* async;
|
||||
21
src/main.cpp
21
src/main.cpp
@@ -1,4 +1,5 @@
|
||||
#include "Bus/BusScannerFactory.h"
|
||||
#include "Class/AsyncActions.h"
|
||||
#include "Class/Switch.h"
|
||||
#include "Cmd.h"
|
||||
#include "DeviceList.h"
|
||||
@@ -6,7 +7,6 @@
|
||||
#include "HttpServer.h"
|
||||
#include "Init.h"
|
||||
#include "Utils/Timings.h"
|
||||
#include "Class/AsyncActions.h"
|
||||
|
||||
void not_async_actions();
|
||||
|
||||
@@ -69,7 +69,8 @@ void setup() {
|
||||
udp_init();
|
||||
#endif
|
||||
|
||||
ts.add(TEST, 1000 * 60, [&](void*) { pm.info(printMemoryStatus()); }, nullptr, true);
|
||||
ts.add(
|
||||
TEST, 1000 * 60, [&](void*) { pm.info(printMemoryStatus()); }, nullptr, true);
|
||||
|
||||
just_load = false;
|
||||
initialized = true;
|
||||
@@ -77,14 +78,20 @@ void setup() {
|
||||
async = new AsyncActions();
|
||||
|
||||
//async->setCallback([&](void*) {
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//});
|
||||
|
||||
async->setCallback(myCallback); //
|
||||
|
||||
|
||||
async->setCallback([]() {
|
||||
Serial.println("123");
|
||||
});
|
||||
|
||||
async->setCallback([](const String str) {
|
||||
Serial.println(str);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Reference in New Issue
Block a user