-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
65 lines (53 loc) · 1.54 KB
/
main.js
File metadata and controls
65 lines (53 loc) · 1.54 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const LOGITECH_VENDOR_ID = 0x046D;
const HIDPP20_USAGE_PAGE = 0xFF43;
const APPLICATION = 0x01;
let hidpp = null;
// TODO
let d = null;
if (!("hid" in navigator)) {
window.location.replace("browser.html");
}
async function initialize() {
hidpp = await import('./lib/LitraDevice.mjs')
// Check if we've already connected devices
navigator.hid.getDevices().then(devices => {
if (devices.length == 0) {
console.log(`No HID devices selected. Press the "request device" button.`);
return;
}
devices.forEach(dev => initDevice(dev));
});
}
async function initDevice(device) {
if (device) {
let dev = new hidpp.LitraDevice(device);
await dev.init();
dev.render(litraSpace);
//TEST
d = dev;
}
}
// Wire add device button
requestDeviceButton.onclick = async event => {
try {
const filters = [
{ usage: 0x0202, vendorId: LOGITECH_VENDOR_ID, usagePage: HIDPP20_USAGE_PAGE },
{ usage: 0x0302, vendorId: LOGITECH_VENDOR_ID, usagePage: HIDPP20_USAGE_PAGE },
{ usage: 0x0602, vendorId: LOGITECH_VENDOR_ID, usagePage: HIDPP20_USAGE_PAGE },
{ usage: 0x0702, vendorId: LOGITECH_VENDOR_ID, usagePage: HIDPP20_USAGE_PAGE },
];
const devices = await navigator.hid.requestDevice({ filters });
devices.forEach(dev => initDevice(dev));
} catch(e) {
// TODO
console.log(e);
}
};
initialize();
navigator.hid.addEventListener("connect", event => {
if (event.device) {
if (event.device.vendorId == LOGITECH_VENDOR_ID) {
initDevice(event.device);
}
}
});