[ai] memory optimizations, wifi reset, battery

This commit is contained in:
2025-11-30 17:06:20 +01:00
parent 34c499bd49
commit 9c937dc62d
8 changed files with 220 additions and 68 deletions

View File

@@ -115,6 +115,24 @@ function loadDirectory() {
xhr.send();
}
function resetWifi() {
if (!confirm('Are you sure you want to reset WiFi settings? The device will restart and create an access point.')) {
return;
}
var xhr = new XMLHttpRequest();
xhr.open('POST', '/reset_wifi', true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status >= 200 && xhr.status < 300) {
alert('WiFi settings reset. Device is restarting...');
} else {
alert('Reset failed: ' + (xhr.responseText || 'Unknown error'));
}
}
};
xhr.send();
}
function loadMapping() {
var el = document.getElementById('mappingList');
if (!el) return;
@@ -241,6 +259,25 @@ function displayState(state) {
var voltageEl = document.getElementById("voltage");
if (voltageEl) voltageEl.innerHTML = (state['voltage'] || '') + ' mV';
// Update header battery indicator
var headerBattery = document.getElementById("batteryStatus");
if (headerBattery) {
var mv = state['voltage'] || 0;
if (mv > 0) {
// Estimate percentage for single cell LiPo (approx 3.3V - 4.2V)
var pct = Math.round((mv - 3300) / (4200 - 3300) * 100);
if (pct < 0) pct = 0;
if (pct > 100) pct = 100;
headerBattery.innerHTML =
'<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" style="opacity:0.7"><path d="M16 4h-1V2a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v2H8a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2z"/></svg>' +
'<span>' + pct + '%</span>';
headerBattery.title = mv + ' mV';
} else {
headerBattery.innerHTML = '';
}
}
var heapEl = document.getElementById("heap");
if (heapEl) heapEl.innerHTML = (state['heap'] || '') + ' bytes free heap';