HTTPServer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 using Config::HTTP_PORT.
  67. /// </summary>
  68. /// <param name="controller">Pointer to ShutterController for camera operations</param>
  69. HTTPServer(IShutterController* controller);
  70. /// <summary>
  71. /// Destructor that cleans up the AsyncWebServer instance.
  72. /// </summary>
  73. ~HTTPServer();
  74. /// <summary>
  75. /// Initializes the WiFi access point and starts the HTTP server.
  76. /// Uses WiFi settings from Config class constants.
  77. /// Must be called during application setup.
  78. /// </summary>
  79. void begin();
  80. /// <summary>
  81. /// Configures the ESP8266 as a WiFi access point using Config WiFi settings.
  82. /// Uses Config::WIFI_SSID, Config::WIFI_PASSWORD, Config::WIFI_IP, Config::WIFI_GATEWAY, and Config::WIFI_SUBNET.
  83. /// </summary>
  84. void setupWiFiAP();
  85. };
  86. #endif // HTTP_SERVER_H