#include #include #include #include #include "settings_service.h" const char *index_html = R"rawliteral( Party Cam Config

Party Cam Settings

Camera


Printer

Upload (Webhook)

)rawliteral"; SettingsService::SettingsService() : server(80) {} void SettingsService::begin() { // 1. Load saved values loadSettings(); WiFiManager wm; wm.setConfigPortalTimeout(180); // 3 minutes String apName = "PartyCam-Setup"; Serial.println("Connecting to WiFi..."); if (!wm.autoConnect(apName.c_str())) { Serial.println("WiFi failed to connect (Timeout). Starting in Offline Mode."); } else { Serial.println("WiFi Connected!"); Serial.print("IP Address: "); Serial.println(WiFi.localIP()); if (MDNS.begin("partycam")) { Serial.println("mDNS responder started: http://partycam.local"); } } // 3. Setup Web Server setupRoutes(); server.begin(); } void SettingsService::loadSettings() { prefs.begin("partycam", false); // Namespace "partycam" currentSettings.contrast = prefs.getInt("contrast", 0); currentSettings.brightness = prefs.getInt("bright", 0); currentSettings.vFlip = prefs.getBool("vflip", false); currentSettings.hMirror = prefs.getBool("hmirror", false); currentSettings.heatTime = prefs.getInt("heat", 120); currentSettings.uploadUrl = prefs.getString("url", ""); currentSettings.enableUpload = prefs.getBool("ena_upload", false); prefs.end(); } void SettingsService::save() { prefs.begin("partycam", false); prefs.putInt("contrast", currentSettings.contrast); prefs.putInt("bright", currentSettings.brightness); prefs.putBool("vflip", currentSettings.vFlip); prefs.putBool("hmirror", currentSettings.hMirror); prefs.putInt("heat", currentSettings.heatTime); prefs.putString("url", currentSettings.uploadUrl); prefs.putBool("ena_upload", currentSettings.enableUpload); prefs.end(); } void SettingsService::setupRoutes() { server.on("/", HTTP_GET, [this]() { String html = index_html; // Simple template replacement html.replace("%CONTRAST%", String(currentSettings.contrast)); html.replace("%BRIGHTNESS%", String(currentSettings.brightness)); html.replace("%VFLIP%", currentSettings.vFlip ? "checked" : ""); html.replace("%HMIRROR%", currentSettings.hMirror ? "checked" : ""); html.replace("%HEAT%", String(currentSettings.heatTime)); html.replace("%URL%", currentSettings.uploadUrl); html.replace("%UPLOAD%", currentSettings.enableUpload ? "checked" : ""); server.send(200, "text/html", html); }); server.on("/save", HTTP_POST, [this]() { if (server.hasArg("contrast")) currentSettings.contrast = server.arg("contrast").toInt(); if (server.hasArg("brightness")) currentSettings.brightness = server.arg("brightness").toInt(); if (server.hasArg("heat")) currentSettings.heatTime = server.arg("heat").toInt(); currentSettings.uploadUrl = server.arg("url"); currentSettings.vFlip = server.hasArg("vflip"); currentSettings.hMirror = server.hasArg("hmirror"); currentSettings.enableUpload = server.hasArg("upload"); save(); server.send(200, "text/html", "Settings Saved! Go Back"); // Apply immediate camera changes if needed sensor_t *s = esp_camera_sensor_get(); if (s) { s->set_contrast(s, currentSettings.contrast); s->set_brightness(s, currentSettings.brightness); s->set_vflip(s, currentSettings.vFlip ? 1 : 0); s->set_hmirror(s, currentSettings.hMirror ? 1 : 0); } }); } void SettingsService::handle() { server.handleClient(); }