Skip to content

Commit

Permalink
modified webserver
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalkbrenner committed Dec 18, 2024
1 parent cf7509d commit 6e30707
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 79 deletions.
83 changes: 11 additions & 72 deletions data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ <h2 class="section-header">Display Settings</h2>
<br>
<!-- Status Message -->
<div id="display-status" class="status-message"></div>
<button onclick="apply()">Apply</button>
</div>

<!-- Information Section -->
Expand Down Expand Up @@ -410,6 +411,16 @@ <h3>Debug Information</h3>
xhr.send(`brightness=${brightness}`);
}

function apply() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/applyt", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
alert("Device will reboot.");
}
};
xhr.send();
}

function toggleDebugInfo() {
var debugInfoDiv = document.getElementById('debug-info');
Expand Down Expand Up @@ -488,67 +499,6 @@ <h3>Debug Information</h3>
xhr.send(formData);
}

function previewScreensaver() {
var xhr = new XMLHttpRequest();
xhr.open("GET", "/preview_screensaver", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
var uploadStatus = document.getElementById('uploadStatus');
if (xhr.status === 200) {
uploadStatus.innerText = "Preview successful!";
document.getElementById('preview').src = "/screensaver.jpg"; // Display the saved image
} else {
uploadStatus.innerText = "Error: " + xhr.responseText;
}
}
};
xhr.send();
}

function toggleDimOptions() {
var showImageChecked = document.getElementById('showImage').checked;
var dimOptions = document.getElementById('dimOptions');
dimOptions.style.display = showImageChecked ? 'block' : 'none';
}

function saveScreensaverSettings() {
// Get the selected screensaver mode
var screensaverMode;
if (document.querySelector('input[name="screensaverMode"]:checked').value == "showImage") {
screensaverMode = 1;
}
else {
screensaverMode = 0;
}

var enableDimAfterTimeout = document.getElementById('dimAfterTime').checked ? 1 : 0;

var dimTime = document.getElementById('dimTime').value;

var params = `screensaverMode=${screensaverMode}&enableDimAfterTimeout=${enableDimAfterTimeout}&dimTime=${dimTime}`;

// Send the data to the ESP32 backend using XMLHttpRequest
var xhr = new XMLHttpRequest();
xhr.open("POST", "/save_screensaver_settings", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
var uploadStatus = document.getElementById('uploadStatus');
if (xhr.status === 200) {
uploadStatus.innerText = "Settings saved successfully!";
uploadStatus.style.color = "green";
} else {
uploadStatus.innerText = "Error saving settings.";
uploadStatus.style.color = "red";
}
}
};

// Send the data to the backend
xhr.send(params);
}

// Load the current config and populate the form fields
function loadConfig() {
var xhr = new XMLHttpRequest();
Expand All @@ -561,17 +511,6 @@ <h3>Debug Information</h3>
document.getElementById("rgb-order").value = config.rgbOrder;
document.getElementById("brightness").value = config.brightness;

// Set the correct radio button for screensaverMode
if (config.screensaverMode == 0) {
document.getElementById("dimScreen").checked = true; // For clearscreen
} else if (config.screensaverMode == 1) {
document.getElementById("showImage").checked = true; // For show image
}

// Set the checkbox and dim timeout for dim options
document.getElementById("dimAfterTime").checked = config.enableDimAfterTimeout == 1;
document.getElementById("dimTime").value = config.dimTimeout;

document.getElementById("scaling-mode").value = config.scaleMode;

// Optionally, show/hide dim options if showImage is selected
Expand Down
9 changes: 5 additions & 4 deletions src/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,17 @@ void runWebServer() {
request->send(LittleFS, "/ppuc.png", "image/png");
});

server.on("/screensaver.jpg", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(LittleFS, "/screensaver.jpg", "image/jpg");
});

server.on("/reset_wifi", HTTP_POST, [](AsyncWebServerRequest *request) {
LittleFS.remove("/wifi_config.txt"); // Remove Wi-Fi config
request->send(200, "text/plain", "Wi-Fi reset successful.");
Restart(); // Restart the device
});

server.on("/apply", HTTP_POST, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", "Apply successful.");
Restart(); // Restart the device
});

// Serve debug information
server.on("/debug_info", HTTP_GET, [](AsyncWebServerRequest *request) {
String debugInfo = "IP Address: " + WiFi.localIP().toString() + "\n";
Expand Down
3 changes: 0 additions & 3 deletions src/webserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ extern uint16_t port;
extern uint8_t ssid_length;
extern uint8_t pwd_length;

extern uint32_t dimTimeout;
extern bool enableDimAfterTimeout;
extern uint8_t screensaverMode;
extern uint8_t lumstep;
extern uint8_t rgbMode;
extern uint8_t rgbModeLoaded;
Expand Down

0 comments on commit 6e30707

Please sign in to comment.