HTTPServer.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 /api/focus request to perform a half press (focus).
  22. /// </summary>
  23. /// <param name="request">Async web server request object</param>
  24. void handleFocus(AsyncWebServerRequest *request);
  25. /// <summary>
  26. /// Handles GET /api/takePhoto request to take a photo with optional delay.
  27. /// Accepts optional query parameter "msec" for photo hold duration.
  28. /// </summary>
  29. /// <param name="request">Async web server request object</param>
  30. void handleTakePhoto(AsyncWebServerRequest *request);
  31. /// <summary>
  32. /// Handles GET /api/reset request to release the shutter and return to neutral position.
  33. /// </summary>
  34. /// <param name="request">Async web server request object</param>
  35. void handleReset(AsyncWebServerRequest *request);
  36. /// <summary>
  37. /// Handles GET /api/multiple request to take multiple photos in sequence.
  38. /// Accepts query parameters: "count" (number of photos) and "delay" (ms between shots).
  39. /// Optional parameter "msec" specifies duration of each shot.
  40. /// </summary>
  41. /// <param name="request">Async web server request object</param>
  42. void handleMultiple(AsyncWebServerRequest *request);
  43. /// <summary>
  44. /// Handles GET /get request as a health check endpoint.
  45. /// </summary>
  46. /// <param name="request">Async web server request object</param>
  47. void handleHealthCheck(AsyncWebServerRequest *request);
  48. /// <summary>
  49. /// Logs the start of a request processing and enables the status LED.
  50. /// </summary>
  51. /// <param name="endpoint">Name of the API endpoint being processed</param>
  52. void onRequestStart(const char* endpoint);
  53. /// <summary>
  54. /// Logs the completion of a request processing and disables the status LED.
  55. /// </summary>
  56. /// <param name="endpoint">Name of the API endpoint that was processed</param>
  57. void onRequestEnd(const char* endpoint);
  58. public:
  59. /// <summary>
  60. /// Constructs an HTTPServer instance.
  61. /// </summary>
  62. /// <param name="port">HTTP server port number (typically 80)</param>
  63. /// <param name="controller">Pointer to ShutterController for camera operations</param>
  64. HTTPServer(uint16_t port, IShutterController* controller);
  65. /// <summary>
  66. /// Destructor that cleans up the AsyncWebServer instance.
  67. /// </summary>
  68. ~HTTPServer();
  69. /// <summary>
  70. /// Initializes the WiFi access point and starts the HTTP server.
  71. /// Must be called during application setup.
  72. /// </summary>
  73. /// <param name="ssid">WiFi network name</param>
  74. /// <param name="password">WiFi network password</param>
  75. /// <param name="local_IP">Static IP address for the access point</param>
  76. /// <param name="gateway">Gateway IP address</param>
  77. /// <param name="subnet">Subnet mask</param>
  78. void begin(const char* ssid, const char* password,
  79. IPAddress local_IP, IPAddress gateway, IPAddress subnet);
  80. /// <summary>
  81. /// Configures the ESP8266 as a WiFi access point with the specified credentials.
  82. /// </summary>
  83. /// <param name="ssid">WiFi network name</param>
  84. /// <param name="password">WiFi network password</param>
  85. /// <param name="local_IP">Static IP address for the access point</param>
  86. /// <param name="gateway">Gateway IP address</param>
  87. /// <param name="subnet">Subnet mask</param>
  88. void setupWiFiAP(const char* ssid, const char* password,
  89. IPAddress local_IP, IPAddress gateway, IPAddress subnet);
  90. };
  91. #endif // HTTP_SERVER_H