feat: task manager

This commit is contained in:
2025-08-21 21:52:25 +02:00
parent 953768b681
commit f80b594d21
8 changed files with 495 additions and 35 deletions

View File

@@ -0,0 +1,68 @@
/*
* Task Management Example
*
* This example demonstrates how to use the TaskManager to add custom tasks
* to the SPORE system. The TaskManager provides a clean interface for
* registering, controlling, and monitoring system tasks.
*/
#include <Arduino.h>
#include "TaskManager.h"
#include "NodeContext.h"
// Example custom task functions
void customTask1() {
Serial.println("[CustomTask1] Executing custom task 1");
// Add your custom logic here
}
void customTask2() {
Serial.println("[CustomTask2] Executing custom task 2");
// Add your custom logic here
}
void periodicMaintenance() {
Serial.println("[Maintenance] Running periodic maintenance");
// Add maintenance logic here
}
void setup() {
Serial.begin(115200);
Serial.println("Task Management Example");
// Create context and task manager
NodeContext ctx;
TaskManager taskManager(ctx);
// Register custom tasks with different intervals
taskManager.registerTask("custom_task_1", 5000, customTask1); // Every 5 seconds
taskManager.registerTask("custom_task_2", 10000, customTask2); // Every 10 seconds
taskManager.registerTask("maintenance", 30000, periodicMaintenance); // Every 30 seconds
// Initialize and start all tasks
taskManager.initialize();
// Print initial task status
taskManager.printTaskStatus();
// Example: Disable a task temporarily
taskManager.disableTask("custom_task_2");
Serial.println("Disabled custom_task_2");
// Example: Change task interval
taskManager.setTaskInterval("custom_task_1", 2000); // Change to 2 seconds
Serial.println("Changed custom_task_1 interval to 2 seconds");
// Re-enable the disabled task
taskManager.enableTask("custom_task_2");
Serial.println("Re-enabled custom_task_2");
// Print updated status
taskManager.printTaskStatus();
}
void loop() {
// The TaskManager handles all task execution
// No need to call individual task functions
yield();
}