Ajout prise en charge ESP-Display
This commit is contained in:
83
src/main.cpp
83
src/main.cpp
@@ -4,32 +4,29 @@
|
||||
*
|
||||
* Orchestrates all system components:
|
||||
* - Configuration management
|
||||
* - WiFi connectivity
|
||||
* - Touchscreen UI
|
||||
* - Motor control (DC analog)
|
||||
* - DCC signal generation
|
||||
* - LED status indicators
|
||||
* - Web server interface
|
||||
* - Relay control for 2-rail/3-rail switching
|
||||
*
|
||||
* @author Locomotive Test Bench Project
|
||||
* @date 2025
|
||||
* @version 1.0
|
||||
* @version 2.0
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Config.h"
|
||||
#include "WiFiManager.h"
|
||||
#include "MotorController.h"
|
||||
#include "DCCGenerator.h"
|
||||
#include "LEDIndicator.h"
|
||||
#include "WebServer.h"
|
||||
#include "RelayController.h"
|
||||
#include "TouchscreenUI.h"
|
||||
|
||||
// Global objects
|
||||
Config config;
|
||||
WiFiManager wifiManager(&config);
|
||||
MotorController motorController;
|
||||
DCCGenerator dccGenerator;
|
||||
LEDIndicator ledIndicator;
|
||||
WebServerManager webServer(&config, &motorController, &dccGenerator, &ledIndicator);
|
||||
RelayController relayController;
|
||||
TouchscreenUI touchUI(&config, &motorController, &dccGenerator, &relayController);
|
||||
|
||||
/**
|
||||
* @brief Setup function - runs once at startup
|
||||
@@ -37,11 +34,10 @@ WebServerManager webServer(&config, &motorController, &dccGenerator, &ledIndicat
|
||||
* 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
|
||||
* 3. Relay controller
|
||||
* 4. Motor controller
|
||||
* 5. DCC generator
|
||||
* 6. Touchscreen UI
|
||||
*/
|
||||
void setup() {
|
||||
// Initialize serial communication
|
||||
@@ -49,19 +45,17 @@ void setup() {
|
||||
delay(1000);
|
||||
|
||||
Serial.println("\n\n=================================");
|
||||
Serial.println(" Locomotive Test Bench v1.0");
|
||||
Serial.println(" Locomotive Test Bench v2.0");
|
||||
Serial.println(" ESP32-2432S028R Edition");
|
||||
Serial.println("=================================\n");
|
||||
|
||||
// Load configuration
|
||||
config.begin();
|
||||
Serial.println("Configuration loaded");
|
||||
|
||||
// Initialize WiFi
|
||||
wifiManager.begin();
|
||||
|
||||
// Initialize LED indicator TODO
|
||||
//ledIndicator.begin();
|
||||
//ledIndicator.setPowerOn(true);
|
||||
// Initialize relay controller
|
||||
relayController.begin();
|
||||
relayController.setRailMode(config.system.is3Rail);
|
||||
|
||||
// Initialize motor controller
|
||||
motorController.begin();
|
||||
@@ -69,62 +63,47 @@ void setup() {
|
||||
// Initialize DCC generator
|
||||
dccGenerator.begin();
|
||||
|
||||
// Set initial mode and LED
|
||||
if (config.system.isDCCMode) {
|
||||
// Initialize touchscreen UI
|
||||
touchUI.begin();
|
||||
|
||||
// Set initial mode (but power is off by default)
|
||||
if (config.system.isDCCMode && config.system.powerOn) {
|
||||
dccGenerator.enable();
|
||||
// ledIndicator.setMode(true);
|
||||
dccGenerator.setLocoSpeed(
|
||||
config.system.dccAddress,
|
||||
config.system.speed,
|
||||
config.system.direction
|
||||
);
|
||||
} else {
|
||||
// ledIndicator.setMode(false);
|
||||
} else if (!config.system.isDCCMode && config.system.powerOn) {
|
||||
motorController.setSpeed(
|
||||
config.system.speed,
|
||||
config.system.direction
|
||||
);
|
||||
Serial.println("=================================\\n");
|
||||
}
|
||||
|
||||
// Start web server BEFORE final status
|
||||
Serial.println("\nStarting web server...");
|
||||
webServer.begin();
|
||||
}
|
||||
|
||||
// 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("WiFi Mode: ");
|
||||
Serial.println(config.wifi.isAPMode ? "Access Point" : "Client");
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(config.wifi.isAPMode ? config.wifi.apSSID : config.wifi.ssid);
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(wifiManager.getIPAddress());
|
||||
Serial.print("Web interface: http://");
|
||||
Serial.println(wifiManager.getIPAddress());
|
||||
Serial.print("Rail Mode: ");
|
||||
Serial.println(config.system.is3Rail ? "3-Rail" : "2-Rail");
|
||||
Serial.print("Power: ");
|
||||
Serial.println(config.system.powerOn ? "ON" : "OFF");
|
||||
Serial.println("=================================\n");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Update WiFi connection status
|
||||
wifiManager.update();
|
||||
|
||||
// Update LED indicators
|
||||
//ledIndicator.update();
|
||||
// Update touchscreen UI (handles all user interactions)
|
||||
touchUI.update();
|
||||
|
||||
// Update DCC signal generation (if enabled)
|
||||
if (config.system.isDCCMode) {
|
||||
if (config.system.isDCCMode && touchUI.isPowerOn()) {
|
||||
dccGenerator.update();
|
||||
} else {
|
||||
} else if (!config.system.isDCCMode && touchUI.isPowerOn()) {
|
||||
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