diff --git a/common.js b/common.js index c4bb6bc..b770930 100644 --- a/common.js +++ b/common.js @@ -128,7 +128,17 @@ export async function connectDevice() { if (glasses) { return glasses; } - return await requestDevice(); + return await requestDevice({ + filters: [{ + vendorId: 0x0486, // ? ASUS Computers Inc. ? + }, { + vendorId: 0x0483, // STMicroelectronics ? + }, { + vendorId: 0x0482, // Kyocera Corporation ? + }, { + vendorId: 0x3318, // Gleaming Reality (Wuxi) Technology Co., LTD ? + }] + }); } export async function disconnectDevice() { diff --git a/index.html b/index.html index edc2d87..dea29b2 100644 --- a/index.html +++ b/index.html @@ -51,7 +51,17 @@ // Request USB device let device; try { - device = await navigator.usb.requestDevice({ filters: [{ vendorId: 0x2341 }] }); + device = await navigator.usb.requestDevice({ + filters: [{ + vendorId: 0x0486, // ? ASUS Computers Inc. ? + }, { + vendorId: 0x0483, // STMicroelectronics ? + }, { + vendorId: 0x0482, // Kyocera Corporation ? + }, { + vendorId: 0x3318, // Gleaming Reality (Wuxi) Technology Co., LTD ? + }] + }); } catch (err) { console.error("No device was selected", err); } diff --git a/index_old.html b/index_old.html index baf510b..dad343e 100644 --- a/index_old.html +++ b/index_old.html @@ -71,6 +71,9 @@
+
+ +
@@ -320,8 +323,11 @@ // }); // } + window.connected_devices = []; + window.connect = function() { Common.connectDevice().then(async glasses => { + connected_devices.push(glasses); if (glasses) { document.getElementById('startIMU').style.display = 'block' document.getElementById('hadConnect').style.display = 'block' @@ -448,6 +454,11 @@ }); } + window.listEndpoints = () => { + // Manager.listEndpoints(connected_devices[0]); + window.listUsbEndpoints(); + } + window.disconnectDevices = () => { window.curGlassesArray.map(g=>{ g._device.close(); @@ -457,31 +468,44 @@ window.endpoints = []; - window.listUsbEndpoints = () => { + window.listUsbEndpoints = async () => { window.endpoints = []; // list usb endpoints - navigator.usb.requestDevice({filters:[]}).then((device)=>{ - window.usb_device = device; + let device = await navigator.usb.requestDevice({ + filters: [{ + vendorId: 0x0486, // ? ASUS Computers Inc. ? + }, { + vendorId: 0x0483, // STMicroelectronics ? + }, { + vendorId: 0x0482, // Kyocera Corporation ? + }, { + vendorId: 0x3318, // Gleaming Reality (Wuxi) Technology Co., LTD ? + }] + }) + + window.usb_device = device; - //usb_device.configurations[0].interfaces[1].alternates[1].endpoints[0] + //usb_device.configurations[0].interfaces[1].alternates[1].endpoints[0] - for(let configuration of device.configurations){ + for(let configuration of device.configurations){ - for(let _interface of configuration.interfaces){ + for(let _interface of configuration.interfaces){ - for(let alternate of _interface?.alternates ?? []){ + for(let alternate of _interface?.alternates ?? []){ - for(let endpoint of alternate.endpoints){ + for(let endpoint of alternate.endpoints){ - window.endpoints.push(endpoint); - } + window.endpoints.push(endpoint); } } } - - console.table(window.endpoints); - }) + } + console.warn('CONNECTED TO DEVICE: ENDPOINTS:') + console.table(window.endpoints); + + // new recursive debug printout: + await Manager.listEndpoints(device) } diff --git a/js_air/manager.js b/js_air/manager.js index 6598fc3..ab7fbb6 100644 --- a/js_air/manager.js +++ b/js_air/manager.js @@ -134,6 +134,39 @@ export async function getFirmwareVersionInDsp() { }); } +export async function listEndpoints(device) { + await device.open(); + + // Listing available configurations valid for selection + let configurations = device.configurations; + for (let i = 0; i < configurations.length; i++) { + console.log(`Configuration ${i}: ${configurations[i].configurationValue}`); + + try{ + // Select the current configuration + // Assuming the configuration is 0-based + await device.selectConfiguration(i+1); + + // Iterate over all available interfaces for the current configuration and claim them + for (let j = 0; j < device.configuration.interfaces.length; j++) { + try{ + await device.claimInterface(j); + device.configuration.interfaces[j].alternates.forEach((alternate) => { + console.log(`Configuration ${i}, iface ${j} Alternate ${alternate.alternateSetting}`); + alternate.endpoints.forEach((endpoint) => { + console.log(`Endpoint ${endpoint.endpointNumber} Direction ${endpoint.direction}`); + }); + }); + }catch(e){ + console.error(e); + } + } + }catch(e){ + console.error(e) + } + } +} + // Parameters required for the progress bar // function progress(cur, all) { // current = cur @@ -183,8 +216,19 @@ async function waitBootDevice() { } // await requestDevice() + // await navigator.hid.requestDevice({ + // filters: [{ vendorId: Protocol.NREAL_VENDOR_ID, productId: Protocol.NREAL_BOOT_PRODUCT_ID }] + // }); await navigator.hid.requestDevice({ - filters: [{ vendorId: Protocol.NREAL_VENDOR_ID, productId: Protocol.NREAL_BOOT_PRODUCT_ID }] + filters: [{ + vendorId: 0x0486, // ? ASUS Computers Inc. ? + }, { + vendorId: 0x0483, // STMicroelectronics ? + }, { + vendorId: 0x0482, // Kyocera Corporation ? + }, { + vendorId: 0x3318, // Gleaming Reality (Wuxi) Technology Co., LTD ? + }] }); const time = new Date().getTime(); while ((new Date().getTime() - time) < 2000) { @@ -489,6 +533,8 @@ async function sendFirmwareInDsp(glasses, data) { } */ + + // Delay synchronization program execution function sleep(delay) { return new Promise((resolve) => setTimeout(resolve, delay)) @@ -542,6 +588,32 @@ export async function stopIMU() { }) } +export async function getDisplayMode(){ + let glasses = await common.connectDevice(); + if (!glasses) { + return 'not found device'; + } + return glasses.sendReportTimeout(Protocol.MESSAGES.R_DISPLAY_MODE) + .then(report => { + if (reportSuccess(report)) { + return report.payload[0]; + } + }); +} + +export async function setDisplayMode(mode){ + let glasses = await common.connectDevice(); + if (!glasses) { + return 'not found device'; + } + return glasses.sendReportTimeout(Protocol.MESSAGES.W_DISPLAY_MODE, [mode]) + .then(report => { + if (reportSuccess(report)) { + return report.payload[0]; + } + }); +} + /** read air glassess Brightness */ export async function getBrightness() { let glasses = await common.connectDevice(); @@ -549,7 +621,7 @@ export async function getBrightness() { return 'not found device'; } // what's the chance the getBrightness is the same as setBrightness? - return glasses.sendReportTimeout(Protocol.MESSAGES.W_BRIGHTNESS) + return glasses.sendReportTimeout(Protocol.MESSAGES.R_BRIGHTNESS) .then(report => { if (reportSuccess(report)) { return report.payload; diff --git a/js_air/protocol.js b/js_air/protocol.js index f33cb44..746283a 100644 --- a/js_air/protocol.js +++ b/js_air/protocol.js @@ -73,6 +73,12 @@ export const MESSAGES = { // R_IMU_DATA: 0x80,//IMU data // UNKNOWN_40: 0x40,//Unknown + R_DISPLAY_MODE: 0x7,//Read display mode + W_DISPLAY_MODE: 0x08,//Write display mode + + R_BRIGHTNESS: 0x0,//Read brightness + W_BRIGHTNESS: 0x0,//Write brightness + W_TOGGLE_IMU: 0x19, W_CANCEL_ACTIVATION: 0x19,