This commit is contained in:
2018-09-03 03:33:51 +02:00
parent b69a0937a0
commit cbb4b95244
5 changed files with 27 additions and 12 deletions

View File

@@ -23,6 +23,7 @@ using namespace std::placeholders;
class IlluCat : public MeshSprocket {
public:
NeoPattern* pixels;
NeoPatternDto defaultState;
NeoPatternDto state;
Task animation;
AsyncWebServer* server;
@@ -51,16 +52,19 @@ class IlluCat : public MeshSprocket {
//pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
}
void defaultAnimation() {
pixels->RainbowCycle(pixelConfig.updateInterval);
String defaultStr = String(defaultState.value);
PIXEL_FNCS[defaultState.mode](pixels, defaultStr.c_str());
}
Sprocket* activate(Scheduler* scheduler, Network* network) {
// call parent method that enables dispatching and plugins
net = static_cast<MeshNet*>(network);
net->mesh.onNewConnection(bind(&IlluCat::newConnection,this, _1));
net->mesh.onChangedConnections(bind(&IlluCat::connectionChanged,this));
net = static_cast<MeshNet*>(network);
net->mesh.onNewConnection(bind(&IlluCat::onNewConnection,this, _1));
net->mesh.onChangedConnections(bind(&IlluCat::onConnectionChanged,this));
if(SPIFFS.begin()){
pixelConfig.fromFile("/config.json");
pixelConfig.fromFile("/pixelConfig.json");
defaultState.fromFile("/pixelState.json");
state = defaultState;
}
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
server = new AsyncWebServer(80);
@@ -73,7 +77,7 @@ class IlluCat : public MeshSprocket {
// FIXME OnDisable is triggered after last scan, aprx. 10 sec
net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
return MeshSprocket::activate(scheduler, network);;
return MeshSprocket::activate(scheduler, network);
} using MeshSprocket::activate;
void onMessage( uint32_t from, String &msg ) {
@@ -82,11 +86,11 @@ class IlluCat : public MeshSprocket {
PIXEL_FNCS[state.mode](pixels, state.valueStr);
}
void newConnection(uint32_t nodeId){
void onNewConnection(uint32_t nodeId){
PRINT_MSG(Serial, SPROCKET_TYPE, "connected to %u", nodeId);
defaultAnimation();
}
void connectionChanged(){
void onConnectionChanged(){
PRINT_MSG(Serial, SPROCKET_TYPE, "connection changed");
if(!net->mesh.getNodeList().size()){
defaultAnimation();