mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-16 18:05:05 +01:00
load pixel config from json file
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "NeoPattern.cpp"
|
||||
#include "NeoPatternDto.cpp"
|
||||
#include "NeoPatternDto.h"
|
||||
#include "NeoPattern_api_json.h"
|
||||
#include "NeoPattern_api_modes.cpp"
|
||||
#include "utils_print.h"
|
||||
@@ -22,22 +22,29 @@ using namespace std::placeholders;
|
||||
|
||||
class IlluCat : public MeshSprocket {
|
||||
public:
|
||||
NeoPixelConfig pixelConfig;
|
||||
NeoPattern* pixels;
|
||||
NeoPatternDto state;
|
||||
Task animation;
|
||||
AsyncWebServer* server;
|
||||
|
||||
NeoPixelConfig pixelConfig;
|
||||
SprocketConfig sprocketConfig;
|
||||
OtaConfig otaConfig;
|
||||
WebServerConfig webConfig;
|
||||
|
||||
IlluCat(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg, NeoPixelConfig pixelCfg) : MeshSprocket(cfg) {
|
||||
pixelConfig = pixelCfg;
|
||||
pixels = new NeoPattern(pixelCfg.length, pixelCfg.pin, NEO_GRB + NEO_KHZ800);
|
||||
server = new AsyncWebServer(80);
|
||||
addPlugin(new OtaTcpPlugin(otaCfg));
|
||||
addPlugin(new WebServerPlugin(webCfg, server));
|
||||
addPlugin(new WebConfigPlugin(server));
|
||||
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
||||
IlluCat(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg/* , NeoPixelConfig pixelCfg */) : MeshSprocket(cfg) {
|
||||
//pixelConfig = pixelCfg;
|
||||
|
||||
scanningAnimation();
|
||||
sprocketConfig = cfg;
|
||||
otaConfig = otaCfg;
|
||||
webConfig = webCfg;
|
||||
|
||||
pixelConfig.pin = 4;
|
||||
pixelConfig.length = 8;
|
||||
pixelConfig.brightness = 32;
|
||||
pixelConfig.updateInterval = 100;
|
||||
pixelConfig.defaultColor = 100;
|
||||
|
||||
}
|
||||
void scanningAnimation() {
|
||||
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
|
||||
@@ -48,19 +55,27 @@ class IlluCat : public MeshSprocket {
|
||||
}
|
||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||
// call parent method that enables dispatching and plugins
|
||||
MeshSprocket::activate(scheduler, network);
|
||||
net = static_cast<MeshNet*>(network);
|
||||
net->mesh.onNewConnection(bind(&IlluCat::newConnection,this, _1));
|
||||
net->mesh.onChangedConnections(bind(&IlluCat::connectionChanged,this));
|
||||
|
||||
if(SPIFFS.begin()){
|
||||
pixelConfig.fromFile("/config.json");
|
||||
}
|
||||
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
|
||||
server = new AsyncWebServer(80);
|
||||
addPlugin(new OtaTcpPlugin(otaConfig));
|
||||
addPlugin(new WebServerPlugin(webConfig, server));
|
||||
addPlugin(new WebConfigPlugin(server));
|
||||
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
||||
|
||||
scanningAnimation();
|
||||
|
||||
// FIXME OnDisable is triggered after last scan, aprx. 10 sec
|
||||
net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
|
||||
return this;
|
||||
return MeshSprocket::activate(scheduler, network);;
|
||||
} using MeshSprocket::activate;
|
||||
|
||||
void animate(){
|
||||
pixels->Update();
|
||||
}
|
||||
|
||||
void onMessage( uint32_t from, String &msg ) {
|
||||
PRINT_MSG(Serial, SPROCKET_TYPE, "msg from %u = %s\n", from, msg.c_str());
|
||||
state.fromJsonString(msg);
|
||||
|
||||
Reference in New Issue
Block a user