Debug dongle test code
This commit is contained in:
214
data/index_offline.html
Normal file
214
data/index_offline.html
Normal file
@@ -0,0 +1,214 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>ESP32 Debug Dongle (Offline)</title>
|
||||
<style>
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body {
|
||||
font-family: monospace;
|
||||
background: #1a1a2e;
|
||||
color: #eee;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.header {
|
||||
background: #16213e;
|
||||
padding: 10px 15px;
|
||||
display: flex;
|
||||
gap: 15px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
border-bottom: 1px solid #0f3460;
|
||||
}
|
||||
.header h1 { font-size: 1em; color: #e94560; }
|
||||
select, button, input {
|
||||
background: #0f3460;
|
||||
color: #fff;
|
||||
border: 1px solid #1a1a2e;
|
||||
padding: 5px 10px;
|
||||
border-radius: 3px;
|
||||
font-family: monospace;
|
||||
}
|
||||
.terminal-wrap {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 10px;
|
||||
overflow: hidden;
|
||||
}
|
||||
#output {
|
||||
flex: 1;
|
||||
background: #0d0d1a;
|
||||
border: 1px solid #333;
|
||||
padding: 10px;
|
||||
overflow-y: auto;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
font-size: 14px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
#inputLine {
|
||||
display: flex;
|
||||
margin-top: 5px;
|
||||
}
|
||||
#input {
|
||||
flex: 1;
|
||||
background: #0d0d1a;
|
||||
border: 1px solid #333;
|
||||
color: #4ade80;
|
||||
padding: 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
#input:focus { outline: 1px solid #e94560; }
|
||||
.status { font-size: 0.8em; color: #666; }
|
||||
.status.connected { color: #4ade80; }
|
||||
.green { color: #4ade80; }
|
||||
.red { color: #ef4444; }
|
||||
.yellow { color: #fbbf24; }
|
||||
.cyan { color: #22d3d3; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1>🔌 ESP32 Debug</h1>
|
||||
<select id="port">
|
||||
<option value="0">Internal</option>
|
||||
<option value="1">USB</option>
|
||||
<option value="2">External</option>
|
||||
</select>
|
||||
<select id="baud">
|
||||
<option value="9600">9600</option>
|
||||
<option value="115200" selected>115200</option>
|
||||
<option value="921600">921600</option>
|
||||
</select>
|
||||
<button onclick="clear_()">Clear</button>
|
||||
<button onclick="reconnect()">Reconnect</button>
|
||||
<span id="status" class="status">Disconnected</span>
|
||||
</div>
|
||||
<div class="terminal-wrap">
|
||||
<div id="output"></div>
|
||||
<div id="inputLine">
|
||||
<input type="text" id="input" placeholder="Type and press Enter..." autofocus>
|
||||
<button onclick="sendInput()">Send</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const output = document.getElementById('output');
|
||||
const input = document.getElementById('input');
|
||||
const status = document.getElementById('status');
|
||||
let ws = null;
|
||||
let history = [];
|
||||
let histIdx = 0;
|
||||
|
||||
function log(msg, cls='') {
|
||||
const span = document.createElement('span');
|
||||
if(cls) span.className = cls;
|
||||
span.textContent = msg;
|
||||
output.appendChild(span);
|
||||
output.scrollTop = output.scrollHeight;
|
||||
}
|
||||
|
||||
function connect() {
|
||||
log('Connecting...\\n', 'yellow');
|
||||
ws = new WebSocket('ws://' + location.host + '/ws');
|
||||
ws.binaryType = 'arraybuffer';
|
||||
|
||||
ws.onopen = () => {
|
||||
log('Connected!\\n', 'green');
|
||||
status.textContent = 'Connected';
|
||||
status.className = 'status connected';
|
||||
sendCmd({cmd:'getStatus'});
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
log('Disconnected\\n', 'red');
|
||||
status.textContent = 'Disconnected';
|
||||
status.className = 'status';
|
||||
setTimeout(connect, 3000);
|
||||
};
|
||||
|
||||
ws.onmessage = (e) => {
|
||||
const data = new Uint8Array(e.data);
|
||||
if(data[0] === 0) {
|
||||
// Command response
|
||||
try {
|
||||
const json = JSON.parse(new TextDecoder().decode(data.slice(1)));
|
||||
if(json.type === 'status') {
|
||||
document.getElementById('port').value = json.currentPort;
|
||||
document.getElementById('baud').value = json.baudSerial1;
|
||||
} else if(json.type === 'portChanged') {
|
||||
log('[Port changed]\\n', 'yellow');
|
||||
}
|
||||
} catch(e) {}
|
||||
} else {
|
||||
output.appendChild(document.createTextNode(new TextDecoder().decode(data)));
|
||||
output.scrollTop = output.scrollHeight;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function sendCmd(cmd) {
|
||||
if(ws && ws.readyState === 1) {
|
||||
const json = JSON.stringify(cmd);
|
||||
const arr = new Uint8Array(json.length + 1);
|
||||
arr[0] = 0;
|
||||
for(let i=0; i<json.length; i++) arr[i+1] = json.charCodeAt(i);
|
||||
ws.send(arr);
|
||||
}
|
||||
}
|
||||
|
||||
function sendData(str) {
|
||||
if(ws && ws.readyState === 1) {
|
||||
ws.send(new TextEncoder().encode(str));
|
||||
}
|
||||
}
|
||||
|
||||
function sendInput() {
|
||||
const val = input.value;
|
||||
if(val) {
|
||||
history.push(val);
|
||||
histIdx = history.length;
|
||||
sendData(val + '\\r\\n');
|
||||
log('> ' + val + '\\n', 'cyan');
|
||||
input.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
function clear_() {
|
||||
output.innerHTML = '';
|
||||
}
|
||||
|
||||
function reconnect() {
|
||||
if(ws) ws.close();
|
||||
}
|
||||
|
||||
input.addEventListener('keydown', (e) => {
|
||||
if(e.key === 'Enter') sendInput();
|
||||
else if(e.key === 'ArrowUp' && histIdx > 0) {
|
||||
histIdx--;
|
||||
input.value = history[histIdx];
|
||||
} else if(e.key === 'ArrowDown' && histIdx < history.length) {
|
||||
histIdx++;
|
||||
input.value = history[histIdx] || '';
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('port').onchange = (e) => {
|
||||
sendCmd({cmd:'setPort', port:parseInt(e.target.value)});
|
||||
};
|
||||
|
||||
document.getElementById('baud').onchange = (e) => {
|
||||
const port = parseInt(document.getElementById('port').value);
|
||||
sendCmd({cmd:'setBaud', port:port, baud:parseInt(e.target.value)});
|
||||
};
|
||||
|
||||
log('ESP32 Debug Dongle - Offline Version\\n', 'cyan');
|
||||
log('(Lightweight terminal without xterm.js)\\n\\n');
|
||||
connect();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user