listEndpoints etc

This commit is contained in:
jake downs 2024-02-18 20:25:30 -05:00
parent 33f8f61a14
commit e0cd593338
5 changed files with 139 additions and 17 deletions

View File

@ -128,7 +128,17 @@ export async function connectDevice() {
if (glasses) { if (glasses) {
return 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() { export async function disconnectDevice() {

View File

@ -51,7 +51,17 @@
// Request USB device // Request USB device
let device; let device;
try { 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) { } catch (err) {
console.error("No device was selected", err); console.error("No device was selected", err);
} }

View File

@ -71,6 +71,9 @@
</head> </head>
<body> <body>
<div id="noSupportHid"></div> <div id="noSupportHid"></div>
<div id="listEndpoints">
<button onclick="listEndpoints()">list endpoints</button>
</div>
<div id="connect"><button>connect</button></div> <div id="connect"><button>connect</button></div>
<div id="disconnect" onclick="disconnectDevices()"><button>disconnect</button></div> <div id="disconnect" onclick="disconnectDevices()"><button>disconnect</button></div>
<div id="startIMU" style="display: none;" onclick="startIMU()"><button>start headtracking</button></div> <div id="startIMU" style="display: none;" onclick="startIMU()"><button>start headtracking</button></div>
@ -320,8 +323,11 @@
// }); // });
// } // }
window.connected_devices = [];
window.connect = function() { window.connect = function() {
Common.connectDevice().then(async glasses => { Common.connectDevice().then(async glasses => {
connected_devices.push(glasses);
if (glasses) { if (glasses) {
document.getElementById('startIMU').style.display = 'block' document.getElementById('startIMU').style.display = 'block'
document.getElementById('hadConnect').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.disconnectDevices = () => {
window.curGlassesArray.map(g=>{ window.curGlassesArray.map(g=>{
g._device.close(); g._device.close();
@ -457,31 +468,44 @@
window.endpoints = []; window.endpoints = [];
window.listUsbEndpoints = () => { window.listUsbEndpoints = async () => {
window.endpoints = []; window.endpoints = [];
// list usb endpoints // list usb endpoints
navigator.usb.requestDevice({filters:[]}).then((device)=>{ let device = await navigator.usb.requestDevice({
window.usb_device = device; filters: [{
vendorId: 0x0486, // ? ASUS Computers Inc. ?
}, {
vendorId: 0x0483, // STMicroelectronics ?
}, {
vendorId: 0x0482, // Kyocera Corporation ?
}, {
vendorId: 0x3318, // Gleaming Reality (Wuxi) Technology Co., LTD ?
}]
})
//usb_device.configurations[0].interfaces[1].alternates[1].endpoints[0] window.usb_device = device;
for(let configuration of device.configurations){ //usb_device.configurations[0].interfaces[1].alternates[1].endpoints[0]
for(let _interface of configuration.interfaces){ for(let configuration of device.configurations){
for(let alternate of _interface?.alternates ?? []){ for(let _interface of configuration.interfaces){
for(let endpoint of alternate.endpoints){ for(let alternate of _interface?.alternates ?? []){
window.endpoints.push(endpoint); for(let endpoint of alternate.endpoints){
}
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)
} }

View File

@ -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 // Parameters required for the progress bar
// function progress(cur, all) { // function progress(cur, all) {
// current = cur // current = cur
@ -183,8 +216,19 @@ async function waitBootDevice() {
} }
// await requestDevice() // await requestDevice()
// await navigator.hid.requestDevice({
// filters: [{ vendorId: Protocol.NREAL_VENDOR_ID, productId: Protocol.NREAL_BOOT_PRODUCT_ID }]
// });
await navigator.hid.requestDevice({ 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(); const time = new Date().getTime();
while ((new Date().getTime() - time) < 2000) { while ((new Date().getTime() - time) < 2000) {
@ -489,6 +533,8 @@ async function sendFirmwareInDsp(glasses, data) {
} }
*/ */
// Delay synchronization program execution // Delay synchronization program execution
function sleep(delay) { function sleep(delay) {
return new Promise((resolve) => setTimeout(resolve, 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 */ /** read air glassess Brightness */
export async function getBrightness() { export async function getBrightness() {
let glasses = await common.connectDevice(); let glasses = await common.connectDevice();
@ -549,7 +621,7 @@ export async function getBrightness() {
return 'not found device'; return 'not found device';
} }
// what's the chance the getBrightness is the same as setBrightness? // 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 => { .then(report => {
if (reportSuccess(report)) { if (reportSuccess(report)) {
return report.payload; return report.payload;

View File

@ -73,6 +73,12 @@ export const MESSAGES = {
// R_IMU_DATA: 0x80,//IMU data // R_IMU_DATA: 0x80,//IMU data
// UNKNOWN_40: 0x40,//Unknown // 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_TOGGLE_IMU: 0x19,
W_CANCEL_ACTIVATION: 0x19, W_CANCEL_ACTIVATION: 0x19,