mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-15 01:42:22 +01:00
load pixel config from json file
This commit is contained in:
@@ -10,12 +10,26 @@
|
|||||||
// TODO move ARRAY_LENGTH to core lib
|
// TODO move ARRAY_LENGTH to core lib
|
||||||
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0])
|
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0])
|
||||||
|
|
||||||
struct NeoPixelConfig {
|
struct NeoPixelConfig : public JsonStruct {
|
||||||
int pin;
|
int pin;
|
||||||
int length;
|
int length;
|
||||||
int brightness;
|
int brightness;
|
||||||
int updateInterval;
|
int updateInterval;
|
||||||
int defaultColor;
|
int defaultColor;
|
||||||
|
void mapJsonObject(JsonObject& root) {
|
||||||
|
root["pin"] = pin;
|
||||||
|
root["length"] = length;
|
||||||
|
root["brightness"] = brightness;
|
||||||
|
root["updateInterval"] = updateInterval;
|
||||||
|
root["defaultColor"] = defaultColor;
|
||||||
|
}
|
||||||
|
void fromJsonObject(JsonObject& json) {
|
||||||
|
pin = getIntAttrFromJson(json, "pin");
|
||||||
|
length = getIntAttrFromJson(json, "length");
|
||||||
|
brightness = getIntAttrFromJson(json, "brightness");
|
||||||
|
updateInterval = getIntAttrFromJson(json, "updateInterval");
|
||||||
|
defaultColor = getIntAttrFromJson(json, "defaultColor");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NeoPatternDto : public JsonStruct {
|
struct NeoPatternDto : public JsonStruct {
|
||||||
@@ -34,6 +34,7 @@ lib_deps = ${common.lib_deps}
|
|||||||
painlessMesh
|
painlessMesh
|
||||||
ESP8266mDNS
|
ESP8266mDNS
|
||||||
ArduinoOTA
|
ArduinoOTA
|
||||||
|
ArduinoJson
|
||||||
ESP Async WebServer
|
ESP Async WebServer
|
||||||
ESPAsyncTCP
|
ESPAsyncTCP
|
||||||
Adafruit NeoPixel
|
Adafruit NeoPixel
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "NeoPattern.cpp"
|
#include "NeoPattern.cpp"
|
||||||
#include "NeoPatternDto.cpp"
|
#include "NeoPatternDto.h"
|
||||||
#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"
|
||||||
@@ -22,22 +22,29 @@ using namespace std::placeholders;
|
|||||||
|
|
||||||
class IlluCat : public MeshSprocket {
|
class IlluCat : public MeshSprocket {
|
||||||
public:
|
public:
|
||||||
NeoPixelConfig pixelConfig;
|
|
||||||
NeoPattern* pixels;
|
NeoPattern* pixels;
|
||||||
NeoPatternDto state;
|
NeoPatternDto state;
|
||||||
Task animation;
|
Task animation;
|
||||||
AsyncWebServer* server;
|
AsyncWebServer* server;
|
||||||
|
|
||||||
|
NeoPixelConfig pixelConfig;
|
||||||
|
SprocketConfig sprocketConfig;
|
||||||
|
OtaConfig otaConfig;
|
||||||
|
WebServerConfig webConfig;
|
||||||
|
|
||||||
IlluCat(SprocketConfig cfg, OtaConfig otaCfg, WebServerConfig webCfg, NeoPixelConfig pixelCfg) : MeshSprocket(cfg) {
|
IlluCat(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);
|
|
||||||
server = new AsyncWebServer(80);
|
|
||||||
addPlugin(new OtaTcpPlugin(otaCfg));
|
|
||||||
addPlugin(new WebServerPlugin(webCfg, server));
|
|
||||||
addPlugin(new WebConfigPlugin(server));
|
|
||||||
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
|
||||||
|
|
||||||
scanningAnimation();
|
sprocketConfig = cfg;
|
||||||
|
otaConfig = otaCfg;
|
||||||
|
webConfig = webCfg;
|
||||||
|
|
||||||
|
pixelConfig.pin = 4;
|
||||||
|
pixelConfig.length = 8;
|
||||||
|
pixelConfig.brightness = 32;
|
||||||
|
pixelConfig.updateInterval = 100;
|
||||||
|
pixelConfig.defaultColor = 100;
|
||||||
|
|
||||||
}
|
}
|
||||||
void scanningAnimation() {
|
void scanningAnimation() {
|
||||||
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
|
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
|
||||||
@@ -48,19 +55,27 @@ class IlluCat : public MeshSprocket {
|
|||||||
}
|
}
|
||||||
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);
|
net = static_cast<MeshNet*>(network);
|
||||||
net->mesh.onNewConnection(bind(&IlluCat::newConnection,this, _1));
|
net->mesh.onNewConnection(bind(&IlluCat::newConnection,this, _1));
|
||||||
net->mesh.onChangedConnections(bind(&IlluCat::connectionChanged,this));
|
net->mesh.onChangedConnections(bind(&IlluCat::connectionChanged,this));
|
||||||
|
|
||||||
|
if(SPIFFS.begin()){
|
||||||
|
pixelConfig.fromFile("/config.json");
|
||||||
|
}
|
||||||
|
pixels = new NeoPattern(pixelConfig.length, pixelConfig.pin, NEO_GRB + NEO_KHZ800);
|
||||||
|
server = new AsyncWebServer(80);
|
||||||
|
addPlugin(new OtaTcpPlugin(otaConfig));
|
||||||
|
addPlugin(new WebServerPlugin(webConfig, server));
|
||||||
|
addPlugin(new WebConfigPlugin(server));
|
||||||
|
addPlugin(new PixelPlugin(pixelConfig, pixels));
|
||||||
|
|
||||||
|
scanningAnimation();
|
||||||
|
|
||||||
// FIXME OnDisable is triggered after last scan, aprx. 10 sec
|
// FIXME OnDisable is triggered after last scan, aprx. 10 sec
|
||||||
net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
|
net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
|
||||||
return this;
|
return MeshSprocket::activate(scheduler, network);;
|
||||||
} using MeshSprocket::activate;
|
} using MeshSprocket::activate;
|
||||||
|
|
||||||
void animate(){
|
|
||||||
pixels->Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void onMessage( uint32_t from, String &msg ) {
|
void onMessage( uint32_t from, String &msg ) {
|
||||||
PRINT_MSG(Serial, SPROCKET_TYPE, "msg from %u = %s\n", from, msg.c_str());
|
PRINT_MSG(Serial, SPROCKET_TYPE, "msg from %u = %s\n", from, msg.c_str());
|
||||||
state.fromJsonString(msg);
|
state.fromJsonString(msg);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "TaskSchedulerDeclarations.h"
|
#include "TaskSchedulerDeclarations.h"
|
||||||
#include "MeshNet.h"
|
#include "MeshNet.h"
|
||||||
#include "Plugin.h"
|
#include "Plugin.h"
|
||||||
|
#include "NeoPatternDto.h"
|
||||||
#include "NeoPattern.cpp"
|
#include "NeoPattern.cpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ MeshNet net({
|
|||||||
IlluCat sprocket(
|
IlluCat sprocket(
|
||||||
{ STARTUP_DELAY, SERIAL_BAUD_RATE },
|
{ STARTUP_DELAY, SERIAL_BAUD_RATE },
|
||||||
{ OTA_PORT, OTA_PASSWORD },
|
{ OTA_PORT, OTA_PASSWORD },
|
||||||
{ WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE },
|
{ 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 }
|
{ LED_STRIP_PIN, LED_STRIP_LENGTH, LED_STRIP_BRIGHTNESS, LED_STRIP_UPDATE_INTERVAL, LED_STRIP_DEFAULT_COLOR } */
|
||||||
);
|
);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|||||||
Reference in New Issue
Block a user