feat: services (#2)

This commit is contained in:
2025-09-13 13:45:24 +02:00
parent fe045804cb
commit 12caeb0be6
33 changed files with 3293 additions and 785 deletions

View File

@@ -0,0 +1,71 @@
#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);
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();
}