Initialisation depot
This commit is contained in:
140
include/WebServer.h
Normal file
140
include/WebServer.h
Normal file
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* @file WebServer.h
|
||||
* @brief Web server and REST API for remote control
|
||||
*
|
||||
* Provides web-based control interface with:
|
||||
* - Responsive Bootstrap-based UI
|
||||
* - RESTful API for control and configuration
|
||||
* - LittleFS-based file serving
|
||||
* - Real-time status updates
|
||||
*
|
||||
* @author Locomotive Test Bench Project
|
||||
* @date 2025
|
||||
*/
|
||||
|
||||
#ifndef WEB_SERVER_H
|
||||
#define WEB_SERVER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <AsyncTCP.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include "Config.h"
|
||||
#include "MotorController.h"
|
||||
#include "DCCGenerator.h"
|
||||
#include "LEDIndicator.h"
|
||||
|
||||
/**
|
||||
* @class WebServerManager
|
||||
* @brief Manages web server and API endpoints
|
||||
*
|
||||
* Serves web interface from LittleFS and provides REST API
|
||||
* for controlling the locomotive test bench remotely.
|
||||
*
|
||||
* API Endpoints:
|
||||
* - GET /api/status - Get current system status
|
||||
* - POST /api/mode - Set control mode (analog/dcc)
|
||||
* - POST /api/speed - Set speed and direction
|
||||
* - POST /api/dcc/address - Set DCC address
|
||||
* - POST /api/dcc/function - Control DCC functions
|
||||
* - POST /api/wifi - Configure WiFi settings
|
||||
*/
|
||||
class WebServerManager {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param cfg Pointer to Config object
|
||||
* @param motor Pointer to MotorController
|
||||
* @param dcc Pointer to DCCGenerator
|
||||
* @param led Pointer to LEDIndicator
|
||||
*/
|
||||
WebServerManager(Config* cfg, MotorController* motor, DCCGenerator* dcc, LEDIndicator* led);
|
||||
|
||||
/**
|
||||
* @brief Initialize web server
|
||||
*
|
||||
* Mounts LittleFS, sets up routes, and starts AsyncWebServer.
|
||||
*/
|
||||
void begin();
|
||||
|
||||
/**
|
||||
* @brief Update web server (currently unused)
|
||||
*
|
||||
* AsyncWebServer handles requests asynchronously.
|
||||
*/
|
||||
void update();
|
||||
|
||||
private:
|
||||
Config* config; ///< Configuration manager
|
||||
MotorController* motorController; ///< Motor controller instance
|
||||
DCCGenerator* dccGenerator; ///< DCC generator instance
|
||||
LEDIndicator* ledIndicator; ///< LED indicator instance
|
||||
AsyncWebServer server; ///< Async web server (port 80)
|
||||
|
||||
/**
|
||||
* @brief Set up all HTTP routes and handlers
|
||||
*/
|
||||
void setupRoutes();
|
||||
|
||||
/**
|
||||
* @brief Handle root page request
|
||||
* @param request HTTP request object
|
||||
*/
|
||||
void handleRoot(AsyncWebServerRequest *request);
|
||||
|
||||
/**
|
||||
* @brief Handle status request
|
||||
* @param request HTTP request object
|
||||
*/
|
||||
void handleGetStatus(AsyncWebServerRequest *request);
|
||||
|
||||
/**
|
||||
* @brief Handle mode change request
|
||||
* @param request HTTP request object
|
||||
*/
|
||||
void handleSetMode(AsyncWebServerRequest *request);
|
||||
|
||||
/**
|
||||
* @brief Handle speed setting request
|
||||
* @param request HTTP request object
|
||||
*/
|
||||
void handleSetSpeed(AsyncWebServerRequest *request);
|
||||
|
||||
/**
|
||||
* @brief Handle DCC function request
|
||||
* @param request HTTP request object
|
||||
*/
|
||||
void handleSetFunction(AsyncWebServerRequest *request);
|
||||
|
||||
/**
|
||||
* @brief Handle config retrieval request
|
||||
* @param request HTTP request object
|
||||
*/
|
||||
void handleGetConfig(AsyncWebServerRequest *request);
|
||||
|
||||
/**
|
||||
* @brief Handle WiFi configuration request
|
||||
* @param request HTTP request object
|
||||
*/
|
||||
void handleSetWiFi(AsyncWebServerRequest *request);
|
||||
|
||||
/**
|
||||
* @brief Handle restart request
|
||||
* @param request HTTP request object
|
||||
*/
|
||||
void handleRestart(AsyncWebServerRequest *request);
|
||||
|
||||
/**
|
||||
* @brief Get system status as JSON
|
||||
* @return JSON string with status information
|
||||
*/
|
||||
String getStatusJSON();
|
||||
|
||||
/**
|
||||
* @brief Get configuration as JSON
|
||||
* @return JSON string with configuration
|
||||
*/
|
||||
String getConfigJSON();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user