-
Notifications
You must be signed in to change notification settings - Fork 22
Add the abilty to resend code though bluetooth in the same session #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
07cacfc
9dfd844
018af5a
e1683b1
aa342f4
1180a0d
e83e1e9
004b3f5
4e878ee
41e7a77
dc1ecac
c4e0745
f76600c
3a595e4
87ce5bc
39d6675
31561dc
888aa70
2b2ace0
5bc6a3b
f4dede9
52f055f
745a588
0633bfd
476a1cd
2fa86cb
3bec955
f088c1a
7429c39
76a0b89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |||||
| from typing import ContextManager, TextIO | ||||||
|
|
||||||
| import argcomplete | ||||||
| import questionary | ||||||
| from argcomplete.completers import FilesCompleter | ||||||
|
|
||||||
| from pybricksdev import __name__ as MODULE_NAME | ||||||
|
|
@@ -160,6 +161,13 @@ def add_parser(self, subparsers: argparse._SubParsersAction): | |||||
| default=True, | ||||||
| ) | ||||||
|
|
||||||
| parser.add_argument( | ||||||
| "--stay-connected", | ||||||
| help="Add a menu option to resend the code with bluetooth instead of disconnecting from the robot after the program ends.", | ||||||
| action=argparse.BooleanOptionalAction, | ||||||
| default=False, | ||||||
| ) | ||||||
|
|
||||||
| async def run(self, args: argparse.Namespace): | ||||||
|
|
||||||
| # Pick the right connection | ||||||
|
|
@@ -213,16 +221,32 @@ def is_pybricks_usb(dev): | |||||
| # Connect to the address and run the script | ||||||
| await hub.connect() | ||||||
| try: | ||||||
| with _get_script_path(args.file) as script_path: | ||||||
| if args.start: | ||||||
| await hub.run(script_path, args.wait) | ||||||
| else: | ||||||
| await hub.download(script_path) | ||||||
| while True: | ||||||
| with _get_script_path(args.file) as script_path: | ||||||
| if args.start: | ||||||
| await hub.run(script_path, args.wait) | ||||||
| else: | ||||||
| await hub.download(script_path) | ||||||
|
|
||||||
| if not args.wait or not args.stay_connected: | ||||||
| break | ||||||
|
|
||||||
| resend = await questionary.select( | ||||||
| "Would you like to resend your code?", choices=["Resend", "Exit"] | ||||||
|
||||||
| ).ask_async() | ||||||
|
|
||||||
| if resend == "Exit": | ||||||
|
||||||
| if resend == "Exit": | |
| if response == "Exit": |
Would make more sense to me if the variable name wasn't one of the options.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is disconnection really the only possible thing that could happen to cause a RuntimeError?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could use
race_disconnect()here to cancel the menu if the hub becomes disconnected rather than waiting for the user to respond.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would be a much cleaner option. Since we would be properly handling the disconnect event, maybe it would be a good idea to prompt the user to re-connect?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like it would make the implementation quite a bit more complex. So I would say no. Or at least save that for implementing later.
After the program exits because of disconnect, the user should be able to just press up to get the command from the history in their terminal and run it again to reconnect.