-
Notifications
You must be signed in to change notification settings - Fork 1
/
simpledata.html
25 lines (21 loc) · 986 Bytes
/
simpledata.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
<button id="scan">SCAN</button>
<script>
function scan() {
navigator.hid.requestDevice({filters: [{ vendorId: 0x046d }]}).then(devices => {
if (!devices.length) return;
const device = devices[0];
device.open().then(() => {
console.log('Opened device: ' + device.productName);
device.addEventListener('inputreport', e => {
// First attempt: Print all the data
// console.log('Report ID', e.reportId);
// console.log('Data', new Int8Array(e.data.buffer));
// Second attempt: extract translation and rotation:
if (e.reportId === 1) console.log('T', new Int16Array(e.data.buffer));
if (e.reportId === 2) console.log('R', new Int16Array(e.data.buffer));
});
});
});
}
document.querySelector('#scan').addEventListener('click', scan);
</script>