From 7e632eb89bec680f0e2999a7a8a2645b32ff953a Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sun, 23 Sep 2018 15:05:54 +0200 Subject: [PATCH] update endpoints --- src/IlluCat.h | 37 +++++++++---------------------------- src/PixelPlugin.h | 8 +++++++- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/IlluCat.h b/src/IlluCat.h index ed53462..c4980be 100644 --- a/src/IlluCat.h +++ b/src/IlluCat.h @@ -55,55 +55,50 @@ 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); } virtual void defaultAnimation() { String defaultStr = String(defaultState.value); PIXEL_FNCS[defaultState.mode](pixels, defaultStr.c_str()); - //pixels->RainbowCycle(150); } Sprocket* activate(Scheduler* scheduler, Network* network) { net = static_cast(network); - net->mesh.onNewConnection(bind(&IlluCat::onNewConnection,this, _1)); - //net->mesh.onChangedConnections(bind(&IlluCat::onConnectionChanged,this)); + // load config files from SPIFFS if(SPIFFS.begin()){ pixelConfig.fromFile("/pixelConfig.json"); defaultState.fromFile("/pixelState.json"); state = defaultState; } + + // initialize services pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800); server = new AsyncWebServer(80); ws = new AsyncWebSocket("/pixel"); dnsServer = new DNSServer(); + // add plugins addPlugin(new OtaTcpPlugin(otaConfig)); addPlugin(new WebServerPlugin(webConfig, server)); addPlugin(new WebConfigPlugin(server)); addPlugin(new PixelPlugin(pixelConfig, pixels)); + defaultAnimation(); - - // TODO plugin? + // configure DNS + // plugin? dnsServer->setErrorReplyCode(DNSReplyCode::NoError); dnsServer->start(DNS_PORT, "*", WiFi.softAPIP()); Serial.println("SoftAP IP: " + WiFi.softAPIP().toString()); - defaultAnimation(); - // TODO plugin // setup web stuff server->serveStatic("/pixelConfig.json", SPIFFS, "pixelConfig.json"); - server->on("/pixel/state", HTTP_POST, bind(&IlluCat::patternWebRequestHandler, this, _1)); + server->on("/pixel/api", HTTP_POST, bind(&IlluCat::patternWebRequestHandler, this, _1)); ws->onEvent(bind(&IlluCat::onWsEvent, this, _1, _2, _3, _4, _5, _6)); server->addHandler(ws); - // FIXME OnDisable is triggered after last scan, aprx. 10 sec - // 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; @@ -130,7 +125,7 @@ class IlluCat : public MeshSprocket { String frame = WsUtils::parseFrameAsString(type, arg, data, len, 0); net->mesh.sendBroadcast(frame); dispatch(0, frame); - client->text(String(millis())); + //client->text(String(millis())); } } @@ -143,20 +138,6 @@ class IlluCat : public MeshSprocket { } } - virtual void onNewConnection(uint32_t nodeId){ - PRINT_MSG(Serial, SPROCKET_TYPE, "connected to %u", nodeId); - // publish current state to new node - // TODO broadcast enable/disable flag - //String stateJson = currentMessage.toJsonString(); - //net->mesh.sendSingle(nodeId, stateJson); - } - //virtual void onConnectionChanged(){ - // PRINT_MSG(Serial, SPROCKET_TYPE, "connection changed"); - // //if(!net->mesh.getNodeList().size()){ - // // defaultAnimation(); - // //} - //} - void loop(){ MeshSprocket::loop(); dnsServer->processNextRequest(); diff --git a/src/PixelPlugin.h b/src/PixelPlugin.h index dfd7f70..1e4ae5c 100644 --- a/src/PixelPlugin.h +++ b/src/PixelPlugin.h @@ -40,9 +40,15 @@ class PixelPlugin : public Plugin { animation.enable(); Serial.println("NeoPixels activated"); } - // TODO set the whole pixel state void setState(String msg){ state.fromJsonString(msg); + pixels->setBrightness(state.brightness); + pixels->ColorSet(state.color); + pixels->Index = 0; + pixels->Color1 = state.color; + pixels->Color2 = state.color2; + pixels->TotalSteps = state.totalSteps; + pixels->ActivePattern = (pattern) state.pattern; } void colorWheel(String msg){ int color = atoi(msg.c_str());