mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-15 21:18:21 +01:00
improve pixel example
This commit is contained in:
@@ -37,6 +37,7 @@ firmware-build:
|
|||||||
- pio run -t clean
|
- pio run -t clean
|
||||||
- pio run --environment basic
|
- pio run --environment basic
|
||||||
- pio run --environment mesh
|
- pio run --environment mesh
|
||||||
|
- pio run --environment meshPixel
|
||||||
- pio run --environment meshMqttBridge
|
- pio run --environment meshMqttBridge
|
||||||
- pio run --environment ota
|
- pio run --environment ota
|
||||||
artifacts:
|
artifacts:
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"stationMode": 1,
|
"stationMode": 0,
|
||||||
"channel": 11,
|
"channel": 11,
|
||||||
"meshPort": 5555,
|
"meshPort": 5555,
|
||||||
"meshSSID": "MyMesh",
|
"meshSSID": "WibblyWobbly",
|
||||||
"meshPassword": "th3r31sn0sp00n",
|
"meshPassword": "th3r31sn0sp00n",
|
||||||
"stationSSID": "MyAP",
|
"stationSSID": "MyAP",
|
||||||
"stationPassword": "myApPassword",
|
"stationPassword": "myApPassword",
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class NeoPattern : public Adafruit_NeoPixel
|
|||||||
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type)
|
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type)
|
||||||
:Adafruit_NeoPixel(pixels, pin, type)
|
:Adafruit_NeoPixel(pixels, pin, type)
|
||||||
{
|
{
|
||||||
bind(&NeoPattern::onCompleteDefault, this, pixels);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCompleteDefault(int pixels) {
|
void onCompleteDefault(int pixels) {
|
||||||
@@ -111,10 +111,12 @@ class NeoPattern : public Adafruit_NeoPixel
|
|||||||
if (Index >= TotalSteps)
|
if (Index >= TotalSteps)
|
||||||
{
|
{
|
||||||
Index = 0;
|
Index = 0;
|
||||||
|
completed = 1;
|
||||||
if (OnComplete != NULL)
|
if (OnComplete != NULL)
|
||||||
{
|
{
|
||||||
completed = 1;
|
|
||||||
OnComplete(numPixels()); // call the comlpetion callback
|
OnComplete(numPixels()); // call the comlpetion callback
|
||||||
|
} else {
|
||||||
|
Reverse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,10 +126,12 @@ class NeoPattern : public Adafruit_NeoPixel
|
|||||||
if (Index <= 0)
|
if (Index <= 0)
|
||||||
{
|
{
|
||||||
Index = TotalSteps-1;
|
Index = TotalSteps-1;
|
||||||
|
completed = 1;
|
||||||
if (OnComplete != NULL)
|
if (OnComplete != NULL)
|
||||||
{
|
{
|
||||||
completed = 1;
|
|
||||||
OnComplete(numPixels()); // call the comlpetion callback
|
OnComplete(numPixels()); // call the comlpetion callback
|
||||||
|
} else {
|
||||||
|
Reverse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
#include <base/MeshMessage.h>
|
#include <base/MeshMessage.h>
|
||||||
|
|
||||||
class Plugin {
|
class Plugin {
|
||||||
protected:
|
|
||||||
Scheduler* scheduler;
|
|
||||||
public:
|
public:
|
||||||
virtual void activate(Scheduler*, Network*);
|
virtual void activate(Scheduler*, Network*);
|
||||||
virtual void enable(){};
|
virtual void enable(){};
|
||||||
|
|||||||
@@ -8,25 +8,17 @@
|
|||||||
#include <MeshNet.h>
|
#include <MeshNet.h>
|
||||||
#include <base/MeshMessage.h>
|
#include <base/MeshMessage.h>
|
||||||
#include <base/MeshSprocketConfig.h>
|
#include <base/MeshSprocketConfig.h>
|
||||||
#include <plugins/WebSO.h>
|
|
||||||
#include <plugins/OtaTcpPlugin.cpp>
|
|
||||||
#include <plugins/WebServerPlugin.cpp>
|
|
||||||
#include <plugins/WebConfigPlugin.cpp>
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
AsyncWebServer WEBSERVER(80);
|
|
||||||
|
|
||||||
class MeshSprocket : public Sprocket {
|
class MeshSprocket : public Sprocket {
|
||||||
public:
|
public:
|
||||||
MeshNet* net;
|
MeshNet* net;
|
||||||
|
|
||||||
MeshSprocket(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg) : Sprocket(cfg) {
|
MeshSprocket(SprocketConfig cfg) : Sprocket(cfg) {
|
||||||
addPlugin(new OtaTcpPlugin(otaCfg));
|
|
||||||
addPlugin(new WebServerPlugin(webCfg, &WEBSERVER));
|
|
||||||
addPlugin(new WebConfigPlugin(&WEBSERVER));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||||
|
|||||||
@@ -4,17 +4,24 @@
|
|||||||
#include <painlessMesh.h>
|
#include <painlessMesh.h>
|
||||||
#include <base/MeshSprocket.h>
|
#include <base/MeshSprocket.h>
|
||||||
#include <MeshNet.h>
|
#include <MeshNet.h>
|
||||||
|
#include <plugins/WebSO.h>
|
||||||
|
#include <plugins/OtaTcpPlugin.cpp>
|
||||||
|
#include <plugins/WebServerPlugin.cpp>
|
||||||
|
#include <plugins/WebConfigPlugin.cpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
AsyncWebServer WEBSERVER(80);
|
||||||
|
|
||||||
class MeshApp : public MeshSprocket {
|
class MeshApp : public MeshSprocket {
|
||||||
public:
|
public:
|
||||||
Task heartbeatTask;
|
Task heartbeatTask;
|
||||||
|
|
||||||
MeshApp(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg) : MeshSprocket(cfg, otaCfg, webCfg) {
|
MeshApp(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg) : MeshSprocket(cfg) {
|
||||||
|
addPlugin(new OtaTcpPlugin(otaCfg));
|
||||||
|
addPlugin(new WebServerPlugin(webCfg, &WEBSERVER));
|
||||||
|
addPlugin(new WebConfigPlugin(&WEBSERVER));
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||||
|
|||||||
@@ -11,34 +11,42 @@
|
|||||||
#include "NeoPattern_api_json.h"
|
#include "NeoPattern_api_json.h"
|
||||||
#include "NeoPattern_api_modes.cpp"
|
#include "NeoPattern_api_modes.cpp"
|
||||||
#include "utils_print.h"
|
#include "utils_print.h"
|
||||||
|
#include <plugins/WebSO.h>
|
||||||
|
#include <plugins/OtaTcpPlugin.cpp>
|
||||||
|
#include <plugins/WebServerPlugin.cpp>
|
||||||
|
#include <plugins/WebConfigPlugin.cpp>
|
||||||
|
#include <plugins/PixelPlugin.cpp>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
|
||||||
class MeshPixel : public MeshSprocket {
|
class MeshPixel : public MeshSprocket {
|
||||||
public:
|
public:
|
||||||
NeoPixelConfig pixelConfig;
|
NeoPixelConfig pixelConfig;
|
||||||
NeoPattern* pixels;
|
NeoPattern* pixels;
|
||||||
NeoPatternState state;
|
NeoPatternState state;
|
||||||
Task animation;
|
Task animation;
|
||||||
|
AsyncWebServer* server;
|
||||||
|
|
||||||
MeshPixel(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg, NeoPixelConfig pixelCfg) : MeshSprocket(cfg, otaCfg, webCfg) {
|
MeshPixel(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg, NeoPixelConfig pixelCfg) : MeshSprocket(cfg) {
|
||||||
pixelConfig = pixelCfg;
|
pixelConfig = pixelCfg;
|
||||||
pixels = new NeoPattern(pixelCfg.length, pixelCfg.pin, NEO_GRB + NEO_KHZ800);
|
pixels = new NeoPattern(pixelCfg.length, pixelCfg.pin, NEO_GRB + NEO_KHZ800);
|
||||||
pixels->begin();
|
server = new AsyncWebServer(80);
|
||||||
pixels->setBrightness(pixelCfg.brightness);
|
addPlugin(new OtaTcpPlugin(otaCfg));
|
||||||
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelCfg.updateInterval);
|
addPlugin(new WebServerPlugin(webCfg, server));
|
||||||
|
addPlugin(new WebConfigPlugin(server));
|
||||||
|
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
||||||
|
//pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelCfg.updateInterval);
|
||||||
|
startupAnimation();
|
||||||
|
}
|
||||||
|
void startupAnimation() {
|
||||||
|
pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||||
// call parent method that enables dispatching and plugins
|
// call parent method that enables dispatching and plugins
|
||||||
MeshSprocket::activate(scheduler, network);
|
MeshSprocket::activate(scheduler, network);
|
||||||
net->mesh.onNewConnection(bind(&MeshPixel::newConnection,this, _1));
|
net->mesh.onNewConnection(bind(&MeshPixel::newConnection,this, _1));
|
||||||
net->mesh.onChangedConnections(bind(&MeshPixel::connectionChanged,this));
|
net->mesh.onChangedConnections(bind(&MeshPixel::connectionChanged,this));
|
||||||
// pixel task
|
|
||||||
animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&MeshPixel::animate, this, pixels));
|
|
||||||
addTask(animation);
|
|
||||||
return this;
|
return this;
|
||||||
} using MeshSprocket::activate;
|
} using MeshSprocket::activate;
|
||||||
|
|
||||||
@@ -54,12 +62,11 @@ class MeshPixel : public MeshSprocket {
|
|||||||
|
|
||||||
void newConnection(uint32_t nodeId){
|
void newConnection(uint32_t nodeId){
|
||||||
PRINT_MSG(Serial, SPROCKET_TYPE, "connected to %u", nodeId);
|
PRINT_MSG(Serial, SPROCKET_TYPE, "connected to %u", nodeId);
|
||||||
pixels->ActivePattern = NONE;
|
pixels->RainbowCycle(pixelConfig.updateInterval);
|
||||||
pixels->ColorSet(pixels->Wheel(COLOR_CONNECTED));
|
|
||||||
}
|
}
|
||||||
void connectionChanged(){
|
void connectionChanged(){
|
||||||
if(!net->mesh.getNodeList().size()){
|
if(!net->mesh.getNodeList().size()){
|
||||||
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
|
startupAnimation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,10 +32,10 @@
|
|||||||
#define WEB_DEFAULT_FILE "index.html"
|
#define WEB_DEFAULT_FILE "index.html"
|
||||||
|
|
||||||
// NeoPixel
|
// NeoPixel
|
||||||
#define LED_STRIP_PIN D8
|
#define LED_STRIP_PIN D2
|
||||||
#define LED_STRIP_LENGTH 24
|
#define LED_STRIP_LENGTH 12
|
||||||
#define LED_STRIP_BRIGHTNESS 12
|
#define LED_STRIP_BRIGHTNESS 32
|
||||||
#define LED_STRIP_UPDATE_INTERVAL 100
|
#define LED_STRIP_UPDATE_INTERVAL 200
|
||||||
#define LED_STRIP_DEFAULT_COLOR 100
|
#define LED_STRIP_DEFAULT_COLOR 100
|
||||||
#define COLOR_CONNECTED LED_STRIP_DEFAULT_COLOR
|
#define COLOR_CONNECTED LED_STRIP_DEFAULT_COLOR
|
||||||
#define COLOR_NOT_CONNECTED 254
|
#define COLOR_NOT_CONNECTED 254
|
||||||
|
|||||||
@@ -49,11 +49,10 @@ class OtaTcpPlugin : public Plugin {
|
|||||||
//connectUpdateNetwork(network);
|
//connectUpdateNetwork(network);
|
||||||
net = static_cast<MeshNet*>(network);
|
net = static_cast<MeshNet*>(network);
|
||||||
// setup task
|
// setup task
|
||||||
scheduler = userScheduler;
|
|
||||||
otaTask.set(TASK_MILLISECOND * 100, TASK_FOREVER, [](){
|
otaTask.set(TASK_MILLISECOND * 100, TASK_FOREVER, [](){
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
});
|
});
|
||||||
scheduler->addTask(otaTask);
|
userScheduler->addTask(otaTask);
|
||||||
|
|
||||||
// configure OTA
|
// configure OTA
|
||||||
ArduinoOTA.setPort(config.port);
|
ArduinoOTA.setPort(config.port);
|
||||||
|
|||||||
46
src/plugins/PixelPlugin.cpp
Normal file
46
src/plugins/PixelPlugin.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#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 "NeoPattern.cpp"
|
||||||
|
#include "NeoPatternState.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){
|
||||||
|
animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this));
|
||||||
|
userScheduler->addTask(animation);
|
||||||
|
animation.enable();
|
||||||
|
Serial.println("NeoPixels activated");
|
||||||
|
}
|
||||||
|
void animate(){
|
||||||
|
pixels->Update();
|
||||||
|
}
|
||||||
|
void enable(){
|
||||||
|
animation.enable();
|
||||||
|
}
|
||||||
|
void disable(){
|
||||||
|
animation.disable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include "TaskSchedulerDeclarations.h"
|
#include "TaskSchedulerDeclarations.h"
|
||||||
#include "ArduinoOTA.h"
|
|
||||||
#include "MeshNet.h"
|
#include "MeshNet.h"
|
||||||
#include "Plugin.h"
|
#include "Plugin.h"
|
||||||
#include <plugins/WebSO.h>
|
#include <plugins/WebSO.h>
|
||||||
@@ -22,7 +21,6 @@ class WebServerPlugin : public Plugin {
|
|||||||
server = webServer;
|
server = webServer;
|
||||||
}
|
}
|
||||||
void activate(Scheduler* userScheduler, Network* network){
|
void activate(Scheduler* userScheduler, Network* network){
|
||||||
//connectUpdateNetwork(network);
|
|
||||||
net = static_cast<MeshNet*>(network);
|
net = static_cast<MeshNet*>(network);
|
||||||
server->serveStatic(config.contextPath, SPIFFS, config.docRoot).setDefaultFile(config.defaultFile);
|
server->serveStatic(config.contextPath, SPIFFS, config.docRoot).setDefaultFile(config.defaultFile);
|
||||||
// TODO add auth if configured
|
// TODO add auth if configured
|
||||||
|
|||||||
Reference in New Issue
Block a user