Initialisation depot
This commit is contained in:
133
src/main.cpp
Normal file
133
src/main.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/**
|
||||
* @file main.cpp
|
||||
* @brief Main application entry point for Locomotive Test Bench
|
||||
*
|
||||
* Orchestrates all system components:
|
||||
* - Configuration management
|
||||
* - WiFi connectivity
|
||||
* - Motor control (DC analog)
|
||||
* - DCC signal generation
|
||||
* - LED status indicators
|
||||
* - Web server interface
|
||||
*
|
||||
* @author Locomotive Test Bench Project
|
||||
* @date 2025
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Config.h"
|
||||
#include "WiFiManager.h"
|
||||
#include "MotorController.h"
|
||||
#include "DCCGenerator.h"
|
||||
#include "LEDIndicator.h"
|
||||
#include "WebServer.h"
|
||||
|
||||
// Global objects
|
||||
Config config;
|
||||
WiFiManager wifiManager(&config);
|
||||
MotorController motorController;
|
||||
DCCGenerator dccGenerator;
|
||||
LEDIndicator ledIndicator;
|
||||
WebServerManager webServer(&config, &motorController, &dccGenerator, &ledIndicator);
|
||||
|
||||
/**
|
||||
* @brief Setup function - runs once at startup
|
||||
*
|
||||
* Initializes all hardware and software components in correct order:
|
||||
* 1. Serial communication
|
||||
* 2. Configuration system
|
||||
* 3. WiFi connectivity
|
||||
* 4. LED indicators
|
||||
* 5. Motor controller
|
||||
* 6. DCC generator
|
||||
* 7. Web server
|
||||
*/
|
||||
void setup() {
|
||||
// Initialize serial communication
|
||||
Serial.begin(115200);
|
||||
delay(1000);
|
||||
|
||||
Serial.println("\n\n=================================");
|
||||
Serial.println(" Locomotive Test Bench v1.0");
|
||||
Serial.println("=================================\n");
|
||||
|
||||
// Load configuration
|
||||
config.begin();
|
||||
Serial.println("Configuration loaded");
|
||||
|
||||
// Initialize WiFi
|
||||
wifiManager.begin();
|
||||
|
||||
// Initialize LED indicator
|
||||
ledIndicator.begin();
|
||||
ledIndicator.setPowerOn(true);
|
||||
|
||||
// Initialize motor controller
|
||||
motorController.begin();
|
||||
|
||||
// Initialize DCC generator
|
||||
dccGenerator.begin();
|
||||
|
||||
// Set initial mode and LED
|
||||
if (config.system.isDCCMode) {
|
||||
dccGenerator.enable();
|
||||
ledIndicator.setMode(true);
|
||||
dccGenerator.setLocoSpeed(
|
||||
config.system.dccAddress,
|
||||
config.system.speed,
|
||||
config.system.direction
|
||||
);
|
||||
} else {
|
||||
ledIndicator.setMode(false);
|
||||
motorController.setSpeed(
|
||||
config.system.speed,
|
||||
config.system.direction
|
||||
);
|
||||
Serial.println("=================================\\n");
|
||||
}
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief Main loop - runs continuously
|
||||
*
|
||||
* Updates all system components:
|
||||
* - WiFi connection monitoring
|
||||
* - LED status display
|
||||
* - DCC signal generation (if enabled)
|
||||
* - Motor control updates (if in analog mode)
|
||||
*
|
||||
* @note Small delay prevents watchdog timer issues
|
||||
*/
|
||||
// void loop() {
|
||||
// Update WiFi connection status
|
||||
Serial.println("\n=================================");
|
||||
Serial.println("Setup complete!");
|
||||
Serial.println("=================================");
|
||||
Serial.print("Mode: ");
|
||||
Serial.println(config.system.isDCCMode ? "DCC" : "DC Analog");
|
||||
Serial.print("Web interface: http://");
|
||||
Serial.println(wifiManager.getIPAddress());
|
||||
Serial.println("=================================\n");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Update WiFi connection status
|
||||
wifiManager.update();
|
||||
|
||||
// Update LED indicators
|
||||
ledIndicator.update();
|
||||
|
||||
// Update DCC signal generation (if enabled)
|
||||
if (config.system.isDCCMode) {
|
||||
dccGenerator.update();
|
||||
} else {
|
||||
motorController.update();
|
||||
}
|
||||
|
||||
// Web server updates (handled by AsyncWebServer)
|
||||
webServer.update();
|
||||
|
||||
// Small delay to prevent watchdog issues
|
||||
delay(1);
|
||||
}
|
||||
Reference in New Issue
Block a user