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",
|
"text": "None",
|
||||||
"value": ["#000000", "#000000"]
|
"value": ["#000000", "#000000"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"text": "Stadler",
|
||||||
|
"value": ["#0B3F75", "#0B3F75"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"text": "Blu",
|
"text": "Blu",
|
||||||
"value": ["#00416A", "#E4E5E6"]
|
"value": ["#00416A", "#E4E5E6"]
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ class NeoPattern : public Adafruit_NeoPixel
|
|||||||
frameBuffer = (uint8_t *)malloc(768);
|
frameBuffer = (uint8_t *)malloc(768);
|
||||||
OnComplete = callback;
|
OnComplete = callback;
|
||||||
TotalSteps = numPixels();
|
TotalSteps = numPixels();
|
||||||
|
begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type)
|
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type)
|
||||||
@@ -73,6 +74,7 @@ class NeoPattern : public Adafruit_NeoPixel
|
|||||||
{
|
{
|
||||||
frameBuffer = (uint8_t *)malloc(768);
|
frameBuffer = (uint8_t *)malloc(768);
|
||||||
TotalSteps = numPixels();
|
TotalSteps = numPixels();
|
||||||
|
begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleStream(uint8_t *data, size_t len)
|
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);
|
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)
|
void Fire(int Cooling, int Sparking)
|
||||||
{
|
{
|
||||||
byte heat[numPixels()];
|
byte heat[numPixels()];
|
||||||
|
|||||||
@@ -25,12 +25,7 @@ using namespace std::placeholders;
|
|||||||
|
|
||||||
class IlluCat : public Sprocket {
|
class IlluCat : public Sprocket {
|
||||||
public:
|
public:
|
||||||
NeoPattern* pixels;
|
|
||||||
NeoPatternDto defaultState;
|
|
||||||
NeoPatternDto state;
|
|
||||||
AsyncWebServer* server;
|
AsyncWebServer* server;
|
||||||
|
|
||||||
NeoPixelConfig pixelConfig;
|
|
||||||
SprocketConfig sprocketConfig;
|
SprocketConfig sprocketConfig;
|
||||||
OtaConfig otaConfig;
|
OtaConfig otaConfig;
|
||||||
WebServerConfig webConfig;
|
WebServerConfig webConfig;
|
||||||
@@ -45,42 +40,20 @@ class IlluCat : public Sprocket {
|
|||||||
|
|
||||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
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);
|
server = new AsyncWebServer(80);
|
||||||
defaultAnimation();
|
|
||||||
|
|
||||||
// add plugins
|
|
||||||
// TODO how can any type of API be linked to another one?
|
// TODO how can any type of API be linked to another one?
|
||||||
// TODO add HTTP OTA instead of TCP
|
// TODO add HTTP OTA instead of TCP
|
||||||
//addPlugin(new OtaTcpPlugin(otaConfig));
|
//addPlugin(new OtaTcpPlugin(otaConfig));
|
||||||
addPlugin(new WebServerPlugin(webConfig, server));
|
addPlugin(new WebServerPlugin(webConfig, server));
|
||||||
addPlugin(new WebConfigPlugin(server));
|
addPlugin(new WebConfigPlugin(server));
|
||||||
addPlugin(new WebApi(server, 1));
|
addPlugin(new WebApi(server, 1));
|
||||||
// TODO pixel streaming
|
|
||||||
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
|
||||||
|
|
||||||
// setup web stuff
|
// setup web stuff
|
||||||
server->serveStatic("/pixelConfig.json", SPIFFS, "pixelConfig.json");
|
server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json");
|
||||||
|
|
||||||
return Sprocket::activate(scheduler, network);
|
return Sprocket::activate(scheduler, network);
|
||||||
} using Sprocket::activate;
|
} 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
|
// TODO move to Sprocket
|
||||||
virtual void dispatch( uint32_t from, String &msg ) {
|
virtual void dispatch( uint32_t from, String &msg ) {
|
||||||
currentMessage.fromJsonString(msg);
|
currentMessage.fromJsonString(msg);
|
||||||
|
|||||||
@@ -4,10 +4,42 @@ PixelPlugin::PixelPlugin(NeoPixelConfig cfg, NeoPattern *neoPattern)
|
|||||||
{
|
{
|
||||||
pixelConfig = cfg;
|
pixelConfig = cfg;
|
||||||
pixels = neoPattern;
|
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);
|
pixels->setBrightness(pixelConfig.brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PixelPlugin::defaultAnimation() {
|
||||||
|
pixels->RainbowCycle(pixelConfig.updateInterval);
|
||||||
|
animate();
|
||||||
|
}
|
||||||
|
|
||||||
void PixelPlugin::activate(Scheduler *userScheduler, Network *network)
|
void PixelPlugin::activate(Scheduler *userScheduler, Network *network)
|
||||||
{
|
{
|
||||||
subscribe("pixels/colorWheel", bind(&PixelPlugin::colorWheel, this, _1));
|
subscribe("pixels/colorWheel", bind(&PixelPlugin::colorWheel, this, _1));
|
||||||
|
|||||||
@@ -14,6 +14,10 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
#ifndef PIXEL_CONFIG_FILE
|
||||||
|
#define PIXEL_CONFIG_FILE "/pixelConfig.json"
|
||||||
|
#endif
|
||||||
|
|
||||||
class PixelPlugin : public Plugin {
|
class PixelPlugin : public Plugin {
|
||||||
private:
|
private:
|
||||||
NeoPixelConfig pixelConfig;
|
NeoPixelConfig pixelConfig;
|
||||||
@@ -22,7 +26,13 @@ class PixelPlugin : public Plugin {
|
|||||||
public:
|
public:
|
||||||
Task animation;
|
Task animation;
|
||||||
PixelPlugin(NeoPixelConfig cfg, NeoPattern* neoPattern);
|
PixelPlugin(NeoPixelConfig cfg, NeoPattern* neoPattern);
|
||||||
|
PixelPlugin(NeoPattern *neoPattern);
|
||||||
|
PixelPlugin();
|
||||||
|
void loadConfigFromFile();
|
||||||
|
void applyConfig(NeoPixelConfig cfg);
|
||||||
|
void applyConfigFromFile();
|
||||||
void activate(Scheduler* userScheduler, Network* network);
|
void activate(Scheduler* userScheduler, Network* network);
|
||||||
|
void defaultAnimation();
|
||||||
void setState(String msg);
|
void setState(String msg);
|
||||||
void colorWheel(String msg);
|
void colorWheel(String msg);
|
||||||
void setTotalSteps(String msg);
|
void setTotalSteps(String msg);
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
#define MESH_DEBUG_TYPES ERROR | STARTUP | CONNECTION
|
#define MESH_DEBUG_TYPES ERROR | STARTUP | CONNECTION
|
||||||
//ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE
|
//ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE
|
||||||
|
|
||||||
|
#define PIXEL_CONFIG_FILE "/pixelConfig.json"
|
||||||
|
|
||||||
// OTA config
|
// OTA config
|
||||||
#define OTA_PORT 8266
|
#define OTA_PORT 8266
|
||||||
#define OTA_PASSWORD ""
|
#define OTA_PASSWORD ""
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ IlluCat sprocket(
|
|||||||
);
|
);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
sprocket.addPlugin(new PixelPlugin());
|
||||||
sprocket.join(net);
|
sprocket.join(net);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ MeshCat sprocket(
|
|||||||
);
|
);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
sprocket.addPlugin(new PixelPlugin());
|
||||||
sprocket.join(net);
|
sprocket.join(net);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user