Skip to content

Commit c34ca8d

Browse files
committed
cli/__init__.py: Add an option to the --stay-connected menu to re-run the stored program
1 parent e72b050 commit c34ca8d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pybricksdev/cli/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import questionary
2020
from argcomplete.completers import FilesCompleter
2121

22+
from packaging.version import Version
2223
from pybricksdev import __name__ as MODULE_NAME
2324
from pybricksdev import __version__ as MODULE_VERSION
2425
from pybricksdev.connections.pybricks import (
@@ -243,8 +244,9 @@ def is_pybricks_usb(dev):
243244
class ResponseOptions(IntEnum):
244245
RECOMPILE_RUN = 0
245246
RECOMPILE_DOWNLOAD = 1
246-
CHANGE_TARGET_FILE = 2
247-
EXIT = 3
247+
RERUN_STORED = 2
248+
CHANGE_TARGET_FILE = 3
249+
EXIT = 4
248250

249251
async def reconnect_hub():
250252
if not await questionary.confirm(
@@ -271,6 +273,7 @@ async def reconnect_hub():
271273
response_options = [
272274
"Recompile and Run",
273275
"Recompile and Download",
276+
"Re-run Stored Program",
274277
"Change Target File",
275278
"Exit",
276279
]
@@ -311,6 +314,15 @@ async def reconnect_hub():
311314
with _get_script_path(args.file) as script_path:
312315
await hub.download(script_path)
313316

317+
case ResponseOptions.RERUN_STORED:
318+
if hub.fw_version < Version("v1.2.0"):
319+
print(
320+
"Running a stored program remotely is only supported in firmware version >= v1.2.0."
321+
)
322+
else:
323+
await hub.start_user_program()
324+
await hub._wait_for_user_program_stop()
325+
314326
case ResponseOptions.CHANGE_TARGET_FILE:
315327
args.file.close()
316328
while True:

0 commit comments

Comments
 (0)