pybricks / support

Pybricks support and general discussion
MIT License
109 stars 7 forks source link

Program slots and Pybricks Code #1799

Open laurensvalk opened 2 months ago

laurensvalk commented 2 months ago

One thing I not so sure about though is how to deal with multiple "user" slots in Pybricks Code.

It would probably be a good idea to add some kind of way to read which slots have a valid program in them.

With WebBluetooth, we can't get the actual error code for failures. So if we attempt to run a program in a slot with a bad program, there is no way to know why the error occurred. Was it out of range? Was it a bad program? Did the hub battery die? Right now, we don't have any "expected" errors, so we kind of ignore this problem.

So that's why I'm thinking it would be better to have something where we can "ask first" before trying something that would fail, so that we don't actually ever try to do something that might fail under normal circumstances.

Originally posted by @dlech in https://github.com/pybricks/pybricks-micropython/pull/264

laurensvalk commented 2 months ago

We'll also want to tell Pybricks Code the maximum available size for the current slot, since it is no longer the fixed size we provide in the hub capabilities.

laurensvalk commented 2 months ago

Gathering some notes from elsewhere in one place:

At minimum, we'll also want to do the following:

  • [ ] Introduce a status flag such as PBIO_PYBRICKS_STATUS_RECEIVING_PROGRAM to prevent the UI interactions like a slot change while a big program is being loaded. This isn't done yet, so changing slot while loading lead to failure.
  • [ ] Inform Pybricks Code about the maximum size for the current slot, or all slots. Perhaps also include the slot in the event status report (slot is not necessarily the same as program ID). Right now, Pybricks Code won't know that storage is full until it is actually full.

We can probably rethink the logic for downloading programs more generally. At the moment, Pybricks Code sets the program size to 0 (to prevent it from being run), then uploads the program, then downloads the size. This is no longer sufficient, hence the need for a status. Alternately, maybe this should be a process of some kind so the hub can know about failure (and clear that status). Right now, if uploading stops halfway the hub has no way of knowing since it doesn't know the final file size.

Originally posted by @laurensvalk in https://github.com/pybricks/pybricks-micropython/pull/266

I would much prefer to see slots saved to external flash when not in use rather than trying to keep all slots in RAM at the same time. Otherwise, we are wasting a lot of RAM.

Originally posted by @dlech in https://github.com/pybricks/pybricks-micropython/pull/266