434 lines
16 KiB
C
434 lines
16 KiB
C
#ifndef WEB_SETTINGS_H
|
|
#define WEB_SETTINGS_H
|
|
|
|
const char HTML_SETTINGS[] = R"rawliteral(
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Settings - ESP32 Logger</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
background: #1a1a2e;
|
|
color: #eee;
|
|
line-height: 1.6;
|
|
}
|
|
.header {
|
|
background: #16213e;
|
|
padding: 1rem;
|
|
text-align: center;
|
|
border-bottom: 2px solid #e94560;
|
|
}
|
|
.header h1 { color: #e94560; font-size: 1.5rem; }
|
|
.nav {
|
|
background: #0f3460;
|
|
padding: 0.5rem;
|
|
display: flex;
|
|
justify-content: center;
|
|
flex-wrap: wrap;
|
|
gap: 0.5rem;
|
|
}
|
|
.nav a {
|
|
color: #fff;
|
|
text-decoration: none;
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 4px;
|
|
transition: background 0.3s;
|
|
}
|
|
.nav a:hover, .nav a.active { background: #e94560; }
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 2rem;
|
|
}
|
|
.settings-card {
|
|
background: #16213e;
|
|
padding: 2rem;
|
|
border-radius: 8px;
|
|
margin-bottom: 1rem;
|
|
}
|
|
.settings-card h2 {
|
|
color: #e94560;
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 0.5rem;
|
|
color: #00d9ff;
|
|
}
|
|
.form-group input, .form-group select {
|
|
width: 100%;
|
|
padding: 0.75rem;
|
|
background: #0f3460;
|
|
border: 1px solid #e94560;
|
|
color: #fff;
|
|
border-radius: 4px;
|
|
font-size: 1rem;
|
|
}
|
|
.form-group input:focus {
|
|
outline: none;
|
|
border-color: #00d9ff;
|
|
}
|
|
.btn {
|
|
background: #e94560;
|
|
color: #fff;
|
|
border: none;
|
|
padding: 1rem 2rem;
|
|
font-size: 1rem;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
transition: background 0.3s;
|
|
width: 100%;
|
|
}
|
|
.btn:hover { background: #ff6b6b; }
|
|
.btn-green { background: #00d9ff; color: #000; }
|
|
.btn-green:hover { background: #00b8d4; }
|
|
.status-box {
|
|
background: #0f3460;
|
|
padding: 1rem;
|
|
border-radius: 4px;
|
|
margin-bottom: 1rem;
|
|
}
|
|
.status-row {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
padding: 0.5rem 0;
|
|
border-bottom: 1px solid #1a1a2e;
|
|
}
|
|
.status-row:last-child { border-bottom: none; }
|
|
.status-label { color: #aaa; }
|
|
.status-value { color: #00d9ff; }
|
|
.checkbox-group {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
.checkbox-group input[type="checkbox"] {
|
|
width: 20px;
|
|
height: 20px;
|
|
}
|
|
.row {
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
flex-wrap: wrap;
|
|
}
|
|
.row input, .row select {
|
|
flex: 1;
|
|
min-width: 80px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1>Settings</h1>
|
|
</div>
|
|
<nav class="nav">
|
|
<a href="/">Dashboard</a>
|
|
<a href="/graph">Graph</a>
|
|
<a href="/files">Files</a>
|
|
<a href="/can">CAN Transmit</a>
|
|
<a href="/settings" class="active">Settings</a>
|
|
</nav>
|
|
<div class="container">
|
|
<div class="settings-card">
|
|
<h2>CAN Configuration</h2>
|
|
<div class="status-box">
|
|
<div class="status-row">
|
|
<span class="status-label">CAN Status:</span>
|
|
<span class="status-value" id="canStatus">Active</span>
|
|
</div>
|
|
<div class="status-row">
|
|
<span class="status-label">Current Mode:</span>
|
|
<span class="status-value" id="currentCANMode">Normal</span>
|
|
</div>
|
|
</div>
|
|
|
|
<form id="canForm" onsubmit="saveCANConfig(event)">
|
|
<div class="form-group">
|
|
<label>CAN Type</label>
|
|
<select id="canType" onchange="toggleCANFDOptions()">
|
|
<option value="fd">CAN FD (up to 64 bytes, flexible data rate)</option>
|
|
<option value="classic">Classic CAN (8 bytes, fixed rate)</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="form-group">
|
|
<label>Arbitration Baud</label>
|
|
<select id="arbBaud">
|
|
<option value="125000">125 kbps</option>
|
|
<option value="250000">250 kbps</option>
|
|
<option value="500000" selected>500 kbps</option>
|
|
<option value="1000000">1 Mbps</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group" id="dataBaudGroup">
|
|
<label>Data Baud (CAN FD only)</label>
|
|
<select id="dataBaud">
|
|
<option value="1000000">1 Mbps</option>
|
|
<option value="2000000" selected>2 Mbps</option>
|
|
<option value="4000000">4 Mbps</option>
|
|
<option value="8000000">8 Mbps</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>CAN Mode</label>
|
|
<select id="canMode">
|
|
<option value="0">Normal</option>
|
|
<option value="1">Listen Only</option>
|
|
<option value="2">Loopback</option>
|
|
</select>
|
|
</div>
|
|
|
|
<button type="submit" class="btn">Apply CAN Settings</button>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="settings-card">
|
|
<h2>Signal Configuration</h2>
|
|
<div class="form-group">
|
|
<label>Manual Signal Definition</label>
|
|
<div class="row">
|
|
<input type="text" id="sigName" placeholder="Signal Name" style="flex:1">
|
|
<input type="text" id="sigCanId" placeholder="CAN ID (hex)" style="width:100px">
|
|
</div>
|
|
<div class="row" style="margin-top:0.5rem">
|
|
<input type="number" id="sigStartBit" placeholder="Start Bit" style="width:80px">
|
|
<input type="number" id="sigLength" placeholder="Length" style="width:80px">
|
|
<input type="number" id="sigFactor" placeholder="Factor" value="1" style="width:80px">
|
|
<input type="number" id="sigOffset" placeholder="Offset" value="0" style="width:80px">
|
|
</div>
|
|
<button class="btn" style="margin-top:1rem" onclick="addSignal()">Add Signal</button>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>Upload DBC File</label>
|
|
<input type="file" id="dbcFile" accept=".dbc" onchange="uploadDBC()">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="settings-card">
|
|
<h2>WiFi Configuration</h2>
|
|
<div class="status-box">
|
|
<div class="status-row">
|
|
<span class="status-label">Current Mode:</span>
|
|
<span class="status-value" id="currentMode">AP Mode</span>
|
|
</div>
|
|
<div class="status-row">
|
|
<span class="status-label">AP IP:</span>
|
|
<span class="status-value" id="apIP">192.168.4.1</span>
|
|
</div>
|
|
<div class="status-row">
|
|
<span class="status-label">STA IP:</span>
|
|
<span class="status-value" id="staIP">Not connected</span>
|
|
</div>
|
|
</div>
|
|
|
|
<form id="wifiForm" onsubmit="saveWiFi(event)">
|
|
<div class="form-group checkbox-group">
|
|
<input type="checkbox" id="enableSTA" onchange="toggleSTA()">
|
|
<label for="enableSTA" style="margin-bottom: 0;">Enable STA Mode (Connect to existing WiFi)</label>
|
|
</div>
|
|
|
|
<div id="staConfig" style="display: none;">
|
|
<div class="form-group">
|
|
<label>WiFi SSID</label>
|
|
<input type="text" id="ssid" placeholder="Your WiFi Network">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>WiFi Password</label>
|
|
<input type="password" id="password" placeholder="WiFi Password">
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn">Save WiFi Settings</button>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="settings-card">
|
|
<h2>Time Settings</h2>
|
|
<div class="status-box">
|
|
<div class="status-row">
|
|
<span class="status-label">Current Time:</span>
|
|
<span class="status-value" id="currentTime">--</span>
|
|
</div>
|
|
<div class="status-row">
|
|
<span class="status-label">RTC Status:</span>
|
|
<span class="status-value" id="rtcStatus">OK</span>
|
|
</div>
|
|
</div>
|
|
<button class="btn btn-green" onclick="syncTime()">Sync Time from Device</button>
|
|
</div>
|
|
|
|
<div class="settings-card">
|
|
<h2>System</h2>
|
|
<button class="btn" onclick="restartSystem()">Restart System</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function toggleCANFDOptions() {
|
|
const canType = document.getElementById('canType').value;
|
|
const dataBaudGroup = document.getElementById('dataBaudGroup');
|
|
if (canType === 'classic') {
|
|
dataBaudGroup.style.opacity = '0.5';
|
|
dataBaudGroup.style.pointerEvents = 'none';
|
|
} else {
|
|
dataBaudGroup.style.opacity = '1';
|
|
dataBaudGroup.style.pointerEvents = 'auto';
|
|
}
|
|
}
|
|
|
|
function toggleSTA() {
|
|
const enabled = document.getElementById('enableSTA').checked;
|
|
document.getElementById('staConfig').style.display = enabled ? 'block' : 'none';
|
|
}
|
|
|
|
function saveWiFi(event) {
|
|
event.preventDefault();
|
|
|
|
const config = {
|
|
enableSTA: document.getElementById('enableSTA').checked,
|
|
ssid: document.getElementById('ssid').value,
|
|
password: document.getElementById('password').value
|
|
};
|
|
|
|
fetch('/api/wifi', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify(config)
|
|
})
|
|
.then(() => alert('WiFi settings saved. System will restart.'));
|
|
}
|
|
|
|
function saveCANConfig(event) {
|
|
event.preventDefault();
|
|
|
|
const canType = document.getElementById('canType').value;
|
|
const config = {
|
|
arbBaud: parseInt(document.getElementById('arbBaud').value),
|
|
dataBaud: canType === 'fd' ? parseInt(document.getElementById('dataBaud').value) : parseInt(document.getElementById('arbBaud').value),
|
|
mode: parseInt(document.getElementById('canMode').value),
|
|
enableFD: canType === 'fd'
|
|
};
|
|
|
|
fetch('/api/can/config', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify(config)
|
|
})
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
alert('CAN settings applied!');
|
|
loadStatus();
|
|
});
|
|
}
|
|
|
|
function addSignal() {
|
|
const name = document.getElementById('sigName').value;
|
|
const canId = parseInt(document.getElementById('sigCanId').value, 16);
|
|
const startBit = parseInt(document.getElementById('sigStartBit').value);
|
|
const length = parseInt(document.getElementById('sigLength').value);
|
|
const factor = parseFloat(document.getElementById('sigFactor').value) || 1;
|
|
const offset = parseFloat(document.getElementById('sigOffset').value) || 0;
|
|
|
|
if (!name || isNaN(canId)) {
|
|
alert('Please enter signal name and CAN ID');
|
|
return;
|
|
}
|
|
|
|
fetch('/api/signal/add', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({
|
|
name: name,
|
|
canId: canId,
|
|
startBit: startBit || 0,
|
|
length: length || 8,
|
|
factor: factor,
|
|
offset: offset,
|
|
littleEndian: true,
|
|
signed: false
|
|
})
|
|
})
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
alert('Signal added!');
|
|
document.getElementById('sigName').value = '';
|
|
});
|
|
}
|
|
|
|
function uploadDBC() {
|
|
const file = document.getElementById('dbcFile').files[0];
|
|
if (!file) return;
|
|
|
|
const reader = new FileReader();
|
|
reader.onload = function(e) {
|
|
fetch('/api/dbc/upload', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'text/plain'},
|
|
body: e.target.result
|
|
})
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
if (data.status === 'loaded') {
|
|
alert('DBC file loaded successfully!');
|
|
} else {
|
|
alert('Failed to load DBC: ' + data.error);
|
|
}
|
|
});
|
|
};
|
|
reader.readAsText(file);
|
|
}
|
|
|
|
function syncTime() {
|
|
const now = new Date();
|
|
const timestamp = Math.floor(now.getTime() / 1000);
|
|
|
|
fetch('/api/time', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({timestamp: timestamp})
|
|
})
|
|
.then(() => {
|
|
alert('Time synchronized!');
|
|
loadStatus();
|
|
});
|
|
}
|
|
|
|
function restartSystem() {
|
|
if (!confirm('Restart the system?')) return;
|
|
fetch('/api/restart', {method: 'POST'});
|
|
}
|
|
|
|
function loadStatus() {
|
|
fetch('/api/status')
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
document.getElementById('currentMode').textContent =
|
|
data.ap && data.sta ? 'AP+STA' : (data.ap ? 'AP' : 'STA');
|
|
document.getElementById('apIP').textContent = data.ap_ip || 'N/A';
|
|
document.getElementById('staIP').textContent = data.sta_ip || 'Not connected';
|
|
document.getElementById('canStatus').textContent = data.can.initialized ? 'Active' : 'Inactive';
|
|
});
|
|
|
|
document.getElementById('currentTime').textContent = new Date().toLocaleString();
|
|
}
|
|
|
|
loadStatus();
|
|
setInterval(loadStatus, 30000);
|
|
</script>
|
|
</body>
|
|
</html>
|
|
)rawliteral";
|
|
|
|
#endif // WEB_SETTINGS_H
|