summaryrefslogtreecommitdiffstatshomepage
path: root/tools
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-05-30 13:23:12 +1000
committerDamien George <damien@micropython.org>2023-06-02 16:11:29 +1000
commit7c2c9ea21cd320ac4044847f889ad3eeef7f8c7b (patch)
tree8f8685b8bbd15fc9bc83a068bce083239e23c73a /tools
parente4886dda859d873e77b1ff5f5b8d4a3aa0f3d517 (diff)
downloadmicropython-7c2c9ea21cd320ac4044847f889ad3eeef7f8c7b.tar.gz
micropython-7c2c9ea21cd320ac4044847f889ad3eeef7f8c7b.zip
tools/mpremote: Add `sleep` command.
This allows the sequence to be paused (e.g. wait for device, etc). Also removes the t_ms arg in reset/bootloader, because these arguments don't really need to be changed, and keeping them would mean inconsistent units used for time delays. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/mpremote/mpremote/main.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py
index eafa5b97e3..50a4e334bd 100644
--- a/tools/mpremote/mpremote/main.py
+++ b/tools/mpremote/mpremote/main.py
@@ -18,7 +18,7 @@ MicroPython device over a serial connection. Commands supported are:
"""
import argparse
-import os, sys
+import os, sys, time
from collections.abc import Mapping
from textwrap import dedent
@@ -42,6 +42,10 @@ from .repl import do_repl
_PROG = "mpremote"
+def do_sleep(state, args):
+ time.sleep(args.ms[0])
+
+
def do_help(state, _args=None):
def print_commands_help(cmds, help_key):
max_command_len = max(len(cmd) for cmd in cmds.keys())
@@ -98,6 +102,12 @@ def argparse_connect():
return cmd_parser
+def argparse_sleep():
+ cmd_parser = argparse.ArgumentParser(description="sleep before executing next command")
+ cmd_parser.add_argument("ms", nargs=1, type=float, help="milliseconds to sleep for")
+ return cmd_parser
+
+
def argparse_edit():
cmd_parser = argparse.ArgumentParser(description="edit files on the device")
cmd_parser.add_argument("files", nargs="+", help="list of remote paths")
@@ -212,6 +222,10 @@ _COMMANDS = {
do_connect,
argparse_connect,
),
+ "sleep": (
+ do_sleep,
+ argparse_sleep,
+ ),
"disconnect": (
do_disconnect,
argparse_none("disconnect current device"),
@@ -294,19 +308,19 @@ _BUILTIN_COMMAND_EXPANSIONS = {
"import uos\nprint('mount \\tsize \\tused \\tavail \\tuse%')\nfor _m in [''] + uos.listdir('/'):\n _s = uos.stat('/' + _m)\n if not _s[0] & 1 << 14: continue\n _s = uos.statvfs(_m)\n if _s[0]:\n _size = _s[0] * _s[2]; _free = _s[0] * _s[3]; print(_m, _size, _size - _free, _free, int(100 * (_size - _free) / _size), sep='\\t')",
],
# Other shortcuts.
- "reset t_ms=100": {
+ "reset": {
"command": [
"exec",
"--no-follow",
- "import utime, machine; utime.sleep_ms(t_ms); machine.reset()",
+ "import time, machine; time.sleep_ms(100); machine.reset()",
],
- "help": "reset the device after delay",
+ "help": "hard reset the device",
},
- "bootloader t_ms=100": {
+ "bootloader": {
"command": [
"exec",
"--no-follow",
- "import utime, machine; utime.sleep_ms(t_ms); machine.bootloader()",
+ "import time, machine; time.sleep_ms(100); machine.bootloader()",
],
"help": "make the device enter its bootloader",
},