mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-18 02:36:40 +01:00
separate declarations
This commit is contained in:
94
src/PixelPlugin.cpp
Normal file
94
src/PixelPlugin.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "PixelPlugin.h"
|
||||
|
||||
PixelPlugin::PixelPlugin(NeoPixelConfig cfg, NeoPattern *neoPattern)
|
||||
{
|
||||
pixelConfig = cfg;
|
||||
pixels = neoPattern;
|
||||
pixels->begin();
|
||||
pixels->setBrightness(pixelConfig.brightness);
|
||||
}
|
||||
|
||||
void PixelPlugin::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();
|
||||
PRINT_MSG(Serial, SPROCKET_TYPE, "NeoPixels activated");
|
||||
}
|
||||
|
||||
void PixelPlugin::setState(String msg)
|
||||
{
|
||||
PRINT_MSG(Serial, SPROCKET_TYPE, msg.c_str());
|
||||
state.fromJsonString(msg);
|
||||
//pixels->setBrightness(state.brightness);
|
||||
//pixels->ColorSet(state.color);
|
||||
pixels->Index = 0;
|
||||
pixels->Color1 = state.color;
|
||||
pixels->Color2 = state.color2;
|
||||
pixels->TotalSteps = state.totalSteps;
|
||||
pixels->ActivePattern = (pattern)state.pattern;
|
||||
pixels->Direction = FORWARD;
|
||||
}
|
||||
|
||||
void PixelPlugin::colorWheel(String msg)
|
||||
{
|
||||
int color = atoi(msg.c_str());
|
||||
pixels->ActivePattern = NONE;
|
||||
pixels->ColorSet(pixels->Wheel(color));
|
||||
}
|
||||
|
||||
void PixelPlugin::setTotalSteps(String msg)
|
||||
{
|
||||
pixels->TotalSteps = atoi(msg.c_str());
|
||||
}
|
||||
|
||||
void PixelPlugin::setBrightness(String msg)
|
||||
{
|
||||
int inVal = atoi(msg.c_str());
|
||||
pixels->setBrightness(inVal);
|
||||
pixels->show();
|
||||
}
|
||||
|
||||
void PixelPlugin::setColor(String msg)
|
||||
{
|
||||
pixels->ActivePattern = NONE;
|
||||
pixels->Color1 = atoi(msg.c_str());
|
||||
//if(pixels->ActivePattern == NONE){
|
||||
pixels->ColorSet(pixels->Color1);
|
||||
//}
|
||||
}
|
||||
|
||||
void PixelPlugin::setColor2(String msg)
|
||||
{
|
||||
pixels->Color2 = atoi(msg.c_str());
|
||||
}
|
||||
|
||||
void PixelPlugin::setPattern(String msg)
|
||||
{
|
||||
pixels->Index = 0;
|
||||
pixels->Direction = FORWARD;
|
||||
pixels->ActivePattern = (pattern)atoi(msg.c_str());
|
||||
}
|
||||
|
||||
void PixelPlugin::animate()
|
||||
{
|
||||
pixels->Update();
|
||||
}
|
||||
|
||||
void PixelPlugin::enable()
|
||||
{
|
||||
animation.enable();
|
||||
}
|
||||
|
||||
void PixelPlugin::disable()
|
||||
{
|
||||
animation.disable();
|
||||
}
|
||||
Reference in New Issue
Block a user