mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 13:25:03 +01:00
illucat and basic button
This commit is contained in:
45
src/examples/illucat/Illucat.h
Normal file
45
src/examples/illucat/Illucat.h
Normal 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
|
||||
Reference in New Issue
Block a user