mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-15 21:18:21 +01:00
45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
#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 |