separate concerns

This commit is contained in:
2018-10-04 02:34:37 +02:00
parent 0686895f33
commit 207f90d60a
9 changed files with 262 additions and 117 deletions

39
src/wifiMesh/MeshCat.h Normal file
View File

@@ -0,0 +1,39 @@
#ifndef __MESHCAT__
#define __MESHCAT__
#include <TaskSchedulerDeclarations.h>
#include <MeshNet.h>
#include <SprocketConfig.h>
#include "utils_print.h"
#include "IlluCat.h"
#include "config.h"
using namespace std;
using namespace std::placeholders;
class MeshCat : public IlluCat {
public:
Scheduler* meshScheduler;
MeshCat(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg) : IlluCat(cfg, otaCfg, webCfg) {
meshScheduler = new Scheduler();
}
Sprocket* join(Network& net){
PRINT_MSG(Serial, SPROCKET_TYPE, "join mesh network");
net.init(meshScheduler);
net.onReceive(bind(&IlluCat::dispatch,this, _1, _2));
net.connect();
network = net;
return activate(&scheduler, &net);
}
void loop() {
meshScheduler->execute();
yield();
Sprocket::loop();
yield();
}
};
#endif

25
src/wifiMesh/main.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include "config.h"
#include "MeshNet.h"
#include "MeshCat.h"
MeshNet net({
SPROCKET_MODE, WIFI_CHANNEL,
MESH_PORT, MESH_PREFIX, MESH_PASSWORD,
STATION_SSID, STATION_PASSWORD, HOSTNAME,
MESH_DEBUG_TYPES
});
MeshCat sprocket(
{ STARTUP_DELAY, SERIAL_BAUD_RATE },
{ OTA_PORT, OTA_PASSWORD },
{ WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE }
);
void setup() {
delay(STARTUP_DELAY);
sprocket.join(net);
}
void loop() {
sprocket.loop();
yield();
}