HTTPServer.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef HTTP_SERVER_H
  2. #define HTTP_SERVER_H
  3. #include <ESPAsyncWebServer.h>
  4. #include <ESP8266WiFi.h>
  5. #include "ShutterController.h"
  6. /// <summary>
  7. /// HTTP server for handling Minolta remote control API requests.
  8. /// Manages WiFi access point configuration, HTTP routes, and request handling
  9. /// for camera control operations like focus, shutter, and multiple shots.
  10. /// </summary>
  11. class HTTPServer
  12. {
  13. private:
  14. /// <summary>Pointer to the AsyncWebServer instance</summary>
  15. AsyncWebServer* server;
  16. /// <summary>Pointer to the ShutterController interface for camera control</summary>
  17. IShutterController* shutterController;
  18. /// <summary>Registers all HTTP API endpoints and their handlers</summary>
  19. void setupRoutes();
  20. /// <summary>
  21. /// Handles GET / request to serve the home page.
  22. /// Returns a simple HTML control interface for the camera remote.
  23. /// </summary>
  24. /// <param name="request">Async web server request object</param>
  25. void handleRoot(AsyncWebServerRequest *request);
  26. /// <summary>
  27. /// Handles GET /api/focus request to perform a half press (focus).
  28. /// </summary>
  29. /// <param name="request">Async web server request object</param>
  30. void handleFocus(AsyncWebServerRequest *request);
  31. /// <summary>
  32. /// Handles GET /api/takePhoto request to take a photo with optional delay.
  33. /// Accepts optional query parameter "msec" for photo hold duration.
  34. /// </summary>
  35. /// <param name="request">Async web server request object</param>
  36. void handleTakePhoto(AsyncWebServerRequest *request);
  37. /// <summary>
  38. /// Handles GET /api/reset request to release the shutter and return to neutral position.
  39. /// </summary>
  40. /// <param name="request">Async web server request object</param>
  41. void handleReset(AsyncWebServerRequest *request);
  42. /// <summary>
  43. /// Handles GET /api/multiple request to take multiple photos in sequence.
  44. /// Accepts query parameters: "count" (number of photos) and "delay" (ms between shots).
  45. /// Optional parameter "msec" specifies duration of each shot.
  46. /// </summary>
  47. /// <param name="request">Async web server request object</param>
  48. void handleMultiple(AsyncWebServerRequest *request);
  49. /// <summary>
  50. /// Handles GET /api/healthcheck request as a health check endpoint.
  51. /// </summary>
  52. /// <param name="request">Async web server request object</param>
  53. void handleHealthCheck(AsyncWebServerRequest *request);
  54. /// <summary>
  55. /// Logs the start of a request processing and enables the status LED.
  56. /// </summary>
  57. /// <param name="endpoint">Name of the API endpoint being processed</param>
  58. void onRequestStart(const char* endpoint);
  59. /// <summary>
  60. /// Logs the completion of a request processing and disables the status LED.
  61. /// </summary>
  62. /// <param name="endpoint">Name of the API endpoint that was processed</param>
  63. void onRequestEnd(const char* endpoint);
  64. public:
  65. /// <summary>
  66. /// Constructs an HTTPServer instance.
  67. /// </summary>
  68. /// <param name="port">HTTP server port number (typically 80)</param>
  69. /// <param name="controller">Pointer to ShutterController for camera operations</param>
  70. HTTPServer(uint16_t port, IShutterController* controller);
  71. /// <summary>
  72. /// Destructor that cleans up the AsyncWebServer instance.
  73. /// </summary>
  74. ~HTTPServer();
  75. /// <summary>
  76. /// Initializes the WiFi access point and starts the HTTP server.
  77. /// Must be called during application setup.
  78. /// </summary>
  79. /// <param name="ssid">WiFi network name</param>
  80. /// <param name="password">WiFi network password</param>
  81. /// <param name="local_IP">Static IP address for the access point</param>
  82. /// <param name="gateway">Gateway IP address</param>
  83. /// <param name="subnet">Subnet mask</param>
  84. void begin(const char* ssid, const char* password,
  85. IPAddress local_IP, IPAddress gateway, IPAddress subnet);
  86. /// <summary>
  87. /// Configures the ESP8266 as a WiFi access point with the specified credentials.
  88. /// </summary>
  89. /// <param name="ssid">WiFi network name</param>
  90. /// <param name="password">WiFi network password</param>
  91. /// <param name="local_IP">Static IP address for the access point</param>
  92. /// <param name="gateway">Gateway IP address</param>
  93. /// <param name="subnet">Subnet mask</param>
  94. void setupWiFiAP(const char* ssid, const char* password,
  95. IPAddress local_IP, IPAddress gateway, IPAddress subnet);
  96. };
  97. #endif // HTTP_SERVER_H