|
|
@@ -1,14 +1,34 @@
|
|
|
-#include <ArduinoJson.h>
|
|
|
+/// <summary>
|
|
|
+/// Minolta Remote Control Application
|
|
|
+///
|
|
|
+/// This application implements a WiFi-controlled remote for Minolta cameras.
|
|
|
+/// Running on an ESP8266 microcontroller, it creates a WiFi access point and provides
|
|
|
+/// an HTTP API for controlling camera focus and shutter functions remotely.
|
|
|
+///
|
|
|
+/// Features:
|
|
|
+/// - WiFi Access Point for remote connectivity
|
|
|
+/// - HTTP REST API for camera control
|
|
|
+/// - Support for half-press (focus), full-press (capture), and multiple shots
|
|
|
+/// - Status LED feedback (GPIO-2/LED_BUILTIN)
|
|
|
+///
|
|
|
+/// Hardware:
|
|
|
+/// - ESP8266 D1 Mini microcontroller
|
|
|
+/// - GPIO5 (D1) - Focus control pin
|
|
|
+/// - GPIO4 (D2) - Shutter control pin
|
|
|
+/// - GPIO2 (LED_BUILTIN) - Status LED indicator
|
|
|
+///
|
|
|
+/// API Endpoints:
|
|
|
+/// - GET /api/focus - Perform a half press (focus)
|
|
|
+/// - GET /api/takePhoto[?msec=duration] - Take a photo
|
|
|
+/// - GET /api/reset - Release the shutter
|
|
|
+/// - GET /api/multiple?count=n&delay=ms[&msec=duration] - Take multiple photos
|
|
|
+/// - GET /get - Health check
|
|
|
+/// </summary>
|
|
|
|
|
|
-#include <AsyncEventSource.h>
|
|
|
-#include <AsyncJson.h>
|
|
|
-#include <AsyncWebSocket.h>
|
|
|
-#include <AsyncWebSynchronization.h>
|
|
|
-#include <ESPAsyncWebServer.h>
|
|
|
-#include <StringArray.h>
|
|
|
-#include <WebAuthentication.h>
|
|
|
-#include <WebHandlerImpl.h>
|
|
|
-#include <WebResponseImpl.h>
|
|
|
+#include <ArduinoJson.h>
|
|
|
+#include "Config.h"
|
|
|
+#include "ShutterController.h"
|
|
|
+#include "HTTPServer.h"
|
|
|
|
|
|
#include <AsyncEventSource.h>
|
|
|
#include <AsyncJson.h>
|
|
|
@@ -39,159 +59,63 @@
|
|
|
#include <WiFiServerSecureBearSSL.h>
|
|
|
#include <WiFiUdp.h>
|
|
|
|
|
|
-static const uint8_t D1 = 5;
|
|
|
-static const uint8_t D2 = 4;
|
|
|
-static const char* ssid = "MINOLTA_REMOTE_CONTROL";
|
|
|
-static const char* password = "12345678";
|
|
|
-bool isFocusPressed = false;
|
|
|
-IPAddress local_IP(192,168,1,200);
|
|
|
-IPAddress gateway(192,168,1,1);
|
|
|
-IPAddress subnet(255,255,255,0);
|
|
|
-AsyncWebServer server(80);
|
|
|
-
|
|
|
-void setup() {
|
|
|
- // put your setup code here, to run once:
|
|
|
- Serial.begin(115200);
|
|
|
- pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
|
|
|
+static const uint8_t D1 = Config::PIN_FOCUS;
|
|
|
+static const uint8_t D2 = Config::PIN_SHUTTER;
|
|
|
+static const char* ssid = Config::WIFI_SSID;
|
|
|
+static const char* password = Config::WIFI_PASSWORD;
|
|
|
+IPAddress local_IP = Config::WIFI_IP;
|
|
|
+IPAddress gateway = Config::WIFI_GATEWAY;
|
|
|
+IPAddress subnet = Config::WIFI_SUBNET;
|
|
|
+
|
|
|
+/// <summary>Pointer to the ShutterController instance for camera control operations</summary>
|
|
|
+IShutterController* shutterController = nullptr;
|
|
|
+
|
|
|
+/// <summary>Pointer to the HTTPServer instance for handling API requests</summary>
|
|
|
+HTTPServer* httpServer = nullptr;
|
|
|
+
|
|
|
+/// <summary>
|
|
|
+/// Initializes all hardware components: serial communication and GPIO pins.
|
|
|
+/// Sets up serial communication at the configured baud rate,
|
|
|
+/// configures all GPIO pins as outputs, and initializes them to LOW.
|
|
|
+/// Logs a confirmation message to the serial console upon completion.
|
|
|
+/// </summary>
|
|
|
+void initializeHardware()
|
|
|
+{
|
|
|
+ Serial.begin(Config::SERIAL_BAUD);
|
|
|
+ pinMode(LED_BUILTIN, OUTPUT);
|
|
|
pinMode(D1, OUTPUT);
|
|
|
pinMode(D2, OUTPUT);
|
|
|
- digitalWrite(LED_BUILTIN, LOW);
|
|
|
+ digitalWrite(LED_BUILTIN, LOW);
|
|
|
digitalWrite(D1, LOW);
|
|
|
digitalWrite(D2, LOW);
|
|
|
- if (!WiFi.softAPConfig (local_IP, gateway, subnet))
|
|
|
- {
|
|
|
- Serial.println("Failed to config IP");
|
|
|
- }
|
|
|
- WiFi.softAP(ssid, password);
|
|
|
- Serial.println(WiFi.softAPIP());
|
|
|
- Serial.println("Waiting for connect");
|
|
|
- /*while(WiFi.status() != WL_CONNECTED)
|
|
|
- {
|
|
|
- digitalWrite(LED_BUILTIN, HIGH);
|
|
|
- delay(500);
|
|
|
- Serial.print(".");
|
|
|
- Serial.print(WiFi.status());
|
|
|
- digitalWrite(LED_BUILTIN, LOW);
|
|
|
- }*/
|
|
|
- Serial.println("Client connected");
|
|
|
-
|
|
|
- server.on("/api/focus",HTTP_GET, [](AsyncWebServerRequest *request)
|
|
|
- {
|
|
|
- Serial.println("api/focus");
|
|
|
- digitalWrite(LED_BUILTIN, HIGH);
|
|
|
- halfPress();
|
|
|
- digitalWrite(LED_BUILTIN, LOW);
|
|
|
- request->send(200,"application/json","{\"result\":\"true\"}");
|
|
|
- });
|
|
|
-
|
|
|
- server.on("/api/takePhoto",HTTP_GET, [](AsyncWebServerRequest *request)
|
|
|
- {
|
|
|
- Serial.println("api/takePhoto");
|
|
|
- digitalWrite(LED_BUILTIN, HIGH);
|
|
|
- if (request->hasParam("msec"))
|
|
|
- {
|
|
|
- int ms = request->getParam("msec")->value().toInt();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- pressFullWithDelay(1000);
|
|
|
- }
|
|
|
- digitalWrite(LED_BUILTIN, LOW);
|
|
|
- request->send(200,"application/json","{\"result\":\"true\"}");
|
|
|
- });
|
|
|
-
|
|
|
- server.on("/api/reset",HTTP_GET, [](AsyncWebServerRequest *request)
|
|
|
- {
|
|
|
- Serial.println("api/reset");
|
|
|
- digitalWrite(LED_BUILTIN, HIGH);
|
|
|
- unPress();
|
|
|
- digitalWrite(LED_BUILTIN, LOW);
|
|
|
- request->send(200,"application/json","{\"result\":\"true\"}");
|
|
|
- });
|
|
|
-
|
|
|
- server.on("/api/multiple",HTTP_GET, [](AsyncWebServerRequest *request)
|
|
|
- {
|
|
|
- Serial.println("api/multiple");
|
|
|
- digitalWrite(LED_BUILTIN, HIGH);
|
|
|
- if (request->hasParam("count") && request->hasParam("delay"))
|
|
|
- {
|
|
|
- int ms = 1000;
|
|
|
- int count = request->getParam("count")->value().toInt();
|
|
|
- int delayMs = request->getParam("delay")->value().toInt();
|
|
|
- if (request->hasParam("msec"))
|
|
|
- {
|
|
|
- ms = request->getParam("msec")->value().toInt();
|
|
|
- }
|
|
|
- if (!isFocusPressed)
|
|
|
- {
|
|
|
- halfPress();
|
|
|
- delay(1000);
|
|
|
- }
|
|
|
- while (count>0)
|
|
|
- {
|
|
|
- fullPress();
|
|
|
- delay(ms);
|
|
|
- digitalWrite(D2, LOW);
|
|
|
- count--;
|
|
|
- delay(delayMs);
|
|
|
- }
|
|
|
- }
|
|
|
- digitalWrite(LED_BUILTIN, LOW);
|
|
|
- request->send(200,"application/json","{\"result\":\"true\"}");
|
|
|
- });
|
|
|
- server.on("/get", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(200, "text/plain", "Is working"); });
|
|
|
- server.begin();
|
|
|
+ Serial.println("Hardware initialized");
|
|
|
}
|
|
|
|
|
|
-void halfPress()
|
|
|
-{
|
|
|
- digitalWrite(D1, HIGH);
|
|
|
- isFocusPressed = true;
|
|
|
-}
|
|
|
-
|
|
|
-void fullPress()
|
|
|
-{
|
|
|
- if (!isFocusPressed)
|
|
|
- {
|
|
|
- halfPress();
|
|
|
- delay(1000);
|
|
|
- }
|
|
|
-
|
|
|
- digitalWrite(D2, HIGH);
|
|
|
-}
|
|
|
-
|
|
|
-void pressFullWithDelay(int ms)
|
|
|
-{
|
|
|
- fullPress();
|
|
|
- delay(ms);
|
|
|
- unPress();
|
|
|
-}
|
|
|
-
|
|
|
-void unPress()
|
|
|
-{
|
|
|
- digitalWrite(D2, LOW);
|
|
|
- digitalWrite(D1, LOW);
|
|
|
- isFocusPressed = false;
|
|
|
-}
|
|
|
-
|
|
|
-void multipleShoot(int ms, int count, int delayMs)
|
|
|
-{
|
|
|
- if (!isFocusPressed)
|
|
|
- {
|
|
|
- halfPress();
|
|
|
- delay(1000);
|
|
|
- }
|
|
|
- while (count>0)
|
|
|
- {
|
|
|
- fullPress();
|
|
|
- delay(ms);
|
|
|
- digitalWrite(D2, LOW);
|
|
|
- count--;
|
|
|
- delay(delayMs);
|
|
|
- }
|
|
|
+/// <summary>
|
|
|
+/// Arduino setup function called once on device boot.
|
|
|
+/// Initializes all system components in sequence:
|
|
|
+/// 1. Hardware (serial, GPIO pins)
|
|
|
+/// 2. ShutterController for camera control
|
|
|
+/// 3. HTTPServer with WiFi access point
|
|
|
+/// After setup completes, the device is ready to accept API requests.
|
|
|
+/// </summary>
|
|
|
+void setup() {
|
|
|
+ // Initialize hardware (serial and pins)
|
|
|
+ initializeHardware();
|
|
|
+
|
|
|
+ // Initialize ShutterController
|
|
|
+ shutterController = new ShutterController(D1, D2);
|
|
|
+
|
|
|
+ // Initialize HTTPServer
|
|
|
+ httpServer = new HTTPServer(Config::HTTP_PORT, shutterController);
|
|
|
+ httpServer->begin(ssid, password, local_IP, gateway, subnet);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+/// <summary>
|
|
|
+/// Arduino loop function called repeatedly after setup completes.
|
|
|
+/// Currently empty as the HTTP server runs asynchronously via interrupts.
|
|
|
+/// Can be extended in the future for periodic tasks or health monitoring.
|
|
|
+/// </summary>
|
|
|
void loop() {
|
|
|
// put your main code here, to run repeatedly:
|
|
|
|