Initialisation depot
This commit is contained in:
82
ESP32/DCC-Loco/include/ConfigServer.h
Normal file
82
ESP32/DCC-Loco/include/ConfigServer.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* @file ConfigServer.h
|
||||
* @brief WiFi/Bluetooth Configuration Server
|
||||
*
|
||||
* Provides WebSocket-based configuration interface over WiFi or Bluetooth.
|
||||
* Allows reading/writing CVs, testing outputs, and monitoring decoder status.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_SERVER_H
|
||||
#define CONFIG_SERVER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include "CVManager.h"
|
||||
|
||||
class ConfigServer {
|
||||
public:
|
||||
ConfigServer(CVManager& cvManager);
|
||||
|
||||
/**
|
||||
* @brief Initialize configuration server
|
||||
* @param ssid WiFi SSID (nullptr for AP mode with default name)
|
||||
* @param password WiFi password
|
||||
* @param useAP true for AP mode, false for station mode
|
||||
* @return true if successful
|
||||
*/
|
||||
bool begin(const char* ssid = nullptr, const char* password = nullptr, bool useAP = true);
|
||||
|
||||
/**
|
||||
* @brief Stop configuration server
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* @brief Check if configuration mode is active
|
||||
*/
|
||||
bool isActive() const { return active; }
|
||||
|
||||
/**
|
||||
* @brief Update server (call from loop)
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* @brief Set decoder status callback
|
||||
* Function signature: void callback(JsonObject& status)
|
||||
*/
|
||||
typedef void (*StatusCallback)(JsonObject& status);
|
||||
void setStatusCallback(StatusCallback callback);
|
||||
|
||||
private:
|
||||
CVManager& cvMgr;
|
||||
AsyncWebServer* server;
|
||||
AsyncWebSocket* ws;
|
||||
bool active;
|
||||
|
||||
StatusCallback statusCallback;
|
||||
unsigned long lastStatusUpdate;
|
||||
|
||||
void setupWebSocket();
|
||||
void setupHTTPRoutes();
|
||||
void handleWebSocketMessage(void* arg, uint8_t* data, size_t len);
|
||||
void handleWebSocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client,
|
||||
AwsEventType type, void* arg, uint8_t* data, size_t len);
|
||||
|
||||
void handleReadCV(AsyncWebSocketClient* client, JsonObject& json);
|
||||
void handleWriteCV(AsyncWebSocketClient* client, JsonObject& json);
|
||||
void handleGetStatus(AsyncWebSocketClient* client);
|
||||
void handleTestOutput(AsyncWebSocketClient* client, JsonObject& json);
|
||||
void handleReset(AsyncWebSocketClient* client);
|
||||
|
||||
void sendResponse(AsyncWebSocketClient* client, const char* type,
|
||||
bool success, const char* message = nullptr);
|
||||
void broadcastStatus();
|
||||
|
||||
String getDefaultAPName();
|
||||
};
|
||||
|
||||
#endif // CONFIG_SERVER_H
|
||||
Reference in New Issue
Block a user