mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-16 10:04:30 +01:00
basic led code
This commit is contained in:
84
src/IlluCat.h
Normal file
84
src/IlluCat.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#ifndef __MESH_APP__
|
||||
#define __MESH_APP__
|
||||
|
||||
#include <painlessMesh.h>
|
||||
#include <base/MeshSprocket.h>
|
||||
#include <MeshNet.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "NeoPattern.cpp"
|
||||
#include "NeoPatternDto.cpp"
|
||||
#include "NeoPattern_api_json.h"
|
||||
#include "NeoPattern_api_modes.cpp"
|
||||
#include "utils_print.h"
|
||||
#include <plugins/WebSO.h>
|
||||
#include <plugins/OtaTcpPlugin.cpp>
|
||||
#include <plugins/WebServerPlugin.cpp>
|
||||
#include <plugins/WebConfigPlugin.cpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
class IlluCat : public MeshSprocket {
|
||||
public:
|
||||
NeoPixelConfig pixelConfig;
|
||||
NeoPattern* pixels;
|
||||
NeoPatternDto state;
|
||||
Task animation;
|
||||
AsyncWebServer* server;
|
||||
|
||||
IlluCat(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg, NeoPixelConfig pixelCfg) : MeshSprocket(cfg) {
|
||||
pixelConfig = pixelCfg;
|
||||
pixels = new NeoPattern(pixelCfg.length, pixelCfg.pin, NEO_GRB + NEO_KHZ800);
|
||||
server = new AsyncWebServer(80);
|
||||
addPlugin(new OtaTcpPlugin(otaCfg));
|
||||
addPlugin(new WebServerPlugin(webCfg, server));
|
||||
addPlugin(new WebConfigPlugin(server));
|
||||
|
||||
pixels->begin();
|
||||
pixels->setBrightness(pixelConfig.brightness);
|
||||
animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&IlluCat::animate, this));
|
||||
addTask(animation);
|
||||
scanningAnimation();
|
||||
}
|
||||
void scanningAnimation() {
|
||||
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
|
||||
//pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
|
||||
}
|
||||
void defaultAnimation() {
|
||||
pixels->RainbowCycle(pixelConfig.updateInterval);
|
||||
}
|
||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||
// call parent method that enables dispatching and plugins
|
||||
MeshSprocket::activate(scheduler, network);
|
||||
net->mesh.onNewConnection(bind(&IlluCat::newConnection,this, _1));
|
||||
net->mesh.onChangedConnections(bind(&IlluCat::connectionChanged,this));
|
||||
|
||||
// FIXME OnDisable is triggered after last scan, aprx. 10 sec
|
||||
net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
|
||||
return this;
|
||||
} using MeshSprocket::activate;
|
||||
|
||||
void animate(){
|
||||
pixels->Update();
|
||||
}
|
||||
|
||||
void onMessage( uint32_t from, String &msg ) {
|
||||
PRINT_MSG(Serial, SPROCKET_TYPE, "msg from %u = %s\n", from, msg.c_str());
|
||||
state.fromJsonString(msg);
|
||||
PIXEL_FNCS[state.mode](pixels, state.valueStr);
|
||||
}
|
||||
|
||||
void newConnection(uint32_t nodeId){
|
||||
PRINT_MSG(Serial, SPROCKET_TYPE, "connected to %u", nodeId);
|
||||
defaultAnimation();
|
||||
}
|
||||
void connectionChanged(){
|
||||
PRINT_MSG(Serial, SPROCKET_TYPE, "connection changed");
|
||||
if(!net->mesh.getNodeList().size()){
|
||||
defaultAnimation();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
43
src/config.h
Normal file
43
src/config.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef __MESH_CONFIG__
|
||||
#define __MESH_CONFIG__
|
||||
|
||||
// Scheduler config
|
||||
#define _TASK_SLEEP_ON_IDLE_RUN
|
||||
#define _TASK_STD_FUNCTION
|
||||
|
||||
// Chip config
|
||||
#define SPROCKET_TYPE "ILLUCAT"
|
||||
#define SERIAL_BAUD_RATE 115200
|
||||
#define STARTUP_DELAY 3000
|
||||
|
||||
// Mesh config
|
||||
#define SPROCKET_MODE 0
|
||||
#define WIFI_CHANNEL 11
|
||||
#define MESH_PORT 5555
|
||||
#define MESH_PREFIX "illucat-mesh"
|
||||
#define MESH_PASSWORD "th3r31sn0sp00n"
|
||||
#define STATION_SSID "MyAP"
|
||||
#define STATION_PASSWORD "th3r31sn0sp00n"
|
||||
#define HOSTNAME "illucat"
|
||||
#define MESH_DEBUG_TYPES ERROR | STARTUP | CONNECTION
|
||||
//ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE
|
||||
|
||||
// OTA config
|
||||
#define OTA_PORT 8266
|
||||
#define OTA_PASSWORD ""
|
||||
|
||||
// WebServer
|
||||
#define WEB_CONTEXT_PATH "/"
|
||||
#define WEB_DOC_ROOT "/www"
|
||||
#define WEB_DEFAULT_FILE "index.html"
|
||||
|
||||
// NeoPixel
|
||||
#define LED_STRIP_PIN D2
|
||||
#define LED_STRIP_LENGTH 8
|
||||
#define LED_STRIP_BRIGHTNESS 48
|
||||
#define LED_STRIP_UPDATE_INTERVAL 200
|
||||
#define LED_STRIP_DEFAULT_COLOR 100
|
||||
#define COLOR_CONNECTED LED_STRIP_DEFAULT_COLOR
|
||||
#define COLOR_NOT_CONNECTED 255
|
||||
|
||||
#endif
|
||||
25
src/main.cpp
Normal file
25
src/main.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "config.h"
|
||||
#include "MeshNet.h"
|
||||
#include "IlluCat.h"
|
||||
|
||||
MeshNet net({
|
||||
SPROCKET_MODE, WIFI_CHANNEL,
|
||||
MESH_PORT, MESH_PREFIX, MESH_PASSWORD,
|
||||
STATION_SSID, STATION_PASSWORD, HOSTNAME,
|
||||
MESH_DEBUG_TYPES
|
||||
});
|
||||
IlluCat sprocket(
|
||||
{ STARTUP_DELAY, SERIAL_BAUD_RATE },
|
||||
{ OTA_PORT, OTA_PASSWORD },
|
||||
{ WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE },
|
||||
{ LED_STRIP_PIN, LED_STRIP_LENGTH, LED_STRIP_BRIGHTNESS, LED_STRIP_UPDATE_INTERVAL, LED_STRIP_DEFAULT_COLOR }
|
||||
);
|
||||
|
||||
void setup() {
|
||||
sprocket.join(net);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
sprocket.loop();
|
||||
yield();
|
||||
}
|
||||
Reference in New Issue
Block a user