зеркало из https://github.com/microsoft/jacdac-ts.git
74 строки
1.9 KiB
HTML
74 строки
1.9 KiB
HTML
<html>
|
|
|
|
<head>
|
|
<style>
|
|
body {
|
|
font-family: monospace;
|
|
}
|
|
|
|
.segment {
|
|
padding: 0.5rem;
|
|
margin: 0.5rem;
|
|
}
|
|
|
|
#log {
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
#log>div {
|
|
margin: 0.25rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>JACDAC/Console</h1>
|
|
<div>
|
|
<button id="connect">connect to jacdac device</button>
|
|
</div>
|
|
<div id="devices" class="segment"></div>
|
|
<div id="log" class="segment">
|
|
<div>waiting for message...</div>
|
|
</div>
|
|
|
|
<script src="/dist/jacdac.umd.js"></script>
|
|
<script>
|
|
const devicesDiv = document.getElementById("devices");
|
|
|
|
async function sniff() {
|
|
log('starting')
|
|
let bus;
|
|
try {
|
|
bus = await jacdac.requestUSBBus();
|
|
bus.minConsolePriority = jacdac.ConsolePriority.Debug;
|
|
bus.on('deviceconnect', d => {
|
|
devicesDiv.innerText = bus.devices().map(d => d.toString()).join(', ')
|
|
});
|
|
bus.on('packetreceive', pkt => {
|
|
const decoded = jacdac.decodePacketData(pkt);
|
|
console.debug(jacdac.printPacket(pkt))
|
|
if (decoded)
|
|
log(decoded)
|
|
})
|
|
log('started')
|
|
} catch (err) {
|
|
log(err)
|
|
await bus.disconnect()
|
|
}
|
|
}
|
|
|
|
const connect = document.getElementById("connect");
|
|
connect.onclick = sniff;
|
|
|
|
function log(msg) {
|
|
const logDiv = document.getElementById("log");
|
|
const line = document.createElement("div");
|
|
line.innerText = "" + msg;
|
|
logDiv.insertBefore(line, logDiv.firstElementChild);
|
|
if (logDiv.childElementCount > 100)
|
|
logDiv.lastElementChild.remove();
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html> |