illucat and basic button

This commit is contained in:
2018-06-29 22:33:36 +02:00
parent 0ba64686a1
commit 492d7f70a9
8 changed files with 501 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
#ifndef __MESH_APP__
#define __MESH_APP__
#include <painlessMesh.h>
#include <Sprocket.h>
#include <MeshNet.h>
#include "NeoPattern.h"
using namespace std;
using namespace std::placeholders;
struct NeoPixelConfig {
int pin;
int length;
};
class Illucat : public Sprocket {
public:
MeshNet* net;
NeoPattern* pixels;
Illucat(SprocketConfig cfg, NeoPixelConfig pixelCfg) : Sprocket(cfg) {
pixels = new NeoPattern(pixelCfg.length, pixelCfg.pin, NEO_GRB + NEO_KHZ800, [](int pixels){});
}
Sprocket* activate(Scheduler* scheduler, Network* network) {
net = static_cast<MeshNet*>(network);
net->mesh.onReceive(bind(&Illucat::messageReceived,this, _1, _2));
// TODO default rainbow task
} using Sprocket::activate;
void messageReceived( uint32_t from, String &msg ) {
Serial.printf("illucat: received from %u msg=%s\n", from, msg.c_str());
setHexColor(msg.c_str());
}
void setHexColor(const char *hex){
int r, g, b;
sscanf(hex, "%02x%02x%02x", &r, &g, &b);
pixels->ColorSet(pixels->Color(r,g,b));
}
void loop() {
net->update();
scheduler.execute();
}
};
#endif