Skip to content

Conversation

afarago
Copy link
Contributor

@afarago afarago commented Aug 27, 2025

Minor implementation changes to make pybricks/support#2318 work

@afarago afarago force-pushed the feature-ev3-firmware-flash branch from 59e70c7 to 9d52d9d Compare August 27, 2025 20:15
Copy link
Member

@dlech dlech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for continuing the work here. In addition to the comments I made, we need to fix the failing tests and write a descriptive commit message.

@afarago afarago requested a review from dlech August 28, 2025 20:56
@afarago afarago requested a review from dlech August 29, 2025 18:19
Copy link
Member

@dlech dlech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there. 😄

It would also be nice to clean up the commits into logical commits for the various fixes and features with appropriate messages. I don't mind doing that when I merge it if that is more convenient.

src/usb/sagas.ts Outdated
Comment on lines 168 to 175
if (!usbDevice.configuration && usbDevice.configurations.length > 0) {
const [, selectErr] = yield* call(() =>
maybe(
usbDevice.selectConfiguration(
usbDevice.configurations[0].configurationValue,
),
),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!usbDevice.configuration && usbDevice.configurations.length > 0) {
const [, selectErr] = yield* call(() =>
maybe(
usbDevice.selectConfiguration(
usbDevice.configurations[0].configurationValue,
),
),
);
if (usbDevice.configuration === null) {
const [, selectErr] = yield* call(() =>
maybe(usbDevice.selectConfiguration(1)),
);

Since we control the firmware, we know that we always want configuration 1, which may or may not be the configuration at index 0.

And prefer strict equality checks instead of truthy/falsy unless there is a good reason for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, corrected.

Any comment or assert to document this "magic" number?

Concern: code-logic wise this could even break, only works as you control the firmware.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are probably a few other hard-coded USB things that we need to clean up like this. Agree that it would be sensible to make a constant for this. But we can save that for later.

@afarago
Copy link
Contributor Author

afarago commented Aug 30, 2025

Almost there. 😄

It would also be nice to clean up the commits into logical commits for the various fixes and features with appropriate messages. I don't mind doing that when I merge it if that is more convenient.

That is a fair comment. :D Apologies for my back-and-forth's.
Should I simply squash the commits into one?
I am also ok if you do it as you prefer.

@dlech
Copy link
Member

dlech commented Aug 30, 2025

I'll fix up the commits how I like them and merge this.

dlech and others added 7 commits August 30, 2025 22:00
Fix issues with null vs. undefined.

Based on DefinitelyTyped/DefinitelyTyped#73568
On some OSes, like macOS, the configuration may not be selected, so we
need to make sure it is always set.
Dispatch an error in case there is no firmware URL. Normally this should
never happen, but currently it does because we don't have EV3 firmware
yet. The error is more useful than just spinning forever.
The v2.1 spec allows this, but up to now, Pybricks code didn't handle it.
Start listening for reply before sending command to avoid race condition
of reply being received and action dispatched before we call take().
Implement unique message ID for EV3 firmware messages.
Add missing bits to get firmware flashing on EV3 working. Currently
requires custom firmware since we don't have a packaged one yet.
@dlech dlech force-pushed the feature-ev3-firmware-flash branch from 8edc14a to 311a833 Compare August 30, 2025 22:43
For some reason, the type checker doesn't catch this, but
FailToFinishReasonType.Unknown requires an error argument, otherwise
we get an unhandled exception.
@dlech dlech merged commit fa21abc into pybricks:master Aug 30, 2025
4 checks passed
@dlech
Copy link
Member

dlech commented Aug 30, 2025

Still lots to do, but nice to handle it in smaller chunks like this. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants