Files
FilaMan-System-ESP32/data/waage.html
T
Manuel Weiser 526b25ba1e Refactor upgrade, scale, and WiFi pages for improved UI and functionality
- Updated page titles and structure for clarity.
- Enhanced sidebar navigation and status indicators.
- Improved form styling and user feedback during updates.
- Added WebSocket handling for real-time status updates.
- Streamlined version fetching logic across pages.
2026-02-21 10:49:59 +01:00

155 lines
6.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FilaMan - Scale Configuration</title>
<link rel="icon" type="image/png" href="/favicon.ico">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="fm-page">
<aside class="fm-sidebar">
<div class="sidebar-brand">
<img src="/logo.png" alt="Logo" class="sidebar-logo">
<div class="brand-text">
<h1>FilaMan <span class="version"></span></h1>
</div>
</div>
<nav class="fm-nav">
<a href="/">Start</a>
<a href="/waage" class="active">Scale</a>
<a href="/setup">Setup</a>
<a href="/upgrade">Upgrade</a>
</nav>
<div class="sidebar-status">
<div class="status-item">
<span class="status-dot" id="filamanDot"></span>
<span>System Sync</span>
</div>
<div class="status-item">
<span id="ramStatus"></span>
</div>
</div>
</aside>
<main class="fm-main">
<header>
<h1>Scale Configuration</h1>
<p>Manage and calibrate your built-in scale for precise filament weighing.</p>
</header>
<div class="fm-card">
<h2>Scale Actions</h2>
<div style="display: flex; gap: 1rem; align-items: center; flex-wrap: wrap;">
<button id="calibrateBtn" class="fm-btn fm-btn-primary">Calibrate Scale</button>
<button id="tareBtn" class="fm-btn fm-btn-outline">Tare Scale</button>
<label class="status-pill" style="display: flex; align-items: center; gap: 0.5rem; cursor: pointer;">
<input type="checkbox" id="autoTareCheckbox" onchange="setAutoTare(this.checked);" {{autoTare}}>
<span>Enable Auto-TARE</span>
</label>
</div>
<div id="statusMessage" style="margin-top: 1.5rem; color: var(--accent);"></div>
</div>
<div id="calibrationCard" class="fm-card" style="display: none; border-color: var(--error-text);">
<h2>Calibration Procedure</h2>
<p>Follow these steps carefully to ensure accuracy:</p>
<ol style="margin-left: 1.5rem; margin-bottom: 1.5rem; color: var(--text-muted);">
<li>Ensure the scale is completely empty.</li>
<li>Prepare a 500g calibration weight.</li>
<li>Click "Start Calibration" below.</li>
<li>Step 1: Wait for zero-point reading.</li>
<li>Step 2: Place the 500g weight on the scale when prompted.</li>
<li>Step 3: Remove the weight.</li>
</ol>
<button id="startCalibrationBtn" class="fm-btn fm-btn-danger">Start Calibration</button>
</div>
</main>
</div>
<script>
// Fetch Version
fetch('/api/version')
.then(response => response.json())
.then(data => {
const versionSpan = document.querySelector('.version');
if (versionSpan) versionSpan.textContent = 'v' + data.version;
})
.catch(error => console.error('Error fetching version:', error));
let ws = null;
const statusMessage = document.getElementById('statusMessage');
function connectWebSocket() {
ws = new WebSocket(`ws://${window.location.hostname}/ws`);
ws.onopen = () => {
statusMessage.textContent = 'Scale connected via WebSocket';
enableButtons(true);
};
ws.onclose = () => {
statusMessage.textContent = 'Scale connection lost. Reconnecting...';
enableButtons(false);
setTimeout(connectWebSocket, 2000);
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'heartbeat') {
const dot = document.getElementById('filamanDot');
dot.className = data.filaman_connected ? 'status-dot online' : 'status-dot offline';
document.getElementById('ramStatus').textContent = data.freeHeap + ' KB free';
}
if (data.type === 'scale') {
if (data.payload === 'success') {
statusMessage.textContent = 'Action successful';
statusMessage.style.color = 'var(--success-text)';
} else if (data.payload === 'error') {
statusMessage.textContent = 'Error while performing action';
statusMessage.style.color = 'var(--error-text)';
}
}
};
}
function enableButtons(enabled) {
document.getElementById('calibrateBtn').disabled = !enabled;
document.getElementById('tareBtn').disabled = !enabled;
}
document.getElementById('calibrateBtn').addEventListener('click', () => {
document.getElementById('calibrationCard').style.display = 'block';
});
document.getElementById('startCalibrationBtn').addEventListener('click', () => {
ws.send(JSON.stringify({
type: 'scale',
payload: 'calibrate'
}));
document.getElementById('calibrationCard').style.display = 'none';
});
document.getElementById('tareBtn').addEventListener('click', () => {
ws.send(JSON.stringify({
type: 'scale',
payload: 'tare'
}));
});
function setAutoTare(enabled) {
ws.send(JSON.stringify({
type: 'scale',
payload: 'setAutoTare',
enabled: enabled
}));
}
connectWebSocket();
setInterval(() => { if(ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({type:'heartbeat'})); }, 5000);
</script>
</body>
</html>