mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-15 17:58:20 +01:00
externalize pixel stuff, add pixel instance to plugin, remove old code
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
"text": "None",
|
||||
"value": ["#000000", "#000000"]
|
||||
},
|
||||
{
|
||||
"text": "Stadler",
|
||||
"value": ["#0B3F75", "#0B3F75"]
|
||||
},
|
||||
{
|
||||
"text": "Blu",
|
||||
"value": ["#00416A", "#E4E5E6"]
|
||||
|
||||
@@ -66,6 +66,7 @@ class NeoPattern : public Adafruit_NeoPixel
|
||||
frameBuffer = (uint8_t *)malloc(768);
|
||||
OnComplete = callback;
|
||||
TotalSteps = numPixels();
|
||||
begin();
|
||||
}
|
||||
|
||||
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type)
|
||||
@@ -73,6 +74,7 @@ class NeoPattern : public Adafruit_NeoPixel
|
||||
{
|
||||
frameBuffer = (uint8_t *)malloc(768);
|
||||
TotalSteps = numPixels();
|
||||
begin();
|
||||
}
|
||||
|
||||
void handleStream(uint8_t *data, size_t len)
|
||||
@@ -386,6 +388,9 @@ class NeoPattern : public Adafruit_NeoPixel
|
||||
return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Effects from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/
|
||||
*/
|
||||
void Fire(int Cooling, int Sparking)
|
||||
{
|
||||
byte heat[numPixels()];
|
||||
|
||||
@@ -25,12 +25,7 @@ using namespace std::placeholders;
|
||||
|
||||
class IlluCat : public Sprocket {
|
||||
public:
|
||||
NeoPattern* pixels;
|
||||
NeoPatternDto defaultState;
|
||||
NeoPatternDto state;
|
||||
AsyncWebServer* server;
|
||||
|
||||
NeoPixelConfig pixelConfig;
|
||||
SprocketConfig sprocketConfig;
|
||||
OtaConfig otaConfig;
|
||||
WebServerConfig webConfig;
|
||||
@@ -45,42 +40,20 @@ class IlluCat : public Sprocket {
|
||||
|
||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||
|
||||
// load config files from SPIFFS
|
||||
if(SPIFFS.begin()){
|
||||
pixelConfig.fromFile("/pixelConfig.json");
|
||||
// FIXME actualy store and load state to use as initial animation
|
||||
defaultState.fromFile("/pixelState.json");
|
||||
state = defaultState;
|
||||
}
|
||||
|
||||
// initialize services
|
||||
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
|
||||
server = new AsyncWebServer(80);
|
||||
defaultAnimation();
|
||||
|
||||
// add plugins
|
||||
// TODO how can any type of API be linked to another one?
|
||||
// TODO add HTTP OTA instead of TCP
|
||||
//addPlugin(new OtaTcpPlugin(otaConfig));
|
||||
addPlugin(new WebServerPlugin(webConfig, server));
|
||||
addPlugin(new WebConfigPlugin(server));
|
||||
addPlugin(new WebApi(server, 1));
|
||||
// TODO pixel streaming
|
||||
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
||||
|
||||
|
||||
// setup web stuff
|
||||
server->serveStatic("/pixelConfig.json", SPIFFS, "pixelConfig.json");
|
||||
server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json");
|
||||
|
||||
return Sprocket::activate(scheduler, network);
|
||||
} using Sprocket::activate;
|
||||
|
||||
virtual void scanningAnimation() {
|
||||
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
|
||||
}
|
||||
virtual void defaultAnimation() {
|
||||
pixels->RainbowCycle(pixelConfig.updateInterval);
|
||||
}
|
||||
|
||||
// TODO move to Sprocket
|
||||
virtual void dispatch( uint32_t from, String &msg ) {
|
||||
currentMessage.fromJsonString(msg);
|
||||
|
||||
@@ -4,10 +4,42 @@ PixelPlugin::PixelPlugin(NeoPixelConfig cfg, NeoPattern *neoPattern)
|
||||
{
|
||||
pixelConfig = cfg;
|
||||
pixels = neoPattern;
|
||||
pixels->begin();
|
||||
applyConfig(pixelConfig);
|
||||
defaultAnimation();
|
||||
}
|
||||
|
||||
PixelPlugin::PixelPlugin(NeoPattern *neoPattern)
|
||||
{
|
||||
pixels = neoPattern;
|
||||
loadConfigFromFile();
|
||||
applyConfig(pixelConfig);
|
||||
defaultAnimation();
|
||||
}
|
||||
|
||||
PixelPlugin::PixelPlugin()
|
||||
{
|
||||
loadConfigFromFile();
|
||||
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
|
||||
applyConfig(pixelConfig);
|
||||
defaultAnimation();
|
||||
}
|
||||
|
||||
void PixelPlugin::loadConfigFromFile(){
|
||||
if (SPIFFS.begin()){
|
||||
pixelConfig.fromFile(PIXEL_CONFIG_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
void PixelPlugin::applyConfig(NeoPixelConfig cfg)
|
||||
{
|
||||
pixels->setBrightness(pixelConfig.brightness);
|
||||
}
|
||||
|
||||
void PixelPlugin::defaultAnimation() {
|
||||
pixels->RainbowCycle(pixelConfig.updateInterval);
|
||||
animate();
|
||||
}
|
||||
|
||||
void PixelPlugin::activate(Scheduler *userScheduler, Network *network)
|
||||
{
|
||||
subscribe("pixels/colorWheel", bind(&PixelPlugin::colorWheel, this, _1));
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
#ifndef PIXEL_CONFIG_FILE
|
||||
#define PIXEL_CONFIG_FILE "/pixelConfig.json"
|
||||
#endif
|
||||
|
||||
class PixelPlugin : public Plugin {
|
||||
private:
|
||||
NeoPixelConfig pixelConfig;
|
||||
@@ -22,7 +26,13 @@ class PixelPlugin : public Plugin {
|
||||
public:
|
||||
Task animation;
|
||||
PixelPlugin(NeoPixelConfig cfg, NeoPattern* neoPattern);
|
||||
PixelPlugin(NeoPattern *neoPattern);
|
||||
PixelPlugin();
|
||||
void loadConfigFromFile();
|
||||
void applyConfig(NeoPixelConfig cfg);
|
||||
void applyConfigFromFile();
|
||||
void activate(Scheduler* userScheduler, Network* network);
|
||||
void defaultAnimation();
|
||||
void setState(String msg);
|
||||
void colorWheel(String msg);
|
||||
void setTotalSteps(String msg);
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#define MESH_DEBUG_TYPES ERROR | STARTUP | CONNECTION
|
||||
//ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE
|
||||
|
||||
#define PIXEL_CONFIG_FILE "/pixelConfig.json"
|
||||
|
||||
// OTA config
|
||||
#define OTA_PORT 8266
|
||||
#define OTA_PASSWORD ""
|
||||
|
||||
@@ -18,6 +18,7 @@ IlluCat sprocket(
|
||||
);
|
||||
|
||||
void setup() {
|
||||
sprocket.addPlugin(new PixelPlugin());
|
||||
sprocket.join(net);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ MeshCat sprocket(
|
||||
);
|
||||
|
||||
void setup() {
|
||||
sprocket.addPlugin(new PixelPlugin());
|
||||
sprocket.join(net);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user