moar topics

This commit is contained in:
2018-09-17 15:34:24 +02:00
parent 939f167dad
commit ad8ba61986
7 changed files with 91 additions and 12 deletions

View File

@@ -53,6 +53,7 @@ class IlluCat : public MeshSprocket {
pixelConfig.defaultColor = 100;
}
// TDOO remove
virtual void scanningAnimation() {
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
//pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
@@ -97,7 +98,8 @@ class IlluCat : public MeshSprocket {
server->addHandler(ws);
// FIXME OnDisable is triggered after last scan, aprx. 10 sec
net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
// FIXME chck if this is also triggered when new connection arrives
//net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
return MeshSprocket::activate(scheduler, network);
} using MeshSprocket::activate;
@@ -113,9 +115,15 @@ class IlluCat : public MeshSprocket {
virtual void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) {
if(type == WS_EVT_DATA){
String frame = WsUtils::parseFrameAsString(type, arg, data, len, 0);
onMessage(0, frame);
net->mesh.sendBroadcast(frame);
client->text(String(millis()));
//onMessage(0, frame);
NeoPatternMsg msg;
msg.fromJsonString(frame);
if(msg.valid){
// TODO convert message to send to mesh
//net->mesh.sendBroadcast(frame);
publish(msg.topic, msg.payload);
client->text(String(millis()));
}
}
}

View File

@@ -26,11 +26,38 @@ class PixelPlugin : public Plugin {
pixels->setBrightness(pixelConfig.brightness);
}
void activate(Scheduler* userScheduler, Network* network){
subscribe("pixels/color", bind(&PixelPlugin::setColor, this, _1));
subscribe("pixels/color2", bind(&PixelPlugin::setColor2, this, _1));
subscribe("pixels/pattern", bind(&PixelPlugin::setPattern, this, _1));
subscribe("pixels/totalSteps", bind(&PixelPlugin::setTotalSteps, this, _1));
subscribe("pixels/brightness", bind(&PixelPlugin::setBrightness, this, _1));
animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this));
userScheduler->addTask(animation);
animation.enable();
Serial.println("NeoPixels activated");
}
void setTotalSteps(String msg){
pixels->TotalSteps = atoi(msg.c_str());
}
void setBrightness(String msg){
int inVal = atoi(msg.c_str());
pixels->setBrightness(inVal);
pixels->show();
}
void setColor(String msg){
pixels->Color1 = atoi(msg.c_str());
if(pixels->ActivePattern == NONE){
pixels->ColorSet(pixels->Color1);
}
}
void setColor2(String msg){
pixels->Color2 = atoi(msg.c_str());
}
void setPattern(String msg){
pixels->Index = 0;
pixels->ActivePattern = (pattern)atoi(msg.c_str());
}
void animate(){
pixels->Update();
}