usb/sagas: always set configuration

On some OSes, like macOS, the configuration may not be selected, so we
need to make sure it is always set.
This commit is contained in:
Attila Farago
2025-08-30 19:12:53 -04:00
committed by David Lechner
parent 6fc327a917
commit c6302232e3
+10 -11
View File
@@ -161,17 +161,16 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator {
return;
}
// REVISIT: For now, we are making the assumption that there is only one
// configuration and it is already selected and that it contains a Pybricks
// interface.
assert(
usbDevice.configuration !== undefined,
'USB device configuration is undefined',
);
assert(
usbDevice.configuration.interfaces.length > 0,
'USB device has no interfaces',
);
const [, selectErr] = yield* call(() => maybe(usbDevice.selectConfiguration(1)));
if (selectErr) {
// TODO: show error message to user here
console.error('Failed to select USB device configuration:', selectErr);
yield* put(usbDidFailToConnectPybricks());
yield* cleanup();
return;
}
assert(usbDevice.configuration !== null, 'USB device configuration is null');
const iface = usbDevice.configuration.interfaces.find(
(iface) =>