minolta_remote_v1.ino 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /// <summary>
  2. /// Minolta Remote Control Application
  3. ///
  4. /// This application implements a WiFi-controlled remote for Minolta cameras.
  5. /// Running on an ESP8266 microcontroller, it creates a WiFi access point and provides
  6. /// an HTTP API for controlling camera focus and shutter functions remotely.
  7. ///
  8. /// Features:
  9. /// - WiFi Access Point for remote connectivity
  10. /// - HTTP REST API for camera control
  11. /// - Support for half-press (focus), full-press (capture), and multiple shots
  12. /// - Status LED feedback (GPIO-2/LED_BUILTIN)
  13. ///
  14. /// Hardware:
  15. /// - ESP8266 D1 Mini microcontroller
  16. /// - GPIO5 (D1) - Focus control pin
  17. /// - GPIO4 (D2) - Shutter control pin
  18. /// - GPIO2 (LED_BUILTIN) - Status LED indicator
  19. ///
  20. /// API Endpoints:
  21. /// - GET / - Home page with web interface for camera control
  22. /// - GET /api/focus - Perform a half press (focus)
  23. /// - GET /api/takePhoto[?msec=duration] - Take a photo
  24. /// - GET /api/reset - Release the shutter
  25. /// - GET /api/multiple?count=n&delay=ms[&msec=duration] - Take multiple photos
  26. /// - GET /api/healthcheck - Health check endpoint
  27. /// </summary>
  28. #include <ArduinoJson.h>
  29. #include "Config.h"
  30. #include "ShutterController.h"
  31. #include "HTTPServer.h"
  32. #include <AsyncEventSource.h>
  33. #include <AsyncJson.h>
  34. #include <AsyncWebSocket.h>
  35. #include <AsyncWebSynchronization.h>
  36. #include <ESPAsyncWebServer.h>
  37. #include <StringArray.h>
  38. #include <WebAuthentication.h>
  39. #include <WebHandlerImpl.h>
  40. #include <WebResponseImpl.h>
  41. #include <ArduinoWiFiServer.h>
  42. #include <BearSSLHelpers.h>
  43. #include <CertStoreBearSSL.h>
  44. #include <ESP8266WiFi.h>
  45. #include <ESP8266WiFiAP.h>
  46. #include <ESP8266WiFiGeneric.h>
  47. #include <ESP8266WiFiGratuitous.h>
  48. #include <ESP8266WiFiMulti.h>
  49. #include <ESP8266WiFiScan.h>
  50. #include <ESP8266WiFiSTA.h>
  51. #include <ESP8266WiFiType.h>
  52. #include <WiFiClient.h>
  53. #include <WiFiClientSecure.h>
  54. #include <WiFiClientSecureBearSSL.h>
  55. #include <WiFiServer.h>
  56. #include <WiFiServerSecure.h>
  57. #include <WiFiServerSecureBearSSL.h>
  58. #include <WiFiUdp.h>
  59. static const uint8_t D1 = Config::PIN_FOCUS;
  60. static const uint8_t D2 = Config::PIN_SHUTTER;
  61. static const char* ssid = Config::WIFI_SSID;
  62. static const char* password = Config::WIFI_PASSWORD;
  63. IPAddress local_IP = Config::WIFI_IP;
  64. IPAddress gateway = Config::WIFI_GATEWAY;
  65. IPAddress subnet = Config::WIFI_SUBNET;
  66. /// <summary>Pointer to the ShutterController instance for camera control operations</summary>
  67. IShutterController* shutterController = nullptr;
  68. /// <summary>Pointer to the HTTPServer instance for handling API requests</summary>
  69. HTTPServer* httpServer = nullptr;
  70. /// <summary>
  71. /// Initializes all hardware components: serial communication and GPIO pins.
  72. /// Sets up serial communication at the configured baud rate,
  73. /// configures all GPIO pins as outputs, and initializes them to LOW.
  74. /// Logs a confirmation message to the serial console upon completion.
  75. /// </summary>
  76. void initializeHardware()
  77. {
  78. Serial.begin(Config::SERIAL_BAUD);
  79. pinMode(LED_BUILTIN, OUTPUT);
  80. pinMode(D1, OUTPUT);
  81. pinMode(D2, OUTPUT);
  82. digitalWrite(LED_BUILTIN, LOW);
  83. digitalWrite(D1, LOW);
  84. digitalWrite(D2, LOW);
  85. Serial.println("Hardware initialized");
  86. }
  87. /// <summary>
  88. /// Arduino setup function called once on device boot.
  89. /// Initializes all system components in sequence:
  90. /// 1. Hardware (serial, GPIO pins)
  91. /// 2. ShutterController for camera control
  92. /// 3. HTTPServer with WiFi access point
  93. /// After setup completes, the device is ready to accept API requests.
  94. /// </summary>
  95. void setup() {
  96. // Initialize hardware (serial and pins)
  97. initializeHardware();
  98. // Initialize ShutterController
  99. shutterController = new ShutterController(D1, D2);
  100. // Initialize HTTPServer
  101. httpServer = new HTTPServer(Config::HTTP_PORT, shutterController);
  102. httpServer->begin(ssid, password, local_IP, gateway, subnet);
  103. }
  104. /// <summary>
  105. /// Arduino loop function called repeatedly after setup completes.
  106. /// Currently empty as the HTTP server runs asynchronously via interrupts.
  107. /// Can be extended in the future for periodic tasks or health monitoring.
  108. /// </summary>
  109. void loop() {
  110. // put your main code here, to run repeatedly:
  111. }