feat: implement Spore framework class as main orchestration layer

- Add Spore class as unified interface for all core framework functionality
- Implement setup() and begin() methods for flexible initialization pattern
- Add service registration with addService() for both raw and smart pointers
- Provide accessor methods for core components (getTaskManager, getContext, etc.)
- Automatically include core services (Node, Network, Cluster, Task)
- Update all examples to use simplified Spore framework approach
- Fix circular dependency issues in include structure
- Remove setHostname and setApiPort configuration methods
- Add comprehensive documentation and usage examples

The Spore class encapsulates all core functionality from the base example
and provides a clean, unified API for the entire framework. Examples now
use just spore.setup() -> add services -> spore.begin() -> spore.loop().
This commit is contained in:
2025-09-13 21:17:54 +02:00
parent 72b559e047
commit bf17684dc6
12 changed files with 356 additions and 184 deletions

View File

@@ -1,17 +1,5 @@
#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 "Spore.h"
#include "NeoPatternService.h"
#ifndef LED_STRIP_PIN
@@ -26,46 +14,32 @@
#define LED_STRIP_TYPE (NEO_GRB + NEO_KHZ800)
#endif
NodeContext ctx({
// Create Spore instance with custom labels
Spore spore({
{"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);
// Create custom service
NeoPatternService* neoPatternService = nullptr;
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();
// Initialize the Spore framework
spore.setup();
// Create and add custom service
neoPatternService = new NeoPatternService(spore.getTaskManager(), LED_STRIP_LENGTH, LED_STRIP_PIN, LED_STRIP_TYPE);
spore.addService(neoPatternService);
// Start the API server and complete initialization
spore.begin();
Serial.println("[Main] NeoPattern service registered and ready!");
}
void loop() {
taskManager.execute();
yield();
// Run the Spore framework loop
spore.loop();
}