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

7
data/pixelConfig.json Normal file
View File

@@ -0,0 +1,7 @@
{
"pin": 4,
"length": 8,
"brightness": 32,
"updateInterval": 150,
"defaultColor": 100
}

4
data/pixelState.json Normal file
View File

@@ -0,0 +1,4 @@
{
"mode": 3,
"value": 1
}

View File

@@ -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]);

View File

@@ -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

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();