diff --git a/data/pixelConfig.json b/data/pixelConfig.json new file mode 100644 index 0000000..fdeb075 --- /dev/null +++ b/data/pixelConfig.json @@ -0,0 +1,7 @@ +{ + "pin": 4, + "length": 8, + "brightness": 32, + "updateInterval": 150, + "defaultColor": 100 +} \ No newline at end of file diff --git a/data/pixelState.json b/data/pixelState.json new file mode 100644 index 0000000..c116550 --- /dev/null +++ b/data/pixelState.json @@ -0,0 +1,4 @@ +{ + "mode": 3, + "value": 1 +} \ No newline at end of file diff --git a/lib/NeoPattern/NeoPatternDto.h b/lib/NeoPattern/NeoPatternDto.h index 297982b..fcbfb6d 100644 --- a/lib/NeoPattern/NeoPatternDto.h +++ b/lib/NeoPattern/NeoPatternDto.h @@ -50,7 +50,7 @@ struct NeoPatternDto : public JsonStruct { // Map a json object to this struct. void fromJsonObject(JsonObject& json){ if(!verifyJsonObject(json)){ - PRINT_MSG(Serial, "PatternState.fromJsonObject", "cannot parse JSON"); + PRINT_MSG(Serial, "fromJsonObject", "cannot parse JSON"); return; } mode = atoi(json[JSON_MODE_NODE]); diff --git a/lib/NeoPattern/NeoPattern_api_json.h b/lib/NeoPattern/NeoPattern_api_json.h index 9e9bb71..61c3f70 100644 --- a/lib/NeoPattern/NeoPattern_api_json.h +++ b/lib/NeoPattern/NeoPattern_api_json.h @@ -9,8 +9,8 @@ patterns: NONE = 0, RAINBOW_CYCLE = 1, THEATER_CHASE = 2, COLOR_WIPE = 3, SCANNE } */ -#define JSON_MODE_NODE "pixelMode" -#define JSON_VALUE "pixelValue" +#define JSON_MODE_NODE "mode" +#define JSON_VALUE "value" #define JSON_ACTION_NODE "action" #endif \ No newline at end of file diff --git a/src/IlluCat.h b/src/IlluCat.h index 2ae54af..16eb459 100644 --- a/src/IlluCat.h +++ b/src/IlluCat.h @@ -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(network); - net->mesh.onNewConnection(bind(&IlluCat::newConnection,this, _1)); - net->mesh.onChangedConnections(bind(&IlluCat::connectionChanged,this)); + net = static_cast(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();