From 6f91c57743cf8d692d0f73d1583c34a93463baf3 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Fri, 11 Nov 2022 12:57:16 -0600 Subject: [PATCH] firmware/sagas: add delay after connecting This adds a delay after connecting to a hub when flashing firmware via BLE before sending any commands. This gives the OS Bluetooth stack time to finish enumerating the Bluetooth device before we start trying to interact with the device. Hopefully this fixes issues for some people who are seeing problems while flashing firmware. Issue: https://github.com/orgs/pybricks/discussions/792 --- CHANGELOG.md | 2 ++ src/firmware/sagas.ts | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 545218cf..3d4c607d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,10 @@ ### Fixed - Fixed app freezing when checking for updates and update server is unreachable ([pybricks-code#1299]). +- Added delay to try to mitigate errors when flashing firmware on city hubs ([support#792]). [pybricks-code#1299]: https://github.com/pybricks/pybricks-code/issues/1299 +[support#792]: https://github.com/orgs/pybricks/discussions/792 ## [2.0.0-beta.10] - 2022-11-11 diff --git a/src/firmware/sagas.ts b/src/firmware/sagas.ts index 6ef85cc5..f64bb5ea 100644 --- a/src/firmware/sagas.ts +++ b/src/firmware/sagas.ts @@ -393,6 +393,12 @@ function* handleFlashFirmware(action: ReturnType): Generat return; } + // istanbul ignore if + if (process.env.NODE_ENV !== 'test') { + // give OS Bluetooth stack some time to settle + yield* delay(1000); + } + const nextMessageId = yield* getContext<() => number>('nextMessageId'); const infoAction = yield* put(infoRequest(nextMessageId()));