feat: multi-board HAL guards, RFRemote subsystem, Player/OTA improvements
Multi-board variant support: - variants/vesper.hpp: enable HAS_RF=1, define RF_RX_PIN=22 - variants/agnus.hpp: enable HAS_RF=1, RF_RX_PIN=22, correct HAS_RTC=0 - main.cpp, Player, HealthMonitor, OTAManager, ConfigManager: wrap all RTC/SD/RF-dependent code in #if HAS_RTC / HAS_SD_CARD / HAS_RF guards so Agnus builds cleanly without those peripherals RFRemote subsystem (new): - src/RFRemote/: RF receiver driver (GPIO RF_RX_PIN) + command handler - Registered with HealthMonitor and CommunicationRouter when HAS_RF=1 Player improvements: - uid -> pid rename throughout (Player, BuiltInMelodies, api-reference) - loadMelodyInRAM() now returns bool - playerControlTaskFn task added — defers stop/pause/resume out of timer callback (Tmr Svc) to avoid stack overflows - setDependencies() accepts nullptr FileManager for SD-less boards OTAManager: - Consume download_url from server metadata response instead of constructing firmware path locally - HTTP redirect following enabled (setFollowRedirects) - HAS_RTC guards on TimeKeeper references platformio.ini: - Add rc-switch library for RF remote support - Remove BOARD_TYPE/BOARD_NAME/BOARD_VERSION flags (moved to variant headers) - MQTT_SECRET placeholders only — no secrets in source Docs: - docs/architecture/codebase-refactor-plan.md: new migration strategy doc - docs/reference/api-reference.md: updated for pid, note_assignments, download_url - Remove stale docs: ota-telemetry-api.md, platformio-commands.md, firmware-variants.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+56
-1
@@ -95,15 +95,21 @@
|
||||
// HARDWARE LIBRARIES - Peripheral device control
|
||||
// ═══════════════════════════════════════════════════════════════════════════════════
|
||||
#include <Adafruit_PCF8574.h> // I2C GPIO expander for relay control
|
||||
#if HAS_RTC
|
||||
#include <RTClib.h> // Real-time clock functionality
|
||||
#endif
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════════════
|
||||
// CUSTOM CLASSES - Include Custom Classes and Functions
|
||||
// ═══════════════════════════════════════════════════════════════════════════════════
|
||||
#include "SDCardMutex/SDCardMutex.hpp" // ⚠️ MUST be included before any SD-using classes
|
||||
#include "ConfigManager/ConfigManager.hpp"
|
||||
#if HAS_SD_CARD
|
||||
#include "FileManager/FileManager.hpp"
|
||||
#endif
|
||||
#if HAS_RTC
|
||||
#include "TimeKeeper/TimeKeeper.hpp"
|
||||
#endif
|
||||
#include "Logging/Logging.hpp"
|
||||
#include "Telemetry/Telemetry.hpp"
|
||||
#include "OTAManager/OTAManager.hpp"
|
||||
@@ -119,13 +125,20 @@
|
||||
#include "InputManager/InputManager.hpp"
|
||||
#include "Version.hpp"
|
||||
#include "NvsMigration/NvsMigration.hpp"
|
||||
#if HAS_RF
|
||||
#include "RFRemote/RFRemote.hpp"
|
||||
#endif
|
||||
|
||||
#define TAG "Main"
|
||||
|
||||
// Class Constructors
|
||||
ConfigManager configManager;
|
||||
#if HAS_SD_CARD
|
||||
FileManager fileManager(&configManager);
|
||||
#endif
|
||||
#if HAS_RTC
|
||||
Timekeeper timekeeper;
|
||||
#endif
|
||||
Telemetry telemetry;
|
||||
OTAManager otaManager(configManager);
|
||||
Player player;
|
||||
@@ -137,6 +150,9 @@ CommunicationRouter communication(configManager, otaManager, networking, server
|
||||
HealthMonitor healthMonitor;
|
||||
FirmwareValidator firmwareValidator;
|
||||
InputManager inputManager;
|
||||
#if HAS_RF
|
||||
RFRemote rfRemote;
|
||||
#endif
|
||||
|
||||
|
||||
// 🔥 OUTPUT SYSTEM - PCF8574/PCF8575 I2C Expanders Configuration
|
||||
@@ -165,8 +181,10 @@ PCF8574OutputManager outputManager(0x24, ChipType::PCF8574, 6);
|
||||
BellEngine bellEngine(player, configManager, telemetry, outputManager); // 🔥 THE ULTIMATE BEAST!
|
||||
|
||||
TaskHandle_t bellEngineHandle = NULL; // Legacy - will be removed
|
||||
#if HAS_RTC
|
||||
TimerHandle_t schedulerTimer;
|
||||
TimerHandle_t ntpSyncTimer; // Non-blocking delayed NTP sync timer
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -177,6 +195,7 @@ void handleFactoryReset() {
|
||||
}
|
||||
}
|
||||
|
||||
#if HAS_RTC
|
||||
// One-shot task to perform NTP sync outside the Tmr Svc context
|
||||
static void ntpSyncTask(void* param) {
|
||||
LOG_DEBUG(TAG, "Network stabilization complete - starting NTP sync");
|
||||
@@ -190,6 +209,7 @@ static void ntpSyncTask(void* param) {
|
||||
void ntpSyncTimerCallback(TimerHandle_t xTimer) {
|
||||
xTaskCreate(ntpSyncTask, "ntpSync", 3072, NULL, 5, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -197,7 +217,7 @@ void setup()
|
||||
{
|
||||
// Initialize Serial Communications (for debugging) & I2C Bus (for Hardware Control)
|
||||
Serial.begin(115200);
|
||||
Serial.print("VESPER System Booting UP! - Version ");
|
||||
Serial.print("BellSystems Firmware Booting - Version ");
|
||||
Serial.println(FW_VERSION);
|
||||
|
||||
// ── NVS schema migration ─────────────────────────────────────────────────
|
||||
@@ -256,7 +276,9 @@ void setup()
|
||||
healthMonitor.begin();
|
||||
// Register all subsystems with health monitor for continuous monitoring
|
||||
healthMonitor.setConfigManager(&configManager);
|
||||
#if HAS_SD_CARD
|
||||
healthMonitor.setFileManager(&fileManager);
|
||||
#endif
|
||||
|
||||
// Initialize Output Manager - 🔥 THE NEW WAY!
|
||||
outputManager.setConfigManager(&configManager);
|
||||
@@ -292,6 +314,7 @@ void setup()
|
||||
|
||||
// SD Card initialization is now handled by ConfigManager
|
||||
|
||||
#if HAS_RTC
|
||||
// Initialize timekeeper with NO clock outputs
|
||||
timekeeper.begin(); // No parameters needed
|
||||
// Connect the timekeeper to dependencies (CLEAN!)
|
||||
@@ -303,12 +326,15 @@ void setup()
|
||||
|
||||
// Register TimeKeeper with health monitor
|
||||
healthMonitor.setTimeKeeper(&timekeeper);
|
||||
#endif
|
||||
|
||||
// Initialize Telemetry
|
||||
telemetry.setPlayerReference(&player.isPlaying);
|
||||
// 🚑 CRITICAL: Connect force stop callback for overload protection!
|
||||
telemetry.setForceStopCallback([]() { player.forceStop(); });
|
||||
#if HAS_SD_CARD
|
||||
telemetry.setFileManager(&fileManager);
|
||||
#endif
|
||||
telemetry.begin();
|
||||
|
||||
// Register Telemetry with health monitor
|
||||
@@ -333,18 +359,31 @@ void setup()
|
||||
// Set all dependency references BEFORE begin() so that registerHandlers()
|
||||
// (called inside begin()) can construct every domain handler.
|
||||
communication.setPlayerReference(&player);
|
||||
#if HAS_SD_CARD
|
||||
communication.setFileManagerReference(&fileManager);
|
||||
#endif
|
||||
#if HAS_RTC
|
||||
communication.setTimeKeeperReference(&timekeeper);
|
||||
#endif
|
||||
communication.setFirmwareValidatorReference(&firmwareValidator);
|
||||
communication.setTelemetryReference(&telemetry);
|
||||
communication.setHealthMonitorReference(&healthMonitor);
|
||||
communication.setOutputManagerReference(&outputManager);
|
||||
#if HAS_RF
|
||||
communication.setRFRemoteReference(&rfRemote);
|
||||
#endif
|
||||
communication.begin();
|
||||
|
||||
#if HAS_SD_CARD
|
||||
player.setDependencies(&communication, &fileManager);
|
||||
#else
|
||||
player.setDependencies(&communication, nullptr);
|
||||
#endif
|
||||
player.setBellEngine(&bellEngine); // Connect the beast!
|
||||
player.setTelemetry(&telemetry);
|
||||
#if HAS_RTC
|
||||
player.setTimekeeper(&timekeeper); // 🔥 Connect for alert coordination
|
||||
#endif
|
||||
|
||||
// Register Communication with health monitor
|
||||
healthMonitor.setCommunication(&communication);
|
||||
@@ -355,6 +394,7 @@ void setup()
|
||||
// Track if AsyncWebServer has been started to prevent duplicates
|
||||
static bool webServerStarted = false;
|
||||
|
||||
#if HAS_RTC
|
||||
// Create NTP sync timer (one-shot, 3 second delay for network stabilization)
|
||||
ntpSyncTimer = xTimerCreate(
|
||||
"NTPSync", // Timer name
|
||||
@@ -363,18 +403,21 @@ void setup()
|
||||
NULL, // Timer ID (not used)
|
||||
ntpSyncTimerCallback // Callback function
|
||||
);
|
||||
#endif
|
||||
|
||||
// Set up network callbacks
|
||||
networking.setNetworkCallbacks(
|
||||
[&webServerStarted]() {
|
||||
communication.onNetworkConnected();
|
||||
|
||||
#if HAS_RTC
|
||||
// Schedule non-blocking NTP sync after 3s network stabilization (like MQTT)
|
||||
// Skip NTP sync in AP mode (no internet connection)
|
||||
if (!networking.isInAPMode() && ntpSyncTimer) {
|
||||
LOG_DEBUG(TAG, "Network connected - scheduling NTP sync after 3s stabilization (non-blocking)");
|
||||
xTimerStart(ntpSyncTimer, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Start AsyncWebServer when network becomes available (only once!)
|
||||
if (!webServerStarted && networking.getState() != NetworkState::WIFI_PORTAL_MODE) {
|
||||
@@ -392,12 +435,14 @@ void setup()
|
||||
LOG_INFO(TAG, "Network already connected - initializing services");
|
||||
communication.onNetworkConnected();
|
||||
|
||||
#if HAS_RTC
|
||||
// Schedule non-blocking NTP sync after 3s network stabilization (like MQTT)
|
||||
// Skip NTP sync in AP mode (no internet connection)
|
||||
if (!networking.isInAPMode() && ntpSyncTimer) {
|
||||
LOG_DEBUG(TAG, "Network already connected - scheduling NTP sync after 3s stabilization (non-blocking)");
|
||||
xTimerStart(ntpSyncTimer, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
// 🔥 CRITICAL: Start AsyncWebServer ONLY when network is ready
|
||||
// Do NOT start if WiFiManager portal is active (port 80 conflict!)
|
||||
@@ -413,9 +458,13 @@ void setup()
|
||||
|
||||
// Initialize OTA Manager
|
||||
otaManager.begin();
|
||||
#if HAS_SD_CARD
|
||||
otaManager.setFileManager(&fileManager);
|
||||
#endif
|
||||
otaManager.setPlayer(&player); // Set player reference for idle check
|
||||
#if HAS_RTC
|
||||
otaManager.setTimeKeeper(&timekeeper); // Set timekeeper reference for freeze mode
|
||||
#endif
|
||||
otaManager.setTelemetry(&telemetry); // Set telemetry reference for freeze mode
|
||||
|
||||
// 🔥 FIX: OTA check will happen asynchronously via scheduled timer (no blocking delay)
|
||||
@@ -425,6 +474,12 @@ void setup()
|
||||
// Register OTA Manager with health monitor
|
||||
healthMonitor.setOTAManager(&otaManager);
|
||||
|
||||
#if HAS_RF
|
||||
// Initialize RF remote receiver
|
||||
rfRemote.begin(&player);
|
||||
healthMonitor.setRFRemote(&rfRemote);
|
||||
#endif
|
||||
|
||||
// Note: AsyncWebServer will be started by network callbacks when connection is ready
|
||||
// This avoids port 80 conflicts with WiFiManager's captive portal
|
||||
|
||||
|
||||
Reference in New Issue
Block a user