-
Notifications
You must be signed in to change notification settings - Fork 0
/
multidevice_example.html
48 lines (44 loc) · 1.92 KB
/
multidevice_example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>fibre-js Test</title>
<style>
div {
font-size : 30px; text-align : left; color:darkblue;
}
</style>
</head>
<body>
<div id="textcontent">loading...</div>
<script type="module">
import { fibreOpen } from './fibre.js';
const filter = 'usb:idVendor=0x1209,idProduct=0x0D32,bInterfaceClass=0,bInterfaceSubClass=1,bInterfaceProtocol=0';
const showStatus = (status) => document.getElementById("textcontent").innerHTML = status;
const connectedObjects = [];
const displayLoop = async () => {
while (connectedObjects.length) {
let results = await Promise.all(connectedObjects.map(async (dev) => await dev.vbus_voltage.read()));
showStatus('connected to ' + results.length + ' devices' + results.map((x) => "<br>vbus_voltage: " + x + "V").join());
await new Promise((resolve) => setTimeout(resolve, 100));
}
showStatus("no devices connected");
}
let onFoundObject = async (obj) => {
connectedObjects.push(obj);
obj._onLost.then(() => connectedObjects.splice(connectedObjects.indexOf(obj), 1));
if (connectedObjects.length == 1) {
displayLoop();
}
}
fibreOpen().then((libfibre) => {
const domain = libfibre.openDomain(filter);
domain.startDiscovery(onFoundObject);
document.getElementById("connectBtn").onclick = libfibre.usbDiscoverer.showDialog;
document.getElementById("connectBtn").removeAttribute('disabled');
showStatus("loaded WASM libfibre version " + libfibre.version.major + "." + libfibre.version.minor + "." + libfibre.version.patch);
});
</script>
<button id="connectBtn" disabled>Connect</button>
</body>
</html>