basic led code

This commit is contained in:
2018-09-02 19:10:32 +02:00
parent bafc541cbb
commit e9ba25c4db
20 changed files with 910 additions and 1 deletions

84
src/IlluCat.h Normal file
View File

@@ -0,0 +1,84 @@
#ifndef __MESH_APP__
#define __MESH_APP__
#include <painlessMesh.h>
#include <base/MeshSprocket.h>
#include <MeshNet.h>
#include "config.h"
#include "NeoPattern.cpp"
#include "NeoPatternDto.cpp"
#include "NeoPattern_api_json.h"
#include "NeoPattern_api_modes.cpp"
#include "utils_print.h"
#include <plugins/WebSO.h>
#include <plugins/OtaTcpPlugin.cpp>
#include <plugins/WebServerPlugin.cpp>
#include <plugins/WebConfigPlugin.cpp>
using namespace std;
using namespace std::placeholders;
class IlluCat : public MeshSprocket {
public:
NeoPixelConfig pixelConfig;
NeoPattern* pixels;
NeoPatternDto state;
Task animation;
AsyncWebServer* server;
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));
pixels->begin();
pixels->setBrightness(pixelConfig.brightness);
animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&IlluCat::animate, this));
addTask(animation);
scanningAnimation();
}
void scanningAnimation() {
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
//pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
}
void defaultAnimation() {
pixels->RainbowCycle(pixelConfig.updateInterval);
}
Sprocket* activate(Scheduler* scheduler, Network* network) {
// call parent method that enables dispatching and plugins
MeshSprocket::activate(scheduler, network);
net->mesh.onNewConnection(bind(&IlluCat::newConnection,this, _1));
net->mesh.onChangedConnections(bind(&IlluCat::connectionChanged,this));
// FIXME OnDisable is triggered after last scan, aprx. 10 sec
net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
return this;
} 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);
PIXEL_FNCS[state.mode](pixels, state.valueStr);
}
void newConnection(uint32_t nodeId){
PRINT_MSG(Serial, SPROCKET_TYPE, "connected to %u", nodeId);
defaultAnimation();
}
void connectionChanged(){
PRINT_MSG(Serial, SPROCKET_TYPE, "connection changed");
if(!net->mesh.getNodeList().size()){
defaultAnimation();
}
}
};
#endif