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

View File

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

View File

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