mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 09:36:27 +00:00
bootloader: add withResponse option
This takes advantage of new (not implemented yet) Web Bluetooth APIs to write with or without response
This commit is contained in:
@@ -81,7 +81,17 @@ async function send(action: Action, dispatch: Dispatch): Promise<void> {
|
||||
if (!char) {
|
||||
throw Error('Not connected');
|
||||
}
|
||||
await char.writeValue((action as BootloaderConnectionSendAction).data);
|
||||
const sendAction = action as BootloaderConnectionSendAction;
|
||||
// Fall back to legacy WebBluetooth writeValue if new methods are not
|
||||
// available.
|
||||
const writeValue = sendAction.withResponse
|
||||
? // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
||||
// @ts-ignore
|
||||
char.writeValueWithResponse || char.writeValue
|
||||
: // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
||||
// @ts-ignore
|
||||
char.writeValueWithoutResponse || char.writeValue;
|
||||
await writeValue(sendAction.data);
|
||||
dispatch(didSend());
|
||||
} catch (err) {
|
||||
dispatch(didSend(err));
|
||||
|
||||
Reference in New Issue
Block a user