mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-14 17:35:22 +01:00
create minimal mesh implementation
This commit is contained in:
@@ -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));
|
||||
}
|
||||
@@ -1,17 +1,14 @@
|
||||
#ifndef __ILLUCAT__
|
||||
#define __ILLUCAT__
|
||||
|
||||
#include "config.h"
|
||||
#include <TaskScheduler.h>
|
||||
#include <MeshNet.h>
|
||||
#include <Sprocket.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "NeoPattern.cpp"
|
||||
#include "NeoPatternDto.h"
|
||||
#include <plugins/WebServerConfig.h>
|
||||
#include <plugins/WebServerPlugin.cpp>
|
||||
#include <plugins/WebConfigPlugin.cpp>
|
||||
#include "WebApi.cpp"
|
||||
#include "WebApiPlugin.cpp"
|
||||
#include "PixelPlugin.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -33,12 +30,9 @@ class IlluCat : public Sprocket
|
||||
addPlugin(new PixelPlugin());
|
||||
addPlugin(new WebServerPlugin(webConfig, server));
|
||||
addPlugin(new WebConfigPlugin(server));
|
||||
addPlugin(new WebApi(server, "mesh/broadcast"));
|
||||
addPlugin(new WebApiPlugin(server, "mesh/broadcast"));
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,13 +1,5 @@
|
||||
#include "PixelPlugin.h"
|
||||
|
||||
PixelPlugin::PixelPlugin(NeoPixelConfig cfg, NeoPattern *neoPattern)
|
||||
{
|
||||
pixelConfig = cfg;
|
||||
pixels = neoPattern;
|
||||
applyConfig(pixelConfig);
|
||||
defaultAnimation();
|
||||
}
|
||||
|
||||
PixelPlugin::PixelPlugin(NeoPattern *neoPattern)
|
||||
{
|
||||
pixels = neoPattern;
|
||||
@@ -15,7 +7,17 @@ PixelPlugin::PixelPlugin(NeoPattern *neoPattern)
|
||||
applyConfig(pixelConfig);
|
||||
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()
|
||||
{
|
||||
loadConfigFromFile();
|
||||
@@ -114,6 +116,7 @@ void PixelPlugin::setPattern(String msg)
|
||||
void PixelPlugin::animate()
|
||||
{
|
||||
pixels->Update();
|
||||
yield();
|
||||
}
|
||||
|
||||
void PixelPlugin::enable()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define __PIXEL_PLUGIN__
|
||||
|
||||
#define _TASK_SLEEP_ON_IDLE_RUN
|
||||
#define _TASK_STD_FUNCTION
|
||||
#define _TASK_STD_FUNCTION
|
||||
|
||||
#include "TaskSchedulerDeclarations.h"
|
||||
#include "MeshNet.h"
|
||||
@@ -18,31 +18,41 @@ using namespace std::placeholders;
|
||||
#define PIXEL_CONFIG_FILE "/pixelConfig.json"
|
||||
#endif
|
||||
|
||||
class PixelPlugin : public Plugin {
|
||||
private:
|
||||
NeoPixelConfig pixelConfig;
|
||||
NeoPattern* pixels;
|
||||
NeoPatternState state;
|
||||
public:
|
||||
Task animation;
|
||||
PixelPlugin(NeoPixelConfig cfg, NeoPattern* neoPattern);
|
||||
PixelPlugin(NeoPattern *neoPattern);
|
||||
PixelPlugin();
|
||||
void loadConfigFromFile();
|
||||
void applyConfig(NeoPixelConfig cfg);
|
||||
void applyConfigFromFile();
|
||||
void activate(Scheduler* userScheduler);
|
||||
void defaultAnimation();
|
||||
void setState(String msg);
|
||||
void colorWheel(String msg);
|
||||
void setTotalSteps(String msg);
|
||||
void setBrightness(String msg);
|
||||
void setColor(String msg);
|
||||
void setColor2(String msg);
|
||||
void setPattern(String msg);
|
||||
void animate();
|
||||
void enable();
|
||||
void disable();
|
||||
struct PixelConfig
|
||||
{
|
||||
int pin;
|
||||
int length;
|
||||
int brightness;
|
||||
int updateInterval;
|
||||
};
|
||||
|
||||
class PixelPlugin : public Plugin
|
||||
{
|
||||
private:
|
||||
NeoPixelConfig pixelConfig;
|
||||
NeoPattern *pixels;
|
||||
NeoPatternState state;
|
||||
|
||||
public:
|
||||
Task animation;
|
||||
PixelPlugin(PixelConfig cfg);
|
||||
PixelPlugin(NeoPattern *neoPattern);
|
||||
PixelPlugin();
|
||||
void loadConfigFromFile();
|
||||
void applyConfig(NeoPixelConfig cfg);
|
||||
void applyConfigFromFile();
|
||||
void activate(Scheduler *userScheduler);
|
||||
void defaultAnimation();
|
||||
void setState(String msg);
|
||||
void colorWheel(String msg);
|
||||
void setTotalSteps(String msg);
|
||||
void setBrightness(String msg);
|
||||
void setColor(String msg);
|
||||
void setColor2(String msg);
|
||||
void setPattern(String msg);
|
||||
void animate();
|
||||
void enable();
|
||||
void disable();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -17,7 +17,7 @@ using namespace std::placeholders;
|
||||
// TODO headerfile
|
||||
// FIXME constants
|
||||
|
||||
class WebApi : public Plugin
|
||||
class WebApiPlugin : public Plugin
|
||||
{
|
||||
|
||||
public:
|
||||
@@ -28,7 +28,7 @@ class WebApi : public Plugin
|
||||
int broadcast;
|
||||
String broadcastTopic;
|
||||
|
||||
WebApi(AsyncWebServer *_server, String _broadcastTopic)
|
||||
WebApiPlugin(AsyncWebServer *_server, String _broadcastTopic)
|
||||
{
|
||||
server = _server;
|
||||
broadcast = _broadcastTopic ? 1 : 0;
|
||||
@@ -39,16 +39,16 @@ class WebApi : public Plugin
|
||||
void activate(Scheduler *_scheduler)
|
||||
{
|
||||
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->on("/api", HTTP_POST, bind(&WebApi::postRequestHandler, this, _1));
|
||||
server->on("/update", HTTP_GET, bind(&WebApi::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("/api", HTTP_POST, bind(&WebApiPlugin::postRequestHandler, this, _1));
|
||||
server->on("/update", HTTP_GET, bind(&WebApiPlugin::simpleFirmwareUploadFormvoid, this, _1));
|
||||
server->on("/update", HTTP_POST, bind(&WebApiPlugin::onFirmwareUpdateRequest, this, _1), bind(&WebApiPlugin::onFirmwareUpload, this, _1, _2, _3, _4, _5, _6));
|
||||
}
|
||||
|
||||
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.payload = WebUtils::getRequestParameterOrDefault(request, "payload", "");
|
||||
currentMessage.broadcast = atoi(WebUtils::getRequestParameterOrDefault(request, "broadcast", "0").c_str());
|
||||
@@ -1,9 +1,10 @@
|
||||
#ifndef __MESH_CONFIG__
|
||||
#define __MESH_CONFIG__
|
||||
#ifndef __ILLUCAT_CONFIG__
|
||||
#define __ILLUCAT_CONFIG__
|
||||
|
||||
// Scheduler config
|
||||
#define _TASK_SLEEP_ON_IDLE_RUN
|
||||
#define _TASK_STD_FUNCTION
|
||||
#define _TASK_PRIORITY
|
||||
|
||||
// Chip config
|
||||
#define SPROCKET_TYPE "ILLUCAT"
|
||||
@@ -23,7 +24,7 @@
|
||||
#define HOSTNAME "illucat"
|
||||
#define CONNECT_TIMEOUT 10000
|
||||
#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"
|
||||
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
#include "config.h"
|
||||
#include "plugins/MeshNetworkPlugin.cpp"
|
||||
#include "IlluCat.h"
|
||||
|
||||
IlluCat *sprocket;
|
||||
#include "Sprocket.h"
|
||||
#include <plugins/MeshNetworkPlugin.cpp>
|
||||
#include "PixelPlugin.h"
|
||||
|
||||
Sprocket *sprocket;
|
||||
void setup()
|
||||
{
|
||||
sprocket = new IlluCat(
|
||||
{STARTUP_DELAY, SERIAL_BAUD_RATE},
|
||||
{WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE});
|
||||
sprocket = new Sprocket(
|
||||
{STARTUP_DELAY, SERIAL_BAUD_RATE});
|
||||
sprocket->addPlugin(new PixelPlugin(
|
||||
{LED_STRIP_PIN,
|
||||
LED_STRIP_LENGTH,
|
||||
LED_STRIP_BRIGHTNESS,
|
||||
LED_STRIP_UPDATE_INTERVAL}));
|
||||
sprocket->addPlugin(new MeshNetworkPlugin(
|
||||
{SPROCKET_MODE, WIFI_CHANNEL,
|
||||
MESH_PORT, MESH_PREFIX, MESH_PASSWORD,
|
||||
|
||||
Reference in New Issue
Block a user