71 lines
1.7 KiB
C++
71 lines
1.7 KiB
C++
#include <Arduino.h>
|
|
#include <functional>
|
|
#include "Globals.h"
|
|
#include "NodeContext.h"
|
|
#include "NetworkManager.h"
|
|
#include "ClusterManager.h"
|
|
#include "ApiServer.h"
|
|
#include "TaskManager.h"
|
|
|
|
// Services
|
|
#include "services/NodeService.h"
|
|
#include "services/NetworkService.h"
|
|
#include "services/ClusterService.h"
|
|
#include "services/TaskService.h"
|
|
#include "NeoPatternService.h"
|
|
|
|
#ifndef LED_STRIP_PIN
|
|
#define LED_STRIP_PIN 2
|
|
#endif
|
|
|
|
#ifndef LED_STRIP_LENGTH
|
|
#define LED_STRIP_LENGTH 8
|
|
#endif
|
|
|
|
#ifndef LED_STRIP_TYPE
|
|
#define LED_STRIP_TYPE (NEO_GRB + NEO_KHZ800)
|
|
#endif
|
|
|
|
NodeContext ctx({
|
|
{"app", "neopattern"},
|
|
{"device", "light"},
|
|
{"pixels", String(LED_STRIP_LENGTH)},
|
|
{"pin", String(LED_STRIP_PIN)}
|
|
});
|
|
NetworkManager network(ctx);
|
|
TaskManager taskManager(ctx);
|
|
ClusterManager cluster(ctx, taskManager);
|
|
ApiServer apiServer(ctx, taskManager, ctx.config.api_server_port);
|
|
|
|
// Create services
|
|
NodeService nodeService(ctx, apiServer);
|
|
NetworkService networkService(network);
|
|
ClusterService clusterService(ctx);
|
|
TaskService taskService(taskManager);
|
|
NeoPatternService neoPatternService(taskManager, LED_STRIP_LENGTH, LED_STRIP_PIN, LED_STRIP_TYPE);
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
|
|
// Setup WiFi first
|
|
network.setupWiFi();
|
|
|
|
// Initialize and start all tasks
|
|
taskManager.initialize();
|
|
|
|
// Register services and start API server
|
|
apiServer.addService(nodeService);
|
|
apiServer.addService(networkService);
|
|
apiServer.addService(clusterService);
|
|
apiServer.addService(taskService);
|
|
apiServer.addService(neoPatternService);
|
|
apiServer.begin();
|
|
|
|
// Print initial task status
|
|
taskManager.printTaskStatus();
|
|
}
|
|
|
|
void loop() {
|
|
taskManager.execute();
|
|
yield();
|
|
} |