|
@@ -1,14 +1,15 @@
|
|
|
#include "HTTPServer.h"
|
|
#include "HTTPServer.h"
|
|
|
|
|
+#include "Config.h"
|
|
|
#include <Arduino.h>
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
-/// Constructs an HTTPServer instance with the specified port and shutter controller.
|
|
|
|
|
|
|
+/// Constructs an HTTPServer instance using Config::HTTP_PORT.
|
|
|
/// Creates a new AsyncWebServer instance but does not start it yet.
|
|
/// Creates a new AsyncWebServer instance but does not start it yet.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
-HTTPServer::HTTPServer(uint16_t port, IShutterController* controller)
|
|
|
|
|
|
|
+HTTPServer::HTTPServer(IShutterController* controller)
|
|
|
: shutterController(controller)
|
|
: shutterController(controller)
|
|
|
{
|
|
{
|
|
|
- server = new AsyncWebServer(port);
|
|
|
|
|
|
|
+ server = new AsyncWebServer(Config::HTTP_PORT);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -23,17 +24,16 @@ HTTPServer::~HTTPServer()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
-/// Configures the ESP8266 as a WiFi access point with the provided credentials.
|
|
|
|
|
-/// Sets up the static IP configuration and starts the access point.
|
|
|
|
|
|
|
+/// Configures the ESP8266 as a WiFi access point using Config WiFi settings.
|
|
|
|
|
+/// Uses Config::WIFI_IP, Config::WIFI_GATEWAY, and Config::WIFI_SUBNET for softAPConfig.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
-void HTTPServer::setupWiFiAP(const char* ssid, const char* password,
|
|
|
|
|
- IPAddress local_IP, IPAddress gateway, IPAddress subnet)
|
|
|
|
|
|
|
+void HTTPServer::setupWiFiAP()
|
|
|
{
|
|
{
|
|
|
- if (!WiFi.softAPConfig(local_IP, gateway, subnet))
|
|
|
|
|
|
|
+ if (!WiFi.softAPConfig(Config::WIFI_IP, Config::WIFI_GATEWAY, Config::WIFI_SUBNET))
|
|
|
{
|
|
{
|
|
|
Serial.println("Failed to config IP");
|
|
Serial.println("Failed to config IP");
|
|
|
}
|
|
}
|
|
|
- WiFi.softAP(ssid, password);
|
|
|
|
|
|
|
+ WiFi.softAP(Config::WIFI_SSID, Config::WIFI_PASSWORD);
|
|
|
Serial.println(WiFi.softAPIP());
|
|
Serial.println(WiFi.softAPIP());
|
|
|
Serial.println("AP Started - Waiting for connections");
|
|
Serial.println("AP Started - Waiting for connections");
|
|
|
}
|
|
}
|
|
@@ -187,19 +187,19 @@ void HTTPServer::handleRoot(AsyncWebServerRequest *request)
|
|
|
</head>
|
|
</head>
|
|
|
<body>
|
|
<body>
|
|
|
<div class="container">
|
|
<div class="container">
|
|
|
- <h1>📷 Minolta Remote</h1>
|
|
|
|
|
|
|
+ <h1>Minolta Remote</h1>
|
|
|
|
|
|
|
|
<div class="section">
|
|
<div class="section">
|
|
|
<h2>Basic Controls</h2>
|
|
<h2>Basic Controls</h2>
|
|
|
- <button class="btn-focus" onclick="sendRequest('/api/focus')">🎯 Focus</button>
|
|
|
|
|
- <button class="btn-photo" onclick="sendRequest('/api/takePhoto')">📸 Take Photo</button>
|
|
|
|
|
- <button class="btn-reset" onclick="sendRequest('/api/reset')">🔄 Reset</button>
|
|
|
|
|
|
|
+ <button class="btn-focus" onclick="sendRequest('/api/focus')">Focus</button>
|
|
|
|
|
+ <button class="btn-photo" onclick="sendRequest('/api/takePhoto')">Take Photo</button>
|
|
|
|
|
+ <button class="btn-reset" onclick="sendRequest('/api/reset')">Reset</button>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div class="section">
|
|
<div class="section">
|
|
|
<h2>Photo Hold Duration</h2>
|
|
<h2>Photo Hold Duration</h2>
|
|
|
<input type="number" id="msec" min="100" max="5000" value="1000" placeholder="Duration (ms)">
|
|
<input type="number" id="msec" min="100" max="5000" value="1000" placeholder="Duration (ms)">
|
|
|
- <button class="btn-photo" onclick="takePhotoWithDelay()">📸 Take with Delay</button>
|
|
|
|
|
|
|
+ <button class="btn-photo" onclick="takePhotoWithDelay()">Take with Delay</button>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div class="section">
|
|
<div class="section">
|
|
@@ -211,7 +211,7 @@ void HTTPServer::handleRoot(AsyncWebServerRequest *request)
|
|
|
<div class="input-group">
|
|
<div class="input-group">
|
|
|
<input type="number" id="msecMulti" min="100" max="5000" value="1000" placeholder="Duration (ms)">
|
|
<input type="number" id="msecMulti" min="100" max="5000" value="1000" placeholder="Duration (ms)">
|
|
|
</div>
|
|
</div>
|
|
|
- <button class="btn-multiple" onclick="multipleShoot()">🎬 Multiple Shots</button>
|
|
|
|
|
|
|
+ <button class="btn-multiple" onclick="multipleShoot()">Multiple Shots</button>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div id="status" class="status"></div>
|
|
<div id="status" class="status"></div>
|
|
@@ -222,12 +222,12 @@ void HTTPServer::handleRoot(AsyncWebServerRequest *request)
|
|
|
fetch(endpoint)
|
|
fetch(endpoint)
|
|
|
.then(response => {
|
|
.then(response => {
|
|
|
if (response.ok) {
|
|
if (response.ok) {
|
|
|
- showStatus('✓ Success: ' + endpoint, 'success');
|
|
|
|
|
|
|
+ showStatus('Success: ' + endpoint, 'success');
|
|
|
} else {
|
|
} else {
|
|
|
- showStatus('✗ Error: ' + response.statusText, 'error');
|
|
|
|
|
|
|
+ showStatus('Error: ' + response.statusText, 'error');
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
- .catch(error => showStatus('✗ Connection Error', 'error'));
|
|
|
|
|
|
|
+ .catch(error => showStatus('Connection Error', 'error'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function takePhotoWithDelay() {
|
|
function takePhotoWithDelay() {
|
|
@@ -235,12 +235,12 @@ void HTTPServer::handleRoot(AsyncWebServerRequest *request)
|
|
|
fetch('/api/takePhoto?msec=' + msec)
|
|
fetch('/api/takePhoto?msec=' + msec)
|
|
|
.then(response => {
|
|
.then(response => {
|
|
|
if (response.ok) {
|
|
if (response.ok) {
|
|
|
- showStatus('✓ Photo taken (' + msec + 'ms)', 'success');
|
|
|
|
|
|
|
+ showStatus('Photo taken (' + msec + 'ms)', 'success');
|
|
|
} else {
|
|
} else {
|
|
|
- showStatus('✗ Error taking photo', 'error');
|
|
|
|
|
|
|
+ showStatus('Error taking photo', 'error');
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
- .catch(error => showStatus('✗ Connection Error', 'error'));
|
|
|
|
|
|
|
+ .catch(error => showStatus('Connection Error', 'error'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function multipleShoot() {
|
|
function multipleShoot() {
|
|
@@ -249,19 +249,19 @@ void HTTPServer::handleRoot(AsyncWebServerRequest *request)
|
|
|
const msec = document.getElementById('msecMulti').value;
|
|
const msec = document.getElementById('msecMulti').value;
|
|
|
|
|
|
|
|
if (count < 1 || count > 100) {
|
|
if (count < 1 || count > 100) {
|
|
|
- showStatus('✗ Count must be between 1 and 100', 'error');
|
|
|
|
|
|
|
+ showStatus('Count must be between 1 and 100', 'error');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fetch('/api/multiple?count=' + count + '&delay=' + delay + '&msec=' + msec)
|
|
fetch('/api/multiple?count=' + count + '&delay=' + delay + '&msec=' + msec)
|
|
|
.then(response => {
|
|
.then(response => {
|
|
|
if (response.ok) {
|
|
if (response.ok) {
|
|
|
- showStatus('✓ ' + count + ' shots queued', 'success');
|
|
|
|
|
|
|
+ showStatus(count + ' shots queued', 'success');
|
|
|
} else {
|
|
} else {
|
|
|
- showStatus('✗ Error taking photos', 'error');
|
|
|
|
|
|
|
+ showStatus('Error taking photos', 'error');
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
- .catch(error => showStatus('✗ Connection Error', 'error'));
|
|
|
|
|
|
|
+ .catch(error => showStatus('Connection Error', 'error'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function showStatus(message, type) {
|
|
function showStatus(message, type) {
|
|
@@ -383,14 +383,12 @@ void HTTPServer::onRequestEnd(const char* endpoint)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
-/// Initializes the WiFi access point and starts the HTTP server.
|
|
|
|
|
-/// Must be called during application setup to enable the server.
|
|
|
|
|
-/// Calls setupWiFiAP() to configure WiFi, setupRoutes() to register endpoints, and starts the server.
|
|
|
|
|
|
|
+/// Initializes the WiFi access point using Config settings and starts the HTTP server.
|
|
|
|
|
+/// Calls setupWiFiAP() to configure WiFi, then setupRoutes() to register API endpoints.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
-void HTTPServer::begin(const char* ssid, const char* password,
|
|
|
|
|
- IPAddress local_IP, IPAddress gateway, IPAddress subnet)
|
|
|
|
|
|
|
+void HTTPServer::begin()
|
|
|
{
|
|
{
|
|
|
- setupWiFiAP(ssid, password, local_IP, gateway, subnet);
|
|
|
|
|
|
|
+ setupWiFiAP();
|
|
|
setupRoutes();
|
|
setupRoutes();
|
|
|
server->begin();
|
|
server->begin();
|
|
|
Serial.println("HTTP Server started");
|
|
Serial.println("HTTP Server started");
|