mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-15 01:42:22 +01:00
85 lines
2.8 KiB
C++
85 lines
2.8 KiB
C++
#ifndef __PIXEL_PLUGIN__
|
|
#define __PIXEL_PLUGIN__
|
|
|
|
#define _TASK_SLEEP_ON_IDLE_RUN
|
|
#define _TASK_STD_FUNCTION
|
|
|
|
#include "TaskSchedulerDeclarations.h"
|
|
#include "MeshNet.h"
|
|
#include "Plugin.h"
|
|
#include "NeoPatternDto.h"
|
|
#include "NeoPattern.cpp"
|
|
|
|
using namespace std;
|
|
using namespace std::placeholders;
|
|
|
|
class PixelPlugin : public Plugin {
|
|
private:
|
|
NeoPixelConfig pixelConfig;
|
|
NeoPattern* pixels;
|
|
NeoPatternState state;
|
|
public:
|
|
Task animation;
|
|
PixelPlugin(NeoPixelConfig cfg, NeoPattern* neoPattern){
|
|
pixelConfig = cfg;
|
|
pixels = neoPattern;
|
|
pixels->begin();
|
|
pixels->setBrightness(pixelConfig.brightness);
|
|
}
|
|
void activate(Scheduler* userScheduler, Network* network){
|
|
subscribe("pixels/colorWheel", bind(&PixelPlugin::colorWheel, this, _1));
|
|
subscribe("pixels/color", bind(&PixelPlugin::setColor, this, _1));
|
|
subscribe("pixels/color2", bind(&PixelPlugin::setColor2, this, _1));
|
|
subscribe("pixels/pattern", bind(&PixelPlugin::setPattern, this, _1));
|
|
subscribe("pixels/totalSteps", bind(&PixelPlugin::setTotalSteps, this, _1));
|
|
subscribe("pixels/brightness", bind(&PixelPlugin::setBrightness, this, _1));
|
|
subscribe("pixels/state", bind(&PixelPlugin::setState, this, _1));
|
|
|
|
animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this));
|
|
userScheduler->addTask(animation);
|
|
animation.enable();
|
|
Serial.println("NeoPixels activated");
|
|
}
|
|
// TODO set the whole pixel state
|
|
void setState(String msg){
|
|
state.fromJsonString(msg);
|
|
}
|
|
void colorWheel(String msg){
|
|
int color = atoi(msg.c_str());
|
|
pixels->ActivePattern = NONE;
|
|
pixels->ColorSet(pixels->Wheel(color));
|
|
}
|
|
void setTotalSteps(String msg){
|
|
pixels->TotalSteps = atoi(msg.c_str());
|
|
}
|
|
void setBrightness(String msg){
|
|
int inVal = atoi(msg.c_str());
|
|
pixels->setBrightness(inVal);
|
|
pixels->show();
|
|
}
|
|
void setColor(String msg){
|
|
pixels->ActivePattern = NONE;
|
|
pixels->Color1 = atoi(msg.c_str());
|
|
//if(pixels->ActivePattern == NONE){
|
|
pixels->ColorSet(pixels->Color1);
|
|
//}
|
|
}
|
|
void setColor2(String msg){
|
|
pixels->Color2 = atoi(msg.c_str());
|
|
}
|
|
void setPattern(String msg){
|
|
pixels->Index = 0;
|
|
pixels->ActivePattern = (pattern)atoi(msg.c_str());
|
|
}
|
|
void animate(){
|
|
pixels->Update();
|
|
}
|
|
void enable(){
|
|
animation.enable();
|
|
}
|
|
void disable(){
|
|
animation.disable();
|
|
}
|
|
};
|
|
|
|
#endif |