mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-16 01:58:47 +01:00
stuff
This commit is contained in:
7
data/pixelConfig.json
Normal file
7
data/pixelConfig.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"pin": 4,
|
||||||
|
"length": 8,
|
||||||
|
"brightness": 32,
|
||||||
|
"updateInterval": 150,
|
||||||
|
"defaultColor": 100
|
||||||
|
}
|
||||||
4
data/pixelState.json
Normal file
4
data/pixelState.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"mode": 3,
|
||||||
|
"value": 1
|
||||||
|
}
|
||||||
@@ -50,7 +50,7 @@ struct NeoPatternDto : public JsonStruct {
|
|||||||
// Map a json object to this struct.
|
// Map a json object to this struct.
|
||||||
void fromJsonObject(JsonObject& json){
|
void fromJsonObject(JsonObject& json){
|
||||||
if(!verifyJsonObject(json)){
|
if(!verifyJsonObject(json)){
|
||||||
PRINT_MSG(Serial, "PatternState.fromJsonObject", "cannot parse JSON");
|
PRINT_MSG(Serial, "fromJsonObject", "cannot parse JSON");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mode = atoi(json[JSON_MODE_NODE]);
|
mode = atoi(json[JSON_MODE_NODE]);
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ patterns: NONE = 0, RAINBOW_CYCLE = 1, THEATER_CHASE = 2, COLOR_WIPE = 3, SCANNE
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define JSON_MODE_NODE "pixelMode"
|
#define JSON_MODE_NODE "mode"
|
||||||
#define JSON_VALUE "pixelValue"
|
#define JSON_VALUE "value"
|
||||||
#define JSON_ACTION_NODE "action"
|
#define JSON_ACTION_NODE "action"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -23,6 +23,7 @@ using namespace std::placeholders;
|
|||||||
class IlluCat : public MeshSprocket {
|
class IlluCat : public MeshSprocket {
|
||||||
public:
|
public:
|
||||||
NeoPattern* pixels;
|
NeoPattern* pixels;
|
||||||
|
NeoPatternDto defaultState;
|
||||||
NeoPatternDto state;
|
NeoPatternDto state;
|
||||||
Task animation;
|
Task animation;
|
||||||
AsyncWebServer* server;
|
AsyncWebServer* server;
|
||||||
@@ -51,16 +52,19 @@ class IlluCat : public MeshSprocket {
|
|||||||
//pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
|
//pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
|
||||||
}
|
}
|
||||||
void defaultAnimation() {
|
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) {
|
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()){
|
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);
|
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
|
||||||
server = new AsyncWebServer(80);
|
server = new AsyncWebServer(80);
|
||||||
@@ -73,7 +77,7 @@ class IlluCat : public MeshSprocket {
|
|||||||
|
|
||||||
// FIXME OnDisable is triggered after last scan, aprx. 10 sec
|
// FIXME OnDisable is triggered after last scan, aprx. 10 sec
|
||||||
net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
|
net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
|
||||||
return MeshSprocket::activate(scheduler, network);;
|
return MeshSprocket::activate(scheduler, network);
|
||||||
} using MeshSprocket::activate;
|
} using MeshSprocket::activate;
|
||||||
|
|
||||||
void onMessage( uint32_t from, String &msg ) {
|
void onMessage( uint32_t from, String &msg ) {
|
||||||
@@ -82,11 +86,11 @@ class IlluCat : public MeshSprocket {
|
|||||||
PIXEL_FNCS[state.mode](pixels, state.valueStr);
|
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);
|
PRINT_MSG(Serial, SPROCKET_TYPE, "connected to %u", nodeId);
|
||||||
defaultAnimation();
|
defaultAnimation();
|
||||||
}
|
}
|
||||||
void connectionChanged(){
|
void onConnectionChanged(){
|
||||||
PRINT_MSG(Serial, SPROCKET_TYPE, "connection changed");
|
PRINT_MSG(Serial, SPROCKET_TYPE, "connection changed");
|
||||||
if(!net->mesh.getNodeList().size()){
|
if(!net->mesh.getNodeList().size()){
|
||||||
defaultAnimation();
|
defaultAnimation();
|
||||||
|
|||||||
Reference in New Issue
Block a user