create minimal mesh implementation

This commit is contained in:
2018-11-09 19:14:03 +01:00
parent 2c94dfe83d
commit 418d5e18fd
7 changed files with 73 additions and 79 deletions

View File

@@ -1,18 +0,0 @@
#include "IlluCat.h"
IlluCat::IlluCat(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg) : Sprocket(cfg)
{
sprocketConfig = cfg;
otaConfig = otaCfg;
webConfig = webCfg;
server = new AsyncWebServer(80);
server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json");
}
void IlluCat::setup()
{
addPlugin(new PixelPlugin());
addPlugin(new WebServerPlugin(webConfig, server));
addPlugin(new WebConfigPlugin(server));
addPlugin(new WebApi(server, 1));
}

View File

@@ -1,17 +1,14 @@
#ifndef __ILLUCAT__ #ifndef __ILLUCAT__
#define __ILLUCAT__ #define __ILLUCAT__
#include "config.h"
#include <TaskScheduler.h> #include <TaskScheduler.h>
#include <MeshNet.h>
#include <Sprocket.h> #include <Sprocket.h>
#include "config.h"
#include "NeoPattern.cpp"
#include "NeoPatternDto.h"
#include <plugins/WebServerConfig.h> #include <plugins/WebServerConfig.h>
#include <plugins/WebServerPlugin.cpp> #include <plugins/WebServerPlugin.cpp>
#include <plugins/WebConfigPlugin.cpp> #include <plugins/WebConfigPlugin.cpp>
#include "WebApi.cpp" #include "WebApiPlugin.cpp"
#include "PixelPlugin.h" #include "PixelPlugin.h"
using namespace std; using namespace std;
@@ -33,12 +30,9 @@ class IlluCat : public Sprocket
addPlugin(new PixelPlugin()); addPlugin(new PixelPlugin());
addPlugin(new WebServerPlugin(webConfig, server)); addPlugin(new WebServerPlugin(webConfig, server));
addPlugin(new WebConfigPlugin(server)); addPlugin(new WebConfigPlugin(server));
addPlugin(new WebApi(server, "mesh/broadcast")); addPlugin(new WebApiPlugin(server, "mesh/broadcast"));
} }
void setup()
{
}
}; };
#endif #endif

View File

@@ -1,13 +1,5 @@
#include "PixelPlugin.h" #include "PixelPlugin.h"
PixelPlugin::PixelPlugin(NeoPixelConfig cfg, NeoPattern *neoPattern)
{
pixelConfig = cfg;
pixels = neoPattern;
applyConfig(pixelConfig);
defaultAnimation();
}
PixelPlugin::PixelPlugin(NeoPattern *neoPattern) PixelPlugin::PixelPlugin(NeoPattern *neoPattern)
{ {
pixels = neoPattern; pixels = neoPattern;
@@ -15,7 +7,17 @@ PixelPlugin::PixelPlugin(NeoPattern *neoPattern)
applyConfig(pixelConfig); applyConfig(pixelConfig);
defaultAnimation(); defaultAnimation();
} }
PixelPlugin::PixelPlugin(PixelConfig cfg)
{
pixelConfig.brightness = cfg.brightness;
pixelConfig.pin = cfg.pin;
pixelConfig.length = cfg.length;
pixelConfig.updateInterval = cfg.updateInterval;
loadConfigFromFile();
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
applyConfig(pixelConfig);
defaultAnimation();
}
PixelPlugin::PixelPlugin() PixelPlugin::PixelPlugin()
{ {
loadConfigFromFile(); loadConfigFromFile();
@@ -114,6 +116,7 @@ void PixelPlugin::setPattern(String msg)
void PixelPlugin::animate() void PixelPlugin::animate()
{ {
pixels->Update(); pixels->Update();
yield();
} }
void PixelPlugin::enable() void PixelPlugin::enable()

View File

@@ -18,20 +18,30 @@ using namespace std::placeholders;
#define PIXEL_CONFIG_FILE "/pixelConfig.json" #define PIXEL_CONFIG_FILE "/pixelConfig.json"
#endif #endif
class PixelPlugin : public Plugin { struct PixelConfig
{
int pin;
int length;
int brightness;
int updateInterval;
};
class PixelPlugin : public Plugin
{
private: private:
NeoPixelConfig pixelConfig; NeoPixelConfig pixelConfig;
NeoPattern* pixels; NeoPattern *pixels;
NeoPatternState state; NeoPatternState state;
public: public:
Task animation; Task animation;
PixelPlugin(NeoPixelConfig cfg, NeoPattern* neoPattern); PixelPlugin(PixelConfig cfg);
PixelPlugin(NeoPattern *neoPattern); PixelPlugin(NeoPattern *neoPattern);
PixelPlugin(); PixelPlugin();
void loadConfigFromFile(); void loadConfigFromFile();
void applyConfig(NeoPixelConfig cfg); void applyConfig(NeoPixelConfig cfg);
void applyConfigFromFile(); void applyConfigFromFile();
void activate(Scheduler* userScheduler); void activate(Scheduler *userScheduler);
void defaultAnimation(); void defaultAnimation();
void setState(String msg); void setState(String msg);
void colorWheel(String msg); void colorWheel(String msg);

View File

@@ -17,7 +17,7 @@ using namespace std::placeholders;
// TODO headerfile // TODO headerfile
// FIXME constants // FIXME constants
class WebApi : public Plugin class WebApiPlugin : public Plugin
{ {
public: public:
@@ -28,7 +28,7 @@ class WebApi : public Plugin
int broadcast; int broadcast;
String broadcastTopic; String broadcastTopic;
WebApi(AsyncWebServer *_server, String _broadcastTopic) WebApiPlugin(AsyncWebServer *_server, String _broadcastTopic)
{ {
server = _server; server = _server;
broadcast = _broadcastTopic ? 1 : 0; broadcast = _broadcastTopic ? 1 : 0;
@@ -39,16 +39,16 @@ class WebApi : public Plugin
void activate(Scheduler *_scheduler) void activate(Scheduler *_scheduler)
{ {
ws = new AsyncWebSocket("/ws"); ws = new AsyncWebSocket("/ws");
ws->onEvent(bind(&WebApi::onWsEvent, this, _1, _2, _3, _4, _5, _6)); ws->onEvent(bind(&WebApiPlugin::onWsEvent, this, _1, _2, _3, _4, _5, _6));
server->addHandler(ws); server->addHandler(ws);
server->on("/api", HTTP_POST, bind(&WebApi::postRequestHandler, this, _1)); server->on("/api", HTTP_POST, bind(&WebApiPlugin::postRequestHandler, this, _1));
server->on("/update", HTTP_GET, bind(&WebApi::simpleFirmwareUploadFormvoid, this, _1)); server->on("/update", HTTP_GET, bind(&WebApiPlugin::simpleFirmwareUploadFormvoid, this, _1));
server->on("/update", HTTP_POST, bind(&WebApi::onFirmwareUpdateRequest, this, _1), bind(&WebApi::onFirmwareUpload, this, _1, _2, _3, _4, _5, _6)); server->on("/update", HTTP_POST, bind(&WebApiPlugin::onFirmwareUpdateRequest, this, _1), bind(&WebApiPlugin::onFirmwareUpload, this, _1, _2, _3, _4, _5, _6));
} }
void postRequestHandler(AsyncWebServerRequest *request) void postRequestHandler(AsyncWebServerRequest *request)
{ {
PRINT_MSG(Serial, SPROCKET_TYPE, "POST WebApi"); PRINT_MSG(Serial, SPROCKET_TYPE, "POST WebApiPlugin");
currentMessage.topic = WebUtils::getRequestParameterOrDefault(request, "topic", ""); currentMessage.topic = WebUtils::getRequestParameterOrDefault(request, "topic", "");
currentMessage.payload = WebUtils::getRequestParameterOrDefault(request, "payload", ""); currentMessage.payload = WebUtils::getRequestParameterOrDefault(request, "payload", "");
currentMessage.broadcast = atoi(WebUtils::getRequestParameterOrDefault(request, "broadcast", "0").c_str()); currentMessage.broadcast = atoi(WebUtils::getRequestParameterOrDefault(request, "broadcast", "0").c_str());

View File

@@ -1,9 +1,10 @@
#ifndef __MESH_CONFIG__ #ifndef __ILLUCAT_CONFIG__
#define __MESH_CONFIG__ #define __ILLUCAT_CONFIG__
// Scheduler config // Scheduler config
#define _TASK_SLEEP_ON_IDLE_RUN #define _TASK_SLEEP_ON_IDLE_RUN
#define _TASK_STD_FUNCTION #define _TASK_STD_FUNCTION
#define _TASK_PRIORITY
// Chip config // Chip config
#define SPROCKET_TYPE "ILLUCAT" #define SPROCKET_TYPE "ILLUCAT"
@@ -23,7 +24,7 @@
#define HOSTNAME "illucat" #define HOSTNAME "illucat"
#define CONNECT_TIMEOUT 10000 #define CONNECT_TIMEOUT 10000
#define MESH_DEBUG_TYPES ERROR | STARTUP | CONNECTION #define MESH_DEBUG_TYPES ERROR | STARTUP | CONNECTION
//ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE //#define MESH_DEBUG_TYPES ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE
#define PIXEL_CONFIG_FILE "/pixelConfig.json" #define PIXEL_CONFIG_FILE "/pixelConfig.json"

View File

@@ -1,14 +1,18 @@
#include "config.h" #include "config.h"
#include "plugins/MeshNetworkPlugin.cpp" #include "Sprocket.h"
#include "IlluCat.h" #include <plugins/MeshNetworkPlugin.cpp>
#include "PixelPlugin.h"
IlluCat *sprocket;
Sprocket *sprocket;
void setup() void setup()
{ {
sprocket = new IlluCat( sprocket = new Sprocket(
{STARTUP_DELAY, SERIAL_BAUD_RATE}, {STARTUP_DELAY, SERIAL_BAUD_RATE});
{WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE}); sprocket->addPlugin(new PixelPlugin(
{LED_STRIP_PIN,
LED_STRIP_LENGTH,
LED_STRIP_BRIGHTNESS,
LED_STRIP_UPDATE_INTERVAL}));
sprocket->addPlugin(new MeshNetworkPlugin( sprocket->addPlugin(new MeshNetworkPlugin(
{SPROCKET_MODE, WIFI_CHANNEL, {SPROCKET_MODE, WIFI_CHANNEL,
MESH_PORT, MESH_PREFIX, MESH_PASSWORD, MESH_PORT, MESH_PREFIX, MESH_PASSWORD,