refactor: reorganize project structure with modern C++ namespace organization
- Restructure include/ and src/ directories with logical grouping - Move core components to spore/core/ (NodeContext, NetworkManager, TaskManager, ClusterManager, ApiServer) - Move services to spore/services/ (NodeService, NetworkService, ClusterService, TaskService) - Move types to spore/types/ (NodeInfo, ApiTypes, Config) - Move internal components to spore/internal/ (Globals) - Update all #include statements to use new namespace paths - Update platformio.ini build filters for all environments - Update all example files to use new include paths - Maintain backward compatibility for public API - Improve code organization, maintainability, and scalability This reorganization follows modern C++ project structure patterns and provides clear separation between public API, internal implementation, and utilities. All examples compile successfully with the new structure.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
#include "Spore.h"
|
||||
#include "spore/Spore.h"
|
||||
|
||||
// Create Spore instance with custom labels
|
||||
Spore spore({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "NeoPatternService.h"
|
||||
#include "ApiServer.h"
|
||||
#include "spore/core/ApiServer.h"
|
||||
|
||||
NeoPatternService::NeoPatternService(TaskManager& taskMgr, uint16_t numPixels, uint8_t pin, uint8_t type)
|
||||
: taskManager(taskMgr),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "services/Service.h"
|
||||
#include "TaskManager.h"
|
||||
#include "spore/Service.h"
|
||||
#include "spore/core/TaskManager.h"
|
||||
#include "NeoPattern.cpp"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
#include "Spore.h"
|
||||
#include "spore/Spore.h"
|
||||
#include "NeoPatternService.h"
|
||||
|
||||
#ifndef LED_STRIP_PIN
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "NeoPixelService.h"
|
||||
#include "ApiServer.h"
|
||||
#include "spore/core/ApiServer.h"
|
||||
|
||||
// Wheel helper: map 0-255 to RGB rainbow
|
||||
static uint32_t colorWheel(Adafruit_NeoPixel& strip, uint8_t pos) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "services/Service.h"
|
||||
#include "TaskManager.h"
|
||||
#include "spore/Service.h"
|
||||
#include "spore/core/TaskManager.h"
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
#include "Spore.h"
|
||||
#include "spore/Spore.h"
|
||||
#include "NeoPixelService.h"
|
||||
|
||||
#ifndef NEOPIXEL_PIN
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "RelayService.h"
|
||||
#include "ApiServer.h"
|
||||
#include "spore/core/ApiServer.h"
|
||||
|
||||
RelayService::RelayService(TaskManager& taskMgr, int pin)
|
||||
: taskManager(taskMgr), relayPin(pin), relayOn(false) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "services/Service.h"
|
||||
#include "TaskManager.h"
|
||||
#include "spore/Service.h"
|
||||
#include "spore/core/TaskManager.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
class RelayService : public Service {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
#include "Spore.h"
|
||||
#include "spore/Spore.h"
|
||||
#include "RelayService.h"
|
||||
|
||||
// Choose a default relay pin. For ESP-01 this is GPIO0. Adjust as needed for your board.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "ApiServer.h"
|
||||
#include "spore/core/ApiServer.h"
|
||||
|
||||
class Service {
|
||||
public:
|
||||
@@ -4,12 +4,12 @@
|
||||
#include <memory>
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
#include "NodeContext.h"
|
||||
#include "NetworkManager.h"
|
||||
#include "ClusterManager.h"
|
||||
#include "ApiServer.h"
|
||||
#include "TaskManager.h"
|
||||
#include "services/Service.h"
|
||||
#include "core/NodeContext.h"
|
||||
#include "core/NetworkManager.h"
|
||||
#include "core/ClusterManager.h"
|
||||
#include "core/ApiServer.h"
|
||||
#include "core/TaskManager.h"
|
||||
#include "Service.h"
|
||||
|
||||
class Spore {
|
||||
public:
|
||||
@@ -7,10 +7,10 @@
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
#include "NodeContext.h"
|
||||
#include "NodeInfo.h"
|
||||
#include "TaskManager.h"
|
||||
#include "ApiTypes.h"
|
||||
#include "spore/core/NodeContext.h"
|
||||
#include "spore/types/NodeInfo.h"
|
||||
#include "spore/core/TaskManager.h"
|
||||
#include "spore/types/ApiTypes.h"
|
||||
|
||||
class Service; // Forward declaration
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "NodeContext.h"
|
||||
#include "NodeInfo.h"
|
||||
#include "TaskManager.h"
|
||||
#include "spore/core/NodeContext.h"
|
||||
#include "spore/types/NodeInfo.h"
|
||||
#include "spore/core/TaskManager.h"
|
||||
#include <Arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ArduinoJson.h>
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "NodeContext.h"
|
||||
#include "spore/core/NodeContext.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <vector>
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
#include <WiFiUdp.h>
|
||||
#include <map>
|
||||
#include "NodeInfo.h"
|
||||
#include "spore/types/NodeInfo.h"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <initializer_list>
|
||||
#include "Config.h"
|
||||
#include "ApiTypes.h"
|
||||
#include "spore/types/Config.h"
|
||||
#include "spore/types/ApiTypes.h"
|
||||
|
||||
class NodeContext {
|
||||
public:
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "NodeContext.h"
|
||||
#include "spore/core/NodeContext.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
// Define our own callback type to avoid conflict with TaskScheduler
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "services/Service.h"
|
||||
#include "NodeContext.h"
|
||||
#include "spore/Service.h"
|
||||
#include "spore/core/NodeContext.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
class ClusterService : public Service {
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "services/Service.h"
|
||||
#include "NetworkManager.h"
|
||||
#include "NodeContext.h"
|
||||
#include "spore/Service.h"
|
||||
#include "spore/core/NetworkManager.h"
|
||||
#include "spore/core/NodeContext.h"
|
||||
|
||||
class NetworkService : public Service {
|
||||
public:
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "services/Service.h"
|
||||
#include "NodeContext.h"
|
||||
#include "spore/Service.h"
|
||||
#include "spore/core/NodeContext.h"
|
||||
#include <ArduinoJson.h>
|
||||
#include <Updater.h>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "services/Service.h"
|
||||
#include "TaskManager.h"
|
||||
#include "spore/Service.h"
|
||||
#include "spore/core/TaskManager.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
class TaskService : public Service {
|
||||
@@ -30,9 +30,11 @@ board_build.flash_size = 1M
|
||||
lib_deps = ${common.lib_deps}
|
||||
build_src_filter =
|
||||
+<examples/base/*.cpp>
|
||||
+<src/*.c>
|
||||
+<src/*.cpp>
|
||||
+<src/services/*.cpp>
|
||||
+<src/spore/*.cpp>
|
||||
+<src/spore/core/*.cpp>
|
||||
+<src/spore/services/*.cpp>
|
||||
+<src/spore/types/*.cpp>
|
||||
+<src/internal/*.cpp>
|
||||
|
||||
[env:d1_mini]
|
||||
platform = platformio/espressif8266@^4.2.1
|
||||
@@ -45,9 +47,11 @@ board_build.flash_size = 4M
|
||||
lib_deps = ${common.lib_deps}
|
||||
build_src_filter =
|
||||
+<examples/base/*.cpp>
|
||||
+<src/*.c>
|
||||
+<src/*.cpp>
|
||||
+<src/services/*.cpp>
|
||||
+<src/spore/*.cpp>
|
||||
+<src/spore/core/*.cpp>
|
||||
+<src/spore/services/*.cpp>
|
||||
+<src/spore/types/*.cpp>
|
||||
+<src/internal/*.cpp>
|
||||
|
||||
[env:esp01_1m_relay]
|
||||
platform = platformio/espressif8266@^4.2.1
|
||||
@@ -61,9 +65,11 @@ board_build.flash_size = 1M
|
||||
lib_deps = ${common.lib_deps}
|
||||
build_src_filter =
|
||||
+<examples/relay/*.cpp>
|
||||
+<src/*.c>
|
||||
+<src/*.cpp>
|
||||
+<src/services/*.cpp>
|
||||
+<src/spore/*.cpp>
|
||||
+<src/spore/core/*.cpp>
|
||||
+<src/spore/services/*.cpp>
|
||||
+<src/spore/types/*.cpp>
|
||||
+<src/internal/*.cpp>
|
||||
|
||||
[env:esp01_1m_neopixel]
|
||||
platform = platformio/espressif8266@^4.2.1
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "Spore.h"
|
||||
#include "services/NodeService.h"
|
||||
#include "services/NetworkService.h"
|
||||
#include "services/ClusterService.h"
|
||||
#include "services/TaskService.h"
|
||||
#include "spore/Spore.h"
|
||||
#include "spore/services/NodeService.h"
|
||||
#include "spore/services/NetworkService.h"
|
||||
#include "spore/services/ClusterService.h"
|
||||
#include "spore/services/TaskService.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
Spore::Spore() : ctx(), network(ctx), taskManager(ctx), cluster(ctx, taskManager),
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "ApiServer.h"
|
||||
#include "services/Service.h"
|
||||
#include "spore/core/ApiServer.h"
|
||||
#include "spore/Service.h"
|
||||
#include <algorithm>
|
||||
|
||||
const char* ApiServer::methodToStr(int method) {
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "ClusterManager.h"
|
||||
#include "Globals.h"
|
||||
#include "spore/core/ClusterManager.h"
|
||||
#include "spore/internal/Globals.h"
|
||||
|
||||
ClusterManager::ClusterManager(NodeContext& ctx, TaskManager& taskMgr) : ctx(ctx), taskManager(taskMgr) {
|
||||
// Register callback for node_discovered event
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "NetworkManager.h"
|
||||
#include "spore/core/NetworkManager.h"
|
||||
|
||||
// SSID and password are now configured via Config class
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "NodeContext.h"
|
||||
#include "spore/core/NodeContext.h"
|
||||
|
||||
NodeContext::NodeContext() {
|
||||
udp = new WiFiUDP();
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "TaskManager.h"
|
||||
#include "spore/core/TaskManager.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
TaskManager::TaskManager(NodeContext& ctx) : ctx(ctx) {}
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "services/ClusterService.h"
|
||||
#include "ApiServer.h"
|
||||
#include "spore/services/ClusterService.h"
|
||||
#include "spore/core/ApiServer.h"
|
||||
|
||||
ClusterService::ClusterService(NodeContext& ctx) : ctx(ctx) {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "services/NetworkService.h"
|
||||
#include "spore/services/NetworkService.h"
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
NetworkService::NetworkService(NetworkManager& networkManager)
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "services/NodeService.h"
|
||||
#include "ApiServer.h"
|
||||
#include "spore/services/NodeService.h"
|
||||
#include "spore/core/ApiServer.h"
|
||||
|
||||
NodeService::NodeService(NodeContext& ctx, ApiServer& apiServer) : ctx(ctx), apiServer(apiServer) {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "services/TaskService.h"
|
||||
#include "ApiServer.h"
|
||||
#include "spore/services/TaskService.h"
|
||||
#include "spore/core/ApiServer.h"
|
||||
#include <algorithm>
|
||||
|
||||
TaskService::TaskService(TaskManager& taskManager) : taskManager(taskManager) {}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "Config.h"
|
||||
#include "spore/types/Config.h"
|
||||
|
||||
Config::Config() {
|
||||
// WiFi Configuration
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "NodeInfo.h"
|
||||
#include "Globals.h"
|
||||
#include "spore/types/NodeInfo.h"
|
||||
#include "spore/internal/Globals.h"
|
||||
|
||||
const char* statusToStr(NodeInfo::Status status) {
|
||||
switch (status) {
|
||||
Reference in New Issue
Block a user