create scheduler instance

This commit is contained in:
2018-11-08 13:58:07 +01:00
parent f290ec6197
commit c75c4f24f3
3 changed files with 12 additions and 8 deletions

View File

@@ -13,10 +13,11 @@ Sprocket* Sprocket::init(SprocketConfig cfg){
delay(cfg.startupDelay);
Serial.begin(cfg.serialBaudRate);
SPIFFS.begin();
scheduler = new Scheduler();
return this;
}
Sprocket* Sprocket::activate() {
return activate(&scheduler);
return activate(scheduler);
}
Sprocket* Sprocket::activate(Scheduler* scheduler) {
// setup plugins
@@ -24,23 +25,23 @@ Sprocket* Sprocket::activate(Scheduler* scheduler) {
return this;
}
// TODO check if we want to remove network from sprocket and handle everything via plugins
Sprocket* Sprocket::join(Network& net){
Serial.println("join network");
net.init(&scheduler);
//net.onReceive(bind(&Sprocket::dispatch,this, _1, _2));
net.init(scheduler);
net.connect();
network = net;
return activate(&scheduler);
return activate(scheduler);
}
Sprocket* Sprocket::addTask(Task& tsk){
scheduler.addTask(tsk);
scheduler->addTask(tsk);
tsk.enable();
return this;
}
void Sprocket::loop(){
scheduler.execute();
scheduler->execute();
}
void Sprocket::dispatch( uint32_t from, String &msg ) {

View File

@@ -1,6 +1,9 @@
#ifndef __SPROCKET_H__
#define __SPROCKET_H__
#define _TASK_SLEEP_ON_IDLE_RUN
#define _TASK_STD_FUNCTION
#include <TaskSchedulerDeclarations.h>
//#include <TaskScheduler.h>
#include <Arduino.h>
@@ -23,7 +26,7 @@ class Sprocket : public Mediator {
protected:
// TODO move scheduler out of Sprocket
// => see difference between standalone and mesh sprochet usage of scheduler
Scheduler scheduler;
Scheduler* scheduler;
Network network;
private:
SprocketMessage currentMessage;

View File

@@ -15,7 +15,7 @@ MeshApp sprocket(
);
void setup() {
sprocket.join(net);
//sprocket.join(net);
}
void loop() {