Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions components/odrive_ascii/web/odrive_control_panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
<header>
<h1>ODrive Native &mdash; WebUSB Control Panel</h1>
<div class="spacer"></div>
<label class="checkbox-inline" title="Show every USB device in the chooser instead of only the default ODrive VID/PID (0x1209/0x0d32).">
<label class="checkbox-inline" title="Show every USB device in the chooser instead of only espp devices (the default filter is VID 0x1209, any PID).">
<input type="checkbox" id="anyDevice"> Any device
</label>
<button id="connectBtn" class="primary">Connect</button>
Expand Down Expand Up @@ -669,16 +669,25 @@ <h2>Device</h2>
if (device) await disconnect(); else await connect();
});

// WebUSB requires a `filters` member (there is no acceptAllDevices). The
// "show all" path uses one empty filter `{}` (matches everything); a few
// WebUSB implementations reject an empty filter object, so fall back to a
// VID-only filter in that case.
async function requestUsbDevice(anyDevice) {
const showAll = { filters: [{}] };
const vidOnly = { filters: [{ vendorId: DEFAULT_VID }] };
try {
return await navigator.usb.requestDevice(anyDevice ? showAll : vidOnly);
} catch (e) {
if (anyDevice && e && e.name === "TypeError")
return await navigator.usb.requestDevice(vidOnly);
throw e;
}
}

async function connect() {
try {
// WebUSB has no `acceptAllDevices` option (that is Web Bluetooth) --
// `filters` is a required member, and a single empty filter object `{}`
// matches every device. The default filter is VID-only so any espp
// device (VID 0x1209) is offered, not just the ODrive PID.
const options = els.anyDevice.checked
? { filters: [{}] }
: { filters: [{ vendorId: DEFAULT_VID }] };
device = await navigator.usb.requestDevice(options);
device = await requestUsbDevice(els.anyDevice.checked);
} catch (e) {
// Only NotFoundError is a user cancel / no-match; anything else is real.
if (e && e.name === "NotFoundError") {
Expand Down Expand Up @@ -1457,7 +1466,7 @@ <h2>Device</h2>
setStatus("", "Disconnected");
setConnectedUI(false);
logLine("sys", "Ready. Click Connect and pick the ODrive native (vendor) USB device.");
logLine("sys", `Default filter: any espp device (VID 0x${DEFAULT_VID.toString(16)}). Tick "Any device" to see all.`);
logLine("sys", `Default filter: any device with VID 0x${DEFAULT_VID.toString(16).padStart(4, "0")}. Tick "Any device" to see all.`);
logLine("sys", "This panel speaks the native (Fibre-endpoint) BINARY protocol, not ASCII.");
drawPlot(); updateLegend();
}
Expand Down
36 changes: 23 additions & 13 deletions components/odrive_ascii/web/odrive_webusb_console.html
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
<header>
<h1>ODrive ASCII &mdash; WebUSB Console</h1>
<div class="spacer"></div>
<label class="checkbox-inline" title="Show every USB device in the chooser instead of only the default ODrive VID/PID (0x1209/0x0d32).">
<label class="checkbox-inline" title="Show every USB device in the chooser instead of only espp devices (the default filter is VID 0x1209, any PID).">
<input type="checkbox" id="anyDevice"> Any device
</label>
<button id="connectBtn" class="primary">Connect</button>
Expand Down Expand Up @@ -670,18 +670,28 @@ <h2>Misc</h2>
}
});

// WebUSB requires a `filters` member (there is no acceptAllDevices). The
// "show all" path uses one empty filter `{}` (matches everything); a few
// WebUSB implementations reject an empty filter object, so fall back to a
// VID-only filter in that case.
async function requestUsbDevice(anyDevice) {
const showAll = { filters: [{}] };
const vidOnly = { filters: [{ vendorId: DEFAULT_VID }] };
try {
return await navigator.usb.requestDevice(anyDevice ? showAll : vidOnly);
} catch (e) {
if (anyDevice && e && e.name === "TypeError")
return await navigator.usb.requestDevice(vidOnly);
Comment on lines +683 to +684
throw e;
}
}

async function connect() {
// 1) Ask the user to pick a device. Default filter targets the espp
// ODrive vendor VID/PID; "Any device" shows every device instead.
// 1) Ask the user to pick a device. Default filter is VID-only (any
// device with VID 0x1209, not just the ODrive PID); "Any device"
// shows every connected device instead.
try {
// WebUSB has no `acceptAllDevices` option (that is Web Bluetooth) --
// `filters` is a required member, and a single empty filter object `{}`
// matches every device. The default filter is VID-only so any espp
// device (VID 0x1209) is offered, not just the ODrive PID.
const options = els.anyDevice.checked
? { filters: [{}] }
: { filters: [{ vendorId: DEFAULT_VID }] };
device = await navigator.usb.requestDevice(options);
device = await requestUsbDevice(els.anyDevice.checked);
} catch (e) {
// Only a NotFoundError means the user dismissed the chooser (or nothing
// matched). Anything else is a real error worth surfacing.
Expand Down Expand Up @@ -1184,8 +1194,8 @@ <h2>Misc</h2>
}
setStatus("", "Disconnected");
setConnectedUI(false);
logLine("sys", "Ready. Click Connect and pick the ODrive vendor USB device.");
logLine("sys", `Default filter: any espp device (VID 0x${DEFAULT_VID.toString(16)}). Tick "Any device" to see all.`);
logLine("sys", "Ready. Click Connect and pick your ODrive (the chooser lists any device with VID 0x1209).");
logLine("sys", `Default filter: any device with VID 0x${DEFAULT_VID.toString(16).padStart(4, "0")}. Tick "Any device" to see all.`);
drawSpark();
}

Expand Down
Loading