cleanup basic example

This commit is contained in:
2018-07-19 17:27:29 +02:00
parent c5396b5bc0
commit 4ec1481902
4 changed files with 10 additions and 14 deletions

View File

@@ -19,7 +19,6 @@ upload_speed = 921600
monitor_baud = 115200
lib_deps =
Hash
ESP Async WebServer
ESPAsyncTCP
TaskScheduler
painlessMesh

View File

@@ -9,6 +9,9 @@
using namespace std;
using namespace std::placeholders;
// FIXME move to some global fnc lib
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0])
struct SprocketConfig {
int startupDelay;
int serialBaudRate;
@@ -28,7 +31,8 @@ class Sprocket {
virtual Sprocket* activate();
virtual Sprocket* activate(Scheduler*) { return this; }
virtual Sprocket* activate(Scheduler*, Network*) { return this; }
//virtual void dispatch(uint32_t from, String &msg) {};
// TODO bind onMessage to network->onReceive
//virtual void onMessage(uint32_t from, String &msg) {};
};
#endif

View File

@@ -1,8 +1,6 @@
#ifndef __EXAMPLE_APP__
#define __EXAMPLE_APP__
//#include "Sprocket.h"
#include <ESPAsyncWebServer.h>
#include <Sprocket.h>
using namespace std;
@@ -12,23 +10,17 @@ class ExampleApp : public Sprocket {
public:
Task someTask;
ExampleApp(SprocketConfig cfg) : Sprocket(cfg) {
Serial.println("joo");
Serial.println("init");
}
Sprocket* activate(Scheduler* scheduler) {
Serial.println("activate");
someTask.set(TASK_SECOND, TASK_FOREVER, [this](){
someTask.set(TASK_SECOND, TASK_FOREVER, [](){
Serial.println("do stuff in task");
});
scheduler->addTask(someTask);
someTask.enable();
return this;
} using Sprocket::activate;
void server(AsyncWebServer* srv) {
srv->on("/ping", HTTP_POST, bind(&ExampleApp::handlePingRequest, this, _1));
}
void handlePingRequest(AsyncWebServerRequest *request) {
Serial.println("pinged");
request->send(200, "text/html", "pong");
}
};
#endif

View File

@@ -1,9 +1,10 @@
#define _TASK_SLEEP_ON_IDLE_RUN
#define _TASK_STD_FUNCTION
#define SERIAL_BAUD_RATE 115200
#define STARTUP_DELAY 3000
#include "ExampleApp.h"
#include "ExampleApp.cpp"
ExampleApp sprocket({ STARTUP_DELAY, SERIAL_BAUD_RATE });